-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: fix cache collision on JSON files using file: URL
PR-URL: #49887 Fixes: #49724 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
- Loading branch information
Showing
5 changed files
with
104 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { register } from 'node:module'; | ||
import assert from 'node:assert'; | ||
|
||
async function resolve(referrer, context, next) { | ||
const result = await next(referrer, context); | ||
const url = new URL(result.url); | ||
url.searchParams.set('randomSeed', Math.random()); | ||
result.url = url.href; | ||
return result; | ||
} | ||
|
||
function load(url, context, next) { | ||
if (context.importAssertions.type === 'json') { | ||
return { | ||
shortCircuit: true, | ||
format: 'json', | ||
source: JSON.stringify({ data: Math.random() }), | ||
}; | ||
} | ||
return next(url, context); | ||
} | ||
|
||
register(`data:text/javascript,export ${encodeURIComponent(resolve)};export ${encodeURIComponent(load)}`); | ||
|
||
assert.notDeepStrictEqual( | ||
await import(fixtures.fileURL('empty.json'), { assert: { type: 'json' } }), | ||
await import(fixtures.fileURL('empty.json'), { assert: { type: 'json' } }), | ||
); |
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
2 changes: 1 addition & 1 deletion
2
test/fixtures/source-map/output/source_map_sourcemapping_url_string.snapshot
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Error: an exception. | ||
at Object.<anonymous> (*typescript-sourcemapping_url_string.ts:3:7) | ||
at Module._compile (node:internal*modules*cjs*loader:1241:14) | ||
at Module._compile (node:internal*modules*cjs*loader:1406:14) |