mirror of
https://github.com/denoland/deno.git
synced 2024-12-17 21:03:01 -05:00
fix(npm): handle declaration file resolution where packages incorrectly define "types" last in "exports" (#17290)
Closes #17279
This commit is contained in:
parent
4289ba0f77
commit
ab07129ee7
12 changed files with 34 additions and 17 deletions
1
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-a.d.ts
vendored
Normal file
1
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-a.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export function entryA(): 12;
|
|
@ -1 +0,0 @@
|
||||||
export function entryC(): 12;
|
|
|
@ -1,2 +0,0 @@
|
||||||
// it will go to this and not the types entry because this entry was first
|
|
||||||
export function entryB(): string;
|
|
1
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.d.ts
vendored
Normal file
1
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export function entryImport(): "import";
|
0
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.js
vendored
Normal file
0
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.js
vendored
Normal file
0
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-js-only.js
vendored
Normal file
0
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-js-only.js
vendored
Normal file
1
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-types.d.ts
vendored
Normal file
1
cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-types.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export function entryTypes(): "types";
|
|
@ -8,12 +8,16 @@
|
||||||
},
|
},
|
||||||
"import": "./dist/client.mjs"
|
"import": "./dist/client.mjs"
|
||||||
},
|
},
|
||||||
"./entry-b": {
|
"./entry-import": {
|
||||||
"import": "./entry-b.d.ts",
|
"import": "./entry-import.d.ts",
|
||||||
"types": "./dist/entry-b-wrong.d.ts"
|
"types": "./entry-types.d.ts"
|
||||||
},
|
},
|
||||||
"./entry-c": {
|
"./entry-types-last-no-declaration-before": {
|
||||||
"import": "./dist/entry-c.js"
|
"import": "./entry-js-only.js",
|
||||||
|
"types": "./entry-types.d.ts"
|
||||||
|
},
|
||||||
|
"./entry-a": {
|
||||||
|
"import": "./dist/entry-a.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
cli/tests/testdata/npm/types/main.out
vendored
13
cli/tests/testdata/npm/types/main.out
vendored
|
@ -53,14 +53,19 @@ const valueA: "test1" = getClient();
|
||||||
~~~~~~
|
~~~~~~
|
||||||
at [WILDCARD]/npm/types/main.ts:[WILDCARD]
|
at [WILDCARD]/npm/types/main.ts:[WILDCARD]
|
||||||
|
|
||||||
TS2322 [ERROR]: Type 'string' is not assignable to type '"test2"'.
|
TS2322 [ERROR]: Type '"import"' is not assignable to type '"test2"'.
|
||||||
const valueB: "test2" = entryB();
|
const valueB: "test2" = entryImport();
|
||||||
~~~~~~
|
~~~~~~
|
||||||
at [WILDCARD]/types/main.ts:[WILDCARD]
|
at [WILDCARD]/types/main.ts:[WILDCARD]
|
||||||
|
|
||||||
TS2322 [ERROR]: Type '12' is not assignable to type '"test3"'.
|
TS2322 [ERROR]: Type '12' is not assignable to type '"test3"'.
|
||||||
const valueC: "test3" = entryC();
|
const valueC: "test3" = entryA();
|
||||||
~~~~~~
|
~~~~~~
|
||||||
at [WILDCARD]/types/main.ts:[WILDCARD]
|
at [WILDCARD]/types/main.ts:[WILDCARD]
|
||||||
|
|
||||||
Found 8 errors.
|
TS2322 [ERROR]: Type '"types"' is not assignable to type '"test4"'.
|
||||||
|
const valueD: "test4" = entryTypes();
|
||||||
|
~~~~~~
|
||||||
|
at file:///[WILDCARD]/types/main.ts:[WILDCARD]
|
||||||
|
|
||||||
|
Found 9 errors.
|
||||||
|
|
10
cli/tests/testdata/npm/types/main.ts
vendored
10
cli/tests/testdata/npm/types/main.ts
vendored
|
@ -2,8 +2,9 @@ import type { Fizzbuzz } from "npm:@denotest/types";
|
||||||
import type { SomeInterface } from "npm:@denotest/types_imported";
|
import type { SomeInterface } from "npm:@denotest/types_imported";
|
||||||
import type { Foobar as FooInterface } from "npm:@denotest/types_imported/subpath";
|
import type { Foobar as FooInterface } from "npm:@denotest/types_imported/subpath";
|
||||||
import { getClient } from "npm:@denotest/types-exports-subpaths/client";
|
import { getClient } from "npm:@denotest/types-exports-subpaths/client";
|
||||||
import { entryB } from "npm:@denotest/types-exports-subpaths/entry-b";
|
import { entryImport } from "npm:@denotest/types-exports-subpaths/entry-import";
|
||||||
import { entryC } from "npm:@denotest/types-exports-subpaths/entry-c";
|
import { entryA } from "npm:@denotest/types-exports-subpaths/entry-a";
|
||||||
|
import { entryTypes } from "npm:@denotest/types-exports-subpaths/entry-types-last-no-declaration-before";
|
||||||
|
|
||||||
const foobar: FooInterface = {
|
const foobar: FooInterface = {
|
||||||
foo: "foo",
|
foo: "foo",
|
||||||
|
@ -21,5 +22,6 @@ const fizzbuzz: Fizzbuzz = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const valueA: "test1" = getClient();
|
const valueA: "test1" = getClient();
|
||||||
const valueB: "test2" = entryB();
|
const valueB: "test2" = entryImport();
|
||||||
const valueC: "test3" = entryC();
|
const valueC: "test3" = entryA();
|
||||||
|
const valueD: "test4" = entryTypes();
|
||||||
|
|
|
@ -445,7 +445,13 @@ fn resolve_package_target(
|
||||||
mode,
|
mode,
|
||||||
npm_resolver,
|
npm_resolver,
|
||||||
)
|
)
|
||||||
.map(Some);
|
.map(|path| {
|
||||||
|
if mode.is_types() {
|
||||||
|
path_to_declaration_path(path, referrer_kind)
|
||||||
|
} else {
|
||||||
|
Some(path)
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if let Some(target_arr) = target.as_array() {
|
} else if let Some(target_arr) = target.as_array() {
|
||||||
if target_arr.is_empty() {
|
if target_arr.is_empty() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
|
|
Loading…
Reference in a new issue