-
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.
repl: fix referrer for dynamic import
The ESM loader does not accept a directory as the referrer, it requires a path within the directory. Add `/repl` to ensure relative dynamic imports can succeed. Fixes: #19570 PR-URL: #30609 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Coe <bencoe@gmail.com>
- Loading branch information
1 parent
036a982
commit d7972b7
Showing
2 changed files
with
34 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const args = [ | ||
'--interactive', | ||
'--experimental-repl-await', | ||
'--experimental-modules' | ||
]; | ||
|
||
const opts = { cwd: fixtures.path('es-modules') }; | ||
const child = cp.spawn(process.execPath, args, opts); | ||
|
||
let output = ''; | ||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', (data) => { | ||
output += data; | ||
}); | ||
|
||
child.on('exit', common.mustCall(() => { | ||
const results = output.replace(/^> /mg, '').split('\n').slice(2); | ||
assert.deepStrictEqual(results, ['[Module] { message: \'A message\' }', '']); | ||
})); | ||
|
||
child.stdin.write('await import(\'./message.mjs\');\n'); | ||
child.stdin.write('.exit'); | ||
child.stdin.end(); |