From eee5c1f6bd8c7ba8ce468b5022401b9051f9aa85 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Thu, 29 Mar 2018 19:30:25 -0500 Subject: [PATCH] repl: enable dynamic import --- lib/repl.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/repl.js b/lib/repl.js index a7977dc72fb781..986b22217be6aa 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -49,6 +49,7 @@ const { } = require('internal/modules/cjs/helpers'); const internalUtil = require('internal/util'); const { isTypedArray } = require('internal/util/types'); +const { getURLFromFilePath } = require('internal/url'); const util = require('util'); const utilBinding = process.binding('util'); const { inherits } = util; @@ -256,7 +257,17 @@ function REPLServer(prompt, } script = vm.createScript(code, { filename: file, - displayErrors: true + displayErrors: true, + async resolveDynamicImport(specifier, scriptOrModule) { + const loader = await require('internal/process/esm_loader') + .loaderPromise; + + const filename = scriptOrModule.filename; + const referrer = scriptOrModule.url || + getURLFromFilePath(filename === 'repl' ? + path.join(process.cwd(), filename) : filename).href; + return loader.import(specifier, referrer); + }, }); } catch (e) { debug('parse error %j', code, e);