From 1117d2db3965fc44f174be3fd029293b7e2b952e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 Nov 2021 16:55:10 +0100 Subject: compat: support compat mode in REPL (#12882) This commit introduces "ProcState::maybe_resolver" field, which stores a single instance of resolver for the whole lifetime of the process, instead of creating these resolvers for each creation of module graph. As a result, this resolver can be used in fallback case where graph is not constructed (REPL, loading modules using "require") unifying resolution logic. --- cli/tests/testdata/compat/dyn_import_reject.out | 2 +- cli/tests/testdata/compat/import_esm_from_cjs/index.js | 1 + .../compat/import_esm_from_cjs/node_modules/pure-cjs/index.js | 4 ++++ .../compat/import_esm_from_cjs/node_modules/pure-cjs/package.json | 4 ++++ .../compat/import_esm_from_cjs/node_modules/pure-esm/index.js | 2 ++ .../compat/import_esm_from_cjs/node_modules/pure-esm/package.json | 5 +++++ 6 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 cli/tests/testdata/compat/import_esm_from_cjs/index.js create mode 100644 cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-cjs/index.js create mode 100644 cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-cjs/package.json create mode 100644 cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-esm/index.js create mode 100644 cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-esm/package.json (limited to 'cli/tests/testdata') diff --git a/cli/tests/testdata/compat/dyn_import_reject.out b/cli/tests/testdata/compat/dyn_import_reject.out index 6d78135b2..1324c8aeb 100644 --- a/cli/tests/testdata/compat/dyn_import_reject.out +++ b/cli/tests/testdata/compat/dyn_import_reject.out @@ -1,2 +1,2 @@ -TypeError: Cannot load module "file:///[WILDCARD]/testdata/compat/foobar.js". +TypeError: [ERR_MODULE_NOT_FOUND] Cannot find module "file://[WILDCARD]/testdata/compat/foobar.js" imported from "file://[WILDCARD]/testdata/compat/dyn_import_reject.js" ERR_MODULE_NOT_FOUND diff --git a/cli/tests/testdata/compat/import_esm_from_cjs/index.js b/cli/tests/testdata/compat/import_esm_from_cjs/index.js new file mode 100644 index 000000000..4ba03e104 --- /dev/null +++ b/cli/tests/testdata/compat/import_esm_from_cjs/index.js @@ -0,0 +1 @@ +require("pure-cjs"); diff --git a/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-cjs/index.js b/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-cjs/index.js new file mode 100644 index 000000000..35f7c3774 --- /dev/null +++ b/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-cjs/index.js @@ -0,0 +1,4 @@ +async function run() { + const _result = await import('pure-esm'); +} +run() diff --git a/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-cjs/package.json b/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-cjs/package.json new file mode 100644 index 000000000..e854fd992 --- /dev/null +++ b/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-cjs/package.json @@ -0,0 +1,4 @@ +{ + "name": "pure-cjs", + "main": "./index.js" +} diff --git a/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-esm/index.js b/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-esm/index.js new file mode 100644 index 000000000..898097cb5 --- /dev/null +++ b/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-esm/index.js @@ -0,0 +1,2 @@ +import fs from 'node:fs'; +console.log(typeof fs.chmod); diff --git a/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-esm/package.json b/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-esm/package.json new file mode 100644 index 000000000..a373d3ad9 --- /dev/null +++ b/cli/tests/testdata/compat/import_esm_from_cjs/node_modules/pure-esm/package.json @@ -0,0 +1,5 @@ +{ + "name": "pure-esm", + "type": "module", + "main": "./index.js" +} -- cgit v1.2.3