knip 2.10.3 → 2.10.4

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.
@@ -59,6 +59,7 @@ export declare class ConfigurationChief {
59
59
  setWorkspaces(): Promise<void>;
60
60
  private getManifestWorkspaces;
61
61
  private getAdditionalWorkspaces;
62
+ private getAllWorkspaceNames;
62
63
  private getAllWorkspaces;
63
64
  getEnabledWorkspaces(): Workspace[];
64
65
  getDescendentWorkspaces(name: string): string[];
@@ -165,9 +165,9 @@ export class ConfigurationChief {
165
165
  this.ignoreWorkspaces = this.getIgnoredWorkspaces();
166
166
  this.manifestWorkspaces = await this.getManifestWorkspaces();
167
167
  this.additionalWorkspaces = await this.getAdditionalWorkspaces();
168
- this.localWorkspaces = new Set(compact(this.getEnabledWorkspaces().map(w => w.pkgName)));
168
+ this.localWorkspaces = new Set(compact(this.getAllWorkspaces().map(w => w.pkgName)));
169
169
  this.workspaces = this.getEnabledWorkspaces();
170
- this.workspaceDirs = this.getAllWorkspaces()
170
+ this.workspaceDirs = this.getAllWorkspaceNames()
171
171
  .sort(byPathDepth)
172
172
  .reverse()
173
173
  .map(dir => join(this.cwd, dir));
@@ -190,12 +190,11 @@ export class ConfigurationChief {
190
190
  const globbedDirs = await _dirGlob({ patterns, cwd: this.cwd });
191
191
  return new Set([...dirs, ...globbedDirs].filter(name => name !== ROOT_WORKSPACE_NAME && !this.manifestWorkspaces.has(name) && !this.ignoreWorkspaces.includes(name)));
192
192
  }
193
- getAllWorkspaces() {
193
+ getAllWorkspaceNames() {
194
194
  return compact([ROOT_WORKSPACE_NAME, ...this.manifestWorkspaces.keys(), ...this.additionalWorkspaces]);
195
195
  }
196
- getEnabledWorkspaces() {
197
- const allWorkspaces = this.getAllWorkspaces();
198
- const ignoredWorkspaces = this.getIgnoredWorkspaces();
196
+ getAllWorkspaces() {
197
+ const workspaceDirs = this.getAllWorkspaceNames();
199
198
  const getAncestors = (name) => (ancestors, ancestorName) => {
200
199
  if (name === ancestorName)
201
200
  return ancestors;
@@ -203,20 +202,22 @@ export class ConfigurationChief {
203
202
  ancestors.push(ancestorName);
204
203
  return ancestors;
205
204
  };
206
- const workspaces = workspaceArg ? [workspaceArg] : allWorkspaces;
207
- return workspaces
208
- .filter(w => !ignoredWorkspaces.includes(w))
209
- .sort(byPathDepth)
210
- .map((name) => ({
205
+ return workspaceDirs.sort(byPathDepth).map((name) => ({
211
206
  name,
212
207
  pkgName: this.manifestWorkspaces.get(name) ?? this.manifest?.name,
213
208
  dir: join(this.cwd, name),
214
209
  config: this.getConfigForWorkspace(name),
215
- ancestors: allWorkspaces.reduce(getAncestors(name), []),
210
+ ancestors: workspaceDirs.reduce(getAncestors(name), []),
216
211
  }));
217
212
  }
213
+ getEnabledWorkspaces() {
214
+ const allWorkspaces = this.getAllWorkspaces();
215
+ const ignoredWorkspaces = this.getIgnoredWorkspaces();
216
+ const workspaces = workspaceArg ? allWorkspaces.filter(w => w.name === workspaceArg) : allWorkspaces;
217
+ return workspaces.filter(w => !ignoredWorkspaces.includes(w.name));
218
+ }
218
219
  getDescendentWorkspaces(name) {
219
- return this.getAllWorkspaces()
220
+ return this.getAllWorkspaceNames()
220
221
  .filter(workspaceName => workspaceName !== name)
221
222
  .filter(workspaceName => name === ROOT_WORKSPACE_NAME || workspaceName.startsWith(name + '/'));
222
223
  }
@@ -273,7 +274,7 @@ export class ConfigurationChief {
273
274
  }
274
275
  getUnusedIgnoredWorkspaces() {
275
276
  const ignoredWorkspaceNames = this.config.ignoreWorkspaces;
276
- const workspaceNames = this.getAllWorkspaces();
277
+ const workspaceNames = this.getAllWorkspaceNames();
277
278
  return ignoredWorkspaceNames.filter(workspaceName => !workspaceNames.includes(workspaceName));
278
279
  }
279
280
  }
@@ -117,10 +117,8 @@ export const getImportsAndExports = (sourceFile, options) => {
117
117
  for (const visitor of visitors.export) {
118
118
  if (visitor) {
119
119
  const results = visitor(node, options);
120
- if (results) {
120
+ if (results)
121
121
  [results].flat().forEach(addExport);
122
- return;
123
- }
124
122
  }
125
123
  }
126
124
  for (const visitor of visitors.script) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.10.3";
1
+ export declare const version = "2.10.4";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.10.3';
1
+ export const version = '2.10.4';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.10.3",
3
+ "version": "2.10.4",
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",
@@ -67,23 +67,23 @@
67
67
  "@types/js-yaml": "4.0.5",
68
68
  "@types/micromatch": "4.0.2",
69
69
  "@types/minimist": "1.2.2",
70
- "@types/node": "18.16.3",
70
+ "@types/node": "20.1.0",
71
71
  "@types/npmcli__map-workspaces": "3.0.1",
72
72
  "@types/webpack": "5.28.1",
73
- "@typescript-eslint/eslint-plugin": "5.59.1",
74
- "@typescript-eslint/parser": "5.59.1",
73
+ "@typescript-eslint/eslint-plugin": "5.59.2",
74
+ "@typescript-eslint/parser": "5.59.2",
75
75
  "c8": "7.13.0",
76
- "eslint": "8.39.0",
76
+ "eslint": "8.40.0",
77
77
  "eslint-import-resolver-typescript": "3.5.5",
78
78
  "eslint-plugin-import": "2.27.5",
79
79
  "eslint-plugin-n": "15.7.0",
80
80
  "glob": "10.2.2",
81
81
  "prettier": "2.8.8",
82
- "release-it": "15.10.1",
82
+ "release-it": "15.10.3",
83
83
  "remark-cli": "11.0.0",
84
84
  "remark-preset-webpro": "0.0.2",
85
85
  "tsx": "3.12.7",
86
- "type-fest": "3.9.0"
86
+ "type-fest": "3.10.0"
87
87
  },
88
88
  "engines": {
89
89
  "node": ">=16.17.0 <17 || >=18.6.0"