optional-require
Advanced tools
Comparing version
16
index.js
@@ -6,5 +6,17 @@ "use strict"; | ||
function findModuleNotFound(err, name) { | ||
// First line is "Cannot find module 'foo'" | ||
// Check the first line of the error message | ||
const msg = err.message.split("\n")[0]; | ||
return msg && msg.includes(`'${name}'`); | ||
return msg && ( | ||
// Check for "Cannot find module 'foo'" | ||
msg.includes(`'${name}'`) | ||
// Check for "Your application tried to access foo (a peer dependency) ..." (Yarn v2 PnP) | ||
// https://github.com/yarnpkg/berry/blob/e81dc0d29bb2f41818d9c5c1c74bab1406fb979b/packages/yarnpkg-pnp/sources/loader/makeApi.ts#L680 | ||
|| msg.includes(` ${name} `) | ||
// Check for "Your application tried to access foo. While ..." (Yarn v2 PnP) | ||
// https://github.com/yarnpkg/berry/blob/e81dc0d29bb2f41818d9c5c1c74bab1406fb979b/packages/yarnpkg-pnp/sources/loader/makeApi.ts#L704 | ||
|| msg.includes(` ${name}. `) | ||
// Check for "Your application tried to access foo, but ..." (Yarn v2 PnP) | ||
// https://github.com/yarnpkg/berry/blob/e81dc0d29bb2f41818d9c5c1c74bab1406fb979b/packages/yarnpkg-pnp/sources/loader/makeApi.ts#L718 | ||
|| msg.includes(` ${name}, `) | ||
); | ||
} | ||
@@ -11,0 +23,0 @@ |
{ | ||
"name": "optional-require", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "NodeJS Require that let you handle module not found error without try/catch", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
7400
12.53%64
23.08%