diff options
12 files changed, 34 insertions, 17 deletions
diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-a.d.ts b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-a.d.ts new file mode 100644 index 000000000..f49faf22f --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-a.d.ts @@ -0,0 +1 @@ +export function entryA(): 12; diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.js b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-a.js index 070b1ccbd..070b1ccbd 100644 --- a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.js +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-a.js diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.d.ts b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.d.ts deleted file mode 100644 index e18f8b551..000000000 --- a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.d.ts +++ /dev/null @@ -1 +0,0 @@ -export function entryC(): 12; diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-b.d.ts b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-b.d.ts deleted file mode 100644 index 79c9c8434..000000000 --- a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-b.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// it will go to this and not the types entry because this entry was first -export function entryB(): string;
\ No newline at end of file diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.d.ts b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.d.ts new file mode 100644 index 000000000..253279e6c --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.d.ts @@ -0,0 +1 @@ +export function entryImport(): "import"; diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.js b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-import.js diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-js-only.js b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-js-only.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-js-only.js diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-types.d.ts b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-types.d.ts new file mode 100644 index 000000000..bd1ff702f --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-types.d.ts @@ -0,0 +1 @@ +export function entryTypes(): "types"; diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/package.json index 35a1cd9f5..169017560 100644 --- a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/package.json +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/package.json @@ -8,12 +8,16 @@ }, "import": "./dist/client.mjs" }, - "./entry-b": { - "import": "./entry-b.d.ts", - "types": "./dist/entry-b-wrong.d.ts" + "./entry-import": { + "import": "./entry-import.d.ts", + "types": "./entry-types.d.ts" }, - "./entry-c": { - "import": "./dist/entry-c.js" + "./entry-types-last-no-declaration-before": { + "import": "./entry-js-only.js", + "types": "./entry-types.d.ts" + }, + "./entry-a": { + "import": "./dist/entry-a.js" } } } diff --git a/cli/tests/testdata/npm/types/main.out b/cli/tests/testdata/npm/types/main.out index 47d72f74c..de1f2c145 100644 --- a/cli/tests/testdata/npm/types/main.out +++ b/cli/tests/testdata/npm/types/main.out @@ -53,14 +53,19 @@ const valueA: "test1" = getClient(); ~~~~~~ at [WILDCARD]/npm/types/main.ts:[WILDCARD] -TS2322 [ERROR]: Type 'string' is not assignable to type '"test2"'. -const valueB: "test2" = entryB(); +TS2322 [ERROR]: Type '"import"' is not assignable to type '"test2"'. +const valueB: "test2" = entryImport(); ~~~~~~ at [WILDCARD]/types/main.ts:[WILDCARD] TS2322 [ERROR]: Type '12' is not assignable to type '"test3"'. -const valueC: "test3" = entryC(); +const valueC: "test3" = entryA(); ~~~~~~ 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. diff --git a/cli/tests/testdata/npm/types/main.ts b/cli/tests/testdata/npm/types/main.ts index fb8b65c98..ae420f6d6 100644 --- a/cli/tests/testdata/npm/types/main.ts +++ b/cli/tests/testdata/npm/types/main.ts @@ -2,8 +2,9 @@ import type { Fizzbuzz } from "npm:@denotest/types"; import type { SomeInterface } from "npm:@denotest/types_imported"; import type { Foobar as FooInterface } from "npm:@denotest/types_imported/subpath"; import { getClient } from "npm:@denotest/types-exports-subpaths/client"; -import { entryB } from "npm:@denotest/types-exports-subpaths/entry-b"; -import { entryC } from "npm:@denotest/types-exports-subpaths/entry-c"; +import { entryImport } from "npm:@denotest/types-exports-subpaths/entry-import"; +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 = { foo: "foo", @@ -21,5 +22,6 @@ const fizzbuzz: Fizzbuzz = { }; const valueA: "test1" = getClient(); -const valueB: "test2" = entryB(); -const valueC: "test3" = entryC(); +const valueB: "test2" = entryImport(); +const valueC: "test3" = entryA(); +const valueD: "test4" = entryTypes(); diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs index 95099d14e..7500f0f31 100644 --- a/ext/node/resolution.rs +++ b/ext/node/resolution.rs @@ -445,7 +445,13 @@ fn resolve_package_target( mode, 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() { if target_arr.is_empty() { return Ok(None); |