@node-red/registry 2.2.2 → 2.2.3

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.
@@ -11,6 +11,7 @@ const exec = require("@node-red/util").exec;
11
11
  const log = require("@node-red/util").log;
12
12
  const hooks = require("@node-red/util").hooks;
13
13
  const url = require("url");
14
+ const { createRequire } = require("module");
14
15
 
15
16
  const BUILTIN_MODULES = require('module').builtinModules;
16
17
 
@@ -139,10 +140,15 @@ function importModule(module) {
139
140
  }
140
141
  const externalModuleDir = getInstallDir();
141
142
  const moduleDir = path.join(externalModuleDir,"node_modules",module);
143
+ // To handle both CJS and ESM we need to resolve the module to the
144
+ // specific file that is loaded when the module is required/imported
145
+ // As this won't be on the natural module search path, we use createRequire
146
+ // to access the module
147
+ const modulePath = createRequire(moduleDir).resolve(module)
142
148
  // Import needs the full path to the module's main .js file
143
149
  // It also needs to be a file:// url for Windows
144
- const moduleFile = url.pathToFileURL(require.resolve(moduleDir));
145
- return import(moduleFile);
150
+ const moduleUrl = url.pathToFileURL(modulePath);
151
+ return import(moduleUrl);
146
152
  }
147
153
 
148
154
  function parseModuleName(module) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/registry",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./lib/index.js",
6
6
  "repository": {
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "dependencies": {
19
- "@node-red/util": "2.2.2",
19
+ "@node-red/util": "2.2.3",
20
20
  "clone": "2.1.2",
21
21
  "fs-extra": "10.0.0",
22
22
  "semver": "7.3.5",