import-sync
Advanced tools
Comparing version 2.0.6 to 2.1.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VALID_FILE_EXTENSIONS = void 0; | ||
exports.VALID_FILE_EXTENSIONS = Object.freeze(['.js', '.mjs', '.cjs']); | ||
exports.VALID_FILE_EXTENSIONS = Object.freeze(['.js', '.mjs', '.cjs', '.ts']); | ||
//# sourceMappingURL=config.js.map |
@@ -54,4 +54,5 @@ "use strict"; | ||
const es6Require = createEs6Require(opts.esmOptions); | ||
let importedModule; | ||
try { | ||
return es6Require(modulePath); | ||
importedModule = es6Require(modulePath); | ||
} | ||
@@ -68,4 +69,13 @@ catch (error) { | ||
} | ||
// In case CJS shows up as empty, e.g. when importing CommonJS/CommonTS into Jest | ||
if (Object.keys(importedModule).length === 0) { | ||
try { | ||
const basicModule = require(modulePath); | ||
importedModule = Object.keys(basicModule).length > 0 ? basicModule : importedModule; | ||
} | ||
catch (error) { /* nothing to do */ } | ||
} | ||
return importedModule; | ||
}; | ||
exports.default = importSync; | ||
//# sourceMappingURL=import.js.map |
@@ -1,2 +0,2 @@ | ||
export const VALID_FILE_EXTENSIONS = Object.freeze(['.js', '.mjs', '.cjs']); | ||
export const VALID_FILE_EXTENSIONS = Object.freeze(['.js', '.mjs', '.cjs', '.ts']); | ||
//# sourceMappingURL=config.js.map |
@@ -49,4 +49,5 @@ import esm from 'esm'; | ||
const es6Require = createEs6Require(opts.esmOptions); | ||
let importedModule; | ||
try { | ||
return es6Require(modulePath); | ||
importedModule = es6Require(modulePath); | ||
} | ||
@@ -63,4 +64,13 @@ catch (error) { | ||
} | ||
// In case CJS shows up as empty, e.g. when importing CommonJS/CommonTS into Jest | ||
if (Object.keys(importedModule).length === 0) { | ||
try { | ||
const basicModule = require(modulePath); | ||
importedModule = Object.keys(basicModule).length > 0 ? basicModule : importedModule; | ||
} | ||
catch (error) { /* nothing to do */ } | ||
} | ||
return importedModule; | ||
}; | ||
export default importSync; | ||
//# sourceMappingURL=import.js.map |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "2.0.6", | ||
"version": "2.1.0", | ||
"files": [ | ||
@@ -10,0 +10,0 @@ "dist" |
@@ -146,4 +146,3 @@ <div align="center"> | ||
- `'./minimal'` | ||
- `importSync` will look for `'./minimal.js'` before `'./minimal.mjs'` | ||
- `importSync` will look for matching extensions in the order `[.js, .mjs, .cjs]` | ||
- `importSync` will look for matching extensions in the order `[.js, .mjs, .cjs, .ts]` | ||
- `'node-fetch'` | ||
@@ -250,9 +249,4 @@ - `importSync` can import pure-esm [node-fetch](https://github.com/node-fetch/node-fetch) (v3) in your cjs project | ||
One known non-issue is that in [jest](https://jestjs.io/), calling `importSync` on | ||
a CommonJS module returns an empty object. | ||
There is currently no known limitations. | ||
There are currently no plans to fix this issue, as the built-in NodeJS | ||
[require](https://nodejs.org/api/modules.html#requireid) function should simply be used | ||
instead when importing CommonJS modules. | ||
## 5. Caveats | ||
@@ -259,0 +253,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
37415
348
316
8