@cspell/dynamic-import 7.0.0-alpha.1 → 7.0.0

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.
@@ -1,5 +1,6 @@
1
1
  import { sep as pathSep } from 'path';
2
2
  import { pathToFileURL } from 'url';
3
+ const isWindowsPath = /^[a-z]:\\/i;
3
4
  /**
4
5
  * Dynamically import a module using `import`.
5
6
  * @param moduleName - name of module, or relative path.
@@ -8,9 +9,10 @@ import { pathToFileURL } from 'url';
8
9
  */
9
10
  export async function dynamicImportFrom(moduleName, paths) {
10
11
  paths = Array.isArray(paths) ? paths : paths ? [paths] : undefined;
12
+ const modulesNameToImport = typeof moduleName === 'string' && isWindowsPath.test(moduleName) ? pathToFileURL(moduleName) : moduleName;
11
13
  if (!paths || !paths.length || typeof moduleName !== 'string') {
12
14
  try {
13
- return await import(moduleName.toString());
15
+ return await import(modulesNameToImport.toString());
14
16
  }
15
17
  catch (e) {
16
18
  // console.log('%o', e);
@@ -23,16 +25,20 @@ export async function dynamicImportFrom(moduleName, paths) {
23
25
  const { resolve } = importResolveModule;
24
26
  let lastError = undefined;
25
27
  for (const parent of paths) {
28
+ const url = typeof parent === 'string'
29
+ ? parent.startsWith('file://')
30
+ ? new URL(parent)
31
+ : pathToFileURL(parent + pathSep)
32
+ : parent;
33
+ let resolved = '';
34
+ let location = '';
26
35
  try {
27
- const url = typeof parent === 'string'
28
- ? parent.startsWith('file://')
29
- ? new URL(parent)
30
- : pathToFileURL(parent + pathSep)
31
- : parent;
32
- const location = await resolve(moduleName, url.toString());
36
+ resolved = resolve(modulesNameToImport.toString(), url.toString());
37
+ location = isWindowsPath.test(resolved) ? pathToFileURL(resolved).toString() : resolved;
33
38
  return await import(location);
34
39
  }
35
40
  catch (err) {
41
+ // console.warn('%o', { moduleName, modulesNameToImport, paths, parentUrl: url, err, resolved, location });
36
42
  lastError = err;
37
43
  }
38
44
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "7.0.0-alpha.1",
6
+ "version": "7.0.0",
7
7
  "description": "Dynamic Module Loader",
8
8
  "keywords": [
9
9
  "module",
@@ -57,7 +57,7 @@
57
57
  "node": ">=16"
58
58
  },
59
59
  "dependencies": {
60
- "import-meta-resolve": "^2.2.2"
60
+ "import-meta-resolve": "^3.0.0"
61
61
  },
62
- "gitHead": "626d1a01b413c1b6de0b386a5a264b78a10ba146"
62
+ "gitHead": "52960d5ed75655978f9b633f44fd106937a63cd7"
63
63
  }