knip 3.4.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -195,6 +195,7 @@ export class WorkspaceWorker {
195
195
  manifest: this.manifest,
196
196
  config: pluginConfig,
197
197
  isProduction: this.isProduction,
198
+ enabledPlugins: this.enabledPlugins,
198
199
  });
199
200
  dependencies.forEach(specifier => {
200
201
  pluginDependencies.add(specifier);
@@ -4,7 +4,7 @@ import { findVitestDependencies } from '../vitest/index.js';
4
4
  export const NAME = 'Vite';
5
5
  export const ENABLERS = ['vite'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- export const CONFIG_FILE_PATTERNS = ['vite.config.{js,mjs,ts,cjs,mts,cts}'];
7
+ export const CONFIG_FILE_PATTERNS = ['vite*.config.{js,mjs,ts,cjs,mts,cts}'];
8
8
  const findViteDependencies = async (configFilePath, options) => {
9
9
  const localConfig = await load(configFilePath);
10
10
  if (!localConfig)
@@ -8,7 +8,7 @@ export const NAME = 'Vitest';
8
8
  export const ENABLERS = ['vitest'];
9
9
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
10
10
  export const CONFIG_FILE_PATTERNS = [
11
- 'vitest.config.{js,mjs,ts,cjs,mts,cts}',
11
+ 'vitest*.config.{js,mjs,ts,cjs,mts,cts}',
12
12
  'vitest.{workspace,projects}.{ts,js,json}',
13
13
  ];
14
14
  export const ENTRY_FILE_PATTERNS = ['**/*.{test,spec}.?(c|m)[jt]s?(x)'];
@@ -19,17 +19,23 @@ const resolveEntry = (containingFilePath, specifier) => {
19
19
  return toEntryPattern(relative(dir, resolvedPath));
20
20
  return specifier;
21
21
  };
22
+ const enablesCoverageInScript = /vitest(.+)--coverage(?:\.enabled(?:=true)?)?/;
23
+ const hasScriptWithCoverage = (scripts) => {
24
+ return Object.values(scripts).some(script => {
25
+ return enablesCoverageInScript.test(script);
26
+ });
27
+ };
22
28
  const findConfigDependencies = (configFilePath, localConfig, options) => {
23
- const { isProduction, config } = options;
29
+ const { isProduction, config, manifest } = options;
24
30
  const testConfig = localConfig.test;
25
31
  const entryPatterns = (config?.entry ?? testConfig?.include ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
26
32
  if (!testConfig || isProduction)
27
33
  return entryPatterns;
28
34
  const environments = testConfig.environment ? [getEnvPackageName(testConfig.environment)] : [];
29
35
  const reporters = getExternalReporters(testConfig.reporters);
30
- const coverage = testConfig.coverage && testConfig.coverage.enabled !== false
31
- ? [`@vitest/coverage-${testConfig.coverage.provider ?? 'v8'}`]
32
- : [];
36
+ const hasCoverageEnabled = (testConfig.coverage && testConfig.coverage.enabled !== false) ||
37
+ (manifest.scripts !== undefined && hasScriptWithCoverage(manifest.scripts));
38
+ const coverage = hasCoverageEnabled ? [`@vitest/coverage-${testConfig.coverage?.provider ?? 'v8'}`] : [];
33
39
  const setupFiles = [testConfig.setupFiles ?? []].flat().map(v => resolveEntry(configFilePath, v));
34
40
  const globalSetup = [testConfig.globalSetup ?? []].flat().map(v => resolveEntry(configFilePath, v));
35
41
  return [...entryPatterns, ...environments, ...reporters, ...coverage, ...setupFiles, ...globalSetup];
@@ -49,7 +55,7 @@ export const findVitestDependencies = async (configFilePath, localConfig, option
49
55
  }
50
56
  const entry = localConfig.build?.lib?.entry ?? [];
51
57
  const dependencies = (typeof entry === 'string' ? [entry] : Object.values(entry)).map(specifier => resolveEntry(configFilePath, specifier));
52
- if (!localConfig.test)
58
+ if (!options.enabledPlugins.includes('vitest'))
53
59
  return dependencies;
54
60
  return [...dependencies, ...findConfigDependencies(configFilePath, localConfig, options)];
55
61
  };
@@ -7,7 +7,7 @@ import { getDependenciesFromConfig } from '../babel/index.js';
7
7
  export const NAME = 'Webpack';
8
8
  export const ENABLERS = ['webpack'];
9
9
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
10
- export const CONFIG_FILE_PATTERNS = ['webpack.config*.{js,ts}'];
10
+ export const CONFIG_FILE_PATTERNS = ['webpack.config*.{js,ts,mjs,cjs,mts,cts}'];
11
11
  const hasBabelOptions = (use) => Boolean(use) &&
12
12
  typeof use !== 'string' &&
13
13
  'loader' in use &&
@@ -87,7 +87,7 @@ const findWebpackDependencies = async (configFilePath, options) => {
87
87
  if (isProduction)
88
88
  return [...entryPatterns];
89
89
  const scripts = Object.values(manifest.scripts ?? {});
90
- const webpackCLI = scripts.some(script => script?.includes('webpack ')) ? ['webpack-cli'] : [];
90
+ const webpackCLI = scripts.some(script => script && /(?<=^|\s)webpack(?=\s|$)/.test(script)) ? ['webpack-cli'] : [];
91
91
  const webpackDevServer = scripts.some(script => script?.includes('webpack serve')) ? ['webpack-dev-server'] : [];
92
92
  return compact([...entryPatterns, ...dependencies, ...webpackCLI, ...webpackDevServer]);
93
93
  };
@@ -12,6 +12,7 @@ export type GenericPluginCallbackOptions = {
12
12
  manifest: PackageJsonWithPlugins;
13
13
  config: EnsuredPluginConfiguration;
14
14
  isProduction: boolean;
15
+ enabledPlugins: string[];
15
16
  };
16
17
  export type GenericPluginCallback = (configFilePath: string, options: GenericPluginCallbackOptions) => Promise<string[]> | string[];
17
18
  export {};
@@ -1,4 +1,4 @@
1
- export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolated workspaces in monorepo\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
1
+ export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolated workspaces in monorepo\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n\nWebsite: https://knip.dev";
2
2
  declare const _default: {
3
3
  config: string | undefined;
4
4
  debug: boolean | undefined;
@@ -40,7 +40,7 @@ $ knip --workspace packages/client --include files,dependencies
40
40
  $ knip -c ./config/knip.json --reporter compact
41
41
  $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
42
42
 
43
- More documentation and bug reports: https://github.com/webpro/knip`;
43
+ Website: https://knip.dev`;
44
44
  let parsedArgs;
45
45
  try {
46
46
  parsedArgs = parseArgs({
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "3.4.0";
1
+ export declare const version = "3.5.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '3.4.0';
1
+ export const version = '3.5.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {