File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,12 @@ function REPLServer(prompt,
279
279
}
280
280
281
281
function defaultEval ( code , context , file , cb ) {
282
+ const { getOptionValue } = require ( 'internal/options' ) ;
283
+ const experimentalModules = getOptionValue ( '--experimental-modules' ) ;
284
+ const asyncESM = experimentalModules ?
285
+ require ( 'internal/process/esm_loader' ) :
286
+ null ;
287
+
282
288
let result , script , wrappedErr ;
283
289
let err = null ;
284
290
let wrappedCmd = false ;
@@ -312,6 +318,12 @@ function REPLServer(prompt,
312
318
if ( code === '\n' )
313
319
return cb ( null ) ;
314
320
321
+ let pwd ;
322
+ try {
323
+ const { pathToFileURL } = require ( 'url' ) ;
324
+ pwd = pathToFileURL ( process . cwd ( ) ) . href ;
325
+ } catch {
326
+ }
315
327
while ( true ) {
316
328
try {
317
329
if ( ! / ^ \s * $ / . test ( code ) &&
@@ -322,7 +334,12 @@ function REPLServer(prompt,
322
334
}
323
335
script = vm . createScript ( code , {
324
336
filename : file ,
325
- displayErrors : true
337
+ displayErrors : true ,
338
+ importModuleDynamically : experimentalModules ?
339
+ async ( specifier ) => {
340
+ return ( await asyncESM . loaderPromise ) . import ( specifier , pwd ) ;
341
+ } :
342
+ undefined
326
343
} ) ;
327
344
} catch ( e ) {
328
345
debug ( 'parse error %j' , code , e ) ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
+ const { spawn } = require ( 'child_process' ) ;
5
+
6
+ const child = spawn ( process . execPath , [
7
+ '--experimental-modules' ,
8
+ '--interactive'
9
+ ] ) ;
10
+ child . stdin . end ( `
11
+ import('fs').then(
12
+ ns => ns.default === require('fs') ? 0 : 1,
13
+ _ => 2
14
+ ).then(process.exit)
15
+ ` ) ;
16
+
17
+ child . on ( 'exit' , ( code ) => {
18
+ assert . strictEqual ( code , 0 ) ;
19
+ } ) ;
You can’t perform that action at this time.
0 commit comments