@dekkai/env
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -39,3 +39,3 @@ /** | ||
try { | ||
import(`${null}`).catch(() => false); | ||
import(/* webpackIgnore: true */ `${null}`).catch(() => false); | ||
return true; | ||
@@ -58,2 +58,4 @@ } | ||
} | ||
// eslint-disable-next-line no-new-func | ||
const requireFunc = new Function('mod', 'return require(mod)'); | ||
/** | ||
@@ -65,9 +67,10 @@ * Detects the environment and loads a module using either `require` or `import`. | ||
if (kSupportsDynamicImport) { | ||
return await import(mod.toString()); | ||
return await import(/* webpackIgnore: true */ mod.toString()); | ||
} | ||
else if (isNodeJS()) { | ||
return typeof module !== 'undefined' && typeof module.require === 'function' && module.require(mod.toString()) || | ||
// eslint-disable-next-line camelcase | ||
typeof __non_webpack_require__ === 'function' && __non_webpack_require__(mod.toString()) || | ||
typeof require === 'function' && require(mod.toString()); // eslint-disable-line | ||
// return typeof module !== 'undefined' && typeof module.require === 'function' && module.require(mod.toString()) || | ||
// // eslint-disable-next-line camelcase | ||
// typeof __non_webpack_require__ === 'function' && __non_webpack_require__(mod.toString()) || | ||
// typeof require === 'function' && require(mod.toString()); // eslint-disable-line | ||
return requireFunc(mod); | ||
} | ||
@@ -74,0 +77,0 @@ // not supported, a dynamic loader could be created for browser environments here, all modern browsers support |
@@ -9,3 +9,3 @@ import { isNodeJS } from './node.js'; | ||
try { | ||
import(`${null}`).catch(() => false); | ||
import(/* webpackIgnore: true */ `${null}`).catch(() => false); | ||
return true; | ||
@@ -28,2 +28,4 @@ } | ||
} | ||
// eslint-disable-next-line no-new-func | ||
const requireFunc = new Function('mod', 'return require(mod)'); | ||
/** | ||
@@ -35,9 +37,10 @@ * Detects the environment and loads a module using either `require` or `import`. | ||
if (kSupportsDynamicImport) { | ||
return await import(mod.toString()); | ||
return await import(/* webpackIgnore: true */ mod.toString()); | ||
} | ||
else if (isNodeJS()) { | ||
return typeof module !== 'undefined' && typeof module.require === 'function' && module.require(mod.toString()) || | ||
// eslint-disable-next-line camelcase | ||
typeof __non_webpack_require__ === 'function' && __non_webpack_require__(mod.toString()) || | ||
typeof require === 'function' && require(mod.toString()); // eslint-disable-line | ||
// return typeof module !== 'undefined' && typeof module.require === 'function' && module.require(mod.toString()) || | ||
// // eslint-disable-next-line camelcase | ||
// typeof __non_webpack_require__ === 'function' && __non_webpack_require__(mod.toString()) || | ||
// typeof require === 'function' && require(mod.toString()); // eslint-disable-line | ||
return requireFunc(mod); | ||
} | ||
@@ -44,0 +47,0 @@ // not supported, a dynamic loader could be created for browser environments here, all modern browsers support |
{ | ||
"name": "@dekkai/env", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Utility methods to detect runtimes and load modules dynamically.", | ||
@@ -33,3 +33,3 @@ "main": "build/lib/mod.js", | ||
"test:browser": "karma start --single-run --browsers ChromeHeadless karma.conf.cjs", | ||
"test:deno": "deno run --allow-read --allow-net spec/env/deno.suite.js", | ||
"test:deno": "deno run --allow-read --allow-net --location 'http://localhost:0' spec/env/deno.suite.js", | ||
"lint": "eslint . --ext .js,.ts,.jsx,.tsx", | ||
@@ -36,0 +36,0 @@ "prepack": "run-s clean test lint", |
@@ -9,3 +9,3 @@ import {isNodeJS} from './node'; | ||
try { | ||
import(`${null}`).catch(() => false); | ||
import(/* webpackIgnore: true */ `${null}`).catch(() => false); | ||
return true; | ||
@@ -38,2 +38,5 @@ } catch { | ||
// eslint-disable-next-line no-new-func | ||
const requireFunc = new Function('mod', 'return require(mod)'); | ||
/** | ||
@@ -45,8 +48,9 @@ * Detects the environment and loads a module using either `require` or `import`. | ||
if (kSupportsDynamicImport) { | ||
return await import(mod.toString()); | ||
return await import(/* webpackIgnore: true */ mod.toString()); | ||
} else if (isNodeJS()) { | ||
return typeof module !== 'undefined' && typeof module.require === 'function' && module.require(mod.toString()) || | ||
// eslint-disable-next-line camelcase | ||
typeof __non_webpack_require__ === 'function' && __non_webpack_require__(mod.toString()) || | ||
typeof require === 'function' && require(mod.toString()); // eslint-disable-line | ||
// return typeof module !== 'undefined' && typeof module.require === 'function' && module.require(mod.toString()) || | ||
// // eslint-disable-next-line camelcase | ||
// typeof __non_webpack_require__ === 'function' && __non_webpack_require__(mod.toString()) || | ||
// typeof require === 'function' && require(mod.toString()); // eslint-disable-line | ||
return requireFunc(mod); | ||
} | ||
@@ -53,0 +57,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
23500
283
1
1