knip 5.63.1 → 5.64.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/CacheConsultant.js +1 -1
- package/dist/ConfigurationChief.d.ts +20 -8
- package/dist/DependencyDeputy.js +5 -4
- package/dist/IssueCollector.js +1 -1
- package/dist/IssueFixer.js +3 -1
- package/dist/ProjectPrincipal.d.ts +1 -1
- package/dist/ProjectPrincipal.js +2 -2
- package/dist/WorkspaceWorker.d.ts +1 -1
- package/dist/WorkspaceWorker.js +2 -2
- package/dist/binaries/bash-parser.d.ts +1 -0
- package/dist/binaries/bash-parser.js +3 -0
- package/dist/binaries/fallback.js +3 -2
- package/dist/binaries/index.js +1 -1
- package/dist/binaries/package-manager/bun.js +1 -0
- package/dist/binaries/plugins.js +3 -1
- package/dist/cli.js +9 -9
- package/dist/compilers/index.d.ts +57 -30
- package/dist/compilers/index.js +1 -1
- package/dist/constants.js +2 -0
- package/dist/graph/analyze.js +7 -4
- package/dist/graph/build.js +9 -9
- package/dist/index.js +2 -2
- package/dist/manifest/index.js +1 -1
- package/dist/plugins/angular/index.js +2 -3
- package/dist/plugins/bumpp/index.d.ts +8 -0
- package/dist/plugins/bumpp/index.js +11 -0
- package/dist/plugins/changelogen/index.js +1 -1
- package/dist/plugins/changelogithub/index.js +1 -1
- package/dist/plugins/commitlint/index.js +1 -1
- package/dist/plugins/eslint/index.d.ts +7 -0
- package/dist/plugins/eslint/index.js +12 -0
- package/dist/plugins/glob/index.d.ts +0 -1
- package/dist/plugins/glob/index.js +0 -1
- package/dist/plugins/index.d.ts +19 -7
- package/dist/plugins/index.js +6 -2
- package/dist/plugins/karma/helpers.js +1 -1
- package/dist/plugins/lint-staged/index.js +1 -1
- package/dist/plugins/linthtml/index.js +1 -1
- package/dist/plugins/lockfile-lint/index.js +1 -1
- package/dist/plugins/node-modules-inspector/index.d.ts +0 -1
- package/dist/plugins/node-modules-inspector/index.js +1 -2
- package/dist/plugins/npm-package-json-lint/index.js +1 -1
- package/dist/plugins/nuxt/index.js +7 -1
- package/dist/plugins/nuxt/types.d.ts +1 -1
- package/dist/plugins/oxlint/index.d.ts +0 -1
- package/dist/plugins/oxlint/index.js +0 -1
- package/dist/plugins/playwright/index.d.ts +0 -1
- package/dist/plugins/playwright/index.js +0 -1
- package/dist/plugins/playwright-test/index.d.ts +0 -1
- package/dist/plugins/playwright-test/index.js +0 -1
- package/dist/plugins/pnpm/index.d.ts +1 -0
- package/dist/plugins/pnpm/index.js +5 -1
- package/dist/plugins/postcss/index.js +1 -1
- package/dist/plugins/prisma/index.d.ts +0 -1
- package/dist/plugins/prisma/index.js +0 -1
- package/dist/plugins/react-router/index.js +1 -1
- package/dist/plugins/rslib/index.js +1 -1
- package/dist/plugins/rstest/index.d.ts +10 -0
- package/dist/plugins/rstest/index.js +29 -0
- package/dist/plugins/rstest/types.d.ts +6 -0
- package/dist/plugins/rstest/types.js +1 -0
- package/dist/plugins/semantic-release/index.js +1 -1
- package/dist/plugins/size-limit/index.js +1 -1
- package/dist/plugins/stylelint/index.js +1 -1
- package/dist/plugins/syncpack/index.js +1 -1
- package/dist/plugins/ts-node/index.d.ts +0 -1
- package/dist/plugins/ts-node/index.js +0 -1
- package/dist/plugins/unocss/index.js +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/reporters/githubActions.d.ts +3 -0
- package/dist/reporters/githubActions.js +94 -0
- package/dist/reporters/index.d.ts +1 -0
- package/dist/reporters/index.js +2 -0
- package/dist/reporters/json.js +1 -1
- package/dist/reporters/util/configuration-hints.d.ts +13 -1
- package/dist/reporters/util/configuration-hints.js +1 -0
- package/dist/schema/configuration.d.ts +1187 -6393
- package/dist/schema/configuration.js +54 -51
- package/dist/schema/plugins.d.ts +579 -2595
- package/dist/schema/plugins.js +6 -4
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +2 -0
- package/dist/types/args.d.ts +2 -0
- package/dist/types/config.d.ts +2 -2
- package/dist/types/exports.d.ts +1 -1
- package/dist/types/imports.d.ts +1 -1
- package/dist/types/module-graph.d.ts +5 -4
- package/dist/typescript/SourceFile.d.ts +2 -2
- package/dist/typescript/ast-helpers.d.ts +4 -0
- package/dist/typescript/ast-helpers.js +29 -0
- package/dist/typescript/find-internal-references.js +10 -1
- package/dist/typescript/get-imports-and-exports.js +28 -18
- package/dist/typescript/resolve-module-names.js +1 -1
- package/dist/typescript/visitors/dynamic-imports/importCall.js +6 -1
- package/dist/util/cli-arguments.d.ts +3 -2
- package/dist/util/cli-arguments.js +2 -2
- package/dist/util/create-options.d.ts +61 -35
- package/dist/util/create-options.js +1 -1
- package/dist/util/errors.d.ts +4 -4
- package/dist/util/errors.js +8 -8
- package/dist/util/file-entry-cache.js +1 -1
- package/dist/util/glob-core.js +1 -1
- package/dist/util/glob.js +1 -1
- package/dist/util/input.d.ts +1 -1
- package/dist/util/load-config.d.ts +2 -1
- package/dist/util/load-config.js +4 -4
- package/dist/util/loader.js +1 -1
- package/dist/util/modules.js +18 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +18 -19
- package/schema.json +8 -0
package/dist/schema/plugins.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
1
|
+
import { z } from 'zod/mini';
|
|
2
2
|
export const globSchema = z.union([z.string(), z.array(z.string())]);
|
|
3
3
|
export const pluginSchema = z.union([
|
|
4
4
|
z.boolean(),
|
|
5
5
|
globSchema,
|
|
6
6
|
z.object({
|
|
7
|
-
config:
|
|
8
|
-
entry:
|
|
9
|
-
project:
|
|
7
|
+
config: z.optional(globSchema),
|
|
8
|
+
entry: z.optional(globSchema),
|
|
9
|
+
project: z.optional(globSchema),
|
|
10
10
|
}),
|
|
11
11
|
]);
|
|
12
12
|
export const pluginsSchema = z.object({
|
|
@@ -15,6 +15,7 @@ export const pluginsSchema = z.object({
|
|
|
15
15
|
ava: pluginSchema,
|
|
16
16
|
babel: pluginSchema,
|
|
17
17
|
biome: pluginSchema,
|
|
18
|
+
bumpp: pluginSchema,
|
|
18
19
|
bun: pluginSchema,
|
|
19
20
|
c8: pluginSchema,
|
|
20
21
|
capacitor: pluginSchema,
|
|
@@ -88,6 +89,7 @@ export const pluginsSchema = z.object({
|
|
|
88
89
|
rsbuild: pluginSchema,
|
|
89
90
|
rslib: pluginSchema,
|
|
90
91
|
rspack: pluginSchema,
|
|
92
|
+
rstest: pluginSchema,
|
|
91
93
|
'semantic-release': pluginSchema,
|
|
92
94
|
sentry: pluginSchema,
|
|
93
95
|
'simple-git-hooks': pluginSchema,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type PluginName = 'angular' | 'astro' | 'ava' | 'babel' | 'biome' | 'bun' | 'c8' | 'capacitor' | 'changelogen' | 'changelogithub' | 'changesets' | 'commitizen' | 'commitlint' | 'convex' | 'create-typescript-app' | 'cspell' | 'cucumber' | 'cypress' | 'dependency-cruiser' | 'docusaurus' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'hardhat' | 'husky' | 'i18next-parser' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nano-staged' | 'nest' | 'netlify' | 'next' | 'node' | 'node-modules-inspector' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'oxlint' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'pnpm' | 'postcss' | 'preconstruct' | 'prettier' | 'prisma' | 'react-cosmos' | 'react-router' | 'relay' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rslib' | 'rspack' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'sst' | 'starlight' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'svgo' | 'syncpack' | 'tailwind' | 'travis' | 'ts-node' | 'tsdown' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
|
|
2
|
-
export declare const pluginNames: readonly ["angular", "astro", "ava", "babel", "biome", "bun", "c8", "capacitor", "changelogen", "changelogithub", "changesets", "commitizen", "commitlint", "convex", "create-typescript-app", "cspell", "cucumber", "cypress", "dependency-cruiser", "docusaurus", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "hardhat", "husky", "i18next-parser", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "metro", "mocha", "moonrepo", "msw", "nano-staged", "nest", "netlify", "next", "node", "node-modules-inspector", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "oxlint", "playwright", "playwright-ct", "playwright-test", "plop", "pnpm", "postcss", "preconstruct", "prettier", "prisma", "react-cosmos", "react-router", "relay", "release-it", "remark", "remix", "rollup", "rsbuild", "rslib", "rspack", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "sst", "starlight", "storybook", "stryker", "stylelint", "svelte", "svgo", "syncpack", "tailwind", "travis", "ts-node", "tsdown", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
|
|
1
|
+
export type PluginName = 'angular' | 'astro' | 'ava' | 'babel' | 'biome' | 'bumpp' | 'bun' | 'c8' | 'capacitor' | 'changelogen' | 'changelogithub' | 'changesets' | 'commitizen' | 'commitlint' | 'convex' | 'create-typescript-app' | 'cspell' | 'cucumber' | 'cypress' | 'dependency-cruiser' | 'docusaurus' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'hardhat' | 'husky' | 'i18next-parser' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nano-staged' | 'nest' | 'netlify' | 'next' | 'node' | 'node-modules-inspector' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'oxlint' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'pnpm' | 'postcss' | 'preconstruct' | 'prettier' | 'prisma' | 'react-cosmos' | 'react-router' | 'relay' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rslib' | 'rspack' | 'rstest' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'sst' | 'starlight' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'svgo' | 'syncpack' | 'tailwind' | 'travis' | 'ts-node' | 'tsdown' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
|
|
2
|
+
export declare const pluginNames: readonly ["angular", "astro", "ava", "babel", "biome", "bumpp", "bun", "c8", "capacitor", "changelogen", "changelogithub", "changesets", "commitizen", "commitlint", "convex", "create-typescript-app", "cspell", "cucumber", "cypress", "dependency-cruiser", "docusaurus", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "hardhat", "husky", "i18next-parser", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "metro", "mocha", "moonrepo", "msw", "nano-staged", "nest", "netlify", "next", "node", "node-modules-inspector", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "oxlint", "playwright", "playwright-ct", "playwright-test", "plop", "pnpm", "postcss", "preconstruct", "prettier", "prisma", "react-cosmos", "react-router", "relay", "release-it", "remark", "remix", "rollup", "rsbuild", "rslib", "rspack", "rstest", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "sst", "starlight", "storybook", "stryker", "stylelint", "svelte", "svgo", "syncpack", "tailwind", "travis", "ts-node", "tsdown", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
|
|
@@ -4,6 +4,7 @@ export const pluginNames = [
|
|
|
4
4
|
'ava',
|
|
5
5
|
'babel',
|
|
6
6
|
'biome',
|
|
7
|
+
'bumpp',
|
|
7
8
|
'bun',
|
|
8
9
|
'c8',
|
|
9
10
|
'capacitor',
|
|
@@ -77,6 +78,7 @@ export const pluginNames = [
|
|
|
77
78
|
'rsbuild',
|
|
78
79
|
'rslib',
|
|
79
80
|
'rspack',
|
|
81
|
+
'rstest',
|
|
80
82
|
'semantic-release',
|
|
81
83
|
'sentry',
|
|
82
84
|
'simple-git-hooks',
|
package/dist/types/args.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ParsedArgs } from 'minimist';
|
|
2
|
+
import type { Input } from '../util/input.js';
|
|
2
3
|
export type ConfigArg = boolean | (string | [string, (id: string) => string])[];
|
|
3
4
|
export type Args = {
|
|
4
5
|
binaries?: string[];
|
|
@@ -11,4 +12,5 @@ export type Args = {
|
|
|
11
12
|
config?: ConfigArg;
|
|
12
13
|
args?: (args: string[]) => string[];
|
|
13
14
|
fromArgs?: string[] | ((parsed: ParsedArgs, args: string[]) => string[]);
|
|
15
|
+
resolveInputs?: (parsed: ParsedArgs, args: string[]) => Input[];
|
|
14
16
|
};
|
package/dist/types/config.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type ts from 'typescript';
|
|
2
|
-
import type { z } from 'zod';
|
|
2
|
+
import type { z } from 'zod/mini';
|
|
3
3
|
import type { AsyncCompilers, SyncCompilers } from '../compilers/types.js';
|
|
4
4
|
import type { knipConfigurationSchema } from '../schema/configuration.js';
|
|
5
5
|
import type { pluginSchema } from '../schema/plugins.js';
|
|
6
6
|
import type { Input } from '../util/input.js';
|
|
7
|
-
import type { PluginName } from './PluginNames.js';
|
|
8
7
|
import type { Args } from './args.js';
|
|
9
8
|
import type { SymbolType } from './issues.js';
|
|
10
9
|
import type { Tags } from './options.js';
|
|
10
|
+
import type { PluginName } from './PluginNames.js';
|
|
11
11
|
import type { PackageJson } from './package-json.js';
|
|
12
12
|
export interface GetInputsFromScriptsOptions extends BaseOptions {
|
|
13
13
|
knownBinsOnly?: boolean;
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type ts from 'typescript';
|
|
2
2
|
import type { SymbolType } from './issues.js';
|
|
3
3
|
type Identifier = string;
|
|
4
|
-
type ExportPosTuple = [number, number, number];
|
|
4
|
+
export type ExportPosTuple = [number, number, number];
|
|
5
5
|
export type Fix = ExportPosTuple | undefined;
|
|
6
6
|
export type Fixes = Array<ExportPosTuple>;
|
|
7
7
|
export type ExportNode = {
|
package/dist/types/imports.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type ImportDetails = {
|
|
|
19
19
|
reExportedNs: IdToFileMap;
|
|
20
20
|
};
|
|
21
21
|
export type ImportMap = Map<FilePath, ImportDetails>;
|
|
22
|
-
export type
|
|
22
|
+
export type Import = {
|
|
23
23
|
specifier: string;
|
|
24
24
|
pos?: number;
|
|
25
25
|
line?: number;
|
|
@@ -50,13 +50,14 @@ export type ExportMember = {
|
|
|
50
50
|
jsDocTags: Tags;
|
|
51
51
|
};
|
|
52
52
|
export type ExportMap = Map<Identifier, Export>;
|
|
53
|
+
export type Specifiers = Set<[Import, FilePath]>;
|
|
53
54
|
export type FileNode = {
|
|
54
55
|
imports: {
|
|
55
56
|
internal: ImportMap;
|
|
56
|
-
external: Set<
|
|
57
|
-
unresolved: Set<
|
|
57
|
+
external: Set<Import>;
|
|
58
|
+
unresolved: Set<Import>;
|
|
58
59
|
resolved: Set<FilePath>;
|
|
59
|
-
specifiers:
|
|
60
|
+
specifiers: Specifiers;
|
|
60
61
|
};
|
|
61
62
|
exports: ExportMap;
|
|
62
63
|
duplicates: Iterable<Array<IssueSymbol>>;
|
|
@@ -49,3 +49,7 @@ export declare const isModuleExportsAccess: (node: ts.PropertyAccessExpression)
|
|
|
49
49
|
export declare const getImportMap: (sourceFile: ts.SourceFile) => Map<string, string>;
|
|
50
50
|
export declare const getDefaultImportName: (importMap: ReturnType<typeof getImportMap>, specifier: string) => string | undefined;
|
|
51
51
|
export declare const getPropertyValues: (node: ts.ObjectLiteralExpression, propertyName: string) => Set<string>;
|
|
52
|
+
export declare const getAccessedIdentifiers: (identifier: string, scope: ts.Node) => {
|
|
53
|
+
identifier: string;
|
|
54
|
+
pos: number;
|
|
55
|
+
}[];
|
|
@@ -265,3 +265,32 @@ export const getPropertyValues = (node, propertyName) => {
|
|
|
265
265
|
}
|
|
266
266
|
return values;
|
|
267
267
|
};
|
|
268
|
+
export const getAccessedIdentifiers = (identifier, scope) => {
|
|
269
|
+
const identifiers = [];
|
|
270
|
+
function visit(node) {
|
|
271
|
+
if (ts.isPropertyAccessExpression(node) && node.expression.getText() === identifier) {
|
|
272
|
+
identifiers.push({ identifier: String(node.name.escapedText), pos: node.name.pos });
|
|
273
|
+
}
|
|
274
|
+
else if (ts.isElementAccessExpression(node) &&
|
|
275
|
+
node.expression.getText() === identifier &&
|
|
276
|
+
ts.isStringLiteral(node.argumentExpression)) {
|
|
277
|
+
identifiers.push({
|
|
278
|
+
identifier: stripQuotes(node.argumentExpression.text),
|
|
279
|
+
pos: node.argumentExpression.pos,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
else if (ts.isVariableDeclaration(node) &&
|
|
283
|
+
node.initializer?.getText() === identifier &&
|
|
284
|
+
ts.isObjectBindingPattern(node.name)) {
|
|
285
|
+
for (const element of node.name.elements) {
|
|
286
|
+
if (ts.isBindingElement(element)) {
|
|
287
|
+
const identifier = (element.propertyName ?? element.name).getText();
|
|
288
|
+
identifiers.push({ identifier, pos: element.pos });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
ts.forEachChild(node, visit);
|
|
293
|
+
}
|
|
294
|
+
visit(scope);
|
|
295
|
+
return identifiers;
|
|
296
|
+
};
|
|
@@ -38,12 +38,21 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
|
|
|
38
38
|
const declaration = symbol.declarations?.[0];
|
|
39
39
|
if (declaration) {
|
|
40
40
|
if (findInFlow(declaration.name?.flowNode, item.symbol)) {
|
|
41
|
-
|
|
41
|
+
refCount++;
|
|
42
|
+
return [refCount, isSymbolInExport];
|
|
42
43
|
}
|
|
43
44
|
if (ts.isImportSpecifier(declaration) && symbols.has(symbol)) {
|
|
44
45
|
return [++refCount, isSymbolInExport];
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Property) {
|
|
49
|
+
const type = typeChecker.getTypeOfSymbol(symbol);
|
|
50
|
+
if (type?.symbol && item.symbol === type.symbol) {
|
|
51
|
+
refCount++;
|
|
52
|
+
if (isBindingElement)
|
|
53
|
+
return [refCount, isSymbolInExport];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
47
56
|
symbols.add(symbol);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { ALIAS_TAG, ANONYMOUS, IMPORT_STAR, PROTOCOL_VIRTUAL } from '../constants.js';
|
|
4
|
-
import { timerify } from '../util/Performance.js';
|
|
5
4
|
import { addNsValue, addValue, createImports } from '../util/module-graph.js';
|
|
6
5
|
import { getPackageNameFromFilePath, isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
|
|
6
|
+
import { timerify } from '../util/Performance.js';
|
|
7
7
|
import { isInNodeModules } from '../util/path.js';
|
|
8
8
|
import { shouldIgnore } from '../util/tag.js';
|
|
9
9
|
import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeRef, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isInForIteration, isObjectEnumerationCallExpressionArgument, isReferencedInExport, } from './ast-helpers.js';
|
|
@@ -78,7 +78,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
78
78
|
const addInternalImport = (options) => {
|
|
79
79
|
const { identifier, symbol, filePath, namespace, alias, specifier, isReExport } = options;
|
|
80
80
|
const isStar = identifier === IMPORT_STAR;
|
|
81
|
-
specifiers.add([specifier, filePath]);
|
|
81
|
+
specifiers.add([{ specifier, pos: options.pos, line: options.line, col: options.col }, filePath]);
|
|
82
82
|
const file = internal.get(filePath);
|
|
83
83
|
const imports = file ?? createImports();
|
|
84
84
|
if (!file)
|
|
@@ -112,10 +112,9 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
const addImport = (opts, node) => {
|
|
115
|
-
|
|
116
|
-
if (isBuiltin(specifier))
|
|
115
|
+
if (isBuiltin(opts.specifier))
|
|
117
116
|
return;
|
|
118
|
-
const module = resolveModule(specifier);
|
|
117
|
+
const module = resolveModule(opts.specifier);
|
|
119
118
|
if (module) {
|
|
120
119
|
const filePath = module.resolvedFileName;
|
|
121
120
|
if (filePath) {
|
|
@@ -124,33 +123,44 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
124
123
|
return;
|
|
125
124
|
}
|
|
126
125
|
if (!module.isExternalLibraryImport || !isInNodeModules(filePath)) {
|
|
127
|
-
|
|
126
|
+
const { line, character } = node.getSourceFile().getLineAndCharacterOfPosition(opts.pos);
|
|
127
|
+
addInternalImport({
|
|
128
|
+
...opts,
|
|
129
|
+
identifier: opts.identifier ?? ANONYMOUS,
|
|
130
|
+
filePath,
|
|
131
|
+
isReExport: opts.isReExport ?? false,
|
|
132
|
+
line: line + 1,
|
|
133
|
+
col: character + 1,
|
|
134
|
+
});
|
|
128
135
|
}
|
|
129
136
|
if (module.isExternalLibraryImport) {
|
|
130
|
-
if (options.skipTypeOnly && isTypeOnly)
|
|
137
|
+
if (options.skipTypeOnly && opts.isTypeOnly)
|
|
131
138
|
return;
|
|
132
|
-
const
|
|
139
|
+
const isInNM = isInNodeModules(opts.specifier);
|
|
140
|
+
const sanitizedSpecifier = sanitizeSpecifier(isInNM || isInNodeModules(filePath) ? getPackageNameFromFilePath(opts.specifier) : opts.specifier);
|
|
133
141
|
if (!isStartsLikePackageName(sanitizedSpecifier)) {
|
|
134
142
|
return;
|
|
135
143
|
}
|
|
136
|
-
|
|
144
|
+
if (isInNM) {
|
|
145
|
+
external.add({ specifier: sanitizedSpecifier });
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(opts.pos);
|
|
149
|
+
external.add({ specifier: sanitizedSpecifier, pos: opts.pos, line: line + 1, col: character + 2 });
|
|
150
|
+
}
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
153
|
}
|
|
140
154
|
else {
|
|
141
|
-
if (options.skipTypeOnly && isTypeOnly)
|
|
155
|
+
if (options.skipTypeOnly && opts.isTypeOnly)
|
|
142
156
|
return;
|
|
143
157
|
if (shouldIgnore(getJSDocTags(node), options.tags))
|
|
144
158
|
return;
|
|
145
|
-
if (specifier.startsWith(PROTOCOL_VIRTUAL))
|
|
159
|
+
if (opts.specifier.startsWith(PROTOCOL_VIRTUAL))
|
|
146
160
|
return;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
unresolved.add({ specifier });
|
|
153
|
-
}
|
|
161
|
+
const pos = 'moduleSpecifier' in node ? node.moduleSpecifier.pos : node.pos;
|
|
162
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(pos);
|
|
163
|
+
unresolved.add({ specifier: opts.specifier, pos, line: line + 1, col: character + 2 });
|
|
154
164
|
}
|
|
155
165
|
};
|
|
156
166
|
const addExport = ({ node, symbol, identifier, type, pos, members = [], fix }) => {
|
|
@@ -2,8 +2,8 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { isBuiltin } from 'node:module';
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { DEFAULT_EXTENSIONS } from '../constants.js';
|
|
5
|
-
import { timerify } from '../util/Performance.js';
|
|
6
5
|
import { sanitizeSpecifier } from '../util/modules.js';
|
|
6
|
+
import { timerify } from '../util/Performance.js';
|
|
7
7
|
import { dirname, extname, isAbsolute, isInNodeModules, join } from '../util/path.js';
|
|
8
8
|
import { _createSyncResolver, _resolveSync } from '../util/resolve.js';
|
|
9
9
|
import { isDeclarationFileExtension } from './ast-helpers.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { ANONYMOUS } from '../../../constants.js';
|
|
3
|
-
import { findAncestor, findDescendants, isAccessExpression, isImportCall, isTopLevel, stripQuotes, } from '../../ast-helpers.js';
|
|
3
|
+
import { findAncestor, findDescendants, getAccessedIdentifiers, isAccessExpression, isImportCall, isTopLevel, stripQuotes, } from '../../ast-helpers.js';
|
|
4
4
|
import { importVisitor as visit } from '../index.js';
|
|
5
5
|
const getSymbol = (node, isTopLevel) => (isTopLevel ? node.symbol : undefined);
|
|
6
6
|
export default visit(() => true, node => {
|
|
@@ -64,6 +64,11 @@ export default visit(() => true, node => {
|
|
|
64
64
|
if (ts.isIdentifier(variableDeclaration.name)) {
|
|
65
65
|
const alias = String(variableDeclaration.name.escapedText);
|
|
66
66
|
const symbol = getSymbol(variableDeclaration, isTLA);
|
|
67
|
+
const scope = findAncestor(variableDeclaration, ts.isFunctionBody) || node.getSourceFile();
|
|
68
|
+
const accessed = getAccessedIdentifiers(alias, scope);
|
|
69
|
+
if (accessed.length > 0) {
|
|
70
|
+
return accessed.map(acc => ({ identifier: acc.identifier, alias, symbol, specifier, pos: acc.pos }));
|
|
71
|
+
}
|
|
67
72
|
return { identifier: 'default', alias, symbol, specifier, pos: node.arguments[0].pos };
|
|
68
73
|
}
|
|
69
74
|
const bindings = findDescendants(variableDeclaration, ts.isBindingElement);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --format Format modified files after --fix using the local formatter\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n(2) Fixable issue types: dependencies, exports, types\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
|
|
2
|
-
export
|
|
1
|
+
export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --format Format modified files after --fix using the local formatter\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, github-actions, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n(2) Fixable issue types: dependencies, exports, types\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
|
|
2
|
+
export type ParsedCLIArgs = ReturnType<typeof parseCLIArgs>;
|
|
3
|
+
export default function parseCLIArgs(): {
|
|
3
4
|
cache?: boolean | undefined;
|
|
4
5
|
'cache-location'?: string | undefined;
|
|
5
6
|
config?: string | undefined;
|
|
@@ -29,7 +29,7 @@ Options:
|
|
|
29
29
|
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
30
30
|
--preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
|
|
31
31
|
--preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)
|
|
32
|
-
--reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, can be repeated (default: symbols)
|
|
32
|
+
--reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, github-actions, can be repeated (default: symbols)
|
|
33
33
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
34
34
|
--tags Include or exclude tagged exports
|
|
35
35
|
--no-config-hints Suppress configuration hints
|
|
@@ -60,7 +60,7 @@ $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
|
60
60
|
$ knip --tags=-lintignore
|
|
61
61
|
|
|
62
62
|
Website: https://knip.dev`;
|
|
63
|
-
export default function () {
|
|
63
|
+
export default function parseCLIArgs() {
|
|
64
64
|
return parseArgs({
|
|
65
65
|
options: {
|
|
66
66
|
cache: { type: 'boolean' },
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { Options } from '../types/options.js';
|
|
2
|
-
import type
|
|
3
|
-
type ParsedArgs = ReturnType<typeof parseArgs>;
|
|
2
|
+
import type { ParsedCLIArgs } from './cli-arguments.js';
|
|
4
3
|
interface CreateOptions extends Partial<Options> {
|
|
5
|
-
parsedCLIArgs?:
|
|
4
|
+
parsedCLIArgs?: ParsedCLIArgs;
|
|
6
5
|
}
|
|
7
6
|
export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
8
7
|
cacheLocation: string;
|
|
@@ -39,13 +38,6 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
39
38
|
isTreatConfigHintsAsErrors: boolean;
|
|
40
39
|
isWatch: boolean;
|
|
41
40
|
parsedConfig: {
|
|
42
|
-
node?: string | boolean | string[] | {
|
|
43
|
-
config?: string | string[] | undefined;
|
|
44
|
-
entry?: string | string[] | undefined;
|
|
45
|
-
project?: string | string[] | undefined;
|
|
46
|
-
} | undefined;
|
|
47
|
-
entry?: string | string[] | undefined;
|
|
48
|
-
project?: string | string[] | undefined;
|
|
49
41
|
angular?: string | boolean | string[] | {
|
|
50
42
|
config?: string | string[] | undefined;
|
|
51
43
|
entry?: string | string[] | undefined;
|
|
@@ -71,6 +63,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
71
63
|
entry?: string | string[] | undefined;
|
|
72
64
|
project?: string | string[] | undefined;
|
|
73
65
|
} | undefined;
|
|
66
|
+
bumpp?: string | boolean | string[] | {
|
|
67
|
+
config?: string | string[] | undefined;
|
|
68
|
+
entry?: string | string[] | undefined;
|
|
69
|
+
project?: string | string[] | undefined;
|
|
70
|
+
} | undefined;
|
|
74
71
|
bun?: string | boolean | string[] | {
|
|
75
72
|
config?: string | string[] | undefined;
|
|
76
73
|
entry?: string | string[] | undefined;
|
|
@@ -296,6 +293,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
296
293
|
entry?: string | string[] | undefined;
|
|
297
294
|
project?: string | string[] | undefined;
|
|
298
295
|
} | undefined;
|
|
296
|
+
node?: string | boolean | string[] | {
|
|
297
|
+
config?: string | string[] | undefined;
|
|
298
|
+
entry?: string | string[] | undefined;
|
|
299
|
+
project?: string | string[] | undefined;
|
|
300
|
+
} | undefined;
|
|
299
301
|
'node-modules-inspector'?: string | boolean | string[] | {
|
|
300
302
|
config?: string | string[] | undefined;
|
|
301
303
|
entry?: string | string[] | undefined;
|
|
@@ -431,6 +433,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
431
433
|
entry?: string | string[] | undefined;
|
|
432
434
|
project?: string | string[] | undefined;
|
|
433
435
|
} | undefined;
|
|
436
|
+
rstest?: string | boolean | string[] | {
|
|
437
|
+
config?: string | string[] | undefined;
|
|
438
|
+
entry?: string | string[] | undefined;
|
|
439
|
+
project?: string | string[] | undefined;
|
|
440
|
+
} | undefined;
|
|
434
441
|
'semantic-release'?: string | boolean | string[] | {
|
|
435
442
|
config?: string | string[] | undefined;
|
|
436
443
|
entry?: string | string[] | undefined;
|
|
@@ -601,32 +608,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
601
608
|
entry?: string | string[] | undefined;
|
|
602
609
|
project?: string | string[] | undefined;
|
|
603
610
|
} | undefined;
|
|
604
|
-
exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
|
|
605
|
-
$schema?: string | undefined;
|
|
606
|
-
rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers", "error" | "warn" | "off">> | undefined;
|
|
607
|
-
paths?: Record<string, string[]> | undefined;
|
|
608
|
-
ignore?: string | string[] | undefined;
|
|
609
|
-
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
610
|
-
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
611
|
-
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
612
|
-
ignoreUnresolved?: (string | RegExp)[] | undefined;
|
|
613
|
-
ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
|
|
614
|
-
ignoreWorkspaces?: string[] | undefined;
|
|
615
|
-
includeEntryExports?: boolean | undefined;
|
|
616
|
-
compilers?: Record<string, true | ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
|
|
617
|
-
syncCompilers?: Record<string, true | ((args_0: string, args_1: string, ...args: unknown[]) => string)> | undefined;
|
|
618
|
-
asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => Promise<string>> | undefined;
|
|
619
|
-
tags?: string[] | undefined;
|
|
620
|
-
treatConfigHintsAsErrors?: boolean | undefined;
|
|
621
|
-
include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
|
|
622
611
|
workspaces?: Record<string, {
|
|
623
|
-
node?: string | boolean | string[] | {
|
|
624
|
-
config?: string | string[] | undefined;
|
|
625
|
-
entry?: string | string[] | undefined;
|
|
626
|
-
project?: string | string[] | undefined;
|
|
627
|
-
} | undefined;
|
|
628
|
-
entry?: string | string[] | undefined;
|
|
629
|
-
project?: string | string[] | undefined;
|
|
630
612
|
angular?: string | boolean | string[] | {
|
|
631
613
|
config?: string | string[] | undefined;
|
|
632
614
|
entry?: string | string[] | undefined;
|
|
@@ -652,6 +634,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
652
634
|
entry?: string | string[] | undefined;
|
|
653
635
|
project?: string | string[] | undefined;
|
|
654
636
|
} | undefined;
|
|
637
|
+
bumpp?: string | boolean | string[] | {
|
|
638
|
+
config?: string | string[] | undefined;
|
|
639
|
+
entry?: string | string[] | undefined;
|
|
640
|
+
project?: string | string[] | undefined;
|
|
641
|
+
} | undefined;
|
|
655
642
|
bun?: string | boolean | string[] | {
|
|
656
643
|
config?: string | string[] | undefined;
|
|
657
644
|
entry?: string | string[] | undefined;
|
|
@@ -877,6 +864,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
877
864
|
entry?: string | string[] | undefined;
|
|
878
865
|
project?: string | string[] | undefined;
|
|
879
866
|
} | undefined;
|
|
867
|
+
node?: string | boolean | string[] | {
|
|
868
|
+
config?: string | string[] | undefined;
|
|
869
|
+
entry?: string | string[] | undefined;
|
|
870
|
+
project?: string | string[] | undefined;
|
|
871
|
+
} | undefined;
|
|
880
872
|
'node-modules-inspector'?: string | boolean | string[] | {
|
|
881
873
|
config?: string | string[] | undefined;
|
|
882
874
|
entry?: string | string[] | undefined;
|
|
@@ -1012,6 +1004,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
1012
1004
|
entry?: string | string[] | undefined;
|
|
1013
1005
|
project?: string | string[] | undefined;
|
|
1014
1006
|
} | undefined;
|
|
1007
|
+
rstest?: string | boolean | string[] | {
|
|
1008
|
+
config?: string | string[] | undefined;
|
|
1009
|
+
entry?: string | string[] | undefined;
|
|
1010
|
+
project?: string | string[] | undefined;
|
|
1011
|
+
} | undefined;
|
|
1015
1012
|
'semantic-release'?: string | boolean | string[] | {
|
|
1016
1013
|
config?: string | string[] | undefined;
|
|
1017
1014
|
entry?: string | string[] | undefined;
|
|
@@ -1182,6 +1179,8 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
1182
1179
|
entry?: string | string[] | undefined;
|
|
1183
1180
|
project?: string | string[] | undefined;
|
|
1184
1181
|
} | undefined;
|
|
1182
|
+
entry?: string | string[] | undefined;
|
|
1183
|
+
project?: string | string[] | undefined;
|
|
1185
1184
|
paths?: Record<string, string[]> | undefined;
|
|
1186
1185
|
ignore?: string | string[] | undefined;
|
|
1187
1186
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
@@ -1190,6 +1189,33 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
1190
1189
|
ignoreUnresolved?: (string | RegExp)[] | undefined;
|
|
1191
1190
|
includeEntryExports?: boolean | undefined;
|
|
1192
1191
|
}> | undefined;
|
|
1192
|
+
include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
|
|
1193
|
+
exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
|
|
1194
|
+
$schema?: string | undefined;
|
|
1195
|
+
rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers", "error" | "warn" | "off">> | undefined;
|
|
1196
|
+
entry?: string | string[] | undefined;
|
|
1197
|
+
project?: string | string[] | undefined;
|
|
1198
|
+
paths?: Record<string, string[]> | undefined;
|
|
1199
|
+
ignore?: string | string[] | undefined;
|
|
1200
|
+
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
1201
|
+
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
1202
|
+
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
1203
|
+
ignoreUnresolved?: (string | RegExp)[] | undefined;
|
|
1204
|
+
ignoreExportsUsedInFile?: boolean | {
|
|
1205
|
+
class?: boolean | undefined;
|
|
1206
|
+
enum?: boolean | undefined;
|
|
1207
|
+
function?: boolean | undefined;
|
|
1208
|
+
interface?: boolean | undefined;
|
|
1209
|
+
member?: boolean | undefined;
|
|
1210
|
+
type?: boolean | undefined;
|
|
1211
|
+
} | undefined;
|
|
1212
|
+
ignoreWorkspaces?: string[] | undefined;
|
|
1213
|
+
includeEntryExports?: boolean | undefined;
|
|
1214
|
+
compilers?: Record<string, true | ((filename: string, contents: string) => string) | ((filename: string, contents: string) => Promise<string>)> | undefined;
|
|
1215
|
+
syncCompilers?: Record<string, true | ((filename: string, contents: string) => string)> | undefined;
|
|
1216
|
+
asyncCompilers?: Record<string, (filename: string, contents: string) => Promise<string>> | undefined;
|
|
1217
|
+
tags?: string[] | undefined;
|
|
1218
|
+
treatConfigHintsAsErrors?: boolean | undefined;
|
|
1193
1219
|
};
|
|
1194
1220
|
rules: {
|
|
1195
1221
|
files: import("../types/issues.js").IssueSeverity;
|
|
@@ -30,7 +30,7 @@ export const createOptions = async (options) => {
|
|
|
30
30
|
if (parsedCLIArgs.config && !configFilePath && !manifest.knip) {
|
|
31
31
|
throw new ConfigurationError(`Unable to find ${parsedCLIArgs.config} or package.json#knip`);
|
|
32
32
|
}
|
|
33
|
-
const loadedConfig = Object.assign({}, manifest.knip, configFilePath ? await loadResolvedConfigFile(configFilePath) : {});
|
|
33
|
+
const loadedConfig = Object.assign({}, manifest.knip, configFilePath ? await loadResolvedConfigFile(configFilePath, parsedCLIArgs) : {});
|
|
34
34
|
const parsedConfig = knipConfigurationSchema.parse(partitionCompilers(loadedConfig));
|
|
35
35
|
if (!configFilePath && manifest.knip)
|
|
36
36
|
configFilePath = manifestPath;
|
package/dist/util/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { core } from 'zod/mini';
|
|
2
2
|
interface ErrorWithCause extends Error {
|
|
3
3
|
cause: Error;
|
|
4
4
|
}
|
|
@@ -6,8 +6,8 @@ export declare class ConfigurationError extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class LoaderError extends Error {
|
|
8
8
|
}
|
|
9
|
-
export declare const isKnownError: (error: Error) => error is ZodError<any> | ConfigurationError | LoaderError;
|
|
10
|
-
export declare const
|
|
9
|
+
export declare const isKnownError: (error: Error) => error is core.$ZodError<any> | ConfigurationError | LoaderError;
|
|
10
|
+
export declare const hasErrorCause: (error: Error) => error is ErrorWithCause;
|
|
11
11
|
export declare const isConfigurationError: (error: Error) => error is ConfigurationError;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const getKnownErrors: (error: Error) => Error[];
|
|
13
13
|
export {};
|
package/dist/util/errors.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { core } from 'zod/mini';
|
|
2
|
+
const isZodErrorLike = (error) => error instanceof core.$ZodError;
|
|
3
3
|
export class ConfigurationError extends Error {
|
|
4
4
|
}
|
|
5
5
|
export class LoaderError extends Error {
|
|
6
6
|
}
|
|
7
|
-
export const isKnownError = (error) => error instanceof ConfigurationError || error instanceof LoaderError || error
|
|
8
|
-
export const
|
|
7
|
+
export const isKnownError = (error) => error instanceof ConfigurationError || error instanceof LoaderError || isZodErrorLike(error);
|
|
8
|
+
export const hasErrorCause = (error) => !isZodErrorLike(error) && error.cause instanceof Error;
|
|
9
9
|
export const isConfigurationError = (error) => error instanceof ConfigurationError;
|
|
10
|
-
export const
|
|
11
|
-
if (error
|
|
12
|
-
return
|
|
13
|
-
return error;
|
|
10
|
+
export const getKnownErrors = (error) => {
|
|
11
|
+
if (isZodErrorLike(error))
|
|
12
|
+
return [...error.issues].map(error => new Error(error.message));
|
|
13
|
+
return [error];
|
|
14
14
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { deserialize, serialize } from 'node:v8';
|
|
4
|
-
import { timerify } from './Performance.js';
|
|
5
4
|
import { debugLog } from './debug.js';
|
|
6
5
|
import { isDirectory, isFile } from './fs.js';
|
|
6
|
+
import { timerify } from './Performance.js';
|
|
7
7
|
import { dirname, isAbsolute, resolve } from './path.js';
|
|
8
8
|
const createCache = (filePath) => {
|
|
9
9
|
try {
|