knip 5.26.0 → 5.27.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 (112) hide show
  1. package/dist/CacheConsultant.d.ts +8 -2
  2. package/dist/CacheConsultant.js +9 -16
  3. package/dist/ConfigurationChief.d.ts +11 -4
  4. package/dist/ConfigurationChief.js +22 -21
  5. package/dist/ConfigurationValidator.d.ts +224 -0
  6. package/dist/ConfigurationValidator.js +4 -0
  7. package/dist/DependencyDeputy.d.ts +3 -2
  8. package/dist/DependencyDeputy.js +4 -4
  9. package/dist/PrincipalFactory.d.ts +4 -0
  10. package/dist/PrincipalFactory.js +3 -2
  11. package/dist/ProjectPrincipal.d.ts +5 -4
  12. package/dist/ProjectPrincipal.js +8 -6
  13. package/dist/WorkspaceWorker.d.ts +5 -3
  14. package/dist/WorkspaceWorker.js +2 -2
  15. package/dist/binaries/resolvers/bun.js +1 -1
  16. package/dist/binaries/util.js +2 -2
  17. package/dist/cli.js +23 -12
  18. package/dist/compilers/index.d.ts +40 -0
  19. package/dist/index.js +55 -134
  20. package/dist/plugins/babel/index.js +2 -1
  21. package/dist/plugins/babel/types.d.ts +1 -0
  22. package/dist/plugins/cypress/helpers.d.ts +3 -0
  23. package/dist/plugins/cypress/helpers.js +23 -0
  24. package/dist/plugins/cypress/index.d.ts +3 -1
  25. package/dist/plugins/cypress/index.js +5 -0
  26. package/dist/plugins/cypress/types.d.ts +6 -0
  27. package/dist/plugins/cypress/types.js +1 -0
  28. package/dist/plugins/eslint/helpers.js +8 -7
  29. package/dist/plugins/husky/index.d.ts +1 -1
  30. package/dist/plugins/husky/index.js +9 -2
  31. package/dist/plugins/index.d.ts +4 -0
  32. package/dist/plugins/index.js +4 -0
  33. package/dist/plugins/ladle/index.d.ts +13 -0
  34. package/dist/plugins/ladle/index.js +36 -0
  35. package/dist/plugins/ladle/types.d.ts +4 -0
  36. package/dist/plugins/ladle/types.js +1 -0
  37. package/dist/plugins/playwright/index.d.ts +1 -1
  38. package/dist/plugins/playwright/types.d.ts +36 -0
  39. package/dist/plugins/playwright/types.js +1 -0
  40. package/dist/plugins/playwright-ct/index.d.ts +2 -2
  41. package/dist/plugins/react-cosmos/index.d.ts +12 -0
  42. package/dist/plugins/react-cosmos/index.js +33 -0
  43. package/dist/plugins/react-cosmos/types.d.ts +5 -0
  44. package/dist/plugins/react-cosmos/types.js +1 -0
  45. package/dist/plugins/rsbuild/index.d.ts +10 -0
  46. package/dist/plugins/rsbuild/index.js +15 -0
  47. package/dist/plugins/rsbuild/types.d.ts +3 -0
  48. package/dist/plugins/rsbuild/types.js +1 -0
  49. package/dist/plugins/rspack/index.d.ts +10 -0
  50. package/dist/plugins/rspack/index.js +22 -0
  51. package/dist/plugins/vitest/index.js +1 -1
  52. package/dist/types/cli.d.ts +16 -9
  53. package/dist/typescript/{createHosts.js → create-hosts.js} +1 -1
  54. package/dist/typescript/{resolveModuleNames.js → resolve-module-names.js} +3 -2
  55. package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +1 -1
  56. package/dist/typescript/visitors/dynamic-imports/importCall.js +25 -31
  57. package/dist/typescript/visitors/dynamic-imports/importType.d.ts +1 -1
  58. package/dist/typescript/visitors/dynamic-imports/index.d.ts +1 -1
  59. package/dist/typescript/visitors/dynamic-imports/jsDocType.d.ts +1 -1
  60. package/dist/typescript/visitors/dynamic-imports/propertyAccessCall.d.ts +1 -1
  61. package/dist/typescript/visitors/dynamic-imports/requireCall.d.ts +1 -1
  62. package/dist/typescript/visitors/dynamic-imports/requireCall.js +8 -4
  63. package/dist/typescript/visitors/exports/exportAssignment.d.ts +1 -1
  64. package/dist/typescript/visitors/exports/exportDeclaration.d.ts +1 -1
  65. package/dist/typescript/visitors/exports/exportKeyword.d.ts +1 -1
  66. package/dist/typescript/visitors/exports/exportsAccessExpression.d.ts +1 -1
  67. package/dist/typescript/visitors/exports/index.d.ts +1 -1
  68. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
  69. package/dist/typescript/visitors/helpers.js +1 -1
  70. package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
  71. package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
  72. package/dist/typescript/visitors/imports/index.d.ts +1 -1
  73. package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
  74. package/dist/typescript/visitors/index.d.ts +1 -1
  75. package/dist/typescript/visitors/scripts/bun.d.ts +1 -1
  76. package/dist/typescript/visitors/scripts/execa.d.ts +1 -1
  77. package/dist/typescript/visitors/scripts/index.d.ts +1 -1
  78. package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
  79. package/dist/util/create-workspace-graph.d.ts +8 -0
  80. package/dist/util/{pkgs-graph.js → create-workspace-graph.js} +3 -3
  81. package/dist/util/dependency-graph.d.ts +3 -4
  82. package/dist/util/dependency-graph.js +35 -3
  83. package/dist/util/get-included-issue-types.d.ts +6 -6
  84. package/dist/util/get-included-issue-types.js +5 -5
  85. package/dist/util/globby.js +2 -2
  86. package/dist/util/handle-dependency.d.ts +1 -1
  87. package/dist/util/handle-dependency.js +7 -9
  88. package/dist/util/loader.js +1 -1
  89. package/dist/util/modules.d.ts +0 -1
  90. package/dist/util/modules.js +0 -7
  91. package/dist/util/plugin.d.ts +1 -0
  92. package/dist/util/plugin.js +7 -6
  93. package/dist/util/reporter.d.ts +2 -2
  94. package/dist/util/reporter.js +12 -10
  95. package/dist/util/require.d.ts +0 -3
  96. package/dist/util/require.js +3 -34
  97. package/dist/util/resolve.d.ts +2 -1
  98. package/dist/util/resolve.js +21 -12
  99. package/dist/util/to-source-path.d.ts +2 -2
  100. package/dist/util/watch.d.ts +25 -0
  101. package/dist/util/watch.js +85 -0
  102. package/dist/version.d.ts +1 -1
  103. package/dist/version.js +1 -1
  104. package/package.json +3 -5
  105. package/schema.json +16 -0
  106. package/dist/util/pkgs-graph.d.ts +0 -8
  107. /package/dist/typescript/{createHosts.d.ts → create-hosts.d.ts} +0 -0
  108. /package/dist/typescript/{getImportsAndExports.d.ts → get-imports-and-exports.d.ts} +0 -0
  109. /package/dist/typescript/{getImportsAndExports.js → get-imports-and-exports.js} +0 -0
  110. /package/dist/typescript/{resolveModuleNames.d.ts → resolve-module-names.d.ts} +0 -0
  111. /package/dist/util/{register.d.ts → jiti.d.ts} +0 -0
  112. /package/dist/util/{register.js → jiti.js} +0 -0
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { watch } from 'node:fs';
2
- import { CacheConsultant } from './CacheConsultant.js';
3
2
  import { ConfigurationChief } from './ConfigurationChief.js';
4
3
  import { ConsoleStreamer } from './ConsoleStreamer.js';
5
4
  import { DependencyDeputy } from './DependencyDeputy.js';
@@ -10,35 +9,38 @@ import { WorkspaceWorker } from './WorkspaceWorker.js';
10
9
  import { _getDependenciesFromScripts } from './binaries/index.js';
11
10
  import { getCompilerExtensions, getIncludedCompilers } from './compilers/index.js';
12
11
  import { getFilteredScripts } from './manifest/helpers.js';
13
- import watchReporter from './reporters/watch.js';
14
12
  import { debugLog, debugLogArray, debugLogObject } from './util/debug.js';
15
- import { addNsValues, addValues, createFileNode } from './util/dependency-graph.js';
16
- import { isFile } from './util/fs.js';
13
+ import { getOrCreateFileNode, updateImportMap } from './util/dependency-graph.js';
17
14
  import { _glob, negate } from './util/glob.js';
18
15
  import { getGitIgnoredHandler } from './util/globby.js';
19
- import { getHandler } from './util/handle-dependency.js';
16
+ import { getReferencedDependencyHandler } from './util/handle-dependency.js';
20
17
  import { getHasStrictlyNsReferences, getType } from './util/has-strictly-ns-references.js';
21
18
  import { getIsIdentifierReferencedHandler } from './util/is-identifier-referenced.js';
22
19
  import { getEntryPathFromManifest, getPackageNameFromModuleSpecifier } from './util/modules.js';
23
- import { dirname, join, toPosix } from './util/path.js';
20
+ import { dirname, join } from './util/path.js';
24
21
  import { findMatch } from './util/regex.js';
25
22
  import { getShouldIgnoreHandler, getShouldIgnoreTagHandler } from './util/tag.js';
26
23
  import { augmentWorkspace, getToSourcePathHandler } from './util/to-source-path.js';
27
24
  import { createAndPrintTrace, printTrace } from './util/trace.js';
28
25
  import { loadTSConfig } from './util/tsconfig-loader.js';
26
+ import { getWatchHandler } from './util/watch.js';
29
27
  export const main = async (unresolvedConfiguration) => {
30
- const { cwd, tsConfigFile, gitignore, isStrict, isProduction, isShowProgress, isIncludeEntryExports, isIncludeLibs, isIsolateWorkspaces, isDebug, isWatch, tags, isFix, fixTypes, isRemoveFiles, } = unresolvedConfiguration;
28
+ const { cacheLocation, cwd, excludedIssueTypes, fixTypes, gitignore, includedIssueTypes, isCache, isDebug, isDependenciesShorthand, isExportsShorthand, isFilesShorthand, isFix, isHideConfigHints, isIncludeEntryExports, isIncludeLibs, isIsolateWorkspaces, isProduction, isRemoveFiles, isShowProgress, isStrict, isWatch, tags, tsConfigFile, workspace, } = unresolvedConfiguration;
31
29
  debugLogObject('*', 'Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
32
- const chief = new ConfigurationChief({ cwd, isProduction, isStrict, isIncludeEntryExports });
30
+ const chief = new ConfigurationChief({ cwd, isProduction, isStrict, isIncludeEntryExports, workspace });
33
31
  const deputy = new DependencyDeputy({ isProduction, isStrict });
34
32
  const factory = new PrincipalFactory();
35
33
  const streamer = new ConsoleStreamer({ isEnabled: isShowProgress });
36
- const isGitIgnored = await getGitIgnoredHandler({ cwd, gitignore });
37
- const toSourceFilePath = getToSourcePathHandler(chief);
38
34
  streamer.cast('Reading workspace configuration(s)...');
39
35
  await chief.init();
40
36
  const workspaces = chief.getIncludedWorkspaces();
41
- const report = chief.getIncludedIssueTypes();
37
+ const report = chief.getIncludedIssueTypes({
38
+ includedIssueTypes,
39
+ excludedIssueTypes,
40
+ isDependenciesShorthand,
41
+ isExportsShorthand,
42
+ isFilesShorthand,
43
+ });
42
44
  const rules = chief.getRules();
43
45
  const filters = chief.getFilters();
44
46
  const fixer = new IssueFixer({ isEnabled: isFix, cwd, fixTypes, isRemoveFiles });
@@ -53,6 +55,11 @@ export const main = async (unresolvedConfiguration) => {
53
55
  const o = () => workspaces.map(w => ({ pkgName: w.pkgName, name: w.name, config: w.config, ancestors: w.ancestors }));
54
56
  debugLogObject('*', 'Included workspaces', () => workspaces.map(w => w.pkgName));
55
57
  debugLogObject('*', 'Included workspace configs', o);
58
+ const isGitIgnored = await getGitIgnoredHandler({ cwd, gitignore });
59
+ const toSourceFilePath = getToSourcePathHandler(chief);
60
+ const handleReferencedDependency = getReferencedDependencyHandler(collector, deputy, chief);
61
+ const shouldIgnore = getShouldIgnoreHandler(isProduction);
62
+ const shouldIgnoreTags = getShouldIgnoreTagHandler(tags);
56
63
  for (const workspace of workspaces) {
57
64
  const { name, dir, ancestors, pkgName, manifestPath } = workspace;
58
65
  streamer.cast(`Analyzing workspace ${name}...`);
@@ -81,6 +88,9 @@ export const main = async (unresolvedConfiguration) => {
81
88
  isIsolateWorkspaces,
82
89
  isSkipLibs,
83
90
  isWatch,
91
+ toSourceFilePath,
92
+ isCache,
93
+ cacheLocation,
84
94
  });
85
95
  const worker = new WorkspaceWorker({
86
96
  name,
@@ -94,6 +104,8 @@ export const main = async (unresolvedConfiguration) => {
94
104
  rootIgnore: chief.config.ignore,
95
105
  negatedWorkspacePatterns: chief.getNegatedWorkspacePatterns(name),
96
106
  enabledPluginsInAncestors: ancestors.flatMap(ancestor => enabledPluginsStore.get(ancestor) ?? []),
107
+ isCache,
108
+ cacheLocation,
97
109
  });
98
110
  await worker.init();
99
111
  principal.addEntryPaths(definitionPaths);
@@ -177,39 +189,7 @@ export const main = async (unresolvedConfiguration) => {
177
189
  const analyzedFiles = new Set();
178
190
  const unreferencedFiles = new Set();
179
191
  const entryPaths = new Set();
180
- const getFileNode = (filePath) => graph.get(filePath) ?? createFileNode();
181
- const handleReferencedDependency = getHandler(collector, deputy, chief);
182
- const updateImportDetails = (importedModule, importItems) => {
183
- for (const id of importItems.refs)
184
- importedModule.refs.add(id);
185
- for (const [id, v] of importItems.imported.entries())
186
- addValues(importedModule.imported, id, v);
187
- for (const [id, v] of importItems.importedAs.entries())
188
- addNsValues(importedModule.importedAs, id, v);
189
- for (const [id, v] of importItems.importedNs.entries())
190
- addValues(importedModule.importedNs, id, v);
191
- for (const [id, v] of importItems.reExported.entries())
192
- addValues(importedModule.reExported, id, v);
193
- for (const [id, v] of importItems.reExportedAs.entries())
194
- addNsValues(importedModule.reExportedAs, id, v);
195
- for (const [id, v] of importItems.reExportedNs.entries())
196
- addValues(importedModule.reExportedNs, id, v);
197
- };
198
- const updateImportMap = (file, importMap) => {
199
- for (const [importedFilePath, importDetails] of importMap.entries()) {
200
- const importedFileImports = file.imports.internal.get(importedFilePath);
201
- if (!importedFileImports)
202
- file.imports.internal.set(importedFilePath, importDetails);
203
- else
204
- updateImportDetails(importedFileImports, importDetails);
205
- const importedFile = getFileNode(importedFilePath);
206
- if (!importedFile.imported)
207
- importedFile.imported = importDetails;
208
- else
209
- updateImportDetails(importedFile.imported, importDetails);
210
- graph.set(importedFilePath, importedFile);
211
- }
212
- };
192
+ const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths);
213
193
  const isPackageNameInternalWorkspace = (packageName) => chief.availableWorkspacePkgNames.has(packageName);
214
194
  const getPrincipalByFilePath = (filePath) => {
215
195
  const workspace = chief.findWorkspaceByFilePath(filePath);
@@ -230,12 +210,12 @@ export const main = async (unresolvedConfiguration) => {
230
210
  isReportClassMembers,
231
211
  tags,
232
212
  }, isGitIgnored, isPackageNameInternalWorkspace, getPrincipalByFilePath);
233
- const file = getFileNode(filePath);
213
+ const file = getOrCreateFileNode(graph, filePath);
234
214
  file.imports = imports;
235
215
  file.exports = exports;
236
216
  file.scripts = scripts;
237
217
  file.traceRefs = traceRefs;
238
- updateImportMap(file, imports.internal);
218
+ updateImportMap(file, imports.internal, graph);
239
219
  file.internalImportCache = imports.internal;
240
220
  graph.set(filePath, file);
241
221
  if (scripts && scripts.size > 0) {
@@ -252,12 +232,12 @@ export const main = async (unresolvedConfiguration) => {
252
232
  }
253
233
  };
254
234
  for (const principal of principals) {
255
- principal.init(toSourceFilePath);
235
+ principal.init();
256
236
  for (const [containingFilePath, specifier, workspaceName] of principal.referencedDependencies) {
257
237
  const workspace = chief.findWorkspaceByName(workspaceName);
258
238
  if (workspace) {
259
239
  const specifierFilePath = handleReferencedDependency(specifier, containingFilePath, workspace);
260
- if (specifierFilePath)
240
+ if (specifierFilePath && !isGitIgnored(specifierFilePath))
261
241
  principal.addEntryPath(specifierFilePath);
262
242
  }
263
243
  }
@@ -285,16 +265,13 @@ export const main = async (unresolvedConfiguration) => {
285
265
  if (isIsolateWorkspaces)
286
266
  for (const principal of principals)
287
267
  factory.deletePrincipal(principal);
288
- const shouldIgnore = getShouldIgnoreHandler(isProduction);
289
- const shouldIgnoreTags = getShouldIgnoreTagHandler(tags);
290
- const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths);
291
268
  const ignoreExportsUsedInFile = chief.config.ignoreExportsUsedInFile;
292
269
  const isExportedItemReferenced = (exportedItem) => exportedItem.refs[1] ||
293
270
  (exportedItem.refs[0] > 0 &&
294
271
  (typeof ignoreExportsUsedInFile === 'object'
295
272
  ? exportedItem.type !== 'unknown' && !!ignoreExportsUsedInFile[exportedItem.type]
296
273
  : ignoreExportsUsedInFile));
297
- const findUnusedExports = async () => {
274
+ const collectUnusedExports = async () => {
298
275
  if (isReportValues || isReportTypes) {
299
276
  streamer.cast('Connecting the dots...');
300
277
  for (const [filePath, file] of graph.entries()) {
@@ -472,98 +449,42 @@ export const main = async (unresolvedConfiguration) => {
472
449
  collector.addIssue(issue);
473
450
  for (const issue of optionalPeerDependencyIssues)
474
451
  collector.addIssue(issue);
475
- const configurationHints = deputy.getConfigurationHints(collector.getIssues());
476
- for (const hint of configurationHints)
477
- collector.addConfigurationHint(hint);
452
+ deputy.removeIgnoredIssues(collector.getIssues());
453
+ if (!workspace && !isProduction && !isHideConfigHints) {
454
+ const configurationHints = deputy.getConfigurationHints();
455
+ for (const hint of configurationHints)
456
+ collector.addConfigurationHint(hint);
457
+ }
478
458
  }
479
459
  const unusedIgnoredWorkspaces = chief.getUnusedIgnoredWorkspaces();
480
460
  for (const identifier of unusedIgnoredWorkspaces) {
481
461
  collector.addConfigurationHint({ type: 'ignoreWorkspaces', identifier });
482
462
  }
483
463
  };
464
+ await collectUnusedExports();
465
+ const { issues, counters, tagHints, configurationHints } = collector.getIssues();
484
466
  if (isWatch) {
485
- const cacheLocation = CacheConsultant.getCacheLocation();
486
- watch('.', { recursive: true }, async (eventType, filename) => {
487
- debugLog('*', `(raw) ${eventType} ${filename}`);
488
- if (filename) {
489
- const startTime = performance.now();
490
- const filePath = join(cwd, toPosix(filename));
491
- if (filename.startsWith(cacheLocation) || filename.startsWith('.git/') || isGitIgnored(filePath)) {
492
- debugLog('*', `ignoring ${eventType} ${filename}`);
493
- return;
494
- }
495
- const workspace = chief.findWorkspaceByFilePath(filePath);
496
- if (workspace) {
497
- const principal = factory.getPrincipalByPackageName(workspace.pkgName);
498
- if (principal) {
499
- const event = eventType === 'rename' ? (isFile(filePath) ? 'added' : 'deleted') : 'modified';
500
- principal.invalidateFile(filePath);
501
- unreferencedFiles.clear();
502
- const cachedUnusedFiles = collector.purge();
503
- switch (event) {
504
- case 'added':
505
- principal.addProjectPath(filePath);
506
- principal.deletedFiles.delete(filePath);
507
- cachedUnusedFiles.add(filePath);
508
- debugLog(workspace.name, `Watcher: + ${filename}`);
509
- break;
510
- case 'deleted':
511
- analyzedFiles.delete(filePath);
512
- principal.removeProjectPath(filePath);
513
- cachedUnusedFiles.delete(filePath);
514
- debugLog(workspace.name, `Watcher: - ${filename}`);
515
- break;
516
- case 'modified':
517
- debugLog(workspace.name, `Watcher: ± ${filename}`);
518
- break;
519
- }
520
- const filePaths = principal.getUsedResolvedFiles();
521
- if (event === 'added' || event === 'deleted') {
522
- graph.clear();
523
- for (const filePath of filePaths)
524
- analyzeSourceFile(filePath, principal);
525
- }
526
- else {
527
- for (const [filePath, file] of graph) {
528
- if (filePaths.includes(filePath)) {
529
- file.imported = undefined;
530
- }
531
- else {
532
- graph.delete(filePath);
533
- analyzedFiles.delete(filePath);
534
- cachedUnusedFiles.add(filePath);
535
- }
536
- }
537
- for (const filePath of filePaths)
538
- if (!graph.has(filePath))
539
- analyzeSourceFile(filePath, principal);
540
- if (!cachedUnusedFiles.has(filePath))
541
- analyzeSourceFile(filePath, principal);
542
- for (const filePath of filePaths) {
543
- const file = graph.get(filePath);
544
- if (file?.internalImportCache)
545
- updateImportMap(file, file.internalImportCache);
546
- }
547
- }
548
- await findUnusedExports();
549
- const unusedFiles = [...cachedUnusedFiles].filter(filePath => !analyzedFiles.has(filePath));
550
- collector.addFilesIssues(unusedFiles);
551
- collector.addFileCounts({ processed: analyzedFiles.size, unused: unusedFiles.length });
552
- const { issues } = collector.getIssues();
553
- watchReporter({ report, issues, streamer, startTime, size: analyzedFiles.size, isDebug });
554
- }
555
- }
556
- }
467
+ const isIgnored = (filePath) => filePath.startsWith(cacheLocation) || filePath.includes('/.git/') || isGitIgnored(filePath);
468
+ const watchHandler = await getWatchHandler({
469
+ analyzedFiles,
470
+ analyzeSourceFile,
471
+ chief,
472
+ collector,
473
+ collectUnusedExports,
474
+ cwd,
475
+ factory,
476
+ graph,
477
+ isDebug,
478
+ isIgnored,
479
+ report,
480
+ streamer,
481
+ unreferencedFiles,
557
482
  });
483
+ watch('.', { recursive: true }, watchHandler);
558
484
  }
559
- await findUnusedExports();
560
- const { issues, counters, tagHints, configurationHints } = collector.getIssues();
561
- if (isFix) {
485
+ if (isFix)
562
486
  await fixer.fixIssues(issues);
563
- }
564
- if (isWatch)
565
- watchReporter({ report, issues, streamer, size: analyzedFiles.size, isDebug });
566
- else
487
+ if (!isWatch)
567
488
  streamer.clear();
568
489
  return { report, issues, counters, rules, tagHints, configurationHints };
569
490
  };
@@ -10,7 +10,8 @@ export const getDependenciesFromConfig = (config) => {
10
10
  const presets = config.presets?.flatMap(getName).map(name => resolveName(name, 'preset')) ?? [];
11
11
  const plugins = config.plugins?.flatMap(getName).map(name => resolveName(name, 'plugin')) ?? [];
12
12
  const nested = config.env ? Object.values(config.env).flatMap(getDependenciesFromConfig) : [];
13
- return compact([...presets, ...plugins, ...nested]);
13
+ const overrides = config.overrides ? [config.overrides].flat().flatMap(getDependenciesFromConfig) : [];
14
+ return compact([...presets, ...plugins, ...nested, ...overrides]);
14
15
  };
15
16
  const resolveConfig = async (config) => {
16
17
  if (typeof config === 'function')
@@ -4,6 +4,7 @@ export type BabelConfigObj = {
4
4
  plugins?: (string | [string, unknown])[];
5
5
  presets?: (string | [string, unknown])[];
6
6
  env?: Record<string, BabelConfigObj>;
7
+ overrides?: BabelConfigObj[];
7
8
  };
8
9
  export type BabelConfig = BabelConfigObj | BabelConfigFn;
9
10
  export {};
@@ -0,0 +1,3 @@
1
+ import type { PluginOptions } from '#p/types/plugins.js';
2
+ import type { CypressConfig } from './types.js';
3
+ export declare const resolveDependencies: (config: CypressConfig, options: PluginOptions) => Promise<string[]>;
@@ -0,0 +1,23 @@
1
+ import { isInternal, toAbsolute } from '#p/util/path.js';
2
+ import { load, resolveEntry } from '#p/util/plugin.js';
3
+ export const resolveDependencies = async (config, options) => {
4
+ const { reporter } = config;
5
+ const { configFileDir } = options;
6
+ const resolve = (specifier) => resolveEntry(options, specifier);
7
+ const reporters = reporter ? new Set([reporter]) : new Set();
8
+ if (reporter === 'cypress-multi-reporters' && config.reporterOptions?.configFile) {
9
+ const { configFile } = config.reporterOptions;
10
+ const configFilePath = toAbsolute(configFile, configFileDir);
11
+ if (isInternal(configFilePath)) {
12
+ const reporterConfig = await load(configFilePath);
13
+ if (typeof reporterConfig === 'object' && reporterConfig.reporterEnabled) {
14
+ const { reporterEnabled: reporterConcatenatedNames } = reporterConfig;
15
+ const reporterNames = reporterConcatenatedNames.split(',');
16
+ for (const reporterName of reporterNames) {
17
+ reporters.add(resolve(reporterName.trim()));
18
+ }
19
+ }
20
+ }
21
+ }
22
+ return [...reporters];
23
+ };
@@ -1,4 +1,5 @@
1
- import type { IsPluginEnabled, ResolveEntryPaths } from '#p/types/plugins.js';
1
+ import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { CypressConfig } from './types.js';
2
3
  declare const _default: {
3
4
  title: string;
4
5
  enablers: string[];
@@ -6,5 +7,6 @@ declare const _default: {
6
7
  config: string[];
7
8
  entry: string[];
8
9
  resolveEntryPaths: ResolveEntryPaths;
10
+ resolveConfig: ResolveConfig<CypressConfig>;
9
11
  };
10
12
  export default _default;
@@ -1,5 +1,6 @@
1
1
  import { hasDependency } from '#p/util/plugin.js';
2
2
  import { toEntryPattern } from '../../util/protocols.js';
3
+ import { resolveDependencies } from './helpers.js';
3
4
  const title = 'Cypress';
4
5
  const enablers = ['cypress'];
5
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -19,6 +20,9 @@ const resolveEntryPaths = async (localConfig) => {
19
20
  ...(supportFiles.length > 0 ? supportFiles : SUPPORT_FILE_PATTERNS),
20
21
  ].map(toEntryPattern);
21
22
  };
23
+ const resolveConfig = (config, options) => {
24
+ return resolveDependencies(config, options);
25
+ };
22
26
  export default {
23
27
  title,
24
28
  enablers,
@@ -26,4 +30,5 @@ export default {
26
30
  config,
27
31
  entry,
28
32
  resolveEntryPaths,
33
+ resolveConfig,
29
34
  };
@@ -0,0 +1,6 @@
1
+ export interface CypressConfig {
2
+ reporter: string;
3
+ reporterOptions?: {
4
+ configFile?: string;
5
+ };
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,7 @@
1
1
  import { compact } from '#p/util/array.js';
2
2
  import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier } from '#p/util/modules.js';
3
3
  import { basename, dirname, isAbsolute, isInternal, toAbsolute } from '#p/util/path.js';
4
- import { load } from '#p/util/plugin.js';
5
- import { _resolve } from '#p/util/require.js';
4
+ import { load, resolve } from '#p/util/plugin.js';
6
5
  import { getDependenciesFromConfig } from '../babel/index.js';
7
6
  const getDependencies = (config) => {
8
7
  const extendsSpecifiers = config.extends ? [config.extends].flat().map(resolveExtendSpecifier) : [];
@@ -27,11 +26,13 @@ export const getDependenciesDeep = async (localConfig, options, dependencies = n
27
26
  if (localConfig.extends) {
28
27
  for (const extend of [localConfig.extends].flat()) {
29
28
  if (isInternal(extend)) {
30
- const filePath = _resolve(toAbsolute(extend, configFileDir));
31
- dependencies.add(filePath);
32
- const localConfig = await load(filePath);
33
- const opts = { ...options, configFileDir: dirname(filePath), configFileName: basename(filePath) };
34
- addAll(await getDependenciesDeep(localConfig, opts, dependencies));
29
+ const filePath = resolve(toAbsolute(extend, configFileDir), configFileDir);
30
+ if (filePath) {
31
+ dependencies.add(filePath);
32
+ const localConfig = await load(filePath);
33
+ const opts = { ...options, configFileDir: dirname(filePath), configFileName: basename(filePath) };
34
+ addAll(await getDependenciesDeep(localConfig, opts, dependencies));
35
+ }
35
36
  }
36
37
  }
37
38
  }
@@ -4,6 +4,6 @@ declare const _default: {
4
4
  enablers: string[];
5
5
  isEnabled: IsPluginEnabled;
6
6
  config: string[];
7
- resolveConfig: ResolveConfig<string>;
7
+ resolveConfig: ResolveConfig;
8
8
  };
9
9
  export default _default;
@@ -4,10 +4,17 @@ const title = 'husky';
4
4
  const enablers = ['husky'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
6
  const gitHookPaths = getGitHookPaths('.husky', false);
7
- const config = [...gitHookPaths];
8
- const resolveConfig = async (script, options) => {
7
+ const config = [...gitHookPaths, 'package.json'];
8
+ const resolveConfig = (script, options) => {
9
9
  if (!script)
10
10
  return [];
11
+ if (options.configFileName === 'package.json') {
12
+ const hooks = script.hooks;
13
+ if (hooks) {
14
+ const scripts = Object.values(hooks);
15
+ return ['husky', ...getDependenciesFromScripts(scripts, { ...options })];
16
+ }
17
+ }
11
18
  return getDependenciesFromScripts(String(script), { ...options, knownGlobalsOnly: true });
12
19
  };
13
20
  export default {
@@ -17,6 +17,7 @@ export { default as githubActions } from './github-actions/index.js';
17
17
  export { default as graphqlCodegen } from './graphql-codegen/index.js';
18
18
  export { default as husky } from './husky/index.js';
19
19
  export { default as jest } from './jest/index.js';
20
+ export { default as ladle } from './ladle/index.js';
20
21
  export { default as lefthook } from './lefthook/index.js';
21
22
  export { default as linthtml } from './linthtml/index.js';
22
23
  export { default as lintStaged } from './lint-staged/index.js';
@@ -37,10 +38,13 @@ export { default as playwright } from './playwright/index.js';
37
38
  export { default as playwrightCt } from './playwright-ct/index.js';
38
39
  export { default as postcss } from './postcss/index.js';
39
40
  export { default as prettier } from './prettier/index.js';
41
+ export { default as reactCosmos } from './react-cosmos/index.js';
40
42
  export { default as releaseIt } from './release-it/index.js';
41
43
  export { default as remark } from './remark/index.js';
42
44
  export { default as remix } from './remix/index.js';
43
45
  export { default as rollup } from './rollup/index.js';
46
+ export { default as rsbuild } from './rsbuild/index.js';
47
+ export { default as rspack } from './rspack/index.js';
44
48
  export { default as semanticRelease } from './semantic-release/index.js';
45
49
  export { default as sentry } from './sentry/index.js';
46
50
  export { default as simpleGitHooks } from './simple-git-hooks/index.js';
@@ -17,6 +17,7 @@ export { default as githubActions } from './github-actions/index.js';
17
17
  export { default as graphqlCodegen } from './graphql-codegen/index.js';
18
18
  export { default as husky } from './husky/index.js';
19
19
  export { default as jest } from './jest/index.js';
20
+ export { default as ladle } from './ladle/index.js';
20
21
  export { default as lefthook } from './lefthook/index.js';
21
22
  export { default as linthtml } from './linthtml/index.js';
22
23
  export { default as lintStaged } from './lint-staged/index.js';
@@ -37,10 +38,13 @@ export { default as playwright } from './playwright/index.js';
37
38
  export { default as playwrightCt } from './playwright-ct/index.js';
38
39
  export { default as postcss } from './postcss/index.js';
39
40
  export { default as prettier } from './prettier/index.js';
41
+ export { default as reactCosmos } from './react-cosmos/index.js';
40
42
  export { default as releaseIt } from './release-it/index.js';
41
43
  export { default as remark } from './remark/index.js';
42
44
  export { default as remix } from './remix/index.js';
43
45
  export { default as rollup } from './rollup/index.js';
46
+ export { default as rsbuild } from './rsbuild/index.js';
47
+ export { default as rspack } from './rspack/index.js';
44
48
  export { default as semanticRelease } from './semantic-release/index.js';
45
49
  export { default as sentry } from './sentry/index.js';
46
50
  export { default as simpleGitHooks } from './simple-git-hooks/index.js';
@@ -0,0 +1,13 @@
1
+ import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { LadleConfig } from './types.js';
3
+ declare const _default: {
4
+ title: string;
5
+ enablers: import("#p/types/config.js").IgnorePatterns;
6
+ isEnabled: IsPluginEnabled;
7
+ config: string[];
8
+ entry: string[];
9
+ project: string[];
10
+ resolveEntryPaths: ResolveEntryPaths<LadleConfig>;
11
+ resolveConfig: ResolveConfig<LadleConfig>;
12
+ };
13
+ export default _default;
@@ -0,0 +1,36 @@
1
+ import { toAbsolute } from '#p/util/path.js';
2
+ import { hasDependency, load } from '#p/util/plugin.js';
3
+ import { toEntryPattern } from '../../util/protocols.js';
4
+ import { resolveConfig as resolveVitestConfig } from '../vitest/index.js';
5
+ const title = 'Ladle';
6
+ const enablers = ['@ladle/react'];
7
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
+ const config = ['.ladle/config.{mjs,js,ts}'];
9
+ const stories = ['src/**/*.stories.{js,jsx,ts,tsx,mdx}'];
10
+ const restEntry = ['.ladle/components.{js,jsx,ts,tsx}'];
11
+ const entry = [...restEntry, ...stories];
12
+ const project = ['.ladle/**/*.{js,jsx,ts,tsx}'];
13
+ const resolveEntryPaths = (localConfig, options) => {
14
+ const localStories = typeof localConfig.stories === 'string' ? [localConfig.stories] : localConfig.stories;
15
+ const viteConfig = localConfig.viteConfig ? [toAbsolute(localConfig.viteConfig, options.cwd)] : [];
16
+ const patterns = [...restEntry, ...(localStories ?? stories), ...viteConfig];
17
+ return patterns.map(toEntryPattern);
18
+ };
19
+ const resolveConfig = async (localConfig, options) => {
20
+ if (localConfig.viteConfig) {
21
+ const viteConfigPath = toAbsolute(localConfig.viteConfig, options.cwd);
22
+ const viteConfig = await load(viteConfigPath);
23
+ return resolveVitestConfig(viteConfig, options);
24
+ }
25
+ return [];
26
+ };
27
+ export default {
28
+ title,
29
+ enablers,
30
+ isEnabled,
31
+ config,
32
+ entry,
33
+ project,
34
+ resolveEntryPaths,
35
+ resolveConfig,
36
+ };
@@ -0,0 +1,4 @@
1
+ export type LadleConfig = {
2
+ stories?: string | string[];
3
+ viteConfig?: string;
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
- import type { PlaywrightTestConfig } from 'playwright/test';
2
1
  import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { PlaywrightTestConfig } from './types.js';
3
3
  export declare const entry: string[];
4
4
  export declare const resolveEntryPaths: ResolveEntryPaths<PlaywrightTestConfig>;
5
5
  export declare const resolveConfig: ResolveConfig<PlaywrightTestConfig>;
@@ -0,0 +1,36 @@
1
+ type LiteralUnion<T extends U, U = string> = T | (U & {
2
+ zz_IGNORE_ME?: never;
3
+ });
4
+ type ReporterDescription = Readonly<['blob'] | ['blob', {
5
+ outputDir?: string;
6
+ fileName?: string;
7
+ }] | ['dot'] | ['line'] | ['list'] | ['list', {
8
+ printSteps?: boolean;
9
+ }] | ['github'] | ['junit'] | ['junit', {
10
+ outputFile?: string;
11
+ stripANSIControlSequences?: boolean;
12
+ includeProjectInTestName?: boolean;
13
+ }] | ['json'] | ['json', {
14
+ outputFile?: string;
15
+ }] | ['html'] | [
16
+ 'html',
17
+ {
18
+ outputFolder?: string;
19
+ open?: 'always' | 'never' | 'on-failure';
20
+ host?: string;
21
+ port?: number;
22
+ attachmentsBaseURL?: string;
23
+ }
24
+ ] | ['null'] | [string] | [string, any]>;
25
+ type Project = {
26
+ name: string;
27
+ use: string;
28
+ testMatch?: string | RegExp | (string | RegExp)[];
29
+ };
30
+ export type PlaywrightTestConfig = {
31
+ projects?: Project[];
32
+ testMatch?: string | RegExp | (string | RegExp)[];
33
+ testDir?: string;
34
+ reporter?: LiteralUnion<'dot' | 'line' | 'list' | 'junit' | 'html' | 'json' | 'github' | 'null', string> | ReporterDescription[];
35
+ };
36
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -5,7 +5,7 @@ declare const _default: {
5
5
  isEnabled: IsPluginEnabled;
6
6
  config: string[];
7
7
  entry: string[];
8
- resolveEntryPaths: import("#p/types/plugins.js").ResolveEntryPaths<import("playwright/test").PlaywrightTestConfig>;
9
- resolveConfig: import("#p/types/plugins.js").ResolveConfig<import("playwright/test").PlaywrightTestConfig>;
8
+ resolveEntryPaths: import("#p/types/plugins.js").ResolveEntryPaths<import("../playwright/types.js").PlaywrightTestConfig>;
9
+ resolveConfig: import("#p/types/plugins.js").ResolveConfig<import("../playwright/types.js").PlaywrightTestConfig>;
10
10
  };
11
11
  export default _default;
@@ -0,0 +1,12 @@
1
+ import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { ReactCosmosConfig } from './types.js';
3
+ declare const _default: {
4
+ title: string;
5
+ enablers: import("#p/types/config.js").IgnorePatterns;
6
+ isEnabled: IsPluginEnabled;
7
+ config: string[];
8
+ entry: string[];
9
+ resolveConfig: ResolveConfig<ReactCosmosConfig>;
10
+ resolveEntryPaths: ResolveEntryPaths<ReactCosmosConfig>;
11
+ };
12
+ export default _default;