knip 2.19.1 → 2.19.3
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 +14 -14
- package/dist/plugins/typescript/index.js +13 -8
- package/dist/plugins/webpack/index.js +18 -8
- package/dist/typescript/SourceFileManager.js +5 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -6
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
|
-
- [
|
|
686
|
-
- [
|
|
687
|
-
- [
|
|
688
|
-
- [
|
|
689
|
-
- [
|
|
690
|
-
- [
|
|
691
|
-
- [
|
|
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/
|
|
756
|
-
[24]: https://github.com/
|
|
757
|
-
[25]: https://github.com/
|
|
758
|
-
[26]: https://github.com/
|
|
759
|
-
[27]: https://github.com/
|
|
760
|
-
[28]: https://github.com/
|
|
761
|
-
[29]: https://github.com/
|
|
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
|
-
|
|
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 =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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);
|
|
@@ -54,14 +54,24 @@ const findWebpackDependencies = async (configFilePath, { manifest, isProduction
|
|
|
54
54
|
const cfg = typeof config === 'function' ? config(env, argv) : config;
|
|
55
55
|
return [cfg].flat().flatMap(config => {
|
|
56
56
|
const dependencies = (config.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []).map(loader => loader.replace(/\?.*/, ''));
|
|
57
|
-
const entries =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
const entries = [];
|
|
58
|
+
if (typeof cfg.entry === 'string')
|
|
59
|
+
entries.push(cfg.entry);
|
|
60
|
+
else if (Array.isArray(cfg.entry))
|
|
61
|
+
entries.push(...cfg.entry);
|
|
62
|
+
else if (typeof cfg.entry === 'object') {
|
|
63
|
+
Object.values(cfg.entry).map(entry => {
|
|
64
|
+
if (typeof entry === 'string')
|
|
65
|
+
entries.push(entry);
|
|
66
|
+
else if (Array.isArray(entry))
|
|
67
|
+
entries.push(...entry);
|
|
68
|
+
else if (typeof entry === 'function')
|
|
69
|
+
entries.push(entry());
|
|
70
|
+
else if (entry && typeof entry === 'object' && 'filename' in entry)
|
|
71
|
+
entries.push(entry['filename']);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return [...dependencies, ...entries.map(entry => (config.context ? join(config.context, entry) : entry))];
|
|
65
75
|
});
|
|
66
76
|
});
|
|
67
77
|
const scripts = Object.values(manifest.scripts ?? {});
|
|
@@ -20,8 +20,11 @@ export class SourceFileManager {
|
|
|
20
20
|
if (this.sourceFileCache.has(filePath))
|
|
21
21
|
return this.sourceFileCache.get(filePath);
|
|
22
22
|
const contents = ts.sys.readFile(filePath);
|
|
23
|
-
if (typeof contents !== 'string')
|
|
24
|
-
|
|
23
|
+
if (typeof contents !== 'string') {
|
|
24
|
+
if (isInternal(filePath))
|
|
25
|
+
throw new Error(`Unable to read ${filePath}`);
|
|
26
|
+
return this.createSourceFile(filePath, '');
|
|
27
|
+
}
|
|
25
28
|
const ext = extname(filePath);
|
|
26
29
|
const compiler = this.syncCompilers?.get(ext);
|
|
27
30
|
const compiled = compiler ? compiler(contents, filePath) : contents;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.19.
|
|
1
|
+
export declare const version = "2.19.3";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.19.
|
|
1
|
+
export const version = '2.19.3';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.3",
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
88
|
+
"type-fest": "4.2.0"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": ">=16.17.0 <17 || >=18.6.0"
|