knip 5.30.4 → 5.30.6

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.
@@ -34,7 +34,7 @@ export declare class WorkspaceWorker {
34
34
  isStrict: boolean;
35
35
  rootIgnore: Configuration['ignore'];
36
36
  negatedWorkspacePatterns: string[];
37
- enabledPluginsMap: Record<"angular" | "astro" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "drizzle" | "eleventy" | "eslint" | "gatsby" | "githubActions" | "graphqlCodegen" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "lintStaged" | "lockfileLint" | "lostPixel" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nodeTestRunner" | "npmPackageJsonLint" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "playwrightCt" | "postcss" | "preconstruct" | "prettier" | "reactCosmos" | "releaseIt" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "semanticRelease" | "sentry" | "simpleGitHooks" | "sizeLimit" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vercelOg" | "vike" | "vite" | "vitest" | "vue" | "webdriverIo" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie", boolean>;
37
+ enabledPluginsMap: Record<"astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo", boolean>;
38
38
  enabledPlugins: PluginName[];
39
39
  enabledPluginsInAncestors: string[];
40
40
  cache: CacheConsultant<CacheItem>;
@@ -55,7 +55,7 @@ export declare class WorkspaceWorker {
55
55
  entryFilePatterns: Set<string>;
56
56
  productionEntryFilePatterns: Set<string>;
57
57
  referencedDependencies: ReferencedDependencies;
58
- enabledPlugins: ("angular" | "astro" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "drizzle" | "eleventy" | "eslint" | "gatsby" | "githubActions" | "graphqlCodegen" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "lintStaged" | "lockfileLint" | "lostPixel" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nodeTestRunner" | "npmPackageJsonLint" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "playwrightCt" | "postcss" | "preconstruct" | "prettier" | "reactCosmos" | "releaseIt" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "semanticRelease" | "sentry" | "simpleGitHooks" | "sizeLimit" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vercelOg" | "vike" | "vite" | "vitest" | "vue" | "webdriverIo" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie")[];
58
+ enabledPlugins: ("astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo")[];
59
59
  }>;
60
60
  onDispose(): void;
61
61
  }
@@ -6,10 +6,11 @@ const enablers = ['@playwright/test'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
7
  const config = ['playwright.config.{js,ts}'];
8
8
  export const entry = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
9
- const toEntryPatterns = (testMatch, cwd, configDir, localConfig) => {
9
+ const toEntryPatterns = (testMatch, cwd, configDir, localConfig, rootConfig) => {
10
10
  if (!testMatch)
11
11
  return [];
12
- const dir = relative(cwd, localConfig.testDir ? join(configDir, localConfig.testDir) : configDir);
12
+ const testDir = localConfig.testDir ?? rootConfig.testDir;
13
+ const dir = relative(cwd, testDir ? join(configDir, testDir) : configDir);
13
14
  const patterns = [testMatch].flat().filter((p) => typeof p === 'string');
14
15
  return patterns.map(pattern => toEntryPattern(join(dir, pattern)));
15
16
  };
@@ -17,7 +18,7 @@ const builtinReporters = ['dot', 'line', 'list', 'junit', 'html', 'blob', 'json'
17
18
  export const resolveEntryPaths = async (localConfig, options) => {
18
19
  const { cwd, configFileDir } = options;
19
20
  const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig];
20
- return projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFileDir, config));
21
+ return projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFileDir, config, localConfig));
21
22
  };
