@oclif/core 2.11.4 → 2.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module-loader.js +3 -8
- package/package.json +1 -1
package/lib/module-loader.js
CHANGED
|
@@ -11,11 +11,6 @@ const getPackageType = require('get-package-type');
|
|
|
11
11
|
*/
|
|
12
12
|
// eslint-disable-next-line camelcase
|
|
13
13
|
const s_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs'];
|
|
14
|
-
/**
|
|
15
|
-
* Provides a mechanism to use dynamic import / import() with tsconfig -> module: commonJS as otherwise import() gets
|
|
16
|
-
* transpiled to require().
|
|
17
|
-
*/
|
|
18
|
-
const _importDynamic = new Function('modulePath', 'return import(modulePath)'); // eslint-disable-line no-new-func
|
|
19
14
|
/**
|
|
20
15
|
* Provides a static class with several utility methods to work with Oclif config / plugin to load ESM or CJS Node
|
|
21
16
|
* modules and source files.
|
|
@@ -45,8 +40,8 @@ class ModuleLoader {
|
|
|
45
40
|
let isESM;
|
|
46
41
|
try {
|
|
47
42
|
({ isESM, filePath } = ModuleLoader.resolvePath(config, modulePath));
|
|
48
|
-
// It is important to await on
|
|
49
|
-
return isESM ? await
|
|
43
|
+
// It is important to await on import to catch the error code.
|
|
44
|
+
return isESM ? await import(url.pathToFileURL(filePath).href) : require(filePath);
|
|
50
45
|
}
|
|
51
46
|
catch (error) {
|
|
52
47
|
if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
|
|
@@ -77,7 +72,7 @@ class ModuleLoader {
|
|
|
77
72
|
let isESM;
|
|
78
73
|
try {
|
|
79
74
|
({ isESM, filePath } = ModuleLoader.resolvePath(config, modulePath));
|
|
80
|
-
const module = isESM ? await
|
|
75
|
+
const module = isESM ? await import(url.pathToFileURL(filePath).href) : require(filePath);
|
|
81
76
|
return { isESM, module, filePath };
|
|
82
77
|
}
|
|
83
78
|
catch (error) {
|