-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib,src: extract sourceMappingURL from module
PR-URL: #51690 Refs: #51522 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
- Loading branch information
1 parent
eb1089a
commit 8dc3f91
Showing
8 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { spawnPromisified } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import assert from 'node:assert'; | ||
import { execPath } from 'node:process'; | ||
import { describe, it } from 'node:test'; | ||
|
||
describe('esm source-map', { concurrency: true }, () => { | ||
// Issue: https://github.com/nodejs/node/issues/51522 | ||
|
||
[ | ||
[ | ||
'in middle from esm', | ||
'source-map/extract-url/esm-url-in-middle.mjs', | ||
true, | ||
], | ||
[ | ||
'inside string from esm', | ||
'source-map/extract-url/esm-url-in-string.mjs', | ||
false, | ||
], | ||
].forEach(([name, path, shouldExtract]) => { | ||
it((shouldExtract ? 'should extract source map url' : 'should not extract source map url') + name, async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--no-warnings', | ||
'--enable-source-maps', | ||
fixtures.path(path), | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
if (shouldExtract) { | ||
assert.match(stderr, /index\.ts/); | ||
} else { | ||
assert.doesNotMatch(stderr, /index\.ts/); | ||
} | ||
assert.strictEqual(code, 1); | ||
assert.strictEqual(signal, null); | ||
}); | ||
}); | ||
|
||
[ | ||
[ | ||
'in middle from esm imported by esm', | ||
`import ${JSON.stringify(fixtures.fileURL('source-map/extract-url/esm-url-in-middle.mjs'))}`, | ||
true, | ||
], | ||
[ | ||
'in middle from cjs imported by esm', | ||
`import ${JSON.stringify(fixtures.fileURL('source-map/extract-url/cjs-url-in-middle.js'))}`, | ||
true, | ||
], | ||
[ | ||
'in middle from cjs required by esm', | ||
"import { createRequire } from 'module';" + | ||
'const require = createRequire(import.meta.url);' + | ||
`require(${JSON.stringify(fixtures.path('source-map/extract-url/cjs-url-in-middle.js'))})`, | ||
true, | ||
], | ||
|
||
[ | ||
'inside string from esm imported by esm', | ||
`import ${JSON.stringify(fixtures.fileURL('source-map/extract-url/esm-url-in-string.mjs'))}`, | ||
false, | ||
], | ||
[ | ||
'inside string from cjs imported by esm', | ||
`import ${JSON.stringify(fixtures.fileURL('source-map/extract-url/cjs-url-in-string.js'))}`, | ||
false, | ||
], | ||
[ | ||
'inside string from cjs required by esm', | ||
"import { createRequire } from 'module';" + | ||
'const require = createRequire(import.meta.url);' + | ||
`require(${JSON.stringify(fixtures.path('source-map/extract-url/cjs-url-in-string.js'))})`, | ||
false, | ||
], | ||
].forEach(([name, evalCode, shouldExtract]) => { | ||
it((shouldExtract ? 'should extract source map url' : 'should not extract source map url') + name, async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--no-warnings', | ||
'--enable-source-maps', | ||
'--input-type=module', | ||
'--eval', | ||
evalCode, | ||
]); | ||
|
||
assert.strictEqual(stdout, ''); | ||
if (shouldExtract) { | ||
assert.match(stderr, /index\.ts/); | ||
} else { | ||
assert.doesNotMatch(stderr, /index\.ts/); | ||
} | ||
assert.strictEqual(code, 1); | ||
assert.strictEqual(signal, null); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
throw new Error("Hello world!"); | ||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vcHJvamVjdC9pbmRleC50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsidGhyb3cgbmV3IEVycm9yKFwiSGVsbG8gd29ybGQhXCIpXG4iXSwKICAibWFwcGluZ3MiOiAiO0FBQUEsTUFBTSxJQUFJLE1BQU0sY0FBYzsiLAogICJuYW1lcyI6IFtdCn0K | ||
console.log(1); | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
throw new Error("Hello world!");` | ||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vcHJvamVjdC9pbmRleC50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsidGhyb3cgbmV3IEVycm9yKFwiSGVsbG8gd29ybGQhXCIpXG4iXSwKICAibWFwcGluZ3MiOiAiO0FBQUEsTUFBTSxJQUFJLE1BQU0sY0FBYzsiLAogICJuYW1lcyI6IFtdCn0K | ||
console.log(1); | ||
//` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
throw new Error("Hello world!"); | ||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vcHJvamVjdC9pbmRleC50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsidGhyb3cgbmV3IEVycm9yKFwiSGVsbG8gd29ybGQhXCIpXG4iXSwKICAibWFwcGluZ3MiOiAiO0FBQUEsTUFBTSxJQUFJLE1BQU0sY0FBYzsiLAogICJuYW1lcyI6IFtdCn0K | ||
console.log(1); | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
throw new Error("Hello world!");` | ||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vcHJvamVjdC9pbmRleC50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsidGhyb3cgbmV3IEVycm9yKFwiSGVsbG8gd29ybGQhXCIpXG4iXSwKICAibWFwcGluZ3MiOiAiO0FBQUEsTUFBTSxJQUFJLE1BQU0sY0FBYzsiLAogICJuYW1lcyI6IFtdCn0K | ||
console.log(1); | ||
//` |