From 296ab06d68b7e1790b5b9982dce24a82bc0af485 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Sat, 4 May 2024 10:44:35 +0200 Subject: [PATCH] Include package.json#types and typings (resolves #607) --- .../knip/fixtures/workspaces-dts/packages/client/client.d.ts | 0 .../fixtures/workspaces-dts/packages/client/package.json | 1 + .../fixtures/workspaces-dts/packages/server/package.json | 1 + .../knip/fixtures/workspaces-dts/packages/server/server.d.ts | 0 packages/knip/src/util/modules.ts | 5 ++++- packages/knip/test/workspaces-dts.test.ts | 4 ++-- 6 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 packages/knip/fixtures/workspaces-dts/packages/client/client.d.ts create mode 100644 packages/knip/fixtures/workspaces-dts/packages/server/server.d.ts diff --git a/packages/knip/fixtures/workspaces-dts/packages/client/client.d.ts b/packages/knip/fixtures/workspaces-dts/packages/client/client.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/knip/fixtures/workspaces-dts/packages/client/package.json b/packages/knip/fixtures/workspaces-dts/packages/client/package.json index 0481b60c1..36b2aef5d 100644 --- a/packages/knip/fixtures/workspaces-dts/packages/client/package.json +++ b/packages/knip/fixtures/workspaces-dts/packages/client/package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "private": true, "type": "module", + "types": "client.d.ts", "dependencies": { "@workspaces-dts/shared": "*" } diff --git a/packages/knip/fixtures/workspaces-dts/packages/server/package.json b/packages/knip/fixtures/workspaces-dts/packages/server/package.json index fbc97308a..a6dfb4963 100644 --- a/packages/knip/fixtures/workspaces-dts/packages/server/package.json +++ b/packages/knip/fixtures/workspaces-dts/packages/server/package.json @@ -3,6 +3,7 @@ "version": "0.0.0", "private": true, "type": "module", + "typings": "server.d.ts", "dependencies": { "@workspaces-dts/shared": "*" } diff --git a/packages/knip/fixtures/workspaces-dts/packages/server/server.d.ts b/packages/knip/fixtures/workspaces-dts/packages/server/server.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/knip/src/util/modules.ts b/packages/knip/src/util/modules.ts index 51f6dd10c..b949c621e 100644 --- a/packages/knip/src/util/modules.ts +++ b/packages/knip/src/util/modules.ts @@ -44,7 +44,7 @@ export const getEntryPathFromManifest = ( manifest: PackageJson, sharedGlobOptions: { cwd: string; workingDir: string; gitignore: boolean; ignore: string[] } ) => { - const { main, bin, exports } = manifest; + const { main, bin, exports, types, typings } = manifest; const entryPaths = new Set(); @@ -59,6 +59,9 @@ export const getEntryPathFromManifest = ( for (const item of getStringValues(exports)) entryPaths.add(item); } + if (typeof types === 'string') entryPaths.add(types); + if (typeof typings === 'string') entryPaths.add(typings); + // Use glob, as we only want source files that: // - exist // - are not (generated) files that are .gitignore'd diff --git a/packages/knip/test/workspaces-dts.test.ts b/packages/knip/test/workspaces-dts.test.ts index 04ce42a52..fe9511d75 100644 --- a/packages/knip/test/workspaces-dts.test.ts +++ b/packages/knip/test/workspaces-dts.test.ts @@ -18,7 +18,7 @@ test('Find unused un-built exports across workspaces', async () => { assert.deepEqual(counters, { ...baseCounters, exports: 1, - processed: 6, - total: 6, + processed: 8, + total: 8, }); });