| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a81eae6 commit 106e5ce
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -324,10 +324,12 @@ function REPLServer(prompt, | |||
| 324 | 324 | if (code === '\n') | |
| 325 | 325 | return cb(null); | |
| 326 | 326 | ||
| 327 | - let pwd; | ||
| 327 | + let parentURL; | ||
| 328 | 328 | try { | |
| 329 | 329 | const { pathToFileURL } = require('url'); | |
| 330 | - pwd = pathToFileURL(process.cwd()).href; | ||
| 330 | + // Adding `/repl` prevents dynamic imports from loading relative | ||
| 331 | + // to the parent of `process.cwd()`. | ||
| 332 | + parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href; | ||
| 331 | 333 | } catch { | |
| 332 | 334 | } | |
| 333 | 335 | while (true) { | |
@@ -342,7 +344,7 @@ function REPLServer(prompt, | |||
| 342 | 344 | filename: file, | |
| 343 | 345 | displayErrors: true, | |
| 344 | 346 | importModuleDynamically: experimentalModules ? async (specifier) => { | |
| 345 | - return asyncESM.ESMLoader.import(specifier, pwd); | ||
| 347 | + return asyncESM.ESMLoader.import(specifier, parentURL); | ||
| 346 | 348 | } : undefined | |
| 347 | 349 | }); | |
| 348 | 350 | } catch (e) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cp = require('child_process'); | ||
| 5 | + const fixtures = require('../common/fixtures'); | ||
| 6 | + | ||
| 7 | + const args = [ | ||
| 8 | + '--interactive', | ||
| 9 | + '--experimental-repl-await', | ||
| 10 | + '--experimental-modules' | ||
| 11 | + ]; | ||
| 12 | + | ||
| 13 | + const opts = { cwd: fixtures.path('es-modules') }; | ||
| 14 | + const child = cp.spawn(process.execPath, args, opts); | ||
| 15 | + | ||
| 16 | + let output = ''; | ||
| 17 | + child.stdout.setEncoding('utf8'); | ||
| 18 | + child.stdout.on('data', (data) => { | ||
| 19 | + output += data; | ||
| 20 | + }); | ||
| 21 | + | ||
| 22 | + child.on('exit', common.mustCall(() => { | ||
| 23 | + const results = output.replace(/^> /mg, '').split('\n').slice(2); | ||
| 24 | + assert.deepStrictEqual(results, ['[Module] { message: \'A message\' }', '']); | ||
| 25 | + })); | ||
| 26 | + | ||
| 27 | + child.stdin.write('await import(\'./message.mjs\');\n'); | ||
| 28 | + child.stdin.write('.exit'); | ||
| 29 | + child.stdin.end(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments