knip 4.0.4 → 4.1.0
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 +3 -1
- package/dist/binaries/bash-parser.js +1 -1
- package/dist/binaries/resolvers/bun.d.ts +2 -0
- package/dist/binaries/resolvers/bun.js +17 -0
- package/dist/binaries/resolvers/index.d.ts +1 -0
- package/dist/binaries/resolvers/index.js +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +3 -0
- package/dist/typescript/visitors/helpers.d.ts +2 -0
- package/dist/typescript/visitors/helpers.js +8 -0
- package/dist/typescript/visitors/scripts/bun.d.ts +3 -0
- package/dist/typescript/visitors/scripts/bun.js +9 -0
- package/dist/typescript/visitors/scripts/execa.js +2 -9
- package/dist/typescript/visitors/scripts/index.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/DependencyDeputy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
|
-
import { IGNORE_DEFINITELY_TYPED, IGNORED_DEPENDENCIES, IGNORED_GLOBAL_BINARIES, ROOT_WORKSPACE_NAME, } from './constants.js';
|
|
2
|
+
import { IGNORE_DEFINITELY_TYPED, IGNORED_DEPENDENCIES, IGNORED_GLOBAL_BINARIES, IGNORED_RUNTIME_DEPENDENCIES, ROOT_WORKSPACE_NAME, } from './constants.js';
|
|
3
3
|
import { isDefinitelyTyped, getDefinitelyTypedFor, getPackageFromDefinitelyTyped } from './util/modules.js';
|
|
4
4
|
import { hasMatch, hasMatchInArray, hasMatchInSet, toRegexOrString, findKey } from './util/regex.js';
|
|
5
5
|
export class DependencyDeputy {
|
|
@@ -111,6 +111,8 @@ export class DependencyDeputy {
|
|
|
111
111
|
maybeAddReferencedExternalDependency(workspace, packageName) {
|
|
112
112
|
if (isBuiltin(packageName))
|
|
113
113
|
return true;
|
|
114
|
+
if (IGNORED_RUNTIME_DEPENDENCIES.has(packageName))
|
|
115
|
+
return true;
|
|
114
116
|
if (packageName === workspace.pkgName)
|
|
115
117
|
return true;
|
|
116
118
|
const workspaceNames = this.isStrict ? [workspace.name] : [workspace.name, ...[...workspace.ancestors].reverse()];
|
|
@@ -19,7 +19,7 @@ export const getBinariesFromScript = (script, { cwd, manifest, knownGlobalsOnly
|
|
|
19
19
|
return [];
|
|
20
20
|
if (binary.startsWith('-') || binary.startsWith('"') || binary.startsWith('..'))
|
|
21
21
|
return [];
|
|
22
|
-
if (['
|
|
22
|
+
if (['deno'].includes(binary))
|
|
23
23
|
return [];
|
|
24
24
|
const args = node.suffix?.map(arg => arg.text) ?? [];
|
|
25
25
|
if (['!', 'test'].includes(binary))
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import parseArgs from 'minimist';
|
|
2
|
+
import { tryResolveFilePath } from '../util.js';
|
|
3
|
+
const commands = ['add', 'create', 'init', 'install', 'link', 'pm', 'remove', 'run', 'update'];
|
|
4
|
+
export const resolve = (_binary, args, { manifest, cwd, fromArgs }) => {
|
|
5
|
+
const scripts = manifest.scripts ? Object.keys(manifest.scripts) : [];
|
|
6
|
+
const parsed = parseArgs(args);
|
|
7
|
+
const [command, script] = parsed._;
|
|
8
|
+
if (command === 'run' && scripts.includes(script))
|
|
9
|
+
return [];
|
|
10
|
+
if (commands.includes(command))
|
|
11
|
+
return [];
|
|
12
|
+
const filePath = command === 'run' ? script : command;
|
|
13
|
+
const specifier = tryResolveFilePath(cwd, filePath);
|
|
14
|
+
if (specifier)
|
|
15
|
+
return [specifier];
|
|
16
|
+
return fromArgs(args);
|
|
17
|
+
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const DEFAULT_EXTENSIONS: string[];
|
|
|
5
5
|
export declare const GLOBAL_IGNORE_PATTERNS: string[];
|
|
6
6
|
export declare const IGNORED_GLOBAL_BINARIES: Set<string>;
|
|
7
7
|
export declare const IGNORED_DEPENDENCIES: Set<string>;
|
|
8
|
+
export declare const IGNORED_RUNTIME_DEPENDENCIES: Set<string>;
|
|
8
9
|
export declare const DUMMY_VIRTUAL_FILE_EXTENSIONS: Set<string>;
|
|
9
10
|
export declare const IGNORED_FILE_EXTENSIONS: Set<string>;
|
|
10
11
|
export declare const IGNORE_DEFINITELY_TYPED: string[];
|
package/dist/constants.js
CHANGED
|
@@ -30,6 +30,8 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
|
|
|
30
30
|
'find',
|
|
31
31
|
'git',
|
|
32
32
|
'grep',
|
|
33
|
+
'gzip',
|
|
34
|
+
'ls',
|
|
33
35
|
'mkdir',
|
|
34
36
|
'mv',
|
|
35
37
|
'node',
|
|
@@ -47,6 +49,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
|
|
|
47
49
|
'xargs',
|
|
48
50
|
]);
|
|
49
51
|
export const IGNORED_DEPENDENCIES = new Set(['knip', 'typescript']);
|
|
52
|
+
export const IGNORED_RUNTIME_DEPENDENCIES = new Set(['bun']);
|
|
50
53
|
export const DUMMY_VIRTUAL_FILE_EXTENSIONS = new Set(['.html', '.jpeg', '.jpg', '.png', '.svg', '.webp']);
|
|
51
54
|
export const IGNORED_FILE_EXTENSIONS = new Set([
|
|
52
55
|
'.avif',
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
1
2
|
import type { BoundSourceFile } from '../SourceFile.js';
|
|
2
3
|
export declare const isNotJS: (sourceFile: BoundSourceFile) => boolean;
|
|
3
4
|
export declare const isJS: (sourceFile: BoundSourceFile) => boolean;
|
|
4
5
|
export declare function getJSXImplicitImportBase(sourceFile: BoundSourceFile): string | undefined;
|
|
6
|
+
export declare function hasImportSpecifier(node: ts.Statement, name: string): boolean;
|
|
@@ -8,3 +8,11 @@ export function getJSXImplicitImportBase(sourceFile) {
|
|
|
8
8
|
: jsxImportSourcePragmas;
|
|
9
9
|
return jsxImportSourcePragma?.arguments.factory;
|
|
10
10
|
}
|
|
11
|
+
export function hasImportSpecifier(node, name) {
|
|
12
|
+
return (ts.isImportDeclaration(node) &&
|
|
13
|
+
ts.isStringLiteral(node.moduleSpecifier) &&
|
|
14
|
+
node.moduleSpecifier.text === name &&
|
|
15
|
+
!!node.importClause?.namedBindings &&
|
|
16
|
+
ts.isNamedImports(node.importClause.namedBindings) &&
|
|
17
|
+
node.importClause.namedBindings.elements.some(element => element.name.text === '$'));
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { stripQuotes } from '../../ast-helpers.js';
|
|
3
|
+
import { hasImportSpecifier } from '../helpers.js';
|
|
4
|
+
import { scriptVisitor as visit } from '../index.js';
|
|
5
|
+
export default visit(sourceFile => sourceFile.statements.some(node => hasImportSpecifier(node, 'bun')), node => {
|
|
6
|
+
if (ts.isTaggedTemplateExpression(node) && node.tag.getText() === '$') {
|
|
7
|
+
return stripQuotes(node.template.getText());
|
|
8
|
+
}
|
|
9
|
+
});
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { stripQuotes } from '../../ast-helpers.js';
|
|
3
|
+
import { hasImportSpecifier } from '../helpers.js';
|
|
3
4
|
import { scriptVisitor as visit } from '../index.js';
|
|
4
|
-
export default visit(sourceFile => sourceFile.statements.some(
|
|
5
|
+
export default visit(sourceFile => sourceFile.statements.some(node => hasImportSpecifier(node, 'execa')), node => {
|
|
5
6
|
if (ts.isTaggedTemplateExpression(node)) {
|
|
6
7
|
if (node.tag.getText() === '$' || (ts.isCallExpression(node.tag) && node.tag.expression.getText() === '$')) {
|
|
7
8
|
return stripQuotes(node.template.getText());
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
});
|
|
11
|
-
function statementImportsExeca$(node) {
|
|
12
|
-
return (ts.isImportDeclaration(node) &&
|
|
13
|
-
ts.isStringLiteral(node.moduleSpecifier) &&
|
|
14
|
-
node.moduleSpecifier.text === 'execa' &&
|
|
15
|
-
!!node.importClause?.namedBindings &&
|
|
16
|
-
ts.isNamedImports(node.importClause.namedBindings) &&
|
|
17
|
-
node.importClause.namedBindings.elements.some(element => element.name.text === '$'));
|
|
18
|
-
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "4.0
|
|
1
|
+
export declare const version = "4.1.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '4.0
|
|
1
|
+
export const version = '4.1.0';
|