Skip to content

Commit

Permalink
Merge node and node-test-runner plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Feb 10, 2025
1 parent 72cbcfa commit 1019b99
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 29 deletions.
2 changes: 0 additions & 2 deletions packages/knip/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { default as msw } from './msw/index.js';
import { default as nest } from './nest/index.js';
import { default as netlify } from './netlify/index.js';
import { default as next } from './next/index.js';
import { default as nodeTestRunner } from './node-test-runner/index.js';
import { default as node } from './node/index.js';
import { default as nodemon } from './nodemon/index.js';
import { default as npmPackageJsonLint } from './npm-package-json-lint/index.js';
Expand Down Expand Up @@ -133,7 +132,6 @@ export const Plugins = {
netlify,
next,
node,
'node-test-runner': nodeTestRunner,
nodemon,
'npm-package-json-lint': npmPackageJsonLint,
nuxt,
Expand Down
22 changes: 0 additions & 22 deletions packages/knip/src/plugins/node-test-runner/index.ts

This file was deleted.

26 changes: 25 additions & 1 deletion packages/knip/src/plugins/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
import type { Plugin } from '../../types/config.js';
import type { IsPluginEnabled, Plugin, ResolveEntryPaths } from '../../types/config.js';
import type { PackageJson } from '../../types/package-json.js';
import { toEntry } from '../../util/input.js';

const title = 'Node.js';

const isEnabled: IsPluginEnabled = () => true;

const config = ['package.json'];

const packageJsonPath = (id: PackageJson) => id;

const resolveEntryPaths: ResolveEntryPaths<PackageJson> = localConfig => {
const scripts = localConfig.scripts;

const entry = ['server.js'];

if (scripts && Object.keys(scripts).some(script => /(?<=^|\s)node\s(.*)--test/.test(scripts[script]))) {
entry.push(...['**/*{.,-,_}test.?(c|m)js', '**/test-*.?(c|m)js', '**/test.?(c|m)js', '**/test/**/*.?(c|m)js']);
}

return entry.map(toEntry);
};

const args = {
positional: true,
nodeImportArgs: true,
};

export default {
title,
isEnabled,
packageJsonPath,
config,
resolveEntryPaths,
args,
} satisfies Plugin;
1 change: 0 additions & 1 deletion packages/knip/src/schema/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const pluginsSchema = z.object({
netlify: pluginSchema,
next: pluginSchema,
node: pluginSchema,
'node-test-runner': pluginSchema,
nodemon: pluginSchema,
'npm-package-json-lint': pluginSchema,
nuxt: pluginSchema,
Expand Down
2 changes: 0 additions & 2 deletions packages/knip/src/types/PluginNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export type PluginName =
| 'netlify'
| 'next'
| 'node'
| 'node-test-runner'
| 'nodemon'
| 'npm-package-json-lint'
| 'nuxt'
Expand Down Expand Up @@ -134,7 +133,6 @@ export const pluginNames = [
'netlify',
'next',
'node',
'node-test-runner',
'nodemon',
'npm-package-json-lint',
'nuxt',
Expand Down
2 changes: 1 addition & 1 deletion packages/knip/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export type Resolve = (options: PluginOptions) => Promise<Input[]> | Input[];
export interface Plugin {
title: string;
args?: Args;
packageJsonPath?: string | ((manifest: PackageJson) => string);
packageJsonPath?: string | ((manifest: PackageJson) => unknown);
enablers?: IgnorePatterns | string;
isEnabled?: IsPluginEnabled;
isRootOnly?: boolean;
Expand Down

0 comments on commit 1019b99

Please sign in to comment.