knip 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cli.js +7 -1
- package/dist/help.js +2 -0
- package/dist/index.js +11 -1
- package/dist/runner.js +9 -3
- package/dist/types.d.ts +8 -0
- package/dist/util/debug.d.ts +12 -0
- package/dist/util/debug.js +54 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -93,6 +93,8 @@ Options:
|
|
|
93
93
|
--max-issues Maximum number of issues before non-zero exit code (default: 0)
|
|
94
94
|
--reporter Select reporter: symbols, compact (default: symbols)
|
|
95
95
|
--jsdoc Enable JSDoc parsing, with options: public
|
|
96
|
+
--debug Show debug output
|
|
97
|
+
--debug-level Set verbosity of debug output (default: 1, max: 2)
|
|
96
98
|
|
|
97
99
|
Issue groups: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates
|
|
98
100
|
|
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ const _1 = require(".");
|
|
|
10
10
|
const help_1 = require("./help");
|
|
11
11
|
const reporters_1 = __importDefault(require("./reporters"));
|
|
12
12
|
const errors_1 = require("./util/errors");
|
|
13
|
-
const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'no-progress': noProgress = false, reporter = 'symbols', 'max-issues': maxIssues = '0', jsdoc: jsDoc = [], }, } = (0, node_util_1.parseArgs)({
|
|
13
|
+
const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'no-progress': noProgress = false, reporter = 'symbols', 'max-issues': maxIssues = '0', jsdoc: jsDoc = [], debug: isDebug = false, 'debug-level': debugLevel = '1', }, } = (0, node_util_1.parseArgs)({
|
|
14
14
|
options: {
|
|
15
15
|
help: { type: 'boolean' },
|
|
16
16
|
config: { type: 'string', short: 'c' },
|
|
@@ -25,6 +25,8 @@ const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsC
|
|
|
25
25
|
'max-issues': { type: 'string' },
|
|
26
26
|
reporter: { type: 'string' },
|
|
27
27
|
jsdoc: { type: 'string', multiple: true },
|
|
28
|
+
debug: { type: 'boolean' },
|
|
29
|
+
'debug-level': { type: 'string' },
|
|
28
30
|
},
|
|
29
31
|
});
|
|
30
32
|
if (help) {
|
|
@@ -49,6 +51,10 @@ const run = async () => {
|
|
|
49
51
|
isDev,
|
|
50
52
|
isShowProgress,
|
|
51
53
|
jsDoc,
|
|
54
|
+
debug: {
|
|
55
|
+
isEnabled: isDebug,
|
|
56
|
+
level: isDebug ? Number(debugLevel) : 0,
|
|
57
|
+
},
|
|
52
58
|
});
|
|
53
59
|
printReport({ report, issues, workingDir, isDev });
|
|
54
60
|
const reportGroup = report.files ? 'files' : Object.keys(report).find(key => report[key]);
|
package/dist/help.js
CHANGED
|
@@ -17,6 +17,8 @@ Options:
|
|
|
17
17
|
--max-issues Maximum number of issues before non-zero exit code (default: 0)
|
|
18
18
|
--reporter Select reporter: symbols, compact (default: symbols)
|
|
19
19
|
--jsdoc Enable JSDoc parsing, with options: public
|
|
20
|
+
--debug Show debug output
|
|
21
|
+
--debug-level Set verbosity of debug output (default: 1, max: 2)
|
|
20
22
|
|
|
21
23
|
Issue groups: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates
|
|
22
24
|
|
package/dist/index.js
CHANGED
|
@@ -12,8 +12,10 @@ const path_1 = require("./util/path");
|
|
|
12
12
|
const project_1 = require("./util/project");
|
|
13
13
|
const runner_1 = require("./runner");
|
|
14
14
|
const errors_1 = require("./util/errors");
|
|
15
|
+
const debug_1 = require("./util/debug");
|
|
15
16
|
const main = async (options) => {
|
|
16
|
-
const { cwd, workingDir, configFilePath = 'knip.json', tsConfigFilePath, include, exclude, ignore, gitignore, isDev, isShowProgress, jsDoc, } = options;
|
|
17
|
+
const { cwd, workingDir, configFilePath = 'knip.json', tsConfigFilePath, include, exclude, ignore, gitignore, isDev, isShowProgress, jsDoc, debug, } = options;
|
|
18
|
+
(0, debug_1.debugLogObject)(options, 1, 'Unresolved onfiguration', options);
|
|
17
19
|
const localConfigurationPath = configFilePath && (await (0, fs_1.findFile)(workingDir, configFilePath));
|
|
18
20
|
const manifestPath = await (0, fs_1.findFile)(workingDir, 'package.json');
|
|
19
21
|
const localConfiguration = localConfigurationPath && require(localConfigurationPath);
|
|
@@ -24,6 +26,7 @@ const main = async (options) => {
|
|
|
24
26
|
}
|
|
25
27
|
const dir = node_path_1.default.relative(cwd, workingDir);
|
|
26
28
|
const resolvedConfig = (0, config_1.resolveConfig)(manifest.knip ?? localConfiguration, { workingDir: dir, isDev });
|
|
29
|
+
(0, debug_1.debugLogObject)(options, 1, 'Resolved onfiguration', resolvedConfig);
|
|
27
30
|
if (!resolvedConfig) {
|
|
28
31
|
throw new errors_1.ConfigurationError('Unable to find `entryFiles` and/or `projectFiles` in configuration.');
|
|
29
32
|
}
|
|
@@ -50,10 +53,13 @@ const main = async (options) => {
|
|
|
50
53
|
ignore,
|
|
51
54
|
gitignore,
|
|
52
55
|
});
|
|
56
|
+
(0, debug_1.debugLogFiles)(options, 1, 'Globbed entry paths', entryPaths);
|
|
53
57
|
const production = (0, project_1.createProject)({ projectOptions, paths: entryPaths });
|
|
54
58
|
const entryFiles = production.getSourceFiles();
|
|
59
|
+
(0, debug_1.debugLogSourceFiles)(options, 1, 'Included entry source files', entryFiles);
|
|
55
60
|
production.resolveSourceFileDependencies();
|
|
56
61
|
const productionFiles = production.getSourceFiles();
|
|
62
|
+
(0, debug_1.debugLogSourceFiles)(options, 1, 'Included production source files', productionFiles);
|
|
57
63
|
const projectPaths = await (0, path_1.resolvePaths)({
|
|
58
64
|
cwd,
|
|
59
65
|
workingDir,
|
|
@@ -61,8 +67,10 @@ const main = async (options) => {
|
|
|
61
67
|
ignore,
|
|
62
68
|
gitignore,
|
|
63
69
|
});
|
|
70
|
+
(0, debug_1.debugLogFiles)(options, 1, 'Globbed project paths', projectPaths);
|
|
64
71
|
const project = (0, project_1.createProject)({ projectOptions, paths: projectPaths });
|
|
65
72
|
const projectFiles = project.getSourceFiles();
|
|
73
|
+
(0, debug_1.debugLogSourceFiles)(options, 1, 'Included project source files', projectFiles);
|
|
66
74
|
const config = {
|
|
67
75
|
workingDir,
|
|
68
76
|
report,
|
|
@@ -77,8 +85,10 @@ const main = async (options) => {
|
|
|
77
85
|
jsDocOptions: {
|
|
78
86
|
isReadPublicTag: jsDoc.includes('public'),
|
|
79
87
|
},
|
|
88
|
+
debug,
|
|
80
89
|
};
|
|
81
90
|
const { issues, counters } = await (0, runner_1.findIssues)(config);
|
|
91
|
+
(0, debug_1.debugLogObject)(options, 2, 'Issues', issues);
|
|
82
92
|
return { report, issues, counters };
|
|
83
93
|
};
|
|
84
94
|
exports.main = main;
|
package/dist/runner.js
CHANGED
|
@@ -11,6 +11,7 @@ const project_1 = require("./util/project");
|
|
|
11
11
|
const type_1 = require("./util/type");
|
|
12
12
|
const dependencies_1 = require("./util/dependencies");
|
|
13
13
|
const log_1 = require("./log");
|
|
14
|
+
const debug_1 = require("./util/debug");
|
|
14
15
|
const lineRewriter = new log_1.LineRewriter();
|
|
15
16
|
async function findIssues(configuration) {
|
|
16
17
|
const { workingDir, isShowProgress, report, isDev, jsDocOptions } = configuration;
|
|
@@ -18,6 +19,10 @@ async function findIssues(configuration) {
|
|
|
18
19
|
const { getUnresolvedDependencies, getUnusedDependencies, getUnusedDevDependencies } = (0, dependencies_1.getDependencyAnalyzer)(configuration);
|
|
19
20
|
const [usedProductionFiles, unreferencedProductionFiles] = (0, project_1.partitionSourceFiles)(projectFiles, productionFiles);
|
|
20
21
|
const [usedEntryFiles, usedNonEntryFiles] = (0, project_1.partitionSourceFiles)(usedProductionFiles, entryFiles);
|
|
22
|
+
(0, debug_1.debugLogSourceFiles)(configuration, 1, 'usedProductionFiles', usedProductionFiles);
|
|
23
|
+
(0, debug_1.debugLogSourceFiles)(configuration, 1, 'unreferencedProductionFiles', unreferencedProductionFiles);
|
|
24
|
+
(0, debug_1.debugLogSourceFiles)(configuration, 1, 'usedEntryFiles', usedEntryFiles);
|
|
25
|
+
(0, debug_1.debugLogSourceFiles)(configuration, 1, 'usedNonEntryFiles', usedNonEntryFiles);
|
|
21
26
|
const issues = {
|
|
22
27
|
files: new Set(unreferencedProductionFiles.map(file => file.getFilePath())),
|
|
23
28
|
dependencies: new Set(),
|
|
@@ -44,8 +49,8 @@ async function findIssues(configuration) {
|
|
|
44
49
|
const updateProcessingOutput = (item) => {
|
|
45
50
|
if (!isShowProgress)
|
|
46
51
|
return;
|
|
47
|
-
const counter =
|
|
48
|
-
const total =
|
|
52
|
+
const counter = counters.processed;
|
|
53
|
+
const total = projectFiles.length;
|
|
49
54
|
const percentage = Math.floor((counter / total) * 100);
|
|
50
55
|
const messages = [(0, log_1.getLine)(`${percentage}%`, `of files processed (${counter} of ${total})`)];
|
|
51
56
|
report.files && messages.push((0, log_1.getLine)(unreferencedProductionFiles.length, 'unused files'));
|
|
@@ -78,6 +83,7 @@ async function findIssues(configuration) {
|
|
|
78
83
|
};
|
|
79
84
|
if (report.dependencies || report.unlisted) {
|
|
80
85
|
usedEntryFiles.forEach(sourceFile => {
|
|
86
|
+
counters.processed++;
|
|
81
87
|
const unresolvedDependencies = getUnresolvedDependencies(sourceFile);
|
|
82
88
|
unresolvedDependencies.forEach(issue => addSymbolIssue('unresolved', issue));
|
|
83
89
|
});
|
|
@@ -90,6 +96,7 @@ async function findIssues(configuration) {
|
|
|
90
96
|
report.nsTypes ||
|
|
91
97
|
report.duplicates) {
|
|
92
98
|
usedNonEntryFiles.forEach(sourceFile => {
|
|
99
|
+
counters.processed++;
|
|
93
100
|
const filePath = sourceFile.getFilePath();
|
|
94
101
|
if (report.dependencies || report.unlisted) {
|
|
95
102
|
const unresolvedDependencies = getUnresolvedDependencies(sourceFile);
|
|
@@ -175,7 +182,6 @@ async function findIssues(configuration) {
|
|
|
175
182
|
});
|
|
176
183
|
});
|
|
177
184
|
}
|
|
178
|
-
counters.processed++;
|
|
179
185
|
});
|
|
180
186
|
}
|
|
181
187
|
if (report.dependencies) {
|
package/dist/types.d.ts
CHANGED
|
@@ -47,6 +47,10 @@ export declare type UnresolvedConfiguration = {
|
|
|
47
47
|
isDev: boolean;
|
|
48
48
|
isShowProgress: boolean;
|
|
49
49
|
jsDoc: string[];
|
|
50
|
+
debug: {
|
|
51
|
+
isEnabled: boolean;
|
|
52
|
+
level: number;
|
|
53
|
+
};
|
|
50
54
|
};
|
|
51
55
|
export declare type Report = {
|
|
52
56
|
[key in IssueGroup]: boolean;
|
|
@@ -65,5 +69,9 @@ export declare type Configuration = {
|
|
|
65
69
|
jsDocOptions: {
|
|
66
70
|
isReadPublicTag: boolean;
|
|
67
71
|
};
|
|
72
|
+
debug: {
|
|
73
|
+
isEnabled: boolean;
|
|
74
|
+
level: number;
|
|
75
|
+
};
|
|
68
76
|
};
|
|
69
77
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SourceFile } from 'ts-morph';
|
|
2
|
+
declare type Config = {
|
|
3
|
+
debug: {
|
|
4
|
+
isEnabled: boolean;
|
|
5
|
+
level: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare const debugLogObject: (config: Config, minimumLevel: number, name: string, obj: unknown) => void;
|
|
9
|
+
export declare const debugLogFiles: (config: Config, minimumLevel: number, name: string, filePaths: string[]) => void;
|
|
10
|
+
export declare const debugLogSourceFiles: (config: Config, minimumLevel: number, name: string, sourceFiles: SourceFile[]) => void;
|
|
11
|
+
export declare const debugLogDiff: (config: Config, minimumLevel: number, name: string, arrA: string[], arrB: string[]) => void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.debugLogDiff = exports.debugLogSourceFiles = exports.debugLogFiles = exports.debugLogObject = void 0;
|
|
7
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
8
|
+
const logArray = (collection) => console.log(node_util_1.default.inspect(collection, { maxArrayLength: null }));
|
|
9
|
+
const debugLogObject = (config, minimumLevel, name, obj) => {
|
|
10
|
+
if (minimumLevel > config.debug.level)
|
|
11
|
+
return;
|
|
12
|
+
console.log(`[exportman] ${name}:`);
|
|
13
|
+
console.log(node_util_1.default.inspect(obj, { depth: null, colors: true }));
|
|
14
|
+
};
|
|
15
|
+
exports.debugLogObject = debugLogObject;
|
|
16
|
+
const debugLogFiles = (config, minimumLevel, name, filePaths) => {
|
|
17
|
+
if (minimumLevel > config.debug.level)
|
|
18
|
+
return;
|
|
19
|
+
const { debug } = config;
|
|
20
|
+
if (debug.level > 1) {
|
|
21
|
+
console.debug(`[exportman] ${name} (${filePaths.length}):`);
|
|
22
|
+
logArray(filePaths);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.debug(`[exportman] ${name} (${filePaths.length})`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.debugLogFiles = debugLogFiles;
|
|
29
|
+
const debugLogSourceFiles = (config, minimumLevel, name, sourceFiles) => {
|
|
30
|
+
if (minimumLevel > config.debug.level)
|
|
31
|
+
return;
|
|
32
|
+
const { debug } = config;
|
|
33
|
+
if (debug.level > 1) {
|
|
34
|
+
console.debug(`[exportman] ${name} (${sourceFiles.length}):`);
|
|
35
|
+
logArray(sourceFiles.map(sourceFile => sourceFile.getFilePath()));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.debug(`[exportman] ${name} (${sourceFiles.length})`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.debugLogSourceFiles = debugLogSourceFiles;
|
|
42
|
+
const debugLogDiff = (config, minimumLevel, name, arrA, arrB) => {
|
|
43
|
+
if (minimumLevel > config.debug.level)
|
|
44
|
+
return;
|
|
45
|
+
const onlyInA = arrA.filter(itemA => !arrB.includes(itemA)).sort();
|
|
46
|
+
const onlyInB = arrB.filter(itemB => !arrA.includes(itemB)).sort();
|
|
47
|
+
console.log(`[exportman] ${name}`);
|
|
48
|
+
console.log(`[exportman] Only in left:`);
|
|
49
|
+
logArray(onlyInA);
|
|
50
|
+
console.log();
|
|
51
|
+
console.log(`[exportman] Only in right:`);
|
|
52
|
+
logArray(onlyInB);
|
|
53
|
+
};
|
|
54
|
+
exports.debugLogDiff = debugLogDiff;
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Find unused files and exports in your TypeScript project",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript project",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"find",
|
|
7
7
|
"detect",
|
|
8
8
|
"unused",
|
|
9
|
+
"unreferenced",
|
|
9
10
|
"files",
|
|
11
|
+
"dependencies",
|
|
10
12
|
"exports",
|
|
11
13
|
"types",
|
|
12
14
|
"duplicates",
|