-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make node-notifier an optional dependency
- Loading branch information
Caleb ツ Everett
committed
Sep 6, 2019
1 parent
c588c18
commit ece7ab9
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
export default getNotifier(); | ||
|
||
/** | ||
* Return a notifier implementation. | ||
* | ||
* node-notifier is an optional dependency so it may not be installed. | ||
* If node-notifier is not found then a stub notifier is returned that throws | ||
* an error whenever it is used. | ||
*/ | ||
function getNotifier(): Notify { | ||
try { | ||
const notifier: typeof import('node-notifier') = require('node-notifier'); | ||
return notifier.notify.bind(notifier); | ||
} catch (ex) { | ||
if (ex.code !== 'MODULE_NOT_FOUND') { | ||
throw ex; | ||
} | ||
return () => { | ||
throw Error( | ||
'notify reporter requires optional dependeny node-notifier but it was not found', | ||
); | ||
}; | ||
} | ||
} | ||
|
||
export type Notify = ( | ||
notification?: Notification, | ||
callback?: NotificationCallback, | ||
) => unknown; | ||
|
||
interface Notification { | ||
title?: string; | ||
message?: string; | ||
icon?: string; | ||
closeLabel?: string; | ||
actions?: string | Array<string>; | ||
timeout?: number; | ||
} | ||
|
||
interface NotificationCallback { | ||
(err: Error | null, response: string, metadata?: NotificationMetadata): void; | ||
} | ||
|
||
interface NotificationMetadata { | ||
activationValue?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters