@package-pal/core 0.0.2 → 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.
- package/index.js +419 -264
- package/index.js.map +22 -20
- package/package.json +2 -2
- package/index.d.ts +0 -18
- package/index.d.ts.map +0 -1
- package/lib/api.d.ts +0 -45
- package/lib/api.d.ts.map +0 -1
- package/lib/configuration/functions/check-bun.d.ts +0 -2
- package/lib/configuration/functions/check-bun.d.ts.map +0 -1
- package/lib/configuration/functions/get-default-logger.d.ts +0 -4
- package/lib/configuration/functions/get-default-logger.d.ts.map +0 -1
- package/lib/configuration/functions/is-root-dir.d.ts +0 -2
- package/lib/configuration/functions/is-root-dir.d.ts.map +0 -1
- package/lib/configuration/functions/load-config.d.ts +0 -3
- package/lib/configuration/functions/load-config.d.ts.map +0 -1
- package/lib/configuration/functions/parse-config.d.ts +0 -27
- package/lib/configuration/functions/parse-config.d.ts.map +0 -1
- package/lib/configuration/functions/search-config-path.d.ts +0 -2
- package/lib/configuration/functions/search-config-path.d.ts.map +0 -1
- package/lib/configuration/functions/validate-config-path.d.ts +0 -6
- package/lib/configuration/functions/validate-config-path.d.ts.map +0 -1
- package/lib/configuration/functions/z-loose-function.d.ts +0 -3
- package/lib/configuration/functions/z-loose-function.d.ts.map +0 -1
- package/lib/configuration/functions/z-loose-object-without-index-signature.d.ts +0 -4
- package/lib/configuration/functions/z-loose-object-without-index-signature.d.ts.map +0 -1
- package/lib/configuration/schemas/config.d.ts +0 -121
- package/lib/configuration/schemas/config.d.ts.map +0 -1
- package/lib/configuration/types/activated-config.d.ts +0 -5
- package/lib/configuration/types/activated-config.d.ts.map +0 -1
- package/lib/configuration/types/config-validation-result.d.ts +0 -10
- package/lib/configuration/types/config-validation-result.d.ts.map +0 -1
- package/lib/configuration/types/config.d.ts +0 -25
- package/lib/configuration/types/config.d.ts.map +0 -1
- package/lib/configuration/types/logger.d.ts +0 -7
- package/lib/configuration/types/logger.d.ts.map +0 -1
- package/lib/configuration/types/packages-ready-callback-props.d.ts +0 -7
- package/lib/configuration/types/packages-ready-callback-props.d.ts.map +0 -1
- package/lib/configuration/types/process-package-callback-props.d.ts +0 -10
- package/lib/configuration/types/process-package-callback-props.d.ts.map +0 -1
- package/lib/configuration/types/subprocess-callback.d.ts +0 -2
- package/lib/configuration/types/subprocess-callback.d.ts.map +0 -1
- package/lib/configuration/types/supported-config-type.d.ts +0 -11
- package/lib/configuration/types/supported-config-type.d.ts.map +0 -1
- package/lib/graph/functions/dfs-traverse-graph-paths.d.ts +0 -3
- package/lib/graph/functions/dfs-traverse-graph-paths.d.ts.map +0 -1
- package/lib/graph/functions/dfs-traverse-graph.d.ts +0 -4
- package/lib/graph/functions/dfs-traverse-graph.d.ts.map +0 -1
- package/lib/graph/functions/extract-subgraph.d.ts +0 -3
- package/lib/graph/functions/extract-subgraph.d.ts.map +0 -1
- package/lib/graph/functions/generate-graphs.d.ts +0 -8
- package/lib/graph/functions/generate-graphs.d.ts.map +0 -1
- package/lib/graph/functions/generate-package-circular-dependency-paths.d.ts +0 -5
- package/lib/graph/functions/generate-package-circular-dependency-paths.d.ts.map +0 -1
- package/lib/graph/functions/generate-topological-ranking-range.d.ts +0 -3
- package/lib/graph/functions/generate-topological-ranking-range.d.ts.map +0 -1
- package/lib/graph/functions/generate-topological-ranking.d.ts +0 -2
- package/lib/graph/functions/generate-topological-ranking.d.ts.map +0 -1
- package/lib/graph/functions/generate-topological-sorted-groups.d.ts +0 -5
- package/lib/graph/functions/generate-topological-sorted-groups.d.ts.map +0 -1
- package/lib/graph/functions/is-disjoint.d.ts +0 -3
- package/lib/graph/functions/is-disjoint.d.ts.map +0 -1
- package/lib/graph/functions/is-ranked-greater-than-or-equal.d.ts +0 -3
- package/lib/graph/functions/is-ranked-greater-than-or-equal.d.ts.map +0 -1
- package/lib/graph/functions/is-subgraph.d.ts +0 -3
- package/lib/graph/functions/is-subgraph.d.ts.map +0 -1
- package/lib/graph/types/package-graph.d.ts +0 -3
- package/lib/graph/types/package-graph.d.ts.map +0 -1
- package/lib/graph/types/package-graphs.d.ts +0 -6
- package/lib/graph/types/package-graphs.d.ts.map +0 -1
- package/lib/graph/types/package-node.d.ts +0 -6
- package/lib/graph/types/package-node.d.ts.map +0 -1
- package/lib/graph/types/package-order.d.ts +0 -14
- package/lib/graph/types/package-order.d.ts.map +0 -1
- package/lib/package/functions/load-packages.d.ts +0 -4
- package/lib/package/functions/load-packages.d.ts.map +0 -1
- package/lib/package/functions/parse-package.d.ts +0 -3
- package/lib/package/functions/parse-package.d.ts.map +0 -1
- package/lib/package/functions/scan-package-paths.d.ts +0 -2
- package/lib/package/functions/scan-package-paths.d.ts.map +0 -1
- package/lib/package/functions/scan-packages.d.ts +0 -4
- package/lib/package/functions/scan-packages.d.ts.map +0 -1
- package/lib/package/functions/update-package-version.d.ts +0 -5
- package/lib/package/functions/update-package-version.d.ts.map +0 -1
- package/lib/package/types/package-data.d.ts +0 -11
- package/lib/package/types/package-data.d.ts.map +0 -1
- package/lib/types/bump-package-version-options.d.ts +0 -11
- package/lib/types/bump-package-version-options.d.ts.map +0 -1
- package/lib/types/bump-version-type.d.ts +0 -12
- package/lib/types/bump-version-type.d.ts.map +0 -1
- package/lib/types/config-options.d.ts +0 -5
- package/lib/types/config-options.d.ts.map +0 -1
- package/lib/types/get-config-options.d.ts +0 -5
- package/lib/types/get-config-options.d.ts.map +0 -1
- package/lib/types/get-package-circular-dependency-paths-options.d.ts +0 -6
- package/lib/types/get-package-circular-dependency-paths-options.d.ts.map +0 -1
- package/lib/types/get-package-data-options.d.ts +0 -4
- package/lib/types/get-package-data-options.d.ts.map +0 -1
- package/lib/types/get-package-graph-options.d.ts +0 -5
- package/lib/types/get-package-graph-options.d.ts.map +0 -1
- package/lib/types/get-package-order-options.d.ts +0 -5
- package/lib/types/get-package-order-options.d.ts.map +0 -1
- package/lib/types/package-data-options.d.ts +0 -5
- package/lib/types/package-data-options.d.ts.map +0 -1
- package/lib/types/package-graphs-options.d.ts +0 -5
- package/lib/types/package-graphs-options.d.ts.map +0 -1
- package/lib/types/package-name-options.d.ts +0 -4
- package/lib/types/package-name-options.d.ts.map +0 -1
- package/lib/types/package-order-options.d.ts +0 -5
- package/lib/types/package-order-options.d.ts.map +0 -1
- package/lib/types/watch-packages-options.d.ts +0 -6
- package/lib/types/watch-packages-options.d.ts.map +0 -1
- package/lib/watch/functions/filter-files-modified-since.d.ts +0 -2
- package/lib/watch/functions/filter-files-modified-since.d.ts.map +0 -1
- package/lib/watch/functions/get-commands-for-shell.d.ts +0 -2
- package/lib/watch/functions/get-commands-for-shell.d.ts.map +0 -1
- package/lib/watch/functions/get-line-buffered-writer.d.ts +0 -2
- package/lib/watch/functions/get-line-buffered-writer.d.ts.map +0 -1
- package/lib/watch/functions/normalise-watched-file-path.d.ts +0 -2
- package/lib/watch/functions/normalise-watched-file-path.d.ts.map +0 -1
- package/lib/watch/functions/read-stream.d.ts +0 -2
- package/lib/watch/functions/read-stream.d.ts.map +0 -1
- package/lib/watch/functions/run-async.d.ts +0 -3
- package/lib/watch/functions/run-async.d.ts.map +0 -1
- package/lib/watch/functions/run-subprocess.d.ts +0 -11
- package/lib/watch/functions/run-subprocess.d.ts.map +0 -1
- package/lib/watch/functions/watch-package-changes.d.ts +0 -8
- package/lib/watch/functions/watch-package-changes.d.ts.map +0 -1
- package/lib/watch/types/change-action.d.ts +0 -8
- package/lib/watch/types/change-action.d.ts.map +0 -1
- package/lib/watch/types/exit-state.d.ts +0 -8
- package/lib/watch/types/exit-state.d.ts.map +0 -1
- package/lib/watch/types/package-changes.d.ts +0 -2
- package/lib/watch/types/package-changes.d.ts.map +0 -1
- package/lib/watch/types/run-async-type.d.ts +0 -7
- package/lib/watch/types/run-async-type.d.ts.map +0 -1
- package/lib/watch/types/spawn-options.d.ts +0 -4
- package/lib/watch/types/spawn-options.d.ts.map +0 -1
- package/lib/watch/types/std-type.d.ts +0 -7
- package/lib/watch/types/std-type.d.ts.map +0 -1
package/index.js
CHANGED
|
@@ -20,6 +20,8 @@ var checkBun = () => {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
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,
|
|
@@ -249,11 +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
|
|
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));
|
|
262
|
+
logger.debug(`Successfully loaded config file '${path}'.`);
|
|
257
263
|
logger.debug(dim(bgGray("User config:")), `
|
|
258
264
|
${dim(formatSimpleLogObject(parsedConfig))}`);
|
|
259
265
|
logger.debug(dim(bgGray("Default config:")), `
|
|
@@ -262,7 +268,10 @@ ${dim(formatSimpleLogObject(defaultConfig))}`);
|
|
|
262
268
|
activatedConfig.logger = logger;
|
|
263
269
|
logger.debug(dim(bgGray("Activated config:")), `
|
|
264
270
|
${dim(formatSimpleLogObject(activatedConfig))}`);
|
|
265
|
-
return
|
|
271
|
+
return {
|
|
272
|
+
config: activatedConfig,
|
|
273
|
+
rootDir: dirname3(path)
|
|
274
|
+
};
|
|
266
275
|
};
|
|
267
276
|
|
|
268
277
|
// packages/core/src/lib/graph/functions/generate-graphs.ts
|
|
@@ -561,7 +570,7 @@ import { dim as dim6 } from "yoctocolors";
|
|
|
561
570
|
|
|
562
571
|
// packages/core/src/lib/package/functions/scan-packages.ts
|
|
563
572
|
import {
|
|
564
|
-
dirname as
|
|
573
|
+
dirname as dirname5,
|
|
565
574
|
join as join2
|
|
566
575
|
} from "path";
|
|
567
576
|
import { formatUnknownError } from "@package-pal/util";
|
|
@@ -572,7 +581,7 @@ import {
|
|
|
572
581
|
|
|
573
582
|
// packages/core/src/lib/package/functions/parse-package.ts
|
|
574
583
|
import {
|
|
575
|
-
dirname as
|
|
584
|
+
dirname as dirname4,
|
|
576
585
|
basename as basename2
|
|
577
586
|
} from "path";
|
|
578
587
|
import { isDefined as isDefined2 } from "@package-pal/util";
|
|
@@ -594,7 +603,7 @@ var parsePackage = (path, text) => {
|
|
|
594
603
|
rawContent: text,
|
|
595
604
|
path,
|
|
596
605
|
name: props.name ?? path,
|
|
597
|
-
dir: basename2(
|
|
606
|
+
dir: basename2(dirname4(path)),
|
|
598
607
|
version: props.version ?? undefined,
|
|
599
608
|
dependencies: dependencies ?? undefined,
|
|
600
609
|
peerDependencies: peerDependencies ?? undefined,
|
|
@@ -604,20 +613,26 @@ var parsePackage = (path, text) => {
|
|
|
604
613
|
|
|
605
614
|
// packages/core/src/lib/package/functions/scan-package-paths.ts
|
|
606
615
|
import { scanGlobPatternPaths } from "@package-pal/util";
|
|
607
|
-
var scanPackagePaths = (packages) => {
|
|
616
|
+
var scanPackagePaths = (packages, cwd2) => {
|
|
608
617
|
return scanGlobPatternPaths(packages, {
|
|
609
618
|
absolute: true,
|
|
610
|
-
onlyFiles: false
|
|
619
|
+
onlyFiles: false,
|
|
620
|
+
cwd: cwd2
|
|
611
621
|
});
|
|
612
622
|
};
|
|
613
623
|
|
|
614
624
|
// packages/core/src/lib/package/functions/scan-packages.ts
|
|
615
|
-
var scanPackages = async function* (patterns, logger) {
|
|
616
|
-
for await (const path of scanPackagePaths(patterns)) {
|
|
625
|
+
var scanPackages = async function* (patterns, logger, cwd2) {
|
|
626
|
+
for await (const path of scanPackagePaths(patterns, cwd2)) {
|
|
617
627
|
const packagePath = join2(path, "package.json");
|
|
618
|
-
const dir =
|
|
628
|
+
const dir = dirname5(packagePath);
|
|
619
629
|
try {
|
|
630
|
+
logger.debug(dim5(`Trying to read read package.json in '${dir}'.`));
|
|
620
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
|
+
}
|
|
621
636
|
const text = await file.text();
|
|
622
637
|
const packageData = parsePackage(packagePath, text);
|
|
623
638
|
if (!packageData) {
|
|
@@ -633,12 +648,12 @@ var scanPackages = async function* (patterns, logger) {
|
|
|
633
648
|
};
|
|
634
649
|
|
|
635
650
|
// packages/core/src/lib/package/functions/load-packages.ts
|
|
636
|
-
var loadPackages = async (packagePatterns, logger) => {
|
|
651
|
+
var loadPackages = async (rootDir, packagePatterns, logger) => {
|
|
637
652
|
const patternContent = packagePatterns.map((pattern) => `'${pattern}'`).join(", ");
|
|
638
|
-
logger.debug(dim6(`Loading packages matching pattern/s ${patternContent}
|
|
653
|
+
logger.debug(dim6(`Loading packages matching pattern/s ${patternContent}...${rootDir ? ` from ${rootDir}` : ""}`));
|
|
639
654
|
const packages = [];
|
|
640
655
|
const seen = new Set;
|
|
641
|
-
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)) {
|
|
642
657
|
if (seen.has(packageData.name)) {
|
|
643
658
|
continue;
|
|
644
659
|
}
|
|
@@ -651,10 +666,285 @@ var loadPackages = async (packagePatterns, logger) => {
|
|
|
651
666
|
return packages;
|
|
652
667
|
};
|
|
653
668
|
|
|
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
|
+
|
|
654
944
|
// packages/core/src/lib/package/functions/update-package-version.ts
|
|
655
945
|
var {semver } = globalThis.Bun;
|
|
656
946
|
import { inc } from "semver";
|
|
657
|
-
import { dim as
|
|
947
|
+
import { dim as dim8 } from "yoctocolors";
|
|
658
948
|
var findAndReplaceVersion = ({
|
|
659
949
|
raw,
|
|
660
950
|
field,
|
|
@@ -714,7 +1004,7 @@ var findAndReplaceVersion = ({
|
|
|
714
1004
|
return `${before}${updatedVersion}${after}`;
|
|
715
1005
|
};
|
|
716
1006
|
var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact, logger) => {
|
|
717
|
-
logger.debug(
|
|
1007
|
+
logger.debug(dim8(`Bumping package '${packageName}'...`));
|
|
718
1008
|
const packageNode = packageGraphs.dependencies.get(packageName);
|
|
719
1009
|
if (!packageNode) {
|
|
720
1010
|
throw new Error(`Package '${packageName}' not found.`);
|
|
@@ -746,7 +1036,7 @@ var updatePackageVersion = async (packageName, type, packageGraphs, preId, exact
|
|
|
746
1036
|
return [];
|
|
747
1037
|
}
|
|
748
1038
|
if (exact ? depVersion === bumpedVersion : semver.satisfies(bumpedVersion, depVersion)) {
|
|
749
|
-
logger.debug(
|
|
1039
|
+
logger.debug(dim8(`Skipping '${dependent.name}': ${field} version '${depVersion}' already satisfies '${bumpedVersion}'.`));
|
|
750
1040
|
return [];
|
|
751
1041
|
}
|
|
752
1042
|
const updatedContent2 = findAndReplaceVersion({
|
|
@@ -771,22 +1061,61 @@ import {
|
|
|
771
1061
|
watch
|
|
772
1062
|
} from "fs";
|
|
773
1063
|
import {
|
|
774
|
-
dirname as
|
|
1064
|
+
dirname as dirname8,
|
|
775
1065
|
join as join4
|
|
776
1066
|
} from "path";
|
|
777
1067
|
import {
|
|
778
|
-
assertDefined as
|
|
1068
|
+
assertDefined as assertDefined12,
|
|
779
1069
|
DedupePathsBy,
|
|
780
1070
|
dedupeSharedPaths,
|
|
781
1071
|
getDeferredPromise,
|
|
782
1072
|
getStringMatcher,
|
|
783
|
-
isDefined as isDefined4
|
|
1073
|
+
isDefined as isDefined4,
|
|
1074
|
+
RunAsyncType as RunAsyncType2,
|
|
1075
|
+
runAsync as runAsync2
|
|
784
1076
|
} from "@package-pal/util";
|
|
785
1077
|
import {
|
|
786
|
-
dim as
|
|
1078
|
+
dim as dim10,
|
|
787
1079
|
red as red3
|
|
788
1080
|
} from "yoctocolors";
|
|
789
1081
|
|
|
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
|
+
|
|
790
1119
|
// packages/core/src/lib/graph/functions/generate-topological-ranking-range.ts
|
|
791
1120
|
import { isDefined as isDefined3 } from "@package-pal/util";
|
|
792
1121
|
var generateTopologicalRankingRange = (graph, ranking) => {
|
|
@@ -811,11 +1140,11 @@ var generateTopologicalRankingRange = (graph, ranking) => {
|
|
|
811
1140
|
};
|
|
812
1141
|
|
|
813
1142
|
// packages/core/src/lib/graph/functions/generate-topological-ranking.ts
|
|
814
|
-
import { assertDefined as
|
|
1143
|
+
import { assertDefined as assertDefined10 } from "@package-pal/util";
|
|
815
1144
|
var generateTopologicalRanking = (packageProcessOrder) => {
|
|
816
1145
|
const rankMap = new Map;
|
|
817
1146
|
for (let i = 0;i < packageProcessOrder.length; i++) {
|
|
818
|
-
for (const packageName of
|
|
1147
|
+
for (const packageName of assertDefined10(packageProcessOrder[i])) {
|
|
819
1148
|
rankMap.set(packageName, i);
|
|
820
1149
|
}
|
|
821
1150
|
}
|
|
@@ -880,220 +1209,8 @@ var isSubgraph = (a, b) => {
|
|
|
880
1209
|
return true;
|
|
881
1210
|
};
|
|
882
1211
|
|
|
883
|
-
// packages/core/src/lib/watch/
|
|
884
|
-
var
|
|
885
|
-
Ignore: "Ignore",
|
|
886
|
-
Partial: "Partial",
|
|
887
|
-
Restart: "Restart"
|
|
888
|
-
};
|
|
889
|
-
|
|
890
|
-
// packages/core/src/lib/watch/types/exit-state.ts
|
|
891
|
-
var ExitState = {
|
|
892
|
-
Completed: "Completed",
|
|
893
|
-
Errored: "Errored",
|
|
894
|
-
Cancelled: "Cancelled"
|
|
895
|
-
};
|
|
896
|
-
|
|
897
|
-
// packages/core/src/lib/watch/types/run-async-type.ts
|
|
898
|
-
var RunAsyncType = {
|
|
899
|
-
Sequential: "Sequential",
|
|
900
|
-
Parallel: "Parallel"
|
|
901
|
-
};
|
|
902
|
-
|
|
903
|
-
// packages/core/src/lib/watch/functions/filter-files-modified-since.ts
|
|
904
|
-
var filterFilesModifiedSince = (paths, sinceMs) => {
|
|
905
|
-
return paths.filter((path) => {
|
|
906
|
-
const changedFile = Bun.file(path);
|
|
907
|
-
return changedFile.lastModified >= sinceMs;
|
|
908
|
-
});
|
|
909
|
-
};
|
|
910
|
-
|
|
911
|
-
// packages/core/src/lib/watch/functions/normalise-watched-file-path.ts
|
|
912
|
-
import {
|
|
913
|
-
basename as basename3,
|
|
914
|
-
dirname as dirname5,
|
|
915
|
-
join as join3
|
|
916
|
-
} from "path";
|
|
917
|
-
var removeTrailing = [
|
|
918
|
-
"~",
|
|
919
|
-
".tmp",
|
|
920
|
-
".temp",
|
|
921
|
-
".bak",
|
|
922
|
-
".backup",
|
|
923
|
-
".swp",
|
|
924
|
-
".swo",
|
|
925
|
-
".swn"
|
|
926
|
-
];
|
|
927
|
-
var normaliseWatchedFilePath = (filePath) => {
|
|
928
|
-
const dir = dirname5(filePath);
|
|
929
|
-
let base = basename3(filePath);
|
|
930
|
-
for (const trailing of removeTrailing) {
|
|
931
|
-
if (base.toLowerCase().endsWith(trailing)) {
|
|
932
|
-
const sliceStart = base.startsWith(".") ? 1 : 0;
|
|
933
|
-
base = base.slice(sliceStart, -trailing.length);
|
|
934
|
-
break;
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
return join3(dir, base);
|
|
938
|
-
};
|
|
939
|
-
|
|
940
|
-
// packages/core/src/lib/watch/functions/run-async.ts
|
|
941
|
-
var runAsync = async (type, tasks) => {
|
|
942
|
-
if (type === RunAsyncType.Parallel) {
|
|
943
|
-
return Promise.all(tasks.map((task) => task()));
|
|
944
|
-
}
|
|
945
|
-
const outputs = [];
|
|
946
|
-
for (const task of tasks) {
|
|
947
|
-
const result = await task();
|
|
948
|
-
outputs.push(result);
|
|
949
|
-
}
|
|
950
|
-
return outputs;
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
// packages/core/src/lib/watch/functions/run-subprocess.ts
|
|
954
|
-
import {
|
|
955
|
-
dim as dim8,
|
|
956
|
-
red as red2
|
|
957
|
-
} from "yoctocolors";
|
|
958
|
-
|
|
959
|
-
// packages/core/src/lib/watch/types/std-type.ts
|
|
960
|
-
var StdType = {
|
|
961
|
-
Out: "Out",
|
|
962
|
-
Err: "Err"
|
|
963
|
-
};
|
|
964
|
-
|
|
965
|
-
// packages/core/src/lib/watch/functions/get-commands-for-shell.ts
|
|
966
|
-
var getCommandsForShell = (shellCommand) => {
|
|
967
|
-
const isWindows = process.platform === "win32";
|
|
968
|
-
if (!isWindows) {
|
|
969
|
-
return [
|
|
970
|
-
"sh",
|
|
971
|
-
"-c",
|
|
972
|
-
`"${shellCommand}"`
|
|
973
|
-
];
|
|
974
|
-
}
|
|
975
|
-
const shell = Bun.which("pwsh") ? "pwsh" : Bun.which("powershell") ? "powershell" : "cmd";
|
|
976
|
-
if (shell === "cmd") {
|
|
977
|
-
return [
|
|
978
|
-
shell,
|
|
979
|
-
"/c",
|
|
980
|
-
`"${shellCommand}"`
|
|
981
|
-
];
|
|
982
|
-
}
|
|
983
|
-
const encodedCommand = Buffer.from(shellCommand, "utf16le").toString("base64");
|
|
984
|
-
return [
|
|
985
|
-
shell,
|
|
986
|
-
"-EncodedCommand",
|
|
987
|
-
encodedCommand
|
|
988
|
-
];
|
|
989
|
-
};
|
|
990
|
-
|
|
991
|
-
// packages/core/src/lib/watch/functions/get-line-buffered-writer.ts
|
|
992
|
-
import { identity } from "@package-pal/util";
|
|
993
|
-
var getLineBufferedWriter = (prefix, style = identity, write = process.stdout.write.bind(process.stdout)) => {
|
|
994
|
-
let buffer = "";
|
|
995
|
-
return (chunk) => {
|
|
996
|
-
buffer += chunk;
|
|
997
|
-
const lines = buffer.split(`
|
|
998
|
-
`);
|
|
999
|
-
buffer = lines.pop() ?? "";
|
|
1000
|
-
for (const line of lines) {
|
|
1001
|
-
write(`${prefix}${style(line)}
|
|
1002
|
-
`);
|
|
1003
|
-
}
|
|
1004
|
-
};
|
|
1005
|
-
};
|
|
1006
|
-
|
|
1007
|
-
// packages/core/src/lib/watch/functions/read-stream.ts
|
|
1008
|
-
var readStream = async (stream, use) => {
|
|
1009
|
-
if (!stream) {
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
const decoder = new TextDecoder;
|
|
1013
|
-
const reader = stream.getReader();
|
|
1014
|
-
let result = await reader.read();
|
|
1015
|
-
while (!result.done) {
|
|
1016
|
-
use(decoder.decode(result.value, { stream: true }));
|
|
1017
|
-
result = await reader.read();
|
|
1018
|
-
}
|
|
1019
|
-
const flush = decoder.decode();
|
|
1020
|
-
if (flush) {
|
|
1021
|
-
use(flush);
|
|
1022
|
-
}
|
|
1023
|
-
};
|
|
1024
|
-
|
|
1025
|
-
// packages/core/src/lib/watch/functions/run-subprocess.ts
|
|
1026
|
-
var sigintCode = 130;
|
|
1027
|
-
var sigtermCode = 143;
|
|
1028
|
-
var sigkillCode = 137;
|
|
1029
|
-
var cancelCodes = new Set([
|
|
1030
|
-
sigintCode,
|
|
1031
|
-
sigtermCode,
|
|
1032
|
-
sigkillCode
|
|
1033
|
-
]);
|
|
1034
|
-
var runSubprocess = async (opts) => {
|
|
1035
|
-
if (opts.signal?.aborted) {
|
|
1036
|
-
opts.logger.debug(dim8(`Skipped '${opts.debugName}' subprocess command; signal already cancelled.`));
|
|
1037
|
-
return ExitState.Cancelled;
|
|
1038
|
-
}
|
|
1039
|
-
const commands = getCommandsForShell(opts.shellCommand);
|
|
1040
|
-
const subprocess = Bun.spawn(commands, {
|
|
1041
|
-
cwd: opts.cwd,
|
|
1042
|
-
stdout: "pipe",
|
|
1043
|
-
stderr: "pipe",
|
|
1044
|
-
stdin: "ignore",
|
|
1045
|
-
signal: opts.signal
|
|
1046
|
-
});
|
|
1047
|
-
const pid = subprocess.pid.toString();
|
|
1048
|
-
const [readStdout, readStderr] = [{
|
|
1049
|
-
source: subprocess.stdout,
|
|
1050
|
-
type: StdType.Out,
|
|
1051
|
-
write: getLineBufferedWriter(dim8(`[OUT-${pid}] `))
|
|
1052
|
-
}, {
|
|
1053
|
-
source: subprocess.stderr,
|
|
1054
|
-
type: StdType.Err,
|
|
1055
|
-
write: getLineBufferedWriter(red2(dim8(`[ERR-${pid}] `)))
|
|
1056
|
-
}].map(({
|
|
1057
|
-
source,
|
|
1058
|
-
type,
|
|
1059
|
-
write
|
|
1060
|
-
}) => {
|
|
1061
|
-
return readStream(source, (chunk) => {
|
|
1062
|
-
write(chunk);
|
|
1063
|
-
if (opts.onStdChunk) {
|
|
1064
|
-
opts.onStdChunk(chunk, type);
|
|
1065
|
-
}
|
|
1066
|
-
});
|
|
1067
|
-
});
|
|
1068
|
-
const executedCommand = commands.join(" ");
|
|
1069
|
-
opts.logger.debug(dim8(`Started '${opts.debugName}' subprocess command '${opts.shellCommand}' (${executedCommand}) with PID ${pid}.`));
|
|
1070
|
-
const [
|
|
1071
|
-
,
|
|
1072
|
-
,
|
|
1073
|
-
exitState
|
|
1074
|
-
] = await Promise.all([
|
|
1075
|
-
readStdout,
|
|
1076
|
-
readStderr,
|
|
1077
|
-
subprocess.exited.then((exitCode) => {
|
|
1078
|
-
if (cancelCodes.has(exitCode)) {
|
|
1079
|
-
opts.logger.debug(dim8(`Cancelled '${opts.debugName}' subprocess command; PID ${pid} exited.`));
|
|
1080
|
-
return ExitState.Cancelled;
|
|
1081
|
-
}
|
|
1082
|
-
if (exitCode !== 0) {
|
|
1083
|
-
opts.logger.error(red2(`'${opts.debugName}' command '${opts.shellCommand}' (${executedCommand}) with PID ${pid} failed with exit code ${exitCode.toString()}.`));
|
|
1084
|
-
return ExitState.Errored;
|
|
1085
|
-
}
|
|
1086
|
-
opts.logger.debug(dim8(`Completed '${opts.debugName}' subprocess command; PID ${pid} exited.`));
|
|
1087
|
-
return ExitState.Completed;
|
|
1088
|
-
})
|
|
1089
|
-
]);
|
|
1090
|
-
return exitState;
|
|
1091
|
-
};
|
|
1092
|
-
|
|
1093
|
-
// packages/core/src/lib/watch/functions/watch-package-changes.ts
|
|
1094
|
-
var fileModifiedThresholdMs = 5000;
|
|
1095
|
-
var lastProcessedSubgraph;
|
|
1096
|
-
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) => {
|
|
1097
1214
|
const changedPackages = Array.from(packageChanges.keys());
|
|
1098
1215
|
const changedFilePaths = Array.from(packageChanges.values()).flat();
|
|
1099
1216
|
if (packageChanges.size) {
|
|
@@ -1123,9 +1240,9 @@ var getChangeLogic = (packageGraphs, packageChanges, config, logger) => {
|
|
|
1123
1240
|
action = ChangeAction.Partial;
|
|
1124
1241
|
}
|
|
1125
1242
|
if (action === ChangeAction.Partial && isRankedGreaterThanOrEqualToPrevious) {
|
|
1126
|
-
const [prevMinRank] = generateTopologicalRankingRange(
|
|
1243
|
+
const [prevMinRank] = generateTopologicalRankingRange(assertDefined11(lastProcessedSubgraph), packageRankings);
|
|
1127
1244
|
for (let i = 0;i < changedPackageProcessOrder.length; i++) {
|
|
1128
|
-
changedPackageProcessOrder[i] =
|
|
1245
|
+
changedPackageProcessOrder[i] = assertDefined11(changedPackageProcessOrder[i]).filter((packageName) => {
|
|
1129
1246
|
const rank = packageRankings.get(packageName);
|
|
1130
1247
|
return rank !== undefined && rank >= prevMinRank;
|
|
1131
1248
|
});
|
|
@@ -1138,15 +1255,48 @@ var getChangeLogic = (packageGraphs, packageChanges, config, logger) => {
|
|
|
1138
1255
|
action
|
|
1139
1256
|
};
|
|
1140
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;
|
|
1141
1291
|
var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determineAbortController, logger) => {
|
|
1142
1292
|
const {
|
|
1143
1293
|
action,
|
|
1144
1294
|
changedPackageProcessOrder,
|
|
1145
1295
|
changedPackageSubgraph
|
|
1146
|
-
} = getChangeLogic(packageGraphs, packageChanges, watchConfig, logger);
|
|
1296
|
+
} = getChangeLogic(packageGraphs, packageChanges, lastProcessedSubgraph, watchConfig, logger);
|
|
1147
1297
|
const controller = determineAbortController(action === ChangeAction.Restart);
|
|
1148
1298
|
const onProcessFailure = () => {
|
|
1149
|
-
logger.debug(
|
|
1299
|
+
logger.debug(dim10("Aborting controller: process failed."));
|
|
1150
1300
|
controller.abort();
|
|
1151
1301
|
lastProcessedSubgraph = undefined;
|
|
1152
1302
|
};
|
|
@@ -1156,7 +1306,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1156
1306
|
}
|
|
1157
1307
|
if (packageChanges.size) {
|
|
1158
1308
|
logger.info(`Changes detected. ${action === ChangeAction.Restart ? "Restarting processing" : "Initiating partial processing"} ${watchConfig.subprocess.parallelProcessing ? "in parallel" : "sequentially"}.`);
|
|
1159
|
-
lastProcessedSubgraph = changedPackageSubgraph;
|
|
1309
|
+
lastProcessedSubgraph = lastProcessedSubgraph ? mergeGraphs(lastProcessedSubgraph, changedPackageSubgraph) : changedPackageSubgraph;
|
|
1160
1310
|
}
|
|
1161
1311
|
for (const group of changedPackageProcessOrder) {
|
|
1162
1312
|
const {
|
|
@@ -1164,12 +1314,12 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1164
1314
|
resolve: matchedParallelLongReadyRunningOutput
|
|
1165
1315
|
} = getDeferredPromise();
|
|
1166
1316
|
let matchedLongRunningOutputCount = 0;
|
|
1167
|
-
await
|
|
1317
|
+
await runAsync2(watchConfig.subprocess.parallelProcessing ? RunAsyncType2.Parallel : RunAsyncType2.Sequential, group.map((packageName) => async () => {
|
|
1168
1318
|
const {
|
|
1169
1319
|
promise: longRunningSequentialProcessReady,
|
|
1170
1320
|
resolve: matchedSequentialLongRunningReadyOutput
|
|
1171
1321
|
} = getDeferredPromise();
|
|
1172
|
-
const packageNode =
|
|
1322
|
+
const packageNode = assertDefined12(packageGraphs.dependencies.get(packageName));
|
|
1173
1323
|
const changedPaths = packageChanges.get(packageName) ?? [];
|
|
1174
1324
|
const processPackageProps = {
|
|
1175
1325
|
name: packageName,
|
|
@@ -1179,7 +1329,7 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1179
1329
|
totalProcessOrder: changedPackageProcessOrder,
|
|
1180
1330
|
signal: controller.signal
|
|
1181
1331
|
};
|
|
1182
|
-
const processPackageCwd =
|
|
1332
|
+
const processPackageCwd = dirname8(packageNode.packageData.path);
|
|
1183
1333
|
const beforeProcessPackageShellCommand = await watchConfig.hooks.onBeforeProcessPackage(processPackageProps);
|
|
1184
1334
|
if (beforeProcessPackageShellCommand) {
|
|
1185
1335
|
await runSubprocess({
|
|
@@ -1208,13 +1358,13 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1208
1358
|
if (!ready && readyMatcher?.push(chunk).matched()) {
|
|
1209
1359
|
ready = true;
|
|
1210
1360
|
matchedLongRunningOutputCount++;
|
|
1211
|
-
logger.debug(`'${packageName}' (${matchedLongRunningOutputCount.toString()}/${group.length.toString()}) subprocess matched ready text '${
|
|
1361
|
+
logger.debug(`'${packageName}' (${matchedLongRunningOutputCount.toString()}/${group.length.toString()}) subprocess matched ready text '${assertDefined12(longRunningOutputReadyText)}'.`);
|
|
1212
1362
|
if (!watchConfig.subprocess.parallelProcessing && matchedLongRunningOutputCount) {
|
|
1213
1363
|
matchedSequentialLongRunningReadyOutput();
|
|
1214
1364
|
}
|
|
1215
1365
|
}
|
|
1216
1366
|
if (!errored && erroredMatcher?.push(chunk).matched()) {
|
|
1217
|
-
logger.error(red3(`'${packageName}' subprocess matched error text '${
|
|
1367
|
+
logger.error(red3(`'${packageName}' subprocess matched error text '${assertDefined12(longRunningOutputErroredText)}'.`));
|
|
1218
1368
|
errored = true;
|
|
1219
1369
|
Promise.resolve(watchConfig.hooks.onProcessPackageError(processPackageProps)).then((processPackageErrorCommand) => {
|
|
1220
1370
|
if (!processPackageErrorCommand) {
|
|
@@ -1297,23 +1447,23 @@ var onProcessPackage = async (packageGraphs, packageChanges, watchConfig, determ
|
|
|
1297
1447
|
}
|
|
1298
1448
|
};
|
|
1299
1449
|
var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
1300
|
-
const dedupedRootPackageData = dedupeSharedPaths(packageData.map((packageData2) => packageData2.path), DedupePathsBy.Parent).map((packagePath) =>
|
|
1301
|
-
logger.debug(
|
|
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.`));
|
|
1302
1452
|
let closed = false;
|
|
1303
1453
|
let debounceTimeout;
|
|
1304
1454
|
let startedDebounceMs;
|
|
1305
|
-
let
|
|
1455
|
+
let controller;
|
|
1306
1456
|
const changedPackagePaths = new Map;
|
|
1307
1457
|
const useController = (reset) => {
|
|
1308
|
-
if (
|
|
1458
|
+
if (controller && (reset || controller.signal.aborted)) {
|
|
1309
1459
|
if (reset) {
|
|
1310
|
-
logger.debug(
|
|
1311
|
-
|
|
1460
|
+
logger.debug(dim10("Aborting controller: reset for new packages."));
|
|
1461
|
+
controller.abort();
|
|
1312
1462
|
}
|
|
1313
|
-
|
|
1463
|
+
controller = undefined;
|
|
1314
1464
|
}
|
|
1315
|
-
|
|
1316
|
-
return
|
|
1465
|
+
controller ??= new AbortController;
|
|
1466
|
+
return controller;
|
|
1317
1467
|
};
|
|
1318
1468
|
const onWatchEvent = (watchPath, packageName, _event, filePath, forceEmpty = false) => {
|
|
1319
1469
|
if (!isDefined4(startedDebounceMs)) {
|
|
@@ -1337,7 +1487,7 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
|
1337
1487
|
}
|
|
1338
1488
|
const packageChanges = new Map;
|
|
1339
1489
|
for (const [packageName2, paths] of changedPackagePaths) {
|
|
1340
|
-
const processedPaths = filterFilesModifiedSince(dedupeSharedPaths(Array.from(paths), DedupePathsBy.Child).sort(),
|
|
1490
|
+
const processedPaths = filterFilesModifiedSince(dedupeSharedPaths(Array.from(paths), DedupePathsBy.Child).sort(), assertDefined12(startedDebounceMs) - fileModifiedThresholdMs);
|
|
1341
1491
|
if (processedPaths.length) {
|
|
1342
1492
|
packageChanges.set(packageName2, processedPaths);
|
|
1343
1493
|
}
|
|
@@ -1354,7 +1504,7 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
|
1354
1504
|
name,
|
|
1355
1505
|
path
|
|
1356
1506
|
}) => {
|
|
1357
|
-
const watchPath =
|
|
1507
|
+
const watchPath = dirname8(path);
|
|
1358
1508
|
return watch(watchPath, { recursive: true }, (event, filePath) => {
|
|
1359
1509
|
onWatchEvent(watchPath, name, event, filePath);
|
|
1360
1510
|
});
|
|
@@ -1363,22 +1513,22 @@ var watchPackageChanges = (packageData, packageGraphs, watchConfig, logger) => {
|
|
|
1363
1513
|
watchers.forEach((watcher) => {
|
|
1364
1514
|
watcher.close();
|
|
1365
1515
|
});
|
|
1366
|
-
logger.debug(
|
|
1367
|
-
|
|
1516
|
+
logger.debug(dim10("Aborting controller: closing watchers."));
|
|
1517
|
+
controller?.abort();
|
|
1368
1518
|
closed = true;
|
|
1369
1519
|
};
|
|
1370
1520
|
process.on("SIGINT", () => {
|
|
1371
|
-
logger.debug(
|
|
1521
|
+
logger.debug(dim10("Received SIGINT: closing watchers."));
|
|
1372
1522
|
closeWatchers();
|
|
1373
1523
|
process.exit(0);
|
|
1374
1524
|
});
|
|
1375
1525
|
onWatchEvent(undefined, undefined, undefined, null, true);
|
|
1376
1526
|
return { close: () => {
|
|
1377
1527
|
if (closed) {
|
|
1378
|
-
logger.debug(
|
|
1528
|
+
logger.debug(dim10("Watchers already closed."));
|
|
1379
1529
|
return;
|
|
1380
1530
|
}
|
|
1381
|
-
logger.debug(
|
|
1531
|
+
logger.debug(dim10("Closing watchers."));
|
|
1382
1532
|
closeWatchers();
|
|
1383
1533
|
} };
|
|
1384
1534
|
};
|
|
@@ -1391,7 +1541,7 @@ var readPackagePalConfig = (options) => {
|
|
|
1391
1541
|
var readPackageData = async (options) => {
|
|
1392
1542
|
checkBun();
|
|
1393
1543
|
const packagePatterns = Array.isArray(options.config.packages) ? options.config.packages : [options.config.packages];
|
|
1394
|
-
return loadPackages(packagePatterns, options.config.logger);
|
|
1544
|
+
return loadPackages(options.rootDir, packagePatterns, options.config.logger);
|
|
1395
1545
|
};
|
|
1396
1546
|
var getPackageGraphs = (options) => {
|
|
1397
1547
|
checkBun();
|
|
@@ -1415,6 +1565,10 @@ var watchPackages = (options) => {
|
|
|
1415
1565
|
checkBun();
|
|
1416
1566
|
watchPackageChanges(options.packageData, options.packageGraphs, options.config.watch, options.config.logger);
|
|
1417
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
|
+
};
|
|
1418
1572
|
export {
|
|
1419
1573
|
watchPackages,
|
|
1420
1574
|
readPackagePalConfig,
|
|
@@ -1422,9 +1576,10 @@ export {
|
|
|
1422
1576
|
getPackageOrder,
|
|
1423
1577
|
getPackageGraphs,
|
|
1424
1578
|
getPackageCircularDependencyPaths,
|
|
1579
|
+
forEachPackage,
|
|
1425
1580
|
bumpPackageVersion,
|
|
1426
1581
|
BumpVersionType
|
|
1427
1582
|
};
|
|
1428
1583
|
|
|
1429
|
-
//# debugId=
|
|
1584
|
+
//# debugId=F0FEFB088F7E727464756E2164756E21
|
|
1430
1585
|
//# sourceMappingURL=index.js.map
|