-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
- Loading branch information
Showing
3 changed files
with
98 additions
and
4 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' } }), | ||
); |