Skip to content

Commit 1019b99

Browse files
committedFeb 10, 2025
Merge node and node-test-runner plugins
1 parent 72cbcfa commit 1019b99

File tree

6 files changed

+26
-29
lines changed

6 files changed

+26
-29
lines changed
 

‎packages/knip/src/plugins/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { default as msw } from './msw/index.js';
3838
import { default as nest } from './nest/index.js';
3939
import { default as netlify } from './netlify/index.js';
4040
import { default as next } from './next/index.js';
41-
import { default as nodeTestRunner } from './node-test-runner/index.js';
4241
import { default as node } from './node/index.js';
4342
import { default as nodemon } from './nodemon/index.js';
4443
import { default as npmPackageJsonLint } from './npm-package-json-lint/index.js';
@@ -133,7 +132,6 @@ export const Plugins = {
133132
netlify,
134133
next,
135134
node,
136-
'node-test-runner': nodeTestRunner,
137135
nodemon,
138136
'npm-package-json-lint': npmPackageJsonLint,
139137
nuxt,

‎packages/knip/src/plugins/node-test-runner/index.ts

-22
This file was deleted.
+25-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
import type { Plugin } from '../../types/config.js';
1+
import type { IsPluginEnabled, Plugin, ResolveEntryPaths } from '../../types/config.js';
2+
import type { PackageJson } from '../../types/package-json.js';
3+
import { toEntry } from '../../util/input.js';
24

35
const title = 'Node.js';
46

7+
const isEnabled: IsPluginEnabled = () => true;
8+
9+
const config = ['package.json'];
10+
11+
const packageJsonPath = (id: PackageJson) => id;
12+
13+
const resolveEntryPaths: ResolveEntryPaths<PackageJson> = localConfig => {
14+
const scripts = localConfig.scripts;
15+
16+
const entry = ['server.js'];
17+
18+
if (scripts && Object.keys(scripts).some(script => /(?<=^|\s)node\s(.*)--test/.test(scripts[script]))) {
19+
entry.push(...['**/*{.,-,_}test.?(c|m)js', '**/test-*.?(c|m)js', '**/test.?(c|m)js', '**/test/**/*.?(c|m)js']);
20+
}
21+
22+
return entry.map(toEntry);
23+
};
24+
525
const args = {
626
positional: true,
727
nodeImportArgs: true,
828
};
929

1030
export default {
1131
title,
32+
isEnabled,
33+
packageJsonPath,
34+
config,
35+
resolveEntryPaths,
1236
args,
1337
} satisfies Plugin;

‎packages/knip/src/schema/plugins.ts

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export const pluginsSchema = z.object({
5353
netlify: pluginSchema,
5454
next: pluginSchema,
5555
node: pluginSchema,
56-
'node-test-runner': pluginSchema,
5756
nodemon: pluginSchema,
5857
'npm-package-json-lint': pluginSchema,
5958
nuxt: pluginSchema,

‎packages/knip/src/types/PluginNames.ts

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export type PluginName =
4040
| 'netlify'
4141
| 'next'
4242
| 'node'
43-
| 'node-test-runner'
4443
| 'nodemon'
4544
| 'npm-package-json-lint'
4645
| 'nuxt'
@@ -134,7 +133,6 @@ export const pluginNames = [
134133
'netlify',
135134
'next',
136135
'node',
137-
'node-test-runner',
138136
'nodemon',
139137
'npm-package-json-lint',
140138
'nuxt',

‎packages/knip/src/types/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export type Resolve = (options: PluginOptions) => Promise<Input[]> | Input[];
125125
export interface Plugin {
126126
title: string;
127127
args?: Args;
128-
packageJsonPath?: string | ((manifest: PackageJson) => string);
128+
packageJsonPath?: string | ((manifest: PackageJson) => unknown);
129129
enablers?: IgnorePatterns | string;
130130
isEnabled?: IsPluginEnabled;
131131
isRootOnly?: boolean;

0 commit comments

Comments
 (0)
Please sign in to comment.