knip 5.29.0 → 5.29.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.
@@ -2775,9 +2775,9 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
2775
2775
  ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
2776
2776
  ignoreWorkspaces?: string[] | undefined;
2777
2777
  includeEntryExports?: boolean | undefined;
2778
- compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
2779
- syncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => string> | undefined;
2780
- asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>> | undefined;
2778
+ compilers?: Record<string, ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
2779
+ syncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => string> | undefined;
2780
+ asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => Promise<string>> | undefined;
2781
2781
  astro?: string | boolean | string[] | {
2782
2782
  config?: string | string[] | undefined;
2783
2783
  entry?: string | string[] | undefined;
@@ -3552,9 +3552,9 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
3552
3552
  ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
3553
3553
  ignoreWorkspaces?: string[] | undefined;
3554
3554
  includeEntryExports?: boolean | undefined;
3555
- compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
3556
- syncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => string> | undefined;
3557
- asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>> | undefined;
3555
+ compilers?: Record<string, ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
3556
+ syncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => string> | undefined;
3557
+ asyncCompilers?: Record<string, (args_0: string, args_1: string, ...args: unknown[]) => Promise<string>> | undefined;
3558
3558
  astro?: string | boolean | string[] | {
3559
3559
  config?: string | string[] | undefined;
3560
3560
  entry?: string | string[] | undefined;
@@ -43,7 +43,8 @@ export declare class WorkspaceWorker {
43
43
  private determineEnabledPlugins;
44
44
  private getConfigForPlugin;
45
45
  getEntryFilePatterns(): string[];
46
- getProjectFilePatterns(testFilePatterns: string[]): string[];
46
+ getProjectFilePatterns(projectFilePatterns: string[]): string[];
47
+ getPluginEntryFilePatterns(patterns: string[]): string[];
47
48
  getPluginProjectFilePatterns(): string[];
48
49
  getPluginConfigPatterns(): string[];
49
50
  getProductionEntryFilePatterns(negatedTestFilePatterns: string[]): string[];
@@ -1,7 +1,7 @@
1
1
  import { CacheConsultant } from './CacheConsultant.js';
2
2
  import { plugins } from './plugins.js';
3
3
  import { debugLogArray, debugLogObject } from './util/debug.js';
4
- import { _pureGlob, hasNoProductionSuffix, hasProductionSuffix, negate, prependDirToPattern } from './util/glob.js';
4
+ import { _glob, hasNoProductionSuffix, hasProductionSuffix, negate, prependDirToPattern } from './util/glob.js';
5
5
  import { get, getKeysByValue } from './util/object.js';
6
6
  import { basename, dirname, join, toPosix } from './util/path.js';
7
7
  import { getFinalEntryPaths, loadConfigForPlugin } from './util/plugin.js';
@@ -74,7 +74,7 @@ export class WorkspaceWorker {
74
74
  const excludeProductionNegations = entry.filter(pattern => !(pattern.startsWith('!') && pattern.endsWith('!')));
75
75
  return [excludeProductionNegations, this.negatedWorkspacePatterns].flat();
76
76
  }
77
- getProjectFilePatterns(testFilePatterns) {
77
+ getProjectFilePatterns(projectFilePatterns) {
78
78
  const { project } = this.config;
79
79
  if (project.length === 0)
80
80
  return [];
@@ -85,10 +85,13 @@ export class WorkspaceWorker {
85
85
  excludeProductionNegations,
86
86
  negatedPluginConfigPatterns,
87
87
  negatedPluginProjectFilePatterns,
88
- testFilePatterns,
88
+ projectFilePatterns,
89
89
  this.negatedWorkspacePatterns,
90
90
  ].flat();
91
91
  }
92
+ getPluginEntryFilePatterns(patterns) {
93
+ return [patterns, this.negatedWorkspacePatterns].flat();
94
+ }
92
95
  getPluginProjectFilePatterns() {
93
96
  const patterns = [];
94
97
  for (const [pluginName, plugin] of Object.entries(plugins)) {
@@ -175,7 +178,7 @@ export class WorkspaceWorker {
175
178
  if (!pluginConfig)
176
179
  continue;
177
180
  const patterns = this.getConfigurationFilePatterns(pluginName);
178
- const allConfigFilePaths = await _pureGlob({ patterns, cwd, gitignore: false });
181
+ const allConfigFilePaths = await _glob({ patterns, cwd: baseOptions.rootCwd, dir: cwd, gitignore: false });
179
182
  const { packageJsonPath } = plugin;
180
183
  const configFilePaths = allConfigFilePaths.filter(filePath => basename(filePath) !== 'package.json' ||
181
184
  (typeof packageJsonPath === 'function'
@@ -17,7 +17,7 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
17
17
  ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
18
18
  ignoreWorkspaces?: string[] | undefined;
19
19
  includeEntryExports?: boolean | undefined;
20
- compilers?: Record<string, ((args_0: string, args_1: string, ...args_2: unknown[]) => string) | ((args_0: string, args_1: string, ...args_2: unknown[]) => Promise<string>)> | undefined;
20
+ compilers?: Record<string, ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
21
21
  astro?: string | boolean | string[] | {
22
22
  config?: string | string[] | undefined;
23
23
  entry?: string | string[] | undefined;
package/dist/index.js CHANGED
@@ -111,7 +111,7 @@ export const main = async (unresolvedConfiguration) => {
111
111
  principal.addEntryPaths(definitionPaths);
112
112
  debugLogArray(name, 'Definition paths', definitionPaths);
113
113
  const ignore = worker.getIgnorePatterns();
114
- const sharedGlobOptions = { cwd, workingDir: dir, gitignore };
114
+ const sharedGlobOptions = { cwd, dir, gitignore };
115
115
  collector.addIgnorePatterns(ignore.map(pattern => join(cwd, pattern)));
116
116
  const options = { manifestScriptNames, cwd: dir, dependencies };
117
117
  const dependenciesFromManifest = _getDependenciesFromScripts(manifestScripts, options);
@@ -159,7 +159,7 @@ export const main = async (unresolvedConfiguration) => {
159
159
  principal.addProjectPath(projectPath);
160
160
  }
161
161
  {
162
- const patterns = [...entryFilePatterns, ...productionEntryFilePatterns];
162
+ const patterns = worker.getPluginEntryFilePatterns([...entryFilePatterns, ...productionEntryFilePatterns]);
163
163
  const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
164
164
  debugLogArray(name, 'Plugin entry paths', pluginWorkspaceEntryPaths);
165
165
  principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
@@ -13,7 +13,7 @@ const getDependencies = (config) => {
13
13
  ? getDependenciesFromConfig(config.parserOptions.babelOptions)
14
14
  : [];
15
15
  const settings = config.settings ? getDependenciesFromSettings(config.settings) : [];
16
- const rules = getDependenciesFromRules(config.rules);
16
+ const rules = getDependenciesFromRules({});
17
17
  const overrides = config.overrides ? [config.overrides].flat().flatMap(getDependencies) : [];
18
18
  return compact([...extendsSpecifiers, ...plugins, parser, ...babelDependencies, ...settings, ...rules, ...overrides]);
19
19
  };
@@ -5,6 +5,5 @@ declare const _default: {
5
5
  isEnabled: IsPluginEnabled;
6
6
  entry: string[];
7
7
  production: string[];
8
- project: string[];
9
8
  };
10
9
  export default _default;
@@ -7,14 +7,12 @@ const entry = ['svelte.config.js', ...viteConfig];
7
7
  const production = [
8
8
  'src/routes/**/+{page,server,page.server,error,layout,layout.server}{,@*}.{js,ts,svelte}',
9
9
  'src/hooks.{server,client}.{js,ts}',
10
- 'src/params/*{js,ts}',
10
+ 'src/params/*.{js,ts}',
11
11
  ];
12
- const project = ['src/**/*.{js,ts,svelte}'];
13
12
  export default {
14
13
  title,
15
14
  enablers,
16
15
  isEnabled,
17
16
  entry,
18
17
  production,
19
- project,
20
18
  };
@@ -2,7 +2,7 @@ import { hasDependency } from '#p/util/plugin.js';
2
2
  const title = 'WebdriverIO';
3
3
  const enablers = ['@wdio/cli'];
4
4
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
- const config = ['wdio.conf.js'];
5
+ const config = ['wdio.conf.{js,ts}'];
6
6
  const resolveConfig = async (config) => {
7
7
  const cfg = config?.config;
8
8
  if (!cfg)
@@ -8,8 +8,8 @@ export default visit(() => true, (node, { isFixExports, isFixTypes }) => {
8
8
  const sourceFile = node.getSourceFile();
9
9
  const declarations = sourceFile.getNamedDeclarations?.();
10
10
  return node.exportClause.elements.map(element => {
11
- const identifier = String(element.name.escapedText);
12
- const propName = element.propertyName?.escapedText;
11
+ const identifier = String(element.name.text);
12
+ const propName = element.propertyName?.text;
13
13
  const symbol = declarations?.get(propName ?? identifier)?.[0]?.symbol;
14
14
  const pos = element.name.pos;
15
15
  const fix = isFixExports || isFixTypes ? [element.getStart(), element.getEnd()] : undefined;
@@ -10,7 +10,7 @@ export default visit(() => true, node => {
10
10
  if (node.exportClause.kind === ts.SyntaxKind.NamespaceExport) {
11
11
  return {
12
12
  identifier: IMPORT_STAR,
13
- namespace: String(node.exportClause.name.escapedText),
13
+ namespace: String(node.exportClause.name.text),
14
14
  specifier: node.moduleSpecifier.text,
15
15
  isReExport: true,
16
16
  pos: node.exportClause.name.pos,
@@ -20,8 +20,8 @@ export default visit(() => true, node => {
20
20
  return node.exportClause.elements.map(element => {
21
21
  if (element.propertyName && element.name) {
22
22
  return {
23
- identifier: String(element.propertyName.escapedText),
24
- alias: String(element.name.escapedText),
23
+ identifier: String(element.propertyName.text),
24
+ alias: String(element.name.text),
25
25
  specifier: specifier.text,
26
26
  isReExport: true,
27
27
  pos: element.pos,
@@ -1,17 +1,14 @@
1
- export declare const prependDirToPattern: (workingDir: string, pattern: string) => string;
2
- export declare const negate: (pattern: string) => string;
3
- export declare const hasProductionSuffix: (pattern: string) => boolean;
4
- export declare const hasNoProductionSuffix: (pattern: string) => boolean;
5
- interface BaseGlobOptions {
1
+ interface GlobOptions {
6
2
  cwd: string;
3
+ dir?: string;
7
4
  patterns: string[];
8
5
  gitignore?: boolean;
9
6
  }
10
- interface GlobOptions extends BaseGlobOptions {
11
- workingDir?: string;
12
- }
13
- export declare const _glob: ({ cwd, workingDir, patterns, gitignore }: GlobOptions) => Promise<string[]>;
14
- export declare const _pureGlob: ({ cwd, patterns, gitignore }: BaseGlobOptions) => Promise<string[]>;
15
- export declare const _firstGlob: ({ cwd, patterns }: BaseGlobOptions) => Promise<string | Buffer | undefined>;
16
- export declare const _dirGlob: ({ cwd, patterns, gitignore }: BaseGlobOptions) => Promise<string[]>;
7
+ export declare const prependDirToPattern: (dir: string, pattern: string) => string;
8
+ export declare const negate: (pattern: string) => string;
9
+ export declare const hasProductionSuffix: (pattern: string) => boolean;
10
+ export declare const hasNoProductionSuffix: (pattern: string) => boolean;
11
+ export declare const _glob: ({ cwd, dir, patterns, gitignore }: GlobOptions) => Promise<string[]>;
12
+ export declare const _firstGlob: ({ cwd, patterns }: GlobOptions) => Promise<string | Buffer | undefined>;
13
+ export declare const _dirGlob: ({ cwd, patterns, gitignore }: GlobOptions) => Promise<string[]>;
17
14
  export {};
package/dist/util/glob.js CHANGED
@@ -4,42 +4,35 @@ import { timerify } from './Performance.js';
4
4
  import { compact } from './array.js';
5
5
  import { globby } from './globby.js';
6
6
  import { join, relative } from './path.js';
7
- export const prependDirToPattern = (workingDir, pattern) => {
7
+ const prependDirToPatterns = (cwd, dir, patterns) => {
8
+ const relativePath = relative(cwd, dir);
9
+ const prepend = (pattern) => prependDirToPattern(relativePath, pattern);
10
+ return compact([patterns].flat().map(prepend).map(removeProductionSuffix)).sort(negatedLast);
11
+ };
12
+ const removeProductionSuffix = (pattern) => pattern.replace(/!$/, '');
13
+ const negatedLast = (pattern) => (pattern.startsWith('!') ? 1 : -1);
14
+ export const prependDirToPattern = (dir, pattern) => {
8
15
  if (pattern.startsWith('!'))
9
- return `!${join(workingDir, pattern.slice(1))}`;
10
- return join(workingDir, pattern);
16
+ return `!${join(dir, pattern.slice(1))}`;
17
+ return join(dir, pattern);
11
18
  };
12
19
  export const negate = (pattern) => pattern.replace(/^!?/, '!');
13
20
  export const hasProductionSuffix = (pattern) => pattern.endsWith('!');
14
21
  export const hasNoProductionSuffix = (pattern) => !pattern.endsWith('!');
15
- const removeProductionSuffix = (pattern) => pattern.replace(/!$/, '');
16
- const negatedLast = (pattern) => (pattern.startsWith('!') ? 1 : -1);
17
- const glob = async ({ cwd, workingDir = cwd, patterns, gitignore = true }) => {
22
+ const glob = async ({ cwd, dir = cwd, patterns, gitignore = true }) => {
18
23
  if (patterns.length === 0)
19
24
  return [];
20
- const relativePath = relative(cwd, workingDir);
21
- const prepend = (pattern) => prependDirToPattern(relativePath, pattern);
22
- const globPatterns = compact([patterns].flat().map(prepend).map(removeProductionSuffix)).sort(negatedLast);
25
+ const globPatterns = prependDirToPatterns(cwd, dir, patterns);
23
26
  if (globPatterns[0].startsWith('!'))
24
27
  return [];
25
28
  return globby(globPatterns, {
26
29
  cwd,
27
- dir: workingDir,
30
+ dir,
28
31
  gitignore,
29
32
  absolute: true,
30
33
  dot: true,
31
34
  });
32
35
  };
33
- const pureGlob = async ({ cwd, patterns, gitignore = true }) => {
34
- if (patterns.length === 0)
35
- return [];
36
- return globby(patterns, {
37
- cwd,
38
- dir: cwd,
39
- gitignore,
40
- absolute: true,
41
- });
42
- };
43
36
  const firstGlob = async ({ cwd, patterns }) => {
44
37
  const stream = fg.globStream(patterns.map(removeProductionSuffix), { cwd, ignore: GLOBAL_IGNORE_PATTERNS });
45
38
  for await (const entry of stream) {
@@ -53,6 +46,5 @@ const dirGlob = async ({ cwd, patterns, gitignore = true }) => globby(patterns,
53
46
  gitignore,
54
47
  });
55
48
  export const _glob = timerify(glob);
56
- export const _pureGlob = timerify(pureGlob);
57
49
  export const _firstGlob = timerify(firstGlob);
58
50
  export const _dirGlob = timerify(dirGlob);
@@ -125,7 +125,7 @@ export async function globby(patterns, options) {
125
125
  ignore.push(...i.ignores);
126
126
  }
127
127
  const { dir, ...fastGlobOptions } = { ...options, ignore };
128
- debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, 'Glob options', { patterns, ...options });
128
+ debugLogObject(relative(options.cwd, options.dir) || ROOT_WORKSPACE_NAME, 'Glob options', { patterns, ...options });
129
129
  return fg.glob(patterns, fastGlobOptions);
130
130
  }
131
131
  export async function getGitIgnoredHandler(options) {
@@ -7,7 +7,7 @@ export declare const getDefinitelyTypedFor: (packageName: string) => string;
7
7
  export declare const getPackageFromDefinitelyTyped: (typedDependency: string) => string;
8
8
  export declare const getEntryPathsFromManifest: (manifest: PackageJson, sharedGlobOptions: {
9
9
  cwd: string;
10
- workingDir: string;
10
+ dir: string;
11
11
  gitignore: boolean;
12
12
  ignore: string[];
13
13
  }) => Promise<string[]>;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.29.0";
1
+ export declare const version = "5.29.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.29.0';
1
+ export const version = '5.29.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.29.0",
3
+ "version": "5.29.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {