knip 2.35.0 → 2.36.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.
@@ -1,7 +1,8 @@
1
+ /// <reference types="npmcli__package-json" />
1
2
  import { createPkgGraph } from '@pnpm/workspace.pkgs-graph';
2
3
  import type { SyncCompilers, AsyncCompilers } from './types/compilers.js';
3
4
  import type { Configuration, WorkspaceConfiguration } from './types/config.js';
4
- import type { PackageJsonWithPlugins } from './types/plugins.js';
5
+ import type { PackageJson } from '@npmcli/package-json';
5
6
  type ConfigurationManagerOptions = {
6
7
  cwd: string;
7
8
  isProduction: boolean;
@@ -13,14 +14,14 @@ export type Workspace = {
13
14
  ancestors: string[];
14
15
  config: WorkspaceConfiguration;
15
16
  manifestPath: string;
16
- manifest: PackageJsonWithPlugins;
17
+ manifest: PackageJson;
17
18
  };
18
19
  export declare class ConfigurationChief {
19
20
  cwd: string;
20
21
  isProduction: boolean;
21
22
  config: Configuration;
22
23
  manifestPath?: string;
23
- manifest?: PackageJsonWithPlugins;
24
+ manifest?: PackageJson;
24
25
  ignoredWorkspacePatterns: string[];
25
26
  manifestWorkspaces: Map<string, string>;
26
27
  additionalWorkspaceNames: Set<string>;
@@ -29,7 +30,7 @@ export declare class ConfigurationChief {
29
30
  availableWorkspaceDirs: string[];
30
31
  availableWorkspaceManifests: {
31
32
  dir: string;
32
- manifest: PackageJsonWithPlugins;
33
+ manifest: PackageJson;
33
34
  }[];
34
35
  workspacesGraph: ReturnType<typeof createPkgGraph> | undefined;
35
36
  enabledWorkspaces: Workspace[];
@@ -1,5 +1,5 @@
1
1
  import type { Configuration, PluginName, WorkspaceConfiguration } from './types/config.js';
2
- import type { PackageJsonWithPlugins } from './types/plugins.js';
2
+ import type { PackageJsonWithPlugins } from './types/package-json.js';
3
3
  import type { InstalledBinaries, HostDependencies } from './types/workspace.js';
4
4
  type WorkspaceManagerOptions = {
5
5
  name: string;
@@ -11,7 +11,8 @@ export const PROJECT_FILE_PATTERNS = [];
11
11
  const findPluginDependencies = async (configFilePath, options) => {
12
12
  const { manifest, config, isProduction } = options;
13
13
  const localConfig = configFilePath.endsWith('package.json')
14
- ? manifest.plugin
14
+ ?
15
+ manifest.plugin
15
16
  : await load(configFilePath);
16
17
  if (!localConfig)
17
18
  return [];
@@ -1,12 +1,7 @@
1
- /// <reference types="npmcli__package-json" />
2
- import type { ESLintConfig } from './types.js';
3
- import type { PackageJson } from '@npmcli/package-json';
4
- type Manifest = PackageJson & {
5
- eslintConfig?: ESLintConfig;
6
- };
1
+ import type { PackageJsonWithPlugins } from '../../types/package-json.js';
7
2
  type GetDependenciesDeep = (configFilePath: string, options: {
8
3
  cwd: string;
9
- manifest: Manifest;
4
+ manifest: PackageJsonWithPlugins;
10
5
  }, dependencies?: Set<string>) => Promise<Set<string>>;
11
6
  export declare const getDependenciesDeep: GetDependenciesDeep;
12
7
  export declare const resolvePluginSpecifier: (specifier: string) => string;
@@ -5,8 +5,8 @@ export const ENABLERS = ['prettier'];
5
5
  export const isEnabled = ({ dependencies, config }) => hasDependency(dependencies, ENABLERS) || 'prettier' in config;
6
6
  export const CONFIG_FILE_PATTERNS = [
7
7
  '.prettierrc',
8
- '.prettierrc.{json,js,cjs,yml,yaml}',
9
- 'prettier.config.{js,cjs}',
8
+ '.prettierrc.{json,js,cjs,mjs,yml,yaml}',
9
+ 'prettier.config.{js,cjs,mjs}',
10
10
  'package.json',
11
11
  ];
12
12
  const findPrettierDependencies = async (configFilePath, { manifest, isProduction }) => {
@@ -25,19 +25,19 @@ const resolveExtensibleConfig = async (configFilePath) => {
25
25
  };
26
26
  export const findTypeScriptDependencies = async (configFilePath, options) => {
27
27
  const { isProduction } = options;
28
- if (isProduction)
29
- return [];
30
28
  const { compilerOptions } = await loadTSConfig(configFilePath);
31
29
  const localConfig = await resolveExtensibleConfig(configFilePath);
32
30
  if (!compilerOptions || !localConfig)
33
31
  return [];
32
+ const jsx = compilerOptions?.jsxImportSource ? [compilerOptions.jsxImportSource] : [];
33
+ if (isProduction)
34
+ return [...jsx];
34
35
  const extend = localConfig.extends ? [localConfig.extends].flat().filter(extend => !isInternal(extend)) : [];
35
36
  const types = compilerOptions.types ?? [];
36
37
  const plugins = Array.isArray(compilerOptions?.plugins)
37
38
  ? compilerOptions.plugins.map(plugin => (typeof plugin === 'object' && 'name' in plugin ? plugin.name : ''))
38
39
  : [];
39
40
  const importHelpers = compilerOptions?.importHelpers ? ['tslib'] : [];
40
- const jsx = compilerOptions?.jsxImportSource ? [compilerOptions.jsxImportSource] : [];
41
41
  return compact([...extend, ...types, ...plugins, ...importHelpers, ...jsx]);
42
42
  };
43
43
  export const findDependencies = timerify(findTypeScriptDependencies);
@@ -1,6 +1,6 @@
1
1
  import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
- import { findVitestDeps } from '../vitest/index.js';
3
+ import { findVitestDependencies } from '../vitest/index.js';
4
4
  export const NAME = 'Vite';
5
5
  export const ENABLERS = ['vite'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
@@ -9,16 +9,6 @@ const findViteDependencies = async (configFilePath, options) => {
9
9
  const localConfig = await load(configFilePath);
10
10
  if (!localConfig)
11
11
  return [];
12
- if (typeof localConfig === 'function') {
13
- const dependencies = new Set();
14
- for (const command of ['dev', 'serve', 'build']) {
15
- for (const mode of ['development', 'production']) {
16
- const config = await localConfig({ command, mode, ssrBuild: undefined });
17
- findVitestDeps(config, options).forEach(dependency => dependencies.add(dependency));
18
- }
19
- }
20
- return Array.from(dependencies);
21
- }
22
- return findVitestDeps(localConfig, options);
12
+ return findVitestDependencies(localConfig, options);
23
13
  };
24
14
  export const findDependencies = timerify(findViteDependencies);
@@ -1,6 +1,6 @@
1
- import type { VitestConfig } from './types.js';
1
+ import type { ViteConfig } from './types.js';
2
2
  type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
3
3
  type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>);
4
4
  export declare const getEnvPackageName: (env: VitestEnvironment) => any;
5
- export declare const getExternalReporters: (reporters?: VitestConfig['test']['reporters']) => unknown[];
5
+ export declare const getExternalReporters: (reporters?: ViteConfig['test']['reporters']) => unknown[];
6
6
  export {};
@@ -1,9 +1,9 @@
1
- import type { VitestConfigOrFn } from './types.js';
1
+ import type { ViteConfigOrFn } from './types.js';
2
2
  import type { IsPluginEnabledCallback, GenericPluginCallback, GenericPluginCallbackOptions } from '../../types/plugins.js';
3
3
  export declare const NAME = "Vitest";
4
4
  export declare const ENABLERS: string[];
5
5
  export declare const isEnabled: IsPluginEnabledCallback;
6
6
  export declare const CONFIG_FILE_PATTERNS: string[];
7
7
  export declare const ENTRY_FILE_PATTERNS: string[];
8
- export declare const findVitestDeps: (localConfig: VitestConfigOrFn, options: GenericPluginCallbackOptions) => any[];
8
+ export declare const findVitestDependencies: (localConfig: ViteConfigOrFn, options: GenericPluginCallbackOptions) => Promise<any[]>;
9
9
  export declare const findDependencies: GenericPluginCallback;
@@ -1,4 +1,3 @@
1
- import { compact } from '../../util/array.js';
2
1
  import { timerify } from '../../util/Performance.js';
3
2
  import { hasDependency, load } from '../../util/plugin.js';
4
3
  import { toEntryPattern } from '../../util/protocols.js';
@@ -8,14 +7,11 @@ export const ENABLERS = ['vitest'];
8
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
9
8
  export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vitest.{workspace,projects}.{ts,js,json}'];
10
9
  export const ENTRY_FILE_PATTERNS = ['**/*.{test,spec}.?(c|m)[jt]s?(x)'];
11
- export const findVitestDeps = (localConfig, options) => {
12
- const { isProduction } = options;
13
- localConfig = typeof localConfig === 'function' ? localConfig() : localConfig;
14
- if (!localConfig || !localConfig.test)
15
- return [];
10
+ const findConfigDependencies = (localConfig, options) => {
11
+ const { isProduction, config } = options;
16
12
  const testConfig = localConfig.test;
17
- const entryPatterns = (options.config?.entry ?? testConfig.include ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
18
- if (isProduction)
13
+ const entryPatterns = (config?.entry ?? testConfig?.include ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
14
+ if (!testConfig || isProduction)
19
15
  return entryPatterns;
20
16
  const environments = testConfig.environment ? [getEnvPackageName(testConfig.environment)] : [];
21
17
  const reporters = getExternalReporters(testConfig.reporters);
@@ -24,10 +20,31 @@ export const findVitestDeps = (localConfig, options) => {
24
20
  const globalSetup = testConfig.globalSetup ? [testConfig.globalSetup].flat() : [];
25
21
  return [...entryPatterns, ...environments, ...reporters, ...coverage, ...setupFiles, ...globalSetup];
26
22
  };
27
- const findVitestDependencies = async (configFilePath, options) => {
23
+ export const findVitestDependencies = async (localConfig, options) => {
24
+ if (!localConfig)
25
+ return [];
26
+ if (typeof localConfig === 'function') {
27
+ const dependencies = new Set();
28
+ for (const command of ['dev', 'serve', 'build']) {
29
+ for (const mode of ['development', 'production']) {
30
+ const config = await localConfig({ command, mode, ssrBuild: undefined });
31
+ findConfigDependencies(config, options).forEach(dependency => dependencies.add(dependency));
32
+ }
33
+ }
34
+ return Array.from(dependencies);
35
+ }
36
+ if (!localConfig.test)
37
+ return [];
38
+ return findConfigDependencies(localConfig, options);
39
+ };
40
+ const findVitestWorkspaceDependencies = async (configFilePath, options) => {
28
41
  const localConfig = await load(configFilePath);
29
- return compact([localConfig]
30
- .flat()
31
- .flatMap(config => (!config || typeof config === 'string' ? [] : findVitestDeps(config, options))));
42
+ const dependencies = new Set();
43
+ for (const config of [localConfig].flat()) {
44
+ if (config && typeof config !== 'string') {
45
+ (await findVitestDependencies(config, options)).forEach(dependency => dependencies.add(dependency));
46
+ }
47
+ }
48
+ return Array.from(dependencies);
32
49
  };
33
- export const findDependencies = timerify(findVitestDependencies);
50
+ export const findDependencies = timerify(findVitestWorkspaceDependencies);
@@ -1,4 +1,4 @@
1
- export interface VitestConfig {
1
+ interface VitestConfig {
2
2
  test: {
3
3
  include: string[];
4
4
  coverage?: {
@@ -10,5 +10,16 @@ export interface VitestConfig {
10
10
  setupFiles?: string | string[];
11
11
  };
12
12
  }
13
- export type VitestConfigOrFn = VitestConfig | (() => VitestConfig);
14
- export type VitestWorkspaceConfig = (string | VitestConfig)[];
13
+ export interface ViteConfig extends VitestConfig {
14
+ plugins: unknown[];
15
+ }
16
+ export type COMMAND = 'dev' | 'serve' | 'build';
17
+ export type MODE = 'development' | 'production';
18
+ interface Options {
19
+ command: COMMAND;
20
+ mode: MODE;
21
+ ssrBuild?: boolean | undefined;
22
+ }
23
+ export type ViteConfigOrFn = ViteConfig | ((options: Options) => ViteConfig) | ((options: Options) => Promise<ViteConfig>);
24
+ export type VitestWorkspaceConfig = (string | ViteConfig)[];
25
+ export {};
@@ -7,6 +7,7 @@ export type RawConfiguration = z.infer<typeof ConfigurationValidator>;
7
7
  export type RawPluginConfiguration = z.infer<typeof pluginSchema>;
8
8
  type NormalizedGlob = string[];
9
9
  export type PluginName = keyof typeof Plugins;
10
+ export type PluginMap = typeof Plugins;
10
11
  export type EnsuredPluginConfiguration = {
11
12
  config: NormalizedGlob | null;
12
13
  entry: NormalizedGlob | null;
@@ -0,0 +1,41 @@
1
+ import type { PluginMap } from './config.js';
2
+ import type { LiteralUnion, MergeUnion } from './util.js';
3
+ type Dependency = Record<string, string>;
4
+ type ExportCondition = LiteralUnion<'import' | 'require' | 'node' | 'node-addons' | 'deno' | 'browser' | 'electron' | 'react-native' | 'default', string>;
5
+ type Exports = null | string | string[] | {
6
+ [key in ExportCondition]: Exports;
7
+ } | {
8
+ [key: string]: Exports;
9
+ };
10
+ type ExtractKeys<T, K extends string> = T extends {
11
+ PACKAGE_JSON_PATH: infer P;
12
+ } ? P extends `${infer First}.${infer Second}` ? {
13
+ [K1 in First]?: {
14
+ [K2 in Second]?: unknown;
15
+ };
16
+ } : {
17
+ [P in T['PACKAGE_JSON_PATH'] & string]?: unknown;
18
+ } : Record<K, unknown>;
19
+ type PluginKeys = {
20
+ [K in keyof PluginMap]: ExtractKeys<PluginMap[K], K>;
21
+ };
22
+ type Plugins = MergeUnion<PluginKeys[keyof PluginMap]>;
23
+ export type PackageJsonWithPlugins = {
24
+ name?: string;
25
+ main?: string;
26
+ bin?: string | Record<string, string>;
27
+ version?: string;
28
+ workspaces?: string[] | {
29
+ packages?: string[];
30
+ };
31
+ exports?: Exports;
32
+ scripts?: Record<string, string>;
33
+ dependencies?: Dependency;
34
+ devDependencies?: Dependency;
35
+ peerDependencies?: Dependency;
36
+ optionalDependencies?: Dependency;
37
+ peerDependenciesMeta?: Record<string, {
38
+ optional: true;
39
+ }>;
40
+ } & Plugins;
41
+ export {};
@@ -1,10 +1,8 @@
1
- /// <reference types="npmcli__package-json" />
2
1
  import type { EnsuredPluginConfiguration, WorkspaceConfiguration } from './config.js';
3
- import type { PackageJson } from '@npmcli/package-json';
4
- export type PackageJsonWithPlugins = PackageJson & Record<string, unknown>;
2
+ import type { PackageJsonWithPlugins } from './package-json.js';
5
3
  type IsPluginEnabledCallbackOptions = {
6
4
  cwd: string;
7
- manifest: PackageJson;
5
+ manifest: PackageJsonWithPlugins;
8
6
  dependencies: Set<string>;
9
7
  config: WorkspaceConfiguration;
10
8
  };
@@ -0,0 +1,16 @@
1
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
2
+ export type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
3
+ type CommonKeys<T extends object> = keyof T;
4
+ type AllKeys<T> = T extends unknown ? keyof T : never;
5
+ type Subtract<A, C> = A extends C ? never : A;
6
+ type NonCommonKeys<T extends object> = Subtract<AllKeys<T>, CommonKeys<T>>;
7
+ type PickType<T, K extends AllKeys<T>> = T extends {
8
+ [k in K]?: unknown;
9
+ } ? T[K] : undefined;
10
+ type PickTypeOf<T, K extends string | number | symbol> = K extends AllKeys<T> ? PickType<T, K> : never;
11
+ export type MergeUnion<T extends object> = {
12
+ [k in CommonKeys<T>]: PickTypeOf<T, k>;
13
+ } & {
14
+ [k in NonCommonKeys<T>]?: PickTypeOf<T, k>;
15
+ };
16
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.35.0";
1
+ export declare const version = "2.36.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.35.0';
1
+ export const version = '2.36.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.35.0",
3
+ "version": "2.36.0",
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",
@@ -46,7 +46,7 @@
46
46
  "@npmcli/map-workspaces": "^3.0.4",
47
47
  "@pkgjs/parseargs": "0.11.0",
48
48
  "@pnpm/logger": "5.0.0",
49
- "@pnpm/workspace.pkgs-graph": "2.0.7",
49
+ "@pnpm/workspace.pkgs-graph": "2.0.8",
50
50
  "@snyk/github-codeowners": "^1.1.0",
51
51
  "chalk": "^5.2.0",
52
52
  "easy-table": "^1.2.0",
@@ -61,26 +61,26 @@
61
61
  "summary": "^2.1.0",
62
62
  "typescript": "^5.0.2",
63
63
  "zod": "3.22.4",
64
- "zod-validation-error": "^1.5.0"
64
+ "zod-validation-error": "2.0.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@jest/types": "29.6.3",
68
68
  "@npmcli/package-json": "5.0.0",
69
69
  "@release-it/bumper": "5.1.0",
70
70
  "@swc/cli": "0.1.62",
71
- "@swc/core": "1.3.92",
72
- "@types/eslint": "8.44.4",
73
- "@types/js-yaml": "4.0.7",
74
- "@types/micromatch": "4.0.3",
75
- "@types/minimist": "1.2.3",
76
- "@types/node": "20.8.4",
77
- "@types/npmcli__map-workspaces": "3.0.2",
78
- "@types/pkgjs__parseargs": "0.10.1",
79
- "@types/webpack": "5.28.3",
80
- "@typescript-eslint/eslint-plugin": "6.7.5",
81
- "@typescript-eslint/parser": "6.7.5",
71
+ "@swc/core": "1.3.94",
72
+ "@types/eslint": "8.44.6",
73
+ "@types/js-yaml": "4.0.8",
74
+ "@types/micromatch": "4.0.4",
75
+ "@types/minimist": "1.2.4",
76
+ "@types/node": "20.8.7",
77
+ "@types/npmcli__map-workspaces": "3.0.3",
78
+ "@types/pkgjs__parseargs": "0.10.2",
79
+ "@types/webpack": "5.28.4",
80
+ "@typescript-eslint/eslint-plugin": "6.8.0",
81
+ "@typescript-eslint/parser": "6.8.0",
82
82
  "c8": "8.0.1",
83
- "eslint": "8.51.0",
83
+ "eslint": "8.52.0",
84
84
  "eslint-import-resolver-typescript": "3.6.1",
85
85
  "eslint-plugin-import": "2.28.1",
86
86
  "eslint-plugin-n": "16.2.0",
@@ -89,8 +89,8 @@
89
89
  "release-it": "16.2.1",
90
90
  "remark-cli": "12.0.0",
91
91
  "remark-preset-webpro": "1.0.0",
92
- "tsx": "3.13.0",
93
- "type-fest": "4.4.0"
92
+ "tsx": "3.14.0",
93
+ "type-fest": "4.5.0"
94
94
  },
95
95
  "engines": {
96
96
  "node": ">=16.17.0 <17 || >=18.6.0"
package/schema.json CHANGED
@@ -133,7 +133,7 @@
133
133
  }
134
134
  },
135
135
  "globPatterns": {
136
- "description": "Use file paths and glob patterns to match files. Knip uses fast-glob and and minimatch (https://github.com/micromatch/micromatch#matching-features)",
136
+ "description": "Use file paths and glob patterns to match files. Knip uses fast-glob and minimatch (https://github.com/micromatch/micromatch#matching-features)",
137
137
  "anyOf": [
138
138
  {
139
139
  "type": "string"
@@ -1,13 +0,0 @@
1
- import type { VitestConfig } from '../vitest/types.js';
2
- interface Config extends VitestConfig {
3
- plugins: unknown[];
4
- }
5
- export type COMMAND = 'dev' | 'serve' | 'build';
6
- export type MODE = 'development' | 'production';
7
- interface Options {
8
- command: COMMAND;
9
- mode: MODE;
10
- ssrBuild?: boolean | undefined;
11
- }
12
- export type ViteConfig = Config | ((options: Options) => Config) | ((options: Options) => Promise<Config>);
13
- export {};