knip 6.1.1 → 6.2.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.
@@ -131,15 +131,10 @@ export class ProjectPrincipal {
131
131
  }
132
132
  walkAndAnalyze(analyzeFile) {
133
133
  this.resolvedFiles.clear();
134
- const queue = [...this.entryPaths, ...this.programPaths];
135
- const visited = new Set();
134
+ const visited = new Set([...this.entryPaths, ...this.programPaths]);
136
135
  let lastEntrySize = this.entryPaths.size;
137
136
  let lastProgramSize = this.programPaths.size;
138
- for (let i = 0; i < queue.length; i++) {
139
- const filePath = queue[i];
140
- if (visited.has(filePath))
141
- continue;
142
- visited.add(filePath);
137
+ for (const filePath of visited) {
143
138
  const sourceText = this.fileManager.readFile(filePath);
144
139
  if (!sourceText) {
145
140
  if (this.projectPaths.has(filePath))
@@ -152,29 +147,22 @@ export class ProjectPrincipal {
152
147
  if (this.projectPaths.has(filePath)) {
153
148
  const internalPaths = analyzeFile(filePath, result, sourceText);
154
149
  if (internalPaths) {
155
- for (const p of internalPaths) {
156
- if (!visited.has(p))
157
- queue.push(p);
158
- }
150
+ for (const p of internalPaths)
151
+ visited.add(p);
159
152
  }
160
153
  }
161
154
  else {
162
155
  for (const specifier of extractSpecifiers(result, sourceText, filePath)) {
163
156
  const resolved = this.resolveSpecifier(specifier, filePath);
164
- if (resolved && !isInNodeModules(resolved) && !visited.has(resolved)) {
165
- queue.push(resolved);
166
- }
157
+ if (resolved && !isInNodeModules(resolved))
158
+ visited.add(resolved);
167
159
  }
168
160
  }
169
161
  if (this.entryPaths.size > lastEntrySize || this.programPaths.size > lastProgramSize) {
170
- for (const p of this.entryPaths) {
171
- if (!visited.has(p))
172
- queue.push(p);
173
- }
174
- for (const p of this.programPaths) {
175
- if (!visited.has(p))
176
- queue.push(p);
177
- }
162
+ for (const p of this.entryPaths)
163
+ visited.add(p);
164
+ for (const p of this.programPaths)
165
+ visited.add(p);
178
166
  lastEntrySize = this.entryPaths.size;
179
167
  lastProgramSize = this.programPaths.size;
180
168
  }
@@ -186,13 +174,8 @@ export class ProjectPrincipal {
186
174
  }
187
175
  getUsedResolvedFiles() {
188
176
  this.resolvedFiles.clear();
189
- const queue = [...this.entryPaths, ...this.programPaths];
190
- const visited = new Set();
191
- for (let i = 0; i < queue.length; i++) {
192
- const filePath = queue[i];
193
- if (visited.has(filePath))
194
- continue;
195
- visited.add(filePath);
177
+ const visited = new Set([...this.entryPaths, ...this.programPaths]);
178
+ for (const filePath of visited) {
196
179
  const sourceText = this.fileManager.readFile(filePath);
197
180
  if (!sourceText)
198
181
  continue;
@@ -200,9 +183,8 @@ export class ProjectPrincipal {
200
183
  const result = parseFile(filePath, sourceText);
201
184
  for (const specifier of extractSpecifiers(result, sourceText, filePath)) {
202
185
  const resolved = this.resolveSpecifier(specifier, filePath);
203
- if (resolved && !isInNodeModules(resolved) && !visited.has(resolved)) {
204
- queue.push(resolved);
205
- }
186
+ if (resolved && !isInNodeModules(resolved))
187
+ visited.add(resolved);
206
188
  }
207
189
  }
208
190
  catch {
@@ -38,11 +38,19 @@ const resolveConfig = async (localConfig, options) => {
38
38
  const configs = viteConfigPath
39
39
  ? [toConfig('vite', viteConfigPath, { dir: cwd, containingFilePath: configFilePath })]
40
40
  : [];
41
+ const hasVitestAddon = addons.some(addon => addon === '@storybook/addon-vitest');
42
+ const coverageDeps = hasVitestAddon
43
+ ? [
44
+ toDependency('@vitest/coverage-v8', { optional: true }),
45
+ toDependency('@vitest/coverage-istanbul', { optional: true }),
46
+ ]
47
+ : [];
41
48
  return [
42
49
  ...patterns.map(id => toEntry(id)),
43
50
  ...addons.map(id => toDeferResolve(id)),
44
51
  ...builderPackages.map(id => toDependency(id)),
45
52
  ...frameworks.map(id => toDependency(id)),
53
+ ...coverageDeps,
46
54
  ...configs,
47
55
  ];
48
56
  };
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type { RawConfigurationOrFn as KnipConfig, WorkspaceProjectConfig } from './types/config.ts';
1
+ export type { RawConfigurationOrFn as KnipConfig, RawConfiguration as KnipConfiguration, WorkspaceProjectConfig, } from './types/config.ts';
2
2
  export type { Preprocessor, Reporter, ReporterOptions } from './types/issues.ts';
@@ -28,7 +28,7 @@ export const getPackageNameFromFilePath = (value) => {
28
28
  return name;
29
29
  };
30
30
  export const getPackageNameFromSpecifier = (specifier) => isInNodeModules(specifier) ? getPackageNameFromFilePath(specifier) : getPackageNameFromModuleSpecifier(specifier);
31
- const matchPackageNameStart = /^(@[a-z0-9._]|[a-z0-9])/i;
31
+ const matchPackageNameStart = /^(@[a-z0-9._~]|[a-z0-9])/i;
32
32
  export const isStartsLikePackageName = (specifier) => {
33
33
  const ch = specifier.charCodeAt(0);
34
34
  if (ch === 46 || ch === 47 || ch === 35 || ch === 126 || ch === 36)
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.1.1";
1
+ export declare const version = "6.2.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.1.1';
1
+ export const version = '6.2.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.1.1",
3
+ "version": "6.2.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",