@package-pal/core 0.0.3 → 0.0.5
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.
- package/index.d.ts +17 -0
- package/index.d.ts.map +1 -0
- package/index.js +165 -136
- package/index.js.map +21 -20
- package/lib/api.d.ts +50 -0
- package/lib/api.d.ts.map +1 -0
- package/lib/configuration/functions/check-bun.d.ts +2 -0
- package/lib/configuration/functions/check-bun.d.ts.map +1 -0
- package/lib/configuration/functions/get-default-logger.d.ts +4 -0
- package/lib/configuration/functions/get-default-logger.d.ts.map +1 -0
- package/lib/configuration/functions/is-root-dir.d.ts +2 -0
- package/lib/configuration/functions/is-root-dir.d.ts.map +1 -0
- package/lib/configuration/functions/load-config.d.ts +3 -0
- package/lib/configuration/functions/load-config.d.ts.map +1 -0
- package/lib/configuration/functions/parse-config.d.ts +28 -0
- package/lib/configuration/functions/parse-config.d.ts.map +1 -0
- package/lib/configuration/functions/search-config-path.d.ts +2 -0
- package/lib/configuration/functions/search-config-path.d.ts.map +1 -0
- package/lib/configuration/functions/validate-config-path.d.ts +6 -0
- package/lib/configuration/functions/validate-config-path.d.ts.map +1 -0
- package/lib/configuration/functions/z-loose-function.d.ts +3 -0
- package/lib/configuration/functions/z-loose-function.d.ts.map +1 -0
- package/lib/configuration/functions/z-loose-object-without-index-signature.d.ts +4 -0
- package/lib/configuration/functions/z-loose-object-without-index-signature.d.ts.map +1 -0
- package/lib/configuration/schemas/config.d.ts +127 -0
- package/lib/configuration/schemas/config.d.ts.map +1 -0
- package/lib/configuration/types/activated-config.d.ts +9 -0
- package/lib/configuration/types/activated-config.d.ts.map +1 -0
- package/lib/configuration/types/config-validation-result.d.ts +10 -0
- package/lib/configuration/types/config-validation-result.d.ts.map +1 -0
- package/lib/configuration/types/config.d.ts +26 -0
- package/lib/configuration/types/config.d.ts.map +1 -0
- package/lib/configuration/types/logger.d.ts +7 -0
- package/lib/configuration/types/logger.d.ts.map +1 -0
- package/lib/configuration/types/packages-ready-callback-props.d.ts +7 -0
- package/lib/configuration/types/packages-ready-callback-props.d.ts.map +1 -0
- package/lib/configuration/types/process-package-callback-props.d.ts +10 -0
- package/lib/configuration/types/process-package-callback-props.d.ts.map +1 -0
- package/lib/configuration/types/subprocess-callback.d.ts +2 -0
- package/lib/configuration/types/subprocess-callback.d.ts.map +1 -0
- package/lib/configuration/types/supported-config-type.d.ts +11 -0
- package/lib/configuration/types/supported-config-type.d.ts.map +1 -0
- package/lib/graph/functions/dfs-traverse-graph-paths.d.ts +3 -0
- package/lib/graph/functions/dfs-traverse-graph-paths.d.ts.map +1 -0
- package/lib/graph/functions/dfs-traverse-graph.d.ts +4 -0
- package/lib/graph/functions/dfs-traverse-graph.d.ts.map +1 -0
- package/lib/graph/functions/extract-subgraph.d.ts +3 -0
- package/lib/graph/functions/extract-subgraph.d.ts.map +1 -0
- package/lib/graph/functions/generate-graphs.d.ts +8 -0
- package/lib/graph/functions/generate-graphs.d.ts.map +1 -0
- package/lib/graph/functions/generate-package-circular-dependency-paths.d.ts +5 -0
- package/lib/graph/functions/generate-package-circular-dependency-paths.d.ts.map +1 -0
- package/lib/graph/functions/generate-topological-ranking-range.d.ts +3 -0
- package/lib/graph/functions/generate-topological-ranking-range.d.ts.map +1 -0
- package/lib/graph/functions/generate-topological-ranking.d.ts +2 -0
- package/lib/graph/functions/generate-topological-ranking.d.ts.map +1 -0
- package/lib/graph/functions/generate-topological-sorted-groups.d.ts +5 -0
- package/lib/graph/functions/generate-topological-sorted-groups.d.ts.map +1 -0
- package/lib/graph/functions/is-disjoint.d.ts +3 -0
- package/lib/graph/functions/is-disjoint.d.ts.map +1 -0
- package/lib/graph/functions/is-ranked-greater-than-or-equal.d.ts +3 -0
- package/lib/graph/functions/is-ranked-greater-than-or-equal.d.ts.map +1 -0
- package/lib/graph/functions/is-subgraph.d.ts +3 -0
- package/lib/graph/functions/is-subgraph.d.ts.map +1 -0
- package/lib/graph/functions/merge-graphs.d.ts +3 -0
- package/lib/graph/functions/merge-graphs.d.ts.map +1 -0
- package/lib/graph/types/package-graph.d.ts +3 -0
- package/lib/graph/types/package-graph.d.ts.map +1 -0
- package/lib/graph/types/package-graphs.d.ts +6 -0
- package/lib/graph/types/package-graphs.d.ts.map +1 -0
- package/lib/graph/types/package-node.d.ts +6 -0
- package/lib/graph/types/package-node.d.ts.map +1 -0
- package/lib/graph/types/package-order.d.ts +14 -0
- package/lib/graph/types/package-order.d.ts.map +1 -0
- package/lib/package/functions/load-packages.d.ts +4 -0
- package/lib/package/functions/load-packages.d.ts.map +1 -0
- package/lib/package/functions/parse-package.d.ts +3 -0
- package/lib/package/functions/parse-package.d.ts.map +1 -0
- package/lib/package/functions/run-for-each-package.d.ts +6 -0
- package/lib/package/functions/run-for-each-package.d.ts.map +1 -0
- package/lib/package/functions/scan-package-paths.d.ts +2 -0
- package/lib/package/functions/scan-package-paths.d.ts.map +1 -0
- package/lib/package/functions/scan-packages.d.ts +4 -0
- package/lib/package/functions/scan-packages.d.ts.map +1 -0
- package/lib/package/functions/update-package-version.d.ts +5 -0
- package/lib/package/functions/update-package-version.d.ts.map +1 -0
- package/lib/package/types/dependencies-field.d.ts +9 -0
- package/lib/package/types/dependencies-field.d.ts.map +1 -0
- package/lib/package/types/package-data.d.ts +12 -0
- package/lib/package/types/package-data.d.ts.map +1 -0
- package/lib/process/functions/get-commands-for-shell.d.ts +2 -0
- package/lib/process/functions/get-commands-for-shell.d.ts.map +1 -0
- package/lib/process/functions/get-line-buffered-writer.d.ts +2 -0
- package/lib/process/functions/get-line-buffered-writer.d.ts.map +1 -0
- package/lib/process/functions/parse-ps-flags.d.ts +5 -0
- package/lib/process/functions/parse-ps-flags.d.ts.map +1 -0
- package/lib/process/functions/read-stream.d.ts +2 -0
- package/lib/process/functions/read-stream.d.ts.map +1 -0
- package/lib/process/functions/run-subprocess.d.ts +11 -0
- package/lib/process/functions/run-subprocess.d.ts.map +1 -0
- package/lib/process/types/exit-state.d.ts +8 -0
- package/lib/process/types/exit-state.d.ts.map +1 -0
- package/lib/process/types/std-type.d.ts +7 -0
- package/lib/process/types/std-type.d.ts.map +1 -0
- package/lib/types/bump-package-version-options.d.ts +11 -0
- package/lib/types/bump-package-version-options.d.ts.map +1 -0
- package/lib/types/bump-version-type.d.ts +12 -0
- package/lib/types/bump-version-type.d.ts.map +1 -0
- package/lib/types/config-options.d.ts +5 -0
- package/lib/types/config-options.d.ts.map +1 -0
- package/lib/types/for-each-command-callback.d.ts +6 -0
- package/lib/types/for-each-command-callback.d.ts.map +1 -0
- package/lib/types/for-each-package-options.d.ts +11 -0
- package/lib/types/for-each-package-options.d.ts.map +1 -0
- package/lib/types/get-config-options.d.ts +5 -0
- package/lib/types/get-config-options.d.ts.map +1 -0
- package/lib/types/get-package-circular-dependency-paths-options.d.ts +6 -0
- package/lib/types/get-package-circular-dependency-paths-options.d.ts.map +1 -0
- package/lib/types/get-package-data-options.d.ts +6 -0
- package/lib/types/get-package-data-options.d.ts.map +1 -0
- package/lib/types/get-package-graph-options.d.ts +5 -0
- package/lib/types/get-package-graph-options.d.ts.map +1 -0
- package/lib/types/get-package-order-options.d.ts +5 -0
- package/lib/types/get-package-order-options.d.ts.map +1 -0
- package/lib/types/package-data-options.d.ts +5 -0
- package/lib/types/package-data-options.d.ts.map +1 -0
- package/lib/types/package-graphs-options.d.ts +5 -0
- package/lib/types/package-graphs-options.d.ts.map +1 -0
- package/lib/types/package-name-options.d.ts +4 -0
- package/lib/types/package-name-options.d.ts.map +1 -0
- package/lib/types/package-order-options.d.ts +5 -0
- package/lib/types/package-order-options.d.ts.map +1 -0
- package/lib/types/root-dir-options.d.ts +4 -0
- package/lib/types/root-dir-options.d.ts.map +1 -0
- package/lib/types/watch-packages-options.d.ts +7 -0
- package/lib/types/watch-packages-options.d.ts.map +1 -0
- package/lib/watch/functions/filter-files-modified-since.d.ts +2 -0
- package/lib/watch/functions/filter-files-modified-since.d.ts.map +1 -0
- package/lib/watch/functions/get-change-logic.d.ts +11 -0
- package/lib/watch/functions/get-change-logic.d.ts.map +1 -0
- package/lib/watch/functions/normalise-watched-file-path.d.ts +2 -0
- package/lib/watch/functions/normalise-watched-file-path.d.ts.map +1 -0
- package/lib/watch/functions/watch-package-changes.d.ts +8 -0
- package/lib/watch/functions/watch-package-changes.d.ts.map +1 -0
- package/lib/watch/types/change-action.d.ts +8 -0
- package/lib/watch/types/change-action.d.ts.map +1 -0
- package/lib/watch/types/package-changes.d.ts +2 -0
- package/lib/watch/types/package-changes.d.ts.map +1 -0
- 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
|
|
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 {
|
|
@@ -96,6 +93,7 @@ var Config = z3.object({
|
|
|
96
93
|
watch: z3.optional(zLooseObjectWithoutIndexSignature({
|
|
97
94
|
debounceMs: z3.optional(z3.number()),
|
|
98
95
|
hooks: z3.optional(z3.object({
|
|
96
|
+
onInit: z3.optional(zLooseFunction()),
|
|
99
97
|
onBeforeProcessPackage: z3.optional(zLooseFunction()),
|
|
100
98
|
onProcessPackage: z3.optional(zLooseFunction()),
|
|
101
99
|
onProcessPackageError: z3.optional(zLooseFunction()),
|
|
@@ -106,9 +104,9 @@ var Config = z3.object({
|
|
|
106
104
|
})),
|
|
107
105
|
subprocess: z3.optional(z3.object({
|
|
108
106
|
partialProcessing: z3.optional(z3.boolean()),
|
|
109
|
-
|
|
110
|
-
matchLongRunningOutputAsReady: z3.nullish(z3.string()),
|
|
111
|
-
matchLongRunningOutputAsErrored: z3.nullish(z3.string())
|
|
107
|
+
concurrency: z3.nullish(z3.number()),
|
|
108
|
+
matchLongRunningOutputAsReady: z3.nullish(z3.union([z3.string(), z3.array(z3.string())])),
|
|
109
|
+
matchLongRunningOutputAsErrored: z3.nullish(z3.union([z3.string(), z3.array(z3.string())]))
|
|
112
110
|
}))
|
|
113
111
|
})),
|
|
114
112
|
logLevel: z3.optional(LogLevel)
|
|
@@ -229,6 +227,7 @@ var defaultConfig = {
|
|
|
229
227
|
watch: {
|
|
230
228
|
debounceMs: 500,
|
|
231
229
|
hooks: {
|
|
230
|
+
onInit: noOp2,
|
|
232
231
|
onBeforeProcessPackage: noOp2,
|
|
233
232
|
onProcessPackage: noOp2,
|
|
234
233
|
onProcessPackageError: noOp2,
|
|
@@ -239,7 +238,7 @@ var defaultConfig = {
|
|
|
239
238
|
},
|
|
240
239
|
subprocess: {
|
|
241
240
|
partialProcessing: false,
|
|
242
|
-
|
|
241
|
+
concurrency: null,
|
|
243
242
|
matchLongRunningOutputAsReady: null,
|
|
244
243
|
matchLongRunningOutputAsErrored: null
|
|
245
244
|
}
|
|
@@ -260,14 +259,14 @@ var loadConfig = async (overrideConfigPath) => {
|
|
|
260
259
|
const parsedLogger = parsedConfig["logger"];
|
|
261
260
|
const logger = parsedLogger ?? (!parsedConfig.logLevel || parsedConfig.logLevel === defaultConfig.logLevel ? defaultConfig.logger : getDefaultLogger(parsedConfig.logLevel));
|
|
262
261
|
logger.debug(`Successfully loaded config file '${path}'.`);
|
|
263
|
-
logger.debug(dim(bgGray
|
|
264
|
-
${dim
|
|
265
|
-
logger.debug(dim(bgGray
|
|
266
|
-
${dim
|
|
262
|
+
logger.debug(styleText("dim", styleText("bgGray", "User config:")), `
|
|
263
|
+
${styleText("dim", formatSimpleLogObject(parsedConfig))}`);
|
|
264
|
+
logger.debug(styleText("dim", styleText("bgGray", "Default config:")), `
|
|
265
|
+
${styleText("dim", formatSimpleLogObject(defaultConfig))}`);
|
|
267
266
|
const activatedConfig = deepMergeDefined(defaultConfig, parsedConfig);
|
|
268
267
|
activatedConfig.logger = logger;
|
|
269
|
-
logger.debug(dim(bgGray
|
|
270
|
-
${dim
|
|
268
|
+
logger.debug(styleText("dim", styleText("bgGray", "Activated config:")), `
|
|
269
|
+
${styleText("dim", formatSimpleLogObject(activatedConfig))}`);
|
|
271
270
|
return {
|
|
272
271
|
config: activatedConfig,
|
|
273
272
|
rootDir: dirname3(path)
|
|
@@ -275,14 +274,24 @@ ${dim(formatSimpleLogObject(activatedConfig))}`);
|
|
|
275
274
|
};
|
|
276
275
|
|
|
277
276
|
// packages/core/src/lib/graph/functions/generate-graphs.ts
|
|
277
|
+
import { styleText as styleText2 } from "util";
|
|
278
278
|
import { assertDefined as assertDefined2 } from "@package-pal/util";
|
|
279
|
-
|
|
279
|
+
|
|
280
|
+
// packages/core/src/lib/package/types/dependencies-field.ts
|
|
281
|
+
var DependenciesField = {
|
|
282
|
+
Dependencies: "dependencies",
|
|
283
|
+
DevDependencies: "devDependencies",
|
|
284
|
+
PeerDependencies: "peerDependencies",
|
|
285
|
+
OptionalDependencies: "optionalDependencies"
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// packages/core/src/lib/graph/functions/generate-graphs.ts
|
|
280
289
|
var trackPackageEntryDependencies = ({
|
|
281
290
|
trackedDependencies,
|
|
282
291
|
packageNames,
|
|
283
292
|
packageData
|
|
284
293
|
}) => {
|
|
285
|
-
const iterateEntries =
|
|
294
|
+
const iterateEntries = Object.values(DependenciesField).map((field) => packageData[field]);
|
|
286
295
|
for (const packageEntries of iterateEntries) {
|
|
287
296
|
if (!packageEntries) {
|
|
288
297
|
continue;
|
|
@@ -310,7 +319,7 @@ var generateReverseGraph = (packages, packageGraph) => {
|
|
|
310
319
|
return reversePackageGraph;
|
|
311
320
|
};
|
|
312
321
|
var generateGraphs = (packages, logger) => {
|
|
313
|
-
logger.debug(
|
|
322
|
+
logger.debug(styleText2("dim", `Generating package graphs for ${packages.length.toString()} packages...`));
|
|
314
323
|
const packageNames = new Set(packages.map((packageData) => packageData.name));
|
|
315
324
|
const packageGraph = new Map;
|
|
316
325
|
for (const packageData of packages) {
|
|
@@ -333,11 +342,8 @@ var generateGraphs = (packages, logger) => {
|
|
|
333
342
|
};
|
|
334
343
|
|
|
335
344
|
// packages/core/src/lib/graph/functions/generate-package-circular-dependency-paths.ts
|
|
345
|
+
import { styleText as styleText3 } from "util";
|
|
336
346
|
import { assertDefined as assertDefined6 } from "@package-pal/util";
|
|
337
|
-
import {
|
|
338
|
-
dim as dim3,
|
|
339
|
-
yellow
|
|
340
|
-
} from "yoctocolors";
|
|
341
347
|
|
|
342
348
|
// packages/core/src/lib/graph/functions/dfs-traverse-graph-paths.ts
|
|
343
349
|
import { assertDefined as assertDefined3 } from "@package-pal/util";
|
|
@@ -488,7 +494,7 @@ var findSampleCyclePath = (scc, graph) => {
|
|
|
488
494
|
}));
|
|
489
495
|
};
|
|
490
496
|
var generatePackageCircularDependencyPaths = ({ dependents }, packageSorted, logger) => {
|
|
491
|
-
logger.debug(
|
|
497
|
+
logger.debug(styleText3("dim", "Generating circular dependency paths..."));
|
|
492
498
|
const subgraph = extractSubgraph(dependents, packageSorted.circular);
|
|
493
499
|
const scss = findStronglyConnectedComponents(subgraph);
|
|
494
500
|
const sampleCycles = scss.map((scc) => findSampleCyclePath(scc, subgraph).reverse());
|
|
@@ -497,20 +503,17 @@ var generatePackageCircularDependencyPaths = ({ dependents }, packageSorted, log
|
|
|
497
503
|
return ` ${(index + 1).toString()}. ` + cycle.map((name) => `'${name}'`).join(" \u2192 ");
|
|
498
504
|
}).join(`
|
|
499
505
|
`);
|
|
500
|
-
logger.warn(yellow
|
|
506
|
+
logger.warn(styleText3("yellow", `${sampleCycles.length.toString()} cyclic paths found:
|
|
501
507
|
${sampleCycleContents}`));
|
|
502
508
|
} else {
|
|
503
|
-
logger.debug(
|
|
509
|
+
logger.debug(styleText3("dim", `No cyclic paths found.`));
|
|
504
510
|
}
|
|
505
511
|
return sampleCycles;
|
|
506
512
|
};
|
|
507
513
|
|
|
508
514
|
// packages/core/src/lib/graph/functions/generate-topological-sorted-groups.ts
|
|
515
|
+
import { styleText as styleText4 } from "util";
|
|
509
516
|
import { assertDefined as assertDefined7 } from "@package-pal/util";
|
|
510
|
-
import {
|
|
511
|
-
dim as dim4,
|
|
512
|
-
yellow as yellow2
|
|
513
|
-
} from "yoctocolors";
|
|
514
517
|
var getCircularDependencies = (inDegree) => {
|
|
515
518
|
return Array.from(inDegree.keys()).sort((a, b) => {
|
|
516
519
|
const degA = assertDefined7(inDegree.get(a));
|
|
@@ -519,7 +522,7 @@ var getCircularDependencies = (inDegree) => {
|
|
|
519
522
|
}).sort();
|
|
520
523
|
};
|
|
521
524
|
var generateTopologicalSortedGroups = (packageGraph, logger) => {
|
|
522
|
-
logger.debug(
|
|
525
|
+
logger.debug(styleText4("dim", "Generating topological sorted groups..."));
|
|
523
526
|
const graphEntries = Array.from(packageGraph.entries());
|
|
524
527
|
const inDegree = new Map(graphEntries.map(([packageName]) => [packageName, 0]));
|
|
525
528
|
const graph = new Map(graphEntries.map(([packageName]) => [packageName, new Set]));
|
|
@@ -554,10 +557,10 @@ var generateTopologicalSortedGroups = (packageGraph, logger) => {
|
|
|
554
557
|
}
|
|
555
558
|
ready = nextReady;
|
|
556
559
|
}
|
|
557
|
-
logger.debug(
|
|
560
|
+
logger.debug(styleText4("dim", `Sorted packages into ${result.length.toString()} sequential groups of parallelizable dependencies.`));
|
|
558
561
|
const circular = getCircularDependencies(inDegree);
|
|
559
562
|
if (circular.length) {
|
|
560
|
-
logger.warn(
|
|
563
|
+
logger.warn(styleText4("yellow", `${circular.length.toString()} packages could not be sorted due to circular dependencies. Correct ordering cannot be guaranteed.`));
|
|
561
564
|
}
|
|
562
565
|
return {
|
|
563
566
|
groups: result.map((group) => group.sort()),
|
|
@@ -566,18 +569,15 @@ var generateTopologicalSortedGroups = (packageGraph, logger) => {
|
|
|
566
569
|
};
|
|
567
570
|
|
|
568
571
|
// packages/core/src/lib/package/functions/load-packages.ts
|
|
569
|
-
import {
|
|
572
|
+
import { styleText as styleText6 } from "util";
|
|
570
573
|
|
|
571
574
|
// packages/core/src/lib/package/functions/scan-packages.ts
|
|
575
|
+
import { styleText as styleText5 } from "util";
|
|
572
576
|
import {
|
|
573
577
|
dirname as dirname5,
|
|
574
578
|
join as join2
|
|
575
579
|
} from "path";
|
|
576
580
|
import { formatUnknownError } from "@package-pal/util";
|
|
577
|
-
import {
|
|
578
|
-
dim as dim5,
|
|
579
|
-
red
|
|
580
|
-
} from "yoctocolors";
|
|
581
581
|
|
|
582
582
|
// packages/core/src/lib/package/functions/parse-package.ts
|
|
583
583
|
import {
|
|
@@ -596,8 +596,11 @@ var parsePackage = (path, text) => {
|
|
|
596
596
|
peerDependencies,
|
|
597
597
|
devDependencies
|
|
598
598
|
} = props;
|
|
599
|
-
|
|
600
|
-
|
|
599
|
+
for (const field of Object.values(DependenciesField)) {
|
|
600
|
+
const value = props[field];
|
|
601
|
+
if (isDefined2(value) && typeof value !== "object") {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
601
604
|
}
|
|
602
605
|
return {
|
|
603
606
|
rawContent: text,
|
|
@@ -614,11 +617,15 @@ var parsePackage = (path, text) => {
|
|
|
614
617
|
// packages/core/src/lib/package/functions/scan-package-paths.ts
|
|
615
618
|
import { scanGlobPatternPaths } from "@package-pal/util";
|
|
616
619
|
var scanPackagePaths = (packages, cwd2) => {
|
|
617
|
-
|
|
620
|
+
const baseOpts = {
|
|
618
621
|
absolute: true,
|
|
619
|
-
onlyFiles: false
|
|
620
|
-
|
|
621
|
-
|
|
622
|
+
onlyFiles: false
|
|
623
|
+
};
|
|
624
|
+
const opts = {
|
|
625
|
+
...baseOpts,
|
|
626
|
+
...cwd2 ? { cwd: cwd2 } : {}
|
|
627
|
+
};
|
|
628
|
+
return scanGlobPatternPaths(packages, opts);
|
|
622
629
|
};
|
|
623
630
|
|
|
624
631
|
// packages/core/src/lib/package/functions/scan-packages.ts
|
|
@@ -627,22 +634,22 @@ var scanPackages = async function* (patterns, logger, cwd2) {
|
|
|
627
634
|
const packagePath = join2(path, "package.json");
|
|
628
635
|
const dir = dirname5(packagePath);
|
|
629
636
|
try {
|
|
630
|
-
logger.debug(
|
|
637
|
+
logger.debug(styleText5("dim", `Trying to read read package.json in '${dir}'.`));
|
|
631
638
|
const file = Bun.file(packagePath);
|
|
632
639
|
if (!file.size) {
|
|
633
|
-
logger.debug(
|
|
640
|
+
logger.debug(styleText5("dim", `Failed to read package.json in '${dir}' - ${styleText5("red", "File not found")}.`));
|
|
634
641
|
continue;
|
|
635
642
|
}
|
|
636
643
|
const text = await file.text();
|
|
637
644
|
const packageData = parsePackage(packagePath, text);
|
|
638
645
|
if (!packageData) {
|
|
639
|
-
logger.debug(
|
|
646
|
+
logger.debug(styleText5("dim", `Invalid package.json found in '${dir}'.`));
|
|
640
647
|
continue;
|
|
641
648
|
}
|
|
642
|
-
logger.debug(
|
|
649
|
+
logger.debug(styleText5("dim", `Successfully read package.json in '${dir}'.`));
|
|
643
650
|
yield packageData;
|
|
644
651
|
} catch (e) {
|
|
645
|
-
logger.debug(
|
|
652
|
+
logger.debug(styleText5("dim", `Failed to read package.json in '${dir}' - ${styleText5("red", formatUnknownError(e))}.`));
|
|
646
653
|
}
|
|
647
654
|
}
|
|
648
655
|
};
|
|
@@ -650,7 +657,7 @@ var scanPackages = async function* (patterns, logger, cwd2) {
|
|
|
650
657
|
// packages/core/src/lib/package/functions/load-packages.ts
|
|
651
658
|
var loadPackages = async (rootDir, packagePatterns, logger) => {
|
|
652
659
|
const patternContent = packagePatterns.map((pattern) => `'${pattern}'`).join(", ");
|
|
653
|
-
logger.debug(
|
|
660
|
+
logger.debug(styleText6("dim", `Loading packages matching pattern/s ${patternContent}...${rootDir ? ` from ${rootDir}` : ""}`));
|
|
654
661
|
const packages = [];
|
|
655
662
|
const seen = new Set;
|
|
656
663
|
for await (const packageData of scanPackages(Array.from(new Set(packagePatterns)), logger, rootDir)) {
|
|
@@ -670,15 +677,11 @@ var loadPackages = async (rootDir, packagePatterns, logger) => {
|
|
|
670
677
|
import { dirname as dirname6 } from "path";
|
|
671
678
|
import {
|
|
672
679
|
assertDefined as assertDefined9,
|
|
673
|
-
runAsync
|
|
674
|
-
RunAsyncType
|
|
680
|
+
runAsync
|
|
675
681
|
} from "@package-pal/util";
|
|
676
682
|
|
|
677
683
|
// packages/core/src/lib/process/functions/run-subprocess.ts
|
|
678
|
-
import {
|
|
679
|
-
dim as dim7,
|
|
680
|
-
red as red2
|
|
681
|
-
} from "yoctocolors";
|
|
684
|
+
import { styleText as styleText7 } from "util";
|
|
682
685
|
|
|
683
686
|
// packages/core/src/lib/process/types/exit-state.ts
|
|
684
687
|
var ExitState = {
|
|
@@ -822,9 +825,6 @@ var getLineBufferedWriter = (prefix, style = identity, write = process.stdout.wr
|
|
|
822
825
|
|
|
823
826
|
// packages/core/src/lib/process/functions/read-stream.ts
|
|
824
827
|
var readStream = async (stream, use) => {
|
|
825
|
-
if (!stream) {
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
828
|
const decoder = new TextDecoder;
|
|
829
829
|
const reader = stream.getReader();
|
|
830
830
|
let result = await reader.read();
|
|
@@ -849,27 +849,31 @@ var cancelCodes = new Set([
|
|
|
849
849
|
]);
|
|
850
850
|
var runSubprocess = async (opts) => {
|
|
851
851
|
if (opts.signal?.aborted) {
|
|
852
|
-
opts.logger.debug(
|
|
852
|
+
opts.logger.debug(styleText7("dim", `Skipped '${opts.debugName}' subprocess command; signal already cancelled.`));
|
|
853
853
|
return ExitState.Cancelled;
|
|
854
854
|
}
|
|
855
855
|
const commands = getCommandsForShell(opts.shellCommand);
|
|
856
|
-
const
|
|
857
|
-
cwd: opts.cwd,
|
|
856
|
+
const baseSubprocessOpts = {
|
|
858
857
|
stdout: "pipe",
|
|
859
858
|
stderr: "pipe",
|
|
860
|
-
stdin: "ignore"
|
|
861
|
-
|
|
862
|
-
|
|
859
|
+
stdin: "ignore"
|
|
860
|
+
};
|
|
861
|
+
const subprocessOpts = {
|
|
862
|
+
...baseSubprocessOpts,
|
|
863
|
+
...opts.cwd ? { cwd: opts.cwd } : {},
|
|
864
|
+
...opts.signal ? { signal: opts.signal } : {}
|
|
865
|
+
};
|
|
866
|
+
const subprocess = Bun.spawn(commands, subprocessOpts);
|
|
863
867
|
const pid = subprocess.pid.toString();
|
|
864
868
|
const minPrefixLen = 14;
|
|
865
869
|
const [readStdout, readStderr] = [{
|
|
866
870
|
source: subprocess.stdout,
|
|
867
871
|
type: StdType.Out,
|
|
868
|
-
write: getLineBufferedWriter(
|
|
872
|
+
write: getLineBufferedWriter(styleText7("dim", `[O-${pid}]`.padEnd(minPrefixLen, " ")))
|
|
869
873
|
}, {
|
|
870
874
|
source: subprocess.stderr,
|
|
871
875
|
type: StdType.Err,
|
|
872
|
-
write: getLineBufferedWriter(
|
|
876
|
+
write: getLineBufferedWriter(styleText7("yellow", styleText7("dim", `[E-${pid}]`.padEnd(minPrefixLen, " "))))
|
|
873
877
|
}].map(({
|
|
874
878
|
source,
|
|
875
879
|
type,
|
|
@@ -883,7 +887,7 @@ var runSubprocess = async (opts) => {
|
|
|
883
887
|
});
|
|
884
888
|
});
|
|
885
889
|
const executedCommand = commands.join(" ");
|
|
886
|
-
opts.logger.debug(
|
|
890
|
+
opts.logger.debug(styleText7("dim", `Started '${opts.debugName}' subprocess command '${opts.shellCommand}' (${executedCommand}) with PID ${pid}.`));
|
|
887
891
|
const [
|
|
888
892
|
,
|
|
889
893
|
,
|
|
@@ -893,14 +897,14 @@ var runSubprocess = async (opts) => {
|
|
|
893
897
|
readStderr,
|
|
894
898
|
subprocess.exited.then((exitCode) => {
|
|
895
899
|
if (cancelCodes.has(exitCode)) {
|
|
896
|
-
opts.logger.debug(
|
|
900
|
+
opts.logger.debug(styleText7("dim", `Cancelled '${opts.debugName}' subprocess command; PID ${pid} exited.`));
|
|
897
901
|
return ExitState.Cancelled;
|
|
898
902
|
}
|
|
899
903
|
if (exitCode !== 0) {
|
|
900
|
-
opts.logger.error(
|
|
904
|
+
opts.logger.error(styleText7("red", `'${opts.debugName}' command '${opts.shellCommand}' (${executedCommand}) with PID ${pid} failed with exit code ${exitCode.toString()}.`));
|
|
901
905
|
return ExitState.Errored;
|
|
902
906
|
}
|
|
903
|
-
opts.logger.debug(
|
|
907
|
+
opts.logger.debug(styleText7("dim", `Completed '${opts.debugName}' subprocess command; PID ${pid} exited.`));
|
|
904
908
|
return ExitState.Completed;
|
|
905
909
|
})
|
|
906
910
|
]);
|
|
@@ -908,14 +912,14 @@ var runSubprocess = async (opts) => {
|
|
|
908
912
|
};
|
|
909
913
|
|
|
910
914
|
// packages/core/src/lib/package/functions/run-for-each-package.ts
|
|
911
|
-
var runForEachPackage = async (packageGraphs, packageOrder, getCommand,
|
|
915
|
+
var runForEachPackage = async (packageGraphs, packageOrder, getCommand, logger, topological = true, concurrency) => {
|
|
912
916
|
const controller = new AbortController;
|
|
913
917
|
let processPackageOrder = packageOrder.groups.concat(packageOrder.circular);
|
|
914
918
|
if (!topological) {
|
|
915
919
|
processPackageOrder = [processPackageOrder.flat()];
|
|
916
920
|
}
|
|
917
921
|
for (const group of processPackageOrder) {
|
|
918
|
-
await runAsync(
|
|
922
|
+
await runAsync(group.map((packageName) => async () => {
|
|
919
923
|
const packageNode = assertDefined9(packageGraphs.dependencies.get(packageName));
|
|
920
924
|
const processPackageProps = {
|
|
921
925
|
name: packageName,
|
|
@@ -937,14 +941,14 @@ var runForEachPackage = async (packageGraphs, packageOrder, getCommand, parallel
|
|
|
937
941
|
controller.abort();
|
|
938
942
|
throw new Error("Command failed.");
|
|
939
943
|
}
|
|
940
|
-
}));
|
|
944
|
+
}), concurrency);
|
|
941
945
|
}
|
|
942
946
|
};
|
|
943
947
|
|
|
944
948
|
// packages/core/src/lib/package/functions/update-package-version.ts
|
|
949
|
+
import { styleText as styleText8 } from "util";
|
|
945
950
|
var {semver } = globalThis.Bun;
|
|
946
951
|
import { inc } from "semver";
|
|
947
|
-
import { dim as dim8 } from "yoctocolors";
|
|
948
952
|
var findAndReplaceVersion = ({
|
|
949
953
|
raw,
|
|
950
954
|
field,
|
|
@@ -1004,7 +1008,7 @@ var findAndReplaceVersion = ({
|
|
|
1004
1008
|
return `${before}${updatedVersion}${after}`;
|
|
1005
1009
|
};
|
|
1006
1010
|
var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact, logger) => {
|
|
1007
|
-
logger.debug(
|
|
1011
|
+
logger.debug(styleText8("dim", `Bumping package '${packageName}'...`));
|
|
1008
1012
|
const packageNode = packageGraphs.dependencies.get(packageName);
|
|
1009
1013
|
if (!packageNode) {
|
|
1010
1014
|
throw new Error(`Package '${packageName}' not found.`);
|
|
@@ -1028,15 +1032,14 @@ var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact
|
|
|
1028
1032
|
});
|
|
1029
1033
|
const baseWrite = Bun.write(packageNode.packageData.path, updatedContent);
|
|
1030
1034
|
const dependentWrites = Array.from(dfsTraverseGraph(packageGraphs.dependents, packageName).flatMap((dependent) => {
|
|
1031
|
-
|
|
1032
|
-
return fields.flatMap((field) => {
|
|
1035
|
+
return Object.values(DependenciesField).flatMap((field) => {
|
|
1033
1036
|
const entry = dependent[field];
|
|
1034
1037
|
const depVersion = entry?.[packageName];
|
|
1035
1038
|
if (!depVersion) {
|
|
1036
1039
|
return [];
|
|
1037
1040
|
}
|
|
1038
1041
|
if (exact ? depVersion === bumpedVersion : semver.satisfies(bumpedVersion, depVersion)) {
|
|
1039
|
-
logger.debug(
|
|
1042
|
+
logger.debug(styleText8("dim", `Skipping '${dependent.name}': ${field} version '${depVersion}' already satisfies '${bumpedVersion}'.`));
|
|
1040
1043
|
return [];
|
|
1041
1044
|
}
|
|
1042
1045
|
const updatedContent2 = findAndReplaceVersion({
|
|
@@ -1060,6 +1063,7 @@ var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact
|
|
|
1060
1063
|
import {
|
|
1061
1064
|
watch
|
|
1062
1065
|
} from "fs";
|
|
1066
|
+
import { styleText as styleText10 } from "util";
|
|
1063
1067
|
import {
|
|
1064
1068
|
dirname as dirname8,
|
|
1065
1069
|
join as join4
|
|
@@ -1071,13 +1075,8 @@ import {
|
|
|
1071
1075
|
getDeferredPromise,
|
|
1072
1076
|
getStringMatcher,
|
|
1073
1077
|
isDefined as isDefined4,
|
|
1074
|
-
RunAsyncType as RunAsyncType2,
|
|
1075
1078
|
runAsync as runAsync2
|
|
1076
1079
|
} from "@package-pal/util";
|
|
1077
|
-
import {
|
|
1078
|
-
dim as dim10,
|
|
1079
|
-
red as red3
|
|
1080
|
-
} from "yoctocolors";
|
|
1081
1080
|
|
|
1082
1081
|
// packages/core/src/lib/graph/functions/merge-graphs.ts
|
|
1083
1082
|
var mergeGraphs = (a, b) => {
|
|
@@ -1113,8 +1112,8 @@ var filterFilesModifiedSince = (paths, sinceMs) => {
|
|
|
1113
1112
|
};
|
|
1114
1113
|
|
|
1115
1114
|
// packages/core/src/lib/watch/functions/get-change-logic.ts
|
|
1115
|
+
import { styleText as styleText9 } from "util";
|
|
1116
1116
|
import { assertDefined as assertDefined11 } from "@package-pal/util";
|
|
1117
|
-
import { dim as dim9 } from "yoctocolors";
|
|
1118
1117
|
|
|
1119
1118
|
// packages/core/src/lib/graph/functions/generate-topological-ranking-range.ts
|
|
1120
1119
|
import { isDefined as isDefined3 } from "@package-pal/util";
|
|
@@ -1214,8 +1213,8 @@ var getChangeLogic = (packageGraphs, packageChanges, lastProcessedSubgraph, conf
|
|
|
1214
1213
|
const changedPackages = Array.from(packageChanges.keys());
|
|
1215
1214
|
const changedFilePaths = Array.from(packageChanges.values()).flat();
|
|
1216
1215
|
if (packageChanges.size) {
|
|
1217
|
-
logger.debug(
|
|
1218
|
-
logger.debug(
|
|
1216
|
+
logger.debug(styleText9("dim", `Changes detected in ${changedPackages.map((packageName) => `'${packageName}'`).join(", ")}.`));
|
|
1217
|
+
logger.debug(styleText9("dim", `Changed file paths: ${changedFilePaths.map((filePath) => `'${filePath}'`).join(", ")}.`));
|
|
1219
1218
|
}
|
|
1220
1219
|
const packageOrder = generateTopologicalSortedGroups(packageGraphs.dependents, logger);
|
|
1221
1220
|
const packageProcessOrder = packageOrder.groups.toReversed().concat(packageOrder.circular);
|
|
@@ -1226,9 +1225,9 @@ var getChangeLogic = (packageGraphs, packageChanges, lastProcessedSubgraph, conf
|
|
|
1226
1225
|
const isSubgraphOfPrevious = !!lastProcessedSubgraph && isSubgraph(lastProcessedSubgraph, changedPackageSubgraph);
|
|
1227
1226
|
const isDisjointFromPrevious = !lastProcessedSubgraph || !isSubgraphOfPrevious && isDisjoint(lastProcessedSubgraph, changedPackageSubgraph);
|
|
1228
1227
|
const isRankedGreaterThanOrEqualToPrevious = !!lastProcessedSubgraph && !isSubgraphOfPrevious && isRankedGreaterThanOrEqual(lastProcessedSubgraph, changedPackageSubgraph, packageRankings);
|
|
1229
|
-
logger.debug(
|
|
1230
|
-
logger.debug(
|
|
1231
|
-
logger.debug(
|
|
1228
|
+
logger.debug(styleText9("dim", `Changes are subgraph of previous: ${isSubgraphOfPrevious.toString()}.`));
|
|
1229
|
+
logger.debug(styleText9("dim", `Changes are disjoint from previous: ${isDisjointFromPrevious.toString()}.`));
|
|
1230
|
+
logger.debug(styleText9("dim", `Changes are ranked greater than or equal to previous: ${isRankedGreaterThanOrEqualToPrevious.toString()}.`));
|
|
1232
1231
|
let action = ChangeAction.Restart;
|
|
1233
1232
|
if (!packageChanges.size) {
|
|
1234
1233
|
action = ChangeAction.Ignore;
|
|
@@ -1248,7 +1247,7 @@ var getChangeLogic = (packageGraphs, packageChanges, lastProcessedSubgraph, conf
|
|
|
1248
1247
|
});
|
|
1249
1248
|
}
|
|
1250
1249
|
}
|
|
1251
|
-
logger.debug(
|
|
1250
|
+
logger.debug(styleText9("dim", `Determined change action: ${action}.`));
|
|
1252
1251
|
return {
|
|
1253
1252
|
changedPackageProcessOrder,
|
|
1254
1253
|
changedPackageSubgraph,
|
|
@@ -1295,8 +1294,9 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1295
1294
|
changedPackageSubgraph
|
|
1296
1295
|
} = getChangeLogic(packageGraphs, packageChanges, lastProcessedSubgraph, watchConfig, logger);
|
|
1297
1296
|
const controller = determineAbortController(action === ChangeAction.Restart);
|
|
1297
|
+
const isSequential = watchConfig.subprocess.concurrency === 1;
|
|
1298
1298
|
const onProcessFailure = () => {
|
|
1299
|
-
logger.debug(
|
|
1299
|
+
logger.debug(styleText10("dim", "Aborting controller: process failed."));
|
|
1300
1300
|
controller.abort();
|
|
1301
1301
|
lastProcessedSubgraph = undefined;
|
|
1302
1302
|
};
|
|
@@ -1305,7 +1305,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1305
1305
|
return;
|
|
1306
1306
|
}
|
|
1307
1307
|
if (packageChanges.size) {
|
|
1308
|
-
logger.info(
|
|
1308
|
+
logger.info(`${action === ChangeAction.Restart ? "Restarting processing" : "Initiating partial processing"} ${isSequential ? "sequentially" : `in parallel${isDefined4(watchConfig.subprocess.concurrency) ? ` with concurrency ${watchConfig.subprocess.concurrency.toString()}` : ""}`}.`);
|
|
1309
1309
|
lastProcessedSubgraph = lastProcessedSubgraph ? mergeGraphs(lastProcessedSubgraph, changedPackageSubgraph) : changedPackageSubgraph;
|
|
1310
1310
|
}
|
|
1311
1311
|
for (const group of changedPackageProcessOrder) {
|
|
@@ -1314,7 +1314,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1314
1314
|
resolve: matchedParallelLongReadyRunningOutput
|
|
1315
1315
|
} = getDeferredPromise();
|
|
1316
1316
|
let matchedLongRunningOutputCount = 0;
|
|
1317
|
-
await runAsync2(
|
|
1317
|
+
await runAsync2(group.map((packageName) => async () => {
|
|
1318
1318
|
const {
|
|
1319
1319
|
promise: longRunningSequentialProcessReady,
|
|
1320
1320
|
resolve: matchedSequentialLongRunningReadyOutput
|
|
@@ -1355,36 +1355,42 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1355
1355
|
signal: controller.signal,
|
|
1356
1356
|
logger,
|
|
1357
1357
|
onStdChunk: (chunk) => {
|
|
1358
|
-
if (!ready
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1358
|
+
if (!ready) {
|
|
1359
|
+
const matchedReadyText = readyMatcher?.push(chunk).matched();
|
|
1360
|
+
if (matchedReadyText) {
|
|
1361
|
+
ready = true;
|
|
1362
|
+
matchedLongRunningOutputCount++;
|
|
1363
|
+
logger.debug(`'${packageName}' (${matchedLongRunningOutputCount.toString()}/${group.length.toString()}) subprocess matched ready text '${matchedReadyText}'.`);
|
|
1364
|
+
if (isSequential && matchedLongRunningOutputCount) {
|
|
1365
|
+
matchedSequentialLongRunningReadyOutput();
|
|
1366
|
+
}
|
|
1364
1367
|
}
|
|
1365
1368
|
}
|
|
1366
|
-
if (!errored
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1369
|
+
if (!errored) {
|
|
1370
|
+
const matchedErrorText = erroredMatcher?.push(chunk).matched();
|
|
1371
|
+
if (matchedErrorText) {
|
|
1372
|
+
logger.error(styleText10("red", `'${packageName}' subprocess matched error text '${matchedErrorText}'.`));
|
|
1373
|
+
errored = true;
|
|
1374
|
+
Promise.resolve(watchConfig.hooks.onProcessPackageError(processPackageProps)).then((processPackageErrorCommand) => {
|
|
1375
|
+
if (!processPackageErrorCommand) {
|
|
1376
|
+
onProcessFailure();
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
return runSubprocess({
|
|
1380
|
+
debugName: `after process ${packageName}`,
|
|
1381
|
+
shellCommand: processPackageErrorCommand,
|
|
1382
|
+
cwd: processPackageCwd,
|
|
1383
|
+
signal: controller.signal,
|
|
1384
|
+
logger
|
|
1385
|
+
});
|
|
1386
|
+
}).then((exitState) => {
|
|
1387
|
+
if (exitState === ExitState.Errored) {
|
|
1388
|
+
onProcessFailure();
|
|
1389
|
+
}
|
|
1380
1390
|
});
|
|
1381
|
-
}
|
|
1382
|
-
if (exitState === ExitState.Errored) {
|
|
1383
|
-
onProcessFailure();
|
|
1384
|
-
}
|
|
1385
|
-
});
|
|
1391
|
+
}
|
|
1386
1392
|
}
|
|
1387
|
-
if (
|
|
1393
|
+
if (!isSequential && matchedLongRunningOutputCount === group.length) {
|
|
1388
1394
|
matchedParallelLongReadyRunningOutput();
|
|
1389
1395
|
}
|
|
1390
1396
|
}
|
|
@@ -1409,7 +1415,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1409
1415
|
logger
|
|
1410
1416
|
});
|
|
1411
1417
|
}
|
|
1412
|
-
}));
|
|
1418
|
+
}), watchConfig.subprocess.concurrency);
|
|
1413
1419
|
}
|
|
1414
1420
|
if (packageChanges.size) {
|
|
1415
1421
|
logger.info(`Processing ${controller.signal.aborted ? "cancelled due to new changes" : "completed"}.`);
|
|
@@ -1446,9 +1452,9 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1446
1452
|
});
|
|
1447
1453
|
}
|
|
1448
1454
|
};
|
|
1449
|
-
var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
1455
|
+
var watchPackageChanges = (packageData, packageGraphs, watchConfig, rootDir, logger) => {
|
|
1450
1456
|
const dedupedRootPackageData = dedupeSharedPaths(packageData.map((packageData2) => packageData2.path), DedupePathsBy.Parent).map((packagePath) => assertDefined12(packageData.find((data) => data.path === packagePath)));
|
|
1451
|
-
logger.debug(
|
|
1457
|
+
logger.debug(styleText10("dim", `Starting ${dedupedRootPackageData.length.toString()} watchers for ${packageData.length.toString()} packages.`));
|
|
1452
1458
|
let closed = false;
|
|
1453
1459
|
let debounceTimeout;
|
|
1454
1460
|
let startedDebounceMs;
|
|
@@ -1457,7 +1463,7 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
|
1457
1463
|
const useController = (reset) => {
|
|
1458
1464
|
if (controller && (reset || controller.signal.aborted)) {
|
|
1459
1465
|
if (reset) {
|
|
1460
|
-
logger.debug(
|
|
1466
|
+
logger.debug(styleText10("dim", "Aborting controller: reset for new packages."));
|
|
1461
1467
|
controller.abort();
|
|
1462
1468
|
}
|
|
1463
1469
|
controller = undefined;
|
|
@@ -1465,7 +1471,12 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
|
1465
1471
|
controller ??= new AbortController;
|
|
1466
1472
|
return controller;
|
|
1467
1473
|
};
|
|
1468
|
-
const onWatchEvent = (
|
|
1474
|
+
const onWatchEvent = ({
|
|
1475
|
+
watchPath,
|
|
1476
|
+
packageName,
|
|
1477
|
+
filePath,
|
|
1478
|
+
isInitial = false
|
|
1479
|
+
}) => {
|
|
1469
1480
|
if (!isDefined4(startedDebounceMs)) {
|
|
1470
1481
|
startedDebounceMs = Date.now();
|
|
1471
1482
|
}
|
|
@@ -1481,24 +1492,26 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
|
1481
1492
|
changedPackagePaths.set(packageName, new Set([changedPath]));
|
|
1482
1493
|
}
|
|
1483
1494
|
}
|
|
1495
|
+
const debounceMs = isInitial ? 0 : watchConfig.debounceMs;
|
|
1484
1496
|
debounceTimeout = setTimeout(() => {
|
|
1485
1497
|
if (closed) {
|
|
1486
1498
|
return;
|
|
1487
1499
|
}
|
|
1488
1500
|
const packageChanges = new Map;
|
|
1489
1501
|
for (const [packageName2, paths] of changedPackagePaths) {
|
|
1490
|
-
const
|
|
1502
|
+
const dedupedPaths = dedupeSharedPaths(Array.from(paths), DedupePathsBy.Child).sort();
|
|
1503
|
+
const processedPaths = filterFilesModifiedSince(dedupedPaths, assertDefined12(startedDebounceMs) - fileModifiedThresholdMs);
|
|
1491
1504
|
if (processedPaths.length) {
|
|
1492
1505
|
packageChanges.set(packageName2, processedPaths);
|
|
1493
1506
|
}
|
|
1494
1507
|
}
|
|
1495
1508
|
startedDebounceMs = undefined;
|
|
1496
1509
|
changedPackagePaths.clear();
|
|
1497
|
-
if (!packageChanges.size && !
|
|
1510
|
+
if (!packageChanges.size && !isInitial) {
|
|
1498
1511
|
return;
|
|
1499
1512
|
}
|
|
1500
1513
|
onProcessPackage(packageGraphs, packageChanges, watchConfig, (reset) => useController(reset), logger);
|
|
1501
|
-
},
|
|
1514
|
+
}, debounceMs);
|
|
1502
1515
|
};
|
|
1503
1516
|
const watchers = dedupedRootPackageData.map(({
|
|
1504
1517
|
name,
|
|
@@ -1506,29 +1519,45 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
|
1506
1519
|
}) => {
|
|
1507
1520
|
const watchPath = dirname8(path);
|
|
1508
1521
|
return watch(watchPath, { recursive: true }, (event, filePath) => {
|
|
1509
|
-
onWatchEvent(
|
|
1522
|
+
onWatchEvent({
|
|
1523
|
+
watchPath,
|
|
1524
|
+
packageName: name,
|
|
1525
|
+
event,
|
|
1526
|
+
filePath: filePath ?? undefined
|
|
1527
|
+
});
|
|
1510
1528
|
});
|
|
1511
1529
|
});
|
|
1512
1530
|
const closeWatchers = () => {
|
|
1513
1531
|
watchers.forEach((watcher) => {
|
|
1514
1532
|
watcher.close();
|
|
1515
1533
|
});
|
|
1516
|
-
logger.debug(
|
|
1534
|
+
logger.debug(styleText10("dim", "Aborting controller: closing watchers."));
|
|
1517
1535
|
controller?.abort();
|
|
1518
1536
|
closed = true;
|
|
1519
1537
|
};
|
|
1520
1538
|
process.on("SIGINT", () => {
|
|
1521
|
-
logger.debug(
|
|
1539
|
+
logger.debug(styleText10("dim", "Received SIGINT: closing watchers."));
|
|
1522
1540
|
closeWatchers();
|
|
1523
1541
|
process.exit(0);
|
|
1524
1542
|
});
|
|
1525
|
-
|
|
1543
|
+
Promise.resolve(watchConfig.hooks.onInit()).then(async (onInitShellCommand) => {
|
|
1544
|
+
if (onInitShellCommand) {
|
|
1545
|
+
await runSubprocess({
|
|
1546
|
+
debugName: `on init`,
|
|
1547
|
+
shellCommand: onInitShellCommand,
|
|
1548
|
+
signal: useController(false).signal,
|
|
1549
|
+
cwd: rootDir,
|
|
1550
|
+
logger
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1553
|
+
onWatchEvent({ isInitial: true });
|
|
1554
|
+
});
|
|
1526
1555
|
return { close: () => {
|
|
1527
1556
|
if (closed) {
|
|
1528
|
-
logger.debug(
|
|
1557
|
+
logger.debug(styleText10("dim", "Watchers already closed."));
|
|
1529
1558
|
return;
|
|
1530
1559
|
}
|
|
1531
|
-
logger.debug(
|
|
1560
|
+
logger.debug(styleText10("dim", "Closing watchers."));
|
|
1532
1561
|
closeWatchers();
|
|
1533
1562
|
} };
|
|
1534
1563
|
};
|
|
@@ -1563,11 +1592,11 @@ var bumpPackageVersion = (options) => {
|
|
|
1563
1592
|
};
|
|
1564
1593
|
var watchPackages = (options) => {
|
|
1565
1594
|
checkBun();
|
|
1566
|
-
watchPackageChanges(options.packageData, options.packageGraphs, options.config.watch, options.config.logger);
|
|
1595
|
+
watchPackageChanges(options.packageData, options.packageGraphs, options.config.watch, options.rootDir, options.config.logger);
|
|
1567
1596
|
};
|
|
1568
1597
|
var forEachPackage = (options) => {
|
|
1569
1598
|
checkBun();
|
|
1570
|
-
return runForEachPackage(options.packageGraphs, options.packageOrder, options.getCommand, options.
|
|
1599
|
+
return runForEachPackage(options.packageGraphs, options.packageOrder, options.getCommand, options.config.logger, options.topological, options.concurrency);
|
|
1571
1600
|
};
|
|
1572
1601
|
export {
|
|
1573
1602
|
watchPackages,
|
|
@@ -1581,5 +1610,5 @@ export {
|
|
|
1581
1610
|
BumpVersionType
|
|
1582
1611
|
};
|
|
1583
1612
|
|
|
1584
|
-
//# debugId=
|
|
1613
|
+
//# debugId=57C320DF799C435664756E2164756E21
|
|
1585
1614
|
//# sourceMappingURL=index.js.map
|