1
1
From: Miorel-Lucian Palii <
[email protected] >
2
- Date: Mon, 21 Oct 2024 19:50:25 -0700
2
+ Date: Fri, 25 Oct 2024 21:06:12 -0700
3
3
Subject: Code Chronicles Yarn patch!
4
4
5
5
---
6
6
.../sources/commands/set/version/sources.ts | 16 ++++--
7
- .../sources/commands/foreach.ts | 17 ++++--
7
+ .../sources/commands/foreach.ts | 49 ++++++++++++--- --
8
8
.../sources/commands/build/bundle.ts | 9 +++-
9
9
packages/yarnpkg-core/sources/Manifest.ts | 3 +-
10
10
packages/yarnpkg-core/sources/Report.ts | 53 ++++++++++++++-----
11
- 5 files changed, 72 insertions(+), 26 deletions(-)
11
+ 5 files changed, 95 insertions(+), 35 deletions(-)
12
12
13
13
diff --git a/packages/plugin-essentials/sources/commands/set/version/sources.ts b/packages/plugin-essentials/sources/commands/set/version/sources.ts
14
14
index dc38915c1d06f9f41638c55b973fb08f2f695358..0ab5eec31a8109f165a146d4822369a3f31bb8f5 100644
@@ -52,10 +52,35 @@ index dc38915c1d06f9f41638c55b973fb08f2f695358..0ab5eec31a8109f165a146d4822369a3
52
52
const bundleBuffer = await xfs.readFilePromise(bundlePath);
53
53
54
54
diff --git a/packages/plugin-workspace-tools/sources/commands/foreach.ts b/packages/plugin-workspace-tools/sources/commands/foreach.ts
55
- index 47668fc447c882119b4efb7b75453e2dac30a99e..fefe4d75e5bfd45c081171b5e1f242bceb777c01 100644
55
+ index 47668fc447c882119b4efb7b75453e2dac30a99e..8487c94a62f158fd1c26c64984d8413c9492c38d 100644
56
56
--- a/packages/plugin-workspace-tools/sources/commands/foreach.ts
57
57
+++ b/packages/plugin-workspace-tools/sources/commands/foreach.ts
58
- @@ -260,7 +260,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
58
+ @@ -240,11 +240,23 @@ export default class WorkspacesForeachCommand extends BaseCommand {
59
+ }
60
+ }
61
+
62
+ + // Default to maximum verbosity in terminal environments.
63
+ + const verbosity = this.verbose ?? ((this.context.stdout as WriteStream).isTTY ? Infinity : 0);
64
+ + const label = verbosity > 0;
65
+ + const timing = verbosity > 1;
66
+ + let commandCount = 0;
67
+ +
68
+ for (const workspace of selection) {
69
+ if (scriptName && !workspace.manifest.scripts.has(scriptName) && !isGlobalScript) {
70
+ const accessibleBinaries = await scriptUtils.getWorkspaceAccessibleBinaries(workspace);
71
+ if (!accessibleBinaries.has(scriptName)) {
72
+ - log(`Excluding ${workspace.relativeCwd} because it doesn't have a "${scriptName}" script`);
73
+ + // [Code Chronicles] Report what we skipped for explicitness.
74
+ + if (label && !this.dryRun) {
75
+ + const prefix = getPrefix(workspace, {configuration, label, commandIndex: commandCount++});
76
+ + this.context.stdout.write(`${prefix} Skipping because there's no "${scriptName}" script\n`);
77
+ + } else {
78
+ + log(`Excluding ${workspace.relativeCwd} because it doesn't have a "${scriptName}" script\n`);
79
+ + }
80
+ continue;
81
+ }
82
+ }
83
+ @@ -260,7 +272,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
59
84
}
60
85
61
86
if (this.exclude.length > 0 && (micromatch.isMatch(structUtils.stringifyIdent(workspace.anchoredLocator), this.exclude) || micromatch.isMatch(workspace.relativeCwd, this.exclude))) {
@@ -64,7 +89,54 @@ index 47668fc447c882119b4efb7b75453e2dac30a99e..fefe4d75e5bfd45c081171b5e1f242bc
64
89
continue;
65
90
}
66
91
67
- @@ -448,7 +448,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
92
+ @@ -275,11 +287,6 @@ export default class WorkspacesForeachCommand extends BaseCommand {
93
+ if (this.dryRun)
94
+ return 0;
95
+
96
+ - // Default to maximum verbosity in terminal environments.
97
+ - const verbosity = this.verbose ?? ((this.context.stdout as WriteStream).isTTY ? Infinity : 0);
98
+ - const label = verbosity > 0;
99
+ - const timing = verbosity > 1;
100
+ -
101
+ const concurrency = this.parallel ?
102
+ (this.jobs === `unlimited`
103
+ ? Infinity
104
+ @@ -296,7 +303,6 @@ export default class WorkspacesForeachCommand extends BaseCommand {
105
+ const needsProcessing = new Map<LocatorHash, Workspace>();
106
+ const processing = new Set<DescriptorHash>();
107
+
108
+ - let commandCount = 0;
109
+ let finalExitCode: number | null = null;
110
+
111
+ let abortNextCommands = false;
112
+ @@ -324,11 +330,16 @@ export default class WorkspacesForeachCommand extends BaseCommand {
113
+
114
+ const start = Date.now();
115
+
116
+ + // [Code Chronicles] Update the environment to indicate that it's a
117
+ + // `yarn workspaces foreach`.
118
+ + const oldEnv = process.env;
119
+ + process.env = {...oldEnv, CODE_CHRONICLES_RUNNING_VIA_YARN_WORKSPACES_FOREACH: `1`};
120
+ const exitCode = (await this.cli.run([this.commandName, ...this.args], {
121
+ cwd: workspace.cwd,
122
+ stdout,
123
+ stderr,
124
+ })) || 0;
125
+ + process.env = oldEnv;
126
+
127
+ stdout.end();
128
+ stderr.end();
129
+ @@ -399,7 +410,8 @@ export default class WorkspacesForeachCommand extends BaseCommand {
130
+
131
+ commandPromises.push(limit(async () => {
132
+ const exitCode = await runCommand(workspace, {
133
+ - commandIndex: ++commandCount,
134
+ + // [Code Chronicles] Start the `commandIndex` at 0.
135
+ + commandIndex: commandCount++,
136
+ });
137
+
138
+ needsProcessing.delete(identHash);
139
+ @@ -448,7 +460,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
68
140
69
141
70
142
function createStream(report: Report, {prefix, interlaced}: {prefix: string | null, interlaced: boolean}): [Writable, Promise<boolean>] {
@@ -73,7 +145,15 @@ index 47668fc447c882119b4efb7b75453e2dac30a99e..fefe4d75e5bfd45c081171b5e1f242bc
73
145
74
146
const defaultStream = new miscUtils.DefaultStream();
75
147
defaultStream.pipe(streamReporter, {end: false});
76
- @@ -484,12 +484,19 @@ function getPrefix(workspace: Workspace, {configuration, commandIndex, label}: G
148
+ @@ -480,16 +492,25 @@ type GetPrefixOptions = {
149
+ label: boolean;
150
+ };
151
+
152
+ +
153
+ + // [Code Chronicles] Add a few more colors.
154
+ + const WORKSPACE_COLORS = [`#00A6ED`, `#2E86AB`, `#A23B72`, `#F18F01`, `#C73E1D`, `#CCE2A3`, `#FF69B4`, `#3D9970`];
155
+ +
156
+ function getPrefix(workspace: Workspace, {configuration, commandIndex, label}: GetPrefixOptions) {
77
157
if (!label)
78
158
return null;
79
159
@@ -85,9 +165,8 @@ index 47668fc447c882119b4efb7b75453e2dac30a99e..fefe4d75e5bfd45c081171b5e1f242bc
85
165
+ const prefix = `[${name}]`;
86
166
87
167
- const colors = [`#2E86AB`, `#A23B72`, `#F18F01`, `#C73E1D`, `#CCE2A3`];
88
- + // [Code Chronicles] Add a few more colors.
89
- + const colors = [`#00A6ED`, `#2E86AB`, `#A23B72`, `#F18F01`, `#C73E1D`, `#CCE2A3`, `#FF69B4`, `#3D9970`];
90
- const colorName = colors[commandIndex % colors.length];
168
+ - const colorName = colors[commandIndex % colors.length];
169
+ + const colorName = WORKSPACE_COLORS[commandIndex % WORKSPACE_COLORS.length];
91
170
92
171
return formatUtils.pretty(configuration, prefix, colorName);
93
172
}
0 commit comments