knip 2.21.0 → 2.21.1

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.
@@ -22,8 +22,8 @@ export declare class ConfigurationChief {
22
22
  ignoredWorkspacePatterns: string[];
23
23
  manifestWorkspaces: Map<string, string>;
24
24
  additionalWorkspaceNames: Set<string>;
25
- enabledWorkspaceNames: string[];
26
- enabledWorkspaceDirs: string[];
25
+ availableWorkspaceNames: string[];
26
+ availableWorkspaceDirs: string[];
27
27
  enabledWorkspaces: Workspace[];
28
28
  localWorkspaces: Set<string>;
29
29
  resolvedConfigFilePath?: string;
@@ -37,7 +37,7 @@ export declare class ConfigurationChief {
37
37
  private getIgnoredWorkspacePatterns;
38
38
  private getManifestWorkspaces;
39
39
  private getAdditionalWorkspaceNames;
40
- private getEnabledWorkspaceNames;
40
+ private getAvailableWorkspaceNames;
41
41
  private getEnabledWorkspaces;
42
42
  getWorkspaces(): Workspace[];
43
43
  private getDescendentWorkspaces;
@@ -55,8 +55,8 @@ export class ConfigurationChief {
55
55
  ignoredWorkspacePatterns = [];
56
56
  manifestWorkspaces = new Map();
57
57
  additionalWorkspaceNames = new Set();
58
- enabledWorkspaceNames = [];
59
- enabledWorkspaceDirs = [];
58
+ availableWorkspaceNames = [];
59
+ availableWorkspaceDirs = [];
60
60
  enabledWorkspaces = [];
61
61
  localWorkspaces = new Set();
62
62
  resolvedConfigFilePath;
@@ -170,12 +170,12 @@ export class ConfigurationChief {
170
170
  this.ignoredWorkspacePatterns = this.getIgnoredWorkspacePatterns();
171
171
  this.manifestWorkspaces = await this.getManifestWorkspaces();
172
172
  this.additionalWorkspaceNames = await this.getAdditionalWorkspaceNames();
173
- this.enabledWorkspaceNames = this.getEnabledWorkspaceNames();
174
- this.enabledWorkspaces = this.getEnabledWorkspaces();
175
- this.enabledWorkspaceDirs = this.enabledWorkspaceNames
173
+ this.availableWorkspaceNames = this.getAvailableWorkspaceNames();
174
+ this.availableWorkspaceDirs = this.availableWorkspaceNames
176
175
  .sort(byPathDepth)
177
176
  .reverse()
178
177
  .map(dir => join(this.cwd, dir));
178
+ this.enabledWorkspaces = this.getEnabledWorkspaces();
179
179
  this.localWorkspaces = new Set(compact(this.enabledWorkspaces.map(w => w.pkgName)));
180
180
  }
181
181
  getListedWorkspaces() {
@@ -211,16 +211,13 @@ export class ConfigurationChief {
211
211
  !this.manifestWorkspaces.has(name) &&
212
212
  !micromatch.isMatch(name, this.ignoredWorkspacePatterns)));
213
213
  }
214
- getEnabledWorkspaceNames() {
214
+ getAvailableWorkspaceNames() {
215
215
  return [ROOT_WORKSPACE_NAME, ...this.manifestWorkspaces.keys(), ...this.additionalWorkspaceNames].filter(name => !micromatch.isMatch(name, this.ignoredWorkspacePatterns));
216
216
  }
217
217
  getEnabledWorkspaces() {
218
218
  if (workspaceArg && !existsSync(workspaceArg)) {
219
219
  throw new ConfigurationError(`Directory does not exist: ${workspaceArg}`);
220
220
  }
221
- const workspaceNames = workspaceArg
222
- ? this.enabledWorkspaceNames.filter(name => name === workspaceArg)
223
- : this.enabledWorkspaceNames;
224
221
  const getAncestors = (name) => (ancestors, ancestorName) => {
225
222
  if (name === ancestorName)
226
223
  return ancestors;
@@ -228,19 +225,25 @@ export class ConfigurationChief {
228
225
  ancestors.push(ancestorName);
229
226
  return ancestors;
230
227
  };
228
+ const workspaceNames = workspaceArg
229
+ ? [
230
+ ...this.availableWorkspaceNames.reduce(getAncestors(workspaceArg), []),
231
+ ...this.availableWorkspaceNames.filter(name => name === workspaceArg),
232
+ ]
233
+ : this.availableWorkspaceNames;
231
234
  return workspaceNames.sort(byPathDepth).map((name) => ({
232
235
  name,
233
236
  pkgName: this.manifestWorkspaces.get(name) ?? this.manifest?.name,
234
237
  dir: join(this.cwd, name),
235
238
  config: this.getConfigForWorkspace(name),
236
- ancestors: workspaceNames.reduce(getAncestors(name), []),
239
+ ancestors: this.availableWorkspaceNames.reduce(getAncestors(name), []),
237
240
  }));
238
241
  }
239
242
  getWorkspaces() {
240
243
  return this.enabledWorkspaces;
241
244
  }
242
245
  getDescendentWorkspaces(name) {
243
- return this.enabledWorkspaceNames
246
+ return this.availableWorkspaceNames
244
247
  .filter(workspaceName => workspaceName !== name)
245
248
  .filter(workspaceName => name === ROOT_WORKSPACE_NAME || workspaceName.startsWith(name + '/'));
246
249
  }
@@ -280,7 +283,7 @@ export class ConfigurationChief {
280
283
  return getIncludedIssueTypes(cliArgs, config);
281
284
  }
282
285
  findWorkspaceByFilePath(filePath) {
283
- const workspaceDir = this.enabledWorkspaceDirs.find(workspaceDir => filePath.startsWith(workspaceDir + '/'));
286
+ const workspaceDir = this.availableWorkspaceDirs.find(workspaceDir => filePath.startsWith(workspaceDir + '/'));
284
287
  return this.enabledWorkspaces.find(workspace => workspace.dir === workspaceDir);
285
288
  }
286
289
  findWorkspaceByPackageName(packageName) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.21.0";
1
+ export declare const version = "2.21.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.21.0';
1
+ export const version = '2.21.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.21.0",
3
+ "version": "2.21.1",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",