knip 5.33.1 → 5.33.3
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/WorkspaceWorker.d.ts +0 -1
- package/dist/WorkspaceWorker.js +0 -3
- package/dist/index.js +1 -1
- package/dist/plugins/travis/index.js +1 -1
- package/dist/typescript/ast-helpers.d.ts +1 -1
- package/dist/typescript/ast-helpers.js +5 -1
- package/dist/typescript/find-internal-references.d.ts +1 -1
- package/dist/typescript/find-internal-references.js +12 -10
- package/dist/typescript/get-imports-and-exports.js +16 -13
- package/dist/typescript/visitors/exports/exportKeyword.js +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -44,7 +44,6 @@ export declare class WorkspaceWorker {
|
|
|
44
44
|
private getConfigForPlugin;
|
|
45
45
|
getEntryFilePatterns(): string[];
|
|
46
46
|
getProjectFilePatterns(projectFilePatterns: string[]): string[];
|
|
47
|
-
getPluginEntryFilePatterns(patterns: string[]): string[];
|
|
48
47
|
getPluginProjectFilePatterns(): string[];
|
|
49
48
|
getPluginConfigPatterns(): string[];
|
|
50
49
|
getProductionEntryFilePatterns(negatedTestFilePatterns: string[]): string[];
|
package/dist/WorkspaceWorker.js
CHANGED
|
@@ -89,9 +89,6 @@ export class WorkspaceWorker {
|
|
|
89
89
|
this.negatedWorkspacePatterns,
|
|
90
90
|
].flat();
|
|
91
91
|
}
|
|
92
|
-
getPluginEntryFilePatterns(patterns) {
|
|
93
|
-
return [patterns, this.negatedWorkspacePatterns].flat();
|
|
94
|
-
}
|
|
95
92
|
getPluginProjectFilePatterns() {
|
|
96
93
|
const patterns = [];
|
|
97
94
|
for (const [pluginName, plugin] of Object.entries(plugins)) {
|
package/dist/index.js
CHANGED
|
@@ -160,7 +160,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
160
160
|
principal.addProjectPath(projectPath);
|
|
161
161
|
}
|
|
162
162
|
{
|
|
163
|
-
const patterns =
|
|
163
|
+
const patterns = [...entryFilePatterns, ...productionEntryFilePatterns];
|
|
164
164
|
const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
|
|
165
165
|
debugLogArray(name, 'Plugin entry paths', pluginWorkspaceEntryPaths);
|
|
166
166
|
principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
|
|
@@ -2,7 +2,7 @@ import { _glob } from '#p/util/glob.js';
|
|
|
2
2
|
import { getDependenciesFromScripts } from '../../util/plugin.js';
|
|
3
3
|
const title = 'Travis CI';
|
|
4
4
|
const enablers = 'This plugin is enabled when a `.travis.yml` file is found in the root folder.';
|
|
5
|
-
const isEnabled = async ({ cwd }) =>
|
|
5
|
+
const isEnabled = async ({ cwd }) => (await _glob({ cwd, patterns: ['.travis.yml'] })).length > 0;
|
|
6
6
|
const config = ['.travis.yml'];
|
|
7
7
|
const resolveConfig = async (config, options) => {
|
|
8
8
|
if (!config)
|
|
@@ -24,7 +24,7 @@ export declare const isObjectEnumerationCallExpressionArgument: (node: ts.Identi
|
|
|
24
24
|
export declare const isTopLevel: (node: ts.Node) => boolean;
|
|
25
25
|
export declare const getTypeName: (node: ts.Identifier) => ts.QualifiedName | undefined;
|
|
26
26
|
export declare const isImportSpecifier: (node: ts.Node) => boolean;
|
|
27
|
-
export declare const
|
|
27
|
+
export declare const isReferencedInExport: (node: ts.Node) => boolean;
|
|
28
28
|
export declare const getExportKeywordNode: (node: ts.Node) => ts.ExportKeyword | undefined;
|
|
29
29
|
export declare const getDefaultKeywordNode: (node: ts.Node) => ts.DefaultKeyword | undefined;
|
|
30
30
|
export declare const hasRequireCall: (node: ts.Node) => boolean;
|
|
@@ -172,7 +172,11 @@ const getAncestorTypeDeclaration = (node) => {
|
|
|
172
172
|
node = node.parent;
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
|
-
export const
|
|
175
|
+
export const isReferencedInExport = (node) => {
|
|
176
|
+
if (ts.isTypeQueryNode(node.parent) && isExported(node.parent.parent))
|
|
177
|
+
return true;
|
|
178
|
+
if (ts.isTypeReferenceNode(node.parent) && isExported(node.parent.parent))
|
|
179
|
+
return true;
|
|
176
180
|
const typeNode = getAncestorTypeDeclaration(node);
|
|
177
181
|
return Boolean(typeNode && isExported(typeNode));
|
|
178
182
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import type { Export, ExportMember } from '../types/dependency-graph.js';
|
|
3
3
|
export declare const isType: (item: Export | ExportMember) => boolean;
|
|
4
|
-
export declare const findInternalReferences: (item: Export | ExportMember, sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker,
|
|
4
|
+
export declare const findInternalReferences: (item: Export | ExportMember, sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker, referencedSymbolsInExport: Set<ts.Symbol>, isBindingElement?: boolean) => [number, boolean];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { isIdChar } from '../util/regex.js';
|
|
3
3
|
export const isType = (item) => item.type === 'type' || item.type === 'interface' || item.type === 'enum';
|
|
4
|
-
export const findInternalReferences = (item, sourceFile, typeChecker,
|
|
4
|
+
export const findInternalReferences = (item, sourceFile, typeChecker, referencedSymbolsInExport, isBindingElement) => {
|
|
5
5
|
if (!item.symbol)
|
|
6
6
|
return [0, false];
|
|
7
7
|
if (item.identifier === '')
|
|
@@ -12,7 +12,7 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
|
|
|
12
12
|
const id = item.identifier;
|
|
13
13
|
const symbols = new Set();
|
|
14
14
|
let refCount = 0;
|
|
15
|
-
let
|
|
15
|
+
let isSymbolInExport = false;
|
|
16
16
|
let index = 0;
|
|
17
17
|
while (index < text.length && (index = text.indexOf(id, index)) !== -1) {
|
|
18
18
|
if (!isIdChar(text.charAt(index - 1)) && !isIdChar(text.charAt(index + id.length))) {
|
|
@@ -20,21 +20,23 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
|
|
|
20
20
|
if (!isExportDeclaration) {
|
|
21
21
|
const symbol = typeChecker.getSymbolAtLocation(ts.getTokenAtPosition(sourceFile, index));
|
|
22
22
|
if (symbol) {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
23
|
+
const isInExport = referencedSymbolsInExport.has(symbol);
|
|
24
|
+
if (isInExport)
|
|
25
|
+
isSymbolInExport = true;
|
|
26
26
|
if (item.symbol === symbol) {
|
|
27
27
|
refCount++;
|
|
28
|
-
if (
|
|
29
|
-
return [refCount,
|
|
28
|
+
if (isInExport || isType(item))
|
|
29
|
+
return [refCount, isSymbolInExport];
|
|
30
|
+
if (isBindingElement)
|
|
31
|
+
return [refCount, true];
|
|
30
32
|
}
|
|
31
33
|
const declaration = symbol.declarations?.[0];
|
|
32
34
|
if (declaration) {
|
|
33
35
|
if (item.symbol === declaration.name?.flowNode?.node?.symbol) {
|
|
34
|
-
return [++refCount,
|
|
36
|
+
return [++refCount, isSymbolInExport];
|
|
35
37
|
}
|
|
36
38
|
if (ts.isImportSpecifier(declaration) && symbols.has(symbol)) {
|
|
37
|
-
return [++refCount,
|
|
39
|
+
return [++refCount, isSymbolInExport];
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
symbols.add(symbol);
|
|
@@ -43,5 +45,5 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
|
|
|
43
45
|
}
|
|
44
46
|
index += id.length;
|
|
45
47
|
}
|
|
46
|
-
return [refCount,
|
|
48
|
+
return [refCount, isSymbolInExport];
|
|
47
49
|
};
|
|
@@ -6,7 +6,7 @@ import { addNsValue, addValue, createImports } from '../util/dependency-graph.js
|
|
|
6
6
|
import { getPackageNameFromFilePath, isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
|
|
7
7
|
import { extname, isInNodeModules } from '../util/path.js';
|
|
8
8
|
import { shouldIgnore } from '../util/tag.js';
|
|
9
|
-
import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeName, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isObjectEnumerationCallExpressionArgument,
|
|
9
|
+
import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeName, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isObjectEnumerationCallExpressionArgument, isReferencedInExport, } from './ast-helpers.js';
|
|
10
10
|
import { findInternalReferences, isType } from './find-internal-references.js';
|
|
11
11
|
import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
|
|
12
12
|
import getExportVisitors from './visitors/exports/index.js';
|
|
@@ -45,7 +45,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
|
|
|
45
45
|
const scripts = new Set();
|
|
46
46
|
const traceRefs = new Set();
|
|
47
47
|
const importedInternalSymbols = new Map();
|
|
48
|
-
const
|
|
48
|
+
const referencedSymbolsInExport = new Set();
|
|
49
49
|
const visitors = getVisitors(sourceFile);
|
|
50
50
|
const addNsMemberRefs = (internalImport, namespace, member) => {
|
|
51
51
|
if (typeof member === 'string') {
|
|
@@ -280,10 +280,8 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
|
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
if (!isTopLevel && symbol.exportSymbol) {
|
|
284
|
-
|
|
285
|
-
referencedSymbolsInExportedTypes.add(symbol.exportSymbol);
|
|
286
|
-
}
|
|
283
|
+
if (!isTopLevel && symbol.exportSymbol && isReferencedInExport(node)) {
|
|
284
|
+
referencedSymbolsInExport.add(symbol.exportSymbol);
|
|
287
285
|
}
|
|
288
286
|
}
|
|
289
287
|
}
|
|
@@ -308,17 +306,22 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
|
|
|
308
306
|
for (const node of pragmaImports)
|
|
309
307
|
addImport(node, sourceFile);
|
|
310
308
|
for (const item of exports.values()) {
|
|
311
|
-
|
|
312
|
-
if (item.symbol && referencedSymbolsInExportedTypes.has(item.symbol)) {
|
|
309
|
+
if (item.symbol && referencedSymbolsInExport.has(item.symbol)) {
|
|
313
310
|
item.refs = [1, true];
|
|
314
311
|
}
|
|
315
|
-
else
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
312
|
+
else {
|
|
313
|
+
const isBindingElement = item.symbol?.valueDeclaration && ts.isBindingElement(item.symbol.valueDeclaration);
|
|
314
|
+
if (ignoreExportsUsedInFile === true ||
|
|
315
|
+
(typeof ignoreExportsUsedInFile === 'object' &&
|
|
316
|
+
item.type !== 'unknown' &&
|
|
317
|
+
ignoreExportsUsedInFile[item.type]) ||
|
|
318
|
+
isType(item) ||
|
|
319
|
+
isBindingElement) {
|
|
320
|
+
item.refs = findInternalReferences(item, sourceFile, typeChecker, referencedSymbolsInExport, isBindingElement);
|
|
321
|
+
}
|
|
319
322
|
}
|
|
320
323
|
for (const member of item.members) {
|
|
321
|
-
member.refs = findInternalReferences(member, sourceFile, typeChecker,
|
|
324
|
+
member.refs = findInternalReferences(member, sourceFile, typeChecker, referencedSymbolsInExport);
|
|
322
325
|
member.symbol = undefined;
|
|
323
326
|
}
|
|
324
327
|
item.symbol = undefined;
|
|
@@ -19,6 +19,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
|
|
|
19
19
|
: undefined;
|
|
20
20
|
return {
|
|
21
21
|
node: element,
|
|
22
|
+
symbol: element.symbol,
|
|
22
23
|
identifier: element.name.escapedText.toString(),
|
|
23
24
|
type: SymbolType.UNKNOWN,
|
|
24
25
|
pos: element.name.getStart(),
|
|
@@ -33,6 +34,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
|
|
|
33
34
|
const fix = isFixExports ? [element.getStart(), element.getEnd(), FIX_FLAGS.NONE] : undefined;
|
|
34
35
|
return {
|
|
35
36
|
node: element,
|
|
37
|
+
symbol: element.symbol,
|
|
36
38
|
identifier: element.getText(),
|
|
37
39
|
type: SymbolType.UNKNOWN,
|
|
38
40
|
pos: element.getStart(),
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.33.
|
|
1
|
+
export declare const version = "5.33.3";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.33.
|
|
1
|
+
export const version = '5.33.3';
|