knip 5.63.0 → 5.63.1

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.
Files changed (103) hide show
  1. package/dist/CacheConsultant.d.ts +3 -9
  2. package/dist/CacheConsultant.js +5 -5
  3. package/dist/ConfigurationChief.d.ts +585 -38
  4. package/dist/ConfigurationChief.js +33 -122
  5. package/dist/ConsoleStreamer.d.ts +2 -3
  6. package/dist/ConsoleStreamer.js +2 -2
  7. package/dist/DependencyDeputy.d.ts +2 -6
  8. package/dist/IssueCollector.d.ts +4 -12
  9. package/dist/IssueCollector.js +9 -9
  10. package/dist/IssueFixer.d.ts +3 -14
  11. package/dist/IssueFixer.js +11 -21
  12. package/dist/PrincipalFactory.d.ts +3 -2
  13. package/dist/PrincipalFactory.js +11 -11
  14. package/dist/ProjectPrincipal.d.ts +4 -3
  15. package/dist/ProjectPrincipal.js +8 -8
  16. package/dist/WorkspaceWorker.d.ts +4 -9
  17. package/dist/WorkspaceWorker.js +8 -12
  18. package/dist/binaries/bash-parser.js +1 -1
  19. package/dist/binaries/fallback.js +1 -1
  20. package/dist/binaries/package-manager/pnpm.js +6 -1
  21. package/dist/cli.js +43 -61
  22. package/dist/compilers/index.d.ts +14 -4
  23. package/dist/graph/analyze.d.ts +3 -8
  24. package/dist/graph/analyze.js +24 -27
  25. package/dist/graph/build.d.ts +3 -17
  26. package/dist/graph/build.js +42 -39
  27. package/dist/index.d.ts +3 -7
  28. package/dist/index.js +22 -62
  29. package/dist/plugins/index.d.ts +5 -0
  30. package/dist/plugins/index.js +2 -0
  31. package/dist/plugins/nuxt/index.js +4 -3
  32. package/dist/plugins/nuxt/types.d.ts +3 -2
  33. package/dist/plugins/pnpm/index.d.ts +7 -0
  34. package/dist/plugins/pnpm/index.js +8 -0
  35. package/dist/plugins/rsbuild/index.js +23 -6
  36. package/dist/plugins/rsbuild/types.d.ts +3 -0
  37. package/dist/plugins.js +3 -2
  38. package/dist/reporters/codeclimate.d.ts +1 -1
  39. package/dist/reporters/codeclimate.js +10 -10
  40. package/dist/reporters/codeowners.d.ts +1 -1
  41. package/dist/reporters/codeowners.js +5 -5
  42. package/dist/reporters/compact.d.ts +1 -1
  43. package/dist/reporters/compact.js +7 -7
  44. package/dist/reporters/disclosure.d.ts +1 -1
  45. package/dist/reporters/disclosure.js +2 -2
  46. package/dist/reporters/index.d.ts +6 -6
  47. package/dist/reporters/json.d.ts +1 -1
  48. package/dist/reporters/json.js +3 -3
  49. package/dist/reporters/markdown.d.ts +1 -1
  50. package/dist/reporters/markdown.js +4 -4
  51. package/dist/reporters/symbols.js +1 -1
  52. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  53. package/dist/reporters/util/configuration-hints.js +6 -7
  54. package/dist/reporters/util/util.d.ts +2 -2
  55. package/dist/reporters/util/util.js +4 -4
  56. package/dist/reporters/watch.d.ts +3 -4
  57. package/dist/reporters/watch.js +5 -5
  58. package/dist/schema/configuration.d.ts +64 -8
  59. package/dist/schema/plugins.d.ts +23 -0
  60. package/dist/schema/plugins.js +1 -0
  61. package/dist/types/PluginNames.d.ts +2 -2
  62. package/dist/types/PluginNames.js +1 -0
  63. package/dist/types/config.d.ts +4 -10
  64. package/dist/types/issues.d.ts +1 -2
  65. package/dist/types/{cli.d.ts → options.d.ts} +2 -2
  66. package/dist/types/package-json.d.ts +1 -0
  67. package/dist/types/project.d.ts +1 -7
  68. package/dist/typescript/get-imports-and-exports.d.ts +2 -2
  69. package/dist/typescript/get-imports-and-exports.js +9 -10
  70. package/dist/util/Performance.js +16 -6
  71. package/dist/util/cli-arguments.d.ts +1 -2
  72. package/dist/util/cli-arguments.js +3 -13
  73. package/dist/util/create-options.d.ts +1219 -0
  74. package/dist/util/create-options.js +112 -0
  75. package/dist/util/debug.js +3 -4
  76. package/dist/util/errors.d.ts +1 -1
  77. package/dist/util/file-entry-cache.js +3 -3
  78. package/dist/util/get-included-issue-types.d.ts +9 -13
  79. package/dist/util/get-included-issue-types.js +10 -16
  80. package/dist/util/get-referenced-inputs.js +1 -1
  81. package/dist/util/input.d.ts +1 -1
  82. package/dist/util/input.js +1 -1
  83. package/dist/util/is-identifier-referenced.d.ts +1 -1
  84. package/dist/util/is-identifier-referenced.js +2 -2
  85. package/dist/util/load-config.d.ts +1 -0
  86. package/dist/util/load-config.js +24 -0
  87. package/dist/util/path.d.ts +4 -4
  88. package/dist/util/path.js +5 -7
  89. package/dist/util/require.js +1 -2
  90. package/dist/util/tag.d.ts +1 -1
  91. package/dist/util/to-source-path.d.ts +1 -1
  92. package/dist/util/to-source-path.js +5 -5
  93. package/dist/util/trace.d.ts +6 -6
  94. package/dist/util/trace.js +18 -22
  95. package/dist/util/watch.d.ts +2 -5
  96. package/dist/util/watch.js +3 -3
  97. package/dist/version.d.ts +1 -1
  98. package/dist/version.js +1 -1
  99. package/package.json +2 -2
  100. package/schema.json +4 -0
  101. package/dist/util/unwrap-function.d.ts +0 -1
  102. package/dist/util/unwrap-function.js +0 -13
  103. /package/dist/types/{cli.js → options.js} +0 -0
