knip 6.44.2 → 6.45.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/ConfigurationChief.d.ts +23 -1033
- package/dist/ConfigurationChief.js +71 -15
- package/dist/DependencyDeputy.d.ts +10 -6
- package/dist/DependencyDeputy.js +51 -27
- package/dist/IssueCollector.d.ts +14 -11
- package/dist/IssueCollector.js +25 -20
- package/dist/IssueFixer.js +1 -1
- package/dist/PackagePeeker.d.ts +6 -0
- package/dist/PackagePeeker.js +43 -14
- package/dist/ProjectPrincipal.d.ts +6 -3
- package/dist/ProjectPrincipal.js +83 -32
- package/dist/WorkspaceWorker.d.ts +5 -1
- package/dist/WorkspaceWorker.js +39 -22
- package/dist/binaries/bash-parser.js +1 -7
- package/dist/binaries/command.d.ts +3 -3
- package/dist/binaries/command.js +6 -2
- package/dist/binaries/fallback.js +1 -1
- package/dist/binaries/plugins.d.ts +4 -1
- package/dist/binaries/plugins.js +66 -18
- package/dist/binaries/resolvers/npm.js +7 -5
- package/dist/binaries/resolvers/npx.js +8 -40
- package/dist/binaries/util.d.ts +13 -1
- package/dist/binaries/util.js +35 -1
- package/dist/cli.js +10 -84
- package/dist/configuration-hints.d.ts +16 -0
- package/dist/configuration-hints.js +64 -0
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +2 -0
- package/dist/graph/SubpathReferences.d.ts +33 -0
- package/dist/graph/SubpathReferences.js +114 -0
- package/dist/graph/analyze.d.ts +4 -1
- package/dist/graph/analyze.js +16 -5
- package/dist/graph/build.d.ts +3 -1
- package/dist/graph/build.js +47 -23
- package/dist/graph-explorer/operations/resolve-export-origins.js +1 -1
- package/dist/plugins/angular/index.js +10 -17
- package/dist/plugins/aws-cdk/index.d.ts +3 -0
- package/dist/plugins/aws-cdk/index.js +32 -0
- package/dist/plugins/aws-cdk/types.d.ts +5 -0
- package/dist/plugins/aws-cdk/types.js +1 -0
- package/dist/plugins/babel/index.d.ts +1 -1
- package/dist/plugins/babel/index.js +19 -5
- package/dist/plugins/bun/index.js +8 -7
- package/dist/plugins/c8/index.js +17 -4
- package/dist/plugins/changesets/index.js +3 -2
- package/dist/plugins/commitizen/index.js +6 -3
- package/dist/plugins/commitlint/index.js +10 -11
- package/dist/plugins/cypress/index.js +4 -2
- package/dist/plugins/danger/index.js +1 -1
- package/dist/plugins/docusaurus/helpers.js +6 -6
- package/dist/plugins/docusaurus/index.js +2 -2
- package/dist/plugins/electron-forge/index.js +2 -2
- package/dist/plugins/electron-vite/index.js +2 -2
- package/dist/plugins/eleventy/index.js +3 -2
- package/dist/plugins/eslint/helpers.js +4 -3
- package/dist/plugins/eslint/resolveFromAST.js +2 -2
- package/dist/plugins/evalite/index.d.ts +3 -0
- package/dist/plugins/evalite/index.js +26 -0
- package/dist/plugins/flue/index.js +2 -2
- package/dist/plugins/github-action/index.js +2 -2
- package/dist/plugins/github-actions/index.js +2 -2
- package/dist/plugins/graphql-codegen/index.js +13 -9
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +10 -0
- package/dist/plugins/jest/index.js +5 -5
- package/dist/plugins/knex/index.js +2 -2
- package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +2 -2
- package/dist/plugins/lunaria/index.js +5 -2
- package/dist/plugins/markdownlint/index.js +8 -2
- package/dist/plugins/marko/index.js +2 -2
- package/dist/plugins/marko/taglibs.d.ts +1 -1
- package/dist/plugins/marko/taglibs.js +4 -28
- package/dist/plugins/mdx/index.d.ts +2 -1
- package/dist/plugins/mdx/index.js +7 -4
- package/dist/plugins/mdxlint/index.js +18 -15
- package/dist/plugins/mikro-orm/index.d.ts +3 -0
- package/dist/plugins/mikro-orm/index.js +77 -0
- package/dist/plugins/mikro-orm/types.d.ts +21 -0
- package/dist/plugins/mikro-orm/types.js +1 -0
- package/dist/plugins/msw/index.js +6 -3
- package/dist/plugins/msw/types.d.ts +1 -1
- package/dist/plugins/netlify/index.js +7 -3
- package/dist/plugins/next/index.js +63 -9
- package/dist/plugins/next/types.d.ts +5 -0
- package/dist/plugins/next-mdx/resolveFromAST.js +15 -10
- package/dist/plugins/nitro/index.js +5 -6
- package/dist/plugins/node/index.js +4 -4
- package/dist/plugins/npm-package-json-lint/index.js +10 -3
- package/dist/plugins/nuxt/index.js +18 -10
- package/dist/plugins/nuxt/types.d.ts +4 -0
- package/dist/plugins/nx/index.js +6 -3
- package/dist/plugins/openclaw/index.js +11 -11
- package/dist/plugins/oxlint/index.js +2 -2
- package/dist/plugins/panda-css/index.js +5 -0
- package/dist/plugins/payload/index.js +1 -1
- package/dist/plugins/playwright/index.js +3 -3
- package/dist/plugins/pm2/index.js +7 -7
- package/dist/plugins/prettier/index.js +2 -1
- package/dist/plugins/prisma/index.js +2 -2
- package/dist/plugins/quasar/resolveFromAST.js +14 -9
- package/dist/plugins/react-router/index.js +2 -2
- package/dist/plugins/release-it/index.js +6 -2
- package/dist/plugins/remix/index.js +3 -3
- package/dist/plugins/retry-cli/index.d.ts +3 -0
- package/dist/plugins/retry-cli/index.js +14 -0
- package/dist/plugins/rollup/index.js +1 -4
- package/dist/plugins/rstest/index.js +3 -3
- package/dist/plugins/semantic-release/index.js +3 -3
- package/dist/plugins/serverless-framework/index.js +10 -8
- package/dist/plugins/solidjs-vite-plugin/resolveFromAST.js +2 -2
- package/dist/plugins/stencil/resolveFromAST.js +5 -5
- package/dist/plugins/stryker/index.js +2 -2
- package/dist/plugins/swc/index.js +4 -3
- package/dist/plugins/tailwind/index.js +2 -2
- package/dist/plugins/tanstack-router/index.js +2 -2
- package/dist/plugins/ts-node/index.js +6 -1
- package/dist/plugins/turbo/index.js +3 -3
- package/dist/plugins/typedoc/index.js +2 -2
- package/dist/plugins/typescript/content-mappers.d.ts +1 -1
- package/dist/plugins/typescript/index.js +6 -9
- package/dist/plugins/varlock/scan.js +1 -1
- package/dist/plugins/vite/helpers.d.ts +1 -0
- package/dist/plugins/vite/helpers.js +13 -3
- package/dist/plugins/vite/index.js +5 -2
- package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +2 -2
- package/dist/plugins/vitest/index.js +14 -16
- package/dist/plugins/vue/index.js +1 -1
- package/dist/plugins/web-test-runner/index.d.ts +3 -0
- package/dist/plugins/web-test-runner/index.js +86 -0
- package/dist/plugins/webdriver-io/index.js +22 -17
- package/dist/plugins/webdriver-io/types.d.ts +3 -2
- package/dist/plugins/wrangler/index.js +3 -3
- package/dist/plugins/yarn/index.js +5 -5
- package/dist/plugins.js +2 -5
- package/dist/reporters/github-actions.js +3 -7
- package/dist/reporters/json.d.ts +1 -0
- package/dist/reporters/json.js +1 -0
- package/dist/reporters/util/configuration-hints.d.ts +3 -1
- package/dist/reporters/util/configuration-hints.js +40 -21
- package/dist/reporters/util/util.d.ts +1 -1
- package/dist/run-cli.d.ts +2 -0
- package/dist/run-cli.js +82 -0
- package/dist/run.js +12 -0
- package/dist/session/incremental.d.ts +1 -0
- package/dist/session/incremental.js +1 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/index.js +1 -0
- package/dist/session/watch.js +2 -1
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +5 -0
- package/dist/types/args.d.ts +3 -1
- package/dist/types/config.d.ts +17 -10
- package/dist/types/configuration.d.ts +45 -0
- package/dist/types/configuration.js +1 -0
- package/dist/types/issues.d.ts +4 -0
- package/dist/types/module-graph.d.ts +1 -0
- package/dist/types/options.d.ts +1 -0
- package/dist/types/package-json.d.ts +3 -8
- package/dist/types/workspace.d.ts +1 -0
- package/dist/typescript/ast-nodes.js +47 -1
- package/dist/typescript/get-imports-and-exports.js +18 -6
- package/dist/typescript/resolve-module-names.js +7 -45
- package/dist/typescript/visitors/calls.d.ts +1 -1
- package/dist/typescript/visitors/calls.js +14 -10
- package/dist/typescript/visitors/exports.js +16 -26
- package/dist/typescript/visitors/imports.d.ts +2 -1
- package/dist/typescript/visitors/imports.js +41 -24
- package/dist/typescript/visitors/members.d.ts +1 -1
- package/dist/typescript/visitors/members.js +38 -24
- package/dist/typescript/visitors/shadow.d.ts +2 -0
- package/dist/typescript/visitors/shadow.js +25 -0
- package/dist/typescript/visitors/walk.d.ts +20 -12
- package/dist/typescript/visitors/walk.js +78 -48
- package/dist/util/Performance.d.ts +25 -3
- package/dist/util/Performance.js +51 -27
- package/dist/util/cli-arguments.d.ts +2 -1
- package/dist/util/cli-arguments.js +4 -2
- package/dist/util/create-input-handler.js +138 -119
- package/dist/util/create-options.d.ts +4 -2071
- package/dist/util/create-options.js +6 -4
- package/dist/util/create-workspace-graph.js +2 -1
- package/dist/util/errors.d.ts +5 -2
- package/dist/util/errors.js +11 -18
- package/dist/util/fs.js +4 -2
- package/dist/util/get-included-issue-types.js +1 -0
- package/dist/util/input.d.ts +2 -2
- package/dist/util/input.js +2 -2
- package/dist/util/is-plugin-name.d.ts +2 -0
- package/dist/util/is-plugin-name.js +3 -0
- package/dist/util/jiti.d.ts +2 -1
- package/dist/util/jiti.js +10 -3
- package/dist/util/load-config.d.ts +1 -1
- package/dist/util/load-config.js +3 -2
- package/dist/util/loader.js +3 -2
- package/dist/util/map-workspaces.js +23 -1
- package/dist/util/module-graph.js +1 -0
- package/dist/util/modules.d.ts +2 -0
- package/dist/util/modules.js +78 -0
- package/dist/util/package-json.d.ts +12 -5
- package/dist/util/package-json.js +54 -26
- package/dist/util/parse-and-convert-gitignores.d.ts +2 -2
- package/dist/util/parse-and-convert-gitignores.js +5 -5
- package/dist/util/parse-configuration.d.ts +2 -0
- package/dist/util/parse-configuration.js +66 -0
- package/dist/util/plugin.js +8 -12
- package/dist/util/regex.js +10 -1
- package/dist/util/resolve.d.ts +1 -0
- package/dist/util/resolve.js +3 -2
- package/dist/util/scripts.d.ts +0 -5
- package/dist/util/scripts.js +1 -32
- package/dist/util/to-source-path.d.ts +4 -1
- package/dist/util/to-source-path.js +2 -2
- package/dist/util/unhandled-rejection.d.ts +8 -0
- package/dist/util/unhandled-rejection.js +29 -0
- package/dist/util/validation.d.ts +11 -0
- package/dist/util/validation.js +68 -0
- package/dist/util/watch.d.ts +3 -1
- package/dist/util/watch.js +5 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -7
- package/schema.json +34 -0
- package/dist/schema/configuration.d.ts +0 -3103
- package/dist/schema/configuration.js +0 -94
- package/dist/schema/plugins.d.ts +0 -1019
- package/dist/schema/plugins.js +0 -215
|
@@ -2,9 +2,10 @@ import { blockCommentMatcher, lineCommentMatcher, scriptExtractor } from '../../
|
|
|
2
2
|
import { findImportedCalls, findProperty, getStringValues, resolveObjectArg } from '../../typescript/ast-helpers.js';
|
|
3
3
|
import { getStringValue } from '../../typescript/ast-nodes.js';
|
|
4
4
|
import { isFile, loadFile } from '../../util/fs.js';
|
|
5
|
-
import {
|
|
6
|
-
import { dirname, join, toAbsolute } from '../../util/path.js';
|
|
5
|
+
import { toDeferResolveProductionEntry } from '../../util/input.js';
|
|
6
|
+
import { dirname, isInternal, join, toAbsolute } from '../../util/path.js';
|
|
7
7
|
import { getDependenciesFromConfig } from '../babel/index.js';
|
|
8
|
+
import { toProviderInput } from '../mdx/index.js';
|
|
8
9
|
const babelPluginSources = ['@rolldown/plugin-babel', '@vitejs/plugin-react', 'vite-plugin-babel'];
|
|
9
10
|
const isBabelWrappingPlugin = (path) => babelPluginSources.some(source => path === source || path.startsWith(`${source}/`));
|
|
10
11
|
export const getBabelInputs = (program) => {
|
|
@@ -21,6 +22,15 @@ export const getBabelInputs = (program) => {
|
|
|
21
22
|
}
|
|
22
23
|
return inputs;
|
|
23
24
|
};
|
|
25
|
+
export const getMdxInputs = (program, dir) => {
|
|
26
|
+
const inputs = [];
|
|
27
|
+
for (const call of findImportedCalls(program, '@mdx-js/rollup')) {
|
|
28
|
+
const provider = getStringValue(findProperty(call.arguments?.[0], 'providerImportSource'));
|
|
29
|
+
if (provider && !isInternal(provider))
|
|
30
|
+
inputs.push(toProviderInput(provider, dir));
|
|
31
|
+
}
|
|
32
|
+
return inputs;
|
|
33
|
+
};
|
|
24
34
|
const moduleTypePattern = /\btype\s*=\s*["']?module["']?/i;
|
|
25
35
|
const srcAttrPattern = /\bsrc\s*=\s*["']([^"']+)["']/i;
|
|
26
36
|
const importSpecPattern = /\bimport\b(?:\s*\(\s*|(?:[\w$*,{}\s]*\bfrom\b)?\s*)(['"])([^'"]+)\1/g;
|
|
@@ -60,7 +70,7 @@ export const getHtmlScriptEntries = async (htmlPath, rootDir = dirname(htmlPath)
|
|
|
60
70
|
if (!isFile(htmlPath))
|
|
61
71
|
return [];
|
|
62
72
|
const html = await loadFile(htmlPath);
|
|
63
|
-
return getScriptSources(html, dirname(htmlPath), rootDir, publicDir).map(src =>
|
|
73
|
+
return getScriptSources(html, dirname(htmlPath), rootDir, publicDir).map(src => toDeferResolveProductionEntry(src));
|
|
64
74
|
};
|
|
65
75
|
export const getIndexHtmlEntries = (rootDir, publicDir) => getHtmlScriptEntries(join(rootDir, 'index.html'), rootDir, publicDir);
|
|
66
76
|
export const getVitePluginDirs = (program, specifiers, key) => {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { hasDependency } from '../../util/plugin.js';
|
|
2
2
|
import { resolveConfig } from '../vitest/index.js';
|
|
3
|
-
import { getBabelInputs, getIndexHtmlEntries } from './helpers.js';
|
|
3
|
+
import { getBabelInputs, getIndexHtmlEntries, getMdxInputs } from './helpers.js';
|
|
4
4
|
import { createImportMetaGlobVisitor } from './visitors/importMetaGlob.js';
|
|
5
5
|
const title = 'Vite';
|
|
6
6
|
const enablers = ['vite', 'vitest', 'vite-plus'];
|
|
7
7
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
8
8
|
export const config = ['vite.config.{js,mjs,ts,cjs,mts,cts}'];
|
|
9
|
-
const resolveFromAST =
|
|
9
|
+
const resolveFromAST = (program, options) => [
|
|
10
|
+
...getBabelInputs(program),
|
|
11
|
+
...getMdxInputs(program, options.configFileDir),
|
|
12
|
+
];
|
|
10
13
|
const registerVisitors = ({ ctx, registerVisitor }) => {
|
|
11
14
|
registerVisitor(createImportMetaGlobVisitor(ctx));
|
|
12
15
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Visitor } from 'oxc-parser';
|
|
2
2
|
import { findImportedCalls, findProperty, getFirstPropertyValue, getPropertyValues, } from '../../typescript/ast-helpers.js';
|
|
3
|
-
import {
|
|
3
|
+
import { toDeferResolveProductionEntry } from '../../util/input.js';
|
|
4
4
|
import { join } from '../../util/path.js';
|
|
5
5
|
const defaultSrcDir = 'public';
|
|
6
6
|
const defaultFilename = 'sw.js';
|
|
@@ -10,7 +10,7 @@ const getInjectManifestEntry = (options, configFileDir) => {
|
|
|
10
10
|
return;
|
|
11
11
|
const srcDir = getFirstPropertyValue(options, 'srcDir') ?? defaultSrcDir;
|
|
12
12
|
const filename = getFirstPropertyValue(options, 'filename') ?? defaultFilename;
|
|
13
|
-
return
|
|
13
|
+
return toDeferResolveProductionEntry(join(configFileDir, srcDir, filename));
|
|
14
14
|
};
|
|
15
15
|
export const resolveFromAST = (program, options) => {
|
|
16
16
|
const inputs = [];
|
|
@@ -2,7 +2,7 @@ import { DEFAULT_EXTENSIONS } from '../../constants.js';
|
|
|
2
2
|
import { filterTransitiveDependencies } from '../../util/filter-transitive-dependencies.js';
|
|
3
3
|
import { findFileWithExtensions } from '../../util/fs.js';
|
|
4
4
|
import { _dirGlob, _glob } from '../../util/glob.js';
|
|
5
|
-
import { toConfig, toDeferResolve, toDependency, toEntry,
|
|
5
|
+
import { toConfig, toDeferResolve, toDeferResolveProductionEntry, toDependency, toEntry, } from '../../util/input.js';
|
|
6
6
|
import { getPackageNameFromModuleSpecifier } from '../../util/modules.js';
|
|
7
7
|
import { basename, isAbsolute, isInternal, join, toAbsolute, toPosix } from '../../util/path.js';
|
|
8
8
|
import { hasDependency } from '../../util/plugin.js';
|
|
@@ -24,7 +24,7 @@ const builtInCoverageProviders = new Set(['v8', 'istanbul', 'c8']);
|
|
|
24
24
|
const getCoverageInputs = (provider, customProviderModule, dir) => builtInCoverageProviders.has(provider)
|
|
25
25
|
? [toDependency(`@vitest/coverage-${provider}`)]
|
|
26
26
|
: customProviderModule
|
|
27
|
-
? [
|
|
27
|
+
? [toDeferResolve(customProviderModule, { dir })]
|
|
28
28
|
: [];
|
|
29
29
|
const isProjectConfig = (project) => typeof project === 'object' && !(project instanceof Promise);
|
|
30
30
|
const findConfigDependencies = (localConfig, options, vitestRoot) => {
|
|
@@ -34,7 +34,7 @@ const findConfigDependencies = (localConfig, options, vitestRoot) => {
|
|
|
34
34
|
const env = testConfig.environment;
|
|
35
35
|
const environments = env && env !== 'node' ? (isInternal(env) || isAbsolute(env) ? [toDeferResolve(env)] : [toEnvDependency(env)]) : [];
|
|
36
36
|
const reporters = getExternalReporters(testConfig.reporters).map(specifier => isInternal(specifier) || isAbsolute(specifier)
|
|
37
|
-
?
|
|
37
|
+
? toDeferResolve(specifier, { dir: vitestRoot })
|
|
38
38
|
: toDependency(specifier));
|
|
39
39
|
const hasCoverage = testConfig.coverage && (testConfig.coverage.enabled !== false || testConfig.coverage.provider);
|
|
40
40
|
const coverage = hasCoverage
|
|
@@ -42,14 +42,11 @@ const findConfigDependencies = (localConfig, options, vitestRoot) => {
|
|
|
42
42
|
: [];
|
|
43
43
|
const setupFiles = [testConfig.setupFiles ?? []]
|
|
44
44
|
.flat()
|
|
45
|
-
.map(specifier =>
|
|
46
|
-
const snapshotSerializers = (testConfig.snapshotSerializers ?? []).map(specifier => ({
|
|
47
|
-
...toDeferResolve(specifier),
|
|
48
|
-
dir: vitestRoot,
|
|
49
|
-
}));
|
|
45
|
+
.map(specifier => toDeferResolve(specifier, { dir: vitestRoot }));
|
|
46
|
+
const snapshotSerializers = (testConfig.snapshotSerializers ?? []).map(specifier => toDeferResolve(specifier, { dir: vitestRoot }));
|
|
50
47
|
const globalSetup = [testConfig.globalSetup ?? []]
|
|
51
48
|
.flat()
|
|
52
|
-
.map(specifier =>
|
|
49
|
+
.map(specifier => toDeferResolve(specifier, { dir: vitestRoot }));
|
|
53
50
|
const workspaceDependencies = [];
|
|
54
51
|
if (testConfig.workspace !== undefined) {
|
|
55
52
|
for (const workspaceConfig of testConfig.workspace) {
|
|
@@ -218,7 +215,7 @@ export const resolveConfig = async (localConfig, options) => {
|
|
|
218
215
|
const inputSpecifiers = typeof _input === 'string' ? [_input] : Array.isArray(_input) ? _input : Object.values(_input).flat();
|
|
219
216
|
for (const specifier of inputSpecifiers) {
|
|
220
217
|
const resolved = toAbsolute(specifier, viteRoot);
|
|
221
|
-
inputs.add(
|
|
218
|
+
inputs.add(toDeferResolveProductionEntry(resolved));
|
|
222
219
|
if (resolved.endsWith('.html')) {
|
|
223
220
|
for (const input of await getHtmlScriptEntries(resolved, viteRoot, publicDir))
|
|
224
221
|
inputs.add(input);
|
|
@@ -226,7 +223,7 @@ export const resolveConfig = async (localConfig, options) => {
|
|
|
226
223
|
}
|
|
227
224
|
const _entry = cfg.build?.lib?.entry ?? [];
|
|
228
225
|
const entries = typeof _entry === 'string' ? [_entry] : Array.isArray(_entry) ? _entry : Object.values(_entry).flat();
|
|
229
|
-
const deps = entries.map(specifier => toAbsolute(specifier, viteRoot)).map(id =>
|
|
226
|
+
const deps = entries.map(specifier => toAbsolute(specifier, viteRoot)).map(id => toDeferResolveProductionEntry(id));
|
|
230
227
|
for (const dependency of deps)
|
|
231
228
|
inputs.add(dependency);
|
|
232
229
|
}
|
|
@@ -242,23 +239,24 @@ const args = {
|
|
|
242
239
|
alias: { root: ['r'] },
|
|
243
240
|
resolveInputs: (parsed, { cwd }) => {
|
|
244
241
|
const inputs = [];
|
|
242
|
+
const root = toAbsolute(parsed['root'] ?? '.', cwd);
|
|
245
243
|
if (parsed['ui'])
|
|
246
244
|
inputs.push(toDependency('@vitest/ui', { optional: true }));
|
|
247
245
|
if (typeof parsed['coverage'] === 'object' && parsed['coverage'].provider) {
|
|
248
246
|
const { provider, customProviderModule } = parsed['coverage'];
|
|
249
|
-
inputs.push(...getCoverageInputs(provider, customProviderModule,
|
|
247
|
+
inputs.push(...getCoverageInputs(provider, customProviderModule, root));
|
|
250
248
|
}
|
|
251
249
|
else if (parsed['coverage']) {
|
|
252
250
|
inputs.push(toDependency('@vitest/coverage-v8', { optional: true }));
|
|
253
251
|
}
|
|
254
252
|
if (parsed['reporter']) {
|
|
255
253
|
for (const reporter of getExternalReporters([parsed['reporter']].flat())) {
|
|
256
|
-
inputs.push(toDependency(reporter));
|
|
254
|
+
inputs.push(isInternal(reporter) ? toDeferResolve(reporter, { dir: root }) : toDependency(reporter));
|
|
257
255
|
}
|
|
258
256
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
257
|
+
const env = parsed['environment'];
|
|
258
|
+
if (env && env !== 'node')
|
|
259
|
+
inputs.push(isInternal(env) ? toDeferResolve(env, { dir: root }) : toEnvDependency(env));
|
|
262
260
|
if (typeof parsed['typecheck'] === 'object' && parsed['typecheck'].checker) {
|
|
263
261
|
inputs.push(toDependency(parsed['typecheck'].checker === 'tsc' ? 'typescript' : parsed['typecheck'].checker));
|
|
264
262
|
}
|
|
@@ -5,7 +5,7 @@ import { findWebpackDependenciesFromConfig } from '../webpack/index.js';
|
|
|
5
5
|
const title = 'Vue';
|
|
6
6
|
const enablers = ['vue'];
|
|
7
7
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
8
|
-
const config = ['vue.config.{js,
|
|
8
|
+
const config = ['vue.config.{js,cjs,mjs,ts}'];
|
|
9
9
|
const resolveConfig = async (config, options) => {
|
|
10
10
|
const { manifest } = options;
|
|
11
11
|
const inputs = [];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { findProperty, getPropertyValues, resolveObjectArg } from '../../typescript/ast-helpers.js';
|
|
2
|
+
import { toEntry } from '../../util/input.js';
|
|
3
|
+
import { toAbsolute } from '../../util/path.js';
|
|
4
|
+
import { hasDependency } from '../../util/plugin.js';
|
|
5
|
+
const title = 'Web Test Runner';
|
|
6
|
+
const enablers = ['@web/test-runner'];
|
|
7
|
+
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
8
|
+
const config = ['web-test-runner.config.{js,cjs,mjs}'];
|
|
9
|
+
const toFileEntries = (ids, base) => Array.from(ids, id => {
|
|
10
|
+
const pattern = String(id);
|
|
11
|
+
return toEntry(pattern.startsWith('!') ? `!${toAbsolute(pattern.slice(1), base)}` : toAbsolute(pattern, base));
|
|
12
|
+
});
|
|
13
|
+
const getConfigObject = (program) => {
|
|
14
|
+
const body = program.body ?? [];
|
|
15
|
+
const bindings = new Map();
|
|
16
|
+
for (const node of body) {
|
|
17
|
+
if (node.type !== 'VariableDeclaration')
|
|
18
|
+
continue;
|
|
19
|
+
for (const declaration of node.declarations) {
|
|
20
|
+
if (declaration.id?.type === 'Identifier' && declaration.init)
|
|
21
|
+
bindings.set(declaration.id.name, declaration.init);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const dereference = (node) => {
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
while (node?.type === 'Identifier' && bindings.has(node.name) && !seen.has(node.name)) {
|
|
27
|
+
seen.add(node.name);
|
|
28
|
+
node = bindings.get(node.name);
|
|
29
|
+
}
|
|
30
|
+
return node;
|
|
31
|
+
};
|
|
32
|
+
for (const node of body) {
|
|
33
|
+
if (node.type === 'ExportDefaultDeclaration')
|
|
34
|
+
return resolveObjectArg(dereference(node.declaration));
|
|
35
|
+
const { expression } = node;
|
|
36
|
+
if (node.type === 'ExpressionStatement' &&
|
|
37
|
+
expression?.type === 'AssignmentExpression' &&
|
|
38
|
+
expression.left?.type === 'MemberExpression' &&
|
|
39
|
+
expression.left.object?.name === 'module' &&
|
|
40
|
+
expression.left.property?.name === 'exports') {
|
|
41
|
+
return resolveObjectArg(dereference(expression.right));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const resolveFromAST = (program, options) => {
|
|
46
|
+
const localConfig = getConfigObject(program);
|
|
47
|
+
const patterns = new Set();
|
|
48
|
+
for (const pattern of getPropertyValues(localConfig, 'files'))
|
|
49
|
+
patterns.add(pattern);
|
|
50
|
+
const groups = findProperty(localConfig, 'groups');
|
|
51
|
+
if (groups?.type === 'ArrayExpression') {
|
|
52
|
+
for (const group of groups.elements ?? [])
|
|
53
|
+
for (const pattern of getPropertyValues(group, 'files'))
|
|
54
|
+
patterns.add(pattern);
|
|
55
|
+
}
|
|
56
|
+
return toFileEntries(patterns, options.cwd);
|
|
57
|
+
};
|
|
58
|
+
const args = {
|
|
59
|
+
binaries: ['web-test-runner', 'wtr'],
|
|
60
|
+
config: ['config'],
|
|
61
|
+
string: ['files'],
|
|
62
|
+
boolean: [
|
|
63
|
+
'coverage',
|
|
64
|
+
'debug',
|
|
65
|
+
'help',
|
|
66
|
+
'manual',
|
|
67
|
+
'node-resolve',
|
|
68
|
+
'open',
|
|
69
|
+
'playwright',
|
|
70
|
+
'preserve-symlinks',
|
|
71
|
+
'puppeteer',
|
|
72
|
+
'static-logging',
|
|
73
|
+
'update-snapshots',
|
|
74
|
+
'watch',
|
|
75
|
+
],
|
|
76
|
+
resolveInputs: (parsed, { cwd }) => toFileEntries([...parsed._, ...(parsed['--'] ?? []), ...[parsed.files ?? []].flat()].map(String), cwd),
|
|
77
|
+
};
|
|
78
|
+
const plugin = {
|
|
79
|
+
title,
|
|
80
|
+
enablers,
|
|
81
|
+
isEnabled,
|
|
82
|
+
config,
|
|
83
|
+
resolveFromAST,
|
|
84
|
+
args,
|
|
85
|
+
};
|
|
86
|
+
export default plugin;
|
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
import { toDependency } from '../../util/input.js';
|
|
2
|
+
import { isAbsolute } from '../../util/path.js';
|
|
2
3
|
import { hasDependency } from '../../util/plugin.js';
|
|
4
|
+
import { resolvePackageManifestPath } from '../../util/resolve.js';
|
|
3
5
|
const title = 'WebdriverIO';
|
|
4
6
|
const enablers = ['@wdio/cli'];
|
|
5
7
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
6
8
|
const config = ['wdio.conf.{js,cjs,mjs,ts,cts,mts}'];
|
|
7
|
-
const
|
|
9
|
+
const getNames = (plugins = []) => plugins.flatMap(plugin => {
|
|
10
|
+
const name = Array.isArray(plugin) ? plugin[0] : plugin;
|
|
11
|
+
return typeof name === 'string' && !name.startsWith('file://') && !isAbsolute(name) ? [name] : [];
|
|
12
|
+
});
|
|
13
|
+
const toPluginDependency = (name, type, dir) => {
|
|
14
|
+
if (name.startsWith('@'))
|
|
15
|
+
return toDependency(name);
|
|
16
|
+
const scoped = `@wdio/${name.toLowerCase()}-${type}`;
|
|
17
|
+
const community = `wdio-${name.toLowerCase()}-${type}`;
|
|
18
|
+
const isCommunity = !resolvePackageManifestPath(scoped, dir) && resolvePackageManifestPath(community, dir);
|
|
19
|
+
return toDependency(isCommunity ? community : scoped);
|
|
20
|
+
};
|
|
21
|
+
const resolveConfig = async (config, options) => {
|
|
8
22
|
const cfg = config?.config;
|
|
9
23
|
if (!cfg)
|
|
10
24
|
return [];
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (typeof reporter === 'string')
|
|
19
|
-
return [reporter];
|
|
20
|
-
if (Array.isArray(reporter) && typeof reporter[0] === 'string')
|
|
21
|
-
return [reporter[0]];
|
|
22
|
-
return [];
|
|
23
|
-
})
|
|
24
|
-
.map(reporter => `@wdio/${reporter}-reporter`)
|
|
25
|
-
: [];
|
|
26
|
-
return [...frameworks, ...runners, ...reporters].map(id => toDependency(id));
|
|
25
|
+
const toInputs = (plugins, type) => getNames(plugins).map(name => toPluginDependency(name, type, options.configFileDir));
|
|
26
|
+
return [
|
|
27
|
+
...toInputs([cfg.framework], 'framework'),
|
|
28
|
+
...toInputs([cfg.runner ?? 'local'], 'runner'),
|
|
29
|
+
...toInputs(cfg.reporters, 'reporter'),
|
|
30
|
+
...toInputs(cfg.services, 'service'),
|
|
31
|
+
];
|
|
27
32
|
};
|
|
28
33
|
const plugin = {
|
|
29
34
|
title,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toDeferResolveProductionEntry } from '../../util/input.js';
|
|
2
2
|
import { hasDependency } from '../../util/plugin.js';
|
|
3
3
|
const title = 'Wrangler';
|
|
4
4
|
const enablers = ['wrangler'];
|
|
5
5
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
6
6
|
const config = ['wrangler.{json,jsonc,toml}'];
|
|
7
|
-
const resolveConfig = async (config) => {
|
|
8
|
-
return (config.main ? [config.main] : []).map(id =>
|
|
7
|
+
const resolveConfig = async (config, { cwd }) => {
|
|
8
|
+
return (config.main ? [config.main] : []).map(id => toDeferResolveProductionEntry(id, { dir: cwd }));
|
|
9
9
|
};
|
|
10
10
|
const plugin = {
|
|
11
11
|
title,
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { isFile } from '../../util/fs.js';
|
|
2
|
-
import { toDependency, toEntry } from '../../util/input.js';
|
|
2
|
+
import { toDeferResolveEntry, toDependency, toEntry } from '../../util/input.js';
|
|
3
3
|
const title = 'Yarn';
|
|
4
4
|
const enablers = 'This plugin is enabled when a `yarn.lock` file is found in the root directory, or when `yarn@` is specified in the `packageManager` field of `package.json`.';
|
|
5
5
|
const isEnabled = async ({ cwd, manifest }) => manifest.packageManager?.startsWith('yarn@') || isFile(cwd, 'yarn.lock');
|
|
6
6
|
const isRootOnly = true;
|
|
7
7
|
const config = ['.yarnrc.yml'];
|
|
8
8
|
const entry = ['yarn.config.cjs'];
|
|
9
|
-
const resolveConfig = config => {
|
|
9
|
+
const resolveConfig = (config, { cwd }) => {
|
|
10
10
|
const inputs = entry.map(toEntry);
|
|
11
11
|
if (Array.isArray(config.plugins)) {
|
|
12
12
|
for (const plugin of config.plugins) {
|
|
13
13
|
if (typeof plugin === 'string')
|
|
14
|
-
inputs.push(
|
|
14
|
+
inputs.push(toDeferResolveEntry(plugin, { dir: cwd }));
|
|
15
15
|
else if (typeof plugin.path === 'string')
|
|
16
|
-
inputs.push(
|
|
16
|
+
inputs.push(toDeferResolveEntry(plugin.path, { dir: cwd }));
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
if (config.yarnPath) {
|
|
20
|
-
inputs.push(
|
|
20
|
+
inputs.push(toDeferResolveEntry(config.yarnPath, { dir: cwd }));
|
|
21
21
|
}
|
|
22
22
|
if (config.packageExtensions) {
|
|
23
23
|
for (const extension of Object.values(config.packageExtensions)) {
|
package/dist/plugins.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { parseArgs } from 'node:util';
|
|
2
1
|
import { Plugins } from './plugins/index.js';
|
|
3
|
-
import { timerify } from './util/Performance.js';
|
|
2
|
+
import { perfObserver, timerify } from './util/Performance.js';
|
|
4
3
|
const PMap = Plugins;
|
|
5
|
-
const { values } = parseArgs({ strict: false, options: { performance: { type: 'boolean' } } });
|
|
6
|
-
const isEnabled = !!values.performance;
|
|
7
4
|
const timerifyMethods = ['resolve', 'resolveConfig', 'resolveFromAST'];
|
|
8
5
|
const PluginEntries = Object.entries(PMap);
|
|
9
|
-
if (
|
|
6
|
+
if (perfObserver.isTimerifyFunctions) {
|
|
10
7
|
for (const [, plugin] of PluginEntries) {
|
|
11
8
|
for (const method of timerifyMethods) {
|
|
12
9
|
if (method in plugin)
|
|
@@ -59,18 +59,14 @@ export default ({ report, issues, cwd, configurationHints, tagHints, isDisableCo
|
|
|
59
59
|
core.info(`${CONFIG_HINTS_TITLE} (${configurationHints.length})`);
|
|
60
60
|
const sortedHints = configurationHints.toSorted((a, b) => compareStrings(a.filePath ?? '', b.filePath ?? ''));
|
|
61
61
|
for (const hint of sortedHints) {
|
|
62
|
-
const hintPrinter = hintPrinters.get(hint.type);
|
|
63
|
-
const message = hintPrinter?.print({
|
|
64
|
-
...hint,
|
|
65
|
-
filePath: hint.filePath ?? configFilePath ?? '',
|
|
66
|
-
configFilePath,
|
|
67
|
-
}) ?? '';
|
|
68
62
|
const file = hint.filePath
|
|
69
63
|
? relative(cwd, hint.filePath)
|
|
70
64
|
: configFilePath
|
|
71
65
|
? relative(cwd, configFilePath)
|
|
72
66
|
: 'knip.json';
|
|
73
|
-
const
|
|
67
|
+
const hintPrinter = hintPrinters.get(hint.type);
|
|
68
|
+
const message = hintPrinter?.print({ ...hint, filePath: file, configFilePath }) ?? '';
|
|
69
|
+
const hintMessage = `${message}: ${hint.identifier}`;
|
|
74
70
|
if (isTreatConfigHintsAsErrors) {
|
|
75
71
|
core.error(hintMessage, {
|
|
76
72
|
file,
|
package/dist/reporters/json.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export type JSONReportEntry = {
|
|
|
27
27
|
nsExports?: Array<JSONReportItem>;
|
|
28
28
|
nsTypes?: Array<JSONReportItem>;
|
|
29
29
|
optionalPeerDependencies?: Array<JSONReportItem>;
|
|
30
|
+
subpaths?: Array<JSONReportItem>;
|
|
30
31
|
types?: Array<JSONReportItem>;
|
|
31
32
|
unlisted?: Array<JSONReportNamedItem>;
|
|
32
33
|
unresolved?: Array<JSONReportItem>;
|
package/dist/reporters/json.js
CHANGED
|
@@ -32,6 +32,7 @@ export default async ({ report, issues, options, cwd, write }) => {
|
|
|
32
32
|
...(report.nsExports && { nsExports: [] }),
|
|
33
33
|
...(report.nsTypes && { nsTypes: [] }),
|
|
34
34
|
...(report.optionalPeerDependencies && { optionalPeerDependencies: [] }),
|
|
35
|
+
...(report.subpaths && { subpaths: [] }),
|
|
35
36
|
...(report.types && { types: [] }),
|
|
36
37
|
...(report.unlisted && { unlisted: [] }),
|
|
37
38
|
...(report.unresolved && { unresolved: [] }),
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Results } from '../../run.ts';
|
|
2
|
-
import type { ConfigurationHint, ConfigurationHintType, ReporterOptions } from '../../types/issues.ts';
|
|
2
|
+
import type { ConfigurationHint, ConfigurationHintType, ReporterOptions, UnusedIgnorePatternReason } from '../../types/issues.ts';
|
|
3
3
|
interface PrintHintOptions {
|
|
4
4
|
type: ConfigurationHintType;
|
|
5
5
|
identifier: string | RegExp;
|
|
6
6
|
filePath: string;
|
|
7
7
|
configFilePath?: string;
|
|
8
8
|
workspaceName?: string;
|
|
9
|
+
configKey?: string;
|
|
10
|
+
reason?: UnusedIgnorePatternReason;
|
|
9
11
|
size?: number;
|
|
10
12
|
}
|
|
11
13
|
export declare const hintPrinters: Map<ConfigurationHintType, {
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ROOT_WORKSPACE_NAME } from '../../constants.js';
|
|
2
|
+
import { basename, relative, toRelative } from '../../util/path.js';
|
|
2
3
|
import { Table } from '../../util/table.js';
|
|
3
4
|
import { byPathDepth } from '../../util/workspace.js';
|
|
4
5
|
import { bright, dim, getColoredTitle, getDimmedTitle } from './util.js';
|
|
5
|
-
const getWorkspaceName = (hint) => hint.workspaceName &&
|
|
6
|
-
hint.workspaceName !== '.' &&
|
|
7
|
-
hint.type !== 'top-level-unconfigured' &&
|
|
8
|
-
hint.type !== 'workspace-unconfigured' &&
|
|
9
|
-
hint.type !== 'package-entry'
|
|
10
|
-
? hint.workspaceName
|
|
11
|
-
: '';
|
|
12
6
|
const getIdentifier = (hint) => {
|
|
13
7
|
if (hint.identifier === '.')
|
|
14
8
|
return `. ${dim('(root)')}`;
|
|
@@ -17,30 +11,55 @@ const getIdentifier = (hint) => {
|
|
|
17
11
|
return hint.identifier.toString();
|
|
18
12
|
};
|
|
19
13
|
const getTableForHints = (hints) => {
|
|
20
|
-
const table = new Table({ truncate: { identifier: 'start',
|
|
14
|
+
const table = new Table({ truncate: { identifier: 'start', description: 'none' } });
|
|
21
15
|
for (const hint of hints) {
|
|
22
16
|
table.row();
|
|
23
17
|
table.cell('identifier', getIdentifier(hint));
|
|
24
|
-
table.cell('workspace', getWorkspaceName(hint));
|
|
25
|
-
table.cell('filePath', hint.filePath);
|
|
26
18
|
table.cell('description', dim(hint.message));
|
|
27
19
|
}
|
|
28
20
|
return table;
|
|
29
21
|
};
|
|
30
|
-
const type = (id) =>
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
22
|
+
const type = (id) => id.split('-').at(0);
|
|
23
|
+
const SEP = ' → ';
|
|
24
|
+
const location = (options, key) => {
|
|
25
|
+
const segments = [];
|
|
26
|
+
if (options.filePath) {
|
|
27
|
+
segments.push(options.filePath);
|
|
28
|
+
if (basename(options.filePath) === 'package.json')
|
|
29
|
+
segments.push('knip');
|
|
30
|
+
}
|
|
31
|
+
const workspace = options.configKey ?? (options.workspaceName !== ROOT_WORKSPACE_NAME ? options.workspaceName : undefined);
|
|
32
|
+
if (workspace)
|
|
33
|
+
segments.push(workspace === ROOT_WORKSPACE_NAME ? '(root)' : workspace);
|
|
34
|
+
if (key)
|
|
35
|
+
segments.push(bright(key));
|
|
36
|
+
return segments.join(SEP);
|
|
37
|
+
};
|
|
38
|
+
const reasons = {
|
|
39
|
+
'no-issues': 'no issues',
|
|
40
|
+
gitignored: 'gitignored',
|
|
41
|
+
'no-matches': 'no matches',
|
|
42
|
+
};
|
|
43
|
+
const unused = (options) => {
|
|
44
|
+
const reason = options.reason
|
|
45
|
+
? options.type === 'ignoreFiles' && options.reason === 'no-issues'
|
|
46
|
+
? 'files are used'
|
|
47
|
+
: reasons[options.reason]
|
|
48
|
+
: undefined;
|
|
49
|
+
return `Remove from ${location(options, type(options.type))}${reason ? ` (${reason})` : ''}`;
|
|
50
|
+
};
|
|
51
|
+
const empty = (options) => `Refine ${location(options, type(options.type))} pattern (no matches)`;
|
|
52
|
+
const remove = (options) => `Remove redundant pattern from ${location(options, type(options.type))}`;
|
|
53
|
+
const topLevel = (options) => `Remove unused ${location(options, type(options.type))}, or move to ${bright('"workspaces"')}`;
|
|
35
54
|
const add = (options) => options.configFilePath
|
|
36
|
-
? `Add ${bright('entry')} and/or refine ${bright('project')} files (${options.size} unused files)`
|
|
55
|
+
? `Add ${bright('entry')} and/or refine ${bright('project')} files in ${location(options)} (${options.size} unused files)`
|
|
37
56
|
: `Create ${bright('knip.json')} configuration file, and add ${bright('entry')} and/or refine ${bright('project')} files (${options.size} unused files)`;
|
|
38
57
|
const addWorkspace = (options) => options.configFilePath
|
|
39
|
-
? `Add ${bright('entry')} and/or refine ${bright('project')} files in ${
|
|
58
|
+
? `Add ${bright('entry')} and/or refine ${bright('project')} files in ${location({ ...options, workspaceName: undefined }, `workspaces["${options.workspaceName}"]`)} (${options.size} unused files)`
|
|
40
59
|
: `Create ${bright('knip.json')} configuration file with ${bright(`workspaces["${options.workspaceName}"]`)} object (${options.size} unused files)`;
|
|
41
|
-
const packageEntry = () =>
|
|
42
|
-
const extensionUnregistered = () => `Extension in ${
|
|
43
|
-
const extensionExcluded = () => `Compiled extension excluded by ${
|
|
60
|
+
const packageEntry = (options) => `Package entry file not found${options.filePath ? ` in ${options.filePath}` : ''}`;
|
|
61
|
+
const extensionUnregistered = (options) => `Extension in ${location(options, 'project')} not registered as a compiler`;
|
|
62
|
+
const extensionExcluded = (options) => `Compiled extension excluded by ${location(options, 'project')} (imports not followed)`;
|
|
44
63
|
export const hintPrinters = new Map([
|
|
45
64
|
['ignore', { print: unused }],
|
|
46
65
|
['ignoreFiles', { print: unused }],
|
|
@@ -3,7 +3,7 @@ import type { Issue, IssueRecords, IssueSeverity, IssueSymbol, IssueType } from
|
|
|
3
3
|
import { Table } from '../../util/table.ts';
|
|
4
4
|
export declare const dim: (text: string | number | null | undefined) => string;
|
|
5
5
|
export declare const bright: (text: string | number | null | undefined) => string;
|
|
6
|
-
export declare const getIssueTypeTitle: (reportType: keyof typeof ISSUE_TYPE_TITLE) => "Circular dependencies" | "Duplicate exports" | "Exported types in used namespace" | "Exports in used namespace" | "Referenced optional peerDependencies" | "Unlisted binaries" | "Unlisted dependencies" | "Unresolved catalog references" | "Unresolved imports" | "Unused catalog entries" | "Unused dependencies" | "Unused devDependencies" | "Unused exported enum members" | "Unused exported namespace members" | "Unused exported types" | "Unused exports" | "Unused files";
|
|
6
|
+
export declare const getIssueTypeTitle: (reportType: keyof typeof ISSUE_TYPE_TITLE) => "Circular dependencies" | "Duplicate exports" | "Exported types in used namespace" | "Exports in used namespace" | "Referenced optional peerDependencies" | "Unlisted binaries" | "Unlisted dependencies" | "Unresolved catalog references" | "Unresolved imports" | "Unused catalog entries" | "Unused dependencies" | "Unused devDependencies" | "Unused exported enum members" | "Unused exported namespace members" | "Unused exported types" | "Unused exports" | "Unused files" | "Unused subpaths";
|
|
7
7
|
export declare const getColoredTitle: (title: string, count: number) => string;
|
|
8
8
|
export declare const getDimmedTitle: (title: string, count: number) => string;
|
|
9
9
|
type LogIssueLine = {
|
package/dist/run-cli.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { fix } from './IssueFixer.js';
|
|
2
|
+
import { run } from './run.js';
|
|
3
|
+
import { createOptions } from './util/create-options.js';
|
|
4
|
+
import { getKnownErrors, hasErrorCause, isConfigurationError, isKnownError, isLoaderError, isModuleNotFoundError, } from './util/errors.js';
|
|
5
|
+
import { logError } from './util/log.js';
|
|
6
|
+
import { perfObserver } from './util/Performance.js';
|
|
7
|
+
import { createPreprocessor, toReporterOptions } from './util/preprocessor.js';
|
|
8
|
+
import { runReporters } from './util/reporter.js';
|
|
9
|
+
import { prettyMilliseconds } from './util/string.js';
|
|
10
|
+
import { hasUnhandledRejection, listenForUnhandledRejections } from './util/unhandled-rejection.js';
|
|
11
|
+
import { watchSession } from './session/watch.js';
|
|
12
|
+
export const runCLI = async (args) => {
|
|
13
|
+
let cwd = process.cwd();
|
|
14
|
+
listenForUnhandledRejections(() => cwd);
|
|
15
|
+
if (perfObserver.isEnabled || perfObserver.isDurationEnabled)
|
|
16
|
+
perfObserver.startRun();
|
|
17
|
+
try {
|
|
18
|
+
const options = await createOptions({ args });
|
|
19
|
+
cwd = options.cwd;
|
|
20
|
+
if (options.isWatch) {
|
|
21
|
+
await watchSession(options);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const { results } = await run(options);
|
|
25
|
+
if (options.isWatch || options.isTrace)
|
|
26
|
+
return;
|
|
27
|
+
const preprocess = await createPreprocessor(options.preprocessor);
|
|
28
|
+
const finalData = await preprocess(toReporterOptions(options, results, args));
|
|
29
|
+
if (options.isFix)
|
|
30
|
+
await fix(finalData.issues, finalData.counters, options);
|
|
31
|
+
await runReporters(args.reporter ?? ['symbols'], args['output-file'] ?? [], finalData);
|
|
32
|
+
const totalErrorCount = Object.keys(finalData.report)
|
|
33
|
+
.filter(reportGroup => finalData.report[reportGroup] && options.rules[reportGroup] === 'error')
|
|
34
|
+
.reduce((errorCount, reportGroup) => errorCount + finalData.counters[reportGroup], 0);
|
|
35
|
+
if (perfObserver.isEnabled || perfObserver.isDurationEnabled)
|
|
36
|
+
perfObserver.finalize();
|
|
37
|
+
if (perfObserver.isTimerifyFunctions)
|
|
38
|
+
console.log(`\n${perfObserver.getTimerifiedFunctionsTable()}`);
|
|
39
|
+
if (perfObserver.isMemoryUsageEnabled && !args['memory-realtime'])
|
|
40
|
+
console.log(`\n${perfObserver.getMemoryUsageTable()}`);
|
|
41
|
+
if (perfObserver.isEnabled || perfObserver.isDurationEnabled) {
|
|
42
|
+
const duration = perfObserver.getCurrentDurationInMs();
|
|
43
|
+
const startup = perfObserver.getProcessDurationInMs() - duration;
|
|
44
|
+
console.log(`\nTotal running time: ${prettyMilliseconds(duration)} (+${prettyMilliseconds(startup)} startup)`);
|
|
45
|
+
perfObserver.reset();
|
|
46
|
+
}
|
|
47
|
+
if (results.hasConfigLoadErrors || hasUnhandledRejection()) {
|
|
48
|
+
process.exitCode = 2;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!args['no-exit-code'] &&
|
|
52
|
+
(totalErrorCount > options.maxIssues ||
|
|
53
|
+
(!options.isDisableConfigHints &&
|
|
54
|
+
options.isTreatConfigHintsAsErrors &&
|
|
55
|
+
finalData.configurationHints.length > 0) ||
|
|
56
|
+
(!options.isDisableTagHints && options.isTreatTagHintsAsErrors && finalData.tagHints.size > 0))) {
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
process.exitCode = 2;
|
|
63
|
+
if (!args.debug && error instanceof Error && isKnownError(error)) {
|
|
64
|
+
const knownErrors = getKnownErrors(error);
|
|
65
|
+
for (const knownError of knownErrors)
|
|
66
|
+
logError(knownError.message);
|
|
67
|
+
if (hasErrorCause(knownErrors[0])) {
|
|
68
|
+
console.error('Reason:', knownErrors[0].cause.message);
|
|
69
|
+
if (isModuleNotFoundError(knownErrors[0].cause))
|
|
70
|
+
console.log('Module load error? Visit https://knip.dev/reference/known-issues');
|
|
71
|
+
if (isLoaderError(knownErrors[0]))
|
|
72
|
+
console.log('Configuration file load error? Visit https://knip.dev/reference/known-issues');
|
|
73
|
+
}
|
|
74
|
+
if (isConfigurationError(knownErrors[0]))
|
|
75
|
+
console.log('\nRun `knip --help` or visit https://knip.dev for help');
|
|
76
|
+
process.exitCode = 2;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
process.exitCode = 0;
|
|
82
|
+
};
|