knip 0.4.1 → 0.4.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/README.md +7 -5
- package/dist/cli.js +2 -1
- package/dist/index.js +6 -5
- package/dist/util/errors.d.ts +2 -0
- package/dist/util/errors.js +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,12 +22,14 @@ This is where Knip comes in:
|
|
|
22
22
|
- [x] Supports JavaScript-only projects using ESM (without a `tsconfig.json`)
|
|
23
23
|
|
|
24
24
|
Knip really shines in larger projects where you have non-production files (such as `/docs`, `/tools` and `/scripts`).
|
|
25
|
-
The `includes` setting in `tsconfig.json` is often too broad, resulting in too many false negatives.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
these separately.
|
|
25
|
+
The `includes` setting in `tsconfig.json` is often too broad, resulting in too many false negatives. To produce good
|
|
26
|
+
results it's essential to configure entry files. A comparison with similar toos answers the question
|
|
27
|
+
[Why yet another unused file/dependency/export finder?](#why-yet-another-unused-filedependencyexport-finder)
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
Knip is a fresh take on keeping your projects clean & tidy!
|
|
30
|
+
|
|
31
|
+
[](https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC)
|
|
32
|
+
<sup>_“An orange cow with scissors, Van Gogh style” - generated with OpenAI_</sup>
|
|
31
33
|
|
|
32
34
|
## Installation
|
|
33
35
|
|
package/dist/cli.js
CHANGED
|
@@ -9,6 +9,7 @@ const node_util_1 = require("node:util");
|
|
|
9
9
|
const _1 = require(".");
|
|
10
10
|
const help_1 = require("./help");
|
|
11
11
|
const reporters_1 = __importDefault(require("./reporters"));
|
|
12
|
+
const errors_1 = require("./util/errors");
|
|
12
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
14
|
options: {
|
|
14
15
|
help: { type: 'boolean' },
|
|
@@ -59,7 +60,7 @@ const run = async () => {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
catch (error) {
|
|
62
|
-
if (error instanceof
|
|
63
|
+
if (error instanceof errors_1.ConfigurationError) {
|
|
63
64
|
console.error(error.message + '\n');
|
|
64
65
|
(0, help_1.printHelp)();
|
|
65
66
|
process.exit(1);
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const fs_1 = require("./util/fs");
|
|
|
11
11
|
const path_1 = require("./util/path");
|
|
12
12
|
const project_1 = require("./util/project");
|
|
13
13
|
const runner_1 = require("./runner");
|
|
14
|
+
const errors_1 = require("./util/errors");
|
|
14
15
|
const main = async (options) => {
|
|
15
16
|
const { cwd, workingDir, configFilePath = 'knip.json', tsConfigFilePath, include, exclude, ignore, gitignore, isDev, isShowProgress, jsDoc, } = options;
|
|
16
17
|
const localConfigurationPath = configFilePath && (await (0, fs_1.findFile)(workingDir, configFilePath));
|
|
@@ -19,18 +20,18 @@ const main = async (options) => {
|
|
|
19
20
|
const manifest = manifestPath && require(manifestPath);
|
|
20
21
|
if (!localConfigurationPath && !manifest.knip) {
|
|
21
22
|
const location = workingDir === cwd ? 'current directory' : `${node_path_1.default.relative(cwd, workingDir)} or up.`;
|
|
22
|
-
throw new
|
|
23
|
+
throw new errors_1.ConfigurationError(`Unable to find ${configFilePath} or package.json#knip in ${location}`);
|
|
23
24
|
}
|
|
24
25
|
const dir = node_path_1.default.relative(cwd, workingDir);
|
|
25
26
|
const resolvedConfig = (0, config_1.resolveConfig)(manifest.knip ?? localConfiguration, { workingDir: dir, isDev });
|
|
26
27
|
if (!resolvedConfig) {
|
|
27
|
-
throw new
|
|
28
|
+
throw new errors_1.ConfigurationError('Unable to find `entryFiles` and/or `projectFiles` in configuration.');
|
|
28
29
|
}
|
|
29
30
|
const report = (0, config_1.resolveIncludedIssueGroups)(include, exclude, resolvedConfig);
|
|
30
31
|
let tsConfigPaths = [];
|
|
31
32
|
const tsConfigPath = await (0, fs_1.findFile)(workingDir, tsConfigFilePath ?? 'tsconfig.json');
|
|
32
33
|
if (tsConfigFilePath && !tsConfigPath) {
|
|
33
|
-
throw new
|
|
34
|
+
throw new errors_1.ConfigurationError(`Unable to find ${tsConfigFilePath}`);
|
|
34
35
|
}
|
|
35
36
|
if (tsConfigPath) {
|
|
36
37
|
const tsConfig = typescript_1.default.readConfigFile(tsConfigPath, typescript_1.default.sys.readFile);
|
|
@@ -38,10 +39,10 @@ const main = async (options) => {
|
|
|
38
39
|
? Object.keys(tsConfig.config.compilerOptions.paths).map(p => p.replace(/\*/g, '**'))
|
|
39
40
|
: [];
|
|
40
41
|
if (tsConfig.error) {
|
|
41
|
-
throw new
|
|
42
|
+
throw new errors_1.ConfigurationError(`An error occured when reading ${node_path_1.default.relative(cwd, tsConfigPath)}`);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
const projectOptions =
|
|
45
|
+
const projectOptions = tsConfigPath ? { tsConfigFilePath: tsConfigPath } : { compilerOptions: { allowJs: true } };
|
|
45
46
|
const entryPaths = await (0, path_1.resolvePaths)({
|
|
46
47
|
cwd,
|
|
47
48
|
workingDir,
|