diff options
author | Guy Bedford <guybedford@gmail.com> | 2019-06-23 00:27:56 +0200 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2019-07-02 11:46:56 +0200 |
commit | c9a96aeeeebc60b109ab0a9caff24aa0a4a67bcb (patch) | |
tree | d73b2cf485ad24ed7b0b2f4ad22fd4e88c50df12 | |
parent | b8084840d8a84b7818a952e84419f78b74bf2470 (diff) | |
download | node-new-c9a96aeeeebc60b109ab0a9caff24aa0a4a67bcb.tar.gz |
esm: ensure cwd-relative imports for module --eval
PR-URL: https://github.com/nodejs/node/pull/28389
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r-- | lib/internal/modules/esm/loader.js | 10 | ||||
-rw-r--r-- | test/message/async_error_eval_esm.out | 10 | ||||
-rw-r--r-- | test/parallel/test-cli-eval.js | 9 |
3 files changed, 22 insertions, 7 deletions
diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 0ea1e6f4e5..bffefa884e 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -9,7 +9,10 @@ const { ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK, ERR_UNKNOWN_MODULE_FORMAT } = require('internal/errors').codes; -const { URL } = require('url'); +const { + URL, + pathToFileURL +} = require('url'); const { validateString } = require('internal/validators'); const ModuleMap = require('internal/modules/esm/module_map'); const ModuleJob = require('internal/modules/esm/module_job'); @@ -107,7 +110,10 @@ class Loader { return { url, format }; } - async eval(source, url = `eval:${++this.evalIndex}`) { + async eval( + source, + url = pathToFileURL(`${process.cwd()}/[eval${++this.evalIndex}]`).href + ) { const evalInstance = async (url) => { return { module: new ModuleWrap(source, url), diff --git a/test/message/async_error_eval_esm.out b/test/message/async_error_eval_esm.out index 91ce0ce21c..578a9f5c26 100644 --- a/test/message/async_error_eval_esm.out +++ b/test/message/async_error_eval_esm.out @@ -1,7 +1,7 @@ Error: test - at one (eval:1:2:9) - at two (eval:1:15:9) + at one (file:*/[eval1]:2:9) + at two (file:*/[eval1]:15:9) at processTicksAndRejections (internal/process/task_queues.js:*:*) - at async three (eval:1:18:3) - at async four (eval:1:22:3) - at async main (eval:1:28:5) + at async three (file:*/[eval1]:18:3) + at async four (file:*/[eval1]:22:3) + at async main (file:*/[eval1]:28:5) diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index acf20bb77f..0d2ea48c06 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -274,3 +274,12 @@ child.exec( assert.ifError(err); assert.strictEqual(stdout, 'object\n'); })); + +// Assert that packages can be imported cwd-relative with --eval +child.exec( + `${nodejs} ${execOptions} ` + + '--eval "import \'./test/fixtures/es-modules/mjs-file.mjs\'"', + common.mustCall((err, stdout) => { + assert.ifError(err); + assert.strictEqual(stdout, '.mjs file\n'); + })); |