summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node_resolver/resolution.rs6
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/__test__.jsonc7
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/main.out2
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/main.ts4
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.d.ts3
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.js4
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/package.json3
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.d.ts1
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.js3
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/package.json21
-rw-r--r--tests/specs/node/cjs_dynamic_import_esm_with_exports/package.json3
11 files changed, 53 insertions, 4 deletions
diff --git a/ext/node_resolver/resolution.rs b/ext/node_resolver/resolution.rs
index d7918c75c..25316c385 100644
--- a/ext/node_resolver/resolution.rs
+++ b/ext/node_resolver/resolution.rs
@@ -221,10 +221,8 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
specifier,
referrer,
referrer_kind,
- match referrer_kind {
- NodeModuleKind::Esm => DEFAULT_CONDITIONS,
- NodeModuleKind::Cjs => REQUIRE_CONDITIONS,
- },
+ // even though the referrer may be CJS, if we're here that means we're doing ESM resolution
+ DEFAULT_CONDITIONS,
mode,
)?;
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/__test__.jsonc b/tests/specs/node/cjs_dynamic_import_esm_with_exports/__test__.jsonc
new file mode 100644
index 000000000..980245cb9
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/__test__.jsonc
@@ -0,0 +1,7 @@
+{
+ "envs": {
+ "DENO_FUTURE": "1"
+ },
+ "args": "run --check main.ts",
+ "output": "main.out"
+}
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/main.out b/tests/specs/node/cjs_dynamic_import_esm_with_exports/main.out
new file mode 100644
index 000000000..e85a0148d
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/main.out
@@ -0,0 +1,2 @@
+Check file:///[WILDLINE]main.ts
+3
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/main.ts b/tests/specs/node/cjs_dynamic_import_esm_with_exports/main.ts
new file mode 100644
index 000000000..4e25d92f0
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/main.ts
@@ -0,0 +1,4 @@
+import { addAsync } from "cjs-add";
+
+const value: number = await addAsync(1, 2);
+console.log(value);
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.d.ts b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.d.ts
new file mode 100644
index 000000000..c2195de04
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.d.ts
@@ -0,0 +1,3 @@
+import add from "esm-add";
+
+export function addAsync(a: number, b: number): Promise<ReturnType<typeof add>>; \ No newline at end of file
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.js b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.js
new file mode 100644
index 000000000..471a427bb
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/index.js
@@ -0,0 +1,4 @@
+module.exports.addAsync = async (a, b) => {
+ const add = await import("esm-add");
+ return add.default(a, b);
+}; \ No newline at end of file
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/package.json b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/package.json
new file mode 100644
index 000000000..767134840
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/cjs-add/package.json
@@ -0,0 +1,3 @@
+{
+ "name": "cjs-add"
+} \ No newline at end of file
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.d.ts b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.d.ts
new file mode 100644
index 000000000..01a61d4d5
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.d.ts
@@ -0,0 +1 @@
+export default function add(a: number, b: number): number;
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.js b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.js
new file mode 100644
index 000000000..90e942324
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/index.js
@@ -0,0 +1,3 @@
+export default function add(a, b) {
+ return a + b;
+}
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/package.json b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/package.json
new file mode 100644
index 000000000..879883352
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/node_modules/esm-add/package.json
@@ -0,0 +1,21 @@
+{
+ "name": "esm-add",
+ "version": "0.12.1",
+ "license": "MIT",
+ "type": "module",
+ "main": "index.js",
+ "types": "index.d.ts",
+ "exports": {
+ ".": {
+ "types": "./index.d.ts",
+ "import": "./index.js"
+ },
+ "./package.json": "./package.json"
+ },
+ "files": [
+ "files",
+ "index.js",
+ "index.d.ts",
+ "package.json"
+ ]
+}
diff --git a/tests/specs/node/cjs_dynamic_import_esm_with_exports/package.json b/tests/specs/node/cjs_dynamic_import_esm_with_exports/package.json
new file mode 100644
index 000000000..3dbc1ca59
--- /dev/null
+++ b/tests/specs/node/cjs_dynamic_import_esm_with_exports/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "module"
+}