@package-pal/core 0.0.3 → 0.0.7

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 (151) hide show
  1. package/index.d.ts +17 -0
  2. package/index.d.ts.map +1 -0
  3. package/index.js +214 -192
  4. package/index.js.map +24 -22
  5. package/lib/api.d.ts +50 -0
  6. package/lib/api.d.ts.map +1 -0
  7. package/lib/configuration/functions/check-bun.d.ts +2 -0
  8. package/lib/configuration/functions/check-bun.d.ts.map +1 -0
  9. package/lib/configuration/functions/get-default-logger.d.ts +4 -0
  10. package/lib/configuration/functions/get-default-logger.d.ts.map +1 -0
  11. package/lib/configuration/functions/is-root-dir.d.ts +2 -0
  12. package/lib/configuration/functions/is-root-dir.d.ts.map +1 -0
  13. package/lib/configuration/functions/load-config.d.ts +3 -0
  14. package/lib/configuration/functions/load-config.d.ts.map +1 -0
  15. package/lib/configuration/functions/parse-config.d.ts +29 -0
  16. package/lib/configuration/functions/parse-config.d.ts.map +1 -0
  17. package/lib/configuration/functions/search-config-path.d.ts +2 -0
  18. package/lib/configuration/functions/search-config-path.d.ts.map +1 -0
  19. package/lib/configuration/functions/validate-config-path.d.ts +6 -0
  20. package/lib/configuration/functions/validate-config-path.d.ts.map +1 -0
  21. package/lib/configuration/functions/z-loose-function.d.ts +3 -0
  22. package/lib/configuration/functions/z-loose-function.d.ts.map +1 -0
  23. package/lib/configuration/functions/z-loose-object-without-index-signature.d.ts +4 -0
  24. package/lib/configuration/functions/z-loose-object-without-index-signature.d.ts.map +1 -0
  25. package/lib/configuration/schemas/config.d.ts +131 -0
  26. package/lib/configuration/schemas/config.d.ts.map +1 -0
  27. package/lib/configuration/types/activated-config.d.ts +9 -0
  28. package/lib/configuration/types/activated-config.d.ts.map +1 -0
  29. package/lib/configuration/types/config-validation-result.d.ts +10 -0
  30. package/lib/configuration/types/config-validation-result.d.ts.map +1 -0
  31. package/lib/configuration/types/config.d.ts +26 -0
  32. package/lib/configuration/types/config.d.ts.map +1 -0
  33. package/lib/configuration/types/logger.d.ts +7 -0
  34. package/lib/configuration/types/logger.d.ts.map +1 -0
  35. package/lib/configuration/types/packages-ready-callback-props.d.ts +7 -0
  36. package/lib/configuration/types/packages-ready-callback-props.d.ts.map +1 -0
  37. package/lib/configuration/types/process-package-callback-props.d.ts +10 -0
  38. package/lib/configuration/types/process-package-callback-props.d.ts.map +1 -0
  39. package/lib/configuration/types/subprocess-callback.d.ts +2 -0
  40. package/lib/configuration/types/subprocess-callback.d.ts.map +1 -0
  41. package/lib/configuration/types/supported-config-type.d.ts +11 -0
  42. package/lib/configuration/types/supported-config-type.d.ts.map +1 -0
  43. package/lib/graph/functions/dfs-traverse-graph-paths.d.ts +3 -0
  44. package/lib/graph/functions/dfs-traverse-graph-paths.d.ts.map +1 -0
  45. package/lib/graph/functions/dfs-traverse-graph.d.ts +4 -0
  46. package/lib/graph/functions/dfs-traverse-graph.d.ts.map +1 -0
  47. package/lib/graph/functions/extract-subgraph.d.ts +3 -0
  48. package/lib/graph/functions/extract-subgraph.d.ts.map +1 -0
  49. package/lib/graph/functions/generate-graphs.d.ts +8 -0
  50. package/lib/graph/functions/generate-graphs.d.ts.map +1 -0
  51. package/lib/graph/functions/generate-package-circular-dependency-paths.d.ts +5 -0
  52. package/lib/graph/functions/generate-package-circular-dependency-paths.d.ts.map +1 -0
  53. package/lib/graph/functions/generate-topological-ranking-range.d.ts +3 -0
  54. package/lib/graph/functions/generate-topological-ranking-range.d.ts.map +1 -0
  55. package/lib/graph/functions/generate-topological-ranking.d.ts +2 -0
  56. package/lib/graph/functions/generate-topological-ranking.d.ts.map +1 -0
  57. package/lib/graph/functions/generate-topological-sorted-groups.d.ts +5 -0
  58. package/lib/graph/functions/generate-topological-sorted-groups.d.ts.map +1 -0
  59. package/lib/graph/functions/is-disjoint.d.ts +3 -0
  60. package/lib/graph/functions/is-disjoint.d.ts.map +1 -0
  61. package/lib/graph/functions/is-ranked-greater-than-or-equal.d.ts +3 -0
  62. package/lib/graph/functions/is-ranked-greater-than-or-equal.d.ts.map +1 -0
  63. package/lib/graph/functions/is-subgraph.d.ts +3 -0
  64. package/lib/graph/functions/is-subgraph.d.ts.map +1 -0
  65. package/lib/graph/functions/merge-graphs.d.ts +3 -0
  66. package/lib/graph/functions/merge-graphs.d.ts.map +1 -0
  67. package/lib/graph/types/package-graph.d.ts +3 -0
  68. package/lib/graph/types/package-graph.d.ts.map +1 -0
  69. package/lib/graph/types/package-graphs.d.ts +6 -0
  70. package/lib/graph/types/package-graphs.d.ts.map +1 -0
  71. package/lib/graph/types/package-node.d.ts +6 -0
  72. package/lib/graph/types/package-node.d.ts.map +1 -0
  73. package/lib/graph/types/package-order.d.ts +14 -0
  74. package/lib/graph/types/package-order.d.ts.map +1 -0
  75. package/lib/package/functions/load-packages.d.ts +4 -0
  76. package/lib/package/functions/load-packages.d.ts.map +1 -0
  77. package/lib/package/functions/parse-package.d.ts +3 -0
  78. package/lib/package/functions/parse-package.d.ts.map +1 -0
  79. package/lib/package/functions/run-for-each-package.d.ts +6 -0
  80. package/lib/package/functions/run-for-each-package.d.ts.map +1 -0
  81. package/lib/package/functions/scan-package-paths.d.ts +2 -0
  82. package/lib/package/functions/scan-package-paths.d.ts.map +1 -0
  83. package/lib/package/functions/scan-packages.d.ts +4 -0
  84. package/lib/package/functions/scan-packages.d.ts.map +1 -0
  85. package/lib/package/functions/update-package-version.d.ts +5 -0
  86. package/lib/package/functions/update-package-version.d.ts.map +1 -0
  87. package/lib/package/types/dependencies-field.d.ts +9 -0
  88. package/lib/package/types/dependencies-field.d.ts.map +1 -0
  89. package/lib/package/types/package-data.d.ts +12 -0
  90. package/lib/package/types/package-data.d.ts.map +1 -0
  91. package/lib/process/functions/get-commands-for-shell.d.ts +2 -0
  92. package/lib/process/functions/get-commands-for-shell.d.ts.map +1 -0
  93. package/lib/process/functions/get-line-buffered-writer.d.ts +2 -0
  94. package/lib/process/functions/get-line-buffered-writer.d.ts.map +1 -0
  95. package/lib/process/functions/parse-ps-shell-flags.d.ts +9 -0
  96. package/lib/process/functions/parse-ps-shell-flags.d.ts.map +1 -0
  97. package/lib/process/functions/read-stream.d.ts +2 -0
  98. package/lib/process/functions/read-stream.d.ts.map +1 -0
  99. package/lib/process/functions/run-subprocess.d.ts +11 -0
  100. package/lib/process/functions/run-subprocess.d.ts.map +1 -0
  101. package/lib/process/types/exit-state.d.ts +8 -0
  102. package/lib/process/types/exit-state.d.ts.map +1 -0
  103. package/lib/process/types/std-type.d.ts +7 -0
  104. package/lib/process/types/std-type.d.ts.map +1 -0
  105. package/lib/types/bump-package-version-options.d.ts +11 -0
  106. package/lib/types/bump-package-version-options.d.ts.map +1 -0
  107. package/lib/types/bump-version-type.d.ts +12 -0
  108. package/lib/types/bump-version-type.d.ts.map +1 -0
  109. package/lib/types/config-options.d.ts +5 -0
  110. package/lib/types/config-options.d.ts.map +1 -0
  111. package/lib/types/for-each-command-callback.d.ts +6 -0
  112. package/lib/types/for-each-command-callback.d.ts.map +1 -0
  113. package/lib/types/for-each-package-options.d.ts +11 -0
  114. package/lib/types/for-each-package-options.d.ts.map +1 -0
  115. package/lib/types/get-config-options.d.ts +5 -0
  116. package/lib/types/get-config-options.d.ts.map +1 -0
  117. package/lib/types/get-package-circular-dependency-paths-options.d.ts +6 -0
  118. package/lib/types/get-package-circular-dependency-paths-options.d.ts.map +1 -0
  119. package/lib/types/get-package-data-options.d.ts +6 -0
  120. package/lib/types/get-package-data-options.d.ts.map +1 -0
  121. package/lib/types/get-package-graph-options.d.ts +5 -0
  122. package/lib/types/get-package-graph-options.d.ts.map +1 -0
  123. package/lib/types/get-package-order-options.d.ts +5 -0
  124. package/lib/types/get-package-order-options.d.ts.map +1 -0
  125. package/lib/types/package-data-options.d.ts +5 -0
  126. package/lib/types/package-data-options.d.ts.map +1 -0
  127. package/lib/types/package-graphs-options.d.ts +5 -0
  128. package/lib/types/package-graphs-options.d.ts.map +1 -0
  129. package/lib/types/package-name-options.d.ts +4 -0
  130. package/lib/types/package-name-options.d.ts.map +1 -0
  131. package/lib/types/package-order-options.d.ts +5 -0
  132. package/lib/types/package-order-options.d.ts.map +1 -0
  133. package/lib/types/root-dir-options.d.ts +4 -0
  134. package/lib/types/root-dir-options.d.ts.map +1 -0
  135. package/lib/types/watch-packages-options.d.ts +7 -0
  136. package/lib/types/watch-packages-options.d.ts.map +1 -0
  137. package/lib/watch/functions/filter-files-modified-since.d.ts +2 -0
  138. package/lib/watch/functions/filter-files-modified-since.d.ts.map +1 -0
  139. package/lib/watch/functions/get-change-logic.d.ts +11 -0
  140. package/lib/watch/functions/get-change-logic.d.ts.map +1 -0
  141. package/lib/watch/functions/normalise-pattern-separators.d.ts +2 -0
  142. package/lib/watch/functions/normalise-pattern-separators.d.ts.map +1 -0
  143. package/lib/watch/functions/normalise-watched-file-path.d.ts +2 -0
  144. package/lib/watch/functions/normalise-watched-file-path.d.ts.map +1 -0
  145. package/lib/watch/functions/watch-package-changes.d.ts +8 -0
  146. package/lib/watch/functions/watch-package-changes.d.ts.map +1 -0
  147. package/lib/watch/types/change-action.d.ts +8 -0
  148. package/lib/watch/types/change-action.d.ts.map +1 -0
  149. package/lib/watch/types/package-changes.d.ts +2 -0
  150. package/lib/watch/types/package-changes.d.ts.map +1 -0
  151. package/package.json +10 -8
