import-in-the-middle 1.14.4 → 2.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.
- package/CHANGELOG.md +20 -0
- package/{hook.js → create-hook.mjs} +10 -10
- package/hook.mjs +1 -1
- package/lib/{get-esm-exports.js → get-esm-exports.mjs} +3 -5
- package/lib/{get-exports.js → get-exports.mjs} +86 -9
- package/package.json +1 -1
- package/.editorconfig +0 -14
- package/.eslintrc.yaml +0 -26
- package/.release-please-manifest.json +0 -3
- package/release-please-config.json +0 -10
- package/test/README.md +0 -17
- package/test/check-exports/test.mjs +0 -317
- package/test/fixtures/a.mjs +0 -7
- package/test/fixtures/b.mjs +0 -5
- package/test/fixtures/bundle.mjs +0 -4
- package/test/fixtures/circular-a.js +0 -18
- package/test/fixtures/circular-a.mjs +0 -5
- package/test/fixtures/circular-b.js +0 -15
- package/test/fixtures/circular-b.mjs +0 -3
- package/test/fixtures/cyclical-a.mjs +0 -7
- package/test/fixtures/cyclical-b.mjs +0 -6
- package/test/fixtures/cyclical-self.mjs +0 -8
- package/test/fixtures/duplicate-a.mjs +0 -4
- package/test/fixtures/duplicate-b.mjs +0 -1
- package/test/fixtures/duplicate-c.mjs +0 -1
- package/test/fixtures/duplicate-explicit.mjs +0 -5
- package/test/fixtures/duplicate.mjs +0 -5
- package/test/fixtures/env.mjs +0 -8
- package/test/fixtures/esm-exports.txt +0 -32
- package/test/fixtures/executable +0 -6
- package/test/fixtures/export-types/declarations.mjs +0 -19
- package/test/fixtures/export-types/default-call-expression-renamed.mjs +0 -2
- package/test/fixtures/export-types/default-call-expression.mjs +0 -1
- package/test/fixtures/export-types/default-class-anon.mjs +0 -1
- package/test/fixtures/export-types/default-class.mjs +0 -1
- package/test/fixtures/export-types/default-expression-array.mjs +0 -1
- package/test/fixtures/export-types/default-expression-num.mjs +0 -1
- package/test/fixtures/export-types/default-expression-string.mjs +0 -1
- package/test/fixtures/export-types/default-function-anon.mjs +0 -1
- package/test/fixtures/export-types/default-function.mjs +0 -1
- package/test/fixtures/export-types/default-generator-anon.mjs +0 -1
- package/test/fixtures/export-types/default-generator.mjs +0 -1
- package/test/fixtures/export-types/fn-default-export.mjs +0 -3
- package/test/fixtures/export-types/import-default-export.mjs +0 -2
- package/test/fixtures/export-types/list.mjs +0 -12
- package/test/fixtures/export-types/variable-default-export.mjs +0 -5
- package/test/fixtures/foo.mjs +0 -5
- package/test/fixtures/got-alike.mjs +0 -11
- package/test/fixtures/import-absolute-after.mjs +0 -10
- package/test/fixtures/import-absolute.mjs +0 -18
- package/test/fixtures/import-after.mjs +0 -16
- package/test/fixtures/import.mjs +0 -23
- package/test/fixtures/index.js +0 -1
- package/test/fixtures/invalid-identifier.js +0 -8
- package/test/fixtures/json-attributes.mjs +0 -5
- package/test/fixtures/json.mjs +0 -9
- package/test/fixtures/lib/baz.mjs +0 -4
- package/test/fixtures/module-exports-cjs-shim.mjs +0 -7
- package/test/fixtures/native-modules/aix-ppc64.js +0 -2
- package/test/fixtures/native-modules/darwin-arm64.js +0 -1
- package/test/fixtures/native-modules/darwin-x64.js +0 -1
- package/test/fixtures/native-modules/linux-arm64.js +0 -1
- package/test/fixtures/native-modules/linux-ppc64.js +0 -2
- package/test/fixtures/native-modules/linux-s390x.js +0 -2
- package/test/fixtures/native-modules/linux-x64.js +0 -1
- package/test/fixtures/native-modules/win32-arm64.js +0 -1
- package/test/fixtures/native-modules/win32-x64.js +0 -1
- package/test/fixtures/re-export-cjs-built-in.js +0 -1
- package/test/fixtures/re-export-cjs-json.js +0 -1
- package/test/fixtures/re-export-cjs.js +0 -1
- package/test/fixtures/re-export-star-external.mjs +0 -1
- package/test/fixtures/reexport.js +0 -15
- package/test/fixtures/require-root.js +0 -1
- package/test/fixtures/say-hi.mts +0 -3
- package/test/fixtures/something.js +0 -10
- package/test/fixtures/something.json +0 -3
- package/test/fixtures/something.mjs +0 -9
- package/test/fixtures/something.mts +0 -7
- package/test/fixtures/sub-directory/re-export-star-external.mjs +0 -1
- package/test/generic-loader.mjs +0 -14
- package/test/get-esm-exports/v18.19-get-esm-exports.js +0 -3
- package/test/get-esm-exports/v20-get-esm-exports.js +0 -31
- package/test/hook/circular-imports.mjs +0 -11
- package/test/hook/cyclical-self.mjs +0 -4
- package/test/hook/default-export.mjs +0 -86
- package/test/hook/define-property.js +0 -20
- package/test/hook/duplicate-exports-explicit.mjs +0 -13
- package/test/hook/duplicate-exports.mjs +0 -19
- package/test/hook/dynamic-import-default.js +0 -29
- package/test/hook/dynamic-import-default.mjs +0 -23
- package/test/hook/dynamic-import.js +0 -27
- package/test/hook/dynamic-import.mjs +0 -27
- package/test/hook/import-reexport-cjs.mjs +0 -11
- package/test/hook/loader.mjs +0 -5
- package/test/hook/module-toStringTag.mjs +0 -25
- package/test/hook/re-export-cjs.mjs +0 -26
- package/test/hook/re-export-star-module.mjs +0 -17
- package/test/hook/remove.mjs +0 -23
- package/test/hook/require-root-cjs.mjs +0 -12
- package/test/hook/static-import-default.mjs +0 -26
- package/test/hook/static-import-disabled.mjs +0 -15
- package/test/hook/static-import-package-internals-enabled.mjs +0 -15
- package/test/hook/static-import-package-internals.mjs +0 -15
- package/test/hook/static-import-package.mjs +0 -15
- package/test/hook/static-import-star.mjs +0 -34
- package/test/hook/static-import.mjs +0 -24
- package/test/hook/v14-date-fns.mjs +0 -10
- package/test/hook/v14-declaration-exports.mjs +0 -84
- package/test/hook/v14-double-hook.mjs +0 -33
- package/test/hook/v14-native-modules.mjs +0 -10
- package/test/hook/v14-react-email-components.mjs +0 -16
- package/test/hook/v16-fake-cjs-export.mjs +0 -4
- package/test/hook/v16-got.mjs +0 -16
- package/test/hook/v16-invalid-identifier.mjs +0 -5
- package/test/hook/v18-v21-static-import-assert.mjs +0 -15
- package/test/hook/v18.19-openai.mjs +0 -16
- package/test/hook/v18.19-static-import-gotalike.mjs +0 -26
- package/test/hook/v20.10-static-import-attributes.mjs +0 -15
- package/test/hook/v24-typescript.mjs +0 -8
- package/test/hook/vue-server-renderer.mjs +0 -8
- package/test/low-level/dynamic-import-default.js +0 -23
- package/test/low-level/dynamic-import-default.mjs +0 -23
- package/test/low-level/dynamic-import.js +0 -27
- package/test/low-level/remove.mjs +0 -25
- package/test/low-level/sanitized-url.mjs +0 -11
- package/test/low-level/static-import-default.mjs +0 -20
- package/test/low-level/static-import-disabled.mjs +0 -15
- package/test/low-level/static-import.mjs +0 -24
- package/test/multiple-loaders/multiple-loaders.test.mjs +0 -6
- package/test/multiple-loaders/typescript-loader.mjs +0 -26
- package/test/other/v14-assert-cyclical-dependency-failure.mjs +0 -36
- package/test/other/v20.10-import-executable.mjs +0 -8
- package/test/register/v18.19-circular.mjs +0 -17
- package/test/register/v18.19-exclude-regex.mjs +0 -16
- package/test/register/v18.19-exclude.mjs +0 -15
- package/test/register/v18.19-experimental-patch-internals.mjs +0 -14
- package/test/register/v18.19-include-builtin.mjs +0 -20
- package/test/register/v18.19-include-message-port-absolute-path.mjs +0 -14
- package/test/register/v18.19-include-message-port.mjs +0 -14
- package/test/register/v18.19-include.mjs +0 -16
- package/test/typescript/iitm-ts-node-loader.mjs +0 -18
- package/test/typescript/ts-node.test.mts +0 -19
- package/test/version-check.js +0 -33
- package/tsconfig.json +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.0](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.15.0...import-in-the-middle-v2.0.0) (2025-10-14)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
Converting all modules running in the loader thread to ESM should not be a
|
|
9
|
+
breaking change for most users since it primarily affects internal implementation
|
|
10
|
+
details. However, if you were referencing internal CJS files like `hook.js` this will no longer work.
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* convert all modules running in loader thread to ESM ([#210](https://github.com/nodejs/import-in-the-middle/issues/210)) ([da7c7a6](https://github.com/nodejs/import-in-the-middle/commit/da7c7a6904a40bf394b7b2a271a2838711c5417c))
|
|
15
|
+
|
|
16
|
+
## [1.15.0](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.14.4...import-in-the-middle-v1.15.0) (2025-10-09)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* Compatibility with specifier imports ([#211](https://github.com/nodejs/import-in-the-middle/issues/211)) ([83d662a](https://github.com/nodejs/import-in-the-middle/commit/83d662a8e1f9a7b8632bc78f7499ccc0ab4d12c2))
|
|
22
|
+
|
|
3
23
|
## [1.14.4](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.14.3...import-in-the-middle-v1.14.4) (2025-09-25)
|
|
4
24
|
|
|
5
25
|
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
//
|
|
3
3
|
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { URL, fileURLToPath } from 'url'
|
|
6
|
+
import { inspect } from 'util'
|
|
7
|
+
import { builtinModules } from 'module'
|
|
8
|
+
import { getExports as getExportsImpl } from './lib/get-exports.mjs'
|
|
9
|
+
|
|
8
10
|
const specifiers = new Map()
|
|
9
11
|
const isWin = process.platform === 'win32'
|
|
10
12
|
let experimentalPatchInternals = false
|
|
@@ -17,15 +19,15 @@ const NODE_MAJOR = Number(NODE_VERSION[0])
|
|
|
17
19
|
const NODE_MINOR = Number(NODE_VERSION[1])
|
|
18
20
|
const HANDLED_FORMATS = new Set(['builtin', 'module', 'commonjs'])
|
|
19
21
|
|
|
20
|
-
let entrypoint
|
|
21
|
-
|
|
22
22
|
let getExports
|
|
23
23
|
if (NODE_MAJOR >= 20 || (NODE_MAJOR === 18 && NODE_MINOR >= 19)) {
|
|
24
|
-
getExports =
|
|
24
|
+
getExports = getExportsImpl
|
|
25
25
|
} else {
|
|
26
26
|
getExports = (url) => import(url).then(Object.keys)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
let entrypoint
|
|
30
|
+
|
|
29
31
|
function hasIitm (url) {
|
|
30
32
|
try {
|
|
31
33
|
return new URL(url).searchParams.has('iitm')
|
|
@@ -35,7 +37,7 @@ function hasIitm (url) {
|
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
function isIitm (url, meta) {
|
|
38
|
-
return url === meta.url || url === meta.url.replace('hook.mjs', 'hook.
|
|
40
|
+
return url === meta.url || url === meta.url.replace('hook.mjs', 'create-hook.mjs')
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
function deleteIitm (url) {
|
|
@@ -284,7 +286,7 @@ function addIitm (url) {
|
|
|
284
286
|
return needsToAddFileProtocol(urlObj) ? 'file:' + urlObj.href : urlObj.href
|
|
285
287
|
}
|
|
286
288
|
|
|
287
|
-
function createHook (meta) {
|
|
289
|
+
export function createHook (meta) {
|
|
288
290
|
let cachedResolve
|
|
289
291
|
const iitmURL = new URL('lib/register.js', meta.url).toString()
|
|
290
292
|
let includeModules, excludeModules
|
|
@@ -494,5 +496,3 @@ register(${JSON.stringify(realUrl)}, _, set, get, ${JSON.stringify(specifiers.ge
|
|
|
494
496
|
}
|
|
495
497
|
}
|
|
496
498
|
}
|
|
497
|
-
|
|
498
|
-
module.exports = { createHook }
|
package/hook.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
4
4
|
|
|
5
|
-
import { createHook } from './hook.
|
|
5
|
+
import { createHook } from './create-hook.mjs'
|
|
6
6
|
|
|
7
7
|
const { initialize, load, resolve, getFormat, getSource } = createHook(import.meta)
|
|
8
8
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { Parser } from 'acorn'
|
|
4
|
+
import { importAttributesOrAssertions } from 'acorn-import-attributes'
|
|
5
5
|
|
|
6
6
|
const acornOpts = {
|
|
7
7
|
ecmaVersion: 'latest',
|
|
@@ -32,7 +32,7 @@ function warn (txt) {
|
|
|
32
32
|
* @returns {Set<string>} The identifiers exported by the module along with any
|
|
33
33
|
* custom directives.
|
|
34
34
|
*/
|
|
35
|
-
function getEsmExports (moduleSource) {
|
|
35
|
+
export default function getEsmExports (moduleSource) {
|
|
36
36
|
const exportedNames = new Set()
|
|
37
37
|
const tree = parser.parse(moduleSource, acornOpts)
|
|
38
38
|
for (const node of tree.body) {
|
|
@@ -114,5 +114,3 @@ function parseSpecifiers (node, exportedNames) {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
module.exports = getEsmExports
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import getEsmExports from './get-esm-exports.mjs'
|
|
4
|
+
import { parse as parseCjs, init as parserInit } from 'cjs-module-lexer'
|
|
5
|
+
import { readFileSync, existsSync } from 'fs'
|
|
6
|
+
import { builtinModules, createRequire } from 'module'
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'url'
|
|
8
|
+
import { dirname, join } from 'path'
|
|
9
|
+
|
|
10
|
+
let parserInitialized = false
|
|
9
11
|
|
|
10
12
|
function addDefault (arr) {
|
|
11
13
|
return new Set(['default', ...arr])
|
|
@@ -14,9 +16,15 @@ function addDefault (arr) {
|
|
|
14
16
|
// Cached exports for Node built-in modules
|
|
15
17
|
const BUILT_INS = new Map()
|
|
16
18
|
|
|
19
|
+
let require
|
|
20
|
+
|
|
17
21
|
function getExportsForNodeBuiltIn (name) {
|
|
18
22
|
let exports = BUILT_INS.get()
|
|
19
23
|
|
|
24
|
+
if (!require) {
|
|
25
|
+
require = createRequire(import.meta.url)
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
if (!exports) {
|
|
21
29
|
exports = new Set(addDefault(Object.keys(require(name))))
|
|
22
30
|
BUILT_INS.set(name, exports)
|
|
@@ -27,6 +35,62 @@ function getExportsForNodeBuiltIn (name) {
|
|
|
27
35
|
|
|
28
36
|
const urlsBeingProcessed = new Set() // Guard against circular imports.
|
|
29
37
|
|
|
38
|
+
/**
|
|
39
|
+
* This function looks for the package.json which contains the specifier trying to resolve.
|
|
40
|
+
* Once the package.json file has been found, we extract the file path from the specifier
|
|
41
|
+
* @param {string} specifier The specifier that is being search for inside the imports object
|
|
42
|
+
* @param {URL|string} fromUrl The url from which the search starts from
|
|
43
|
+
* @returns array with url and resolvedExport
|
|
44
|
+
*/
|
|
45
|
+
function resolvePackageImports (specifier, fromUrl) {
|
|
46
|
+
try {
|
|
47
|
+
const fromPath = fileURLToPath(fromUrl)
|
|
48
|
+
let currentDir = dirname(fromPath)
|
|
49
|
+
|
|
50
|
+
// search for package.json file which has the real url to export
|
|
51
|
+
while (currentDir !== dirname(currentDir)) {
|
|
52
|
+
const packageJsonPath = join(currentDir, 'package.json')
|
|
53
|
+
|
|
54
|
+
if (existsSync(packageJsonPath)) {
|
|
55
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
|
56
|
+
if (packageJson.imports && packageJson.imports[specifier]) {
|
|
57
|
+
const imports = packageJson.imports[specifier]
|
|
58
|
+
|
|
59
|
+
// Look for path inside packageJson
|
|
60
|
+
let resolvedExport
|
|
61
|
+
if (imports && typeof imports === 'object') {
|
|
62
|
+
const requireExport = imports.require
|
|
63
|
+
const importExport = imports.import
|
|
64
|
+
// look for the possibility of require and import which is standard for CJS/ESM
|
|
65
|
+
if (requireExport || importExport) {
|
|
66
|
+
// trying to resolve based on order of importance
|
|
67
|
+
resolvedExport = requireExport.node || requireExport.default || importExport.node || importExport.default
|
|
68
|
+
} else if (imports.node || imports.default) {
|
|
69
|
+
resolvedExport = imports.node || imports.default
|
|
70
|
+
}
|
|
71
|
+
} else if (typeof imports === 'string') {
|
|
72
|
+
resolvedExport = imports
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (resolvedExport) {
|
|
76
|
+
const url = resolvedExport.startsWith('.')
|
|
77
|
+
? pathToFileURL(join(currentDir, resolvedExport))
|
|
78
|
+
: fromUrl
|
|
79
|
+
return [url, resolvedExport]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// return if we find a package.json but did not find an import
|
|
83
|
+
return null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
currentDir = dirname(currentDir)
|
|
87
|
+
}
|
|
88
|
+
} catch (cause) {
|
|
89
|
+
throw Error(`Failed to find export: ${specifier}`, { cause })
|
|
90
|
+
}
|
|
91
|
+
return null
|
|
92
|
+
}
|
|
93
|
+
|
|
30
94
|
async function getCjsExports (url, context, parentLoad, source) {
|
|
31
95
|
if (urlsBeingProcessed.has(url)) {
|
|
32
96
|
return []
|
|
@@ -34,6 +98,10 @@ async function getCjsExports (url, context, parentLoad, source) {
|
|
|
34
98
|
urlsBeingProcessed.add(url)
|
|
35
99
|
|
|
36
100
|
try {
|
|
101
|
+
if (!parserInitialized) {
|
|
102
|
+
await parserInit()
|
|
103
|
+
parserInitialized = true
|
|
104
|
+
}
|
|
37
105
|
const result = parseCjs(source)
|
|
38
106
|
const full = addDefault(result.exports)
|
|
39
107
|
|
|
@@ -46,7 +114,18 @@ async function getCjsExports (url, context, parentLoad, source) {
|
|
|
46
114
|
if (re === '.') {
|
|
47
115
|
re = './'
|
|
48
116
|
}
|
|
117
|
+
|
|
118
|
+
// Entries in the import field should always start with #
|
|
119
|
+
if (re.startsWith('#')) {
|
|
120
|
+
const resolved = resolvePackageImports(re, url)
|
|
121
|
+
if (!resolved) return
|
|
122
|
+
[url, re] = resolved
|
|
123
|
+
}
|
|
124
|
+
|
|
49
125
|
// Resolve the re-exported module relative to the current module.
|
|
126
|
+
if (!require) {
|
|
127
|
+
require = createRequire(import.meta.url)
|
|
128
|
+
}
|
|
50
129
|
const newUrl = pathToFileURL(require.resolve(re, { paths: [dirname(fileURLToPath(url))] })).href
|
|
51
130
|
|
|
52
131
|
if (newUrl.endsWith('.node') || newUrl.endsWith('.json')) {
|
|
@@ -81,7 +160,7 @@ async function getCjsExports (url, context, parentLoad, source) {
|
|
|
81
160
|
* Please see {@link getEsmExports} for caveats on special identifiers that may
|
|
82
161
|
* be included in the result set.
|
|
83
162
|
*/
|
|
84
|
-
async function getExports (url, context, parentLoad) {
|
|
163
|
+
export async function getExports (url, context, parentLoad) {
|
|
85
164
|
// `parentLoad` gives us the possibility of getting the source
|
|
86
165
|
// from an upstream loader. This doesn't always work though,
|
|
87
166
|
// so later on we fall back to reading it from disk.
|
|
@@ -125,5 +204,3 @@ async function getExports (url, context, parentLoad) {
|
|
|
125
204
|
throw err
|
|
126
205
|
}
|
|
127
206
|
}
|
|
128
|
-
|
|
129
|
-
module.exports = getExports
|
package/package.json
CHANGED
package/.editorconfig
DELETED
package/.eslintrc.yaml
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
overrides:
|
|
2
|
-
- files:
|
|
3
|
-
- '**/*.{js,cjs,mjs}'
|
|
4
|
-
|
|
5
|
-
parser: '@babel/eslint-parser'
|
|
6
|
-
parserOptions:
|
|
7
|
-
ecmaVersion: latest
|
|
8
|
-
requireConfigFile: false
|
|
9
|
-
sourceType: 'script'
|
|
10
|
-
babelOptions:
|
|
11
|
-
plugins:
|
|
12
|
-
- '@babel/plugin-syntax-import-assertions'
|
|
13
|
-
|
|
14
|
-
rules:
|
|
15
|
-
"import/first": off
|
|
16
|
-
|
|
17
|
-
extends:
|
|
18
|
-
- "standard"
|
|
19
|
-
|
|
20
|
-
ignorePatterns:
|
|
21
|
-
- test/fixtures/circular-a.js
|
|
22
|
-
- test/fixtures/circular-b.js
|
|
23
|
-
- test/fixtures/reexport.js
|
|
24
|
-
- test/fixtures/duplicate-explicit.mjs
|
|
25
|
-
- test/fixtures/duplicate.mjs
|
|
26
|
-
- test/fixtures/export-types/default-call-expression-renamed.mjs
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
|
|
3
|
-
"bootstrap-sha": "57d2459748492abd55e04a679d8b5752b90dfab4",
|
|
4
|
-
"packages": {
|
|
5
|
-
".": {
|
|
6
|
-
"pull-request-title-pattern": "chore: release v${version}",
|
|
7
|
-
"release-type": "node"
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
package/test/README.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
These tests are organized as follows:
|
|
2
|
-
|
|
3
|
-
* Located in the `hook` directory if they use the `Hook` class.
|
|
4
|
-
* Located in the `low-level` directory if they use the "low-level" API,
|
|
5
|
-
`addHook` and `removeHook`.
|
|
6
|
-
* Other tests are in other adjacent directories.
|
|
7
|
-
|
|
8
|
-
The tests can be run individually as Node.js programs with non-zero exit codes
|
|
9
|
-
upon failures. They should be run with the following Node.js command-line
|
|
10
|
-
options (assuming they're run from the project root):
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
--require ./test/version-check.js
|
|
14
|
-
--experimental-loader ./test/generic-loader.mjs
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
The entire test suite can be run with `npm test`.
|
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'child_process'
|
|
2
|
-
import { deepStrictEqual } from 'assert'
|
|
3
|
-
import { dirname, resolve } from 'path'
|
|
4
|
-
import { fileURLToPath } from 'url'
|
|
5
|
-
|
|
6
|
-
const cwd = dirname(fileURLToPath(import.meta.url))
|
|
7
|
-
const hook = resolve(cwd, '..', '..', 'hook.mjs')
|
|
8
|
-
|
|
9
|
-
const mostPopular240NpmModules = [
|
|
10
|
-
'ansi-styles',
|
|
11
|
-
'semver',
|
|
12
|
-
'supports-color',
|
|
13
|
-
'chalk', 'has-flag',
|
|
14
|
-
'debug',
|
|
15
|
-
'tslib',
|
|
16
|
-
'color-convert',
|
|
17
|
-
'ms',
|
|
18
|
-
'color-name',
|
|
19
|
-
'lru-cache',
|
|
20
|
-
'minimatch',
|
|
21
|
-
'strip-ansi',
|
|
22
|
-
'source-map',
|
|
23
|
-
'ansi-regex',
|
|
24
|
-
'glob',
|
|
25
|
-
'readable-stream',
|
|
26
|
-
'commander',
|
|
27
|
-
'yallist',
|
|
28
|
-
'string-width',
|
|
29
|
-
'escape-string-regexp',
|
|
30
|
-
'brace-expansion',
|
|
31
|
-
'find-up',
|
|
32
|
-
'p-locate',
|
|
33
|
-
'locate-path',
|
|
34
|
-
'wrap-ansi',
|
|
35
|
-
'p-limit',
|
|
36
|
-
'safe-buffer',
|
|
37
|
-
'kind-of',
|
|
38
|
-
'minipass',
|
|
39
|
-
'uuid',
|
|
40
|
-
'string_decoder',
|
|
41
|
-
'ajv',
|
|
42
|
-
'emoji-regex',
|
|
43
|
-
'isarray',
|
|
44
|
-
'react-is',
|
|
45
|
-
'fs-extra',
|
|
46
|
-
'is-fullwidth-code-point',
|
|
47
|
-
'get-stream',
|
|
48
|
-
'json-schema-traverse',
|
|
49
|
-
'yargs-parser',
|
|
50
|
-
'glob-parent',
|
|
51
|
-
'yargs',
|
|
52
|
-
'rimraf',
|
|
53
|
-
'acorn',
|
|
54
|
-
'which',
|
|
55
|
-
'estraverse',
|
|
56
|
-
'js-yaml',
|
|
57
|
-
'path-exists',
|
|
58
|
-
'argparse',
|
|
59
|
-
'pretty-format',
|
|
60
|
-
'resolve-from',
|
|
61
|
-
'cliui',
|
|
62
|
-
'schema-utils',
|
|
63
|
-
'globals',
|
|
64
|
-
'camelcase',
|
|
65
|
-
'execa',
|
|
66
|
-
'punycode',
|
|
67
|
-
'path-key',
|
|
68
|
-
'signal-exit',
|
|
69
|
-
'inherits',
|
|
70
|
-
'resolve',
|
|
71
|
-
'mkdirp',
|
|
72
|
-
'is-stream',
|
|
73
|
-
'ws',
|
|
74
|
-
'universalify',
|
|
75
|
-
'qs',
|
|
76
|
-
'slash',
|
|
77
|
-
'json5',
|
|
78
|
-
'iconv-lite',
|
|
79
|
-
'form-data',
|
|
80
|
-
'is-number',
|
|
81
|
-
'eslint-visitor-keys',
|
|
82
|
-
'@jest/types',
|
|
83
|
-
'postcss',
|
|
84
|
-
'make-dir',
|
|
85
|
-
'pify',
|
|
86
|
-
'cross-spawn',
|
|
87
|
-
'braces',
|
|
88
|
-
'whatwg-url',
|
|
89
|
-
'fill-range',
|
|
90
|
-
'eslint-scope',
|
|
91
|
-
'tr46',
|
|
92
|
-
'micromatch',
|
|
93
|
-
'convert-source-map',
|
|
94
|
-
'define-property',
|
|
95
|
-
'agent-base',
|
|
96
|
-
'shebang-regex',
|
|
97
|
-
'shebang-command',
|
|
98
|
-
'mimic-fn',
|
|
99
|
-
'globby',
|
|
100
|
-
'npm-run-path',
|
|
101
|
-
'mime',
|
|
102
|
-
'@babel/code-frame',
|
|
103
|
-
'extend-shallow',
|
|
104
|
-
'to-regex-range',
|
|
105
|
-
'onetime',
|
|
106
|
-
'https-proxy-agent',
|
|
107
|
-
'y18n',
|
|
108
|
-
'buffer',
|
|
109
|
-
'strip-bom',
|
|
110
|
-
'is-glob',
|
|
111
|
-
'doctrine',
|
|
112
|
-
'picocolors',
|
|
113
|
-
'pkg-dir',
|
|
114
|
-
'@babel/types',
|
|
115
|
-
'regenerator-runtime',
|
|
116
|
-
'human-signals',
|
|
117
|
-
'@jridgewell/trace-mapping',
|
|
118
|
-
'ignore',
|
|
119
|
-
'jsesc',
|
|
120
|
-
'parse-json',
|
|
121
|
-
'jest-worker',
|
|
122
|
-
'graceful-fs',
|
|
123
|
-
'jest-util',
|
|
124
|
-
'jsonfile',
|
|
125
|
-
'normalize-path',
|
|
126
|
-
'strip-json-comments',
|
|
127
|
-
'cosmiconfig',
|
|
128
|
-
'minimist',
|
|
129
|
-
'path-type',
|
|
130
|
-
'@babel/parser',
|
|
131
|
-
'balanced-match',
|
|
132
|
-
'picomatch',
|
|
133
|
-
'typescript',
|
|
134
|
-
'isexe',
|
|
135
|
-
'statuses',
|
|
136
|
-
'entities',
|
|
137
|
-
'bytes',
|
|
138
|
-
'node-fetch',
|
|
139
|
-
'http-errors',
|
|
140
|
-
'@babel/highlight',
|
|
141
|
-
'@babel/helper-validator-identifier',
|
|
142
|
-
'function-bind',
|
|
143
|
-
'async',
|
|
144
|
-
'sprintf-js',
|
|
145
|
-
'@babel/generator',
|
|
146
|
-
'is-extendable',
|
|
147
|
-
'get-intrinsic',
|
|
148
|
-
'lodash',
|
|
149
|
-
'mime-db',
|
|
150
|
-
'source-map-support',
|
|
151
|
-
'mime-types',
|
|
152
|
-
'is-arrayish',
|
|
153
|
-
'@babel/core',
|
|
154
|
-
'once',
|
|
155
|
-
'anymatch',
|
|
156
|
-
'depd',
|
|
157
|
-
'hosted-git-info',
|
|
158
|
-
'path-to-regexp',
|
|
159
|
-
'axios',
|
|
160
|
-
'is-core-module',
|
|
161
|
-
'@babel/template',
|
|
162
|
-
'cookie',
|
|
163
|
-
'write-file-atomic',
|
|
164
|
-
'js-tokens',
|
|
165
|
-
'@typescript-eslint/typescript-estree',
|
|
166
|
-
'@typescript-eslint/types',
|
|
167
|
-
'object-inspect',
|
|
168
|
-
'wrappy',
|
|
169
|
-
'is-extglob',
|
|
170
|
-
'chokidar',
|
|
171
|
-
'@typescript-eslint/visitor-keys',
|
|
172
|
-
'call-bind',
|
|
173
|
-
'loader-utils',
|
|
174
|
-
'browserslist',
|
|
175
|
-
'http-proxy-agent',
|
|
176
|
-
'fast-glob',
|
|
177
|
-
'concat-map',
|
|
178
|
-
'inflight',
|
|
179
|
-
'ajv-keywords',
|
|
180
|
-
'ansi-escapes',
|
|
181
|
-
'ci-info',
|
|
182
|
-
'fast-deep-equal',
|
|
183
|
-
'caniuse-lite',
|
|
184
|
-
'fs.realpath',
|
|
185
|
-
'@jridgewell/gen-mapping',
|
|
186
|
-
'setprototypeof',
|
|
187
|
-
'strip-final-newline',
|
|
188
|
-
'optionator',
|
|
189
|
-
'path-is-absolute',
|
|
190
|
-
'@babel/traverse',
|
|
191
|
-
'core-util-is',
|
|
192
|
-
'has-symbols',
|
|
193
|
-
'yocto-queue',
|
|
194
|
-
'p-try',
|
|
195
|
-
'electron-to-chromium',
|
|
196
|
-
'@smithy/smithy-client',
|
|
197
|
-
'yaml',
|
|
198
|
-
'ini',
|
|
199
|
-
'@babel/helper-plugin-utils',
|
|
200
|
-
'jest-get-type',
|
|
201
|
-
'type-check',
|
|
202
|
-
'levn',
|
|
203
|
-
'is-descriptor',
|
|
204
|
-
'prelude-ls',
|
|
205
|
-
'slice-ansi',
|
|
206
|
-
'@typescript-eslint/scope-manager',
|
|
207
|
-
'isobject',
|
|
208
|
-
'esprima',
|
|
209
|
-
'@babel/helper-split-export-declaration',
|
|
210
|
-
'callsites',
|
|
211
|
-
'readdirp',
|
|
212
|
-
'escalade',
|
|
213
|
-
'import-fresh',
|
|
214
|
-
'get-caller-file',
|
|
215
|
-
'@jridgewell/sourcemap-codec',
|
|
216
|
-
'acorn-walk',
|
|
217
|
-
'rxjs',
|
|
218
|
-
'ieee754',
|
|
219
|
-
'is-plain-obj',
|
|
220
|
-
'istanbul-lib-instrument',
|
|
221
|
-
'@babel/helper-module-imports',
|
|
222
|
-
'side-channel',
|
|
223
|
-
'normalize-package-data',
|
|
224
|
-
'is-plain-object',
|
|
225
|
-
'@jridgewell/resolve-uri',
|
|
226
|
-
'follow-redirects',
|
|
227
|
-
'array-union',
|
|
228
|
-
'json-parse-even-better-errors',
|
|
229
|
-
'path-parse',
|
|
230
|
-
'has-property-descriptors',
|
|
231
|
-
'uri-js',
|
|
232
|
-
'safer-buffer',
|
|
233
|
-
'@babel/helpers',
|
|
234
|
-
'on-finished',
|
|
235
|
-
'@babel/helper-function-name',
|
|
236
|
-
'p-map',
|
|
237
|
-
'postcss-value-parser',
|
|
238
|
-
'indent-string',
|
|
239
|
-
'@babel/helper-module-transforms',
|
|
240
|
-
'object-assign',
|
|
241
|
-
'delayed-stream',
|
|
242
|
-
'@nodelib/fs.stat',
|
|
243
|
-
'require-directory',
|
|
244
|
-
'diff',
|
|
245
|
-
'parse5',
|
|
246
|
-
'asynckit',
|
|
247
|
-
'tmp',
|
|
248
|
-
'combined-stream'
|
|
249
|
-
]
|
|
250
|
-
|
|
251
|
-
const otherCommonModulesUsedWithInstrumentation = [
|
|
252
|
-
'express',
|
|
253
|
-
'fastify',
|
|
254
|
-
'@hapi/hapi',
|
|
255
|
-
'connect',
|
|
256
|
-
'svelte',
|
|
257
|
-
'@sveltejs/kit',
|
|
258
|
-
'next',
|
|
259
|
-
'gatsby',
|
|
260
|
-
'@remix-run/node',
|
|
261
|
-
'@remix-run/react'
|
|
262
|
-
]
|
|
263
|
-
|
|
264
|
-
const modules = [...mostPopular240NpmModules, ...otherCommonModulesUsedWithInstrumentation]
|
|
265
|
-
|
|
266
|
-
function installLibs (names) {
|
|
267
|
-
spawnSync('npm', ['init', '-y'], { cwd })
|
|
268
|
-
spawnSync('npm', ['install', ...names], { cwd })
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function getExports (name, loader) {
|
|
272
|
-
const args = ['--input-type=module', '--no-warnings', '-e', `import * as lib from '${name}'; console.log(JSON.stringify(Object.keys(lib)))`]
|
|
273
|
-
if (loader) args.push(loader)
|
|
274
|
-
const out = spawnSync(process.execPath, args, { cwd })
|
|
275
|
-
if (out.status !== 0) {
|
|
276
|
-
console.error(out.stderr.toString())
|
|
277
|
-
throw new Error(`Getting exports returned non-zero exit code '${name}'`)
|
|
278
|
-
}
|
|
279
|
-
const stdout = out.stdout.toString()
|
|
280
|
-
return JSON.parse(stdout).sort()
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const NPM_LIST_SEMVER_PARSE = /└──.*@((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/
|
|
284
|
-
|
|
285
|
-
function getVersion (name) {
|
|
286
|
-
const result = spawnSync('npm', ['list', name, '--depth', '0'], { cwd })
|
|
287
|
-
const stdout = result.output.toString()
|
|
288
|
-
const [, version] = stdout.match(NPM_LIST_SEMVER_PARSE)
|
|
289
|
-
return version
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function testLib (name) {
|
|
293
|
-
const version = getVersion(name)
|
|
294
|
-
try {
|
|
295
|
-
const expected = getExports(name)
|
|
296
|
-
const actual = getExports(name, `--experimental-loader=${hook}`)
|
|
297
|
-
deepStrictEqual(actual, expected, `Exports for ${name} are different`)
|
|
298
|
-
console.log(`✅ Exports for ${name}@${version} match`)
|
|
299
|
-
return false
|
|
300
|
-
} catch (err) {
|
|
301
|
-
console.error(`❌ Error getting exports for ${name}@${version}:`, err)
|
|
302
|
-
return true
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
console.log(`📦 Installing ${modules.length} libraries...`)
|
|
307
|
-
installLibs(modules)
|
|
308
|
-
|
|
309
|
-
let errored = false
|
|
310
|
-
for (const mod of modules) {
|
|
311
|
-
errored += testLib(mod)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (errored) {
|
|
315
|
-
console.error('❌ Some tests failed')
|
|
316
|
-
process.exit(1)
|
|
317
|
-
}
|
package/test/fixtures/a.mjs
DELETED
package/test/fixtures/b.mjs
DELETED
package/test/fixtures/bundle.mjs
DELETED