knip 6.34.0 → 6.35.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/CatalogCounselor.d.ts +2 -0
- package/dist/CatalogCounselor.js +30 -7
- package/dist/ConfigurationChief.d.ts +6 -0
- package/dist/ConfigurationChief.js +3 -5
- package/dist/IssueCollector.d.ts +3 -0
- package/dist/IssueCollector.js +5 -0
- package/dist/ProjectPrincipal.d.ts +9 -10
- package/dist/ProjectPrincipal.js +45 -52
- package/dist/WorkspaceWorker.d.ts +5 -3
- package/dist/WorkspaceWorker.js +9 -6
- package/dist/YamlCatalogPeeker.d.ts +4 -0
- package/dist/YamlCatalogPeeker.js +17 -0
- package/dist/binaries/bash-parser.d.ts +1 -1
- package/dist/binaries/bash-parser.js +12 -58
- package/dist/binaries/command.d.ts +5 -0
- package/dist/binaries/command.js +47 -0
- package/dist/binaries/fallback.d.ts +2 -0
- package/dist/binaries/fallback.js +2 -0
- package/dist/binaries/plugins.d.ts +1 -0
- package/dist/binaries/plugins.js +2 -1
- package/dist/binaries/resolvers/pnpm.js +1 -0
- package/dist/binaries/util.d.ts +1 -0
- package/dist/binaries/util.js +12 -0
- package/dist/cli.js +12 -26
- package/dist/compilers/index.d.ts +3 -1866
- package/dist/compilers/index.js +17 -27
- package/dist/compilers/types.d.ts +4 -5
- package/dist/graph/analyze.js +71 -53
- package/dist/graph/build.d.ts +3 -3
- package/dist/graph/build.js +64 -31
- package/dist/index.d.ts +1 -0
- package/dist/plugins/_vue/auto-import.js +28 -4
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/mise/index.d.ts +3 -0
- package/dist/plugins/mise/index.js +82 -0
- package/dist/plugins/mise/scripts.d.ts +7 -0
- package/dist/plugins/mise/scripts.js +108 -0
- package/dist/plugins/mise/types.d.ts +26 -0
- package/dist/plugins/mise/types.js +1 -0
- package/dist/plugins/rstest/index.js +3 -2
- package/dist/plugins/rstest/types.d.ts +3 -1
- package/dist/plugins/vite/helpers.d.ts +2 -2
- package/dist/plugins/vite/helpers.js +18 -11
- package/dist/plugins/vite/visitors/importMetaGlob.js +12 -0
- package/dist/plugins/vitest/index.js +5 -2
- package/dist/plugins/vitest/types.d.ts +1 -0
- package/dist/reporters/util/configuration-hints.d.ts +1 -1
- package/dist/reporters/util/configuration-hints.js +11 -2
- package/dist/run.d.ts +2 -0
- package/dist/run.js +2 -1
- package/dist/schema/configuration.d.ts +20 -4
- package/dist/schema/configuration.js +5 -6
- package/dist/schema/plugins.d.ts +5 -0
- package/dist/schema/plugins.js +1 -0
- package/dist/session/index.d.ts +1 -1
- package/dist/session/index.js +1 -1
- package/dist/session/session.js +22 -4
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +1 -0
- package/dist/types/config.d.ts +4 -4
- package/dist/types/issues.d.ts +1 -0
- package/dist/types/module-graph.d.ts +2 -0
- package/dist/types.d.ts +1 -0
- package/dist/typescript/SourceFileManager.d.ts +13 -9
- package/dist/typescript/SourceFileManager.js +58 -22
- package/dist/typescript/get-imports-and-exports.js +2 -1
- package/dist/typescript/resolve-module-names.js +7 -27
- package/dist/typescript/visitors/exports.js +8 -4
- package/dist/util/catalog.d.ts +5 -0
- package/dist/util/catalog.js +37 -17
- package/dist/util/create-options.d.ts +17 -3
- package/dist/util/create-options.js +14 -3
- package/dist/util/errors.d.ts +3 -1
- package/dist/util/errors.js +6 -1
- package/dist/util/file-entry-cache.js +2 -2
- package/dist/util/module-graph.js +1 -0
- package/dist/util/package-json.d.ts +1 -0
- package/dist/util/preprocessor.d.ts +6 -0
- package/dist/util/preprocessor.js +24 -0
- package/dist/util/reporter.d.ts +0 -1
- package/dist/util/reporter.js +0 -7
- package/dist/util/watch.d.ts +2 -1
- package/dist/util/watch.js +33 -15
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -7
- package/schema.json +12 -0
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { parse } from 'unbash';
|
|
2
|
-
import { Plugins, pluginArgsMap } from '../plugins.js';
|
|
3
2
|
import { debugLogObject } from '../util/debug.js';
|
|
4
|
-
import { toBinary, toDeferResolve } from '../util/input.js';
|
|
5
3
|
import { extractBinary, isValidBinary } from '../util/modules.js';
|
|
6
4
|
import { relative } from '../util/path.js';
|
|
7
5
|
import { substringBefore, truncate } from '../util/string.js';
|
|
8
6
|
import { walkCommands } from '../util/scripts.js';
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import { resolve as resolverFromPlugins } from './plugins.js';
|
|
12
|
-
import { parseNodeArgs } from './util.js';
|
|
13
|
-
const spawningBinaries = ['cross-env', 'retry-cli'];
|
|
7
|
+
import { getDependenciesFromCommand } from './command.js';
|
|
8
|
+
import { toScript } from './util.js';
|
|
14
9
|
const collectExpansionScripts = (word, out) => {
|
|
15
10
|
if (!word.parts)
|
|
16
11
|
return;
|
|
@@ -35,21 +30,19 @@ export const getDependenciesFromScript = (script, options) => {
|
|
|
35
30
|
const first = typeof args[0] === 'string' ? args[0] : args[0].value;
|
|
36
31
|
if (!isValidBinary(substringBefore(first, ' ')))
|
|
37
32
|
return [];
|
|
38
|
-
|
|
39
|
-
for (const arg of args) {
|
|
40
|
-
if (typeof arg === 'string') {
|
|
41
|
-
if (arg !== '--')
|
|
42
|
-
parts.push(arg);
|
|
43
|
-
}
|
|
44
|
-
else if (arg.value !== '--')
|
|
45
|
-
parts.push(arg.text);
|
|
46
|
-
}
|
|
47
|
-
return getDependenciesFromScript(parts.join(' '), {
|
|
33
|
+
return getDependenciesFromScript(toScript(args), {
|
|
48
34
|
...options,
|
|
49
35
|
knownBinsOnly: false,
|
|
50
36
|
...opts,
|
|
51
37
|
});
|
|
52
38
|
};
|
|
39
|
+
const fromWords = (words, opts) => {
|
|
40
|
+
const script = words
|
|
41
|
+
.filter(word => word.text !== '--')
|
|
42
|
+
.map(word => word.text)
|
|
43
|
+
.join(' ');
|
|
44
|
+
return getDependenciesFromScript(script, opts);
|
|
45
|
+
};
|
|
53
46
|
const definedFunctions = new Set();
|
|
54
47
|
const collectFunctionNames = (statements) => {
|
|
55
48
|
for (const stmt of statements)
|
|
@@ -68,8 +61,6 @@ export const getDependenciesFromScript = (script, options) => {
|
|
|
68
61
|
return [...mainDeps, ...expansionDeps];
|
|
69
62
|
};
|
|
70
63
|
const processCommand = (node, pending) => {
|
|
71
|
-
const text = node.name?.value;
|
|
72
|
-
const binary = text ? extractBinary(text) : text;
|
|
73
64
|
if (node.name)
|
|
74
65
|
collectExpansionScripts(node.name, pending);
|
|
75
66
|
for (const prefix of node.prefix)
|
|
@@ -77,46 +68,9 @@ export const getDependenciesFromScript = (script, options) => {
|
|
|
77
68
|
collectExpansionScripts(prefix.value, pending);
|
|
78
69
|
for (const suffix of node.suffix)
|
|
79
70
|
collectExpansionScripts(suffix, pending);
|
|
80
|
-
if (
|
|
81
|
-
return [];
|
|
82
|
-
if (binary.startsWith('-') || binary.startsWith('..'))
|
|
83
|
-
return [];
|
|
84
|
-
if (definedFunctions.has(binary))
|
|
85
|
-
return [];
|
|
86
|
-
const words = node.suffix;
|
|
87
|
-
if (binary === '!' || binary === 'test')
|
|
88
|
-
return fromArgs(words);
|
|
89
|
-
const fromNodeOptions = node.prefix
|
|
90
|
-
.filter(a => a.name === 'NODE_OPTIONS' && a.value)
|
|
91
|
-
.map(a => a.value.value)
|
|
92
|
-
.map(arg => parseNodeArgs(arg.split(' ')))
|
|
93
|
-
.filter(args => args.require)
|
|
94
|
-
.flatMap(arg => arg.require)
|
|
95
|
-
.map(id => toDeferResolve(id));
|
|
96
|
-
if (binary in KnownResolvers) {
|
|
97
|
-
const resolver = KnownResolvers[binary];
|
|
98
|
-
return resolver(binary, words, { ...options, fromArgs });
|
|
99
|
-
}
|
|
100
|
-
if (pluginArgsMap.has(binary)) {
|
|
101
|
-
return [...resolverFromPlugins(binary, words, { ...options, fromArgs }), ...fromNodeOptions];
|
|
102
|
-
}
|
|
103
|
-
if (spawningBinaries.includes(binary)) {
|
|
104
|
-
const rest = node.suffix
|
|
105
|
-
.filter(w => w.text !== '--')
|
|
106
|
-
.map(w => w.text)
|
|
107
|
-
.join(' ');
|
|
108
|
-
return [toBinary(binary), ...getDependenciesFromScript(rest, options)];
|
|
109
|
-
}
|
|
110
|
-
if (binary in Plugins) {
|
|
111
|
-
const inputs = fallbackResolve(binary, words, { ...options, fromArgs });
|
|
112
|
-
if (options.knownBinsOnly)
|
|
113
|
-
for (const input of inputs)
|
|
114
|
-
input.optional = true;
|
|
115
|
-
return [...inputs, ...fromNodeOptions];
|
|
116
|
-
}
|
|
117
|
-
if (options.knownBinsOnly && !text?.startsWith('.'))
|
|
71
|
+
if (definedFunctions.size && node.name && definedFunctions.has(extractBinary(node.name.value)))
|
|
118
72
|
return [];
|
|
119
|
-
return
|
|
73
|
+
return getDependenciesFromCommand(node, { ...options, fromArgs }, fromWords);
|
|
120
74
|
};
|
|
121
75
|
try {
|
|
122
76
|
const parsed = parse(script);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Command, Word } from 'unbash';
|
|
2
|
+
import type { BinaryResolverOptions, GetInputsFromScriptsOptions } from '../types/config.ts';
|
|
3
|
+
import { type Input } from '../util/input.ts';
|
|
4
|
+
export declare const getInputsFromNodeOptions: (prefix: Command['prefix']) => Input[];
|
|
5
|
+
export declare const getDependenciesFromCommand: (node: Command, options: BinaryResolverOptions, fromWords?: (words: Word[], options: GetInputsFromScriptsOptions) => Input[]) => Input[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Plugins, pluginArgsMap } from '../plugins.js';
|
|
2
|
+
import { toBinary, toDeferResolve } from '../util/input.js';
|
|
3
|
+
import { extractBinary } from '../util/modules.js';
|
|
4
|
+
import { resolve as fallbackResolve, spawningBinaries } from './fallback.js';
|
|
5
|
+
import KnownResolvers from './resolvers/index.js';
|
|
6
|
+
import { resolve as resolverFromPlugins } from './plugins.js';
|
|
7
|
+
import { parseNodeArgs } from './util.js';
|
|
8
|
+
export const getInputsFromNodeOptions = (prefix) => prefix
|
|
9
|
+
.filter(a => a.name === 'NODE_OPTIONS' && a.value)
|
|
10
|
+
.map(a => a.value.value)
|
|
11
|
+
.map(arg => parseNodeArgs(arg.split(' ')))
|
|
12
|
+
.filter(args => args.require)
|
|
13
|
+
.flatMap(arg => arg.require)
|
|
14
|
+
.map(id => toDeferResolve(id));
|
|
15
|
+
export const getDependenciesFromCommand = (node, options, fromWords = options.fromArgs) => {
|
|
16
|
+
const text = node.name?.value;
|
|
17
|
+
const binary = text ? extractBinary(text) : text;
|
|
18
|
+
const { fromArgs } = options;
|
|
19
|
+
if (!binary || binary === '.' || binary === 'source' || binary === '[')
|
|
20
|
+
return [];
|
|
21
|
+
if (binary.startsWith('-') || binary.startsWith('..'))
|
|
22
|
+
return [];
|
|
23
|
+
const words = node.suffix;
|
|
24
|
+
if (binary === '!' || binary === 'test')
|
|
25
|
+
return fromArgs(words);
|
|
26
|
+
const fromNodeOptions = getInputsFromNodeOptions(node.prefix);
|
|
27
|
+
if (binary in KnownResolvers) {
|
|
28
|
+
const resolver = KnownResolvers[binary];
|
|
29
|
+
return resolver(binary, words, options);
|
|
30
|
+
}
|
|
31
|
+
if (pluginArgsMap.has(binary)) {
|
|
32
|
+
return [...resolverFromPlugins(binary, words, options), ...fromNodeOptions];
|
|
33
|
+
}
|
|
34
|
+
if (spawningBinaries.includes(binary)) {
|
|
35
|
+
return [toBinary(binary), ...fromWords(words, options)];
|
|
36
|
+
}
|
|
37
|
+
if (binary in Plugins) {
|
|
38
|
+
const inputs = fallbackResolve(binary, words, options);
|
|
39
|
+
if (options.knownBinsOnly)
|
|
40
|
+
for (const input of inputs)
|
|
41
|
+
input.optional = true;
|
|
42
|
+
return [...inputs, ...fromNodeOptions];
|
|
43
|
+
}
|
|
44
|
+
if (options.knownBinsOnly && !text?.startsWith('.'))
|
|
45
|
+
return [];
|
|
46
|
+
return [...fallbackResolve(binary, words, options), ...fromNodeOptions];
|
|
47
|
+
};
|
|
@@ -4,9 +4,11 @@ import { toBinary, toDeferResolve, toEntry } from '../util/input.js';
|
|
|
4
4
|
import { isValidBinary } from '../util/modules.js';
|
|
5
5
|
import { isAbsolute } from '../util/path.js';
|
|
6
6
|
import { argsAfter } from './util.js';
|
|
7
|
+
export const spawningBinaries = ['cross-env', 'retry-cli'];
|
|
7
8
|
const endOfCommandBinaries = ['dotenvx', 'env-cmd', 'op'];
|
|
8
9
|
const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode', 'vite-node', 'zx']);
|
|
9
10
|
const positionalBinaries = new Set(['concurrently']);
|
|
11
|
+
export const isWrapper = (binary) => spawningBinaries.includes(binary) || endOfCommandBinaries.includes(binary) || positionalBinaries.has(binary);
|
|
10
12
|
export const resolve = (binary, words, { fromArgs }) => {
|
|
11
13
|
const parsed = parseArgs(words, { boolean: ['quiet', 'verbose'], '--': endOfCommandBinaries.includes(binary) });
|
|
12
14
|
const bin = binary.startsWith('.') || (binary.includes('/') && !isAbsolute(binary))
|
package/dist/binaries/plugins.js
CHANGED
|
@@ -4,11 +4,12 @@ import { compact } from '../util/array.js';
|
|
|
4
4
|
import { toBinary, toConfig, toDeferResolve, toDeferResolveEntry, toEntry } from '../util/input.js';
|
|
5
5
|
import { extractBinary } from '../util/modules.js';
|
|
6
6
|
import { dirname } from '../util/path.js';
|
|
7
|
-
import { resolve as fallbackResolve } from './fallback.js';
|
|
7
|
+
import { isWrapper as isFallbackWrapper, resolve as fallbackResolve } from './fallback.js';
|
|
8
8
|
import { toWordArgs } from './util.js';
|
|
9
9
|
const isGlobLikeMatch = /(^!|[*+\\(|{^$])/;
|
|
10
10
|
const isGlobLike = (value) => isGlobLikeMatch.test(value);
|
|
11
11
|
const nodeLoadersArgs = { import: ['r', 'experimental-loader', 'require', 'loader'] };
|
|
12
|
+
export const isWrapper = (binary) => !!pluginArgsMap.get(binary)?.[1].fromArgs || isFallbackWrapper(binary);
|
|
12
13
|
export const resolve = (binary, words, options) => {
|
|
13
14
|
const { cwd, fromArgs, containingFilePath, manifest } = options;
|
|
14
15
|
const [pluginName, pluginArgs] = pluginArgsMap.get(binary) ?? [];
|
package/dist/binaries/util.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Word } from 'unbash';
|
|
2
2
|
import type { BinaryResolverOptions, GetInputsFromScriptsOptions, ScriptArg } from '../types/config.ts';
|
|
3
3
|
import type { Input } from '../util/input.ts';
|
|
4
|
+
export declare const toScript: (args: ScriptArg[]) => string;
|
|
4
5
|
export declare const argsFrom: <T extends string | Word>(args: readonly T[], from: string) => T[];
|
|
5
6
|
export declare const argsAfter: <T extends string | Word>(args: readonly T[], token: string) => T[];
|
|
6
7
|
export declare const toWordArgs: (values: (string | number)[], words: Word[]) => ScriptArg[];
|
package/dist/binaries/util.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import parseArgs from '../util/parse-args.js';
|
|
2
2
|
const valueOf = (arg) => (typeof arg === 'string' ? arg : arg.value);
|
|
3
|
+
export const toScript = (args) => {
|
|
4
|
+
const parts = [];
|
|
5
|
+
for (const arg of args) {
|
|
6
|
+
if (typeof arg === 'string') {
|
|
7
|
+
if (arg !== '--')
|
|
8
|
+
parts.push(arg);
|
|
9
|
+
}
|
|
10
|
+
else if (arg.value !== '--')
|
|
11
|
+
parts.push(arg.text);
|
|
12
|
+
}
|
|
13
|
+
return parts.join(' ');
|
|
14
|
+
};
|
|
3
15
|
export const argsFrom = (args, from) => args.slice(args.findIndex(arg => valueOf(arg) === from));
|
|
4
16
|
export const argsAfter = (args, token) => {
|
|
5
17
|
const index = args.findIndex(arg => valueOf(arg) === token);
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,8 @@ import { createOptions } from './util/create-options.js';
|
|
|
5
5
|
import { getKnownErrors, hasErrorCause, isConfigurationError, isKnownError, isLoaderError, isModuleNotFoundError, } from './util/errors.js';
|
|
6
6
|
import { logError } from './util/log.js';
|
|
7
7
|
import { perfObserver } from './util/Performance.js';
|
|
8
|
-
import {
|
|
8
|
+
import { createPreprocessor, toReporterOptions } from './util/preprocessor.js';
|
|
9
|
+
import { runReporters } from './util/reporter.js';
|
|
9
10
|
import { prettyMilliseconds } from './util/string.js';
|
|
10
11
|
import { version } from './version.js';
|
|
11
12
|
let args = {};
|
|
@@ -32,31 +33,10 @@ const main = async () => {
|
|
|
32
33
|
}
|
|
33
34
|
const options = await createOptions({ args });
|
|
34
35
|
const { results } = await run(options);
|
|
35
|
-
const { issues, counters, tagHints, configurationHints, includedWorkspaceDirs, enabledPlugins, selectedWorkspaces, } = results;
|
|
36
36
|
if (options.isWatch || options.isTrace)
|
|
37
37
|
return;
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
issues,
|
|
41
|
-
counters,
|
|
42
|
-
tagHints,
|
|
43
|
-
configurationHints,
|
|
44
|
-
enabledPlugins,
|
|
45
|
-
includedWorkspaceDirs,
|
|
46
|
-
cwd: options.cwd,
|
|
47
|
-
configFilePath: options.configFilePath,
|
|
48
|
-
isDisableConfigHints: options.isDisableConfigHints,
|
|
49
|
-
isDisableTagHints: options.isDisableTagHints,
|
|
50
|
-
isProduction: options.isProduction,
|
|
51
|
-
isShowProgress: options.isShowProgress,
|
|
52
|
-
isTreatConfigHintsAsErrors: options.isTreatConfigHintsAsErrors,
|
|
53
|
-
isTreatTagHintsAsErrors: options.isTreatTagHintsAsErrors,
|
|
54
|
-
maxShowIssues: options.maxShowIssues,
|
|
55
|
-
options: args['reporter-options'] ?? '',
|
|
56
|
-
preprocessorOptions: args['preprocessor-options'] ?? '',
|
|
57
|
-
selectedWorkspaces,
|
|
58
|
-
};
|
|
59
|
-
const finalData = await runPreprocessors(args.preprocessor ?? [], initialData);
|
|
38
|
+
const preprocess = await createPreprocessor(options.preprocessor);
|
|
39
|
+
const finalData = await preprocess(toReporterOptions(options, results, args));
|
|
60
40
|
if (options.isFix)
|
|
61
41
|
await fix(finalData.issues, finalData.counters, options);
|
|
62
42
|
await runReporters(args.reporter ?? ['symbols'], finalData);
|
|
@@ -74,10 +54,16 @@ const main = async () => {
|
|
|
74
54
|
console.log('\nTotal running time:', prettyMilliseconds(duration));
|
|
75
55
|
perfObserver.reset();
|
|
76
56
|
}
|
|
57
|
+
if (results.hasConfigLoadErrors) {
|
|
58
|
+
process.exitCode = 2;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
77
61
|
if (!args['no-exit-code'] &&
|
|
78
62
|
(totalErrorCount > options.maxIssues ||
|
|
79
|
-
(!options.isDisableConfigHints &&
|
|
80
|
-
|
|
63
|
+
(!options.isDisableConfigHints &&
|
|
64
|
+
options.isTreatConfigHintsAsErrors &&
|
|
65
|
+
finalData.configurationHints.length > 0) ||
|
|
66
|
+
(!options.isDisableTagHints && options.isTreatTagHintsAsErrors && finalData.tagHints.size > 0))) {
|
|
81
67
|
process.exitCode = 1;
|
|
82
68
|
return;
|
|
83
69
|
}
|