import-in-the-middle 1.7.2 → 1.7.4
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/.eslintrc.yaml +23 -0
- package/fix.patch +52 -0
- package/hook.js +142 -30
- package/index.js +4 -4
- package/lib/get-esm-exports.js +47 -5
- package/lib/get-exports.js +54 -7
- package/lib/register.js +3 -4
- package/package.json +20 -5
- package/test/README.md +9 -5
- package/test/fixtures/a.mjs +1 -1
- package/test/fixtures/b.mjs +1 -1
- package/test/fixtures/circular-a.js +18 -0
- package/test/fixtures/circular-b.js +15 -0
- package/test/fixtures/cyclical-a.mjs +7 -0
- package/test/fixtures/cyclical-b.mjs +6 -0
- package/test/fixtures/default-class.mjs +3 -0
- package/test/fixtures/env.mjs +8 -0
- package/test/fixtures/export-types/declarations.mjs +19 -0
- package/test/fixtures/export-types/default-class-anon.mjs +1 -0
- package/test/fixtures/export-types/default-class.mjs +1 -0
- package/test/fixtures/export-types/default-expression-array.mjs +1 -0
- package/test/fixtures/export-types/default-expression-num.mjs +1 -0
- package/test/fixtures/export-types/default-expression-string.mjs +1 -0
- package/test/fixtures/export-types/default-function-anon.mjs +1 -0
- package/test/fixtures/export-types/default-function.mjs +1 -0
- package/test/fixtures/export-types/default-generator-anon.mjs +1 -0
- package/test/fixtures/export-types/default-generator.mjs +1 -0
- package/test/fixtures/export-types/fn-default-export.mjs +3 -0
- package/test/fixtures/export-types/import-default-export.mjs +2 -0
- package/test/fixtures/export-types/list.mjs +12 -0
- package/test/fixtures/export-types/variable-default-export.mjs +5 -0
- package/test/fixtures/foo.mjs +1 -1
- package/test/fixtures/got-alike.mjs +17 -0
- package/test/fixtures/json.mjs +2 -2
- package/test/fixtures/lib/baz.mjs +2 -1
- package/test/fixtures/reexport.js +15 -0
- package/test/fixtures/snake_case.mjs +2 -0
- package/test/fixtures/something.js +1 -1
- package/test/generic-loader.mjs +14 -0
- package/test/get-esm-exports/v20-get-esm-exports.js +1 -1
- package/test/hook/circular-imports.mjs +11 -0
- package/test/hook/default-export.mjs +78 -0
- package/test/hook/dynamic-import-default.js +2 -2
- package/test/hook/dynamic-import-default.mjs +1 -1
- package/test/hook/import-reexport-cjs.mjs +11 -0
- package/test/hook/module-toStringTag.mjs +25 -0
- package/test/hook/static-import-default.mjs +2 -2
- package/test/hook/static-import-package-internals-enabled.mjs +1 -1
- package/test/hook/static-import-star.mjs +12 -10
- package/test/hook/v14-declaration-exports.mjs +84 -0
- package/test/hook/v18.19-static-import-gotalike.mjs +35 -0
- package/test/low-level/dynamic-import-default.js +1 -1
- package/test/low-level/dynamic-import-default.mjs +1 -1
- package/test/low-level/static-import-default.mjs +1 -1
- package/test/other/v14-assert-cyclical-dependency-failure.mjs +36 -0
- package/test/typescript/iitm-ts-node-loader.mjs +4 -4
- package/test/version-check.js +27 -0
- package/test/runtest +0 -46
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// The following is generated by tslib. __exportStar is a format which cjs-module-lexer exposes as a reexport
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
|
|
14
|
+
__exportStar(require("./circular-a"), exports);
|
|
15
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const o = { name5: 1, name6: 1 }
|
|
2
|
+
const array = [1, 1]
|
|
3
|
+
|
|
4
|
+
// Exporting declarations
|
|
5
|
+
export const name1 = 1; export const name2 = 1/*, … */ // also var
|
|
6
|
+
export const name3 = 1; export const name4 = 1/*, … */ // also var, let
|
|
7
|
+
export function functionName () { return 1 }
|
|
8
|
+
export class ClassName { getFoo () { return 1 } }
|
|
9
|
+
export function * generatorFunctionName () { return 1 }
|
|
10
|
+
export const { name5, name6: bar } = o
|
|
11
|
+
export const [name7, name8] = array
|
|
12
|
+
export async function asyncFunctionName () { return 1 }
|
|
13
|
+
export async function * asyncGeneratorFunctionName () { yield 1 }
|
|
14
|
+
export const arrowFunction = () => {
|
|
15
|
+
return 1
|
|
16
|
+
}
|
|
17
|
+
export const asyncArrowFunction = async () => {
|
|
18
|
+
return 1
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default class { getFoo () { return 1 } }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default class ClassName { getFoo () { return 1 } }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default [1]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default 1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default 'dog'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function () { return 1 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function functionName () { return 1 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function * () { return 1 }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function * generatorFunctionName () { return 1 }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Export list
|
|
2
|
+
const name1 = 1
|
|
3
|
+
const name2 = 1
|
|
4
|
+
const name5 = 1
|
|
5
|
+
const variable1 = 1
|
|
6
|
+
const variable2 = 1
|
|
7
|
+
const variable3 = 1
|
|
8
|
+
const name6 = 1
|
|
9
|
+
export { name1, name2 }
|
|
10
|
+
export { variable1 as name3, variable2 as name4, /* …, */ name5 }
|
|
11
|
+
export { variable3 as 'name' }
|
|
12
|
+
export { name6 as default /*, … */ }
|
package/test/fixtures/foo.mjs
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The purpose of this fixture is to replicate a situation where we may
|
|
2
|
+
// end up exporting `default` twice: first from this script itself and second
|
|
3
|
+
// via the `export * from` line.
|
|
4
|
+
//
|
|
5
|
+
// This replicates the way the in-the-wild `got` module does things:
|
|
6
|
+
// https://github.com/sindresorhus/got/blob/3822412/source/index.ts
|
|
7
|
+
|
|
8
|
+
class got {
|
|
9
|
+
foo = 'foo'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default got
|
|
13
|
+
export { got }
|
|
14
|
+
export * from './something.mjs'
|
|
15
|
+
export * from './default-class.mjs'
|
|
16
|
+
export * from './snake_case.mjs'
|
|
17
|
+
export { default as renamedDefaultExport } from './lib/baz.mjs'
|
package/test/fixtures/json.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
4
4
|
|
|
5
|
-
import coolFile from './something.json' assert { type: 'json' }
|
|
5
|
+
import coolFile from './something.json' assert { type: 'json' }
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
data: coolFile.data
|
|
9
|
-
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// The following is generated by tslib. __exportStar is a format which cjs-module-lexer exposes as a reexport
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
|
|
14
|
+
__exportStar(require("./something"), exports);
|
|
15
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
|
|
2
|
+
//
|
|
3
|
+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2024 Datadog, Inc.
|
|
4
|
+
|
|
5
|
+
import * as tsLoader from './typescript/iitm-ts-node-loader.mjs'
|
|
6
|
+
import * as regularLoader from '../hook.mjs'
|
|
7
|
+
import path from 'path'
|
|
8
|
+
|
|
9
|
+
const filename = process.env.IITM_TEST_FILE
|
|
10
|
+
|
|
11
|
+
export const { load, resolve, getFormat, getSource } =
|
|
12
|
+
filename.includes('disabled')
|
|
13
|
+
? {}
|
|
14
|
+
: (path.extname(filename).slice(-2) === 'ts' ? tsLoader : regularLoader)
|
|
@@ -15,7 +15,7 @@ fixture.split('\n').forEach(line => {
|
|
|
15
15
|
if (expectedNames[0] === '') {
|
|
16
16
|
expectedNames.length = 0
|
|
17
17
|
}
|
|
18
|
-
const names = getEsmExports(mod)
|
|
18
|
+
const names = getEsmExports({ moduleSource: mod })
|
|
19
19
|
assert.deepEqual(expectedNames, names)
|
|
20
20
|
console.log(`${mod}\n ✅ contains exports: ${testStr}`)
|
|
21
21
|
})
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
|
|
2
|
+
//
|
|
3
|
+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
4
|
+
|
|
5
|
+
import Hook from '../../index.js'
|
|
6
|
+
import a from '../fixtures/export-types/default-expression-array.mjs'
|
|
7
|
+
import n from '../fixtures/export-types/default-expression-num.mjs'
|
|
8
|
+
import s from '../fixtures/export-types/default-expression-string.mjs'
|
|
9
|
+
import fn from '../fixtures/export-types/default-function.mjs'
|
|
10
|
+
import cn from '../fixtures/export-types/default-class.mjs'
|
|
11
|
+
import gfn from '../fixtures/export-types/default-generator.mjs'
|
|
12
|
+
import afn from '../fixtures/export-types/default-function-anon.mjs'
|
|
13
|
+
import acn from '../fixtures/export-types/default-class-anon.mjs'
|
|
14
|
+
import agfn from '../fixtures/export-types/default-generator-anon.mjs'
|
|
15
|
+
import defaultImportExport from '../fixtures/export-types/import-default-export.mjs'
|
|
16
|
+
import varDefaultExport from '../fixtures/export-types/variable-default-export.mjs'
|
|
17
|
+
import { strictEqual } from 'assert'
|
|
18
|
+
|
|
19
|
+
Hook((exports, name) => {
|
|
20
|
+
if (name.match(/default-expression-array\.m?js/)) {
|
|
21
|
+
exports.default[0] += 1
|
|
22
|
+
} else if (name.match(/default-expression-num\.m?js/)) {
|
|
23
|
+
exports.default += 1
|
|
24
|
+
} else if (name.match(/default-expression-string\.m?js/)) {
|
|
25
|
+
exports.default += 'dawg'
|
|
26
|
+
} else if (name.match(/default-function\.m?js/)) {
|
|
27
|
+
const orig = exports.default
|
|
28
|
+
exports.default = function () {
|
|
29
|
+
return orig() + 1
|
|
30
|
+
}
|
|
31
|
+
} else if (name.match(/default-class\.m?js/)) {
|
|
32
|
+
exports.default.prototype.getFoo = function () {
|
|
33
|
+
return 2
|
|
34
|
+
}
|
|
35
|
+
} else if (name.match(/default-generator\.m?js/)) {
|
|
36
|
+
const orig2 = exports.default
|
|
37
|
+
exports.default = function * () {
|
|
38
|
+
return orig2().next().value + 1
|
|
39
|
+
}
|
|
40
|
+
} else if (name.match(/default-function-anon\.m?js/)) {
|
|
41
|
+
const orig = exports.default
|
|
42
|
+
exports.default = function () {
|
|
43
|
+
return orig() + 1
|
|
44
|
+
}
|
|
45
|
+
} else if (name.match(/default-class-anon\.m?js/)) {
|
|
46
|
+
exports.default.prototype.getFoo = function () {
|
|
47
|
+
return 2
|
|
48
|
+
}
|
|
49
|
+
} else if (name.match(/default-generator-anon\.m?js/)) {
|
|
50
|
+
const orig2 = exports.default
|
|
51
|
+
exports.default = function * () {
|
|
52
|
+
return orig2().next().value + 1
|
|
53
|
+
}
|
|
54
|
+
} else if (name.match(/import-default-export\.m?js/)) {
|
|
55
|
+
const orig3 = exports.default
|
|
56
|
+
exports.default = function () {
|
|
57
|
+
return orig3() + 1
|
|
58
|
+
}
|
|
59
|
+
} else if (name.match(/variable-default-export\.m?js/)) {
|
|
60
|
+
const orig4 = exports.default
|
|
61
|
+
exports.default = function () {
|
|
62
|
+
return orig4() + 1
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
/* eslint-disable new-cap */
|
|
68
|
+
strictEqual(defaultImportExport(), 2)
|
|
69
|
+
strictEqual(varDefaultExport(), 2)
|
|
70
|
+
strictEqual(a[0], 2)
|
|
71
|
+
strictEqual(fn(), 2)
|
|
72
|
+
strictEqual(new cn().getFoo(), 2)
|
|
73
|
+
strictEqual(gfn().next().value, 2)
|
|
74
|
+
strictEqual(afn(), 2)
|
|
75
|
+
strictEqual(new acn().getFoo(), 2)
|
|
76
|
+
strictEqual(agfn().next().value, 2)
|
|
77
|
+
strictEqual(n, 2)
|
|
78
|
+
strictEqual(s, 'dogdawg')
|
|
@@ -8,13 +8,13 @@ const { strictEqual } = require('assert')
|
|
|
8
8
|
Hook((exports, name) => {
|
|
9
9
|
if (name.match(/something.js/)) {
|
|
10
10
|
const orig = exports.default
|
|
11
|
-
exports.default = function bar() {
|
|
11
|
+
exports.default = function bar () {
|
|
12
12
|
return orig() + 15
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
if (name.match(/something.mjs/)) {
|
|
16
16
|
const orig = exports.default
|
|
17
|
-
return function bar() {
|
|
17
|
+
return function bar () {
|
|
18
18
|
return orig() + 15
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
|
|
2
|
+
//
|
|
3
|
+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
4
|
+
|
|
5
|
+
import Hook from '../../index.js'
|
|
6
|
+
import { foo as fooMjs } from '../fixtures/something.mjs'
|
|
7
|
+
import { foo as fooJs } from '../fixtures/something.js'
|
|
8
|
+
import { strictEqual, deepStrictEqual } from 'assert'
|
|
9
|
+
|
|
10
|
+
let hookedExports
|
|
11
|
+
|
|
12
|
+
Hook((exports, name) => {
|
|
13
|
+
hookedExports = exports
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
strictEqual(fooMjs, 42)
|
|
17
|
+
strictEqual(fooJs, 42)
|
|
18
|
+
|
|
19
|
+
strictEqual(hookedExports[Symbol.toStringTag], 'Module')
|
|
20
|
+
deepStrictEqual(Object.getOwnPropertyDescriptor(hookedExports, Symbol.toStringTag), {
|
|
21
|
+
value: 'Module',
|
|
22
|
+
enumerable: false,
|
|
23
|
+
writable: false,
|
|
24
|
+
configurable: false
|
|
25
|
+
})
|
|
@@ -10,13 +10,13 @@ import { strictEqual } from 'assert'
|
|
|
10
10
|
Hook((exports, name) => {
|
|
11
11
|
if (name.match(/something.mjs/)) {
|
|
12
12
|
const orig = exports.default
|
|
13
|
-
exports.default = function bar() {
|
|
13
|
+
exports.default = function bar () {
|
|
14
14
|
return orig() + 15
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
if (name.match(/something.js/)) {
|
|
18
18
|
const orig = exports.default
|
|
19
|
-
return function bar() {
|
|
19
|
+
return function bar () {
|
|
20
20
|
return orig() + 15
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -7,7 +7,7 @@ import { strictEqual } from 'assert'
|
|
|
7
7
|
const c8Dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'node_modules', 'c8')
|
|
8
8
|
|
|
9
9
|
Hook(['c8'], { internals: true }, (exports, name, baseDir) => {
|
|
10
|
-
strictEqual(name, path.join('c8','index.js'))
|
|
10
|
+
strictEqual(name, path.join('c8', 'index.js'))
|
|
11
11
|
strictEqual(baseDir, c8Dir)
|
|
12
12
|
exports.Report = () => 42
|
|
13
13
|
})
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import { strictEqual } from 'assert'
|
|
2
2
|
import Hook from '../../index.js'
|
|
3
|
+
|
|
4
|
+
/* eslint-disable import/first */
|
|
5
|
+
import {
|
|
6
|
+
/* eslint-disable import/no-named-default */
|
|
7
|
+
default as bar,
|
|
8
|
+
foo,
|
|
9
|
+
aFunc,
|
|
10
|
+
baz
|
|
11
|
+
} from '../fixtures/bundle.mjs'
|
|
3
12
|
Hook((exports, name) => {
|
|
4
13
|
if (/bundle\.mjs/.test(name) === false) return
|
|
5
14
|
|
|
6
15
|
const bar = exports.default
|
|
7
|
-
exports.default = function wrappedBar() {
|
|
16
|
+
exports.default = function wrappedBar () {
|
|
8
17
|
return bar() + '-wrapped'
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
const foo = exports.foo
|
|
12
|
-
exports.foo = function wrappedFoo() {
|
|
21
|
+
exports.foo = function wrappedFoo () {
|
|
13
22
|
return foo() + '-wrapped'
|
|
14
23
|
}
|
|
15
24
|
|
|
16
25
|
const aFunc = exports.aFunc
|
|
17
|
-
exports.aFunc = function wrappedAFunc() {
|
|
26
|
+
exports.aFunc = function wrappedAFunc () {
|
|
18
27
|
return aFunc() + '-wrapped'
|
|
19
28
|
}
|
|
20
29
|
})
|
|
21
30
|
|
|
22
|
-
import {
|
|
23
|
-
default as bar,
|
|
24
|
-
foo,
|
|
25
|
-
aFunc,
|
|
26
|
-
baz
|
|
27
|
-
} from '../fixtures/bundle.mjs'
|
|
28
|
-
|
|
29
31
|
strictEqual(bar(), '42-wrapped')
|
|
30
32
|
strictEqual(foo(), 'foo-wrapped')
|
|
31
33
|
strictEqual(aFunc(), 'a-wrapped')
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
|
|
2
|
+
//
|
|
3
|
+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
4
|
+
|
|
5
|
+
import Hook from '../../index.js'
|
|
6
|
+
import {
|
|
7
|
+
name1 as n1,
|
|
8
|
+
name2 as n2,
|
|
9
|
+
name3 as n3,
|
|
10
|
+
name4 as n4,
|
|
11
|
+
ClassName as cn,
|
|
12
|
+
generatorFunctionName as gfn,
|
|
13
|
+
name5 as n5,
|
|
14
|
+
bar as n6,
|
|
15
|
+
name7 as n7,
|
|
16
|
+
name8 as n8,
|
|
17
|
+
asyncFunctionName as afn,
|
|
18
|
+
asyncGeneratorFunctionName as agfn,
|
|
19
|
+
arrowFunction as arfn,
|
|
20
|
+
asyncArrowFunction as aarfn
|
|
21
|
+
, functionName
|
|
22
|
+
} from '../fixtures/export-types/declarations.mjs'
|
|
23
|
+
import { strictEqual } from 'assert'
|
|
24
|
+
|
|
25
|
+
Hook((exports, name) => {
|
|
26
|
+
if (name.match(/declarations\.m?js/)) {
|
|
27
|
+
exports.name1 += 1
|
|
28
|
+
exports.name2 += 1
|
|
29
|
+
exports.name3 += 1
|
|
30
|
+
exports.name4 += 1
|
|
31
|
+
const orig = exports.functionName
|
|
32
|
+
exports.functionName = function () {
|
|
33
|
+
return orig() + 1
|
|
34
|
+
}
|
|
35
|
+
exports.ClassName.prototype.getFoo = function () {
|
|
36
|
+
return 2
|
|
37
|
+
}
|
|
38
|
+
const orig2 = exports.generatorFunctionName
|
|
39
|
+
exports.generatorFunctionName = function * () {
|
|
40
|
+
return orig2().next().value + 1
|
|
41
|
+
}
|
|
42
|
+
exports.name5 += 1
|
|
43
|
+
exports.bar += 1
|
|
44
|
+
exports.name7 += 1
|
|
45
|
+
exports.name8 += 1
|
|
46
|
+
const asyncOrig = exports.asyncFunctionName
|
|
47
|
+
exports.asyncFunctionName = async function () {
|
|
48
|
+
return await asyncOrig() + 1
|
|
49
|
+
}
|
|
50
|
+
const asyncOrig2 = exports.asyncGeneratorFunctionName
|
|
51
|
+
exports.asyncGeneratorFunctionName = async function * () {
|
|
52
|
+
for await (const value of asyncOrig2()) {
|
|
53
|
+
yield value + 1
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const arrowOrig = exports.arrowFunction
|
|
57
|
+
exports.arrowFunction = () => {
|
|
58
|
+
return arrowOrig() + 1
|
|
59
|
+
}
|
|
60
|
+
const asyncArrowOrig = exports.asyncArrowFunction
|
|
61
|
+
exports.asyncArrowFunction = async () => {
|
|
62
|
+
return await asyncArrowOrig() + 1
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
strictEqual(n1, 2)
|
|
68
|
+
strictEqual(n2, 2)
|
|
69
|
+
strictEqual(n3, 2)
|
|
70
|
+
strictEqual(n4, 2)
|
|
71
|
+
strictEqual(functionName(), 2)
|
|
72
|
+
/* eslint-disable new-cap */
|
|
73
|
+
strictEqual(new cn().getFoo(), 2)
|
|
74
|
+
strictEqual(gfn().next().value, 2)
|
|
75
|
+
strictEqual(n5, 2)
|
|
76
|
+
strictEqual(n6, 2)
|
|
77
|
+
strictEqual(n7, 2)
|
|
78
|
+
strictEqual(n8, 2)
|
|
79
|
+
strictEqual(await afn(), 2)
|
|
80
|
+
for await (const value of agfn()) {
|
|
81
|
+
strictEqual(value, 2)
|
|
82
|
+
}
|
|
83
|
+
strictEqual(arfn(), 2)
|
|
84
|
+
strictEqual(await aarfn(), 2)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { strictEqual } from 'assert'
|
|
2
|
+
import Hook from '../../index.js'
|
|
3
|
+
Hook((exports, name) => {
|
|
4
|
+
if (/got-alike\.mjs/.test(name) === false) return
|
|
5
|
+
|
|
6
|
+
const bar = exports.something
|
|
7
|
+
exports.something = function barWrapped () {
|
|
8
|
+
return bar() + '-wrapped'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const renamedDefaultExport = exports.renamedDefaultExport
|
|
12
|
+
exports.renamedDefaultExport = function bazWrapped () {
|
|
13
|
+
return renamedDefaultExport() + '-wrapped'
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
/* eslint-disable import/no-named-default */
|
|
18
|
+
/* eslint-disable camelcase */
|
|
19
|
+
import {
|
|
20
|
+
default as Got,
|
|
21
|
+
something,
|
|
22
|
+
defaultClass as DefaultClass,
|
|
23
|
+
snake_case,
|
|
24
|
+
renamedDefaultExport
|
|
25
|
+
} from '../fixtures/got-alike.mjs'
|
|
26
|
+
|
|
27
|
+
strictEqual(something(), '42-wrapped')
|
|
28
|
+
const got = new Got()
|
|
29
|
+
strictEqual(got.foo, 'foo')
|
|
30
|
+
|
|
31
|
+
const dc = new DefaultClass()
|
|
32
|
+
strictEqual(dc.value, 'DefaultClass')
|
|
33
|
+
|
|
34
|
+
strictEqual(snake_case, 'snake_case')
|
|
35
|
+
strictEqual(renamedDefaultExport(), 'baz-wrapped')
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
|
|
2
|
+
//
|
|
3
|
+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
4
|
+
|
|
5
|
+
import { spawn } from 'child_process'
|
|
6
|
+
import { strictEqual } from 'assert'
|
|
7
|
+
|
|
8
|
+
const nodeProcess = spawn('node', [
|
|
9
|
+
'--loader',
|
|
10
|
+
'./hook.mjs',
|
|
11
|
+
'./test/fixtures/cyclical-a.mjs'
|
|
12
|
+
])
|
|
13
|
+
|
|
14
|
+
// expected output should be 'testB\ntestA' but the hook fails when running against files
|
|
15
|
+
// with cylical dependencies
|
|
16
|
+
const expectedOutput = 'testB\ntestA'
|
|
17
|
+
let stdout = ''
|
|
18
|
+
let stderr = ''
|
|
19
|
+
|
|
20
|
+
nodeProcess.stdout.on('data', (data) => {
|
|
21
|
+
stdout += data.toString()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
nodeProcess.stderr.on('data', (data) => {
|
|
25
|
+
stderr += data.toString()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
nodeProcess.on('close', (code) => {
|
|
29
|
+
// assert that the hook fails with a non-zero exit code
|
|
30
|
+
strictEqual(code === 1 || code === 13, true)
|
|
31
|
+
|
|
32
|
+
// satisfy linter complaining about unused variables
|
|
33
|
+
strictEqual(expectedOutput, expectedOutput)
|
|
34
|
+
strictEqual(typeof stdout, 'string')
|
|
35
|
+
strictEqual(typeof stderr, 'string')
|
|
36
|
+
})
|