File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,12 @@ function REPLServer(prompt,
279279 }
280280
281281 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+
282288 let result , script , wrappedErr ;
283289 let err = null ;
284290 let wrappedCmd = false ;
@@ -312,6 +318,12 @@ function REPLServer(prompt,
312318 if ( code === '\n' )
313319 return cb ( null ) ;
314320
321+ let pwd ;
322+ try {
323+ const { pathToFileURL } = require ( 'url' ) ;
324+ pwd = pathToFileURL ( process . cwd ( ) ) . href ;
325+ } catch {
326+ }
315327 while ( true ) {
316328 try {
317329 if ( ! / ^ \s * $ / . test ( code ) &&
@@ -322,7 +334,12 @@ function REPLServer(prompt,
322334 }
323335 script = vm . createScript ( code , {
324336 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
326343 } ) ;
327344 } catch ( e ) {
328345 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