knip 2.19.1 → 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
@@ -2,35 +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
14
  for (const extend of [config.extends].flat()) {
13
15
  if (isInternal(extend)) {
14
16
  const presetConfigPath = toAbsolute(extend, dirname(configFilePath));
15
17
  const presetConfig = await resolveExtensibleConfig(presetConfigPath);
16
- Object.assign(config, presetConfig);
18
+ config.extends.push(...(presetConfig.extends ? [presetConfig.extends].flat() : []));
17
19
  }
18
20
  }
19
21
  }
20
22
  return config;
21
23
  };
22
24
  const findTypeScriptDependencies = async (configFilePath) => {
25
+ const compilerOptions = await loadTSConfig(configFilePath);
23
26
  const config = await resolveExtensibleConfig(configFilePath);
24
- if (!config)
27
+ if (!compilerOptions || !config)
25
28
  return [];
26
29
  const extend = config.extends ? [config.extends].flat().filter(extend => !isInternal(extend)) : [];
27
- const plugins = compact(config.compilerOptions?.plugins?.map(plugin => plugin.name) ?? []);
28
- const importHelpers = config.compilerOptions?.importHelpers ? ['tslib'] : [];
29
- const jsx = config.compilerOptions?.jsxImportSource
30
- ? [config.compilerOptions.jsxImportSource]
31
- : 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
32
37
  ? ['react']
33
38
  : [];
34
- return [...extend, ...plugins, ...importHelpers, ...jsx];
39
+ return compact([...extend, ...plugins, ...importHelpers, ...jsx]);
35
40
  };
36
41
  export const findDependencies = timerify(findTypeScriptDependencies);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.19.1";
1
+ export declare const version = "2.19.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.19.1';
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.1",
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.75",
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.8",
73
+ "@types/node": "20.4.9",
74
74
  "@types/npmcli__map-workspaces": "3.0.1",
75
75
  "@types/webpack": "5.28.1",
76
76
  "@typescript-eslint/eslint-plugin": "6.3.0",
77
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"