@@ -4,33 +4,19 @@ import type { DependencyDeputy } from '../DependencyDeputy.js';
4
4
  import type { IssueCollector } from '../IssueCollector.js';
5
5
  import type { PrincipalFactory } from '../PrincipalFactory.js';
6
6
  import type { ProjectPrincipal } from '../ProjectPrincipal.js';
7
- import type { Tags } from '../types/cli.js';
8
- import type { Report } from '../types/issues.js';
9
7
  import type { ModuleGraph } from '../types/module-graph.js';
8
+ import type { MainOptions } from '../util/create-options.js';
10
9
  interface BuildOptions {
11
- cacheLocation: string;
12
10
  chief: ConfigurationChief;
13
11
  collector: IssueCollector;
14
- cwd: string;
15
12
  deputy: DependencyDeputy;
16
13
  factory: PrincipalFactory;
17
- gitignore: boolean;
18
- isCache: boolean;
19
- isFixExports: boolean;
20
- isFixTypes: boolean;
21
14
  isGitIgnored: (path: string) => boolean;
22
- isIsolateWorkspaces: boolean;
23
- isProduction: boolean;
24
- isSkipLibs: boolean;
25
- isStrict: boolean;
26
- isWatch: boolean;
27
- report: Report;
28
15
  streamer: ConsoleStreamer;
29
- tags: Tags;
30
- tsConfigFile?: string;
31
16
  workspaces: Workspace[];
17
+ options: MainOptions;
32
18
  }
33
- export declare function build({ cacheLocation, chief, collector, cwd, deputy, factory, gitignore, isCache, isFixExports, isFixTypes, isGitIgnored, isIsolateWorkspaces, isProduction, isSkipLibs, isStrict, isWatch, report, streamer, tags, tsConfigFile, workspaces, }: BuildOptions): Promise<{
19
+ export declare function build({ chief, collector, deputy, factory, isGitIgnored, streamer, workspaces, options, }: BuildOptions): Promise<{
34
20
  graph: ModuleGraph;
35
21
  entryPaths: Set<string>;
36
22
  analyzedFiles: Set<string>;
@@ -13,19 +13,26 @@ import { getPackageNameFromModuleSpecifier, isStartsLikePackageName, sanitizeSpe
13
13
  import { getEntrySpecifiersFromManifest, getManifestImportDependencies } from '../util/package-json.js';
14
14
  import { dirname, extname, isAbsolute, join, relative, toRelative } from '../util/path.js';
15
15
  import { augmentWorkspace, getToSourcePathHandler, getToSourcePathsHandler } from '../util/to-source-path.js';
16
- export async function build({ cacheLocation, chief, collector, cwd, deputy, factory, gitignore, isCache, isFixExports, isFixTypes, isGitIgnored, isIsolateWorkspaces, isProduction, isSkipLibs, isStrict, isWatch, report, streamer, tags, tsConfigFile, workspaces, }) {
16
+ export async function build({ chief, collector, deputy, factory, isGitIgnored, streamer, workspaces, options, }) {
17
17
  const configFilesMap = new Map();
18
18
  const enabledPluginsStore = new Map();
19
19
  const toSourceFilePath = getToSourcePathHandler(chief);
20
20
  const toSourceFilePaths = getToSourcePathsHandler(chief);
21
21
  const getReferencedInternalFilePath = getReferencedInputsHandler(collector, deputy, chief, isGitIgnored);
22
- const isReportClassMembers = report.classMembers;
23
22
  for (const workspace of workspaces) {
24
23
  const { name, dir, manifestPath, manifestStr } = workspace;
25
24
  const manifest = chief.getManifestForWorkspace(name);
26
25
  if (!manifest)
27
26
  continue;
28
- deputy.addWorkspace({ name, cwd, dir, manifestPath, manifestStr, manifest, ...chief.getIgnores(name) });
27
+ deputy.addWorkspace({
28
+ name,
29
+ cwd: options.cwd,
30
+ dir,
31
+ manifestPath,
32
+ manifestStr,
33
+ manifest,
34
+ ...chief.getIgnores(name),
35
+ });
29
36
  }
30
37
  for (const workspace of workspaces) {
31
38
  const { name, dir, ancestors, pkgName, manifestPath: filePath } = workspace;
@@ -38,29 +45,25 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
38
45
  const extensions = getCompilerExtensions(compilers);
39
46
  const extensionGlobStr = `.{${[...DEFAULT_EXTENSIONS, ...extensions].map(ext => ext.slice(1)).join(',')}}`;
40
47
  const config = chief.getConfigForWorkspace(name, extensions);
41
- const tsConfigFilePath = join(dir, tsConfigFile ?? 'tsconfig.json');
48
+ const tsConfigFilePath = join(dir, options.tsConfigFile ?? 'tsconfig.json');
42
49
  const { isFile, compilerOptions, definitionPaths } = await loadTSConfig(tsConfigFilePath);
43
50
  if (isFile)
44
51
  augmentWorkspace(workspace, dir, compilerOptions);
45
52
  const worker = new WorkspaceWorker({
46
53
  name,
47
54
  dir,
48
- cwd,
49
55
  config,
50
56
  manifest,
51
57
  dependencies,
52
58
  getReferencedInternalFilePath: (input) => getReferencedInternalFilePath(input, workspace),
53
59
  findWorkspaceByFilePath: chief.findWorkspaceByFilePath.bind(chief),
54
- isProduction,
55
- isStrict,
56
60
  rootIgnore: chief.config.ignore,
57
61
  negatedWorkspacePatterns: chief.getNegatedWorkspacePatterns(name),
58
62
  ignoredWorkspacePatterns: chief.getIgnoredWorkspacesFor(name),
59
63
  enabledPluginsInAncestors: ancestors.flatMap(ancestor => enabledPluginsStore.get(ancestor) ?? []),
60
64
  getSourceFile: (filePath) => principal.backend.fileManager.getSourceFile(filePath),
61
- isCache,
62
- cacheLocation,
63
65
  configFilesMap,
66
+ options,
64
67
  });
65
68
  await worker.init();
66
69
  const inputs = new Set();
@@ -70,8 +73,8 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
70
73
  inputs.add(toProductionEntry(id, { containingFilePath: tsConfigFilePath }));
71
74
  }
72
75
  const ignore = worker.getIgnorePatterns();
73
- const sharedGlobOptions = { cwd, dir, gitignore };
74
- collector.addIgnorePatterns(ignore.map(pattern => join(cwd, pattern)));
76
+ const sharedGlobOptions = { cwd: options.cwd, dir, gitignore: options.gitignore };
77
+ collector.addIgnorePatterns(ignore.map(pattern => join(options.cwd, pattern)));
75
78
  const entrySpecifiersFromManifest = getEntrySpecifiersFromManifest(manifest);
76
79
  for (const filePath of await toSourceFilePaths(entrySpecifiersFromManifest, dir, extensionGlobStr)) {
77
80
  inputs.add(toProductionEntry(filePath));
@@ -86,19 +89,13 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
86
89
  }
87
90
  for (const dep of getManifestImportDependencies(manifest))
88
91
  deputy.addReferencedDependency(name, dep);
89
- const principal = factory.createPrincipal({
90
- cwd: dir,
92
+ const principal = factory.createPrincipal(options, {
93
+ dir,
91
94
  isFile,
92
95
  compilerOptions,
93
96
  compilers,
94
97
  pkgName,
95
- isIsolateWorkspaces,
96
- isSkipLibs,
97
- isWatch,
98
98
  toSourceFilePath,
99
- isCache,
100
- cacheLocation,
101
- isProduction,
102
99
  });
103
100
  principal.addPaths(config.paths, dir);
104
101
  const inputsFromPlugins = await worker.runPlugins();
@@ -152,7 +149,7 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
152
149
  productionPatternsSkipExports.add(resolvedFilePath);
153
150
  }
154
151
  else if (isDeferResolveEntry(input)) {
155
- if (!isProduction || !input.optional)
152
+ if (!options.isProduction || !input.optional)
156
153
  entryPatternsSkipExports.add(resolvedFilePath);
157
154
  }
158
155
  else {
@@ -161,7 +158,7 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
161
158
  }
162
159
  }
163
160
  }
164
- if (isProduction) {
161
+ if (options.isProduction) {
165
162
  const negatedEntryPatterns = [...entryPatterns, ...entryPatternsSkipExports].map(negate);
166
163
  {
167
164
  const label = 'entry paths';
@@ -238,8 +235,8 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
238
235
  principal.addProjectPath(projectPath);
239
236
  }
240
237
  }
241
- if (chief.resolvedConfigFilePath) {
242
- principal.addEntryPath(chief.resolvedConfigFilePath, { skipExportsAnalysis: true });
238
+ if (options.configFilePath) {
239
+ factory.getPrincipals().at(0)?.addEntryPath(options.configFilePath, { skipExportsAnalysis: true });
243
240
  }
244
241
  worker.onDispose();
245
242
  }
@@ -255,20 +252,20 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
255
252
  if (workspace)
256
253
  return factory.getPrincipalByPackageName(workspace.pkgName);
257
254
  };
255
+ const analyzeOpts = {
256
+ isFixExports: options.isFixUnusedExports,
257
+ isFixTypes: options.isFixUnusedTypes,
258
+ isReportClassMembers: options.isReportClassMembers,
259
+ skipTypeOnly: options.isStrict,
260
+ tags: options.tags,
261
+ };
258
262
  const analyzeSourceFile = (filePath, principal) => {
259
- if (!isWatch && analyzedFiles.has(filePath))
263
+ if (!options.isWatch && analyzedFiles.has(filePath))
260
264
  return;
261
265
  analyzedFiles.add(filePath);
262
266
  const workspace = chief.findWorkspaceByFilePath(filePath);
263
267
  if (workspace) {
264
- const file = principal.analyzeSourceFile(filePath, {
265
- skipTypeOnly: isStrict,
266
- isFixExports,
267
- isFixTypes,
268
- ignoreExportsUsedInFile: chief.config.ignoreExportsUsedInFile,
269
- isReportClassMembers,
270
- tags,
271
- });
268
+ const file = principal.analyzeSourceFile(filePath, analyzeOpts, chief.config.ignoreExportsUsedInFile);
272
269
  const _unresolved = new Set();
273
270
  for (const unresolvedImport of file.imports.unresolved) {
274
271
  const { specifier } = unresolvedImport;
@@ -307,8 +304,14 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
307
304
  const dependencies = deputy.getDependencies(workspace.name);
308
305
  const manifestScriptNames = new Set(Object.keys(chief.getManifestForWorkspace(workspace.name)?.scripts ?? {}));
309
306
  const dir = dirname(filePath);
310
- const options = { cwd: dir, rootCwd: cwd, containingFilePath: filePath, dependencies, manifestScriptNames };
311
- const inputs = _getInputsFromScripts(file.scripts, options);
307
+ const opts = {
308
+ cwd: dir,
309
+ rootCwd: options.cwd,
310
+ containingFilePath: filePath,
311
+ dependencies,
312
+ manifestScriptNames,
313
+ };
314
+ const inputs = _getInputsFromScripts(file.scripts, opts);
312
315
  for (const input of inputs) {
313
316
  input.containingFilePath ??= filePath;
314
317
  input.dir ??= dir;
@@ -334,7 +337,7 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
334
337
  streamer.cast('Running async compilers');
335
338
  await principal.runAsyncCompilers();
336
339
  }
337
- streamer.cast('Analyzing source files', toRelative(principal.cwd));
340
+ streamer.cast('Analyzing source files', toRelative(principal.cwd, options.cwd));
338
341
  let size = principal.entryPaths.size;
339
342
  let round = 0;
340
343
  do {
@@ -350,16 +353,16 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
350
353
  for (const filePath of principal.entryPaths)
351
354
  entryPaths.add(filePath);
352
355
  principal.reconcileCache(graph);
353
- if (isIsolateWorkspaces || (isSkipLibs && !isWatch)) {
354
- factory.deletePrincipal(principal);
356
+ if (options.isIsolateWorkspaces || (options.isSkipLibs && !options.isWatch)) {
357
+ factory.deletePrincipal(principal, options.cwd);
355
358
  principals[i] = undefined;
356
359
  }
357
360
  perfObserver.addMemoryMark(factory.getPrincipalCount());
358
361
  }
359
- if (!isWatch && isSkipLibs && !isIsolateWorkspaces) {
362
+ if (!options.isWatch && options.isSkipLibs && !options.isIsolateWorkspaces) {
360
363
  for (const principal of principals) {
361
364
  if (principal)
362
- factory.deletePrincipal(principal);
365
+ factory.deletePrincipal(principal, options.cwd);
363
366
  }
364
367
  principals.length = 0;
365
368
  }
package/dist/index.d.ts CHANGED
@@ -1,14 +1,10 @@
1
- import type { CommandLineOptions } from './types/cli.js';
1
+ import type { MainOptions } from './util/create-options.js';
2
2
  export type { RawConfiguration as KnipConfig } from './types/config.js';
3
3
  export type { Preprocessor, Reporter, ReporterOptions } from './types/issues.js';
4
- export declare const main: (unresolvedConfiguration: CommandLineOptions) => Promise<{
5
- report: import("./types/issues.js").Report;
4
+ export declare const main: (options: MainOptions) => Promise<{
6
5
  issues: import("./types/issues.js").Issues;
7
6
  counters: import("./types/issues.js").Counters;
8
- rules: import("./types/issues.js").Rules;
9
7
  tagHints: Set<import("./types/issues.js").TagHint>;
10
8
  configurationHints: Set<import("./types/issues.js").ConfigurationHint>;
11
- isTreatConfigHintsAsErrors: boolean;
12
- includedWorkspaces: import("./ConfigurationChief.js").Workspace[];
13
- configFilePath: string | undefined;
9
+ includedWorkspaceDirs: string[];
14
10
  }>;
package/dist/index.js CHANGED
@@ -11,57 +11,30 @@ import { build } from './graph/build.js';
11
11
  import { debugLogArray, debugLogObject } from './util/debug.js';
12
12
  import { getGitIgnoredHandler } from './util/glob-core.js';
13
13
  import { getWatchHandler } from './util/watch.js';
14
- export const main = async (unresolvedConfiguration) => {
15
- const { cacheLocation, cwd, excludedIssueTypes, fixTypes, gitignore, includedIssueTypes, isCache, isDebug, isDependenciesShorthand, isExportsShorthand, isFilesShorthand, isFix, isFormat, isIncludeEntryExports, isIncludeLibs, isIsolateWorkspaces, isProduction, isRemoveFiles, isShowProgress, isStrict, isWatch, tags, tsConfigFile, workspace, } = unresolvedConfiguration;
16
- debugLogObject('*', 'Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
17
- const chief = new ConfigurationChief({ cwd, isProduction, isStrict, isIncludeEntryExports, workspace });
18
- const deputy = new DependencyDeputy({ isProduction, isStrict });
14
+ export const main = async (options) => {
15
+ const { cwd } = options;
16
+ debugLogObject('*', 'Unresolved configuration', options);
17
+ debugLogObject('*', 'Included issue types', options.includedIssueTypes);
18
+ const chief = new ConfigurationChief(options);
19
+ const deputy = new DependencyDeputy(options);
19
20
  const factory = new PrincipalFactory();
20
- const streamer = new ConsoleStreamer({ isEnabled: isShowProgress });
21
+ const streamer = new ConsoleStreamer(options);
22
+ const fixer = new IssueFixer(options);
23
+ const collector = new IssueCollector(options);
21
24
  streamer.cast('Reading workspace configuration');
22
- await chief.init();
23
- const workspaces = chief.getWorkspaces();
24
- const report = chief.getIncludedIssueTypes({
25
- includedIssueTypes,
26
- excludedIssueTypes,
27
- isDependenciesShorthand,
28
- isExportsShorthand,
29
- isFilesShorthand,
30
- });
31
- const rules = chief.getRules();
32
- const filters = chief.getFilters();
33
- const finalTags = tags[0].length > 0 || tags[1].length > 0 ? tags : chief.getTags();
34
- const fixer = new IssueFixer({ isEnabled: isFix, cwd, fixTypes, isRemoveFiles });
35
- debugLogObject('*', 'Included issue types', report);
36
- const isReportClassMembers = report.classMembers;
37
- const isSkipLibs = !(isIncludeLibs || isReportClassMembers);
38
- const collector = new IssueCollector({ cwd, rules, filters });
39
- const o = () => workspaces.map(w => ({ pkgName: w.pkgName, name: w.name, config: w.config, ancestors: w.ancestors }));
25
+ const workspaces = await chief.getWorkspaces();
26
+ const isGitIgnored = await getGitIgnoredHandler(options);
40
27
  debugLogObject('*', 'Included workspaces', () => workspaces.map(w => w.pkgName));
41
- debugLogObject('*', 'Included workspace configs', o);
42
- const isGitIgnored = await getGitIgnoredHandler({ cwd, gitignore });
28
+ debugLogObject('*', 'Included workspace configs', () => workspaces.map(w => ({ pkgName: w.pkgName, name: w.name, config: w.config, ancestors: w.ancestors })));
43
29
  const { graph, entryPaths, analyzedFiles, unreferencedFiles, analyzeSourceFile } = await build({
44
- cacheLocation,
45
30
  chief,
46
31
  collector,
47
- cwd,
48
32
  deputy,
49
33
  factory,
50
- gitignore,
51
- isCache,
52
- isFixExports: fixer.isEnabled && fixer.isFixUnusedExports,
53
- isFixTypes: fixer.isEnabled && fixer.isFixUnusedTypes,
54
34
  isGitIgnored,
55
- isIsolateWorkspaces,
56
- isProduction,
57
- isSkipLibs,
58
- isStrict,
59
- isWatch,
60
- report,
61
35
  streamer,
62
- tags: finalTags,
63
- tsConfigFile,
64
36
  workspaces,
37
+ options,
65
38
  });
66
39
  const reAnalyze = await analyze({
67
40
  analyzedFiles,
@@ -72,39 +45,30 @@ export const main = async (unresolvedConfiguration) => {
72
45
  factory,
73
46
  fixer,
74
47
  graph,
75
- isFix,
76
- isIncludeLibs,
77
- isProduction,
78
- report,
79
48
  streamer,
80
- tags: finalTags,
81
49
  unreferencedFiles,
50
+ options,
82
51
  });
83
- const { issues, counters, tagHints, configurationHints } = collector.getIssues();
84
- for (const hint of chief.getConfigurationHints())
85
- collector.addConfigurationHint(hint);
86
- if (isWatch) {
87
- const isIgnored = (filePath) => filePath.startsWith(cacheLocation) || filePath.includes('/.git/') || isGitIgnored(filePath);
88
- const watchHandler = await getWatchHandler({
52
+ if (options.isWatch) {
53
+ const isIgnored = (filePath) => filePath.startsWith(options.cacheLocation) || filePath.includes('/.git/') || isGitIgnored(filePath);
54
+ const watchHandler = await getWatchHandler(options, {
89
55
  analyzedFiles,
90
56
  analyzeSourceFile,
91
57
  chief,
92
58
  collector,
93
59
  analyze: reAnalyze,
94
- cwd,
95
60
  factory,
96
61
  graph,
97
- isDebug,
98
62
  isIgnored,
99
- report,
100
63
  streamer,
101
64
  unreferencedFiles,
102
65
  });
103
66
  watch('.', { recursive: true }, watchHandler);
104
67
  }
105
- if (isFix) {
68
+ const { issues, counters, tagHints, configurationHints } = collector.getIssues();
69
+ if (options.isFix) {
106
70
  const touchedFiles = await fixer.fixIssues(issues);
107
- if (isFormat) {
71
+ if (options.isFormat) {
108
72
  const report = await formatly(Array.from(touchedFiles), { cwd });
109
73
  if (report.ran && report.result && (report.result.runner === 'virtual' || report.result.code === 0)) {
110
74
  debugLogArray('*', `Formatted files using ${report.formatter.name} (${report.formatter.runner})`, touchedFiles);
@@ -114,17 +78,13 @@ export const main = async (unresolvedConfiguration) => {
114
78
  }
115
79
  }
116
80
  }
117
- if (!isWatch)
81
+ if (!options.isWatch)
118
82
  streamer.clear();
119
83
  return {
120
- report,
121
84
  issues,
122
85
  counters,
123
- rules,
124
86
  tagHints,
125
87
  configurationHints,
126
- isTreatConfigHintsAsErrors: chief.config.isTreatConfigHintsAsErrors,
127
- includedWorkspaces: chief.includedWorkspaces,
128
- configFilePath: chief.resolvedConfigFilePath,
88
+ includedWorkspaceDirs: chief.includedWorkspaces.map(w => w.dir),
129
89
  };
130
90
  };
@@ -515,6 +515,11 @@ export declare const Plugins: {
515
515
  isEnabled: import("../types/config.js").IsPluginEnabled;
516
516
  config: string[];
517
517
  };
518
+ pnpm: {
519
+ title: string;
520
+ isEnabled: import("../types/config.js").IsPluginEnabled;
521
+ config: string[];
522
+ };
518
523
  postcss: {
519
524
  title: string;
520
525
  enablers: string[];
@@ -61,6 +61,7 @@ import { default as playwrightCt } from './playwright-ct/index.js';
61
61
  import { default as playwrightTest } from './playwright-test/index.js';
62
62
  import { default as playwright } from './playwright/index.js';
63
63
  import { default as plop } from './plop/index.js';
64
+ import { default as pnpm } from './pnpm/index.js';
64
65
  import { default as postcss } from './postcss/index.js';
65
66
  import { default as preconstruct } from './preconstruct/index.js';
66
67
  import { default as prettier } from './prettier/index.js';
@@ -173,6 +174,7 @@ export const Plugins = {
173
174
  'playwright-ct': playwrightCt,
174
175
  'playwright-test': playwrightTest,
175
176
  plop,
177
+ pnpm,
176
178
  postcss,
177
179
  preconstruct,
178
180
  prettier,
@@ -1,4 +1,4 @@
1
- import { toProductionEntry } from '../../util/input.js';
1
+ import { toDependency, toProductionEntry } from '../../util/input.js';
2
2
  import { join } from '../../util/path.js';
3
3
  import { hasDependency } from '../../util/plugin.js';
4
4
  const title = 'Nuxt';
@@ -33,8 +33,9 @@ const resolveConfig = async (localConfig) => {
33
33
  'server/routes/**/*.ts',
34
34
  'server/middleware/**/*.ts',
35
35
  'server/plugins/**/*.ts',
36
- ];
37
- return patterns.map(pattern => toProductionEntry(join(srcDir, pattern)));
36
+ ].map(pattern => toProductionEntry(join(srcDir, pattern)));
37
+ const deps = localConfig.modules?.map(id => toDependency(id)) ?? [];
38
+ return [...deps, ...patterns];
38
39
  };
39
40
  const note = `Knip works best with [explicit imports](https://nuxt.com/docs/guide/concepts/auto-imports#explicit-imports).
40
41
  Nuxt allows to [disable auto-imports](https://nuxt.com/docs/guide/concepts/auto-imports#disabling-auto-imports).`;
@@ -1,8 +1,9 @@
1
- export type NuxtConfig = {
1
+ export interface NuxtConfig {
2
2
  srcDir?: string;
3
3
  dir?: {
4
4
  pages?: string;
5
5
  layouts?: string;
6
6
  middleware?: string;
7
7
  };
8
- };
8
+ modules?: Array<string>;
9
+ }
@@ -0,0 +1,7 @@
1
+ import type { IsPluginEnabled } from '../../types/config.js';
2
+ declare const _default: {
3
+ title: string;
4
+ isEnabled: IsPluginEnabled;
5
+ config: string[];
6
+ };
7
+ export default _default;
@@ -0,0 +1,8 @@
1
+ const title = 'pnpm';
2
+ const isEnabled = ({ manifest }) => Boolean(manifest.packageManager?.startsWith('pnpm@'));
3
+ const config = ['.pnpmfile.cjs'];
4
+ export default {
5
+ title,
6
+ isEnabled,
7
+ config,
8
+ };
@@ -6,12 +6,29 @@ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
6
  const config = ['rsbuild*.config.{mjs,ts,js,cjs,mts,cts}'];
7
7
  const resolveConfig = async (config) => {
8
8
  const inputs = new Set();
9
- if (config.source?.entry) {
10
- if (Array.isArray(config.source.entry))
11
- for (const entry of config.source.entry)
12
- inputs.add(toEntry(entry));
13
- if (typeof config.source.entry === 'string')
14
- inputs.add(toEntry(config.source.entry));
9
+ const checkSource = (source) => {
10
+ if (source?.entry) {
11
+ for (const entry of Object.values(source.entry)) {
12
+ if (typeof entry === 'string')
13
+ inputs.add(toEntry(entry));
14
+ else if (Array.isArray(entry))
15
+ for (const e of entry)
16
+ inputs.add(toEntry(e));
17
+ else {
18
+ if (typeof entry.import === 'string')
19
+ inputs.add(toEntry(entry.import));
20
+ else if (Array.isArray(entry.import))
21
+ for (const e of entry.import)
22
+ inputs.add(toEntry(e));
23
+ }
24
+ }
25
+ }
26
+ };
27
+ checkSource(config.source);
28
+ if (config.environments) {
29
+ for (const environment of Object.values(config.environments)) {
30
+ checkSource(environment.source);
31
+ }
15
32
  }
16
33
  return Array.from(inputs);
17
34
  };
@@ -7,5 +7,8 @@ export type RsbuildConfig = {
7
7
  source?: {
8
8
  entry?: Entry;
9
9
  };
10
+ environments?: {
11
+ [k: string]: Pick<RsbuildConfig, 'plugins' | 'source'>;
12
+ };
10
13
  };
11
14
  export {};
package/dist/plugins.js CHANGED
@@ -1,8 +1,9 @@
1
+ import { parseArgs } from 'node:util';
1
2
  import { Plugins } from './plugins/index.js';
2
3
  import { timerify } from './util/Performance.js';
3
- import parsedArgValues from './util/cli-arguments.js';
4
4
  const PMap = Plugins;
5
- const { performance: isEnabled = false } = parsedArgValues;
5
+ const { values } = parseArgs({ strict: false, options: { performance: { type: 'boolean' } } });
6
+ const isEnabled = !!values.performance;
6
7
  const timerifyMethods = ['resolve', 'resolveConfig', 'resolveAST'];
7
8
  const PluginEntries = Object.entries(PMap);
8
9
  if (isEnabled) {
@@ -1,3 +1,3 @@
1
1
  import type { ReporterOptions } from '../types/issues.js';
2
- declare const _default: ({ report, issues }: ReporterOptions) => Promise<void>;
2
+ declare const _default: ({ report, issues, cwd }: ReporterOptions) => Promise<void>;
3
3
  export default _default;
@@ -2,7 +2,7 @@ import { createHash } from 'node:crypto';
2
2
  import { ISSUE_TYPE_TITLE } from '../constants.js';
3
3
  import { toRelative } from '../util/path.js';
4
4
  import { getIssueTypeTitle } from './util/util.js';
5
- export default async ({ report, issues }) => {
5
+ export default async ({ report, issues, cwd }) => {
6
6
  const entries = [];
7
7
  for (const [type, isReportType] of Object.entries(report)) {
8
8
  if (!isReportType) {
@@ -17,9 +17,9 @@ export default async ({ report, issues }) => {
17
17
  check_name: getIssueTypeTitle(fixedType),
18
18
  description: getSymbolDescription({ type: issue.type, symbol, parentSymbol: issue.parentSymbol }),
19
19
  categories: ['Duplication'],
20
- location: createLocation(filePath, symbol.line, symbol.col),
20
+ location: createLocation(filePath, cwd, symbol.line, symbol.col),
21
21
  severity: convertSeverity(issue.severity),
22
- fingerprint: createFingerprint(filePath, symbol.symbol),
22
+ fingerprint: createFingerprint(filePath, cwd, symbol.symbol),
23
23
  })));
24
24
  }
25
25
  else {
@@ -28,9 +28,9 @@ export default async ({ report, issues }) => {
28
28
  check_name: getIssueTypeTitle(fixedType),
29
29
  description: getIssueDescription(issue),
30
30
  categories: ['Bug Risk'],
31
- location: createLocation(filePath, issue.line, issue.col),
31
+ location: createLocation(filePath, cwd, issue.line, issue.col),
32
32
  severity: convertSeverity(issue.severity),
33
- fingerprint: createFingerprint(filePath, issue.symbol),
33
+ fingerprint: createFingerprint(filePath, cwd, issue.symbol),
34
34
  });
35
35
  }
36
36
  }
@@ -62,10 +62,10 @@ function getIssueDescription({ type, symbol, symbols, parentSymbol }) {
62
62
  function getSymbolDescription({ type, symbol, parentSymbol, }) {
63
63
  return `${getPrefix(type)}: ${symbol.symbol}${parentSymbol ? ` (${parentSymbol})` : ''}`;
64
64
  }
65
- function createLocation(filePath, line, col) {
65
+ function createLocation(filePath, cwd, line, col) {
66
66
  if (col !== undefined) {
67
67
  return {
68
- path: toRelative(filePath),
68
+ path: toRelative(filePath, cwd),
69
69
  positions: {
70
70
  begin: {
71
71
  line: line ?? 0,
@@ -79,16 +79,16 @@ function createLocation(filePath, line, col) {
79
79
  };
80
80
  }
81
81
  return {
82
- path: toRelative(filePath),
82
+ path: toRelative(filePath, cwd),
83
83
  lines: {
84
84
  begin: line ?? 0,
85
85
  end: line ?? 0,
86
86
  },
87
87
  };
88
88
  }
89
- function createFingerprint(filePath, message) {
89
+ function createFingerprint(filePath, cwd, message) {
90
90
  const md5 = createHash('md5');
91
- md5.update(toRelative(filePath));
91
+ md5.update(toRelative(filePath, cwd));
92
92
  md5.update(message);
93
93
  return md5.digest('hex');
94
94
  }
@@ -1,3 +1,3 @@
1
1
  import type { ReporterOptions } from '../types/issues.js';
2
- declare const _default: ({ report, issues, isShowProgress, options }: ReporterOptions) => void;
2
+ declare const _default: ({ report, issues, isShowProgress, options, cwd }: ReporterOptions) => void;
3
3
  export default _default;
@@ -1,13 +1,13 @@
1
1
  import { createOwnershipEngine } from '../util/codeowners.js';
2
2
  import { relative, resolve } from '../util/path.js';
3
3
  import { getColoredTitle, getIssueLine, getIssueTypeTitle } from './util/util.js';
4
- const logIssueRecord = (issues) => {
4
+ const logIssueRecord = (issues, cwd) => {
5
5
  const sortedByFilePath = issues.sort((a, b) => (a.owner < b.owner ? -1 : 1));
6
6
  for (const { filePath, symbols, owner, parentSymbol } of sortedByFilePath) {
7
- console.log(getIssueLine({ owner, filePath, symbols, parentSymbol }));
7
+ console.log(getIssueLine({ owner, filePath, symbols, parentSymbol }, cwd));
8
8
  }
9
9
  };
10
- export default ({ report, issues, isShowProgress, options }) => {
10
+ export default ({ report, issues, isShowProgress, options, cwd }) => {
11
11
  let opts = {};
12
12
  try {
13
13
  opts = options ? JSON.parse(options) : opts;
@@ -20,7 +20,7 @@ export default ({ report, issues, isShowProgress, options }) => {
20
20
  const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
21
21
  const [dependenciesOwner = '[no-owner]'] = findOwners('package.json');
22
22
  let totalIssues = 0;
23
- const calcFileOwnership = (filePath) => findOwners(relative(filePath))[0] ?? dependenciesOwner;
23
+ const calcFileOwnership = (filePath) => findOwners(relative(cwd, filePath))[0] ?? dependenciesOwner;
24
24
  const addOwner = (issue) => ({
25
25
  ...issue,
26
26
  owner: calcFileOwnership(issue.filePath),
@@ -40,7 +40,7 @@ export default ({ report, issues, isShowProgress, options }) => {
40
40
  if (totalIssues)
41
41
  console.log();
42
42
  title && console.log(getColoredTitle(title, issuesForType.length));
43
- logIssueRecord(issuesForType);
43
+ logIssueRecord(issuesForType, cwd);
44
44
  }
45
45
  totalIssues = totalIssues + issuesForType.length;
46
46
  }
@@ -1,3 +1,3 @@
1
1
  import type { ReporterOptions } from '../types/issues.js';
2
- declare const _default: ({ report, issues, isShowProgress }: ReporterOptions) => void;
2
+ declare const _default: ({ report, issues, isShowProgress, cwd }: ReporterOptions) => void;
3
3
  export default _default;