knip 3.3.4 → 3.4.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 mapWorkspaces from '@npmcli/map-workspaces';
3
3
  import { createPkgGraph } from '@pnpm/workspace.pkgs-graph';
4
4
  import micromatch from 'micromatch';
5
5
  import { ConfigurationValidator } from './ConfigurationValidator.js';
6
- import { ROOT_WORKSPACE_NAME, DEFAULT_EXTENSIONS, KNIP_CONFIG_LOCATIONS } from './constants.js';
6
+ import { ROOT_WORKSPACE_NAME, DEFAULT_EXTENSIONS, KNIP_CONFIG_LOCATIONS, DUMMY_VIRTUAL_FILE_EXTENSIONS, } from './constants.js';
7
7
  import { defaultRules } from './issues/initializers.js';
8
8
  import * as plugins from './plugins/index.js';
9
9
  import { arrayify } from './util/array.js';
@@ -18,7 +18,7 @@ import { getKeysByValue } from './util/object.js';
18
18
  import { join, relative, toPosix } from './util/path.js';
19
19
  import { normalizePluginConfig, toCamelCase } from './util/plugin.js';
20
20
  import { _require } from './util/require.js';
21
- import { unwrapFunction } from './util/unwrapFunction.js';
21
+ import { unwrapFunction } from './util/unwrap-function.js';
22
22
  import { byPathDepth } from './util/workspace.js';
23
23
  const { config: rawConfigArg, workspace: rawWorkspaceArg, include = [], exclude = [], dependencies = false, exports = false, } = parsedArgValues;
24
24
  const workspaceArg = rawWorkspaceArg ? toPosix(rawWorkspaceArg).replace(/^\.\//, '').replace(/\/$/, '') : undefined;
@@ -114,7 +114,9 @@ export class ConfigurationChief {
114
114
  }
115
115
  }
116
116
  getCompilers() {
117
- return [this.config.syncCompilers, this.config.asyncCompilers];
117
+ const syncCompilers = this.config.syncCompilers;
118
+ DUMMY_VIRTUAL_FILE_EXTENSIONS.forEach(ext => !syncCompilers.has(ext) && syncCompilers.set(ext, () => ''));
119
+ return [syncCompilers, this.config.asyncCompilers];
118
120
  }
