knip 5.41.0 → 5.42.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.
Files changed (63) hide show
  1. package/README.md +2 -5
  2. package/dist/ConfigurationChief.d.ts +1 -0
  3. package/dist/ConfigurationValidator.d.ts +56 -0
  4. package/dist/ProjectPrincipal.js +2 -14
  5. package/dist/WorkspaceWorker.js +2 -3
  6. package/dist/compilers/index.d.ts +10 -0
  7. package/dist/constants.js +2 -0
  8. package/dist/index.js +21 -11
  9. package/dist/plugins/_template/index.js +1 -1
  10. package/dist/plugins/angular/index.js +59 -27
  11. package/dist/plugins/angular/types.d.ts +2 -2
  12. package/dist/plugins/expo/index.d.ts +3 -0
  13. package/dist/plugins/expo/index.js +6 -4
  14. package/dist/plugins/index.d.ts +20 -10
  15. package/dist/plugins/index.js +2 -0
  16. package/dist/plugins/jest/index.d.ts +3 -0
  17. package/dist/plugins/jest/index.js +4 -0
  18. package/dist/plugins/karma/helpers.d.ts +7 -0
  19. package/dist/plugins/karma/helpers.js +32 -0
  20. package/dist/plugins/karma/index.d.ts +1 -2
  21. package/dist/plugins/karma/index.js +10 -36
  22. package/dist/plugins/linthtml/index.d.ts +2 -2
  23. package/dist/plugins/linthtml/types.d.ts +1 -1
  24. package/dist/plugins/metro/index.d.ts +15 -0
  25. package/dist/plugins/metro/index.js +48 -0
  26. package/dist/plugins/metro/types.d.ts +13 -0
  27. package/dist/plugins/metro/types.js +1 -0
  28. package/dist/plugins/nx/index.js +10 -2
  29. package/dist/plugins/nx/types.d.ts +1 -0
  30. package/dist/plugins/release-it/index.d.ts +0 -1
  31. package/dist/plugins/release-it/index.js +0 -2
  32. package/dist/plugins/simple-git-hooks/index.d.ts +2 -3
  33. package/dist/plugins/simple-git-hooks/index.js +1 -9
  34. package/dist/plugins/simple-git-hooks/types.d.ts +1 -1
  35. package/dist/plugins/typescript/index.d.ts +0 -1
  36. package/dist/plugins/typescript/index.js +0 -2
  37. package/dist/plugins/vite/index.d.ts +0 -1
  38. package/dist/plugins/vite/index.js +0 -2
  39. package/dist/plugins/webpack/index.d.ts +4 -1
  40. package/dist/plugins/webpack/index.js +5 -2
  41. package/dist/plugins/wireit/index.d.ts +0 -1
  42. package/dist/plugins/wireit/index.js +0 -2
  43. package/dist/reporters/symbols.js +6 -2
  44. package/dist/schema/plugins.d.ts +23 -0
  45. package/dist/schema/plugins.js +1 -0
  46. package/dist/types/PluginNames.d.ts +2 -2
  47. package/dist/types/PluginNames.js +1 -0
  48. package/dist/types/dependency-graph.d.ts +2 -4
  49. package/dist/typescript/ast-helpers.d.ts +1 -0
  50. package/dist/typescript/ast-helpers.js +1 -0
  51. package/dist/typescript/get-imports-and-exports.d.ts +2 -4
  52. package/dist/typescript/get-imports-and-exports.js +18 -23
  53. package/dist/typescript/visitors/exports/exportAssignment.js +2 -1
  54. package/dist/typescript/visitors/exports/exportDeclaration.js +2 -1
  55. package/dist/typescript/visitors/exports/exportKeyword.js +3 -4
  56. package/dist/typescript/visitors/helpers.d.ts +1 -0
  57. package/dist/typescript/visitors/helpers.js +1 -0
  58. package/dist/util/dependency-graph.js +2 -4
  59. package/dist/util/file-entry-cache.js +3 -3
  60. package/dist/version.d.ts +1 -1
  61. package/dist/version.js +1 -1
  62. package/package.json +12 -12
  63. package/schema.json +4 -0
package/README.md CHANGED
@@ -28,9 +28,7 @@ less maintenance and easier refactorings.
28
28
 
29
29
  ## Contributors
30
30
 
31
- Special thanks to the wonderful people who have contributed to this project:
32
-
33
- [![Contributors][9]][8]
31
+ Special thanks to [the wonderful people who have contributed to Knip][8]!
34
32
 
35
33
  ## Knip
36
34
 
@@ -43,5 +41,4 @@ Special thanks to the wonderful people who have contributed to this project:
43
41
  [5]: https://github.com/webpro-nl/knip/blob/main/.github/CONTRIBUTING.md
