🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

optional-require

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

optional-require - npm Package Compare versions

Comparing version

to
1.0.3

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 @@

2

package.json
{
"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",