knip 2.19.0 → 2.19.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
@@ -682,13 +682,13 @@ The following commands are similar:
682
682
 
683
683
  Many thanks to some of the early adopters of Knip:
684
684
 
685
- - [Abracabra][23]
686
- - [Block Protocol][24]
687
- - [Cursor][25]
688
- - [DeepmergeTS][26]
689
- - [eslint-plugin-functional][27]
690
- - [freeCodeCamp.org][28]
691
- - [is-immutable-type][29]
685
+ - [Block Protocol][23]
686
+ - [DeepmergeTS][24]
687
+ - [eslint-plugin-functional][25]
688
+ - [freeCodeCamp.org][26]
689
+ - [is-immutable-type][27]
690
+ - [IsaacScript][28]
691
+ - [Owncast][29]
692
692
  - [release-it][30]
693
693
  - [Template TypeScript Node Package][31]
694
694
 
@@ -752,13 +752,13 @@ Special thanks to the wonderful people who have contributed to this project:
752
752
  [20]: https://github.com/pzavolinsky/ts-unused-exports
753
753
  [21]: https://github.com/nadeesha/ts-prune
754
754
  [22]: #production-mode
755
- [23]: https://github.com/nicoespeon/abracadabra
756
- [24]: https://github.com/blockprotocol/blockprotocol
757
- [25]: https://github.com/getcursor/cursor
758
- [26]: https://github.com/RebeccaStevens/deepmerge-ts
759
- [27]: https://github.com/eslint-functional/eslint-plugin-functional
760
- [28]: https://github.com/freeCodeCamp/freeCodeCamp
761
- [29]: https://github.com/RebeccaStevens/is-immutable-type
755
+ [23]: https://github.com/blockprotocol/blockprotocol
756
+ [24]: https://github.com/RebeccaStevens/deepmerge-ts
757
+ [25]: https://github.com/eslint-functional/eslint-plugin-functional
758
+ [26]: https://github.com/freeCodeCamp/freeCodeCamp
759
+ [27]: https://github.com/RebeccaStevens/is-immutable-type
760
+ [28]: https://github.com/IsaacScript/isaacscript
761
+ [29]: https://github.com/owncast/owncast
762
762
  [30]: https://github.com/release-it/release-it
763
763
  [31]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
764
764
  [32]: https://github.com/webpro/knip/graphs/contributors
@@ -3,4 +3,5 @@ export declare const NAME = "Ava";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const ENTRY_FILE_PATTERNS: never[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -5,6 +5,7 @@ export const NAME = 'Ava';
5
5
  export const ENABLERS = ['ava'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  export const CONFIG_FILE_PATTERNS = ['ava.config.{js,cjs,mjs}', 'package.json'];
8
+ export const ENTRY_FILE_PATTERNS = [];
8
9
  const findAvaDependencies = async (configFilePath, { cwd, manifest }) => {
9
10
  const config = configFilePath.endsWith('package.json') ? manifest.ava : await load(configFilePath);
10
11
  const requireArgs = (config?.require ?? []).map(require => `--require ${require}`);
@@ -9,5 +9,6 @@ type GetDependenciesDeep = (configFilePath: string, dependencies: Set<string>, o
9
9
  manifest: Manifest;
10
10
  }) => Promise<Set<string>>;
11
11
  export declare const getDependenciesDeep: GetDependenciesDeep;
12
- export declare const resolveExtendsSpecifier: (specifier: string) => string | undefined;
12
+ export declare const resolvePluginSpecifier: (specifier: string) => string;
13
+ export declare const resolveExtendSpecifier: (specifier: string) => string | undefined;
13
14
  export {};
@@ -1,14 +1,13 @@
1
1
  import { compact } from '../../util/array.js';
2
- import { getPackageNameFromModuleSpecifier } from '../../util/modules.js';
3
2
  import { isInternal, dirname, toAbsolute } from '../../util/path.js';
4
3
  import { load } from '../../util/plugin.js';
5
4
  import { _resolve } from '../../util/require.js';
6
5
  import { fallback } from './fallback.js';
7
6
  const getDependencies = (config) => {
8
- const extendsSpecifiers = config.extends ? [config.extends].flat().map(resolveExtendsSpecifier) : [];
7
+ const extendsSpecifiers = config.extends ? [config.extends].flat().map(resolveExtendSpecifier) : [];
9
8
  if (extendsSpecifiers.includes('eslint-plugin-prettier'))
10
9
  extendsSpecifiers.push('eslint-config-prettier');
11
- const plugins = config.plugins ? config.plugins.map(resolvePluginPackageName) : [];
10
+ const plugins = config.plugins ? config.plugins.map(resolvePluginSpecifier) : [];
12
11
  const parser = config.parser;
13
12
  const extraPlugins = config.parserOptions?.babelOptions?.plugins ?? [];
14
13
  const extraParsers = config.parserOptions?.babelOptions?.presets ?? [];
@@ -46,28 +45,29 @@ export const getDependenciesDeep = async (configFilePath, dependencies = new Set
46
45
  }
47
46
  return dependencies;
48
47
  };
49
- const resolvePackageName = (namespace, pluginName) => {
50
- return pluginName.includes(namespace + '-') || pluginName.endsWith(`/${namespace}`)
51
- ? pluginName
52
- : pluginName.startsWith('@')
53
- ? pluginName.includes('/')
54
- ? pluginName.replace(/\//, `/${namespace}-`)
55
- : `${pluginName}/${namespace}`
56
- : `${namespace}-${pluginName}`;
48
+ const isQualifiedSpecifier = (specifier) => specifier === 'eslint' ||
49
+ /\/eslint-(config|plugin)$/.test(specifier) ||
50
+ /.+eslint-(config|plugin)\//.test(specifier) ||
51
+ /eslint-(config|plugin)-/.test(specifier);
52
+ const resolveSpecifier = (namespace, rawSpecifier) => {
53
+ const specifier = rawSpecifier.replace(/(^plugin:|:.+$)/, '');
54
+ if (isQualifiedSpecifier(specifier))
55
+ return specifier;
56
+ if (!specifier.startsWith('@'))
57
+ return `${namespace}-${specifier}`;
58
+ const [scope, name, ...rest] = specifier.split('/');
59
+ if (rawSpecifier.startsWith('plugin:') && rest.length === 0)
60
+ return [scope, namespace, name].join('/');
61
+ return [scope, name ? `${namespace}-${name}` : namespace, ...rest].join('/');
57
62
  };
58
- const resolvePluginPackageName = (pluginName) => resolvePackageName('eslint-plugin', pluginName);
59
- export const resolveExtendsSpecifier = (specifier) => {
63
+ export const resolvePluginSpecifier = (specifier) => resolveSpecifier('eslint-plugin', specifier);
64
+ export const resolveExtendSpecifier = (specifier) => {
60
65
  if (isInternal(specifier))
61
66
  return;
62
- if (/\/eslint-(config|plugin)/.test(specifier))
67
+ if (/^next(\/.+)?$/.test(specifier))
63
68
  return specifier;
64
- const noProtocolSpecifier = specifier.replace(/(^plugin:|:.+$)/, '');
65
- if (noProtocolSpecifier.startsWith('@typescript-eslint/'))
66
- return '@typescript-eslint/eslint-plugin';
67
- if (noProtocolSpecifier === 'eslint')
68
- return;
69
- const packageName = getPackageNameFromModuleSpecifier(noProtocolSpecifier) ?? noProtocolSpecifier;
70
- return resolvePackageName(specifier.startsWith('plugin:') ? 'eslint-plugin' : 'eslint-config', packageName);
69
+ const namespace = specifier.startsWith('plugin:') ? 'eslint-plugin' : 'eslint-config';
70
+ return resolveSpecifier(namespace, specifier);
71
71
  };
72
72
  const getDependenciesFromSettings = (settings = {}) => {
73
73
  return compact(Object.entries(settings).flatMap(([settingKey, settings]) => {
@@ -3,4 +3,5 @@ export declare const NAME = "Jest";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const ENTRY_FILE_PATTERNS: never[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -5,6 +5,7 @@ export const NAME = 'Jest';
5
5
  export const ENABLERS = ['jest'];
6
6
  export const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, ENABLERS) || Boolean(manifest.name?.startsWith('jest-presets'));
7
7
  export const CONFIG_FILE_PATTERNS = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json'];
8
+ export const ENTRY_FILE_PATTERNS = [];
8
9
  const resolveExtensibleConfig = async (configFilePath) => {
9
10
  const config = await load(configFilePath);
10
11
  if (config?.preset) {
@@ -2,33 +2,40 @@ import { compact } from '../../util/array.js';
2
2
  import { dirname, isInternal, toAbsolute } from '../../util/path.js';
3
3
  import { timerify } from '../../util/Performance.js';
4
4
  import { hasDependency, load } from '../../util/plugin.js';
5
+ import { loadTSConfig } from '../../util/tsconfig-loader.js';
5
6
  export const NAME = 'TypeScript';
6
7
  export const ENABLERS = ['typescript'];
7
8
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
9
  export const CONFIG_FILE_PATTERNS = ['tsconfig.json'];
9
10
  const resolveExtensibleConfig = async (configFilePath) => {
10
11
  const config = await load(configFilePath);
12
+ config.extends = config.extends ? [config.extends].flat() : [];
11
13
  if (config?.extends) {
12
- if (isInternal(config.extends)) {
13
- const presetConfigPath = toAbsolute(config.extends, dirname(configFilePath));
14
- const presetConfig = await resolveExtensibleConfig(presetConfigPath);
15
- Object.assign(config, presetConfig);
14
+ for (const extend of [config.extends].flat()) {
15
+ if (isInternal(extend)) {
16
+ const presetConfigPath = toAbsolute(extend, dirname(configFilePath));
17
+ const presetConfig = await resolveExtensibleConfig(presetConfigPath);
18
+ config.extends.push(...(presetConfig.extends ? [presetConfig.extends].flat() : []));
19
+ }
16
20
  }
17
21
  }
18
22
  return config;
19
23
  };
20
24
  const findTypeScriptDependencies = async (configFilePath) => {
25
+ const compilerOptions = await loadTSConfig(configFilePath);
21
26
  const config = await resolveExtensibleConfig(configFilePath);
22
- if (!config)
27
+ if (!compilerOptions || !config)
23
28
  return [];
24
29
  const extend = config.extends ? [config.extends].flat().filter(extend => !isInternal(extend)) : [];
25
- const plugins = compact(config.compilerOptions?.plugins?.map(plugin => plugin.name) ?? []);
26
- const importHelpers = config.compilerOptions?.importHelpers ? ['tslib'] : [];
27
- const jsx = config.compilerOptions?.jsxImportSource
28
- ? [config.compilerOptions.jsxImportSource]
29
- : config.compilerOptions?.jsx
30
+ const plugins = Array.isArray(compilerOptions?.plugins)
31
+ ? compilerOptions.plugins.map(plugin => (typeof plugin === 'object' && 'name' in plugin ? plugin.name : ''))
32
+ : [];
33
+ const importHelpers = compilerOptions?.importHelpers ? ['tslib'] : [];
34
+ const jsx = compilerOptions?.jsxImportSource
35
+ ? [compilerOptions.jsxImportSource]
36
+ : compilerOptions?.jsx
30
37
  ? ['react']
31
38
  : [];
32
- return [...extend, ...plugins, ...importHelpers, ...jsx];
39
+ return compact([...extend, ...plugins, ...importHelpers, ...jsx]);
33
40
  };
34
41
  export const findDependencies = timerify(findTypeScriptDependencies);
@@ -2,6 +2,6 @@ import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types
2
2
  export declare const NAME = "Vitest";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
- export declare const ENTRY_FILE_PATTERNS: string[];
6
5
  export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const ENTRY_FILE_PATTERNS: string[];
7
7
  export declare const findDependencies: GenericPluginCallback;
@@ -5,8 +5,8 @@ import { getEnvPackageName, getExternalReporters } from './helpers.js';
5
5
  export const NAME = 'Vitest';
6
6
  export const ENABLERS = ['vitest'];
7
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
- export const ENTRY_FILE_PATTERNS = ['vite.config.ts'];
9
8
  export const CONFIG_FILE_PATTERNS = ['vitest.config.ts'];
9
+ export const ENTRY_FILE_PATTERNS = ['vite.config.ts'];
10
10
  const findVitestDependencies = async (configFilePath) => {
11
11
  const config = await load(configFilePath);
12
12
  if (!config || !config.test)
@@ -14,7 +14,7 @@ const findVitestDependencies = async (configFilePath) => {
14
14
  const cfg = config.test;
15
15
  const environments = cfg.environment ? [getEnvPackageName(cfg.environment)] : [];
16
16
  const reporters = getExternalReporters(cfg.reporters);
17
- const coverage = cfg.coverage ? [`@vitest/coverage-${cfg.coverage.provider ?? "v8"}`] : [];
17
+ const coverage = cfg.coverage ? [`@vitest/coverage-${cfg.coverage.provider ?? 'v8'}`] : [];
18
18
  const setupFiles = cfg.setupFiles ? [cfg.setupFiles].flat() : [];
19
19
  const globalSetup = cfg.globalSetup ? [cfg.globalSetup].flat() : [];
20
20
  return compact([...environments, ...reporters, ...coverage, ...setupFiles, ...globalSetup]);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.19.0";
1
+ export declare const version = "2.19.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.19.0';
1
+ export const version = '2.19.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.19.0",
3
+ "version": "2.19.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",
@@ -65,27 +65,27 @@
65
65
  "@npmcli/package-json": "4.0.1",
66
66
  "@release-it/bumper": "5.1.0",
67
67
  "@swc/cli": "0.1.62",
68
- "@swc/core": "1.3.74",
68
+ "@swc/core": "1.3.76",
69
69
  "@types/eslint": "8.44.2",
70
70
  "@types/js-yaml": "4.0.5",
71
71
  "@types/micromatch": "4.0.2",
72
72
  "@types/minimist": "1.2.2",
73
- "@types/node": "20.4.7",
73
+ "@types/node": "20.4.9",
74
74
  "@types/npmcli__map-workspaces": "3.0.1",
75
75
  "@types/webpack": "5.28.1",
76
- "@typescript-eslint/eslint-plugin": "6.2.1",
77
- "@typescript-eslint/parser": "6.2.1",
76
+ "@typescript-eslint/eslint-plugin": "6.3.0",
77
+ "@typescript-eslint/parser": "6.3.0",
78
78
  "c8": "8.0.1",
79
79
  "eslint": "8.46.0",
80
- "eslint-import-resolver-typescript": "3.5.5",
80
+ "eslint-import-resolver-typescript": "3.6.0",
81
81
  "eslint-plugin-import": "2.28.0",
82
82
  "eslint-plugin-n": "16.0.1",
83
83
  "prettier": "3.0.1",
84
- "release-it": "16.1.3",
84
+ "release-it": "16.1.4",
85
85
  "remark-cli": "11.0.0",
86
86
  "remark-preset-webpro": "0.0.3",
87
87
  "tsx": "3.12.7",
88
- "type-fest": "4.1.0"
88
+ "type-fest": "4.2.0"
89
89
  },
90
90
  "engines": {
91
91
  "node": ">=16.17.0 <17 || >=18.6.0"