From fec34d8069517be195193cd3578e7988d39fd0e1 Mon Sep 17 00:00:00 2001 From: await-ovo <13152410380@163.com> Date: Wed, 2 Aug 2023 07:20:08 +0800 Subject: fix(ext/node): fix import json using npm specifier (#19723) --- cli/module_loader.rs | 2 +- cli/tests/integration/npm_tests.rs | 14 ++++++++++++++ cli/tests/testdata/npm/dynamic_import_json/main.js | 4 ++++ cli/tests/testdata/npm/dynamic_import_json/main.out | 14 ++++++++++++++ cli/tests/testdata/npm/import_json/main.js | 4 ++++ cli/tests/testdata/npm/import_json/main.out | 10 ++++++++++ 6 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 cli/tests/testdata/npm/dynamic_import_json/main.js create mode 100644 cli/tests/testdata/npm/dynamic_import_json/main.out create mode 100644 cli/tests/testdata/npm/import_json/main.js create mode 100644 cli/tests/testdata/npm/import_json/main.out (limited to 'cli') 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" + } +} -- cgit v1.2.3