1 | ;
|
2 |
|
3 | /*
|
4 | * attempt to require a given node_module.
|
5 | * If the module was found, return found value
|
6 | * If the module was NOT found, return null
|
7 | * If requiring the module crashes for an unexpected reason, throw the unexpected error
|
8 | */
|
9 | module.exports = function tryRequire(moduleName) {
|
10 | try {
|
11 | return require(moduleName);
|
12 | } catch (err) {
|
13 | if (err !== null && typeof err === 'object' && err.code === 'MODULE_NOT_FOUND') {
|
14 | return null;
|
15 | } else {
|
16 | throw err;
|
17 | }
|
18 | }
|
19 | };
|