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.
- package/dist/DependencyDeputy.js +6 -12
- package/dist/plugins/react-router/index.js +1 -1
- package/dist/typescript/visitors/calls.js +1 -1
- package/dist/typescript/visitors/imports.js +12 -8
- package/dist/typescript/visitors/members.js +4 -3
- package/dist/typescript/visitors/walk.d.ts +2 -2
- package/dist/typescript/visitors/walk.js +5 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/DependencyDeputy.js
CHANGED
|
@@ -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
|
|
191
|
-
const isReferencedDependency = (dependency, isPeerDep) => {
|
|
190
|
+
const isReferencedDependency = (dependency, visited = new Set()) => {
|
|
192
191
|
if (referencedDependencies?.has(dependency))
|
|
193
192
|
return true;
|
|
194
|
-
if (
|
|
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,
|
|
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
|
-
|
|
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
|
|
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 [
|
|
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.
|
|
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' &&
|
|
164
|
-
|
|
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(
|
|
169
|
-
let
|
|
170
|
-
if (!
|
|
171
|
-
|
|
172
|
-
s.
|
|
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
|
|
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
|
|
134
|
-
|
|
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.
|
|
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
|
-
|
|
50
|
-
|
|
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
|
-
|
|
645
|
-
|
|
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,
|
|
686
|
-
for (const nsName of
|
|
687
|
-
if (!state.
|
|
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.
|
|
1
|
+
export declare const version = "6.3.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '6.3.
|
|
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.
|
|
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/
|
|
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",
|