diff options
Diffstat (limited to 'lib/repl.js')
-rw-r--r-- | lib/repl.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/repl.js b/lib/repl.js index d1b9a91df6..4dabe2110d 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -279,6 +279,12 @@ function REPLServer(prompt, } function defaultEval(code, context, file, cb) { + const { getOptionValue } = require('internal/options'); + const experimentalModules = getOptionValue('--experimental-modules'); + const asyncESM = experimentalModules ? + require('internal/process/esm_loader') : + null; + let result, script, wrappedErr; let err = null; let wrappedCmd = false; @@ -312,6 +318,12 @@ function REPLServer(prompt, if (code === '\n') return cb(null); + let pwd; + try { + const { pathToFileURL } = require('url'); + pwd = pathToFileURL(process.cwd()).href; + } catch { + } while (true) { try { if (!/^\s*$/.test(code) && @@ -322,7 +334,12 @@ function REPLServer(prompt, } script = vm.createScript(code, { filename: file, - displayErrors: true + displayErrors: true, + importModuleDynamically: experimentalModules ? + async (specifier) => { + return (await asyncESM.loaderPromise).import(specifier, pwd); + } : + undefined }); } catch (e) { debug('parse error %j', code, e); |