knip 3.9.0 → 3.11.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.
@@ -3,7 +3,7 @@ import { compact } from '../util/array.js';
3
3
  import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
4
4
  import { extname, isInternal } from '../util/path.js';
5
5
  import { timerify } from '../util/Performance.js';
6
- import { isBinary } from '../util/protocols.js';
6
+ import { fromBinary, isBinary } from '../util/protocols.js';
7
7
  import { getBinariesFromScript } from './bash-parser.js';
8
8
  const defaultCwd = process.cwd();
9
9
  const getDependenciesFromScripts = (npmScripts, options = {}) => {
@@ -13,8 +13,11 @@ const getDependenciesFromScripts = (npmScripts, options = {}) => {
13
13
  return compact(results.map(identifier => {
14
14
  if (identifier.startsWith('http'))
15
15
  return;
16
- if (isBinary(identifier))
16
+ if (isBinary(identifier)) {
17
+ if (!/^\b/.test(fromBinary(identifier)))
18
+ return;
17
19
  return identifier;
20
+ }
18
21
  if (isInternal(identifier)) {
19
22
  const ext = extname(identifier);
20
23
  if (ext && IGNORED_FILE_EXTENSIONS.has(ext))
@@ -10,6 +10,7 @@ const argFilters = {
10
10
  'babel-node': withPositional,
11
11
  esbuild: withPositional,
12
12
  execa: withPositional,
13
+ vitest: withoutRequire,
13
14
  'ts-node': withPositional,
14
15
  zx: withPositional,
15
16
  default: withoutPositional,
@@ -5,7 +5,7 @@ export const NAME = 'Eleventy';
5
5
  export const ENABLERS = ['@11ty/eleventy'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  export const ENTRY_FILE_PATTERNS = ['.eleventy.js', 'eleventy.config.{js,cjs}'];
8
- export const PRODUCTION_ENTRY_FILE_PATTERNS = ['_includes', '_data'];
8
+ export const PRODUCTION_ENTRY_FILE_PATTERNS = ['posts/**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}'];
9
9
  const findEleventyDependencies = async (configFilePath, options) => {
10
10
  const { config } = options;
11
11
  return config.entry
@@ -5,5 +5,10 @@ export declare const ENABLERS: string[];
5
5
  export declare const isEnabled: IsPluginEnabledCallback;
6
6
  export declare const CONFIG_FILE_PATTERNS: string[];
7
7
  export declare const ENTRY_FILE_PATTERNS: string[];
8
- export declare const toEntryPatterns: (testMatch: string | RegExp | Array<string | RegExp> | undefined, cwd: string, configFilePath: string, config: PlaywrightTestConfig) => string[];
8
+ export declare const findPlaywrightDependenciesFromConfig: ({ config, cwd, configFilePath, defaultPatterns, }: {
9
+ config: PlaywrightTestConfig;
10
+ cwd: string;
11
+ configFilePath: string;
12
+ defaultPatterns: string[];
13
+ }) => string[];
9
14
  export declare const findDependencies: GenericPluginCallback;
@@ -7,22 +7,32 @@ export const ENABLERS = ['@playwright/test'];
7
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
8
  export const CONFIG_FILE_PATTERNS = ['playwright.config.{js,ts}'];
9
9
  export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
10
- export const toEntryPatterns = (testMatch, cwd, configFilePath, config) => {
10
+ const toEntryPatterns = (testMatch, cwd, configFilePath, config) => {
11
11
  if (!testMatch)
12
12
  return [];
13
13
  const dir = relative(cwd, config.testDir ? join(dirname(configFilePath), config.testDir) : dirname(configFilePath));
14
14
  const patterns = [testMatch].flat().filter((p) => typeof p === 'string');
15
15
  return patterns.map(pattern => toEntryPattern(join(dir, pattern)));
16
16
  };
17
+ const builtinReporters = ['dot', 'line', 'list', 'junit', 'html', 'blob', 'json', 'github'];
18
+ export const findPlaywrightDependenciesFromConfig = ({ config, cwd, configFilePath, defaultPatterns, }) => {
19
+ const projects = config.projects ? [config, ...config.projects] : [config];
20
+ const patterns = projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFilePath, config));
21
+ const reporters = [config.reporter].flat().flatMap(reporter => {
22
+ const name = typeof reporter === 'string' ? reporter : reporter?.[0];
23
+ if (!name || builtinReporters.includes(name))
24
+ return [];
25
+ return [name];
26
+ });
27
+ return [...(patterns.length > 0 ? patterns : defaultPatterns), ...reporters];
28
+ };
17
29
  const findPlaywrightDependencies = async (configFilePath, options) => {
18
30
  const { cwd, config } = options;
19
31
  const localConfig = await load(configFilePath);
32
+ const defaultPatterns = (config?.entry ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
20
33
  if (localConfig) {
21
- const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig];
22
- const patterns = projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFilePath, config));
23
- if (patterns.length > 0)
24
- return patterns;
34
+ return findPlaywrightDependenciesFromConfig({ cwd, configFilePath, config: localConfig, defaultPatterns });
25
35
  }
26
- return (config?.entry ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
36
+ return defaultPatterns;
27
37
  };
28
38
  export const findDependencies = timerify(findPlaywrightDependencies);
@@ -1,7 +1,7 @@
1
1
  import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
3
  import { toEntryPattern } from '../../util/protocols.js';
4
- import { toEntryPatterns } from '../playwright/index.js';
4
+ import { findPlaywrightDependenciesFromConfig } from '../playwright/index.js';
5
5
  export const NAME = 'Playwright for components';
6
6
  export const ENABLERS = [/^@playwright\/experimental-ct-/];
7
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
@@ -10,12 +10,10 @@ export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
10
10
  const findPlaywrightCTDependencies = async (configFilePath, options) => {
11
11
  const { cwd, config } = options;
12
12
  const localConfig = await load(configFilePath);
13
+ const defaultPatterns = (config?.entry ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
13
14
  if (localConfig) {
14
- const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig];
15
- const patterns = projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFilePath, config));
16
- if (patterns.length > 0)
17
- return patterns;
15
+ return findPlaywrightDependenciesFromConfig({ config: localConfig, cwd, configFilePath, defaultPatterns });
18
16
  }
19
- return (config?.entry ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
17
+ return defaultPatterns;
20
18
  };
21
19
  export const findDependencies = timerify(findPlaywrightCTDependencies);
@@ -3,5 +3,6 @@ declare const _default: {
3
3
  compact: ({ report, issues, isShowProgress }: import("../index.js").ReporterOptions) => void;
4
4
  codeowners: ({ report, issues, isShowProgress, options }: import("../index.js").ReporterOptions) => void;
5
5
  json: ({ report, issues, options }: import("../index.js").ReporterOptions) => Promise<void>;
6
+ markdown: ({ report, issues }: import("../index.js").ReporterOptions) => void;
6
7
  };
7
8
  export default _default;
@@ -1,10 +1,12 @@
1
1
  import codeowners from './codeowners.js';
2
2
  import compact from './compact.js';
3
3
  import json from './json.js';
4
+ import markdown from './markdown.js';
4
5
  import symbols from './symbols.js';
5
6
  export default {
6
7
  symbols,
7
8
  compact,
8
9
  codeowners,
9
10
  json,
11
+ markdown,
10
12
  };
@@ -0,0 +1,3 @@
1
+ import type { ReporterOptions } from '../types/issues.js';
2
+ declare const _default: ({ report, issues }: ReporterOptions) => void;
3
+ export default _default;
@@ -0,0 +1,33 @@
1
+ import { relative, toRelative } from '../util/path.js';
2
+ import { getTitle } from './util.js';
3
+ export default ({ report, issues }) => {
4
+ console.log('# Knip report\n');
5
+ for (const [reportType, isReportType] of Object.entries(report)) {
6
+ if (isReportType) {
7
+ const title = getTitle(reportType);
8
+ const isSet = issues[reportType] instanceof Set;
9
+ const issuesForType = isSet
10
+ ? Array.from(issues[reportType])
11
+ : Object.values(issues[reportType]).map(Object.values).flat();
12
+ if (issuesForType.length > 0) {
13
+ console.log(`## ${title} (${issuesForType.length})\n`);
14
+ if (isSet) {
15
+ issuesForType.sort().forEach((issue) => {
16
+ console.log(`* ${toRelative(issue)}`);
17
+ });
18
+ }
19
+ else {
20
+ const longestSymbol = issuesForType.sort((a, b) => b.symbol.length - a.symbol.length)[0].symbol.length;
21
+ const longestFilePath = relative(issuesForType.sort((a, b) => relative(b.filePath).length - relative(a.filePath).length)[0].filePath).length;
22
+ const sortedByFilePath = issuesForType.sort((a, b) => (a.filePath > b.filePath ? 1 : -1));
23
+ console.log(`| ${`Name`.padEnd(longestSymbol)} | ${`Location`.padEnd(longestFilePath)} |`);
24
+ console.log(`|:${'-'.repeat(longestSymbol + 1)}|:${'-'.repeat(longestFilePath + 1)}|`);
25
+ sortedByFilePath.forEach((issue) => {
26
+ console.log(`| ${issue.symbol.padEnd(longestSymbol)} | ${relative(issue.filePath).padEnd(longestFilePath)} |`);
27
+ });
28
+ }
29
+ console.log('');
30
+ }
31
+ }
32
+ }
33
+ };
@@ -0,0 +1,3 @@
1
+ import ts from 'typescript';
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => import("../../getImportsAndExports.js").AddImportOptions | import("../../getImportsAndExports.js").AddImportOptions[] | undefined) | undefined;
3
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import ts from 'typescript';
2
+ import { importVisitor as visit } from '../index.js';
3
+ export default visit(() => true, node => {
4
+ if (ts.isImportTypeNode(node) && node.isTypeOf) {
5
+ if (ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) {
6
+ return { specifier: node.argument.literal.text, identifier: undefined, pos: 0 };
7
+ }
8
+ }
9
+ });
@@ -2,6 +2,7 @@ import ts from 'typescript';
2
2
  import importCall from './importCall.js';
3
3
  import importDeclaration from './importDeclaration.js';
4
4
  import importEqualsDeclaration from './importEqualsDeclaration.js';
5
+ import importType from './importType.js';
5
6
  import jsDocType from './jsDocType.js';
6
7
  import propertyAccessCall from './propertyAccessCall.js';
7
8
  import reExportDeclaration from './reExportDeclaration.js';
@@ -10,6 +11,7 @@ const visitors = [
10
11
  importCall,
11
12
  importDeclaration,
12
13
  importEqualsDeclaration,
14
+ importType,
13
15
  jsDocType,
14
16
  propertyAccessCall,
15
17
  reExportDeclaration,
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "3.9.0";
1
+ export declare const version = "3.11.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '3.9.0';
1
+ export const version = '3.11.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "3.9.0",
3
+ "version": "3.11.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": {
@@ -58,7 +58,7 @@
58
58
  "@npmcli/package-json": "5.0.0",
59
59
  "@pkgjs/parseargs": "0.11.0",
60
60
  "@pnpm/logger": "5.0.0",
61
- "@pnpm/workspace.pkgs-graph": "^2.0.12",
61
+ "@pnpm/workspace.pkgs-graph": "^2.0.13",
62
62
  "@snyk/github-codeowners": "1.1.0",
63
63
  "chalk": "^5.3.0",
64
64
  "easy-table": "1.2.0",
@@ -83,7 +83,7 @@
83
83
  "@knip/eslint-config": "0.0.0",
84
84
  "@release-it/bumper": "^6.0.1",
85
85
  "@swc/cli": "^0.1.63",
86
- "@swc/core": "^1.3.101",
86
+ "@swc/core": "^1.3.102",
87
87
  "@types/js-yaml": "^4.0.9",
88
88
  "@types/micromatch": "^4.0.6",
89
89
  "@types/minimist": "^1.2.5",
@@ -97,7 +97,7 @@
97
97
  "prettier": "^3.1.1",
98
98
  "release-it": "^17.0.1",
99
99
  "tsx": "^4.7.0",
100
- "type-fest": "^4.8.3",
100
+ "type-fest": "^4.9.0",
101
101
  "typescript": "5.3.3"
102
102
  },
103
103
  "engines": {