knip 5.75.1 → 5.75.2
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/binaries/fallback.js +1 -1
- package/dist/cli.js +14 -14
- package/dist/util/create-options.d.ts +1 -1
- package/dist/util/create-options.js +40 -40
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { compact } from '../util/array.js';
|
|
|
3
3
|
import { toBinary, toDeferResolve, toEntry } from '../util/input.js';
|
|
4
4
|
import { isValidBinary } from './bash-parser.js';
|
|
5
5
|
const spawningBinaries = ['cross-env', 'retry-cli'];
|
|
6
|
-
const endOfCommandBinaries = ['dotenvx', 'env-cmd'];
|
|
6
|
+
const endOfCommandBinaries = ['dotenvx', 'env-cmd', 'op'];
|
|
7
7
|
const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode', 'vite-node', 'zx']);
|
|
8
8
|
const positionalBinaries = new Set(['concurrently']);
|
|
9
9
|
export const resolve = (binary, args, { fromArgs }) => {
|
package/dist/cli.js
CHANGED
|
@@ -7,9 +7,9 @@ import { perfObserver } from './util/Performance.js';
|
|
|
7
7
|
import { runPreprocessors, runReporters } from './util/reporter.js';
|
|
8
8
|
import { prettyMilliseconds } from './util/string.js';
|
|
9
9
|
import { version } from './version.js';
|
|
10
|
-
let
|
|
10
|
+
let args = {};
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
args = parseArgs();
|
|
13
13
|
}
|
|
14
14
|
catch (error) {
|
|
15
15
|
if (error instanceof Error) {
|
|
@@ -21,12 +21,12 @@ catch (error) {
|
|
|
21
21
|
}
|
|
22
22
|
const run = async () => {
|
|
23
23
|
try {
|
|
24
|
-
const options = await createOptions({
|
|
25
|
-
if (
|
|
24
|
+
const options = await createOptions({ args });
|
|
25
|
+
if (args.help) {
|
|
26
26
|
console.log(helpText);
|
|
27
27
|
process.exit(0);
|
|
28
28
|
}
|
|
29
|
-
if (
|
|
29
|
+
if (args.version) {
|
|
30
30
|
console.log(version);
|
|
31
31
|
process.exit(0);
|
|
32
32
|
}
|
|
@@ -46,12 +46,12 @@ const run = async () => {
|
|
|
46
46
|
isProduction: options.isProduction,
|
|
47
47
|
isShowProgress: options.isShowProgress,
|
|
48
48
|
isTreatConfigHintsAsErrors: options.isTreatConfigHintsAsErrors,
|
|
49
|
-
maxShowIssues:
|
|
50
|
-
options:
|
|
51
|
-
preprocessorOptions:
|
|
49
|
+
maxShowIssues: args['max-show-issues'] ? Number(args['max-show-issues']) : undefined,
|
|
50
|
+
options: args['reporter-options'] ?? '',
|
|
51
|
+
preprocessorOptions: args['preprocessor-options'] ?? '',
|
|
52
52
|
};
|
|
53
|
-
const finalData = await runPreprocessors(
|
|
54
|
-
await runReporters(
|
|
53
|
+
const finalData = await runPreprocessors(args.preprocessor ?? [], initialData);
|
|
54
|
+
await runReporters(args.reporter ?? ['symbols'], finalData);
|
|
55
55
|
const totalErrorCount = Object.keys(finalData.report)
|
|
56
56
|
.filter(reportGroup => finalData.report[reportGroup] && options.rules[reportGroup] === 'error')
|
|
57
57
|
.reduce((errorCount, reportGroup) => errorCount + finalData.counters[reportGroup], 0);
|
|
@@ -59,27 +59,27 @@ const run = async () => {
|
|
|
59
59
|
await perfObserver.finalize();
|
|
60
60
|
if (perfObserver.isTimerifyFunctions)
|
|
61
61
|
console.log(`\n${perfObserver.getTimerifiedFunctionsTable()}`);
|
|
62
|
-
if (perfObserver.isMemoryUsageEnabled && !
|
|
62
|
+
if (perfObserver.isMemoryUsageEnabled && !args['memory-realtime'])
|
|
63
63
|
console.log(`\n${perfObserver.getMemoryUsageTable()}`);
|
|
64
64
|
if (perfObserver.isEnabled) {
|
|
65
65
|
const duration = perfObserver.getCurrentDurationInMs();
|
|
66
66
|
console.log('\nTotal running time:', prettyMilliseconds(duration));
|
|
67
67
|
perfObserver.reset();
|
|
68
68
|
}
|
|
69
|
-
if (
|
|
69
|
+
if (args['experimental-tags'] && args['experimental-tags'].length > 0) {
|
|
70
70
|
logWarning('DEPRECATION WARNING', '--experimental-tags is deprecated, please start using --tags instead');
|
|
71
71
|
}
|
|
72
72
|
if (options.isIsolateWorkspaces && options.includedIssueTypes.classMembers) {
|
|
73
73
|
logWarning('WARNING', 'Class members are not tracked when using the --isolate-workspaces flag');
|
|
74
74
|
}
|
|
75
|
-
if ((!
|
|
75
|
+
if ((!args['no-exit-code'] && totalErrorCount > Number(args['max-issues'] ?? 0)) ||
|
|
76
76
|
(!options.isDisableConfigHints && options.isTreatConfigHintsAsErrors && configurationHints.size > 0)) {
|
|
77
77
|
process.exit(1);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
catch (error) {
|
|
81
81
|
process.exitCode = 2;
|
|
82
|
-
if (!
|
|
82
|
+
if (!args.debug && error instanceof Error && isKnownError(error)) {
|
|
83
83
|
const knownErrors = getKnownErrors(error);
|
|
84
84
|
for (const knownError of knownErrors)
|
|
85
85
|
logError('ERROR', knownError.message);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Options } from '../types/options.js';
|
|
2
2
|
import type { ParsedCLIArgs } from './cli-arguments.js';
|
|
3
3
|
interface CreateOptions extends Partial<Options> {
|
|
4
|
-
|
|
4
|
+
args?: ParsedCLIArgs;
|
|
5
5
|
}
|
|
6
6
|
export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
7
7
|
cacheLocation: string;
|
|
@@ -13,25 +13,25 @@ import { isAbsolute, join, normalize, toAbsolute, toPosix } from './path.js';
|
|
|
13
13
|
import { splitTags } from './tag.js';
|
|
14
14
|
const pcwd = process.cwd();
|
|
15
15
|
export const createOptions = async (options) => {
|
|
16
|
-
const {
|
|
17
|
-
const cwd = normalize(toPosix(toAbsolute(options.cwd ??
|
|
16
|
+
const { args = {} } = options;
|
|
17
|
+
const cwd = normalize(toPosix(toAbsolute(options.cwd ?? args.directory ?? pcwd, pcwd)));
|
|
18
18
|
const manifestPath = findFile(cwd, 'package.json');
|
|
19
19
|
const manifest = manifestPath && (await loadJSON(manifestPath));
|
|
20
20
|
if (!(manifestPath && manifest)) {
|
|
21
21
|
throw new ConfigurationError('Unable to find package.json');
|
|
22
22
|
}
|
|
23
23
|
let configFilePath;
|
|
24
|
-
for (const configPath of
|
|
24
|
+
for (const configPath of args.config ? [args.config] : KNIP_CONFIG_LOCATIONS) {
|
|
25
25
|
const resolvedConfigFilePath = isAbsolute(configPath) ? configPath : findFile(cwd, configPath);
|
|
26
26
|
if (resolvedConfigFilePath) {
|
|
27
27
|
configFilePath = resolvedConfigFilePath;
|
|
28
28
|
break;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
if (
|
|
32
|
-
throw new ConfigurationError(`Unable to find ${
|
|
31
|
+
if (args.config && !configFilePath && !manifest.knip) {
|
|
32
|
+
throw new ConfigurationError(`Unable to find ${args.config} or package.json#knip`);
|
|
33
33
|
}
|
|
34
|
-
const loadedConfig = Object.assign({}, manifest.knip, configFilePath ? await loadResolvedConfigFile(configFilePath,
|
|
34
|
+
const loadedConfig = Object.assign({}, manifest.knip, configFilePath ? await loadResolvedConfigFile(configFilePath, args) : {});
|
|
35
35
|
const parsedConfig = knipConfigurationSchema.parse(partitionCompilers(loadedConfig));
|
|
36
36
|
if (!configFilePath && manifest.knip)
|
|
37
37
|
configFilePath = manifestPath;
|
|
@@ -43,58 +43,58 @@ export const createOptions = async (options) => {
|
|
|
43
43
|
? manifest.workspaces
|
|
44
44
|
: (manifest.workspaces.packages ?? [])
|
|
45
45
|
: []);
|
|
46
|
-
const isStrict = options.isStrict ??
|
|
47
|
-
const isProduction = options.isProduction ??
|
|
48
|
-
const isDebug =
|
|
49
|
-
const isTrace = Boolean(
|
|
46
|
+
const isStrict = options.isStrict ?? args.strict ?? false;
|
|
47
|
+
const isProduction = options.isProduction ?? args.production ?? isStrict;
|
|
48
|
+
const isDebug = args.debug ?? false;
|
|
49
|
+
const isTrace = Boolean(args.trace ?? args['trace-file'] ?? args['trace-export']);
|
|
50
50
|
const rules = { ...defaultRules, ...parsedConfig.rules };
|
|
51
51
|
const excludesFromRules = getKeysByValue(rules, 'off');
|
|
52
52
|
const includedIssueTypes = getIncludedIssueTypes({
|
|
53
53
|
isProduction,
|
|
54
54
|
exclude: [...excludesFromRules, ...(parsedConfig.exclude ?? [])],
|
|
55
55
|
include: parsedConfig.include ?? [],
|
|
56
|
-
excludeOverrides: options.excludedIssueTypes ??
|
|
56
|
+
excludeOverrides: options.excludedIssueTypes ?? args.exclude ?? [],
|
|
57
57
|
includeOverrides: [
|
|
58
|
-
...(options.includedIssueTypes ??
|
|
59
|
-
...(
|
|
60
|
-
...(
|
|
61
|
-
...(
|
|
58
|
+
...(options.includedIssueTypes ?? args.include ?? []),
|
|
59
|
+
...(args.dependencies ? shorthandDeps : []),
|
|
60
|
+
...(args.exports ? shorthandExports : []),
|
|
61
|
+
...(args.files ? shorthandFiles : []),
|
|
62
62
|
],
|
|
63
63
|
});
|
|
64
64
|
for (const [key, value] of Object.entries(includedIssueTypes)) {
|
|
65
65
|
if (!value)
|
|
66
66
|
rules[key] = 'off';
|
|
67
67
|
}
|
|
68
|
-
const fixTypes = options.fixTypes ??
|
|
69
|
-
const isFixFiles =
|
|
70
|
-
const isIncludeLibs =
|
|
68
|
+
const fixTypes = options.fixTypes ?? args['fix-type'] ?? [];
|
|
69
|
+
const isFixFiles = args['allow-remove-files'] && (fixTypes.length === 0 || fixTypes.includes('files'));
|
|
70
|
+
const isIncludeLibs = args['include-libs'] ?? options.isIncludeLibs ?? false;
|
|
71
71
|
const isReportClassMembers = includedIssueTypes.classMembers;
|
|
72
|
-
const tags = splitTags(
|
|
72
|
+
const tags = splitTags(args.tags ?? options.tags ?? parsedConfig.tags ?? args['experimental-tags'] ?? []);
|
|
73
73
|
return {
|
|
74
|
-
cacheLocation:
|
|
74
|
+
cacheLocation: args['cache-location'] ?? join(cwd, 'node_modules', '.cache', 'knip'),
|
|
75
75
|
catalog: await getCatalogContainer(cwd, manifest, manifestPath, pnpmWorkspacePath, pnpmWorkspace),
|
|
76
|
-
config:
|
|
76
|
+
config: args.config,
|
|
77
77
|
configFilePath,
|
|
78
78
|
cwd,
|
|
79
|
-
dependencies:
|
|
79
|
+
dependencies: args.dependencies ?? false,
|
|
80
80
|
experimentalTags: tags,
|
|
81
|
-
exports:
|
|
82
|
-
files:
|
|
81
|
+
exports: args.exports ?? false,
|
|
82
|
+
files: args.files ?? false,
|
|
83
83
|
fixTypes,
|
|
84
|
-
gitignore:
|
|
84
|
+
gitignore: args['no-gitignore'] ? false : (options.gitignore ?? true),
|
|
85
85
|
includedIssueTypes,
|
|
86
|
-
isCache:
|
|
86
|
+
isCache: args.cache ?? false,
|
|
87
87
|
isDebug,
|
|
88
|
-
isDisableConfigHints:
|
|
89
|
-
isFix:
|
|
88
|
+
isDisableConfigHints: args['no-config-hints'] || isProduction || Boolean(args.workspace),
|
|
89
|
+
isFix: args.fix ?? options.isFix ?? isFixFiles ?? fixTypes.length > 0,
|
|
90
90
|
isFixCatalog: fixTypes.length === 0 || fixTypes.includes('catalog'),
|
|
91
91
|
isFixDependencies: fixTypes.length === 0 || fixTypes.includes('dependencies'),
|
|
92
92
|
isFixFiles,
|
|
93
93
|
isFixUnusedExports: fixTypes.length === 0 || fixTypes.includes('exports'),
|
|
94
94
|
isFixUnusedTypes: fixTypes.length === 0 || fixTypes.includes('types'),
|
|
95
|
-
isFormat:
|
|
96
|
-
isIncludeEntryExports:
|
|
97
|
-
isIsolateWorkspaces: options.isIsolateWorkspaces ??
|
|
95
|
+
isFormat: args.format ?? options.isFormat ?? false,
|
|
96
|
+
isIncludeEntryExports: args['include-entry-exports'] ?? options.isIncludeEntryExports ?? false,
|
|
97
|
+
isIsolateWorkspaces: options.isIsolateWorkspaces ?? args['isolate-workspaces'] ?? false,
|
|
98
98
|
isProduction,
|
|
99
99
|
isReportClassMembers,
|
|
100
100
|
isReportDependencies: includedIssueTypes.dependencies ||
|
|
@@ -106,24 +106,24 @@ export const createOptions = async (options) => {
|
|
|
106
106
|
isSession: options.isSession ?? false,
|
|
107
107
|
isShowProgress: !isDebug &&
|
|
108
108
|
!isTrace &&
|
|
109
|
-
|
|
109
|
+
args['no-progress'] !== true &&
|
|
110
110
|
options.isShowProgress !== false &&
|
|
111
111
|
process.stdout.isTTY &&
|
|
112
112
|
typeof process.stdout.cursorTo === 'function',
|
|
113
113
|
isSkipLibs: !(isIncludeLibs || includedIssueTypes.classMembers),
|
|
114
114
|
isStrict,
|
|
115
115
|
isTrace,
|
|
116
|
-
isTreatConfigHintsAsErrors:
|
|
117
|
-
isUseTscFiles: options.isUseTscFiles ??
|
|
118
|
-
isWatch:
|
|
119
|
-
maxShowIssues:
|
|
116
|
+
isTreatConfigHintsAsErrors: args['treat-config-hints-as-errors'] ?? parsedConfig.treatConfigHintsAsErrors ?? false,
|
|
117
|
+
isUseTscFiles: options.isUseTscFiles ?? args['use-tsconfig-files'] ?? (options.isSession && !configFilePath),
|
|
118
|
+
isWatch: args.watch ?? options.isWatch ?? false,
|
|
119
|
+
maxShowIssues: args['max-show-issues'] ? Number(args['max-show-issues']) : undefined,
|
|
120
120
|
parsedConfig,
|
|
121
121
|
rules,
|
|
122
122
|
tags,
|
|
123
|
-
traceExport:
|
|
124
|
-
traceFile:
|
|
125
|
-
tsConfigFile:
|
|
126
|
-
workspace: options.workspace ??
|
|
123
|
+
traceExport: args['trace-export'],
|
|
124
|
+
traceFile: args['trace-file'] ? toAbsolute(args['trace-file'], cwd) : undefined,
|
|
125
|
+
tsConfigFile: args.tsConfig,
|
|
126
|
+
workspace: options.workspace ?? args.workspace,
|
|
127
127
|
workspaces,
|
|
128
128
|
};
|
|
129
129
|
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.75.
|
|
1
|
+
export declare const version = "5.75.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.75.
|
|
1
|
+
export const version = '5.75.2';
|