bun-workspaces 1.8.2 → 1.9.0
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/README.md +51 -13
- package/package.json +1 -1
- package/src/2392.mjs +184 -3
- package/src/5166.mjs +1 -0
- package/src/8529.mjs +10 -0
- package/src/affected/affectedBaseRef.mjs +12 -0
- package/src/affected/externalDependencyChanges.mjs +47 -0
- package/src/affected/fileAffectedWorkspaces.mjs +145 -53
- package/src/affected/gitAffectedFiles.mjs +44 -1
- package/src/affected/gitAffectedWorkspaces.mjs +73 -3
- package/src/affected/index.mjs +2 -0
- package/src/ai/mcp/serverState.mjs +1 -1
- package/src/cli/commands/commandHandlerUtils.mjs +12 -7
- package/src/cli/commands/commands.mjs +4 -1
- package/src/cli/commands/handleSimpleCommands.mjs +2 -2
- package/src/cli/commands/listAffected.mjs +184 -0
- package/src/cli/commands/runScript/handleRunAffected.mjs +99 -0
- package/src/cli/commands/runScript/handleRunScript.mjs +19 -202
- package/src/cli/commands/runScript/index.mjs +1 -0
- package/src/cli/commands/runScript/scriptRunFlow.mjs +213 -0
- package/src/cli/index.d.ts +749 -134
- package/src/config/public.d.ts +66 -2
- package/src/config/rootConfig/rootConfig.mjs +4 -0
- package/src/config/rootConfig/rootConfigSchema.mjs +3 -0
- package/src/config/workspaceConfig/mergeWorkspaceConfig.mjs +33 -19
- package/src/config/workspaceConfig/workspaceConfig.mjs +3 -0
- package/src/config/workspaceConfig/workspaceConfigSchema.mjs +26 -0
- package/src/index.d.ts +307 -5
- package/src/index.mjs +1 -0
- package/src/internal/bun/bunLock.mjs +33 -0
- package/src/internal/generated/aiDocs/docs.mjs +152 -3
- package/src/internal/generated/ajv/validateRootConfig.mjs +1 -1
- package/src/internal/generated/ajv/validateWorkspaceConfig.mjs +1 -1
- package/src/project/implementations/fileSystemProject/affectedWorkspaces.mjs +225 -0
- package/src/project/implementations/{fileSystemProject.mjs → fileSystemProject/fileSystemProject.mjs} +169 -12
- package/src/project/implementations/fileSystemProject/index.mjs +4 -0
- package/src/project/implementations/memoryProject.mjs +1 -0
- package/src/project/index.mjs +1 -1
- package/src/rslib-runtime.mjs +0 -31
- package/src/workspaces/applyWorkspacePatternConfigs.mjs +10 -1
- package/src/workspaces/dependencyGraph/resolveDependencies.mjs +68 -18
- package/src/workspaces/findWorkspaces.mjs +1 -0
- package/src/workspaces/workspace.mjs +8 -2
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { expandHomePath } from "../../../internal/core/index.mjs";
|
|
4
|
+
import { logger } from "../../../internal/logger/index.mjs";
|
|
5
|
+
import {
|
|
6
|
+
getDefaultOutputStyle,
|
|
7
|
+
validateOutputStyle,
|
|
8
|
+
} from "./output/outputStyle.mjs";
|
|
9
|
+
import {
|
|
10
|
+
createScriptEvent,
|
|
11
|
+
createScriptEventTarget,
|
|
12
|
+
renderGroupedOutput,
|
|
13
|
+
} from "./output/renderGroupedOutput.mjs";
|
|
14
|
+
import { renderPlainOutput } from "./output/renderPlainOutput.mjs";
|
|
15
|
+
|
|
16
|
+
const handleScriptRunFlow = async ({
|
|
17
|
+
project,
|
|
18
|
+
context,
|
|
19
|
+
script,
|
|
20
|
+
scriptArgs,
|
|
21
|
+
cliOptions,
|
|
22
|
+
runner,
|
|
23
|
+
}) => {
|
|
24
|
+
const outputStyle = cliOptions.outputStyle
|
|
25
|
+
? validateOutputStyle(cliOptions.outputStyle)
|
|
26
|
+
: getDefaultOutputStyle();
|
|
27
|
+
logger.debug(`Effective output style: ${outputStyle}`);
|
|
28
|
+
const scriptEventTarget = createScriptEventTarget();
|
|
29
|
+
const inline = cliOptions.inline
|
|
30
|
+
? cliOptions.inlineName || cliOptions.shell
|
|
31
|
+
? {
|
|
32
|
+
scriptName: cliOptions.inlineName,
|
|
33
|
+
shell: cliOptions.shell,
|
|
34
|
+
}
|
|
35
|
+
: true
|
|
36
|
+
: undefined;
|
|
37
|
+
const parallel =
|
|
38
|
+
typeof cliOptions.parallel === "boolean" ||
|
|
39
|
+
typeof cliOptions.parallel === "undefined"
|
|
40
|
+
? undefined
|
|
41
|
+
: cliOptions.parallel === "true"
|
|
42
|
+
? true
|
|
43
|
+
: cliOptions.parallel === "false"
|
|
44
|
+
? false
|
|
45
|
+
: {
|
|
46
|
+
max: cliOptions.parallel,
|
|
47
|
+
};
|
|
48
|
+
const { output, summary, workspaces } = await runner({
|
|
49
|
+
script: script,
|
|
50
|
+
inline,
|
|
51
|
+
args: scriptArgs,
|
|
52
|
+
dependencyOrder: cliOptions.depOrder,
|
|
53
|
+
ignoreDependencyFailure: cliOptions.ignoreDepFailure,
|
|
54
|
+
ignoreOutput: outputStyle === "none",
|
|
55
|
+
onScriptEvent: (event, { workspace, exitResult }) => {
|
|
56
|
+
setTimeout(() =>
|
|
57
|
+
// place at end of call stack so listeners in render func receive event
|
|
58
|
+
scriptEventTarget.dispatchEvent(
|
|
59
|
+
createScriptEvent[event]({
|
|
60
|
+
workspace,
|
|
61
|
+
exitResult,
|
|
62
|
+
}),
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
},
|
|
66
|
+
parallel,
|
|
67
|
+
});
|
|
68
|
+
const scriptName = cliOptions.inline
|
|
69
|
+
? cliOptions.inlineName || "(inline)"
|
|
70
|
+
: script;
|
|
71
|
+
logger.debug(`Script name: ${scriptName}`);
|
|
72
|
+
const stripDisruptiveControls =
|
|
73
|
+
workspaces.length > 1 || !!cliOptions.parallel;
|
|
74
|
+
logger.debug(`Strip disruptive controls: ${stripDisruptiveControls}`);
|
|
75
|
+
let groupedLines = "auto";
|
|
76
|
+
if (cliOptions.groupedLines) {
|
|
77
|
+
if (cliOptions.groupedLines === "all") {
|
|
78
|
+
groupedLines = "all";
|
|
79
|
+
} else if (cliOptions.groupedLines === "auto") {
|
|
80
|
+
groupedLines = "auto";
|
|
81
|
+
} else {
|
|
82
|
+
const parsedGroupedLines = parseInt(cliOptions.groupedLines);
|
|
83
|
+
if (parsedGroupedLines <= 0 || isNaN(parsedGroupedLines)) {
|
|
84
|
+
logger.error(
|
|
85
|
+
`Invalid max grouped lines value: ${cliOptions.groupedLines}. Must be a positive number or "all".`,
|
|
86
|
+
);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
groupedLines = parsedGroupedLines;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
logger.debug(`Effective grouped lines: ${JSON.stringify(groupedLines)}`);
|
|
94
|
+
if (!cliOptions.prefix) {
|
|
95
|
+
logger.warn(
|
|
96
|
+
"--no-prefix is deprecated and will be removed in a future version. Use --output-style=plain instead.",
|
|
97
|
+
);
|
|
98
|
+
if (!cliOptions.outputStyle) {
|
|
99
|
+
cliOptions.outputStyle = "plain";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const outputStyleHandlers = {
|
|
103
|
+
grouped: () =>
|
|
104
|
+
renderGroupedOutput(
|
|
105
|
+
workspaces,
|
|
106
|
+
output,
|
|
107
|
+
summary,
|
|
108
|
+
scriptEventTarget,
|
|
109
|
+
groupedLines,
|
|
110
|
+
context.outputWriters,
|
|
111
|
+
context.terminalWidth,
|
|
112
|
+
context.terminalHeight,
|
|
113
|
+
),
|
|
114
|
+
prefixed: () =>
|
|
115
|
+
renderPlainOutput(output, context.outputWriters, {
|
|
116
|
+
prefix: true,
|
|
117
|
+
stripDisruptiveControls,
|
|
118
|
+
}),
|
|
119
|
+
plain: () =>
|
|
120
|
+
renderPlainOutput(output, context.outputWriters, {
|
|
121
|
+
prefix: false,
|
|
122
|
+
stripDisruptiveControls,
|
|
123
|
+
}),
|
|
124
|
+
none: async () => {
|
|
125
|
+
// no-op
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
await outputStyleHandlers[outputStyle]();
|
|
129
|
+
const exitResults = await summary;
|
|
130
|
+
exitResults.scriptResults.forEach(
|
|
131
|
+
({ success, metadata: { workspace }, exitCode }) => {
|
|
132
|
+
const isSkipped = exitCode === -1;
|
|
133
|
+
if (isSkipped) {
|
|
134
|
+
logger.info(
|
|
135
|
+
`➖ ${workspace.name}: ${scriptName} (skipped due to dependency failure)`,
|
|
136
|
+
);
|
|
137
|
+
} else {
|
|
138
|
+
logger.info(
|
|
139
|
+
`${success ? "✅" : "❌"} ${workspace.name}: ${scriptName}${exitCode ? ` (exited with code ${exitCode})` : ""}`,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
const s = exitResults.scriptResults.length === 1 ? "" : "s";
|
|
145
|
+
const skippedCount = exitResults.scriptResults.filter(
|
|
146
|
+
({ exitCode }) => exitCode === -1,
|
|
147
|
+
).length;
|
|
148
|
+
const skippedMessage = skippedCount ? ` (${skippedCount} skipped)` : "";
|
|
149
|
+
if (exitResults.failureCount) {
|
|
150
|
+
const message = `${exitResults.failureCount} of ${exitResults.scriptResults.length} script${s} failed${skippedMessage}`;
|
|
151
|
+
logger.info(message);
|
|
152
|
+
} else {
|
|
153
|
+
logger.info(
|
|
154
|
+
`${exitResults.scriptResults.length} script${s} ran successfully${skippedMessage}`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (cliOptions.jsonOutfile) {
|
|
158
|
+
const fullOutputPath = path.resolve(
|
|
159
|
+
project.rootDirectory,
|
|
160
|
+
expandHomePath(cliOptions.jsonOutfile),
|
|
161
|
+
);
|
|
162
|
+
// Check if can make directory
|
|
163
|
+
const jsonOutputDir = path.dirname(fullOutputPath);
|
|
164
|
+
if (!fs.existsSync(jsonOutputDir)) {
|
|
165
|
+
try {
|
|
166
|
+
logger.debug(`Creating JSON output file directory "${jsonOutputDir}"`);
|
|
167
|
+
fs.mkdirSync(jsonOutputDir, {
|
|
168
|
+
recursive: true,
|
|
169
|
+
});
|
|
170
|
+
} catch (error) {
|
|
171
|
+
logger.error(
|
|
172
|
+
`Failed to create JSON output file directory "${jsonOutputDir}": ${error}`,
|
|
173
|
+
);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
} else if (fs.statSync(jsonOutputDir).isFile()) {
|
|
178
|
+
logger.error(
|
|
179
|
+
`Given JSON output file directory "${jsonOutputDir}" is an existing file`,
|
|
180
|
+
);
|
|
181
|
+
process.exit(1);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Check if can make file
|
|
185
|
+
if (
|
|
186
|
+
fs.existsSync(fullOutputPath) &&
|
|
187
|
+
fs.statSync(fullOutputPath).isDirectory()
|
|
188
|
+
) {
|
|
189
|
+
logger.error(
|
|
190
|
+
`Given JSON output file path "${fullOutputPath}" is an existing directory`,
|
|
191
|
+
);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
logger.debug(`Writing JSON output file "${fullOutputPath}"`);
|
|
197
|
+
fs.writeFileSync(fullOutputPath, JSON.stringify(exitResults, null, 2));
|
|
198
|
+
} catch (error) {
|
|
199
|
+
logger.error(
|
|
200
|
+
`Failed to write JSON output file "${fullOutputPath}": ${error}`,
|
|
201
|
+
);
|
|
202
|
+
process.exit(1);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
logger.info(`JSON output written to ${fullOutputPath}`);
|
|
206
|
+
}
|
|
207
|
+
if (exitResults.failureCount) {
|
|
208
|
+
process.exit(1);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export { handleScriptRunFlow };
|