-
Notifications
You must be signed in to change notification settings - Fork 4
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
PR-URL: nodejs/node#43763 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Guy Bedford <[email protected]>
- Loading branch information
1 parent
3372af1
commit 6dcfe51
Showing
3 changed files
with
46 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,30 @@ | ||
import '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import assert from 'node:assert'; | ||
import { spawnSync } from 'node:child_process'; | ||
|
||
|
||
{ // 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', | ||
fixtures.path('es-modules', 'runmain.mjs'), | ||
], | ||
{ encoding: 'utf8' }, | ||
); | ||
|
||
// Length minus 1 because the first match is the needle. | ||
const resolveHookRunCount = (stdout.match(/resolve passthru/g)?.length ?? 0) - 1; | ||
|
||
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 {} |