1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-02 20:38:47 -05:00

fix(npm): don't fail if conditional exports don't contains types (#16651)

If resolving types for an npm package, we didn't find "types" entry in 
the conditional exports declaration we were falling-through to regular 
resolution, instead of short-circuiting and giving up on resolving
types, which might lead to unwarranted errors.

Closes https://github.com/denoland/deno/issues/16649
This commit is contained in:
Bartek Iwańczuk 2022-11-16 01:40:03 +01:00 committed by GitHub
parent 7aa8e9c035
commit 300fd07fad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 0 deletions

View file

@ -688,6 +688,8 @@ fn package_config_resolve(
legacy_main_resolve(&package_config, referrer_kind, conditions) legacy_main_resolve(&package_config, referrer_kind, conditions)
{ {
return Ok(Some(path)); return Ok(Some(path));
} else {
return Ok(None);
} }
} }
return package_exports_resolve( return package_exports_resolve(

View file

@ -263,6 +263,14 @@ itest!(types_ambient_module_import_map {
exit_code: 1, exit_code: 1,
}); });
itest!(no_types_in_conditional_exports {
args: "run --check --unstable npm/no_types_in_conditional_exports/main.ts",
output: "npm/no_types_in_conditional_exports/main.out",
exit_code: 0,
envs: env_vars(),
http_server: true,
});
#[test] #[test]
fn parallel_downloading() { fn parallel_downloading() {
let (out, _err) = util::run_and_collect_output_with_args( let (out, _err) = util::run_and_collect_output_with_args(

View file

@ -0,0 +1,5 @@
Download http://localhost:4545/npm/registry/@denotest/no-types-in-conditional-exports
Download http://localhost:4545/npm/registry/@denotest/no-types-in-conditional-exports/1.0.0.tgz
Check [WILDCARD]npm/no_types_in_conditional_exports/main.ts
[WILDCARD]
{ foo: "bar" }

View file

@ -0,0 +1,2 @@
import foo from "npm:@denotest/no-types-in-conditional-exports@1.0.0";
console.log(foo);

View file

@ -0,0 +1,3 @@
export default {
"foo": "bar"
};

View file

@ -0,0 +1,3 @@
module.exports = {
"foo": "bar"
};

View file

@ -0,0 +1,14 @@
{
"name": "@denotest/no-types-in-conditional-exports",
"version": "1.0.0",
"main": "./lib/foo.js",
"module": "./lib/foo-esm.js",
"exports": {
".": {
"require": "./lib/foo.js",
"import": "./lib/foo-esm.js"
},
"./*": "./*"
},
"type": "module"
}