-
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.
esm: fix erroneous re-initialization of ESMLoader
- Loading branch information
1 parent
a933a75
commit c9f8fb7
Showing
3 changed files
with
47 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import '../common/index.mjs'; | ||
import fixtures from '../common/fixtures.js'; | ||
import assert from 'node:assert'; | ||
import { spawnSync } from 'node:child_process'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
|
||
{ // Verify unadulterated source is loaded when there are no loaders | ||
const { status, stderr, stdout } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--loader', | ||
fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs'), | ||
'--no-warnings', | ||
fileURLToPath(fixtures.fileURL('es-modules', 'runmain.mjs')), | ||
], | ||
{ encoding: 'utf8' }, | ||
); | ||
|
||
const resolveHookRunCount = [...(stdout.matchAll(/resolve passthru/g) ?? new Array())] | ||
.length - 1; // less 1 because the first is the needle | ||
|
||
assert.strictEqual(stderr, ''); | ||
/** | ||
* resolveHookRunCount = 2: | ||
* 1. fixtures/…/runmain.mjs | ||
* 2. node:module (imported by fixtures/…/runmain.mjs) | ||
*/ | ||
assert.strictEqual(resolveHookRunCount, 2); | ||
assert.strictEqual(status, 0); | ||
} |
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,7 @@ | ||
import { runMain } from 'node:module'; | ||
|
||
try { await import.meta.resolve('doesnt-matter.mjs') } catch {} | ||
|
||
runMain(); | ||
|
||
try { await import.meta.resolve('doesnt-matter.mjs') } catch {} |