119
121
  getRules() {
120
122
  return this.config.rules;
@@ -6,6 +6,7 @@ import { createHosts } from './typescript/createHosts.js';
6
6
  import { getImportsAndExports } from './typescript/getImportsAndExports.js';
7
7
  import { createCustomModuleResolver } from './typescript/resolveModuleNames.js';
8
8
  import { SourceFileManager } from './typescript/SourceFileManager.js';
9
+ import { compact } from './util/array.js';
9
10
  import { isMaybePackageName, sanitizeSpecifier } from './util/modules.js';
10
11
  import { dirname, extname, isInNodeModules, join } from './util/path.js';
11
12
  import { timerify } from './util/Performance.js';
@@ -20,6 +21,7 @@ const baseCompilerOptions = {
20
21
  jsx: ts.JsxEmit.Preserve,
21
22
  jsxImportSource: undefined,
22
23
  lib: [],
24
+ types: ['node'],
23
25
  noEmit: true,
24
26
  skipDefaultLibCheck: true,
25
27
  skipLibCheck: true,
@@ -43,7 +45,8 @@ export class ProjectPrincipal {
43
45
  this.compilerOptions = {
44
46
  ...compilerOptions,
45
47
  ...baseCompilerOptions,
46
- allowNonTsExtensions: [...compilers].flat().length > 0,
48
+ types: compact([...(compilerOptions.types ?? []), ...baseCompilerOptions.types]),
49
+ allowNonTsExtensions: true,
47
50
  };
48
51
  const [syncCompilers, asyncCompilers] = compilers;
49
52
  this.extensions = new Set([...DEFAULT_EXTENSIONS, ...syncCompilers.keys(), ...asyncCompilers.keys()]);
@@ -149,7 +152,7 @@ export class ProjectPrincipal {
149
152
  const isIgnored = this.isGitIgnored(join(dirname(filePath), sanitizedSpecifier));
150
153
  if (!isIgnored) {
151
154
  const ext = extname(sanitizedSpecifier);
152
- const hasIgnoredExtension = IGNORED_FILE_EXTENSIONS.includes(ext);
155
+ const hasIgnoredExtension = IGNORED_FILE_EXTENSIONS.has(ext);
153
156
  if (!ext || (ext !== '.json' && !hasIgnoredExtension)) {
154
157
  unresolvedImports.add(unresolvedImport);
155
158
  }
@@ -17,7 +17,7 @@ const getDependenciesFromScripts = (npmScripts, options = {}) => {
17
17
  return identifier;
18
18
  if (isInternal(identifier)) {
19
19
  const ext = extname(identifier);
20
- if (ext && IGNORED_FILE_EXTENSIONS.includes(ext))
20
+ if (ext && IGNORED_FILE_EXTENSIONS.has(ext))
21
21
  return;
22
22
  return identifier;
23
23
  }
@@ -5,7 +5,8 @@ export declare const DEFAULT_EXTENSIONS: string[];
5
5
  export declare const GLOBAL_IGNORE_PATTERNS: string[];
6
6
  export declare const IGNORED_GLOBAL_BINARIES: string[];
7
7
  export declare const IGNORED_DEPENDENCIES: string[];
8
- export declare const IGNORED_FILE_EXTENSIONS: string[];
8
+ export declare const DUMMY_VIRTUAL_FILE_EXTENSIONS: Set<string>;
9
+ export declare const IGNORED_FILE_EXTENSIONS: Set<string>;
9
10
  export declare const IGNORE_DEFINITELY_TYPED: string[];
10
11
  export declare const ISSUE_TYPES: IssueType[];
11
12
  export declare const ISSUE_TYPE_TITLE: Record<IssueType, string>;
package/dist/constants.js CHANGED
@@ -35,28 +35,24 @@ export const IGNORED_GLOBAL_BINARIES = [
35
35
  'yarn',
36
36
  ];
37
37
  export const IGNORED_DEPENDENCIES = ['knip', 'typescript'];
38
- export const IGNORED_FILE_EXTENSIONS = [
38
+ export const DUMMY_VIRTUAL_FILE_EXTENSIONS = new Set(['.html', '.jpeg', '.jpg', '.png', '.svg', '.webp']);
39
+ export const IGNORED_FILE_EXTENSIONS = new Set([
39
40
  '.avif',
40
41
  '.css',
41
42
  '.eot',
42
43
  '.gif',
43
- '.html',
44
44
  '.ico',
45
- '.jpeg',
46
- '.jpg',
47
45
  '.less',
48
- '.png',
49
46
  '.sass',
50
47
  '.scss',
51
48
  '.sh',
52
- '.svg',
53
49
  '.ttf',
54
- '.webp',
55
50
  '.woff',
56
51
  '.woff2',
57
52
  '.yaml',
58
53
  '.yml',
59
- ];
54
+ ...DUMMY_VIRTUAL_FILE_EXTENSIONS,
55
+ ]);
60
56
  export const IGNORE_DEFINITELY_TYPED = ['node'];
61
57
  export const ISSUE_TYPES = [
62
58
  'files',
@@ -1,4 +1,4 @@
1
- import { parseArgs } from './parseArgs.js';
1
+ import { parseArgs } from './parse-args.js';
2
2
  export const helpText = `✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects
3
3
 
4
4
  Usage: knip [options]
package/dist/util/git.js CHANGED
@@ -8,7 +8,7 @@ const hookFileNames = [
8
8
  ];
9
9
  const getGitHooksPath = (defaultPath = '.git/hooks') => {
10
10
  try {
11
- return execSync('git config --get core.hooksPath', { encoding: 'utf8' }).trim();
11
+ return execSync('git config --get core.hooksPath', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] }).trim();
12
12
  }
13
13
  catch (error) {
14
14
  return defaultPath;
@@ -0,0 +1 @@
1
+ export declare const unwrapFunction: (maybeFunction: unknown) => Promise<any>;
@@ -1,13 +1,13 @@
1
1
  import { debugLogObject } from './debug.js';
2
- export const unwrapFunction = async (possibleFunction) => {
3
- if (typeof possibleFunction === 'function') {
2
+ export const unwrapFunction = async (maybeFunction) => {
3
+ if (typeof maybeFunction === 'function') {
4
4
  try {
5
- return await possibleFunction();
5
+ return await maybeFunction();
6
6
  }
7
7
  catch (error) {
8
8
  debugLogObject('*', 'Error executing function:', error);
9
9
  throw error;
10
10
  }
11
11
  }
12
- return possibleFunction;
12
+ return maybeFunction;
13
13
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "3.3.4";
1
+ export declare const version = "3.4.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '3.3.4';
1
+ export const version = '3.4.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "3.3.4",
3
+ "version": "3.4.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": {
@@ -64,7 +64,8 @@
64
64
  "zod-validation-error": "2.1.0"
65
65
  },
66
66
  "peerDependencies": {
67
- "typescript": ">=5.0.4"
67
+ "typescript": ">=5.0.4",
68
+ "@types/node": ">=18"
68
69
  },
69
70
  "devDependencies": {
70
71
  "@jest/types": "29.6.3",
@@ -72,21 +73,20 @@
72
73
  "@npmcli/package-json": "5.0.0",
73
74
  "@release-it/bumper": "^6.0.1",
74
75
  "@swc/cli": "^0.1.63",
75
- "@swc/core": "^1.3.99",
76
+ "@swc/core": "^1.3.100",
76
77
  "@types/js-yaml": "^4.0.9",
77
78
  "@types/micromatch": "^4.0.6",
78
79
  "@types/minimist": "^1.2.5",
79
- "@types/node": "^20.10.0",
80
80
  "@types/npmcli__map-workspaces": "^3.0.4",
81
81
  "@types/npmcli__package-json": "^4.0.3",
82
82
  "@types/pkgjs__parseargs": "^0.10.3",
83
83
  "@types/webpack": "^5.28.5",
84
84
  "c8": "8.0.1",
85
85
  "eslint": "^8.54.0",
86
- "playwright": "^1.40.0",
86
+ "playwright": "^1.40.1",
87
87
  "prettier": "^3.1.0",
88
88
  "release-it": "^17.0.0",
89
- "tsx": "^4.5.0",
89
+ "tsx": "^4.6.1",
90
90
  "type-fest": "^4.8.2",
91
91
  "typescript": "5.3.2"
92
92
  },
@@ -120,31 +120,34 @@
120
120
  }
121
121
  },
122
122
  "keywords": [
123
- "find",
124
- "detect",
123
+ "analysis",
125
124
  "analyze",
126
- "scan",
127
- "lint",
128
- "unused",
129
- "unreferenced",
130
- "unresolved",
131
- "missing",
132
- "unimported",
133
- "files",
125
+ "class",
126
+ "cli",
127
+ "dead code",
134
128
  "dependencies",
129
+ "detect",
135
130
  "devDependencies",
136
- "exports",
137
- "types",
138
- "members",
139
- "namespaces",
140
- "duplicates",
141
- "typescript",
142
- "maintenance",
143
- "class",
131
+ "duplicate",
132
+ "entropy",
144
133
  "enum",
134
+ "export",
135
+ "files",
136
+ "find",
137
+ "javascript",
138
+ "lint",
139
+ "maintenance",
145
140
  "members",
146
- "workspace",
147
- "workspaces",
148
- "monorepo"
141
+ "missing",
142
+ "monorepo",
143
+ "namespace",
144
+ "package",
145
+ "scan",
146
+ "types",
147
+ "typescript",
148
+ "unreferenced",
149
+ "unresolved",
150
+ "unused",
151
+ "workspace"
149
152
  ]
150
153
  }
@@ -1 +0,0 @@
1
- export declare const unwrapFunction: (possibleFunction: unknown) => Promise<any>;
File without changes
File without changes