@package-pal/core 0.0.1 → 0.0.3

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 (140) hide show
  1. package/{dist/index.js → index.js} +458 -304
  2. package/index.js.map +52 -0
  3. package/package.json +34 -43
  4. package/dist/index.d.ts +0 -18
  5. package/dist/index.d.ts.map +0 -1
  6. package/dist/index.js.map +0 -50
  7. package/dist/lib/api.d.ts +0 -45
  8. package/dist/lib/api.d.ts.map +0 -1
  9. package/dist/lib/configuration/functions/check-bun.d.ts +0 -2
  10. package/dist/lib/configuration/functions/check-bun.d.ts.map +0 -1
  11. package/dist/lib/configuration/functions/get-default-logger.d.ts +0 -4
  12. package/dist/lib/configuration/functions/get-default-logger.d.ts.map +0 -1
  13. package/dist/lib/configuration/functions/is-root-dir.d.ts +0 -2
  14. package/dist/lib/configuration/functions/is-root-dir.d.ts.map +0 -1
  15. package/dist/lib/configuration/functions/load-config.d.ts +0 -3
  16. package/dist/lib/configuration/functions/load-config.d.ts.map +0 -1
  17. package/dist/lib/configuration/functions/parse-config.d.ts +0 -27
  18. package/dist/lib/configuration/functions/parse-config.d.ts.map +0 -1
  19. package/dist/lib/configuration/functions/search-config-path.d.ts +0 -2
  20. package/dist/lib/configuration/functions/search-config-path.d.ts.map +0 -1
  21. package/dist/lib/configuration/functions/validate-config-path.d.ts +0 -6
  22. package/dist/lib/configuration/functions/validate-config-path.d.ts.map +0 -1
  23. package/dist/lib/configuration/functions/z-loose-function.d.ts +0 -3
  24. package/dist/lib/configuration/functions/z-loose-function.d.ts.map +0 -1
  25. package/dist/lib/configuration/functions/z-loose-object-without-index-signature.d.ts +0 -4
  26. package/dist/lib/configuration/functions/z-loose-object-without-index-signature.d.ts.map +0 -1
  27. package/dist/lib/configuration/schemas/config.d.ts +0 -121
  28. package/dist/lib/configuration/schemas/config.d.ts.map +0 -1
  29. package/dist/lib/configuration/types/activated-config.d.ts +0 -5
  30. package/dist/lib/configuration/types/activated-config.d.ts.map +0 -1
  31. package/dist/lib/configuration/types/config-validation-result.d.ts +0 -10
  32. package/dist/lib/configuration/types/config-validation-result.d.ts.map +0 -1
  33. package/dist/lib/configuration/types/config.d.ts +0 -25
  34. package/dist/lib/configuration/types/config.d.ts.map +0 -1
  35. package/dist/lib/configuration/types/logger.d.ts +0 -7
  36. package/dist/lib/configuration/types/logger.d.ts.map +0 -1
  37. package/dist/lib/configuration/types/packages-ready-callback-props.d.ts +0 -7
  38. package/dist/lib/configuration/types/packages-ready-callback-props.d.ts.map +0 -1
  39. package/dist/lib/configuration/types/process-package-callback-props.d.ts +0 -10
  40. package/dist/lib/configuration/types/process-package-callback-props.d.ts.map +0 -1
  41. package/dist/lib/configuration/types/subprocess-callback.d.ts +0 -2
  42. package/dist/lib/configuration/types/subprocess-callback.d.ts.map +0 -1
  43. package/dist/lib/configuration/types/supported-config-type.d.ts +0 -11
  44. package/dist/lib/configuration/types/supported-config-type.d.ts.map +0 -1
  45. package/dist/lib/graph/functions/dfs-traverse-graph-paths.d.ts +0 -3
  46. package/dist/lib/graph/functions/dfs-traverse-graph-paths.d.ts.map +0 -1
  47. package/dist/lib/graph/functions/dfs-traverse-graph.d.ts +0 -4
  48. package/dist/lib/graph/functions/dfs-traverse-graph.d.ts.map +0 -1
  49. package/dist/lib/graph/functions/extract-subgraph.d.ts +0 -3
  50. package/dist/lib/graph/functions/extract-subgraph.d.ts.map +0 -1
  51. package/dist/lib/graph/functions/generate-graphs.d.ts +0 -8
  52. package/dist/lib/graph/functions/generate-graphs.d.ts.map +0 -1
  53. package/dist/lib/graph/functions/generate-package-circular-dependency-paths.d.ts +0 -5
  54. package/dist/lib/graph/functions/generate-package-circular-dependency-paths.d.ts.map +0 -1
  55. package/dist/lib/graph/functions/generate-topological-ranking-range.d.ts +0 -3
  56. package/dist/lib/graph/functions/generate-topological-ranking-range.d.ts.map +0 -1
  57. package/dist/lib/graph/functions/generate-topological-ranking.d.ts +0 -2
  58. package/dist/lib/graph/functions/generate-topological-ranking.d.ts.map +0 -1
  59. package/dist/lib/graph/functions/generate-topological-sorted-groups.d.ts +0 -5
  60. package/dist/lib/graph/functions/generate-topological-sorted-groups.d.ts.map +0 -1
  61. package/dist/lib/graph/functions/is-disjoint.d.ts +0 -3
  62. package/dist/lib/graph/functions/is-disjoint.d.ts.map +0 -1
  63. package/dist/lib/graph/functions/is-ranked-greater-than-or-equal.d.ts +0 -3
  64. package/dist/lib/graph/functions/is-ranked-greater-than-or-equal.d.ts.map +0 -1
  65. package/dist/lib/graph/functions/is-subgraph.d.ts +0 -3
  66. package/dist/lib/graph/functions/is-subgraph.d.ts.map +0 -1
  67. package/dist/lib/graph/types/package-graph.d.ts +0 -3
  68. package/dist/lib/graph/types/package-graph.d.ts.map +0 -1
  69. package/dist/lib/graph/types/package-graphs.d.ts +0 -6
  70. package/dist/lib/graph/types/package-graphs.d.ts.map +0 -1
  71. package/dist/lib/graph/types/package-node.d.ts +0 -6
  72. package/dist/lib/graph/types/package-node.d.ts.map +0 -1
  73. package/dist/lib/graph/types/package-order.d.ts +0 -14
  74. package/dist/lib/graph/types/package-order.d.ts.map +0 -1
  75. package/dist/lib/package/functions/load-packages.d.ts +0 -4
  76. package/dist/lib/package/functions/load-packages.d.ts.map +0 -1
  77. package/dist/lib/package/functions/parse-package.d.ts +0 -3
  78. package/dist/lib/package/functions/parse-package.d.ts.map +0 -1
  79. package/dist/lib/package/functions/scan-package-paths.d.ts +0 -2
  80. package/dist/lib/package/functions/scan-package-paths.d.ts.map +0 -1
  81. package/dist/lib/package/functions/scan-packages.d.ts +0 -4
  82. package/dist/lib/package/functions/scan-packages.d.ts.map +0 -1
  83. package/dist/lib/package/functions/update-package-version.d.ts +0 -5
  84. package/dist/lib/package/functions/update-package-version.d.ts.map +0 -1
  85. package/dist/lib/package/types/package-data.d.ts +0 -11
  86. package/dist/lib/package/types/package-data.d.ts.map +0 -1
  87. package/dist/lib/types/bump-package-version-options.d.ts +0 -11
  88. package/dist/lib/types/bump-package-version-options.d.ts.map +0 -1
  89. package/dist/lib/types/bump-version-type.d.ts +0 -12
  90. package/dist/lib/types/bump-version-type.d.ts.map +0 -1
  91. package/dist/lib/types/config-options.d.ts +0 -5
  92. package/dist/lib/types/config-options.d.ts.map +0 -1
  93. package/dist/lib/types/get-config-options.d.ts +0 -5
  94. package/dist/lib/types/get-config-options.d.ts.map +0 -1
  95. package/dist/lib/types/get-package-circular-dependency-paths-options.d.ts +0 -6
  96. package/dist/lib/types/get-package-circular-dependency-paths-options.d.ts.map +0 -1
  97. package/dist/lib/types/get-package-data-options.d.ts +0 -4
  98. package/dist/lib/types/get-package-data-options.d.ts.map +0 -1
  99. package/dist/lib/types/get-package-graph-options.d.ts +0 -5
  100. package/dist/lib/types/get-package-graph-options.d.ts.map +0 -1
  101. package/dist/lib/types/get-package-order-options.d.ts +0 -5
  102. package/dist/lib/types/get-package-order-options.d.ts.map +0 -1
  103. package/dist/lib/types/package-data-options.d.ts +0 -5
  104. package/dist/lib/types/package-data-options.d.ts.map +0 -1
  105. package/dist/lib/types/package-graphs-options.d.ts +0 -5
  106. package/dist/lib/types/package-graphs-options.d.ts.map +0 -1
  107. package/dist/lib/types/package-name-options.d.ts +0 -4
  108. package/dist/lib/types/package-name-options.d.ts.map +0 -1
  109. package/dist/lib/types/package-order-options.d.ts +0 -5
  110. package/dist/lib/types/package-order-options.d.ts.map +0 -1
  111. package/dist/lib/types/watch-packages-options.d.ts +0 -6
  112. package/dist/lib/types/watch-packages-options.d.ts.map +0 -1
  113. package/dist/lib/watch/functions/filter-files-modified-since.d.ts +0 -2
  114. package/dist/lib/watch/functions/filter-files-modified-since.d.ts.map +0 -1
  115. package/dist/lib/watch/functions/get-commands-for-shell.d.ts +0 -2
  116. package/dist/lib/watch/functions/get-commands-for-shell.d.ts.map +0 -1
  117. package/dist/lib/watch/functions/get-line-buffered-writer.d.ts +0 -2
  118. package/dist/lib/watch/functions/get-line-buffered-writer.d.ts.map +0 -1
  119. package/dist/lib/watch/functions/normalise-watched-file-path.d.ts +0 -2
  120. package/dist/lib/watch/functions/normalise-watched-file-path.d.ts.map +0 -1
  121. package/dist/lib/watch/functions/read-stream.d.ts +0 -2
  122. package/dist/lib/watch/functions/read-stream.d.ts.map +0 -1
  123. package/dist/lib/watch/functions/run-async.d.ts +0 -3
  124. package/dist/lib/watch/functions/run-async.d.ts.map +0 -1
  125. package/dist/lib/watch/functions/run-subprocess.d.ts +0 -11
  126. package/dist/lib/watch/functions/run-subprocess.d.ts.map +0 -1
  127. package/dist/lib/watch/functions/watch-package-changes.d.ts +0 -8
  128. package/dist/lib/watch/functions/watch-package-changes.d.ts.map +0 -1
  129. package/dist/lib/watch/types/change-action.d.ts +0 -8
  130. package/dist/lib/watch/types/change-action.d.ts.map +0 -1
  131. package/dist/lib/watch/types/exit-state.d.ts +0 -8
  132. package/dist/lib/watch/types/exit-state.d.ts.map +0 -1
  133. package/dist/lib/watch/types/package-changes.d.ts +0 -2
  134. package/dist/lib/watch/types/package-changes.d.ts.map +0 -1
  135. package/dist/lib/watch/types/run-async-type.d.ts +0 -7
  136. package/dist/lib/watch/types/run-async-type.d.ts.map +0 -1
  137. package/dist/lib/watch/types/spawn-options.d.ts +0 -4
  138. package/dist/lib/watch/types/spawn-options.d.ts.map +0 -1
  139. package/dist/lib/watch/types/std-type.d.ts +0 -7
  140. package/dist/lib/watch/types/std-type.d.ts.map +0 -1
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- // src/lib/types/bump-version-type.ts
2
+ // packages/core/src/lib/types/bump-version-type.ts
3
3
  var BumpVersionType = {
4
4
  Major: "major",
5
5
  Minor: "minor",
@@ -9,17 +9,19 @@ var BumpVersionType = {
9
9
  Prepatch: "prepatch",
10
10
  Prerelease: "prerelease"
11
11
  };
12
- // src/lib/api.ts
12
+ // packages/core/src/lib/api.ts
13
13
  import { isDefined as isDefined5 } from "@package-pal/util";
14
14
 
15
- // src/lib/configuration/functions/check-bun.ts
15
+ // packages/core/src/lib/configuration/functions/check-bun.ts
16
16
  var checkBun = () => {
17
17
  if (!Bun) {
18
18
  throw new Error("This package must be run with the Bun runtime.");
19
19
  }
20
20
  };
21
21
 
22
- // src/lib/configuration/functions/load-config.ts
22
+ // packages/core/src/lib/configuration/functions/load-config.ts
23
+ import { dirname as dirname3 } from "path";
24
+ import { cwd } from "process";
23
25
  import {
24
26
  deepMergeDefined,
25
27
  formatSimpleLogObject,
@@ -30,7 +32,7 @@ import {
30
32
  dim
31
33
  } from "yoctocolors";
32
34
 
33
- // src/lib/configuration/functions/get-default-logger.ts
35
+ // packages/core/src/lib/configuration/functions/get-default-logger.ts
34
36
  import {
35
37
  assertDefined,
36
38
  noOp
@@ -52,10 +54,10 @@ var getDefaultLogger = (logLevel) => {
52
54
  };
53
55
  };
54
56
 
55
- // src/lib/configuration/schemas/config.ts
57
+ // packages/core/src/lib/configuration/schemas/config.ts
56
58
  import * as z3 from "zod/mini";
57
59
 
58
- // src/lib/configuration/functions/z-loose-function.ts
60
+ // packages/core/src/lib/configuration/functions/z-loose-function.ts
59
61
  import { z } from "zod/mini";
60
62
  var zLooseFunction = () => {
61
63
  return z.transform((arg, ctx) => {
@@ -71,13 +73,13 @@ var zLooseFunction = () => {
71
73
  });
72
74
  };
73
75
 
74
- // src/lib/configuration/functions/z-loose-object-without-index-signature.ts
76
+ // packages/core/src/lib/configuration/functions/z-loose-object-without-index-signature.ts
75
77
  import * as z2 from "zod/mini";
76
78
  var zLooseObjectWithoutIndexSignature = (shape, params) => {
77
79
  return z2.looseObject(shape, params);
78
80
  };
79
81
 
80
- // src/lib/configuration/schemas/config.ts
82
+ // packages/core/src/lib/configuration/schemas/config.ts
81
83
  var LogLevel = z3.enum([
82
84
  "debug",
83
85
  "info",
@@ -112,13 +114,13 @@ var Config = z3.object({
112
114
  logLevel: z3.optional(LogLevel)
113
115
  });
114
116
 
115
- // src/lib/configuration/functions/validate-config-path.ts
117
+ // packages/core/src/lib/configuration/functions/validate-config-path.ts
116
118
  import {
117
119
  basename,
118
120
  extname
119
121
  } from "path";
120
122
 
121
- // src/lib/configuration/types/supported-config-type.ts
123
+ // packages/core/src/lib/configuration/types/supported-config-type.ts
122
124
  var SupportedConfigType = {
123
125
  TS: "ts",
124
126
  CTS: "cts",
@@ -128,7 +130,7 @@ var SupportedConfigType = {
128
130
  MJS: "mjs"
129
131
  };
130
132
 
131
- // src/lib/configuration/functions/validate-config-path.ts
133
+ // packages/core/src/lib/configuration/functions/validate-config-path.ts
132
134
  var CONFIG_SUPPORTED_BASE_NAME = "ppal.config";
133
135
  var CONFIG_SUPPORTED_TYPES = Object.values(SupportedConfigType);
134
136
  var CONFIG_SUPPORTED_NAMES = CONFIG_SUPPORTED_TYPES.map((type) => `${CONFIG_SUPPORTED_BASE_NAME}.${type}`);
@@ -149,7 +151,7 @@ var validateConfigPath = (path) => {
149
151
  };
150
152
  };
151
153
 
152
- // src/lib/configuration/functions/parse-config.ts
154
+ // packages/core/src/lib/configuration/functions/parse-config.ts
153
155
  var parseConfig = async (path) => {
154
156
  const result = validateConfigPath(path);
155
157
  if (!result.valid) {
@@ -160,7 +162,7 @@ var parseConfig = async (path) => {
160
162
  return Config.parse(base);
161
163
  };
162
164
 
163
- // src/lib/configuration/functions/search-config-path.ts
165
+ // packages/core/src/lib/configuration/functions/search-config-path.ts
164
166
  import {
165
167
  isAbsolute,
166
168
  join,
@@ -168,13 +170,13 @@ import {
168
170
  } from "path";
169
171
  import { isDefined } from "@package-pal/util";
170
172
 
171
- // src/lib/configuration/functions/is-root-dir.ts
173
+ // packages/core/src/lib/configuration/functions/is-root-dir.ts
172
174
  import { dirname } from "path";
173
175
  var isRootDir = (path) => {
174
176
  return dirname(path) === path;
175
177
  };
176
178
 
177
- // src/lib/configuration/functions/search-config-path.ts
179
+ // packages/core/src/lib/configuration/functions/search-config-path.ts
178
180
  var dirDistLimit = 25;
179
181
  var checkForConfigInDir = async (dir) => {
180
182
  return new Promise((resolve) => {
@@ -217,7 +219,7 @@ var searchConfigPath = async (pathOverride) => {
217
219
  return checkForConfigInDir(activeDir);
218
220
  };
219
221
 
220
- // src/lib/configuration/functions/load-config.ts
222
+ // packages/core/src/lib/configuration/functions/load-config.ts
221
223
  var defaultConfig = {
222
224
  packages: "packages/*",
223
225
  version: {
@@ -249,12 +251,15 @@ var loadConfig = async (overrideConfigPath) => {
249
251
  const path = await searchConfigPath(overrideConfigPath);
250
252
  if (!path) {
251
253
  defaultConfig.logger.info("No config file found. Defaults will be applied.");
252
- return defaultConfig;
254
+ return {
255
+ config: defaultConfig,
256
+ rootDir: cwd()
257
+ };
253
258
  }
254
259
  const parsedConfig = await parseConfig(path);
255
260
  const parsedLogger = parsedConfig["logger"];
256
261
  const logger = parsedLogger ?? (!parsedConfig.logLevel || parsedConfig.logLevel === defaultConfig.logLevel ? defaultConfig.logger : getDefaultLogger(parsedConfig.logLevel));
257
- logger.info(`Successfully loaded config file '${path}'.`);
262
+ logger.debug(`Successfully loaded config file '${path}'.`);
258
263
  logger.debug(dim(bgGray("User config:")), `
259
264
  ${dim(formatSimpleLogObject(parsedConfig))}`);
260
265
  logger.debug(dim(bgGray("Default config:")), `
@@ -263,10 +268,13 @@ ${dim(formatSimpleLogObject(defaultConfig))}`);
263
268
  activatedConfig.logger = logger;
264
269
  logger.debug(dim(bgGray("Activated config:")), `
265
270
  ${dim(formatSimpleLogObject(activatedConfig))}`);
266
- return activatedConfig;
271
+ return {
272
+ config: activatedConfig,
273
+ rootDir: dirname3(path)
274
+ };
267
275
  };
268
276
 
269
- // src/lib/graph/functions/generate-graphs.ts
277
+ // packages/core/src/lib/graph/functions/generate-graphs.ts
270
278
  import { assertDefined as assertDefined2 } from "@package-pal/util";
271
279
  import { dim as dim2 } from "yoctocolors";
272
280
  var trackPackageEntryDependencies = ({
@@ -324,14 +332,14 @@ var generateGraphs = (packages, logger) => {
324
332
  };
325
333
  };
326
334
 
327
- // src/lib/graph/functions/generate-package-circular-dependency-paths.ts
335
+ // packages/core/src/lib/graph/functions/generate-package-circular-dependency-paths.ts
328
336
  import { assertDefined as assertDefined6 } from "@package-pal/util";
329
337
  import {
330
338
  dim as dim3,
331
339
  yellow
332
340
  } from "yoctocolors";
333
341
 
334
- // src/lib/graph/functions/dfs-traverse-graph-paths.ts
342
+ // packages/core/src/lib/graph/functions/dfs-traverse-graph-paths.ts
335
343
  import { assertDefined as assertDefined3 } from "@package-pal/util";
336
344
  var dfsTraverseGraphPaths = function* (graph, traverseFromPackages) {
337
345
  const globalVisited = new Set;
@@ -381,10 +389,10 @@ var dfsTraverseGraphPaths = function* (graph, traverseFromPackages) {
381
389
  }
382
390
  };
383
391
 
384
- // src/lib/graph/functions/extract-subgraph.ts
392
+ // packages/core/src/lib/graph/functions/extract-subgraph.ts
385
393
  import { assertDefined as assertDefined5 } from "@package-pal/util";
386
394
 
387
- // src/lib/graph/functions/dfs-traverse-graph.ts
395
+ // packages/core/src/lib/graph/functions/dfs-traverse-graph.ts
388
396
  import { assertDefined as assertDefined4 } from "@package-pal/util";
389
397
  var dfsTraverseGraph = function* (graph, traverseFromPackages) {
390
398
  const visited = new Set;
@@ -408,7 +416,7 @@ var dfsTraverseGraph = function* (graph, traverseFromPackages) {
408
416
  }
409
417
  };
410
418
 
411
- // src/lib/graph/functions/extract-subgraph.ts
419
+ // packages/core/src/lib/graph/functions/extract-subgraph.ts
412
420
  var extractSubgraph = (graph, fromPackages) => {
413
421
  const reachablePackages = new Set(dfsTraverseGraph(graph, fromPackages).map((packageData) => packageData.name));
414
422
  const subgraph = new Map;
@@ -423,7 +431,7 @@ var extractSubgraph = (graph, fromPackages) => {
423
431
  return subgraph;
424
432
  };
425
433
 
426
- // src/lib/graph/functions/generate-package-circular-dependency-paths.ts
434
+ // packages/core/src/lib/graph/functions/generate-package-circular-dependency-paths.ts
427
435
  var findStronglyConnectedComponents = (graph) => {
428
436
  let index = 0;
429
437
  const indices = new Map;
@@ -497,7 +505,7 @@ ${sampleCycleContents}`));
497
505
  return sampleCycles;
498
506
  };
499
507
 
500
- // src/lib/graph/functions/generate-topological-sorted-groups.ts
508
+ // packages/core/src/lib/graph/functions/generate-topological-sorted-groups.ts
501
509
  import { assertDefined as assertDefined7 } from "@package-pal/util";
502
510
  import {
503
511
  dim as dim4,
@@ -557,12 +565,12 @@ var generateTopologicalSortedGroups = (packageGraph, logger) => {
557
565
  };
558
566
  };
559
567
 
560
- // src/lib/package/functions/load-packages.ts
568
+ // packages/core/src/lib/package/functions/load-packages.ts
561
569
  import { dim as dim6 } from "yoctocolors";
562
570
 
563
- // src/lib/package/functions/scan-packages.ts
571
+ // packages/core/src/lib/package/functions/scan-packages.ts
564
572
  import {
565
- dirname as dirname4,
573
+ dirname as dirname5,
566
574
  join as join2
567
575
  } from "path";
568
576
  import { formatUnknownError } from "@package-pal/util";
@@ -571,9 +579,9 @@ import {
571
579
  red
572
580
  } from "yoctocolors";
573
581
 
574
- // src/lib/package/functions/parse-package.ts
582
+ // packages/core/src/lib/package/functions/parse-package.ts
575
583
  import {
576
- dirname as dirname3,
584
+ dirname as dirname4,
577
585
  basename as basename2
578
586
  } from "path";
579
587
  import { isDefined as isDefined2 } from "@package-pal/util";
@@ -595,7 +603,7 @@ var parsePackage = (path, text) => {
595
603
  rawContent: text,
596
604
  path,
597
605
  name: props.name ?? path,
598
- dir: basename2(dirname3(path)),
606
+ dir: basename2(dirname4(path)),
599
607
  version: props.version ?? undefined,
600
608
  dependencies: dependencies ?? undefined,
601
609
  peerDependencies: peerDependencies ?? undefined,
@@ -603,22 +611,28 @@ var parsePackage = (path, text) => {
603
611
  };
604
612
  };
605
613
 
606
- // src/lib/package/functions/scan-package-paths.ts
614
+ // packages/core/src/lib/package/functions/scan-package-paths.ts
607
615
  import { scanGlobPatternPaths } from "@package-pal/util";
608
- var scanPackagePaths = (packages) => {
616
+ var scanPackagePaths = (packages, cwd2) => {
609
617
  return scanGlobPatternPaths(packages, {
610
618
  absolute: true,
611
- onlyFiles: false
619
+ onlyFiles: false,
620
+ cwd: cwd2
612
621
  });
613
622
  };
614
623
 
615
- // src/lib/package/functions/scan-packages.ts
616
- var scanPackages = async function* (patterns, logger) {
617
- for await (const path of scanPackagePaths(patterns)) {
624
+ // packages/core/src/lib/package/functions/scan-packages.ts
625
+ var scanPackages = async function* (patterns, logger, cwd2) {
626
+ for await (const path of scanPackagePaths(patterns, cwd2)) {
618
627
  const packagePath = join2(path, "package.json");
619
- const dir = dirname4(packagePath);
628
+ const dir = dirname5(packagePath);
620
629
  try {
630
+ logger.debug(dim5(`Trying to read read package.json in '${dir}'.`));
621
631
  const file = Bun.file(packagePath);
632
+ if (!file.size) {
633
+ logger.debug(dim5(`Failed to read package.json in '${dir}' - ${red("File not found")}.`));
634
+ continue;
635
+ }
622
636
  const text = await file.text();
623
637
  const packageData = parsePackage(packagePath, text);
624
638
  if (!packageData) {
@@ -633,13 +647,13 @@ var scanPackages = async function* (patterns, logger) {
633
647
  }
634
648
  };
635
649
 
636
- // src/lib/package/functions/load-packages.ts
637
- var loadPackages = async (packagePatterns, logger) => {
650
+ // packages/core/src/lib/package/functions/load-packages.ts
651
+ var loadPackages = async (rootDir, packagePatterns, logger) => {
638
652
  const patternContent = packagePatterns.map((pattern) => `'${pattern}'`).join(", ");
639
- logger.debug(dim6(`Loading packages matching pattern/s ${patternContent}...`));
653
+ logger.debug(dim6(`Loading packages matching pattern/s ${patternContent}...${rootDir ? ` from ${rootDir}` : ""}`));
640
654
  const packages = [];
641
655
  const seen = new Set;
642
- for await (const packageData of scanPackages(Array.from(new Set(packagePatterns)), logger)) {
656
+ for await (const packageData of scanPackages(Array.from(new Set(packagePatterns)), logger, rootDir)) {
643
657
  if (seen.has(packageData.name)) {
644
658
  continue;
645
659
  }
@@ -652,10 +666,285 @@ var loadPackages = async (packagePatterns, logger) => {
652
666
  return packages;
653
667
  };
654
668
 
655
- // src/lib/package/functions/update-package-version.ts
669
+ // packages/core/src/lib/package/functions/run-for-each-package.ts
670
+ import { dirname as dirname6 } from "path";
671
+ import {
672
+ assertDefined as assertDefined9,
673
+ runAsync,
674
+ RunAsyncType
675
+ } from "@package-pal/util";
676
+
677
+ // packages/core/src/lib/process/functions/run-subprocess.ts
678
+ import {
679
+ dim as dim7,
680
+ red as red2
681
+ } from "yoctocolors";
682
+
683
+ // packages/core/src/lib/process/types/exit-state.ts
684
+ var ExitState = {
685
+ Completed: "Completed",
686
+ Errored: "Errored",
687
+ Cancelled: "Cancelled"
688
+ };
689
+
690
+ // packages/core/src/lib/process/types/std-type.ts
691
+ var StdType = {
692
+ Out: "Out",
693
+ Err: "Err"
694
+ };
695
+
696
+ // packages/core/src/lib/process/functions/get-commands-for-shell.ts
697
+ import {
698
+ escapeShellArg,
699
+ getShell,
700
+ Shell
701
+ } from "@package-pal/util";
702
+
703
+ // packages/core/src/lib/process/functions/parse-ps-flags.ts
704
+ import { assertDefined as assertDefined8 } from "@package-pal/util";
705
+ var knownFlagsWithParams = new Set([
706
+ "-executionpolicy",
707
+ "-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"
728
+ ]);
729
+ var knownFlagsNoParams = new Set([
730
+ "-noprofile",
731
+ "-noninteractive",
732
+ "-nologo",
733
+ "-sta",
734
+ "-mta",
735
+ "-encodedcommand",
736
+ "-command",
737
+ "-help",
738
+ "-?",
739
+ "-verbose",
740
+ "-debug",
741
+ "-whatif",
742
+ "-confirm",
743
+ "-usewindowspowershell",
744
+ "-noexit"
745
+ ]);
746
+ var parsePsFlags = (input) => {
747
+ const tokens = input.trim().split(/\s+/);
748
+ const flags = [];
749
+ let i = 0;
750
+ while (i < tokens.length) {
751
+ const token = assertDefined8(tokens[i]);
752
+ const tokenLower = token.toLowerCase();
753
+ if (knownFlagsWithParams.has(tokenLower)) {
754
+ if (i + 1 >= tokens.length) {
755
+ break;
756
+ }
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;
765
+ }
766
+ break;
767
+ }
768
+ const command = tokens.slice(i).join(" ");
769
+ return {
770
+ flags,
771
+ command
772
+ };
773
+ };
774
+
775
+ // packages/core/src/lib/process/functions/get-commands-for-shell.ts
776
+ var shell;
777
+ var getCommandsForShell = (shellCommand) => {
778
+ shell = shell ?? getShell();
779
+ switch (shell) {
780
+ case Shell.cmd:
781
+ return [
782
+ shell,
783
+ "/c",
784
+ escapeShellArg(shellCommand, shell)
785
+ ];
786
+ case Shell.pwsh:
787
+ case Shell.powershell:
788
+ const {
789
+ flags,
790
+ command
791
+ } = parsePsFlags(shellCommand);
792
+ const encodedCommand = Buffer.from(command, "utf16le").toString("base64");
793
+ return [
794
+ shell,
795
+ ...flags,
796
+ ...encodedCommand ? ["-EncodedCommand", encodedCommand] : []
797
+ ];
798
+ default:
799
+ return [
800
+ shell,
801
+ "-c",
802
+ escapeShellArg(shellCommand, shell)
803
+ ];
804
+ }
805
+ };
806
+
807
+ // packages/core/src/lib/process/functions/get-line-buffered-writer.ts
808
+ import { identity } from "@package-pal/util";
809
+ var getLineBufferedWriter = (prefix, style = identity, write = process.stdout.write.bind(process.stdout)) => {
810
+ let buffer = "";
811
+ return (chunk) => {
812
+ buffer += chunk;
813
+ const lines = buffer.split(`
814
+ `);
815
+ buffer = lines.pop() ?? "";
816
+ for (const line of lines) {
817
+ write(`${prefix}${style(line)}
818
+ `);
819
+ }
820
+ };
821
+ };
822
+
823
+ // packages/core/src/lib/process/functions/read-stream.ts
824
+ var readStream = async (stream, use) => {
825
+ if (!stream) {
826
+ return;
827
+ }
828
+ const decoder = new TextDecoder;
829
+ const reader = stream.getReader();
830
+ let result = await reader.read();
831
+ while (!result.done) {
832
+ use(decoder.decode(result.value, { stream: true }));
833
+ result = await reader.read();
834
+ }
835
+ const flush = decoder.decode();
836
+ if (flush) {
837
+ use(flush);
838
+ }
839
+ };
840
+
841
+ // packages/core/src/lib/process/functions/run-subprocess.ts
842
+ var sigintCode = 130;
843
+ var sigtermCode = 143;
844
+ var sigkillCode = 137;
845
+ var cancelCodes = new Set([
846
+ sigintCode,
847
+ sigtermCode,
848
+ sigkillCode
849
+ ]);
850
+ var runSubprocess = async (opts) => {
851
+ if (opts.signal?.aborted) {
852
+ opts.logger.debug(dim7(`Skipped '${opts.debugName}' subprocess command; signal already cancelled.`));
853
+ return ExitState.Cancelled;
854
+ }
855
+ const commands = getCommandsForShell(opts.shellCommand);
856
+ const subprocess = Bun.spawn(commands, {
857
+ cwd: opts.cwd,
858
+ stdout: "pipe",
859
+ stderr: "pipe",
860
+ stdin: "ignore",
861
+ signal: opts.signal
862
+ });
863
+ const pid = subprocess.pid.toString();
864
+ const minPrefixLen = 14;
865
+ const [readStdout, readStderr] = [{
866
+ source: subprocess.stdout,
867
+ type: StdType.Out,
868
+ write: getLineBufferedWriter(dim7(`[O-${pid}]`.padEnd(minPrefixLen, " ")))
869
+ }, {
870
+ source: subprocess.stderr,
871
+ type: StdType.Err,
872
+ write: getLineBufferedWriter(red2(dim7(`[E-${pid}]`.padEnd(minPrefixLen, " "))))
873
+ }].map(({
874
+ source,
875
+ type,
876
+ write
877
+ }) => {
878
+ return readStream(source, (chunk) => {
879
+ write(chunk);
880
+ if (opts.onStdChunk) {
881
+ opts.onStdChunk(chunk, type);
882
+ }
883
+ });
884
+ });
885
+ const executedCommand = commands.join(" ");
886
+ opts.logger.debug(dim7(`Started '${opts.debugName}' subprocess command '${opts.shellCommand}' (${executedCommand}) with PID ${pid}.`));
887
+ const [
888
+ ,
889
+ ,
890
+ exitState
891
+ ] = await Promise.all([
892
+ readStdout,
893
+ readStderr,
894
+ subprocess.exited.then((exitCode) => {
895
+ if (cancelCodes.has(exitCode)) {
896
+ opts.logger.debug(dim7(`Cancelled '${opts.debugName}' subprocess command; PID ${pid} exited.`));
897
+ return ExitState.Cancelled;
898
+ }
899
+ if (exitCode !== 0) {
900
+ opts.logger.error(red2(`'${opts.debugName}' command '${opts.shellCommand}' (${executedCommand}) with PID ${pid} failed with exit code ${exitCode.toString()}.`));
901
+ return ExitState.Errored;
902
+ }
903
+ opts.logger.debug(dim7(`Completed '${opts.debugName}' subprocess command; PID ${pid} exited.`));
904
+ return ExitState.Completed;
905
+ })
906
+ ]);
907
+ return exitState;
908
+ };
909
+
910
+ // packages/core/src/lib/package/functions/run-for-each-package.ts
911
+ var runForEachPackage = async (packageGraphs, packageOrder, getCommand, parallel, topological, logger) => {
912
+ const controller = new AbortController;
913
+ let processPackageOrder = packageOrder.groups.concat(packageOrder.circular);
914
+ if (!topological) {
915
+ processPackageOrder = [processPackageOrder.flat()];
916
+ }
917
+ for (const group of processPackageOrder) {
918
+ await runAsync(parallel ? RunAsyncType.Parallel : RunAsyncType.Sequential, group.map((packageName) => async () => {
919
+ const packageNode = assertDefined9(packageGraphs.dependencies.get(packageName));
920
+ const processPackageProps = {
921
+ name: packageName,
922
+ dir: packageNode.packageData.dir
923
+ };
924
+ const processPackageCwd = dirname6(packageNode.packageData.path);
925
+ const shellCommand = await getCommand(processPackageProps);
926
+ if (!shellCommand) {
927
+ return;
928
+ }
929
+ const exitState = await runSubprocess({
930
+ debugName: `run for ${packageName}`,
931
+ shellCommand,
932
+ cwd: processPackageCwd,
933
+ signal: controller.signal,
934
+ logger
935
+ });
936
+ if (exitState === ExitState.Errored) {
937
+ controller.abort();
938
+ throw new Error("Command failed.");
939
+ }
940
+ }));
941
+ }
942
+ };
943
+
944
+ // packages/core/src/lib/package/functions/update-package-version.ts
656
945
  var {semver } = globalThis.Bun;
657
946
  import { inc } from "semver";
658
- import { dim as dim7 } from "yoctocolors";
947
+ import { dim as dim8 } from "yoctocolors";
659
948
  var findAndReplaceVersion = ({
660
949
  raw,
661
950
  field,
@@ -715,7 +1004,7 @@ var findAndReplaceVersion = ({
715
1004
  return `${before}${updatedVersion}${after}`;
716
1005
  };
717
1006
  var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact, logger) => {
718
- logger.debug(dim7(`Bumping package '${packageName}'...`));
1007
+ logger.debug(dim8(`Bumping package '${packageName}'...`));
719
1008
  const packageNode = packageGraphs.dependencies.get(packageName);
720
1009
  if (!packageNode) {
721
1010
  throw new Error(`Package '${packageName}' not found.`);
@@ -747,7 +1036,7 @@ var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact
747
1036
  return [];
748
1037
  }
749
1038
  if (exact ? depVersion === bumpedVersion : semver.satisfies(bumpedVersion, depVersion)) {
750
- logger.debug(dim7(`Skipping '${dependent.name}': ${field} version '${depVersion}' already satisfies '${bumpedVersion}'.`));
1039
+ logger.debug(dim8(`Skipping '${dependent.name}': ${field} version '${depVersion}' already satisfies '${bumpedVersion}'.`));
751
1040
  return [];
752
1041
  }
753
1042
  const updatedContent2 = findAndReplaceVersion({
@@ -767,28 +1056,67 @@ var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact
767
1056
  });
768
1057
  };
769
1058
 
770
- // src/lib/watch/functions/watch-package-changes.ts
1059
+ // packages/core/src/lib/watch/functions/watch-package-changes.ts
771
1060
  import {
772
1061
  watch
773
1062
  } from "fs";
774
1063
  import {
775
- dirname as dirname6,
1064
+ dirname as dirname8,
776
1065
  join as join4
777
1066
  } from "path";
778
1067
  import {
779
- assertDefined as assertDefined9,
1068
+ assertDefined as assertDefined12,
780
1069
  DedupePathsBy,
781
1070
  dedupeSharedPaths,
782
1071
  getDeferredPromise,
783
1072
  getStringMatcher,
784
- isDefined as isDefined4
1073
+ isDefined as isDefined4,
1074
+ RunAsyncType as RunAsyncType2,
1075
+ runAsync as runAsync2
785
1076
  } from "@package-pal/util";
786
1077
  import {
787
- dim as dim9,
1078
+ dim as dim10,
788
1079
  red as red3
789
1080
  } from "yoctocolors";
790
1081
 
791
- // src/lib/graph/functions/generate-topological-ranking-range.ts
1082
+ // packages/core/src/lib/graph/functions/merge-graphs.ts
1083
+ var mergeGraphs = (a, b) => {
1084
+ const merged = new Map;
1085
+ for (const [name, node] of a) {
1086
+ merged.set(name, {
1087
+ packageData: node.packageData,
1088
+ pointsToPackages: new Set(node.pointsToPackages)
1089
+ });
1090
+ }
1091
+ for (const [name, node] of b) {
1092
+ merged.set(name, {
1093
+ packageData: node.packageData,
1094
+ pointsToPackages: new Set(node.pointsToPackages)
1095
+ });
1096
+ }
1097
+ return merged;
1098
+ };
1099
+
1100
+ // packages/core/src/lib/watch/types/change-action.ts
1101
+ var ChangeAction = {
1102
+ Ignore: "Ignore",
1103
+ Partial: "Partial",
1104
+ Restart: "Restart"
1105
+ };
1106
+
1107
+ // packages/core/src/lib/watch/functions/filter-files-modified-since.ts
1108
+ var filterFilesModifiedSince = (paths, sinceMs) => {
1109
+ return paths.filter((path) => {
1110
+ const changedFile = Bun.file(path);
1111
+ return changedFile.lastModified >= sinceMs;
1112
+ });
1113
+ };
1114
+
1115
+ // packages/core/src/lib/watch/functions/get-change-logic.ts
1116
+ import { assertDefined as assertDefined11 } from "@package-pal/util";
1117
+ import { dim as dim9 } from "yoctocolors";
1118
+
1119
+ // packages/core/src/lib/graph/functions/generate-topological-ranking-range.ts
792
1120
  import { isDefined as isDefined3 } from "@package-pal/util";
793
1121
  var generateTopologicalRankingRange = (graph, ranking) => {
794
1122
  let min = Infinity;
@@ -811,19 +1139,19 @@ var generateTopologicalRankingRange = (graph, ranking) => {
811
1139
  return [min, max];
812
1140
  };
813
1141
 
814
- // src/lib/graph/functions/generate-topological-ranking.ts
815
- import { assertDefined as assertDefined8 } from "@package-pal/util";
1142
+ // packages/core/src/lib/graph/functions/generate-topological-ranking.ts
1143
+ import { assertDefined as assertDefined10 } from "@package-pal/util";
816
1144
  var generateTopologicalRanking = (packageProcessOrder) => {
817
1145
  const rankMap = new Map;
818
1146
  for (let i = 0;i < packageProcessOrder.length; i++) {
819
- for (const packageName of assertDefined8(packageProcessOrder[i])) {
1147
+ for (const packageName of assertDefined10(packageProcessOrder[i])) {
820
1148
  rankMap.set(packageName, i);
821
1149
  }
822
1150
  }
823
1151
  return rankMap;
824
1152
  };
825
1153
 
826
- // src/lib/graph/functions/is-disjoint.ts
1154
+ // packages/core/src/lib/graph/functions/is-disjoint.ts
827
1155
  var isDisjoint = (a, b) => {
828
1156
  for (const key of a.keys()) {
829
1157
  if (b.has(key)) {
@@ -833,7 +1161,7 @@ var isDisjoint = (a, b) => {
833
1161
  return true;
834
1162
  };
835
1163
 
836
- // src/lib/graph/functions/is-ranked-greater-than-or-equal.ts
1164
+ // packages/core/src/lib/graph/functions/is-ranked-greater-than-or-equal.ts
837
1165
  var isRankedGreaterThanOrEqual = (a, b, ranking) => {
838
1166
  const [prevMin] = generateTopologicalRankingRange(a, ranking);
839
1167
  for (const key of b.keys()) {
@@ -845,7 +1173,7 @@ var isRankedGreaterThanOrEqual = (a, b, ranking) => {
845
1173
  return true;
846
1174
  };
847
1175
 
848
- // src/lib/graph/functions/is-subgraph.ts
1176
+ // packages/core/src/lib/graph/functions/is-subgraph.ts
849
1177
  var recordEqual = (a, b) => {
850
1178
  if (!a && !b) {
851
1179
  return true;
@@ -881,220 +1209,8 @@ var isSubgraph = (a, b) => {
881
1209
  return true;
882
1210
  };
883
1211
 
884
- // src/lib/watch/types/change-action.ts
885
- var ChangeAction = {
886
- Ignore: "Ignore",
887
- Partial: "Partial",
888
- Restart: "Restart"
889
- };
890
-
891
- // src/lib/watch/types/exit-state.ts
892
- var ExitState = {
893
- Completed: "Completed",
894
- Errored: "Errored",
895
- Cancelled: "Cancelled"
896
- };
897
-
898
- // src/lib/watch/types/run-async-type.ts
899
- var RunAsyncType = {
900
- Sequential: "Sequential",
901
- Parallel: "Parallel"
902
- };
903
-
904
- // src/lib/watch/functions/filter-files-modified-since.ts
905
- var filterFilesModifiedSince = (paths, sinceMs) => {
906
- return paths.filter((path) => {
907
- const changedFile = Bun.file(path);
908
- return changedFile.lastModified >= sinceMs;
909
- });
910
- };
911
-
912
- // src/lib/watch/functions/normalise-watched-file-path.ts
913
- import {
914
- basename as basename3,
915
- dirname as dirname5,
916
- join as join3
917
- } from "path";
918
- var removeTrailing = [
919
- "~",
920
- ".tmp",
921
- ".temp",
922
- ".bak",
923
- ".backup",
924
- ".swp",
925
- ".swo",
926
- ".swn"
927
- ];
928
- var normaliseWatchedFilePath = (filePath) => {
929
- const dir = dirname5(filePath);
930
- let base = basename3(filePath);
931
- for (const trailing of removeTrailing) {
932
- if (base.toLowerCase().endsWith(trailing)) {
933
- const sliceStart = base.startsWith(".") ? 1 : 0;
934
- base = base.slice(sliceStart, -trailing.length);
935
- break;
936
- }
937
- }
938
- return join3(dir, base);
939
- };
940
-
941
- // src/lib/watch/functions/run-async.ts
942
- var runAsync = async (type, tasks) => {
943
- if (type === RunAsyncType.Parallel) {
944
- return Promise.all(tasks.map((task) => task()));
945
- }
946
- const outputs = [];
947
- for (const task of tasks) {
948
- const result = await task();
949
- outputs.push(result);
950
- }
951
- return outputs;
952
- };
953
-
954
- // src/lib/watch/functions/run-subprocess.ts
955
- import {
956
- dim as dim8,
957
- red as red2
958
- } from "yoctocolors";
959
-
960
- // src/lib/watch/types/std-type.ts
961
- var StdType = {
962
- Out: "Out",
963
- Err: "Err"
964
- };
965
-
966
- // src/lib/watch/functions/get-commands-for-shell.ts
967
- var getCommandsForShell = (shellCommand) => {
968
- const isWindows = process.platform === "win32";
969
- if (!isWindows) {
970
- return [
971
- "sh",
972
- "-c",
973
- `"${shellCommand}"`
974
- ];
975
- }
976
- const shell = Bun.which("pwsh") ? "pwsh" : Bun.which("powershell") ? "powershell" : "cmd";
977
- if (shell === "cmd") {
978
- return [
979
- shell,
980
- "/c",
981
- `"${shellCommand}"`
982
- ];
983
- }
984
- const encodedCommand = Buffer.from(shellCommand, "utf16le").toString("base64");
985
- return [
986
- shell,
987
- "-EncodedCommand",
988
- encodedCommand
989
- ];
990
- };
991
-
992
- // src/lib/watch/functions/get-line-buffered-writer.ts
993
- import { identity } from "@package-pal/util";
994
- var getLineBufferedWriter = (prefix, style = identity, write = process.stdout.write.bind(process.stdout)) => {
995
- let buffer = "";
996
- return (chunk) => {
997
- buffer += chunk;
998
- const lines = buffer.split(`
999
- `);
1000
- buffer = lines.pop() ?? "";
1001
- for (const line of lines) {
1002
- write(`${prefix}${style(line)}
1003
- `);
1004
- }
1005
- };
1006
- };
1007
-
1008
- // src/lib/watch/functions/read-stream.ts
1009
- var readStream = async (stream, use) => {
1010
- if (!stream) {
1011
- return;
1012
- }
1013
- const decoder = new TextDecoder;
1014
- const reader = stream.getReader();
1015
- let result = await reader.read();
1016
- while (!result.done) {
1017
- use(decoder.decode(result.value, { stream: true }));
1018
- result = await reader.read();
1019
- }
1020
- const flush = decoder.decode();
1021
- if (flush) {
1022
- use(flush);
1023
- }
1024
- };
1025
-
1026
- // src/lib/watch/functions/run-subprocess.ts
1027
- var sigintCode = 130;
1028
- var sigtermCode = 143;
1029
- var sigkillCode = 137;
1030
- var cancelCodes = new Set([
1031
- sigintCode,
1032
- sigtermCode,
1033
- sigkillCode
1034
- ]);
1035
- var runSubprocess = async (opts) => {
1036
- if (opts.signal?.aborted) {
1037
- opts.logger.debug(dim8(`Skipped '${opts.debugName}' subprocess command; signal already cancelled.`));
1038
- return ExitState.Cancelled;
1039
- }
1040
- const commands = getCommandsForShell(opts.shellCommand);
1041
- const subprocess = Bun.spawn(commands, {
1042
- cwd: opts.cwd,
1043
- stdout: "pipe",
1044
- stderr: "pipe",
1045
- stdin: "ignore",
1046
- signal: opts.signal
1047
- });
1048
- const pid = subprocess.pid.toString();
1049
- const [readStdout, readStderr] = [{
1050
- source: subprocess.stdout,
1051
- type: StdType.Out,
1052
- write: getLineBufferedWriter(dim8(`[OUT-${pid}] `))
1053
- }, {
1054
- source: subprocess.stderr,
1055
- type: StdType.Err,
1056
- write: getLineBufferedWriter(red2(dim8(`[ERR-${pid}] `)))
1057
- }].map(({
1058
- source,
1059
- type,
1060
- write
1061
- }) => {
1062
- return readStream(source, (chunk) => {
1063
- write(chunk);
1064
- if (opts.onStdChunk) {
1065
- opts.onStdChunk(chunk, type);
1066
- }
1067
- });
1068
- });
1069
- const executedCommand = commands.join(" ");
1070
- opts.logger.debug(dim8(`Started '${opts.debugName}' subprocess command '${opts.shellCommand}' (${executedCommand}) with PID ${pid}.`));
1071
- const [
1072
- ,
1073
- ,
1074
- exitState
1075
- ] = await Promise.all([
1076
- readStdout,
1077
- readStderr,
1078
- subprocess.exited.then((exitCode) => {
1079
- if (cancelCodes.has(exitCode)) {
1080
- opts.logger.debug(dim8(`Cancelled '${opts.debugName}' subprocess command; PID ${pid} exited.`));
1081
- return ExitState.Cancelled;
1082
- }
1083
- if (exitCode !== 0) {
1084
- opts.logger.error(red2(`'${opts.debugName}' command '${opts.shellCommand}' (${executedCommand}) with PID ${pid} failed with exit code ${exitCode.toString()}.`));
1085
- return ExitState.Errored;
1086
- }
1087
- opts.logger.debug(dim8(`Completed '${opts.debugName}' subprocess command; PID ${pid} exited.`));
1088
- return ExitState.Completed;
1089
- })
1090
- ]);
1091
- return exitState;
1092
- };
1093
-
1094
- // src/lib/watch/functions/watch-package-changes.ts
1095
- var fileModifiedThresholdMs = 5000;
1096
- var lastProcessedSubgraph;
1097
- var getChangeLogic = (packageGraphs, packageChanges, config, logger) => {
1212
+ // packages/core/src/lib/watch/functions/get-change-logic.ts
1213
+ var getChangeLogic = (packageGraphs, packageChanges, lastProcessedSubgraph, config, logger) => {
1098
1214
  const changedPackages = Array.from(packageChanges.keys());
1099
1215
  const changedFilePaths = Array.from(packageChanges.values()).flat();
1100
1216
  if (packageChanges.size) {
@@ -1124,9 +1240,9 @@ var getChangeLogic = (packageGraphs, packageChanges, config, logger) => {
1124
1240
  action = ChangeAction.Partial;
1125
1241
  }
1126
1242
  if (action === ChangeAction.Partial && isRankedGreaterThanOrEqualToPrevious) {
1127
- const [prevMinRank] = generateTopologicalRankingRange(assertDefined9(lastProcessedSubgraph), packageRankings);
1243
+ const [prevMinRank] = generateTopologicalRankingRange(assertDefined11(lastProcessedSubgraph), packageRankings);
1128
1244
  for (let i = 0;i < changedPackageProcessOrder.length; i++) {
1129
- changedPackageProcessOrder[i] = assertDefined9(changedPackageProcessOrder[i]).filter((packageName) => {
1245
+ changedPackageProcessOrder[i] = assertDefined11(changedPackageProcessOrder[i]).filter((packageName) => {
1130
1246
  const rank = packageRankings.get(packageName);
1131
1247
  return rank !== undefined && rank >= prevMinRank;
1132
1248
  });
@@ -1139,15 +1255,48 @@ var getChangeLogic = (packageGraphs, packageChanges, config, logger) => {
1139
1255
  action
1140
1256
  };
1141
1257
  };
1258
+
1259
+ // packages/core/src/lib/watch/functions/normalise-watched-file-path.ts
1260
+ import {
1261
+ basename as basename3,
1262
+ dirname as dirname7,
1263
+ join as join3
1264
+ } from "path";
1265
+ var removeTrailing = [
1266
+ "~",
1267
+ ".tmp",
1268
+ ".temp",
1269
+ ".bak",
1270
+ ".backup",
1271
+ ".swp",
1272
+ ".swo",
1273
+ ".swn"
1274
+ ];
1275
+ var normaliseWatchedFilePath = (filePath) => {
1276
+ const dir = dirname7(filePath);
1277
+ let base = basename3(filePath);
1278
+ for (const trailing of removeTrailing) {
1279
+ if (base.toLowerCase().endsWith(trailing)) {
1280
+ const sliceStart = base.startsWith(".") ? 1 : 0;
1281
+ base = base.slice(sliceStart, -trailing.length);
1282
+ break;
1283
+ }
1284
+ }
1285
+ return join3(dir, base);
1286
+ };
1287
+
1288
+ // packages/core/src/lib/watch/functions/watch-package-changes.ts
1289
+ var fileModifiedThresholdMs = 5000;
1290
+ var lastProcessedSubgraph;
1142
1291
  var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determineAbortController, logger) => {
1143
1292
  const {
1144
1293
  action,
1145
1294
  changedPackageProcessOrder,
1146
1295
  changedPackageSubgraph
1147
- } = getChangeLogic(packageGraphs, packageChanges, watchConfig, logger);
1296
+ } = getChangeLogic(packageGraphs, packageChanges, lastProcessedSubgraph, watchConfig, logger);
1148
1297
  const controller = determineAbortController(action === ChangeAction.Restart);
1149
1298
  const onProcessFailure = () => {
1150
- logger.debug(dim9("Aborting controller: process failed."));
1299
+ logger.debug(dim10("Aborting controller: process failed."));
1151
1300
  controller.abort();
1152
1301
  lastProcessedSubgraph = undefined;
1153
1302
  };
@@ -1157,7 +1306,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1157
1306
  }
1158
1307
  if (packageChanges.size) {
1159
1308
  logger.info(`Changes detected. ${action === ChangeAction.Restart ? "Restarting processing" : "Initiating partial processing"} ${watchConfig.subprocess.parallelProcessing ? "in parallel" : "sequentially"}.`);
1160
- lastProcessedSubgraph = changedPackageSubgraph;
1309
+ lastProcessedSubgraph = lastProcessedSubgraph ? mergeGraphs(lastProcessedSubgraph, changedPackageSubgraph) : changedPackageSubgraph;
1161
1310
  }
1162
1311
  for (const group of changedPackageProcessOrder) {
1163
1312
  const {
@@ -1165,12 +1314,12 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1165
1314
  resolve: matchedParallelLongReadyRunningOutput
1166
1315
  } = getDeferredPromise();
1167
1316
  let matchedLongRunningOutputCount = 0;
1168
- await runAsync(watchConfig.subprocess.parallelProcessing ? RunAsyncType.Parallel : RunAsyncType.Sequential, group.map((packageName) => async () => {
1317
+ await runAsync2(watchConfig.subprocess.parallelProcessing ? RunAsyncType2.Parallel : RunAsyncType2.Sequential, group.map((packageName) => async () => {
1169
1318
  const {
1170
1319
  promise: longRunningSequentialProcessReady,
1171
1320
  resolve: matchedSequentialLongRunningReadyOutput
1172
1321
  } = getDeferredPromise();
1173
- const packageNode = assertDefined9(packageGraphs.dependencies.get(packageName));
1322
+ const packageNode = assertDefined12(packageGraphs.dependencies.get(packageName));
1174
1323
  const changedPaths = packageChanges.get(packageName) ?? [];
1175
1324
  const processPackageProps = {
1176
1325
  name: packageName,
@@ -1180,7 +1329,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1180
1329
  totalProcessOrder: changedPackageProcessOrder,
1181
1330
  signal: controller.signal
1182
1331
  };
1183
- const processPackageCwd = dirname6(packageNode.packageData.path);
1332
+ const processPackageCwd = dirname8(packageNode.packageData.path);
1184
1333
  const beforeProcessPackageShellCommand = await watchConfig.hooks.onBeforeProcessPackage(processPackageProps);
1185
1334
  if (beforeProcessPackageShellCommand) {
1186
1335
  await runSubprocess({
@@ -1209,13 +1358,13 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1209
1358
  if (!ready && readyMatcher?.push(chunk).matched()) {
1210
1359
  ready = true;
1211
1360
  matchedLongRunningOutputCount++;
1212
- logger.debug(`'${packageName}' (${matchedLongRunningOutputCount.toString()}/${group.length.toString()}) subprocess matched ready text '${assertDefined9(longRunningOutputReadyText)}'.`);
1361
+ logger.debug(`'${packageName}' (${matchedLongRunningOutputCount.toString()}/${group.length.toString()}) subprocess matched ready text '${assertDefined12(longRunningOutputReadyText)}'.`);
1213
1362
  if (!watchConfig.subprocess.parallelProcessing && matchedLongRunningOutputCount) {
1214
1363
  matchedSequentialLongRunningReadyOutput();
1215
1364
  }
1216
1365
  }
1217
1366
  if (!errored && erroredMatcher?.push(chunk).matched()) {
1218
- logger.error(red3(`'${packageName}' subprocess matched error text '${assertDefined9(longRunningOutputErroredText)}'.`));
1367
+ logger.error(red3(`'${packageName}' subprocess matched error text '${assertDefined12(longRunningOutputErroredText)}'.`));
1219
1368
  errored = true;
1220
1369
  Promise.resolve(watchConfig.hooks.onProcessPackageError(processPackageProps)).then((processPackageErrorCommand) => {
1221
1370
  if (!processPackageErrorCommand) {
@@ -1298,23 +1447,23 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
1298
1447
  }
1299
1448
  };
1300
1449
  var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1301
- const dedupedRootPackageData = dedupeSharedPaths(packageData.map((packageData2) => packageData2.path), DedupePathsBy.Parent).map((packagePath) => assertDefined9(packageData.find((data) => data.path === packagePath)));
1302
- logger.debug(dim9(`Starting ${dedupedRootPackageData.length.toString()} watchers for ${packageData.length.toString()} packages.`));
1450
+ 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.`));
1303
1452
  let closed = false;
1304
1453
  let debounceTimeout;
1305
1454
  let startedDebounceMs;
1306
- let abortController;
1455
+ let controller;
1307
1456
  const changedPackagePaths = new Map;
1308
1457
  const useController = (reset) => {
1309
- if (abortController && (reset || abortController.signal.aborted)) {
1458
+ if (controller && (reset || controller.signal.aborted)) {
1310
1459
  if (reset) {
1311
- logger.debug(dim9("Aborting controller: reset for new packages."));
1312
- abortController.abort();
1460
+ logger.debug(dim10("Aborting controller: reset for new packages."));
1461
+ controller.abort();
1313
1462
  }
1314
- abortController = undefined;
1463
+ controller = undefined;
1315
1464
  }
1316
- abortController ??= new AbortController;
1317
- return abortController;
1465
+ controller ??= new AbortController;
1466
+ return controller;
1318
1467
  };
1319
1468
  const onWatchEvent = (watchPath, packageName, _event, filePath, forceEmpty = false) => {
1320
1469
  if (!isDefined4(startedDebounceMs)) {
@@ -1338,7 +1487,7 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1338
1487
  }
1339
1488
  const packageChanges = new Map;
1340
1489
  for (const [packageName2, paths] of changedPackagePaths) {
1341
- const processedPaths = filterFilesModifiedSince(dedupeSharedPaths(Array.from(paths), DedupePathsBy.Child).sort(), assertDefined9(startedDebounceMs) - fileModifiedThresholdMs);
1490
+ const processedPaths = filterFilesModifiedSince(dedupeSharedPaths(Array.from(paths), DedupePathsBy.Child).sort(), assertDefined12(startedDebounceMs) - fileModifiedThresholdMs);
1342
1491
  if (processedPaths.length) {
1343
1492
  packageChanges.set(packageName2, processedPaths);
1344
1493
  }
@@ -1355,7 +1504,7 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1355
1504
  name,
1356
1505
  path
1357
1506
  }) => {
1358
- const watchPath = dirname6(path);
1507
+ const watchPath = dirname8(path);
1359
1508
  return watch(watchPath, { recursive: true }, (event, filePath) => {
1360
1509
  onWatchEvent(watchPath, name, event, filePath);
1361
1510
  });
@@ -1364,27 +1513,27 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
1364
1513
  watchers.forEach((watcher) => {
1365
1514
  watcher.close();
1366
1515
  });
1367
- logger.debug(dim9("Aborting controller: closing watchers."));
1368
- abortController?.abort();
1516
+ logger.debug(dim10("Aborting controller: closing watchers."));
1517
+ controller?.abort();
1369
1518
  closed = true;
1370
1519
  };
1371
1520
  process.on("SIGINT", () => {
1372
- logger.debug(dim9("Received SIGINT: closing watchers."));
1521
+ logger.debug(dim10("Received SIGINT: closing watchers."));
1373
1522
  closeWatchers();
1374
1523
  process.exit(0);
1375
1524
  });
1376
1525
  onWatchEvent(undefined, undefined, undefined, null, true);
1377
1526
  return { close: () => {
1378
1527
  if (closed) {
1379
- logger.debug(dim9("Watchers already closed."));
1528
+ logger.debug(dim10("Watchers already closed."));
1380
1529
  return;
1381
1530
  }
1382
- logger.debug(dim9("Closing watchers."));
1531
+ logger.debug(dim10("Closing watchers."));
1383
1532
  closeWatchers();
1384
1533
  } };
1385
1534
  };
1386
1535
 
1387
- // src/lib/api.ts
1536
+ // packages/core/src/lib/api.ts
1388
1537
  var readPackagePalConfig = (options) => {
1389
1538
  checkBun();
1390
1539
  return loadConfig(options?.overrideConfigPath);
@@ -1392,7 +1541,7 @@ var readPackagePalConfig = (options) => {
1392
1541
  var readPackageData = async (options) => {
1393
1542
  checkBun();
1394
1543
  const packagePatterns = Array.isArray(options.config.packages) ? options.config.packages : [options.config.packages];
1395
- return loadPackages(packagePatterns, options.config.logger);
1544
+ return loadPackages(options.rootDir, packagePatterns, options.config.logger);
1396
1545
  };
1397
1546
  var getPackageGraphs = (options) => {
1398
1547
  checkBun();
@@ -1416,6 +1565,10 @@ var watchPackages = (options) => {
1416
1565
  checkBun();
1417
1566
  watchPackageChanges(options.packageData, options.packageGraphs, options.config.watch, options.config.logger);
1418
1567
  };
1568
+ var forEachPackage = (options) => {
1569
+ checkBun();
1570
+ return runForEachPackage(options.packageGraphs, options.packageOrder, options.getCommand, options.parallel ?? true, options.topological ?? true, options.config.logger);
1571
+ };
1419
1572
  export {
1420
1573
  watchPackages,
1421
1574
  readPackagePalConfig,
@@ -1423,9 +1576,10 @@ export {
1423
1576
  getPackageOrder,
1424
1577
  getPackageGraphs,
1425
1578
  getPackageCircularDependencyPaths,
1579
+ forEachPackage,
1426
1580
  bumpPackageVersion,
1427
1581
  BumpVersionType
1428
1582
  };
1429
1583
 
1430
- //# debugId=E0ED0EB8F615FC9B64756E2164756E21
1584
+ //# debugId=F0FEFB088F7E727464756E2164756E21
1431
1585
  //# sourceMappingURL=index.js.map