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.
@@ -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 (['bun', 'deno'].includes(binary))
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,2 @@
1
+ import type { Resolver } from '../types.js';
2
+ export declare const resolve: Resolver;
@@ -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
+ };
@@ -1,3 +1,4 @@
1
+ export * as bun from './bun.js';
1
2
  export * as c8 from './c8.js';
2
3
  export * as dotenv from './dotenv.js';
3
4
  export * as node from './node.js';
@@ -1,3 +1,4 @@
1
+ export * as bun from './bun.js';
1
2
  export * as c8 from './c8.js';
2
3
  export * as dotenv from './dotenv.js';
3
4
  export * as node from './node.js';
@@ -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,3 @@
1
+ import ts from 'typescript';
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../getImportsAndExports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
3
+ export default _default;
@@ -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(statementImportsExeca$), node => {
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
- }
@@ -1,5 +1,6 @@
1
1
  import ts from 'typescript';
2
+ import bun from './bun.js';
2
3
  import execa from './execa.js';
3
4
  import zx from './zx.js';
4
- const visitors = [execa, zx];
5
+ const visitors = [bun, execa, zx];
5
6
  export default (sourceFile) => visitors.map(v => v(sourceFile));
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "4.0.4";
1
+ export declare const version = "4.1.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '4.0.4';
1
+ export const version = '4.1.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "4.0.4",
3
+ "version": "4.1.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {