@jcoreio/toolchain-esnext 3.6.1 → 3.6.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcoreio/toolchain-esnext",
3
- "version": "3.6.1",
3
+ "version": "3.6.3",
4
4
  "description": "ESNext JS build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,10 +31,10 @@
31
31
  "fs-extra": "^10.0.0",
32
32
  "resolve": "^1.22.2",
33
33
  "resolve-bin": "^1.0.0",
34
- "@jcoreio/toolchain": "3.6.1"
34
+ "@jcoreio/toolchain": "3.6.3"
35
35
  },
36
36
  "peerDependencies": {
37
- "@jcoreio/toolchain": "3.6.1"
37
+ "@jcoreio/toolchain": "3.6.3"
38
38
  },
39
39
  "toolchainManaged": {
40
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
- const packageJsonFile = await resolve(`${pkg}/package.json`)
27
- const packageJson = await fs.readJson(packageJsonFile)
28
- const exportMap = packageJson ? packageJson.exports : undefined
29
- if (exportMap && exportMap[`./${subpath}`]) return source
30
- const resolved = await resolve(source, {
31
- basedir,
32
- extensions: [path.extname(file), '.mjs', '.cjs', '.js'],
33
- })
34
- return `${pkg}/${path.relative(path.dirname(packageJsonFile), resolved)}`
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
  }