-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 Backport-PR-URL: #50669 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
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' } }), | ||
); |