knip 5.44.4 → 5.44.5

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.
@@ -57,7 +57,7 @@ export declare class WorkspaceWorker {
57
57
  getProductionProjectFilePatterns(negatedTestFilePatterns: string[]): string[];
58
58
  private getConfigurationFilePatterns;
59
59
  getIgnorePatterns(): string[];
60
- findDependenciesByPlugins(): Promise<Input[]>;
60
+ runPlugins(): Promise<Input[]>;
61
61
  onDispose(): void;
62
62
  }
63
63
  export {};
@@ -156,7 +156,7 @@ export class WorkspaceWorker {
156
156
  getIgnorePatterns() {
157
157
  return [...this.rootIgnore, ...this.config.ignore.map(pattern => prependDirToPattern(this.name, pattern))];
158
158
  }
159
- async findDependenciesByPlugins() {
159
+ async runPlugins() {
160
160
  const name = this.name;
161
161
  const cwd = this.dir;
162
162
  const rootCwd = this.cwd;
@@ -4,7 +4,7 @@ import { getCompilerExtensions, getIncludedCompilers } from '../compilers/index.
4
4
  import { debugLog, debugLogArray } from '../util/debug.js';
5
5
  import { getReferencedInputsHandler } from '../util/get-referenced-inputs.js';
6
6
  import { _glob, negate } from '../util/glob.js';
7
- import { isConfigPattern, isEntry, isProductionEntry, toProductionEntry } from '../util/input.js';
7
+ import { isConfigPattern, isDeferResolveEntry, isDeferResolveProductionEntry, isEntry, isProductionEntry, toProductionEntry, } from '../util/input.js';
8
8
  import { getOrCreateFileNode, updateImportMap } from '../util/module-graph.js';
9
9
  import { getEntryPathsFromManifest } from '../util/package-json.js';
10
10
  import { dirname, isAbsolute, join, relative } from '../util/path.js';
@@ -58,21 +58,21 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
58
58
  allConfigFilePaths,
59
59
  });
60
60
  await worker.init();
61
- const deps = new Set();
61
+ const inputs = new Set();
62
62
  if (definitionPaths.length > 0) {
63
63
  debugLogArray(name, 'Definition paths', definitionPaths);
64
64
  for (const id of definitionPaths)
65
- deps.add(toProductionEntry(id, { containingFilePath: tsConfigFilePath }));
65
+ inputs.add(toProductionEntry(id, { containingFilePath: tsConfigFilePath }));
66
66
  }
67
67
  const ignore = worker.getIgnorePatterns();
68
68
  const sharedGlobOptions = { cwd, dir, gitignore };
69
69
  collector.addIgnorePatterns(ignore.map(pattern => join(cwd, pattern)));
70
70
  const entryPathsFromManifest = await getEntryPathsFromManifest(manifest, { ...sharedGlobOptions, ignore });
71
71
  for (const id of entryPathsFromManifest.map(id => toProductionEntry(id)))
72
- deps.add(id);
73
- const dependenciesFromPlugins = await worker.findDependenciesByPlugins();
74
- for (const id of dependenciesFromPlugins)
75
- deps.add(id);
72
+ inputs.add(id);
73
+ const inputsFromPlugins = await worker.runPlugins();
74
+ for (const id of inputsFromPlugins)
75
+ inputs.add(id);
76
76
  enabledPluginsStore.set(name, worker.enabledPlugins);
77
77
  const principal = factory.createPrincipal({
78
78
  cwd: dir,
@@ -90,19 +90,28 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
90
90
  });
91
91
  const entryFilePatterns = new Set();
92
92
  const productionEntryFilePatterns = new Set();
93
- for (const dependency of deps) {
94
- const s = dependency.specifier;
95
- if (isEntry(dependency)) {
93
+ for (const input of inputs) {
94
+ const s = input.specifier;
95
+ if (isEntry(input)) {
96
96
  entryFilePatterns.add(isAbsolute(s) ? relative(dir, s) : s);
97
97
  }
98
- else if (isProductionEntry(dependency)) {
98
+ else if (isProductionEntry(input)) {
99
99
  productionEntryFilePatterns.add(isAbsolute(s) ? relative(dir, s) : s);
100
100
  }
101
- else if (!isConfigPattern(dependency)) {
102
- const ws = (dependency.containingFilePath && chief.findWorkspaceByFilePath(dependency.containingFilePath)) || workspace;
103
- const specifierFilePath = getReferencedInternalFilePath(dependency, ws);
104
- if (specifierFilePath)
105
- principal.addEntryPath(specifierFilePath, { skipExportsAnalysis: true });
101
+ else if (!isConfigPattern(input)) {
102
+ const ws = (input.containingFilePath && chief.findWorkspaceByFilePath(input.containingFilePath)) || workspace;
103
+ const resolvedFilePath = getReferencedInternalFilePath(input, ws);
104
+ if (resolvedFilePath) {
105
+ if (isDeferResolveProductionEntry(input)) {
106
+ productionEntryFilePatterns.add(resolvedFilePath);
107
+ }
108
+ else if (isDeferResolveEntry(input)) {
109
+ entryFilePatterns.add(resolvedFilePath);
110
+ }
111
+ else {
112
+ principal.addEntryPath(resolvedFilePath, { skipExportsAnalysis: true });
113
+ }
114
+ }
106
115
  }
107
116
  }
108
117
  if (isProduction) {
@@ -1,5 +1,5 @@
1
1
  import { compact } from '../../util/array.js';
2
- import { toDeferResolve, toDependency, toDevDependency, toEntry, toProductionEntry, } from '../../util/input.js';
2
+ import { toDeferResolve, toDeferResolveEntry, toDeferResolveProductionEntry, toDependency, toDevDependency, } from '../../util/input.js';
3
3
  import { isAbsolute, isInternal, join, relative } from '../../util/path.js';
4
4
  import { hasDependency } from '../../util/plugin.js';
5
5
  import { getDependenciesFromConfig } from '../babel/index.js';
@@ -83,8 +83,8 @@ export const findWebpackDependenciesFromConfig = async ({ config, cwd }) => {
83
83
  else {
84
84
  const absoluteEntry = isAbsolute(entry) ? entry : join(options.context ? options.context : cwd, entry);
85
85
  const item = relative(cwd, absoluteEntry);
86
- const value = options.mode === 'development' ? toEntry(item) : toProductionEntry(item);
87
- inputs.add(value);
86
+ const input = options.mode === 'development' ? toDeferResolveEntry(item) : toDeferResolveProductionEntry(item);
87
+ inputs.add(input);
88
88
  }
89
89
  }
90
90
  }
@@ -1,6 +1,6 @@
1
1
  import { IGNORED_RUNTIME_DEPENDENCIES } from '../constants.js';
2
2
  import { debugLog } from './debug.js';
3
- import { toDebugString } from './input.js';
3
+ import { isDeferResolve, toDebugString } from './input.js';
4
4
  import { fromBinary, isBinary, isConfigPattern, isDeferResolveEntry, isDependency } from './input.js';
5
5
  import { getPackageNameFromSpecifier } from './modules.js';
6
6
  import { dirname, isAbsolute, isInternal, join } from './path.js';
@@ -54,7 +54,7 @@ export const getReferencedInputsHandler = (collector, deputy, chief, isGitIgnore
54
54
  return;
55
55
  }
56
56
  }
57
- if (!isConfigPattern(input) && deputy.isProduction && !input.production) {
57
+ if (isDeferResolve(input) && deputy.isProduction && !input.production) {
58
58
  return;
59
59
  }
60
60
  const baseDir = input.dir ?? dirname(containingFilePath);
@@ -187,7 +187,7 @@ export async function glob(patterns, options) {
187
187
  const ignore = cachedIgnores || compact(_ignore);
188
188
  const { dir, label, ...fgOptions } = { ...options, ignore };
189
189
  const paths = await fg.glob(patterns, fgOptions);
190
- debugLogObject(relative(options.cwd, options.dir) || ROOT_WORKSPACE_NAME, label ? `Finding ${label} paths` : 'Finding paths', () => ({ patterns, ...fgOptions, ignore: cachedIgnores ? `identical to ${dir} ↑` : ignore, paths }));
190
+ debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, label ? `Finding ${label} paths` : 'Finding paths', () => ({ patterns, ...fgOptions, ignore: cachedIgnores ? `// identical to ${dir}` : ignore, paths }));
191
191
  if (willCache)
192
192
  cachedGlobIgnores.set(options.dir, ignore);
193
193
  return paths;
@@ -32,6 +32,9 @@ export declare const isDependency: (input: Input) => boolean;
32
32
  export declare const toProductionDependency: (specifier: string) => Input;
33
33
  export declare const toDevDependency: (specifier: string) => Input;
34
34
  export declare const toDeferResolve: (specifier: string) => Input;
35
+ export declare const isDeferResolve: (input: Input) => boolean;
36
+ export declare const toDeferResolveProductionEntry: (specifier: string) => Input;
37
+ export declare const isDeferResolveProductionEntry: (input: Input) => boolean;
35
38
  export declare const toDeferResolveEntry: (specifier: string) => Input;
36
39
  export declare const isDeferResolveEntry: (input: Input) => boolean;
37
40
  export declare const toDebugString: (input: Input) => string;
@@ -35,6 +35,13 @@ export const toProductionDependency = (specifier) => ({
35
35
  });
36
36
  export const toDevDependency = (specifier) => ({ type: 'dependency', specifier });
37
37
  export const toDeferResolve = (specifier) => ({ type: 'deferResolve', specifier });
38
+ export const isDeferResolve = (input) => input.type === 'deferResolve';
39
+ export const toDeferResolveProductionEntry = (specifier) => ({
40
+ type: 'deferResolveEntry',
41
+ specifier,
42
+ production: true,
43
+ });
44
+ export const isDeferResolveProductionEntry = (input) => input.type === 'deferResolveEntry' && input.production === true;
38
45
  export const toDeferResolveEntry = (specifier) => ({ type: 'deferResolveEntry', specifier });
39
46
  export const isDeferResolveEntry = (input) => input.type === 'deferResolveEntry';
40
47
  export const toDebugString = (input) => `${input.type}:${input.specifier}${input.containingFilePath ? ` (${toRelative(input.containingFilePath)})` : ''}`;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.44.4";
1
+ export declare const version = "5.44.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.44.4';
1
+ export const version = '5.44.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.44.4",
3
+ "version": "5.44.5",
4
4
  "description": "Find and fix unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {