0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

fix(ext/node): fix import json using npm specifier (#19723)

This commit is contained in:
await-ovo 2023-08-02 07:20:08 +08:00 committed by GitHub
parent 21f1b2f62b
commit fec34d8069
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 2 deletions

View file

@ -786,7 +786,7 @@ impl NpmModuleLoader {
permissions,
)?
} else {
// esm code is untouched
// esm and json code is untouched
code
};
Ok(ModuleCodeSource {

View file

@ -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",

View file

@ -0,0 +1,4 @@
const info = await import("npm:@denotest/binary-package@1/package.json", {
assert: { type: "json" },
});
console.log(json);

View file

@ -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"
}
}
}
}

View file

@ -0,0 +1,4 @@
import json from "npm:@denotest/binary-package@1/package.json" assert {
type: "json",
};
console.log(json);

View file

@ -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"
}
}

View file

@ -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 =