44
42
  [6]: https://knip.dev/sponsors
45
43
  [7]: https://www.youtube.com/watch?v=PE7h7KvQoUI&t=9s
46
- [8]: https://github.com/webpro-nl/knip/graphs/contributors
47
- [9]: https://contrib.rocks/image?repo=webpro-nl/knip
44
+ [8]: https://knip.dev/#-contributors
@@ -102,6 +102,7 @@ export declare class ConfigurationChief {
102
102
  "lockfile-lint"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
103
103
  "lost-pixel"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
104
104
  markdownlint?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
105
+ metro?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
105
106
  mocha?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
106
107
  moonrepo?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
107
108
  msw?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -431,6 +431,19 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
431
431
  entry?: string | string[] | undefined;
432
432
  project?: string | string[] | undefined;
433
433
  }>]>>;
434
+ metro: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
435
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
436
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
437
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
438
+ }, "strip", z.ZodTypeAny, {
439
+ config?: string | string[] | undefined;
440
+ entry?: string | string[] | undefined;
441
+ project?: string | string[] | undefined;
442
+ }, {
443
+ config?: string | string[] | undefined;
444
+ entry?: string | string[] | undefined;
445
+ project?: string | string[] | undefined;
446
+ }>]>>;
434
447
  mocha: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
435
448
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
436
449
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -1348,6 +1361,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
1348
1361
  entry?: string | string[] | undefined;
1349
1362
  project?: string | string[] | undefined;
1350
1363
  } | undefined;
1364
+ metro?: string | boolean | string[] | {
1365
+ config?: string | string[] | undefined;
1366
+ entry?: string | string[] | undefined;
1367
+ project?: string | string[] | undefined;
1368
+ } | undefined;
1351
1369
  mocha?: string | boolean | string[] | {
1352
1370
  config?: string | string[] | undefined;
1353
1371
  entry?: string | string[] | undefined;
@@ -1802,6 +1820,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
1802
1820
  entry?: string | string[] | undefined;
1803
1821
  project?: string | string[] | undefined;
1804
1822
  } | undefined;
1823
+ metro?: string | boolean | string[] | {
1824
+ config?: string | string[] | undefined;
1825
+ entry?: string | string[] | undefined;
1826
+ project?: string | string[] | undefined;
1827
+ } | undefined;
1805
1828
  mocha?: string | boolean | string[] | {
1806
1829
  config?: string | string[] | undefined;
1807
1830
  entry?: string | string[] | undefined;
@@ -2498,6 +2521,19 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
2498
2521
  entry?: string | string[] | undefined;
2499
2522
  project?: string | string[] | undefined;
2500
2523
  }>]>>;
2524
+ metro: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
2525
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2526
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2527
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2528
+ }, "strip", z.ZodTypeAny, {
2529
+ config?: string | string[] | undefined;
2530
+ entry?: string | string[] | undefined;
2531
+ project?: string | string[] | undefined;
2532
+ }, {
2533
+ config?: string | string[] | undefined;
2534
+ entry?: string | string[] | undefined;
2535
+ project?: string | string[] | undefined;
2536
+ }>]>>;
2501
2537
  mocha: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
2502
2538
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2503
2539
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -3417,6 +3453,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
3417
3453
  entry?: string | string[] | undefined;
3418
3454
  project?: string | string[] | undefined;
3419
3455
  } | undefined;
3456
+ metro?: string | boolean | string[] | {
3457
+ config?: string | string[] | undefined;
3458
+ entry?: string | string[] | undefined;
3459
+ project?: string | string[] | undefined;
3460
+ } | undefined;
3420
3461
  mocha?: string | boolean | string[] | {
3421
3462
  config?: string | string[] | undefined;
3422
3463
  entry?: string | string[] | undefined;
@@ -3877,6 +3918,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
3877
3918
  entry?: string | string[] | undefined;
3878
3919
  project?: string | string[] | undefined;
3879
3920
  } | undefined;
3921
+ metro?: string | boolean | string[] | {
3922
+ config?: string | string[] | undefined;
3923
+ entry?: string | string[] | undefined;
3924
+ project?: string | string[] | undefined;
3925
+ } | undefined;
3880
3926
  mocha?: string | boolean | string[] | {
3881
3927
  config?: string | string[] | undefined;
3882
3928
  entry?: string | string[] | undefined;
@@ -4334,6 +4380,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
4334
4380
  entry?: string | string[] | undefined;
4335
4381
  project?: string | string[] | undefined;
4336
4382
  } | undefined;
4383
+ metro?: string | boolean | string[] | {
4384
+ config?: string | string[] | undefined;
4385
+ entry?: string | string[] | undefined;
4386
+ project?: string | string[] | undefined;
4387
+ } | undefined;
4337
4388
  mocha?: string | boolean | string[] | {
4338
4389
  config?: string | string[] | undefined;
4339
4390
  entry?: string | string[] | undefined;
@@ -4794,6 +4845,11 @@ export declare const ConfigurationValidator: z.ZodObject<z.objectUtil.extendShap
4794
4845
  entry?: string | string[] | undefined;
4795
4846
  project?: string | string[] | undefined;
4796
4847
  } | undefined;
4848
+ metro?: string | boolean | string[] | {
4849
+ config?: string | string[] | undefined;
4850
+ entry?: string | string[] | undefined;
4851
+ project?: string | string[] | undefined;
4852
+ } | undefined;
4797
4853
  mocha?: string | boolean | string[] | {
4798
4854
  config?: string | string[] | undefined;
4799
4855
  entry?: string | string[] | undefined;
@@ -155,10 +155,7 @@ export class ProjectPrincipal {
155
155
  throw new Error(`Unable to find ${filePath}`);
156
156
  const skipExports = this.skipExportsAnalysis.has(filePath);
157
157
  const resolve = (specifier) => this.backend.resolveModuleNames([specifier], sourceFile.fileName)[0];
158
- const { imports, exports, scripts, traceRefs } = _getImportsAndExports(sourceFile, resolve, typeChecker, {
159
- ...options,
160
- skipExports,
161
- });
158
+ const { imports, ...rest } = _getImportsAndExports(sourceFile, resolve, typeChecker, { ...options, skipExports });
162
159
  const { internal, resolved, specifiers, unresolved, external } = imports;
163
160
  const unresolvedImports = new Set();
164
161
  for (const [specifier, specifierFilePath] of specifiers) {
@@ -194,16 +191,7 @@ export class ProjectPrincipal {
194
191
  }
195
192
  }
196
193
  }
197
- return {
198
- imports: {
199
- internal,
200
- unresolved: unresolvedImports,
201
- external,
202
- },
203
- exports,
204
- scripts,
205
- traceRefs,
206
- };
194
+ return { imports: { internal, unresolved: unresolvedImports, external }, ...rest };
207
195
  }
208
196
  invalidateFile(filePath) {
209
197
  this.backend.fileManager.snapshotCache.delete(filePath);
@@ -201,7 +201,6 @@ export class WorkspaceWorker {
201
201
  const plugin = Plugins[pluginName];
202
202
  const hasResolveEntryPaths = typeof plugin.resolveEntryPaths === 'function';
203
203
  const hasResolveConfig = typeof plugin.resolveConfig === 'function';
204
- const shouldRunConfigResolver = hasResolveConfig && (!isProduction || (isProduction && 'production' in plugin));
205
204
  const hasResolve = typeof plugin.resolve === 'function';
206
205
  const config = this.getConfigForPlugin(pluginName);
207
206
  if (!config)
@@ -228,7 +227,7 @@ export class WorkspaceWorker {
228
227
  configFileDir: dirname(configFilePath),
229
228
  configFileName: basename(configFilePath),
230
229
  };
231
- if (hasResolveEntryPaths || shouldRunConfigResolver) {
230
+ if (hasResolveEntryPaths || hasResolveConfig) {
232
231
  const isManifest = basename(configFilePath) === 'package.json';
233
232
  const fd = isManifest ? undefined : this.cache.getFileDescriptor(configFilePath);
234
233
  if (fd?.meta?.data && !fd.changed) {
@@ -249,7 +248,7 @@ export class WorkspaceWorker {
249
248
  configEntryPaths.push(entryPath);
250
249
  data.resolveEntryPaths = entryPaths;
251
250
  }
252
- if (shouldRunConfigResolver) {
251
+ if (hasResolveConfig) {
253
252
  const inputs = (await plugin.resolveConfig?.(config, opts)) ?? [];
254
253
  for (const input of inputs) {
255
254
  if (isConfigPattern(input))
@@ -168,6 +168,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
168
168
  entry?: string | string[] | undefined;
169
169
  project?: string | string[] | undefined;
170
170
  } | undefined;
171
+ metro?: string | boolean | string[] | {
172
+ config?: string | string[] | undefined;
173
+ entry?: string | string[] | undefined;
174
+ project?: string | string[] | undefined;
175
+ } | undefined;
171
176
  mocha?: string | boolean | string[] | {
172
177
  config?: string | string[] | undefined;
173
178
  entry?: string | string[] | undefined;
@@ -626,6 +631,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
626
631
  entry?: string | string[] | undefined;
627
632
  project?: string | string[] | undefined;
628
633
  } | undefined;
634
+ metro?: string | boolean | string[] | {
635
+ config?: string | string[] | undefined;
636
+ entry?: string | string[] | undefined;
637
+ project?: string | string[] | undefined;
638
+ } | undefined;
629
639
  mocha?: string | boolean | string[] | {
630
640
  config?: string | string[] | undefined;
631
641
  entry?: string | string[] | undefined;
package/dist/constants.js CHANGED
@@ -84,6 +84,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
84
84
  'pwd',
85
85
  'rm',
86
86
  'rmdir',
87
+ 'rsync',
87
88
  'scp',
88
89
  'seq',
89
90
  'set',
@@ -119,6 +120,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
119
120
  'xvfb-run',
120
121
  'yarn',
121
122
  'yes',
123
+ 'zip',
122
124
  ]);
123
125
  export const IGNORED_DEPENDENCIES = new Set(['knip', 'typescript']);
124
126
  export const IGNORED_RUNTIME_DEPENDENCIES = new Set(['node', 'bun', 'deno']);
package/dist/index.js CHANGED
@@ -232,7 +232,7 @@ export const main = async (unresolvedConfiguration) => {
232
232
  analyzedFiles.add(filePath);
233
233
  const workspace = chief.findWorkspaceByFilePath(filePath);
234
234
  if (workspace) {
235
- const { imports, exports, scripts, traceRefs } = principal.analyzeSourceFile(filePath, {
235
+ const { imports, exports, duplicates, scripts, traceRefs } = principal.analyzeSourceFile(filePath, {
236
236
  skipTypeOnly: isStrict,
237
237
  isFixExports: fixer.isEnabled && fixer.isFixUnusedExports,
238
238
  isFixTypes: fixer.isEnabled && fixer.isFixUnusedTypes,
@@ -243,6 +243,7 @@ export const main = async (unresolvedConfiguration) => {
243
243
  const file = getOrCreateFileNode(graph, filePath);
244
244
  file.imports = imports;
245
245
  file.exports = exports;
246
+ file.duplicates = duplicates;
246
247
  file.scripts = scripts;
247
248
  file.traceRefs = traceRefs;
248
249
  updateImportMap(file, imports.internal, graph);
@@ -270,7 +271,10 @@ export const main = async (unresolvedConfiguration) => {
270
271
  }
271
272
  }
272
273
  };
273
- for (const principal of principals) {
274
+ for (let i = 0; i < principals.length; ++i) {
275
+ const principal = principals[i];
276
+ if (!principal)
277
+ continue;
274
278
  principal.init();
275
279
  streamer.cast('Running async compilers...');
276
280
  await principal.runAsyncCompilers();
@@ -281,7 +285,7 @@ export const main = async (unresolvedConfiguration) => {
281
285
  size = principal.entryPaths.size;
282
286
  const resolvedFiles = principal.getUsedResolvedFiles();
283
287
  const files = resolvedFiles.filter(filePath => !analyzedFiles.has(filePath));
284
- debugLogArray('*', `Analyzing used resolved files [P${principals.indexOf(principal) + 1}/${++round}]`, files);
288
+ debugLogArray('*', `Analyzing used resolved files [P${i + 1}/${++round}]`, files);
285
289
  for (const filePath of files)
286
290
  analyzeSourceFile(filePath, principal);
287
291
  } while (size !== principal.entryPaths.size);
@@ -290,12 +294,18 @@ export const main = async (unresolvedConfiguration) => {
290
294
  for (const filePath of principal.entryPaths)
291
295
  entryPaths.add(filePath);
292
296
  principal.reconcileCache(graph);
293
- if (!isIsolateWorkspaces && isSkipLibs && !isWatch)
297
+ if (!isIsolateWorkspaces && isSkipLibs && !isWatch) {
294
298
  factory.deletePrincipal(principal);
299
+ principals[i] = undefined;
300
+ }
301
+ }
302
+ if (isIsolateWorkspaces) {
303
+ for (const principal of principals) {
304
+ if (principal)
305
+ factory.deletePrincipal(principal);
306
+ }
307
+ principals.length = 0;
295
308
  }
296
- if (isIsolateWorkspaces)
297
- for (const principal of principals)
298
- factory.deletePrincipal(principal);
299
309
  const ignoreExportsUsedInFile = chief.config.ignoreExportsUsedInFile;
300
310
  const isExportedItemReferenced = (exportedItem) => exportedItem.refs[1] ||
301
311
  (exportedItem.refs[0] > 0 &&
@@ -306,7 +316,7 @@ export const main = async (unresolvedConfiguration) => {
306
316
  if (isReportValues || isReportTypes) {
307
317
  streamer.cast('Connecting the dots...');
308
318
  for (const [filePath, file] of graph.entries()) {
309
- const exportItems = file.exports?.exported;
319
+ const exportItems = file.exports;
310
320
  if (!exportItems || exportItems.size === 0)
311
321
  continue;
312
322
  const workspace = chief.findWorkspaceByFilePath(filePath);
@@ -341,7 +351,7 @@ export const main = async (unresolvedConfiguration) => {
341
351
  createAndPrintTrace(filePath, { identifier, isEntry, hasRef: isReferenced });
342
352
  continue;
343
353
  }
344
- const reExportedItem = graph.get(reExportingEntryFile)?.exports.exported.get(identifier);
354
+ const reExportedItem = graph.get(reExportingEntryFile)?.exports.get(identifier);
345
355
  if (reExportedItem && shouldIgnore(reExportedItem.jsDocTags))
346
356
  continue;
347
357
  }
@@ -450,8 +460,8 @@ export const main = async (unresolvedConfiguration) => {
450
460
  for (const [filePath, file] of graph.entries()) {
451
461
  const ws = chief.findWorkspaceByFilePath(filePath);
452
462
  if (ws) {
453
- if (file.exports?.duplicate) {
454
- for (const symbols of file.exports.duplicate) {
463
+ if (file.duplicates) {
464
+ for (const symbols of file.duplicates) {
455
465
  if (symbols.length > 1) {
456
466
  const symbol = symbols.map(s => s.symbol).join('|');
457
467
  collector.addIssue({ type: 'duplicates', filePath, workspace: ws.name, symbol, symbols });
@@ -1,6 +1,6 @@
1
1
  import { toDeferResolve } from '../../util/input.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
- const title = '_template';
3
+ const title = '__PLUGIN_NAME__';
4
4
  const enablers = ['__PLUGIN_NAME__'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
6
  const config = [];
@@ -1,6 +1,7 @@
1
1
  import { toConfig, toDependency, toEntry, toProductionEntry } from '../../util/input.js';
2
2
  import { join } from '../../util/path.js';
3
3
  import { hasDependency } from '../../util/plugin.js';
4
+ import * as karma from '../karma/helpers.js';
4
5
  const title = 'Angular';
5
6
  const enablers = ['@angular/cli'];
6
7
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -13,50 +14,81 @@ const resolveConfig = async (config, options) => {
13
14
  for (const project of Object.values(config.projects)) {
14
15
  if (!project.architect)
15
16
  return [];
16
- for (const target of Object.values(project.architect)) {
17
+ for (const [targetName, target] of Object.entries(project.architect)) {
17
18
  const { options: opts, configurations: configs } = target;
18
19
  const [packageName] = typeof target.builder === 'string' ? target.builder.split(':') : [];
19
20
  if (typeof packageName === 'string')
20
21
  inputs.add(toDependency(packageName));
21
22
  if (opts) {
22
- if ('main' in opts && typeof opts.main === 'string') {
23
- inputs.add(toProductionEntry(join(cwd, opts.main)));
24
- }
25
- if ('browser' in opts && typeof opts.browser === 'string') {
26
- inputs.add(toProductionEntry(join(cwd, opts.browser)));
27
- }
28
- if ('ssr' in opts && opts.ssr && typeof opts.ssr === 'object') {
29
- if ('entry' in opts.ssr && typeof opts.ssr.entry === 'string') {
30
- inputs.add(toProductionEntry(join(cwd, opts.ssr.entry)));
31
- }
32
- }
33
23
  if ('tsConfig' in opts && typeof opts.tsConfig === 'string') {
34
24
  inputs.add(toConfig('typescript', opts.tsConfig, configFilePath));
35
25
  }
36
- if ('server' in opts && opts.server && typeof opts.server === 'string') {
37
- inputs.add(toProductionEntry(join(cwd, opts.server)));
38
- }
39
- if ('fileReplacements' in opts && opts.fileReplacements && Array.isArray(opts.fileReplacements)) {
40
- for (const fileReplacedBy of filesReplacedBy(opts.fileReplacements)) {
41
- inputs.add(toEntry(fileReplacedBy));
26
+ }
27
+ const defaultEntriesByOption = opts ? entriesByOption(opts) : new Map();
28
+ const entriesByOptionByConfig = new Map(configs ? Object.entries(configs).map(([name, opts]) => [name, entriesByOption(opts)]) : []);
29
+ const productionEntriesByOption = entriesByOptionByConfig.get(PRODUCTION_CONFIG_NAME) ?? new Map();
30
+ const normalizePath = (path) => join(cwd, path);
31
+ for (const [configName, entriesByOption] of entriesByOptionByConfig.entries()) {
32
+ for (const entries of entriesByOption.values()) {
33
+ for (const entry of entries) {
34
+ inputs.add(targetName === BUILD_TARGET_NAME && configName === PRODUCTION_CONFIG_NAME
35
+ ? toProductionEntry(normalizePath(entry))
36
+ : toEntry(normalizePath(entry)));
42
37
  }
43
38
  }
44
39
  }
45
- if (configs) {
46
- for (const [configName, config] of Object.entries(configs)) {
47
- const isProductionConfig = configName === 'production';
48
- if ('fileReplacements' in config && config.fileReplacements && Array.isArray(config.fileReplacements)) {
49
- for (const fileReplacedBy of filesReplacedBy(config.fileReplacements)) {
50
- inputs.add(isProductionConfig ? toProductionEntry(fileReplacedBy) : toEntry(fileReplacedBy));
51
- }
52
- }
40
+ for (const [option, entries] of defaultEntriesByOption.entries()) {
41
+ for (const entry of entries) {
42
+ inputs.add(targetName === BUILD_TARGET_NAME && !productionEntriesByOption.get(option)?.length
43
+ ? toProductionEntry(normalizePath(entry))
44
+ : toEntry(normalizePath(entry)));
45
+ }
46
+ }
47
+ if (target.builder === '@angular-devkit/build-angular:karma' && opts) {
48
+ const karmaBuilderOptions = opts;
49
+ const testFilePatterns = karmaBuilderOptions.include ?? ['**/*.spec.ts'];
50
+ for (const testFilePattern of testFilePatterns) {
51
+ inputs.add(toEntry(testFilePattern));
52
+ }
53
+ const excludedTestFilePatterns = karmaBuilderOptions.exclude ?? [];
54
+ for (const excludedTestFilePattern of excludedTestFilePatterns) {
55
+ inputs.add(toEntry(`!${excludedTestFilePattern}`));
56
+ }
57
+ const karmaConfig = karmaBuilderOptions.karmaConfig;
58
+ if (!karmaConfig) {
59
+ karma
60
+ .inputsFromPlugins(['karma-jasmine', 'karma-chrome-launcher', 'karma-jasmine-html-reporter', 'karma-coverage'], options.manifest.devDependencies)
61
+ .forEach(inputs.add, inputs);
62
+ karma.inputsFromFrameworks(['jasmine']).forEach(inputs.add, inputs);
63
+ }
64
+ if (karmaConfig && !karma.configFiles.includes(karmaConfig)) {
65
+ inputs.add(toConfig('karma', karmaConfig, options.configFilePath));
53
66
  }
54
67
  }
55
68
  }
56
69
  }
57
70
  return Array.from(inputs);
58
71
  };
59
- const filesReplacedBy = (fileReplacements) => fileReplacements.map(fileReplacement => 'with' in fileReplacement ? fileReplacement.with : fileReplacement.replaceWith);
72
+ const entriesByOption = (opts) => new Map(Object.entries({
73
+ main: 'main' in opts && opts.main && typeof opts.main === 'string' ? [opts.main] : [],
74
+ scripts: 'scripts' in opts && opts.scripts && Array.isArray(opts.scripts)
75
+ ? opts.scripts.map(scriptStringOrObject => typeof scriptStringOrObject === 'string' ? scriptStringOrObject : scriptStringOrObject.input)
76
+ : [],
77
+ fileReplacements: 'fileReplacements' in opts && opts.fileReplacements && Array.isArray(opts.fileReplacements)
78
+ ? opts.fileReplacements.map(fileReplacement => 'with' in fileReplacement ? fileReplacement.with : fileReplacement.replaceWith)
79
+ : [],
80
+ browser: 'browser' in opts && opts.browser && typeof opts.browser === 'string' ? [opts.browser] : [],
81
+ server: 'server' in opts && opts.server && typeof opts.server === 'string' ? [opts.server] : [],
82
+ ssrEntry: 'ssr' in opts &&
83
+ opts.ssr &&
84
+ typeof opts.ssr === 'object' &&
85
+ 'entry' in opts.ssr &&
86
+ typeof opts.ssr.entry === 'string'
87
+ ? [opts.ssr.entry]
88
+ : [],
89
+ }));
90
+ const PRODUCTION_CONFIG_NAME = 'production';
91
+ const BUILD_TARGET_NAME = 'build';
60
92
  export default {
61
93
  title,
62
94
  enablers,
@@ -1,5 +1,5 @@
1
1
  type FileVersion = number;
2
- type Project = Project1 & {
2
+ export type Project = Project1 & {
3
3
  cli?: {
4
4
  [k: string]: unknown;
5
5
  };
@@ -869,7 +869,7 @@ interface ExtractI18NTarget1 {
869
869
  outputPath?: string;
870
870
  outFile?: string;
871
871
  }
872
- interface KarmaTarget {
872
+ export interface KarmaTarget {
873
873
  main?: string;
874
874
  tsConfig: string;
875
875
  karmaConfig?: string;
@@ -1,5 +1,8 @@
1
1
  import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '../../types/config.js';
2
2
  import type { ExpoConfig } from './types.js';
3
+ export declare const docs: {
4
+ production: string[];
5
+ };
3
6
  declare const _default: {
4
7
  title: string;
5
8
  enablers: string[];
@@ -6,21 +6,23 @@ const title = 'Expo';
6
6
  const enablers = ['expo'];
7
7
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
8
  const config = ['app.json', 'app.config.{ts,js}'];
9
+ const production = ['app/**/*.{js,jsx,ts,tsx}', 'src/app/**/*.{js,jsx,ts,tsx}'];
10
+ export const docs = { production };
9
11
  const resolveEntryPaths = async (expoConfig, { manifest }) => {
10
12
  const config = 'expo' in expoConfig ? expoConfig.expo : expoConfig;
11
- let production = [];
13
+ let patterns = [];
12
14
  if (manifest.main === 'expo-router/entry') {
13
- production = ['app/**/*.{js,jsx,ts,tsx}', 'src/app/**/*.{js,jsx,ts,tsx}'];
15
+ patterns = [...production];
14
16
  const normalizedPlugins = config.plugins?.map(plugin => (Array.isArray(plugin) ? plugin : [plugin])) ?? [];
15
17
  const expoRouterPlugin = normalizedPlugins.find(([plugin]) => plugin === 'expo-router');
16
18
  if (expoRouterPlugin) {
17
19
  const [, options] = expoRouterPlugin;
18
20
  if (typeof options?.root === 'string') {
19
- production = [join(options.root, '**/*.{js,jsx,ts,tsx}')];
21
+ patterns = [join(options.root, '**/*.{js,jsx,ts,tsx}')];
20
22
  }
21
23
  }
22
24
  }
23
- return production.map(entry => toProductionEntry(entry));
25
+ return patterns.map(entry => toProductionEntry(entry));
24
26
  };
25
27
  const resolveConfig = async (expoConfig, options) => getDependencies(expoConfig, options);
26
28
  export default {
@@ -184,6 +184,9 @@ export declare const Plugins: {
184
184
  entry: string[];
185
185
  resolveEntryPaths: import("../types/config.js").ResolveEntryPaths<import("./jest/types.js").JestConfig>;
186
186
  resolveConfig: import("../types/config.js").ResolveConfig<import("./jest/types.js").JestConfig>;
187
+ args: {
188
+ config: boolean;
189
+ };
187
190
  };
188
191
  karma: {
189
192
  title: string;
@@ -191,8 +194,8 @@ export declare const Plugins: {
191
194
  isEnabled: import("../types/config.js").IsPluginEnabled;
192
195
  config: string[];
193
196
  entry: string[];
194
- resolveConfig: import("../types/config.js").ResolveConfig<(config: import("./karma/types.js").Config) => void>;
195
- resolveEntryPaths: import("../types/config.js").ResolveEntryPaths<(config: import("./karma/types.js").Config) => void>;
197
+ resolveConfig: import("../types/config.js").ResolveConfig<import("./karma/helpers.js").ConfigFile>;
198
+ resolveEntryPaths: import("../types/config.js").ResolveEntryPaths<import("./karma/helpers.js").ConfigFile>;
196
199
  };
197
200
  ladle: {
198
201
  title: string;
@@ -225,7 +228,7 @@ export declare const Plugins: {
225
228
  isEnabled: import("../types/config.js").IsPluginEnabled;
226
229
  packageJsonPath: string;
227
230
  config: string[];
228
- resolveConfig: import("../types/config.js").ResolveConfig<import("./linthtml/types.js").PluginConfig>;
231
+ resolveConfig: import("../types/config.js").ResolveConfig<import("./linthtml/types.js").LintHTMLConfig>;
229
232
  };
230
233
  'lockfile-lint': {
231
234
  title: string;
@@ -246,6 +249,15 @@ export declare const Plugins: {
246
249
  config: string[];
247
250
  resolveConfig: import("../types/config.js").ResolveConfig<import("./markdownlint/types.js").MarkdownlintConfig>;
248
251
  };
252
+ metro: {
253
+ title: string;
254
+ note: string;
255
+ enablers: string[];
256
+ isEnabled: import("../types/config.js").IsPluginEnabled;
257
+ config: string[];
258
+ resolveEntryPaths: import("../types/config.js").ResolveEntryPaths<import("./metro/types.js").MetroConfig>;
259
+ resolveConfig: import("../types/config.js").ResolveConfig<import("./metro/types.js").MetroConfig>;
260
+ };
249
261
  mocha: {
250
262
  title: string;
251
263
  enablers: string[];
@@ -441,7 +453,6 @@ export declare const Plugins: {
441
453
  title: string;
442
454
  enablers: string[];
443
455
  isEnabled: import("../types/config.js").IsPluginEnabled;
444
- packageJsonPath: string;
445
456
  config: string[];
446
457
  resolveConfig: import("../types/config.js").ResolveConfig<import("./release-it/types.js").ReleaseItConfig>;
447
458
  };
@@ -500,9 +511,8 @@ export declare const Plugins: {
500
511
  title: string;
501
512
  enablers: string[];
502
513
  isEnabled: import("../types/config.js").IsPluginEnabled;
503
- packageJsonPath: string;
504
514
  config: string[];
505
- resolveConfig: import("../types/config.js").ResolveConfig<import("./simple-git-hooks/types.js").PluginConfig>;
515
+ resolveConfig: import("../types/config.js").ResolveConfig<import("./simple-git-hooks/types.js").SimpleGitHooksConfig>;
506
516
  };
507
517
  'size-limit': {
508
518
  title: string;
@@ -611,7 +621,6 @@ export declare const Plugins: {
611
621
  enablers: string[];
612
622
  isEnabled: import("../types/config.js").IsPluginEnabled;
613
623
  config: string[];
614
- production: string[];
615
624
  resolveConfig: import("../types/config.js").ResolveConfig<import("type-fest").TsConfigJson>;
616
625
  args: {
617
626
  binaries: string[];
@@ -652,7 +661,6 @@ export declare const Plugins: {
652
661
  enablers: string[];
653
662
  isEnabled: import("../types/config.js").IsPluginEnabled;
654
663
  config: string[];
655
- production: string[];
656
664
  resolveEntryPaths: import("../types/config.js").ResolveEntryPaths<import("./vitest/types.js").ViteConfigOrFn | import("./vitest/types.js").VitestWorkspaceConfig>;
657
665
  resolveConfig: import("../types/config.js").ResolveConfig<import("./vitest/types.js").ViteConfigOrFn | import("./vitest/types.js").VitestWorkspaceConfig>;
658
666
  };
@@ -687,14 +695,16 @@ export declare const Plugins: {
687
695
  enablers: string[];
688
696
  isEnabled: import("../types/config.js").IsPluginEnabled;
689
697
  config: string[];
690
- production: string[];
691
698
  resolveConfig: import("../types/config.js").ResolveConfig<import("./webpack/types.js").WebpackConfig>;
699
+ args: {
700
+ binaries: string[];
701
+ config: boolean;
702
+ };
692
703
  };
693
704
  wireit: {
694
705
  title: string;
695
706
  enablers: string[];
696
707
  isEnabled: import("../types/config.js").IsPluginEnabled;
697
- packageJsonPath: string;
698
708
  config: string[];
699
709
  resolveConfig: import("../types/config.js").ResolveConfig<import("./wireit/types.js").WireitConfig>;
700
710
  };
@@ -29,6 +29,7 @@ import { default as linthtml } from './linthtml/index.js';
29
29
  import { default as lockfileLint } from './lockfile-lint/index.js';
30
30
  import { default as lostPixel } from './lost-pixel/index.js';
31
31
  import { default as markdownlint } from './markdownlint/index.js';
32
+ import { default as metro } from './metro/index.js';
32
33
  import { default as mocha } from './mocha/index.js';
33
34
  import { default as moonrepo } from './moonrepo/index.js';
34
35
  import { default as msw } from './msw/index.js';
@@ -119,6 +120,7 @@ export const Plugins = {
119
120
  'lockfile-lint': lockfileLint,
120
121
  'lost-pixel': lostPixel,
121
122
  markdownlint,
123
+ metro,
122
124
  mocha,
123
125
  moonrepo,
124
126
  msw,
@@ -8,5 +8,8 @@ declare const _default: {
8
8
  entry: string[];
9
9
  resolveEntryPaths: ResolveEntryPaths<JestConfig>;
10
10
  resolveConfig: ResolveConfig<JestConfig>;
11
+ args: {
12
+ config: boolean;
13
+ };
11
14
  };
12
15
  export default _default;
@@ -95,6 +95,9 @@ const resolveConfig = async (localConfig, options) => {
95
95
  });
96
96
  return result;
97
97
  };
98
+ const args = {
99
+ config: true,
100
+ };
98
101
  export default {
99
102
  title,
100
103
  enablers,
@@ -103,4 +106,5 @@ export default {
103
106
  entry,
104
107
  resolveEntryPaths,
105
108
  resolveConfig,
109
+ args,
106
110
  };