@jcoreio/toolchain-esnext 3.6.0 → 3.6.2
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/package.json +3 -4
- package/util/resolveImportSource.cjs +17 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcoreio/toolchain-esnext",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2",
|
|
4
4
|
"description": "ESNext JS build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,13 +29,12 @@
|
|
|
29
29
|
"dedent-js": "^1.0.1",
|
|
30
30
|
"eslint": "^8.43.0",
|
|
31
31
|
"fs-extra": "^10.0.0",
|
|
32
|
-
"glob": "^7.2.0",
|
|
33
32
|
"resolve": "^1.22.2",
|
|
34
33
|
"resolve-bin": "^1.0.0",
|
|
35
|
-
"@jcoreio/toolchain": "3.6.
|
|
34
|
+
"@jcoreio/toolchain": "3.6.2"
|
|
36
35
|
},
|
|
37
36
|
"peerDependencies": {
|
|
38
|
-
"@jcoreio/toolchain": "3.6.
|
|
37
|
+
"@jcoreio/toolchain": "3.6.2"
|
|
39
38
|
},
|
|
40
39
|
"toolchainManaged": {
|
|
41
40
|
"dependencies": {
|
|
@@ -3,6 +3,7 @@ const _resolve = require('resolve')
|
|
|
3
3
|
const resolve = promisify(_resolve)
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const fs = require('fs-extra')
|
|
6
|
+
const builtinModules = new Set(require('module').builtinModules)
|
|
6
7
|
|
|
7
8
|
module.exports = async function resolveImportSource({ file, source }) {
|
|
8
9
|
const basedir = path.dirname(file)
|
|
@@ -19,17 +20,24 @@ module.exports = async function resolveImportSource({ file, source }) {
|
|
|
19
20
|
const result = path.relative(basedir, resolved)
|
|
20
21
|
return result.startsWith('.') ? result : `./${result}`
|
|
21
22
|
}
|
|
23
|
+
if (source.startsWith('node:') || builtinModules.has(source)) return source
|
|
22
24
|
const match = /^((?:@[^/]+\/)?[^/]+)(?:\/(.+))?$/.exec(source)
|
|
23
25
|
if (!match) return source
|
|
24
26
|
const [, pkg, subpath] = match
|
|
25
27
|
if (!subpath) return source
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
try {
|
|
29
|
+
const packageJsonFile = await resolve(`${pkg}/package.json`)
|
|
30
|
+
const packageJson = await fs.readJson(packageJsonFile)
|
|
31
|
+
const exportMap = packageJson ? packageJson.exports : undefined
|
|
32
|
+
if (exportMap && exportMap[`./${subpath}`]) return source
|
|
33
|
+
const resolved = await resolve(source, {
|
|
34
|
+
basedir,
|
|
35
|
+
extensions: [path.extname(file), '.mjs', '.cjs', '.js'],
|
|
36
|
+
})
|
|
37
|
+
return `${pkg}/${path.relative(path.dirname(packageJsonFile), resolved)}`
|
|
38
|
+
} catch (error) {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.error(`failed to resolve ${JSON.stringify(source)}`, error)
|
|
41
|
+
return source
|
|
42
|
+
}
|
|
35
43
|
}
|