package/index.js CHANGED
@@ -15,11 +15,12 @@ import { isDefined as isDefined5 } from "@package-pal/util";
15
15
  // packages/core/src/lib/configuration/functions/check-bun.ts
16
16
  var checkBun = () => {
17
17
  if (!Bun) {
18
- throw new Error("This package must be run with the Bun runtime.");
18
+ throw new Error("This package must be run using the Bun runtime (see https://bun.com/).");
19
19
  }
20
20
  };
21
21
 
22
22
  // packages/core/src/lib/configuration/functions/load-config.ts
23
+ import { styleText } from "util";
23
24
  import { dirname as dirname3 } from "path";
24
25
  import { cwd } from "process";
25
26
  import {
@@ -27,10 +28,6 @@ import {
27
28
  formatSimpleLogObject,
28
29
  noOp as noOp2
29
30
  } from "@package-pal/util";
30
- import {
31
- bgGray,
32
- dim
33
- } from "yoctocolors";
34
31
 
35
32
  // packages/core/src/lib/configuration/functions/get-default-logger.ts
36
33
  import {
@@ -95,7 +92,9 @@ var Config = z3.object({
95
92
  })),
96
93
  watch: z3.optional(zLooseObjectWithoutIndexSignature({
97
94
  debounceMs: z3.optional(z3.number()),
95
+ ignore: z3.optional(z3.union([z3.string(), z3.array(z3.string())])),
98
96
  hooks: z3.optional(z3.object({
97
+ onInit: z3.optional(zLooseFunction()),
99
98
  onBeforeProcessPackage: z3.optional(zLooseFunction()),
100
99
  onProcessPackage: z3.optional(zLooseFunction()),
101
100
  onProcessPackageError: z3.optional(zLooseFunction()),
@@ -106,9 +105,9 @@ var Config = z3.object({
106
105
  })),
107
106
  subprocess: z3.optional(z3.object({
108
107
  partialProcessing: z3.optional(z3.boolean()),
109
- parallelProcessing: z3.optional(z3.boolean()),
110
- matchLongRunningOutputAsReady: z3.nullish(z3.string()),
111
- matchLongRunningOutputAsErrored: z3.nullish(z3.string())
108
+ concurrency: z3.nullish(z3.number()),
109
+ matchLongRunningOutputAsReady: z3.nullish(z3.union([z3.string(), z3.array(z3.string())])),
110
+ matchLongRunningOutputAsErrored: z3.nullish(z3.union([z3.string(), z3.array(z3.string())]))
112
111
  }))
113
112
  })),
114
113
  logLevel: z3.optional(LogLevel)
@@ -228,7 +227,9 @@ var defaultConfig = {
228
227
  },
229
228
  watch: {
230
229
  debounceMs: 500,
230
+ ignore: "",
231
231
  hooks: {
232
+ onInit: noOp2,
232
233
  onBeforeProcessPackage: noOp2,
233
234
  onProcessPackage: noOp2,
234
235
  onProcessPackageError: noOp2,
@@ -239,7 +240,7 @@ var defaultConfig = {
239
240
  },
240
241
  subprocess: {
241
242
  partialProcessing: false,
242
- parallelProcessing: true,
243
+ concurrency: null,
243
244
  matchLongRunningOutputAsReady: null,
244
245
  matchLongRunningOutputAsErrored: null
245
246
  }
@@ -260,14 +261,14 @@ var loadConfig = async (overrideConfigPath) => {
260
261
  const parsedLogger = parsedConfig["logger"];
261
262
  const logger = parsedLogger ?? (!parsedConfig.logLevel || parsedConfig.logLevel === defaultConfig.logLevel ? defaultConfig.logger : getDefaultLogger(parsedConfig.logLevel));
262
263
  logger.debug(`Successfully loaded config file '${path}'.`);
263
- logger.debug(dim(bgGray("User config:")), `
264
- ${dim(formatSimpleLogObject(parsedConfig))}`);
265
- logger.debug(dim(bgGray("Default config:")), `
266
- ${dim(formatSimpleLogObject(defaultConfig))}`);
264
+ logger.debug(styleText("dim", styleText("bgGray", "User config:")), `
265
+ ${styleText("dim", formatSimpleLogObject(parsedConfig))}`);
266
+ logger.debug(styleText("dim", styleText("bgGray", "Default config:")), `
267
+ ${styleText("dim", formatSimpleLogObject(defaultConfig))}`);
267
268
  const activatedConfig = deepMergeDefined(defaultConfig, parsedConfig);
268
269
  activatedConfig.logger = logger;
269
- logger.debug(dim(bgGray("Activated config:")), `
270
- ${dim(formatSimpleLogObject(activatedConfig))}`);
270
+ logger.debug(styleText("dim", styleText("bgGray", "Activated config:")), `
271
+ ${styleText("dim", formatSimpleLogObject(activatedConfig))}`);
271
272
  return {
272
273
  config: activatedConfig,
273
274
  rootDir: dirname3(path)
@@ -275,14 +276,24 @@ ${dim(formatSimpleLogObject(activatedConfig))}`);
275
276
  };
276
277
 
277
278
  // packages/core/src/lib/graph/functions/generate-graphs.ts
279
+ import { styleText as styleText2 } from "util";
278
280
  import { assertDefined as assertDefined2 } from "@package-pal/util";
279
- import { dim as dim2 } from "yoctocolors";
281
+
282
+ // packages/core/src/lib/package/types/dependencies-field.ts
283
+ var DependenciesField = {
284
+ Dependencies: "dependencies",
285
+ DevDependencies: "devDependencies",
286
+ PeerDependencies: "peerDependencies",
287
+ OptionalDependencies: "optionalDependencies"
288
+ };
289
+
290
+ // packages/core/src/lib/graph/functions/generate-graphs.ts
280
291
  var trackPackageEntryDependencies = ({
281
292
  trackedDependencies,
282
293
  packageNames,
283
294
  packageData
284
295
  }) => {
285
- const iterateEntries = [packageData.dependencies, packageData.peerDependencies];
296
+ const iterateEntries = Object.values(DependenciesField).map((field) => packageData[field]);
286
297
  for (const packageEntries of iterateEntries) {
287
298
  if (!packageEntries) {
288
299
  continue;
@@ -310,7 +321,7 @@ var generateReverseGraph = (packages, packageGraph) => {
310
321
  return reversePackageGraph;
311
322
  };
312
323
  var generateGraphs = (packages, logger) => {
313
- logger.debug(dim2(`Generating package graphs for ${packages.length.toString()} packages...`));
324
+ logger.debug(styleText2("dim", `Generating package graphs for ${packages.length.toString()} packages...`));
314
325
  const packageNames = new Set(packages.map((packageData) => packageData.name));
315
326
  const packageGraph = new Map;
316
327
  for (const packageData of packages) {
@@ -333,11 +344,8 @@ var generateGraphs = (packages, logger) => {
333
344
  };
334
345
 
335
346
  // packages/core/src/lib/graph/functions/generate-package-circular-dependency-paths.ts
347
+ import { styleText as styleText3 } from "util";
336
348
  import { assertDefined as assertDefined6 } from "@package-pal/util";
337
- import {
338
- dim as dim3,
339
- yellow
340
- } from "yoctocolors";
341
349
 
342
350
  // packages/core/src/lib/graph/functions/dfs-traverse-graph-paths.ts
343
351
  import { assertDefined as assertDefined3 } from "@package-pal/util";
@@ -488,7 +496,7 @@ var findSampleCyclePath = (scc, graph) => {
488
496
  }));
489
497
  };
490
498
  var generatePackageCircularDependencyPaths = ({ dependents }, packageSorted, logger) => {
491
- logger.debug(dim3("Generating circular dependency paths..."));
499
+ logger.debug(styleText3("dim", "Generating circular dependency paths..."));
492
500
  const subgraph = extractSubgraph(dependents, packageSorted.circular);
493
501
  const scss = findStronglyConnectedComponents(subgraph);
494
502
  const sampleCycles = scss.map((scc) => findSampleCyclePath(scc, subgraph).reverse());
@@ -497,20 +505,17 @@ var generatePackageCircularDependencyPaths = ({ dependents }, packageSorted, log
497
505
  return ` ${(index + 1).toString()}. ` + cycle.map((name) => `'${name}'`).join(" \u2192 ");
498
506
  }).join(`
499
507
  `);
500
- logger.warn(yellow(`${sampleCycles.length.toString()} cyclic paths found:
508
+ logger.warn(styleText3("yellow", `${sampleCycles.length.toString()} cyclic paths found:
501
509
  ${sampleCycleContents}`));
502
510
  } else {
503
- logger.debug(dim3(`No cyclic paths found.`));
511
+ logger.debug(styleText3("dim", `No cyclic paths found.`));
504
512
  }
505
513
  return sampleCycles;
506
514
  };
507
515
 
508
516
  // packages/core/src/lib/graph/functions/generate-topological-sorted-groups.ts
517
+ import { styleText as styleText4 } from "util";
509
518
  import { assertDefined as assertDefined7 } from "@package-pal/util";
510
- import {
511
- dim as dim4,
512
- yellow as yellow2
513
- } from "yoctocolors";
514
519
  var getCircularDependencies = (inDegree) => {
515
520
  return Array.from(inDegree.keys()).sort((a, b) => {
516
521
  const degA = assertDefined7(inDegree.get(a));
@@ -519,7 +524,7 @@ var getCircularDependencies = (inDegree) => {
519
524
  }).sort();
520
525
  };
521
526
  var generateTopologicalSortedGroups = (packageGraph, logger) => {
522
- logger.debug(dim4("Generating topological sorted groups..."));
527
+ logger.debug(styleText4("dim", "Generating topological sorted groups..."));
523
528
  const graphEntries = Array.from(packageGraph.entries());
524
529
  const inDegree = new Map(graphEntries.map(([packageName]) => [packageName, 0]));
525
530
  const graph = new Map(graphEntries.map(([packageName]) => [packageName, new Set]));
@@ -554,10 +559,10 @@ var generateTopologicalSortedGroups = (packageGraph, logger) => {
554
559
  }
555
560
  ready = nextReady;
556
561
  }
557
- logger.debug(dim4(`Sorted packages into ${result.length.toString()} sequential groups of parallelizable dependencies.`));
562
+ logger.debug(styleText4("dim", `Sorted packages into ${result.length.toString()} sequential groups of parallelizable dependencies.`));
558
563
  const circular = getCircularDependencies(inDegree);
559
564
  if (circular.length) {
560
- logger.warn(yellow2(`${circular.length.toString()} packages could not be sorted due to circular dependencies. Correct ordering cannot be guaranteed.`));
565
+ logger.warn(styleText4("yellow", `${circular.length.toString()} packages could not be sorted due to circular dependencies. Correct ordering cannot be guaranteed.`));
561
566
  }
562
567
  return {
563
568
  groups: result.map((group) => group.sort()),
@@ -566,18 +571,15 @@ var generateTopologicalSortedGroups = (packageGraph, logger) => {
566
571
  };
567
572
 
568
573
  // packages/core/src/lib/package/functions/load-packages.ts
569
- import { dim as dim6 } from "yoctocolors";
574
+ import { styleText as styleText6 } from "util";
570
575
 
571
576
  // packages/core/src/lib/package/functions/scan-packages.ts
577
+ import { styleText as styleText5 } from "util";
572
578
  import {
573
579
  dirname as dirname5,
574
580
  join as join2
575
581
  } from "path";
576
582
  import { formatUnknownError } from "@package-pal/util";
577
- import {
578
- dim as dim5,
579
- red
580
- } from "yoctocolors";
581
583
 
582
584
  // packages/core/src/lib/package/functions/parse-package.ts
583
585
  import {
@@ -596,8 +598,11 @@ var parsePackage = (path, text) => {
596
598
  peerDependencies,
597
599
  devDependencies
598
600
  } = props;
599
- if (isDefined2(dependencies) && !(typeof dependencies === "object") || isDefined2(peerDependencies) && !(typeof peerDependencies === "object") || isDefined2(devDependencies) && !(typeof devDependencies === "object")) {
600
- return;
601
+ for (const field of Object.values(DependenciesField)) {
602
+ const value = props[field];
603
+ if (isDefined2(value) && typeof value !== "object") {
604
+ return;
605
+ }
601
606
  }
602
607
  return {
603
608
  rawContent: text,
@@ -614,11 +619,15 @@ var parsePackage = (path, text) => {
614
619
  // packages/core/src/lib/package/functions/scan-package-paths.ts
615
620
  import { scanGlobPatternPaths } from "@package-pal/util";
616
621
  var scanPackagePaths = (packages, cwd2) => {
617
- return scanGlobPatternPaths(packages, {
622
+ const baseOpts = {
618
623
  absolute: true,
619
- onlyFiles: false,
620
- cwd: cwd2
621
- });
624
+ onlyFiles: false
625
+ };
626
+ const opts = {
627
+ ...baseOpts,
628
+ ...cwd2 ? { cwd: cwd2 } : {}
629
+ };
630
+ return scanGlobPatternPaths(packages, opts);
622
631
  };
623
632
 
624
633
  // packages/core/src/lib/package/functions/scan-packages.ts
@@ -627,22 +636,22 @@ var scanPackages = async function* (patterns, logger, cwd2) {
627
636
  const packagePath = join2(path, "package.json");
628
637
  const dir = dirname5(packagePath);
629
638
  try {
630
- logger.debug(dim5(`Trying to read read package.json in '${dir}'.`));
639
+ logger.debug(styleText5("dim", `Trying to read read package.json in '${dir}'.`));
631
640
  const file = Bun.file(packagePath);
632
641
  if (!file.size) {
633
- logger.debug(dim5(`Failed to read package.json in '${dir}' - ${red("File not found")}.`));
642
+ logger.debug(styleText5("dim", `Failed to read package.json in '${dir}' - ${styleText5("red", "File not found")}.`));
634
643
  continue;
635
644
  }
636
645
  const text = await file.text();
637
646
  const packageData = parsePackage(packagePath, text);
638
647
  if (!packageData) {
639
- logger.debug(dim5(`Invalid package.json found in '${dir}'.`));
648
+ logger.debug(styleText5("dim", `Invalid package.json found in '${dir}'.`));
640
649
  continue;
641
650
  }
642
- logger.debug(dim5(`Successfully read package.json in '${dir}'.`));
651
+ logger.debug(styleText5("dim", `Successfully read package.json in '${dir}'.`));
643
652
  yield packageData;
644
653
  } catch (e) {
645
- logger.debug(dim5(`Failed to read package.json in '${dir}' - ${red(formatUnknownError(e))}.`));
654
+ logger.debug(styleText5("dim", `Failed to read package.json in '${dir}' - ${styleText5("red", formatUnknownError(e))}.`));
646
655
  }
647
656
  }
648
657
  };
@@ -650,7 +659,7 @@ var scanPackages = async function* (patterns, logger, cwd2) {
650
659
  // packages/core/src/lib/package/functions/load-packages.ts
651
660
  var loadPackages = async (rootDir, packagePatterns, logger) => {
652
661
  const patternContent = packagePatterns.map((pattern) => `'${pattern}'`).join(", ");
653
- logger.debug(dim6(`Loading packages matching pattern/s ${patternContent}...${rootDir ? ` from ${rootDir}` : ""}`));
662
+ logger.debug(styleText6("dim", `Loading packages matching pattern/s ${patternContent}...${rootDir ? ` from ${rootDir}` : ""}`));
654
663
  const packages = [];
655
664
  const seen = new Set;
656
665
  for await (const packageData of scanPackages(Array.from(new Set(packagePatterns)), logger, rootDir)) {
@@ -670,15 +679,11 @@ var loadPackages = async (rootDir, packagePatterns, logger) => {
670
679
  import { dirname as dirname6 } from "path";
671
680
  import {
672
681
  assertDefined as assertDefined9,
673
- runAsync,
674
- RunAsyncType
682
+ runAsync
675
683
  } from "@package-pal/util";
676
684
 
677
685
  // packages/core/src/lib/process/functions/run-subprocess.ts
678
- import {
679
- dim as dim7,
680
- red as red2
681
- } from "yoctocolors";
686
+ import { styleText as styleText7 } from "util";
682
687
 
683
688
  // packages/core/src/lib/process/types/exit-state.ts
684
689
  var ExitState = {
@@ -700,82 +705,57 @@ import {
700
705
  Shell
701
706
  } from "@package-pal/util";
702
707
 
703
- // packages/core/src/lib/process/functions/parse-ps-flags.ts
708
+ // packages/core/src/lib/process/functions/parse-ps-shell-flags.ts
704
709
  import { assertDefined as assertDefined8 } from "@package-pal/util";
705
- var knownFlagsWithParams = new Set([
710
+ var shellFlagsWithParams = new Set([
706
711
  "-executionpolicy",
707
712
  "-windowstyle",
708
- "-version",
709
- "-file",
710
- "-inputformat",
711
- "-outputformat",
712
- "-workingdirectory",
713
- "-psconsolefile",
714
- "-pshome",
715
- "-configurationname",
716
- "-argumentlist",
717
- "-warningaction",
718
- "-erroraction",
719
- "-informationaction",
720
- "-informationvariable",
721
- "-warningvariable",
722
- "-errorvariable",
723
- "-outvariable",
724
- "-outbuffer",
725
- "-throttlelimit",
726
- "-culture",
727
- "-uiculture"
713
+ "-version"
728
714
  ]);
729
- var knownFlagsNoParams = new Set([
715
+ var shellFlagsNoParams = new Set([
730
716
  "-noprofile",
731
717
  "-noninteractive",
732
- "-nologo",
733
718
  "-sta",
734
719
  "-mta",
735
- "-encodedcommand",
736
- "-command",
720
+ "-nologo",
737
721
  "-help",
738
722
  "-?",
739
- "-verbose",
740
- "-debug",
741
- "-whatif",
742
- "-confirm",
743
- "-usewindowspowershell",
744
- "-noexit"
723
+ "-noexit",
724
+ "-usewindowspowerShell"
745
725
  ]);
746
- var parsePsFlags = (input) => {
747
- const tokens = input.trim().split(/\s+/);
748
- const flags = [];
726
+ var parsePsShellFlags = (input) => {
727
+ const isPreEncoded = input.toLowerCase().includes("-encodedcommand");
728
+ const tokens = input.match(/"[^"]*"|'[^']*'|\S+/g) ?? [];
729
+ const flags = new Set;
749
730
  let i = 0;
750
731
  while (i < tokens.length) {
751
732
  const token = assertDefined8(tokens[i]);
752
733
  const tokenLower = token.toLowerCase();
753
- if (knownFlagsWithParams.has(tokenLower)) {
754
- if (i + 1 >= tokens.length) {
755
- break;
734
+ if (shellFlagsWithParams.has(tokenLower)) {
735
+ flags.add(token);
736
+ if (i + 1 < tokens.length) {
737
+ flags.add(assertDefined8(tokens[i + 1]));
738
+ i++;
756
739
  }
757
- flags.push(token, assertDefined8(tokens[i + 1]));
758
- i += 2;
759
- continue;
760
- }
761
- if (knownFlagsNoParams.has(tokenLower)) {
762
- flags.push(token);
763
- i += 1;
764
- continue;
740
+ i++;
741
+ } else if (shellFlagsNoParams.has(tokenLower)) {
742
+ flags.add(token);
743
+ i++;
744
+ } else {
745
+ break;
765
746
  }
766
- break;
767
747
  }
768
748
  const command = tokens.slice(i).join(" ");
769
749
  return {
770
750
  flags,
771
- command
751
+ command,
752
+ isPreEncoded
772
753
  };
773
754
  };
774
755
 
775
756
  // packages/core/src/lib/process/functions/get-commands-for-shell.ts
776
- var shell;
777
757
  var getCommandsForShell = (shellCommand) => {
778
- shell = shell ?? getShell();
758
+ const shell = getShell();
779
759
  switch (shell) {
780
760
  case Shell.cmd:
781
761
  return [
@@ -787,9 +767,13 @@ var getCommandsForShell = (shellCommand) => {
787
767
  case Shell.powershell:
788
768
  const {
789
769
  flags,
790
- command
791
- } = parsePsFlags(shellCommand);
792
- const encodedCommand = Buffer.from(command, "utf16le").toString("base64");
770
+ command,
771
+ isPreEncoded
772
+ } = parsePsShellFlags(shellCommand);
773
+ if (isPreEncoded) {
774
+ return [shell, shellCommand];
775
+ }
776
+ const encodedCommand = Buffer.from(command || " ", "utf16le").toString("base64");
793
777
  return [
794
778
  shell,
795
779
  ...flags,
@@ -822,9 +806,6 @@ var getLineBufferedWriter = (prefix, style = identity, write = process.stdout.wr
822
806
 
823
807
  // packages/core/src/lib/process/functions/read-stream.ts
824
808
  var readStream = async (stream, use) => {
825
- if (!stream) {
826
- return;
827
- }
828
809
  const decoder = new TextDecoder;
829
810
  const reader = stream.getReader();
830
811
  let result = await reader.read();
@@ -849,27 +830,31 @@ var cancelCodes = new Set([
849
830
  ]);
850
831
  var runSubprocess = async (opts) => {
851
832
  if (opts.signal?.aborted) {
852
- opts.logger.debug(dim7(`Skipped '${opts.debugName}' subprocess command; signal already cancelled.`));
833
+ opts.logger.debug(styleText7("dim", `Skipped '${opts.debugName}' subprocess command; signal already cancelled.`));
853
834
  return ExitState.Cancelled;
854
835
  }
855
836
  const commands = getCommandsForShell(opts.shellCommand);
856
- const subprocess = Bun.spawn(commands, {
857
- cwd: opts.cwd,
837
+ const baseSubprocessOpts = {
858
838
  stdout: "pipe",
859
839
  stderr: "pipe",
860
- stdin: "ignore",
861
- signal: opts.signal
862
- });
840
+ stdin: "ignore"
841
+ };
842
+ const subprocessOpts = {
843
+ ...baseSubprocessOpts,
844
+ ...opts.cwd ? { cwd: opts.cwd } : {},
845
+ ...opts.signal ? { signal: opts.signal } : {}
846
+ };
847
+ const subprocess = Bun.spawn(commands, subprocessOpts);
863
848
  const pid = subprocess.pid.toString();
864
849
  const minPrefixLen = 14;
865
850
  const [readStdout, readStderr] = [{
866
851
  source: subprocess.stdout,
867
852
  type: StdType.Out,
868
- write: getLineBufferedWriter(dim7(`[O-${pid}]`.padEnd(minPrefixLen, " ")))
853
+ write: getLineBufferedWriter(styleText7("dim", `[O-${pid}]`.padEnd(minPrefixLen, " ")))
869
854
  }, {
870
855
  source: subprocess.stderr,
871
856
  type: StdType.Err,
872
- write: getLineBufferedWriter(red2(dim7(`[E-${pid}]`.padEnd(minPrefixLen, " "))))
857
+ write: getLineBufferedWriter(styleText7("yellow", styleText7("dim", `[E-${pid}]`.padEnd(minPrefixLen, " "))))
873
858
  }].map(({
874
859
  source,
875
860
  type,
@@ -883,7 +868,7 @@ var runSubprocess = async (opts) => {
883
868
  });
884
869
  });
885
870
  const executedCommand = commands.join(" ");
886
- opts.logger.debug(dim7(`Started '${opts.debugName}' subprocess command '${opts.shellCommand}' (${executedCommand}) with PID ${pid}.`));
871
+ opts.logger.debug(styleText7("dim", `Started '${opts.debugName}' subprocess command '${opts.shellCommand}' (${executedCommand}) with PID ${pid}.`));
887
872
  const [
888
873
  ,
889
874
  ,
@@ -893,14 +878,14 @@ var runSubprocess = async (opts) => {
893
878
  readStderr,
894
879
  subprocess.exited.then((exitCode) => {
895
880
  if (cancelCodes.has(exitCode)) {
896
- opts.logger.debug(dim7(`Cancelled '${opts.debugName}' subprocess command; PID ${pid} exited.`));
881
+ opts.logger.debug(styleText7("dim", `Cancelled '${opts.debugName}' subprocess command; PID ${pid} exited.`));
897
882
  return ExitState.Cancelled;
898
883
  }
899
884
  if (exitCode !== 0) {
900
- opts.logger.error(red2(`'${opts.debugName}' command '${opts.shellCommand}' (${executedCommand}) with PID ${pid} failed with exit code ${exitCode.toString()}.`));
885
+ opts.logger.error(styleText7("red", `'${opts.debugName}' command '${opts.shellCommand}' (${executedCommand}) with PID ${pid} failed with exit code ${exitCode.toString()}.`));
901
886
  return ExitState.Errored;
902
887
  }
903
- opts.logger.debug(dim7(`Completed '${opts.debugName}' subprocess command; PID ${pid} exited.`));
888
+ opts.logger.debug(styleText7("dim", `Completed '${opts.debugName}' subprocess command; PID ${pid} exited.`));
904
889
  return ExitState.Completed;
905
890
  })
906
891
  ]);
@@ -908,14 +893,14 @@ var runSubprocess = async (opts) => {
908
893
  };
909
894
 
910
895
  // packages/core/src/lib/package/functions/run-for-each-package.ts
911
- var runForEachPackage = async (packageGraphs, packageOrder, getCommand, parallel, topological, logger) => {
896
+ var runForEachPackage = async (packageGraphs, packageOrder, getCommand, logger, topological = true, concurrency) => {
912
897
  const controller = new AbortController;
913
898
  let processPackageOrder = packageOrder.groups.concat(packageOrder.circular);
914
899
  if (!topological) {
915
900
  processPackageOrder = [processPackageOrder.flat()];
916
901
  }
917
902
  for (const group of processPackageOrder) {
918
- await runAsync(parallel ? RunAsyncType.Parallel : RunAsyncType.Sequential, group.map((packageName) => async () => {
903
+ await runAsync(group.map((packageName) => async () => {
919
904
  const packageNode = assertDefined9(packageGraphs.dependencies.get(packageName));
920
905
  const processPackageProps = {
921
906
  name: packageName,
@@ -937,14 +922,14 @@ var runForEachPackage = async (packageGraphs, packageOrder, getCommand, parallel
937
922
  controller.abort();
938
923
  throw new Error("Command failed.");
939
924
  }
940
- }));
925
+ }), concurrency);
941
926
  }
942
927
  };
943
928
 
944
929
  // packages/core/src/lib/package/functions/update-package-version.ts
930
+ import { styleText as styleText8 } from "util";
945
931
  var {semver } = globalThis.Bun;
946
932
  import { inc } from "semver";
947
- import { dim as dim8 } from "yoctocolors";
948
933
  var findAndReplaceVersion = ({
949
934
  raw,
950
935
  field,
@@ -1004,7 +989,7 @@ var findAndReplaceVersion = ({
1004
989
  return `${before}${updatedVersion}${after}`;
1005
990
  };
1006
991
  var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact, logger) => {
1007
- logger.debug(dim8(`Bumping package '${packageName}'...`));
992
+ logger.debug(styleText8("dim", `Bumping package '${packageName}'...`));
1008
993
  const packageNode = packageGraphs.dependencies.get(packageName);
1009
994
  if (!packageNode) {
1010
995
  throw new Error(`Package '${packageName}' not found.`);
@@ -1028,15 +1013,14 @@ var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact
1028
1013
  });
1029
1014
  const baseWrite = Bun.write(packageNode.packageData.path, updatedContent);
1030
1015
  const dependentWrites = Array.from(dfsTraverseGraph(packageGraphs.dependents, packageName).flatMap((dependent) => {
1031
- const fields = ["dependencies", "peerDependencies"];
1032
- return fields.flatMap((field) => {
1016
+ return Object.values(DependenciesField).flatMap((field) => {
1033
1017
  const entry = dependent[field];
1034
1018
  const depVersion = entry?.[packageName];
1035
1019
  if (!depVersion) {
1036
1020
  return [];
1037
1021
  }
1038
1022
  if (exact ? depVersion === bumpedVersion : semver.satisfies(bumpedVersion, depVersion)) {
1039
- logger.debug(dim8(`Skipping '${dependent.name}': ${field} version '${depVersion}' already satisfies '${bumpedVersion}'.`));
1023
+ logger.debug(styleText8("dim", `Skipping '${dependent.name}': ${field} version '${depVersion}' already satisfies '${bumpedVersion}'.`));
1040
1024
  return [];
1041
1025
  }
1042
1026
  const updatedContent2 = findAndReplaceVersion({
@@ -1060,6 +1044,7 @@ var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact
1060
1044
  import {
1061
1045
  watch
1062
1046
  } from "fs";
1047
+ import { styleText as styleText10 } from "util";
1063
1048
  import {
1064
1049
  dirname as dirname8,
1065
1050
  join as join4
@@ -1071,13 +1056,9 @@ import {
1071
1056
  getDeferredPromise,
1072
1057
  getStringMatcher,
1073
1058
  isDefined as isDefined4,
1074
- RunAsyncType as RunAsyncType2,
1075
1059
  runAsync as runAsync2
1076
1060
  } from "@package-pal/util";
1077
- import {
1078
- dim as dim10,
1079
- red as red3
1080
- } from "yoctocolors";
1061
+ var {Glob } = globalThis.Bun;
1081
1062
 
1082
1063
  // packages/core/src/lib/graph/functions/merge-graphs.ts
1083
1064
  var mergeGraphs = (a, b) => {
@@ -1113,8 +1094,8 @@ var filterFilesModifiedSince = (paths, sinceMs) => {
1113
1094
  };
1114
1095
 
1115
1096
  // packages/core/src/lib/watch/functions/get-change-logic.ts
1097
+ import { styleText as styleText9 } from "util";
1116
1098
  import { assertDefined as assertDefined11 } from "@package-pal/util";
1117
- import { dim as dim9 } from "yoctocolors";
1118
1099
 
1119
1100
  // packages/core/src/lib/graph/functions/generate-topological-ranking-range.ts
1120
1101
  import { isDefined as isDefined3 } from "@package-pal/util";
@@ -1214,8 +1195,8 @@ var getChangeLogic = (packageGraphs, packageChanges, lastProcessedSubgraph, conf
1214
1195
  const changedPackages = Array.from(packageChanges.keys());
1215
1196
  const changedFilePaths = Array.from(packageChanges.values()).flat();
1216
1197
  if (packageChanges.size) {
1217
- logger.debug(dim9(`Changes detected in ${changedPackages.map((packageName) => `'${packageName}'`).join(", ")}.`));
1218
- logger.debug(dim9(`Changed file paths: ${changedFilePaths.map((filePath) => `'${filePath}'`).join(", ")}.`));
1198
+ logger.debug(styleText9("dim", `Changes detected in ${changedPackages.map((packageName) => `'${packageName}'`).join(", ")}.`));
1199
+ logger.debug(styleText9("dim", `Changed file paths: ${changedFilePaths.map((filePath) => `'${filePath}'`).join(", ")}.`));
1219
1200
  }
1220
1201
  const packageOrder = generateTopologicalSortedGroups(packageGraphs.dependents, logger);
1221
1202
  const packageProcessOrder = packageOrder.groups.toReversed().concat(packageOrder.circular);
@@ -1226,9 +1207,9 @@ var getChangeLogic = (packageGraphs, packageChanges, lastProcessedSubgraph, conf
1226
1207
  const isSubgraphOfPrevious = !!lastProcessedSubgraph && isSubgraph(lastProcessedSubgraph, changedPackageSubgraph);
1227
1208
  const isDisjointFromPrevious = !lastProcessedSubgraph || !isSubgraphOfPrevious && isDisjoint(lastProcessedSubgraph, changedPackageSubgraph);
1228
1209
  const isRankedGreaterThanOrEqualToPrevious = !!lastProcessedSubgraph && !isSubgraphOfPrevious && isRankedGreaterThanOrEqual(lastProcessedSubgraph, changedPackageSubgraph, packageRankings);
1229
- logger.debug(dim9(`Changes are subgraph of previous: ${isSubgraphOfPrevious.toString()}.`));
1230
- logger.debug(dim9(`Changes are disjoint from previous: ${isDisjointFromPrevious.toString()}.`));
1231
- logger.debug(dim9(`Changes are ranked greater than or equal to previous: ${isRankedGreaterThanOrEqualToPrevious.toString()}.`));
1210
+ logger.debug(styleText9("dim", `Changes are subgraph of previous: ${isSubgraphOfPrevious.toString()}.`));
1211
+ logger.debug(styleText9("dim", `Changes are disjoint from previous: ${isDisjointFromPrevious.toString()}.`));
1212
+ logger.debug(styleText9("dim", `Changes are ranked greater than or equal to previous: ${isRankedGreaterThanOrEqualToPrevious.toString()}.`));
1232
1213
  let action = ChangeAction.Restart;
1233
1214
  if (!packageChanges.size) {
1234
1215
  action = ChangeAction.Ignore;
@@ -1248,7 +1229,7 @@ var getChangeLogic = (packageGraphs, packageChanges, lastProcessedSubgraph, conf
1248
1229
  });
1249
1230
  }
1250
1231
  }
1251
- logger.debug(dim9(`Determined change action: ${action}.`));
1232
+ logger.debug(styleText9("dim", `Determined change action: ${action}.`));
1252
1233
  return {
1253
1234
  changedPackageProcessOrder,
1254
1235
  changedPackageSubgraph,
@@ -1256,6 +1237,11 @@ var getChangeLogic = (packageGraphs, packageChanges, lastProcessedSubgraph, conf
1256
1237
  };
1257
1238
  };
1258
1239
 
1240
+ // packages/core/src/lib/watch/functions/normalise-pattern-separators.ts
1241
+ var normalisePatternSeparators = (path) => {
1242
+ return path.replace(/\\/g, "/");
1243
+ };
1244
+
1259
1245
  // packages/core/src/lib/watch/functions/normalise-watched-file-path.ts
1260
1246
  import {
1261
1247
  basename as basename3,
@@ -1294,9 +1280,11 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1294
1280
  changedPackageProcessOrder,
1295
1281
  changedPackageSubgraph
1296
1282
  } = getChangeLogic(packageGraphs, packageChanges, lastProcessedSubgraph, watchConfig, logger);
1297
- const controller = determineAbortController(action === ChangeAction.Restart);
1283
+ const isRestart = action === ChangeAction.Restart;
1284
+ const isSequential = watchConfig.subprocess.concurrency === 1;
1285
+ const controller = determineAbortController(isRestart);
1298
1286
  const onProcessFailure = () => {
1299
- logger.debug(dim10("Aborting controller: process failed."));
1287
+ logger.debug(styleText10("dim", "Aborting controller: process failed."));
1300
1288
  controller.abort();
1301
1289
  lastProcessedSubgraph = undefined;
1302
1290
  };
@@ -1305,8 +1293,8 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1305
1293
  return;
1306
1294
  }
1307
1295
  if (packageChanges.size) {
1308
- logger.info(`Changes detected. ${action === ChangeAction.Restart ? "Restarting processing" : "Initiating partial processing"} ${watchConfig.subprocess.parallelProcessing ? "in parallel" : "sequentially"}.`);
1309
- lastProcessedSubgraph = lastProcessedSubgraph ? mergeGraphs(lastProcessedSubgraph, changedPackageSubgraph) : changedPackageSubgraph;
1296
+ logger.info(`${isRestart ? "Restarting processing" : "Initiating partial processing"} ${isSequential ? "sequentially" : `in parallel${isDefined4(watchConfig.subprocess.concurrency) ? ` with concurrency ${watchConfig.subprocess.concurrency.toString()}` : ""}`}.`);
1297
+ lastProcessedSubgraph = lastProcessedSubgraph && !isRestart ? mergeGraphs(lastProcessedSubgraph, changedPackageSubgraph) : changedPackageSubgraph;
1310
1298
  }
1311
1299
  for (const group of changedPackageProcessOrder) {
1312
1300
  const {
@@ -1314,7 +1302,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1314
1302
  resolve: matchedParallelLongReadyRunningOutput
1315
1303
  } = getDeferredPromise();
1316
1304
  let matchedLongRunningOutputCount = 0;
1317
- await runAsync2(watchConfig.subprocess.parallelProcessing ? RunAsyncType2.Parallel : RunAsyncType2.Sequential, group.map((packageName) => async () => {
1305
+ await runAsync2(group.map((packageName) => async () => {
1318
1306
  const {
1319
1307
  promise: longRunningSequentialProcessReady,
1320
1308
  resolve: matchedSequentialLongRunningReadyOutput
@@ -1355,36 +1343,42 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1355
1343
  signal: controller.signal,
1356
1344
  logger,
1357
1345
  onStdChunk: (chunk) => {
1358
- if (!ready && readyMatcher?.push(chunk).matched()) {
1359
- ready = true;
1360
- matchedLongRunningOutputCount++;
1361
- logger.debug(`'${packageName}' (${matchedLongRunningOutputCount.toString()}/${group.length.toString()}) subprocess matched ready text '${assertDefined12(longRunningOutputReadyText)}'.`);
1362
- if (!watchConfig.subprocess.parallelProcessing && matchedLongRunningOutputCount) {
1363
- matchedSequentialLongRunningReadyOutput();
1346
+ if (!ready) {
1347
+ const matchedReadyText = readyMatcher?.push(chunk).matched();
1348
+ if (matchedReadyText) {
1349
+ ready = true;
1350
+ matchedLongRunningOutputCount++;
1351
+ logger.debug(`'${packageName}' (${matchedLongRunningOutputCount.toString()}/${group.length.toString()}) subprocess matched ready text '${matchedReadyText}'.`);
1352
+ if (isSequential && matchedLongRunningOutputCount) {
1353
+ matchedSequentialLongRunningReadyOutput();
1354
+ }
1364
1355
  }
1365
1356
  }
1366
- if (!errored && erroredMatcher?.push(chunk).matched()) {
1367
- logger.error(red3(`'${packageName}' subprocess matched error text '${assertDefined12(longRunningOutputErroredText)}'.`));
1368
- errored = true;
1369
- Promise.resolve(watchConfig.hooks.onProcessPackageError(processPackageProps)).then((processPackageErrorCommand) => {
1370
- if (!processPackageErrorCommand) {
1371
- onProcessFailure();
1372
- return;
1373
- }
1374
- return runSubprocess({
1375
- debugName: `after process ${packageName}`,
1376
- shellCommand: processPackageErrorCommand,
1377
- cwd: processPackageCwd,
1378
- signal: controller.signal,
1379
- logger
1357
+ if (!errored) {
1358
+ const matchedErrorText = erroredMatcher?.push(chunk).matched();
1359
+ if (matchedErrorText) {
1360
+ logger.error(styleText10("red", `'${packageName}' subprocess matched error text '${matchedErrorText}'.`));
1361
+ errored = true;
1362
+ Promise.resolve(watchConfig.hooks.onProcessPackageError(processPackageProps)).then((processPackageErrorCommand) => {
1363
+ if (!processPackageErrorCommand) {
1364
+ onProcessFailure();
1365
+ return;
1366
+ }
1367
+ return runSubprocess({
1368
+ debugName: `after process ${packageName}`,
1369
+ shellCommand: processPackageErrorCommand,
1370
+ cwd: processPackageCwd,
1371
+ signal: controller.signal,
1372
+ logger
1373
+ });
1374
+ }).then((exitState) => {
1375
+ if (exitState === ExitState.Errored) {
1376
+ onProcessFailure();
1377
+ }
1380
1378
  });
1381
- }).then((exitState) => {
1382
- if (exitState === ExitState.Errored) {
1383
- onProcessFailure();
1384
- }
1385
- });
1379
+ }
1386
1380
  }
1387
- if (watchConfig.subprocess.parallelProcessing && matchedLongRunningOutputCount === group.length) {
1381
+ if (!isSequential && matchedLongRunningOutputCount === group.length) {
1388
1382
  matchedParallelLongReadyRunningOutput();
1389
1383
  }
1390
1384
  }
@@ -1409,7 +1403,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1409
1403
  logger
1410
1404
  });
1411
1405
  }
1412
- }));
1406
+ }), watchConfig.subprocess.concurrency);
1413
1407
  }
1414
1408
  if (packageChanges.size) {
1415
1409
  logger.info(`Processing ${controller.signal.aborted ? "cancelled due to new changes" : "completed"}.`);
@@ -1446,18 +1440,19 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1446
1440
  });
1447
1441
  }
1448
1442
  };
1449
- var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1443
+ var watchPackageChanges = (packageData, packageGraphs, watchConfig, rootDir, logger) => {
1450
1444
  const dedupedRootPackageData = dedupeSharedPaths(packageData.map((packageData2) => packageData2.path), DedupePathsBy.Parent).map((packagePath) => assertDefined12(packageData.find((data) => data.path === packagePath)));
1451
- logger.debug(dim10(`Starting ${dedupedRootPackageData.length.toString()} watchers for ${packageData.length.toString()} packages.`));
1445
+ logger.debug(styleText10("dim", `Starting ${dedupedRootPackageData.length.toString()} watchers for ${packageData.length.toString()} packages.`));
1452
1446
  let closed = false;
1453
1447
  let debounceTimeout;
1454
1448
  let startedDebounceMs;
1455
1449
  let controller;
1450
+ const ignoreGlobs = watchConfig.ignore ? (Array.isArray(watchConfig.ignore) ? watchConfig.ignore : [watchConfig.ignore]).map((pattern) => new Glob(pattern)) : undefined;
1456
1451
  const changedPackagePaths = new Map;
1457
1452
  const useController = (reset) => {
1458
1453
  if (controller && (reset || controller.signal.aborted)) {
1459
1454
  if (reset) {
1460
- logger.debug(dim10("Aborting controller: reset for new packages."));
1455
+ logger.debug(styleText10("dim", "Aborting controller: reset for new packages."));
1461
1456
  controller.abort();
1462
1457
  }
1463
1458
  controller = undefined;
@@ -1465,7 +1460,12 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1465
1460
  controller ??= new AbortController;
1466
1461
  return controller;
1467
1462
  };
1468
- const onWatchEvent = (watchPath, packageName, _event, filePath, forceEmpty = false) => {
1463
+ const onWatchEvent = ({
1464
+ watchPath,
1465
+ packageName,
1466
+ filePath,
1467
+ isInitial = false
1468
+ }) => {
1469
1469
  if (!isDefined4(startedDebounceMs)) {
1470
1470
  startedDebounceMs = Date.now();
1471
1471
  }
@@ -1473,7 +1473,11 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1473
1473
  clearTimeout(debounceTimeout);
1474
1474
  }
1475
1475
  if (packageName && watchPath && filePath) {
1476
- const changedPath = join4(watchPath, normaliseWatchedFilePath(filePath));
1476
+ const changedPath = normalisePatternSeparators(join4(watchPath, normaliseWatchedFilePath(filePath)));
1477
+ if (ignoreGlobs?.some((glob) => glob.match(changedPath))) {
1478
+ logger.debug(styleText10("dim", `Ignoring change '${changedPath}' (matched ignore pattern).`));
1479
+ return;
1480
+ }
1477
1481
  const existingPaths = changedPackagePaths.get(packageName);
1478
1482
  if (existingPaths) {
1479
1483
  existingPaths.add(changedPath);
@@ -1481,24 +1485,26 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1481
1485
  changedPackagePaths.set(packageName, new Set([changedPath]));
1482
1486
  }
1483
1487
  }
1488
+ const debounceMs = isInitial ? 0 : watchConfig.debounceMs;
1484
1489
  debounceTimeout = setTimeout(() => {
1485
1490
  if (closed) {
1486
1491
  return;
1487
1492
  }
1488
1493
  const packageChanges = new Map;
1489
1494
  for (const [packageName2, paths] of changedPackagePaths) {
1490
- const processedPaths = filterFilesModifiedSince(dedupeSharedPaths(Array.from(paths), DedupePathsBy.Child).sort(), assertDefined12(startedDebounceMs) - fileModifiedThresholdMs);
1495
+ const dedupedPaths = dedupeSharedPaths(Array.from(paths), DedupePathsBy.Child).sort();
1496
+ const processedPaths = filterFilesModifiedSince(dedupedPaths, assertDefined12(startedDebounceMs) - fileModifiedThresholdMs);
1491
1497
  if (processedPaths.length) {
1492
1498
  packageChanges.set(packageName2, processedPaths);
1493
1499
  }
1494
1500
  }
1495
1501
  startedDebounceMs = undefined;
1496
1502
  changedPackagePaths.clear();
1497
- if (!packageChanges.size && !forceEmpty) {
1503
+ if (!packageChanges.size && !isInitial) {
1498
1504
  return;
1499
1505
  }
1500
1506
  onProcessPackage(packageGraphs, packageChanges, watchConfig, (reset) => useController(reset), logger);
1501
- }, watchConfig.debounceMs);
1507
+ }, debounceMs);
1502
1508
  };
1503
1509
  const watchers = dedupedRootPackageData.map(({
1504
1510
  name,
@@ -1506,29 +1512,45 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1506
1512
  }) => {
1507
1513
  const watchPath = dirname8(path);
1508
1514
  return watch(watchPath, { recursive: true }, (event, filePath) => {
1509
- onWatchEvent(watchPath, name, event, filePath);
1515
+ onWatchEvent({
1516
+ watchPath,
1517
+ packageName: name,
1518
+ event,
1519
+ filePath: filePath ?? undefined
1520
+ });
1510
1521
  });
1511
1522
  });
1512
1523
  const closeWatchers = () => {
1513
1524
  watchers.forEach((watcher) => {
1514
1525
  watcher.close();
1515
1526
  });
1516
- logger.debug(dim10("Aborting controller: closing watchers."));
1527
+ logger.debug(styleText10("dim", "Aborting controller: closing watchers."));
1517
1528
  controller?.abort();
1518
1529
  closed = true;
1519
1530
  };
1520
1531
  process.on("SIGINT", () => {
1521
- logger.debug(dim10("Received SIGINT: closing watchers."));
1532
+ logger.debug(styleText10("dim", "Received SIGINT: closing watchers."));
1522
1533
  closeWatchers();
1523
1534
  process.exit(0);
1524
1535
  });
1525
- onWatchEvent(undefined, undefined, undefined, null, true);
1536
+ Promise.resolve(watchConfig.hooks.onInit()).then(async (onInitShellCommand) => {
1537
+ if (onInitShellCommand) {
1538
+ await runSubprocess({
1539
+ debugName: `on init`,
1540
+ shellCommand: onInitShellCommand,
1541
+ signal: useController(false).signal,
1542
+ cwd: rootDir,
1543
+ logger
1544
+ });
1545
+ }
1546
+ onWatchEvent({ isInitial: true });
1547
+ });
1526
1548
  return { close: () => {
1527
1549
  if (closed) {
1528
- logger.debug(dim10("Watchers already closed."));
1550
+ logger.debug(styleText10("dim", "Watchers already closed."));
1529
1551
  return;
1530
1552
  }
1531
- logger.debug(dim10("Closing watchers."));
1553
+ logger.debug(styleText10("dim", "Closing watchers."));
1532
1554
  closeWatchers();
1533
1555
  } };
1534
1556
  };
@@ -1563,11 +1585,11 @@ var bumpPackageVersion = (options) => {
1563
1585
  };
1564
1586
  var watchPackages = (options) => {
1565
1587
  checkBun();
1566
- watchPackageChanges(options.packageData, options.packageGraphs, options.config.watch, options.config.logger);
1588
+ watchPackageChanges(options.packageData, options.packageGraphs, options.config.watch, options.rootDir, options.config.logger);
1567
1589
  };
1568
1590
  var forEachPackage = (options) => {
1569
1591
  checkBun();
1570
- return runForEachPackage(options.packageGraphs, options.packageOrder, options.getCommand, options.parallel ?? true, options.topological ?? true, options.config.logger);
1592
+ return runForEachPackage(options.packageGraphs, options.packageOrder, options.getCommand, options.config.logger, options.topological, options.concurrency);
1571
1593
  };
1572
1594
  export {
1573
1595
  watchPackages,
@@ -1581,5 +1603,5 @@ export {
1581
1603
  BumpVersionType
1582
1604
  };
1583
1605
 
1584
- //# debugId=F0FEFB088F7E727464756E2164756E21
1606
+ //# debugId=A9DE039F45717FA664756E2164756E21
1585
1607
  //# sourceMappingURL=index.js.map