knip 5.73.0 → 5.73.2

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.
@@ -11,7 +11,7 @@ import type { ToSourceFilePath } from './util/to-source-path.js';
11
11
  export declare class ProjectPrincipal {
12
12
  entryPaths: Set<string>;
13
13
  projectPaths: Set<string>;
14
- nonEntryPaths: Set<string>;
14
+ programPaths: Set<string>;
15
15
  skipExportsAnalysis: Set<string>;
16
16
  cwd: string;
17
17
  compilerOptions: ts.CompilerOptions;
@@ -44,7 +44,7 @@ export declare class ProjectPrincipal {
44
44
  addEntryPaths(filePaths: Set<string> | string[], options?: {
45
45
  skipExportsAnalysis: boolean;
46
46
  }): void;
47
- addNonEntryPath(filePath: string): void;
47
+ addProgramPath(filePath: string): void;
48
48
  addProjectPath(filePath: string): void;
49
49
  deletedFiles: Set<unknown>;
50
50
  removeProjectPath(filePath: string): void;
@@ -29,7 +29,7 @@ const tsCreateProgram = timerify(ts.createProgram);
29
29
  export class ProjectPrincipal {
30
30
  entryPaths = new Set();
31
31
  projectPaths = new Set();
32
- nonEntryPaths = new Set();
32
+ programPaths = new Set();
33
33
  skipExportsAnalysis = new Set();
34
34
  cwd;
35
35
  compilerOptions;
@@ -98,7 +98,7 @@ export class ProjectPrincipal {
98
98
  this.extensions = new Set([...this.extensions, ...getCompilerExtensions(compilers)]);
99
99
  }
100
100
  createProgram() {
101
- this.backend.program = tsCreateProgram([...this.entryPaths, ...this.nonEntryPaths], this.compilerOptions, this.backend.compilerHost, this.backend.program);
101
+ this.backend.program = tsCreateProgram([...this.entryPaths, ...this.programPaths], this.compilerOptions, this.backend.compilerHost, this.backend.program);
102
102
  const typeChecker = timerify(this.backend.program.getTypeChecker);
103
103
  this.backend.typeChecker = typeChecker();
104
104
  }
@@ -117,9 +117,9 @@ export class ProjectPrincipal {
117
117
  for (const filePath of filePaths)
118
118
  this.addEntryPath(filePath, options);
119
119
  }
120
- addNonEntryPath(filePath) {
120
+ addProgramPath(filePath) {
121
121
  if (!isInNodeModules(filePath) && this.hasAcceptedExtension(filePath)) {
122
- this.nonEntryPaths.add(filePath);
122
+ this.programPaths.add(filePath);
123
123
  }
124
124
  }
125
125
  addProjectPath(filePath) {
@@ -57,6 +57,7 @@ export declare const IMPORT_MODIFIERS: {
57
57
  readonly RE_EXPORT: number;
58
58
  readonly TYPE_ONLY: number;
59
59
  readonly ENTRY: number;
60
+ readonly BRIDGE: number;
60
61
  readonly OPTIONAL: number;
61
62
  readonly SIDE_EFFECTS: number;
62
63
  readonly OPAQUE: number;
package/dist/constants.js CHANGED
@@ -217,7 +217,8 @@ export const IMPORT_MODIFIERS = {
217
217
  RE_EXPORT: 1 << 0,
218
218
  TYPE_ONLY: 1 << 1,
219
219
  ENTRY: 1 << 2,
220
- OPTIONAL: 1 << 3,
221
- SIDE_EFFECTS: 1 << 4,
222
- OPAQUE: 1 << 5,
220
+ BRIDGE: 1 << 3,
221
+ OPTIONAL: 1 << 4,
222
+ SIDE_EFFECTS: 1 << 5,
223
+ OPAQUE: 1 << 6,
223
224
  };
@@ -271,7 +271,12 @@ export async function build({ chief, collector, counselor, deputy, factory, isGi
271
271
  }
272
272
  }
273
273
  }
274
- for (const filePath of file.imports.resolved) {
274
+ for (const filePath of file.imports.programFiles) {
275
+ const isIgnored = isGitIgnored(filePath);
276
+ if (!isIgnored)
277
+ principal.addProgramPath(filePath);
278
+ }
279
+ for (const filePath of file.imports.entryFiles) {
275
280
  const isIgnored = isGitIgnored(filePath);
276
281
  if (!isIgnored)
277
282
  principal.addEntryPath(filePath, { skipExportsAnalysis: true });
@@ -283,7 +288,7 @@ export async function build({ chief, collector, counselor, deputy, factory, isGi
283
288
  file.imports.external.add({ ..._import, specifier: packageName });
284
289
  const principal = getPrincipalByFilePath(_import.filePath);
285
290
  if (principal && !isGitIgnored(_import.filePath)) {
286
- principal.addNonEntryPath(_import.filePath);
291
+ principal.addProgramPath(_import.filePath);
287
292
  }
288
293
  }
289
294
  }
@@ -16,7 +16,7 @@ const production = [
16
16
  ];
17
17
  const resolveFromAST = sourceFile => {
18
18
  const srcDir = getSrcDir(sourceFile);
19
- const setSrcDir = (entry) => entry.replace(/^`src\//, `${srcDir}/`);
19
+ const setSrcDir = (entry) => entry.replace(/^src\//, `${srcDir}/`);
20
20
  return [
21
21
  ...entry.map(setSrcDir).map(path => toEntry(path)),
22
22
  ...production.map(setSrcDir).map(path => toProductionEntry(path)),
@@ -58,7 +58,8 @@ export type FileNode = {
58
58
  internal: ImportMap;
59
59
  external: Set<Import>;
60
60
  unresolved: Set<Import>;
61
- resolved: Set<FilePath>;
61
+ programFiles: Set<FilePath>;
62
+ entryFiles: Set<FilePath>;
62
63
  imports: Imports;
63
64
  };
64
65
  exports: ExportMap;
@@ -37,7 +37,8 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
37
37
  const internal = new Map();
38
38
  const external = new Set();
39
39
  const unresolved = new Set();
40
- const resolved = new Set();
40
+ const programFiles = new Set();
41
+ const entryFiles = new Set();
41
42
  const imports = new Set();
42
43
  const exports = new Map();
43
44
  const aliasedExports = new Map();
@@ -132,9 +133,11 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
132
133
  if (module) {
133
134
  const filePath = module.resolvedFileName;
134
135
  if (filePath) {
135
- if (opts.modifiers && opts.modifiers & IMPORT_MODIFIERS.ENTRY && !isInNodeModules(filePath)) {
136
- resolved.add(filePath);
137
- return;
136
+ if (!isInNodeModules(filePath)) {
137
+ if (opts.modifiers & IMPORT_MODIFIERS.ENTRY)
138
+ entryFiles.add(filePath);
139
+ if (opts.modifiers & IMPORT_MODIFIERS.BRIDGE)
140
+ programFiles.add(filePath);
138
141
  }
139
142
  if (!module.isExternalLibraryImport || !isInNodeModules(filePath)) {
140
143
  const { line, character } = node.getSourceFile().getLineAndCharacterOfPosition(opts.pos);
@@ -176,7 +179,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
176
179
  if (opts.specifier.startsWith(PROTOCOL_VIRTUAL))
177
180
  return;
178
181
  if (opts.modifiers && opts.modifiers & IMPORT_MODIFIERS.OPTIONAL) {
179
- resolved.add(resolve(dirname(sourceFile.fileName), opts.specifier));
182
+ programFiles.add(resolve(dirname(sourceFile.fileName), opts.specifier));
180
183
  return;
181
184
  }
182
185
  const pos = 'moduleSpecifier' in node ? node.moduleSpecifier.pos : node.pos;
@@ -441,7 +444,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
441
444
  item.symbol = undefined;
442
445
  }
443
446
  return {
444
- imports: { internal, external, resolved, imports, unresolved },
447
+ imports: { internal, external, programFiles, entryFiles, imports, unresolved },
445
448
  exports,
446
449
  duplicates: [...aliasedExports.values()],
447
450
  scripts,
@@ -7,7 +7,7 @@ export default visit(() => true, node => {
7
7
  if (isRequireCall(node)) {
8
8
  if (ts.isStringLiteralLike(node.arguments[0])) {
9
9
  const specifier = node.arguments[0].text;
10
- const modifiers = isNotJS(node.getSourceFile()) ? IMPORT_MODIFIERS.ENTRY : IMPORT_MODIFIERS.NONE;
10
+ const modifiers = isNotJS(node.getSourceFile()) ? IMPORT_MODIFIERS.BRIDGE : IMPORT_MODIFIERS.NONE;
11
11
  if (specifier) {
12
12
  const propertyAccessExpression = findAncestor(node, _node => {
13
13
  if (ts.isExpressionStatement(_node) || ts.isCallExpression(_node))
@@ -1,7 +1,6 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import fg from 'fast-glob';
3
3
  import { partition } from './array.js';
4
- import { debugLog } from './debug.js';
5
4
  import { ConfigurationError } from './errors.js';
6
5
  import { getPackageName } from './package-name.js';
7
6
  import { join } from './path.js';
@@ -11,14 +10,15 @@ export default async function mapWorkspaces(cwd, workspaces) {
11
10
  const wsPkgNames = new Set();
12
11
  if (patterns.length === 0 && negatedPatterns.length === 0)
13
12
  return [packages, wsPkgNames];
14
- const matches = await fg.glob(patterns, {
13
+ const manifestPatterns = patterns.map(p => join(p, 'package.json'));
14
+ const matches = await fg.glob(manifestPatterns, {
15
15
  cwd,
16
- onlyDirectories: true,
17
- ignore: ['**/node_modules/**', ...negatedPatterns],
16
+ ignore: ['**/node_modules/**', ...negatedPatterns.map(p => p.slice(1))],
18
17
  });
19
- for (const name of matches) {
18
+ for (const match of matches) {
19
+ const name = match === 'package.json' ? '.' : match.replace(/\/package\.json$/, '');
20
20
  const dir = join(cwd, name);
21
- const manifestPath = join(dir, 'package.json');
21
+ const manifestPath = join(cwd, match);
22
22
  try {
23
23
  const manifestStr = await readFile(manifestPath, 'utf8');
24
24
  const manifest = JSON.parse(manifestStr);
@@ -34,7 +34,8 @@ const createFileNode = () => ({
34
34
  internal: new Map(),
35
35
  external: new Set(),
36
36
  unresolved: new Set(),
37
- resolved: new Set(),
37
+ programFiles: new Set(),
38
+ entryFiles: new Set(),
38
39
  imports: new Set(),
39
40
  },
40
41
  exports: new Map(),
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.73.0";
1
+ export declare const version = "5.73.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.73.0';
1
+ export const version = '5.73.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.73.0",
3
+ "version": "5.73.2",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
package/schema.json CHANGED
@@ -227,18 +227,21 @@
227
227
  "items": {
228
228
  "type": "string",
229
229
  "enum": [
230
- "binaries",
231
- "classMembers",
230
+ "files",
232
231
  "dependencies",
233
- "duplicates",
234
- "enumMembers",
232
+ "devDependencies",
233
+ "optionalPeerDependencies",
234
+ "unlisted",
235
+ "binaries",
236
+ "unresolved",
235
237
  "exports",
236
- "files",
238
+ "types",
237
239
  "nsExports",
238
240
  "nsTypes",
239
- "types",
240
- "unlisted",
241
- "unresolved"
241
+ "duplicates",
242
+ "enumMembers",
243
+ "classMembers",
244
+ "catalog"
242
245
  ]
243
246
  }
244
247
  },