22
23
  export const resolveConfig = async (config) => {
23
24
  const reporters = [config.reporter].flat().flatMap(reporter => {
@@ -26,3 +26,5 @@ export declare const isImportSpecifier: (node: ts.Node) => boolean;
26
26
  export declare const isReferencedInExportedType: (node: ts.Node) => boolean;
27
27
  export declare const getExportKeywordNode: (node: ts.Node) => ts.ExportKeyword | undefined;
28
28
  export declare const getDefaultKeywordNode: (node: ts.Node) => ts.DefaultKeyword | undefined;
29
+ export declare const hasRequireCall: (node: ts.Node) => boolean;
30
+ export declare const isModuleExportsAccess: (node: ts.PropertyAccessExpression) => boolean;
@@ -170,3 +170,9 @@ export const isReferencedInExportedType = (node) => {
170
170
  };
171
171
  export const getExportKeywordNode = (node) => node.modifiers?.find(mod => mod.kind === ts.SyntaxKind.ExportKeyword);
172
172
  export const getDefaultKeywordNode = (node) => node.modifiers?.find(mod => mod.kind === ts.SyntaxKind.DefaultKeyword);
173
+ export const hasRequireCall = (node) => {
174
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'require')
175
+ return true;
176
+ return node.getChildren().some(child => hasRequireCall(child));
177
+ };
178
+ export const isModuleExportsAccess = (node) => ts.isIdentifier(node.expression) && node.expression.escapedText === 'module' && node.name.escapedText === 'exports';
@@ -102,9 +102,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
102
102
  if (module.isExternalLibraryImport) {
103
103
  if (skipTypeOnly && isTypeOnly)
104
104
  return;
105
- const sanitizedSpecifier = isInNodeModules(specifier)
106
- ? getPackageNameFromFilePath(specifier)
107
- : sanitizeSpecifier(specifier);
105
+ const sanitizedSpecifier = sanitizeSpecifier(isInNodeModules(specifier) || isInNodeModules(filePath) ? getPackageNameFromFilePath(specifier) : specifier);
108
106
  if (!isStartsLikePackageName(sanitizedSpecifier)) {
109
107
  return;
110
108
  }
@@ -1,5 +1,6 @@
1
1
  import ts from 'typescript';
2
- import { findAncestor, findDescendants, isRequireCall, isTopLevel } from '../../ast-helpers.js';
2
+ import { IMPORT_STAR } from '../../../constants.js';
3
+ import { findAncestor, findDescendants, isModuleExportsAccess, isRequireCall, isTopLevel } from '../../ast-helpers.js';
3
4
  import { isNotJS } from '../helpers.js';
4
5
  import { importVisitor as visit } from '../index.js';
5
6
  export default visit(() => true, node => {
@@ -43,6 +44,11 @@ export default visit(() => true, node => {
43
44
  }
44
45
  return { identifier: 'default', specifier, pos: node.arguments[0].pos, resolve };
45
46
  }
47
+ if (ts.isBinaryExpression(node.parent) &&
48
+ ts.isPropertyAccessExpression(node.parent.left) &&
49
+ isModuleExportsAccess(node.parent.left)) {
50
+ return { identifier: IMPORT_STAR, specifier, isReExport: true, pos: node.arguments[0].pos };
51
+ }
46
52
  return { identifier: 'default', specifier, pos: node.arguments[0].pos, resolve };
47
53
  }
48
54
  }
@@ -1,9 +1,8 @@
1
1
  import ts from 'typescript';
2
2
  import { SymbolType } from '../../../types/issues.js';
3
- import { stripQuotes } from '../../ast-helpers.js';
3
+ import { hasRequireCall, isModuleExportsAccess, stripQuotes } from '../../ast-helpers.js';
4
4
  import { isJS } from '../helpers.js';
5
5
  import { exportVisitor as visit } from '../index.js';
6
- const isModuleExportsAccess = (node) => ts.isIdentifier(node.expression) && node.expression.escapedText === 'module' && node.name.escapedText === 'exports';
7
6
  export default visit(isJS, (node, { isFixExports }) => {
8
7
  if (ts.isExpressionStatement(node)) {
9
8
  if (ts.isBinaryExpression(node.expression)) {
@@ -29,6 +28,9 @@ export default visit(isJS, (node, { isFixExports }) => {
29
28
  return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.getStart(), fix };
30
29
  });
31
30
  }
31
+ if (ts.isCallExpression(node.expression.right) && hasRequireCall(node.expression.right)) {
32
+ return;
33
+ }
32
34
  return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: expr.pos + 1, fix: undefined };
33
35
  }
34
36
  }
@@ -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 test files, devDependencies)\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 --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\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 --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\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 --tags Include or exclude tagged exports\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(2) Fixable issue types: dependencies, exports, types\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$ knip --tags=-knipignore\n\nWebsite: https://knip.dev";
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 test files, devDependencies)\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 --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\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 --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\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 --tags Include or exclude tagged exports\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 --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\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(2) Fixable issue types: dependencies, exports, types\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$ knip --tags=-knipignore\n\nWebsite: https://knip.dev";
2
2
  declare const _default: {
3
3
  cache: boolean | undefined;
4
4
  'cache-location': string | undefined;
@@ -35,6 +35,9 @@ Options:
35
35
  --no-exit-code Always exit with code zero (0)
36
36
  --max-issues Maximum number of issues before non-zero exit code (default: 0)
37
37
  -d, --debug Show debug output
38
+ --trace Show trace output
39
+ --trace-export [name] Show trace output for named export(s)
40
+ --trace-file [file] Show trace output for exports in file
38
41
  --performance Measure count and running time of expensive functions and display stats table
39
42
  -h, --help Print this help text
40
43
  -V, --version Print version
@@ -14,7 +14,7 @@ export const getPackageNameFromFilePath = (value) => {
14
14
  return match[match.length - 1];
15
15
  return value;
16
16
  };
17
- export const isStartsLikePackageName = (specifier) => /^@?[a-z0-9]/.test(specifier);
17
+ export const isStartsLikePackageName = (specifier) => /^(@[a-z0-9._]|[a-z0-9])/.test(specifier);
18
18
  export const isDefinitelyTyped = (packageName) => packageName.startsWith(`${DT_SCOPE}/`);
19
19
  export const getDefinitelyTypedFor = (packageName) => {
20
20
  if (isDefinitelyTyped(packageName))
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.30.4";
1
+ export declare const version = "5.30.6";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.30.4';
1
+ export const version = '5.30.6';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.30.4",
3
+ "version": "5.30.6",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {