summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/module_loader.rs2
-rw-r--r--cli/tests/integration/npm_tests.rs14
-rw-r--r--cli/tests/testdata/npm/dynamic_import_json/main.js4
-rw-r--r--cli/tests/testdata/npm/dynamic_import_json/main.out14
-rw-r--r--cli/tests/testdata/npm/import_json/main.js4
-rw-r--r--cli/tests/testdata/npm/import_json/main.out10
-rw-r--r--ext/node/resolution.rs2
7 files changed, 48 insertions, 2 deletions
diff --git a/cli/module_loader.rs b/cli/module_loader.rs
index 6f1a23761..b47e2efee 100644
--- a/cli/module_loader.rs
+++ b/cli/module_loader.rs
@@ -786,7 +786,7 @@ impl NpmModuleLoader {
permissions,
)?
} else {
- // esm code is untouched
+ // esm and json code is untouched
code
};
Ok(ModuleCodeSource {
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs
index ddb815a15..34b6add26 100644
--- a/cli/tests/integration/npm_tests.rs
+++ b/cli/tests/integration/npm_tests.rs
@@ -2119,6 +2119,20 @@ itest!(reserved_word_exports {
http_server: true,
});
+itest!(import_json {
+ args: "run -A --quiet npm/import_json/main.js",
+ output: "npm/import_json/main.out",
+ envs: env_vars_for_npm_tests(),
+ http_server: true,
+});
+
+itest!(dynamic_import_json {
+ args: "run -A --quiet npm/import_json/main.js",
+ output: "npm/import_json/main.out",
+ envs: env_vars_for_npm_tests(),
+ http_server: true,
+});
+
itest!(check_package_file_dts_dmts_dcts {
args: "check npm/file_dts_dmts_dcts/main.ts",
output: "npm/file_dts_dmts_dcts/main.out",
diff --git a/cli/tests/testdata/npm/dynamic_import_json/main.js b/cli/tests/testdata/npm/dynamic_import_json/main.js
new file mode 100644
index 000000000..6d8abfc9e
--- /dev/null
+++ b/cli/tests/testdata/npm/dynamic_import_json/main.js
@@ -0,0 +1,4 @@
+const info = await import("npm:@denotest/binary-package@1/package.json", {
+ assert: { type: "json" },
+});
+console.log(json);
diff --git a/cli/tests/testdata/npm/dynamic_import_json/main.out b/cli/tests/testdata/npm/dynamic_import_json/main.out
new file mode 100644
index 000000000..07f48e8a5
--- /dev/null
+++ b/cli/tests/testdata/npm/dynamic_import_json/main.out
@@ -0,0 +1,14 @@
+[Module: null prototype] {
+ default: {
+ {
+ name: "@denotest/binary-package",
+ version: "1.0.0",
+ main: "index.js",
+ optionalDependencies: {
+ "@denotest/binary-package-linux": "1.0.0",
+ "@denotest/binary-package-mac": "1.0.0",
+ "@denotest/binary-package-windows": "1.0.0"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/cli/tests/testdata/npm/import_json/main.js b/cli/tests/testdata/npm/import_json/main.js
new file mode 100644
index 000000000..b752bdef8
--- /dev/null
+++ b/cli/tests/testdata/npm/import_json/main.js
@@ -0,0 +1,4 @@
+import json from "npm:@denotest/binary-package@1/package.json" assert {
+ type: "json",
+};
+console.log(json);
diff --git a/cli/tests/testdata/npm/import_json/main.out b/cli/tests/testdata/npm/import_json/main.out
new file mode 100644
index 000000000..7db7ec4ea
--- /dev/null
+++ b/cli/tests/testdata/npm/import_json/main.out
@@ -0,0 +1,10 @@
+{
+ name: "@denotest/binary-package",
+ version: "1.0.0",
+ main: "index.js",
+ optionalDependencies: {
+ "@denotest/binary-package-linux": "1.0.0",
+ "@denotest/binary-package-mac": "1.0.0",
+ "@denotest/binary-package-windows": "1.0.0"
+ }
+}
diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs
index bb25124bf..6e4637286 100644
--- a/ext/node/resolution.rs
+++ b/ext/node/resolution.rs
@@ -446,7 +446,7 @@ impl NodeResolver {
url: ModuleSpecifier,
) -> Result<NodeResolution, AnyError> {
let url_str = url.as_str().to_lowercase();
- if url_str.starts_with("http") {
+ if url_str.starts_with("http") || url_str.ends_with(".json") {
Ok(NodeResolution::Esm(url))
} else if url_str.ends_with(".js") || url_str.ends_with(".d.ts") {
let maybe_package_config =