knip 6.3.0 → 6.3.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.
@@ -187,12 +187,12 @@ export class DependencyDeputy {
187
187
  const referencedDependencies = this.referencedDependencies.get(workspace);
188
188
  const hasTypesIncluded = this.getHasTypesIncluded(workspace);
189
189
  const peeker = new PackagePeeker(manifestStr);
190
- const peerDepCount = {};
191
- const isReferencedDependency = (dependency, isPeerDep) => {
190
+ const isReferencedDependency = (dependency, visited = new Set()) => {
192
191
  if (referencedDependencies?.has(dependency))
193
192
  return true;
194
- if (isPeerDep && peerDepCount[dependency])
193
+ if (visited.has(dependency))
195
194
  return false;
195
+ visited.add(dependency);
196
196
  const [scope, typedDependency] = dependency.split('/');
197
197
  if (scope === DT_SCOPE) {
198
198
  const typedPackageName = getPackageFromDefinitelyTyped(typedDependency);
@@ -205,21 +205,15 @@ export class DependencyDeputy {
205
205
  ...this.getHostDependenciesFor(workspace, typedPackageName),
206
206
  ];
207
207
  if (hostDependencies.length)
208
- return !!hostDependencies.find(host => isReferencedDependency(host.name, true));
208
+ return !!hostDependencies.find(host => isReferencedDependency(host.name, visited));
209
209
  if (!referencedDependencies?.has(dependency))
210
210
  return false;
211
211
  return referencedDependencies.has(typedPackageName);
212
212
  }
213
213
  const hostDependencies = this.getHostDependenciesFor(workspace, dependency);
214
- for (const { name } of hostDependencies) {
215
- if (!peerDepCount[name])
216
- peerDepCount[name] = 1;
217
- else
218
- peerDepCount[name]++;
219
- }
220
- return hostDependencies.some(hostDependency => (isPeerDep === false || !hostDependency.isPeerOptional) && isReferencedDependency(hostDependency.name, true));
214
+ return hostDependencies.some(hostDependency => isReferencedDependency(hostDependency.name, visited));
221
215
  };
222
- const isNotReferencedDependency = (dependency) => !isReferencedDependency(dependency, false);
216
+ const isNotReferencedDependency = (dependency) => !isReferencedDependency(dependency);
223
217
  for (const symbol of this.getProductionDependencies(workspace).filter(isNotReferencedDependency)) {
224
218
  const position = peeker.getLocation('dependencies', symbol);
225
219
  dependencyIssues.push({ type: 'dependencies', workspace, filePath, symbol, fixes: [], ...position });
@@ -26,7 +26,7 @@ const resolveConfig = async (localConfig, options) => {
26
26
  routeConfig = await load(routesPathJs);
27
27
  }
28
28
  const mapRoute = (route) => {
29
- return [join(appDir, route.file), ...(route.children ? route.children.flatMap(mapRoute) : [])];
29
+ return [toAbsolute(route.file, appDir), ...(route.children ? route.children.flatMap(mapRoute) : [])];
30
30
  };
31
31
  const routes = routeConfig
32
32
  .flatMap(mapRoute)
@@ -96,7 +96,7 @@ export function handleCallExpression(node, s) {
96
96
  }
97
97
  else if (arg.type === 'ObjectExpression') {
98
98
  for (const prop of arg.properties ?? []) {
99
- if (prop.type === 'Property' && prop.shorthand && prop.value?.type === 'Identifier')
99
+ if (prop.type === 'Property' && !prop.computed && prop.value?.type === 'Identifier')
100
100
  markRefIfNs(prop.value.name);
101
101
  if (prop.type === 'SpreadElement' && prop.argument?.type === 'Identifier')
102
102
  markRefIfNs(prop.argument.name);
@@ -160,18 +160,22 @@ export function handleVariableDeclarator(node, s) {
160
160
  }
161
161
  }
162
162
  }
163
- if (prop.type === 'Property' && prop.shorthand && prop.value?.type === 'Identifier') {
164
- const _import = s.localImportMap.get(prop.value.name);
163
+ if (prop.type === 'Property' &&
164
+ !prop.computed &&
165
+ prop.value?.type === 'Identifier' &&
166
+ prop.key?.type === 'Identifier') {
167
+ const nsName = prop.value.name;
168
+ const _import = s.localImportMap.get(nsName);
165
169
  if (_import?.isNamespace) {
166
170
  const internalImport = s.internal.get(_import.filePath);
167
171
  if (internalImport)
168
- internalImport.refs.add(prop.value.name);
169
- let set = s.shorthandNsContainers.get(aliasName);
170
- if (!set) {
171
- set = new Set();
172
- s.shorthandNsContainers.set(aliasName, set);
172
+ internalImport.refs.add(nsName);
173
+ let map = s.nsContainers.get(aliasName);
174
+ if (!map) {
175
+ map = new Map();
176
+ s.nsContainers.set(aliasName, map);
173
177
  }
174
- set.add(prop.value.name);
178
+ map.set(prop.key.name, nsName);
175
179
  }
176
180
  }
177
181
  }
@@ -130,8 +130,9 @@ export function handleMemberExpression(node, s) {
130
130
  node.object.object.type === 'Identifier' &&
131
131
  node.object.property.type === 'Identifier') {
132
132
  const containerName = node.object.object.name;
133
- const nsName = node.object.property.name;
134
- if (s.shorthandNsContainers.get(containerName)?.has(nsName)) {
133
+ const propKey = node.object.property.name;
134
+ const nsName = s.nsContainers.get(containerName)?.get(propKey);
135
+ if (nsName) {
135
136
  const _import = s.localImportMap.get(nsName);
136
137
  if (_import) {
137
138
  const internalImport = s.internal.get(_import.filePath);
@@ -143,7 +144,7 @@ export function handleMemberExpression(node, s) {
143
144
  memberName = getStringValue(node.property);
144
145
  if (memberName) {
145
146
  s.addNsMemberRefs(internalImport, nsName, memberName);
146
- s.accessedShorthandNs.add(`${containerName}.${nsName}`);
147
+ s.accessedNsContainers.add(`${containerName}.${propKey}`);
147
148
  }
148
149
  }
149
150
  }
@@ -46,8 +46,8 @@ export interface WalkState extends WalkContext {
46
46
  handledImportExpressions: Set<number>;
47
47
  bareExprRefs: Set<string>;
48
48
  accessedAliases: Set<string>;
49
- shorthandNsContainers: Map<string, Set<string>>;
50
- accessedShorthandNs: Set<string>;
49
+ nsContainers: Map<string, Map<string, string>>;
50
+ accessedNsContainers: Set<string>;
51
51
  chainedMemberExprs: WeakSet<object>;
52
52
  currentVarDeclStart: number;
53
53
  nsRanges: [number, number][];
@@ -641,8 +641,8 @@ export function walkAST(program, sourceText, filePath, ctx) {
641
641
  handledImportExpressions: new Set(),
642
642
  bareExprRefs: new Set(),
643
643
  accessedAliases: new Set(),
644
- shorthandNsContainers: new Map(),
645
- accessedShorthandNs: new Set(),
644
+ nsContainers: new Map(),
645
+ accessedNsContainers: new Set(),
646
646
  chainedMemberExprs: new WeakSet(),
647
647
  currentVarDeclStart: -1,
648
648
  nsRanges: [],
@@ -682,9 +682,9 @@ export function walkAST(program, sourceText, filePath, ctx) {
682
682
  }
683
683
  }
684
684
  }
685
- for (const [containerName, nsSet] of state.shorthandNsContainers) {
686
- for (const nsName of nsSet) {
687
- if (!state.accessedShorthandNs.has(`${containerName}.${nsName}`)) {
685
+ for (const [containerName, propMap] of state.nsContainers) {
686
+ for (const [propKey, nsName] of propMap) {
687
+ if (!state.accessedNsContainers.has(`${containerName}.${propKey}`)) {
688
688
  const _import = state.localImportMap.get(nsName);
689
689
  if (_import) {
690
690
  const internalImport = state.internal.get(_import.filePath);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.3.0";
1
+ export declare const version = "6.3.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.3.0';
1
+ export const version = '6.3.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.3.0",
3
+ "version": "6.3.1",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
@@ -118,7 +118,7 @@
118
118
  "test": "node scripts/run-test.ts",
119
119
  "test:node": "tsx --test test/*.test.ts test/**/*.test.ts",
120
120
  "test:bun": "bun test test/*.test.ts test/**/*.test.ts",
121
- "test:smoke": "glob-bin -c \"tsx --test\" \"test/*.test.ts\" && glob-bin -c \"tsx --test\" \"test/{plugins,util}/*.test.ts\"",
121
+ "test:smoke": "glob-bin -c \"tsx --test\" \"test/*.test.ts\" && glob-bin -c \"tsx --test\" \"test/plugins/*.test.ts\" && glob-bin -c \"tsx --test\" \"test/util/*.test.ts\"",
122
122
  "test:bun:smoke": "bun test test/*.test.ts test/{plugins,util}/*.test.ts",
123
123
  "watch": "npm link && tsc --watch",
124
124
  "prebuild": "pnpm run generate-plugin-defs && node rmdir.js dist",