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 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. Similar projects
26
- either detect only unimported files, or only unused exports. Most of them don't work by configuring entry files, an
27
- essential feature to produce good results. This also allows to unleash knip on a specific part of your project, and work
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
- ✂️ Knip is another fresh take on keeping your projects clean & tidy!
29
+ Knip is a fresh take on keeping your projects clean & tidy!
30
+
31
+ [![An orange cow with scissors, Van Gogh style](./assets/cow-with-orange-scissors-van-gogh-style.webp)](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 Error) {
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 Error(`Unable to find ${configFilePath} or package.json#knip in ${location}`);
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 Error('Unable to find `entryFiles` and/or `projectFiles` in configuration.');
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 Error(`Unable to find ${tsConfigFilePath}`);
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 Error(`An error occured when reading ${node_path_1.default.relative(cwd, tsConfigPath)}`);
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 = tsConfigFilePath ? { tsConfigFilePath } : { compilerOptions: { allowJs: true } };
45
+ const projectOptions = tsConfigPath ? { tsConfigFilePath: tsConfigPath } : { compilerOptions: { allowJs: true } };
45
46
  const entryPaths = await (0, path_1.resolvePaths)({
46
47
  cwd,
47
48
  workingDir,
@@ -0,0 +1,2 @@
1
+ export declare class ConfigurationError extends Error {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigurationError = void 0;
4
+ class ConfigurationError extends Error {
5
+ }
6
+ exports.ConfigurationError = ConfigurationError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Find unused files and exports in your TypeScript project",
5
5
  "keywords": [
6
6
  "find",