knip 2.0.0 → 2.1.0
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 +2 -0
- package/dist/cli.js +7 -1
- package/dist/configuration-validator.d.ts +56 -0
- package/dist/configuration-validator.js +1 -0
- package/dist/plugins/eslint/index.js +2 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/jest/index.js +7 -5
- package/dist/plugins/vite/index.d.ts +5 -0
- package/dist/plugins/vite/index.js +5 -0
- package/dist/plugins/vitest/index.d.ts +1 -0
- package/dist/plugins/vitest/index.js +2 -1
- package/dist/typescript/createHosts.js +1 -5
- package/dist/util/compilers.d.ts +10 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workspace-worker.d.ts +1 -1
- package/package.json +1 -1
- package/schema.json +4 -0
package/README.md
CHANGED
|
@@ -335,6 +335,7 @@ Knip contains a growing list of plugins:
|
|
|
335
335
|
- [Tailwind][plugin-tailwind]
|
|
336
336
|
- [TypeDoc][plugin-typedoc]
|
|
337
337
|
- [TypeScript][plugin-typescript]
|
|
338
|
+
- [Vite][plugin-vite]
|
|
338
339
|
- [Vitest][plugin-vitest]
|
|
339
340
|
- [Webpack][plugin-webpack]
|
|
340
341
|
|
|
@@ -702,5 +703,6 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
|
|
|
702
703
|
[plugin-tailwind]: ./src/plugins/tailwind
|
|
703
704
|
[plugin-typedoc]: ./src/plugins/typedoc
|
|
704
705
|
[plugin-typescript]: ./src/plugins/typescript
|
|
706
|
+
[plugin-vite]: ./src/plugins/vite
|
|
705
707
|
[plugin-vitest]: ./src/plugins/vitest
|
|
706
708
|
[plugin-webpack]: ./src/plugins/webpack
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import './util/register.js';
|
|
|
3
3
|
import prettyMilliseconds from 'pretty-ms';
|
|
4
4
|
import reporters from './reporters/index.js';
|
|
5
5
|
import parsedArgs, { helpText } from './util/cli-arguments.js';
|
|
6
|
-
import { ConfigurationError } from './util/errors.js';
|
|
6
|
+
import { ConfigurationError, LoaderError } from './util/errors.js';
|
|
7
7
|
import { _load } from './util/loader.js';
|
|
8
8
|
import { cwd, resolve } from './util/path.js';
|
|
9
9
|
import { Performance } from './util/performance.js';
|
|
@@ -51,6 +51,12 @@ const run = async () => {
|
|
|
51
51
|
console.log(helpText);
|
|
52
52
|
process.exit(1);
|
|
53
53
|
}
|
|
54
|
+
else if (error instanceof LoaderError) {
|
|
55
|
+
console.error(error.message);
|
|
56
|
+
if (error.cause instanceof Error)
|
|
57
|
+
console.error('Reason:', error.cause.message);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
54
60
|
throw error;
|
|
55
61
|
}
|
|
56
62
|
};
|
|
@@ -474,6 +474,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
474
474
|
entry?: string | string[] | undefined;
|
|
475
475
|
project?: string | string[] | undefined;
|
|
476
476
|
}>]>>;
|
|
477
|
+
vite: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
478
|
+
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
479
|
+
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
480
|
+
project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
481
|
+
}, "strip", z.ZodTypeAny, {
|
|
482
|
+
config?: string | string[] | undefined;
|
|
483
|
+
entry?: string | string[] | undefined;
|
|
484
|
+
project?: string | string[] | undefined;
|
|
485
|
+
}, {
|
|
486
|
+
config?: string | string[] | undefined;
|
|
487
|
+
entry?: string | string[] | undefined;
|
|
488
|
+
project?: string | string[] | undefined;
|
|
489
|
+
}>]>>;
|
|
477
490
|
vitest: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
478
491
|
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
479
492
|
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
@@ -682,6 +695,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
682
695
|
entry?: string | string[] | undefined;
|
|
683
696
|
project?: string | string[] | undefined;
|
|
684
697
|
} | undefined;
|
|
698
|
+
vite?: string | false | string[] | {
|
|
699
|
+
config?: string | string[] | undefined;
|
|
700
|
+
entry?: string | string[] | undefined;
|
|
701
|
+
project?: string | string[] | undefined;
|
|
702
|
+
} | undefined;
|
|
685
703
|
vitest?: string | false | string[] | {
|
|
686
704
|
config?: string | string[] | undefined;
|
|
687
705
|
entry?: string | string[] | undefined;
|
|
@@ -874,6 +892,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
874
892
|
entry?: string | string[] | undefined;
|
|
875
893
|
project?: string | string[] | undefined;
|
|
876
894
|
} | undefined;
|
|
895
|
+
vite?: string | false | string[] | {
|
|
896
|
+
config?: string | string[] | undefined;
|
|
897
|
+
entry?: string | string[] | undefined;
|
|
898
|
+
project?: string | string[] | undefined;
|
|
899
|
+
} | undefined;
|
|
877
900
|
vitest?: string | false | string[] | {
|
|
878
901
|
config?: string | string[] | undefined;
|
|
879
902
|
entry?: string | string[] | undefined;
|
|
@@ -1340,6 +1363,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1340
1363
|
entry?: string | string[] | undefined;
|
|
1341
1364
|
project?: string | string[] | undefined;
|
|
1342
1365
|
}>]>>;
|
|
1366
|
+
vite: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
1367
|
+
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1368
|
+
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1369
|
+
project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1370
|
+
}, "strip", z.ZodTypeAny, {
|
|
1371
|
+
config?: string | string[] | undefined;
|
|
1372
|
+
entry?: string | string[] | undefined;
|
|
1373
|
+
project?: string | string[] | undefined;
|
|
1374
|
+
}, {
|
|
1375
|
+
config?: string | string[] | undefined;
|
|
1376
|
+
entry?: string | string[] | undefined;
|
|
1377
|
+
project?: string | string[] | undefined;
|
|
1378
|
+
}>]>>;
|
|
1343
1379
|
vitest: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<false>, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
1344
1380
|
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1345
1381
|
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
@@ -1561,6 +1597,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1561
1597
|
entry?: string | string[] | undefined;
|
|
1562
1598
|
project?: string | string[] | undefined;
|
|
1563
1599
|
} | undefined;
|
|
1600
|
+
vite?: string | false | string[] | {
|
|
1601
|
+
config?: string | string[] | undefined;
|
|
1602
|
+
entry?: string | string[] | undefined;
|
|
1603
|
+
project?: string | string[] | undefined;
|
|
1604
|
+
} | undefined;
|
|
1564
1605
|
vitest?: string | false | string[] | {
|
|
1565
1606
|
config?: string | string[] | undefined;
|
|
1566
1607
|
entry?: string | string[] | undefined;
|
|
@@ -1747,6 +1788,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1747
1788
|
entry?: string | string[] | undefined;
|
|
1748
1789
|
project?: string | string[] | undefined;
|
|
1749
1790
|
} | undefined;
|
|
1791
|
+
vite?: string | false | string[] | {
|
|
1792
|
+
config?: string | string[] | undefined;
|
|
1793
|
+
entry?: string | string[] | undefined;
|
|
1794
|
+
project?: string | string[] | undefined;
|
|
1795
|
+
} | undefined;
|
|
1750
1796
|
vitest?: string | false | string[] | {
|
|
1751
1797
|
config?: string | string[] | undefined;
|
|
1752
1798
|
entry?: string | string[] | undefined;
|
|
@@ -1952,6 +1998,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1952
1998
|
entry?: string | string[] | undefined;
|
|
1953
1999
|
project?: string | string[] | undefined;
|
|
1954
2000
|
} | undefined;
|
|
2001
|
+
vite?: string | false | string[] | {
|
|
2002
|
+
config?: string | string[] | undefined;
|
|
2003
|
+
entry?: string | string[] | undefined;
|
|
2004
|
+
project?: string | string[] | undefined;
|
|
2005
|
+
} | undefined;
|
|
1955
2006
|
vitest?: string | false | string[] | {
|
|
1956
2007
|
config?: string | string[] | undefined;
|
|
1957
2008
|
entry?: string | string[] | undefined;
|
|
@@ -2138,6 +2189,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
2138
2189
|
entry?: string | string[] | undefined;
|
|
2139
2190
|
project?: string | string[] | undefined;
|
|
2140
2191
|
} | undefined;
|
|
2192
|
+
vite?: string | false | string[] | {
|
|
2193
|
+
config?: string | string[] | undefined;
|
|
2194
|
+
entry?: string | string[] | undefined;
|
|
2195
|
+
project?: string | string[] | undefined;
|
|
2196
|
+
} | undefined;
|
|
2141
2197
|
vitest?: string | false | string[] | {
|
|
2142
2198
|
config?: string | string[] | undefined;
|
|
2143
2199
|
entry?: string | string[] | undefined;
|
|
@@ -3,7 +3,8 @@ import { hasDependency } from '../../util/plugin.js';
|
|
|
3
3
|
import { getDependenciesDeep } from './helpers.js';
|
|
4
4
|
export const NAME = 'ESLint';
|
|
5
5
|
export const ENABLERS = ['eslint'];
|
|
6
|
-
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS)
|
|
6
|
+
export const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, ENABLERS) ||
|
|
7
|
+
Boolean(manifest.name && /(^eslint-config|\/eslint-config)/.test(manifest.name));
|
|
7
8
|
export const CONFIG_FILE_PATTERNS = ['.eslintrc', '.eslintrc.{js,json,cjs}', '.eslintrc.{yml,yaml}', 'package.json'];
|
|
8
9
|
export const ENTRY_FILE_PATTERNS = ['eslint.config.js'];
|
|
9
10
|
const findESLintDependencies = async (configFilePath, { cwd, manifest }) => {
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -34,5 +34,6 @@ export * as svelte from './svelte/index.js';
|
|
|
34
34
|
export * as tailwind from './tailwind/index.js';
|
|
35
35
|
export * as typedoc from './typedoc/index.js';
|
|
36
36
|
export * as typescript from './typescript/index.js';
|
|
37
|
+
export * as vite from './vite/index.js';
|
|
37
38
|
export * as vitest from './vitest/index.js';
|
|
38
39
|
export * as webpack from './webpack/index.js';
|
package/dist/plugins/index.js
CHANGED
|
@@ -34,5 +34,6 @@ export * as svelte from './svelte/index.js';
|
|
|
34
34
|
export * as tailwind from './tailwind/index.js';
|
|
35
35
|
export * as typedoc from './typedoc/index.js';
|
|
36
36
|
export * as typescript from './typescript/index.js';
|
|
37
|
+
export * as vite from './vite/index.js';
|
|
37
38
|
export * as vitest from './vitest/index.js';
|
|
38
39
|
export * as webpack from './webpack/index.js';
|
|
@@ -3,8 +3,8 @@ import { timerify } from '../../util/performance.js';
|
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
export const NAME = 'Jest';
|
|
5
5
|
export const ENABLERS = ['jest'];
|
|
6
|
-
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
7
|
-
export const CONFIG_FILE_PATTERNS = ['jest.config.{js,ts,mjs,cjs,json}'];
|
|
6
|
+
export const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, ENABLERS) || Boolean(manifest.name?.startsWith('jest-presets'));
|
|
7
|
+
export const CONFIG_FILE_PATTERNS = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json'];
|
|
8
8
|
const maybeJoin = (base, id) => (isAbsolute(id) ? id : join(dirname(base), id));
|
|
9
9
|
const resolveExtensibleConfig = async (configFilePath) => {
|
|
10
10
|
const config = await load(configFilePath);
|
|
@@ -18,12 +18,14 @@ const resolveExtensibleConfig = async (configFilePath) => {
|
|
|
18
18
|
}
|
|
19
19
|
return config;
|
|
20
20
|
};
|
|
21
|
-
const findJestDependencies = async (configFilePath, { cwd }) => {
|
|
22
|
-
const config =
|
|
21
|
+
const findJestDependencies = async (configFilePath, { cwd, manifest }) => {
|
|
22
|
+
const config = configFilePath.endsWith('package.json')
|
|
23
|
+
? manifest.jest
|
|
24
|
+
: await resolveExtensibleConfig(configFilePath);
|
|
23
25
|
if (!config)
|
|
24
26
|
return [];
|
|
25
27
|
const replaceRootDir = (name) => name.includes('<rootDir>') ? join(cwd, name.replace(/^.*<rootDir>/, '')) : name;
|
|
26
|
-
const presets = config.preset ? [config.preset] : [];
|
|
28
|
+
const presets = (config.preset ? [config.preset] : []).map(preset => isInternal(preset) ? preset : join(preset, 'jest-preset'));
|
|
27
29
|
const environments = config.testEnvironment === 'jsdom' ? ['jest-environment-jsdom'] : [];
|
|
28
30
|
const resolvers = config.resolver ? [config.resolver] : [];
|
|
29
31
|
const watchPlugins = config.watchPlugins?.map(watchPlugin => (typeof watchPlugin === 'string' ? watchPlugin : watchPlugin[0])) ?? [];
|
|
@@ -2,5 +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[];
|
|
5
6
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
7
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -5,7 +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
|
|
8
|
+
export const ENTRY_FILE_PATTERNS = ['vite.config.ts'];
|
|
9
|
+
export const CONFIG_FILE_PATTERNS = ['vitest.config.ts'];
|
|
9
10
|
const findVitestDependencies = async (configFilePath) => {
|
|
10
11
|
const config = await load(configFilePath);
|
|
11
12
|
if (!config || !config.test)
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
1
|
import { EOL } from 'node:os';
|
|
3
2
|
import path from 'node:path';
|
|
4
|
-
import { pathToFileURL } from 'node:url';
|
|
5
3
|
import ts from 'typescript';
|
|
6
4
|
import { createCustomModuleResolver } from './resolveModuleNames.js';
|
|
7
5
|
import { SourceFileManager } from './SourceFileManager.js';
|
|
8
6
|
import { createCustomSys } from './sys.js';
|
|
9
|
-
const
|
|
10
|
-
const require = createRequire(pathToFileURL(import.meta.url));
|
|
11
|
-
const libLocation = path.dirname(require.resolve('typescript', { paths: [cwd] }));
|
|
7
|
+
const libLocation = path.dirname(ts.getDefaultLibFilePath({}));
|
|
12
8
|
const fileManager = new SourceFileManager();
|
|
13
9
|
export const createHosts = ({ cwd, compilerOptions, entryPaths, compilers }) => {
|
|
14
10
|
fileManager.installCompilers(compilers);
|
package/dist/util/compilers.d.ts
CHANGED
|
@@ -194,6 +194,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
194
194
|
entry?: string | string[] | undefined;
|
|
195
195
|
project?: string | string[] | undefined;
|
|
196
196
|
} | undefined;
|
|
197
|
+
vite?: string | false | string[] | {
|
|
198
|
+
config?: string | string[] | undefined;
|
|
199
|
+
entry?: string | string[] | undefined;
|
|
200
|
+
project?: string | string[] | undefined;
|
|
201
|
+
} | undefined;
|
|
197
202
|
vitest?: string | false | string[] | {
|
|
198
203
|
config?: string | string[] | undefined;
|
|
199
204
|
entry?: string | string[] | undefined;
|
|
@@ -380,6 +385,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
380
385
|
entry?: string | string[] | undefined;
|
|
381
386
|
project?: string | string[] | undefined;
|
|
382
387
|
} | undefined;
|
|
388
|
+
vite?: string | false | string[] | {
|
|
389
|
+
config?: string | string[] | undefined;
|
|
390
|
+
entry?: string | string[] | undefined;
|
|
391
|
+
project?: string | string[] | undefined;
|
|
392
|
+
} | undefined;
|
|
383
393
|
vitest?: string | false | string[] | {
|
|
384
394
|
config?: string | string[] | undefined;
|
|
385
395
|
entry?: string | string[] | undefined;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.1.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.1.0';
|
|
@@ -50,7 +50,7 @@ export declare class WorkspaceWorker {
|
|
|
50
50
|
peerDependencies: PeerDependencies;
|
|
51
51
|
installedBinaries: InstalledBinaries;
|
|
52
52
|
referencedDependencies: ReferencedDependencies;
|
|
53
|
-
enabledPlugins: ("typescript" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "tailwind" | "typedoc" | "vitest" | "webpack" | "githubActions" | "lintStaged" | "npmPackageJsonLint" | "releaseIt" | "semanticRelease" | "svelte")[];
|
|
53
|
+
enabledPlugins: ("typescript" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "tailwind" | "typedoc" | "vite" | "vitest" | "webpack" | "githubActions" | "lintStaged" | "npmPackageJsonLint" | "releaseIt" | "semanticRelease" | "svelte")[];
|
|
54
54
|
}>;
|
|
55
55
|
}
|
|
56
56
|
export {};
|
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -320,6 +320,10 @@
|
|
|
320
320
|
"title": "TypeScript plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/typescript/README.md)",
|
|
321
321
|
"$ref": "#/definitions/plugin"
|
|
322
322
|
},
|
|
323
|
+
"vite": {
|
|
324
|
+
"title": "vite plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/vite/README.md)",
|
|
325
|
+
"$ref": "#/definitions/plugin"
|
|
326
|
+
},
|
|
323
327
|
"vitest": {
|
|
324
328
|
"title": "vitest plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/vitest/README.md)",
|
|
325
329
|
"$ref": "#/definitions/plugin"
|