bun-workspaces 1.1.1 → 1.1.2
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
CHANGED
|
@@ -65,9 +65,6 @@ bw run lint my-workspace # Run for a single workspace
|
|
|
65
65
|
bw run lint my-workspace-a my-workspace-b # Run for multiple workspaces
|
|
66
66
|
bw run lint my-alias-a my-alias-b # Run by alias (set by optional config)
|
|
67
67
|
|
|
68
|
-
bw run lint "my-workspace-*" # Run for matching workspace names
|
|
69
|
-
bw run lint "alias:my-alias-pattern-*" "path:my-glob/**/*" # Use matching specifiers
|
|
70
|
-
|
|
71
68
|
# A workspace's script will wait until any workspaces it depends on have completed
|
|
72
69
|
# Similar to Bun's --filter behavior
|
|
73
70
|
bw run lint --dep-order
|
|
@@ -75,6 +72,9 @@ bw run lint --dep-order
|
|
|
75
72
|
# Continue running scripts even if a dependency fails
|
|
76
73
|
bw run lint --dep-order --ignore-dep-failure
|
|
77
74
|
|
|
75
|
+
bw run lint "my-workspace-*" # Run for matching workspace names
|
|
76
|
+
bw run lint "alias:my-alias-pattern-*" "path:my-glob/**/*" # Use matching specifiers
|
|
77
|
+
|
|
78
78
|
bw run lint --args="--my-appended-args" # Add args to each script call
|
|
79
79
|
bw run lint --args="--my-arg=<workspaceName>" # Use the workspace name in args
|
|
80
80
|
|
|
@@ -140,14 +140,22 @@ const runSingleScript = async () => {
|
|
|
140
140
|
const { output, exit } = project.runWorkspaceScript({
|
|
141
141
|
workspaceNameOrAlias: "my-workspace",
|
|
142
142
|
script: "my-script",
|
|
143
|
-
|
|
143
|
+
|
|
144
|
+
// Optional. Arguments to add to the command
|
|
145
|
+
// Can be a string or an array of strings
|
|
146
|
+
// If string, the argv will be parsed POSIX-style
|
|
147
|
+
args: ["--my", "--appended", "--args"],
|
|
148
|
+
|
|
149
|
+
// Optional. Whether to ignore all output from the script.
|
|
150
|
+
// This saves memory when you don't need script output.
|
|
151
|
+
ignoreOutput: false,
|
|
144
152
|
});
|
|
145
153
|
|
|
146
154
|
// Get a stream of the script subprocess's output
|
|
147
155
|
for await (const { chunk, metadata } of output.text()) {
|
|
148
|
-
// console.log(chunk); //
|
|
149
|
-
// console.log(metadata.streamName); // "stdout" or "stderr"
|
|
150
|
-
// console.log(metadata.workspace); //
|
|
156
|
+
// console.log(chunk); // The output chunk's content (string)
|
|
157
|
+
// console.log(metadata.streamName); // The output stream, "stdout" or "stderr"
|
|
158
|
+
// console.log(metadata.workspace); // The target Workspace
|
|
151
159
|
}
|
|
152
160
|
|
|
153
161
|
// Get data about the script execution after it exits
|
|
@@ -173,8 +181,8 @@ const runManyScripts = async () => {
|
|
|
173
181
|
// Required. The package.json "scripts" field name to run
|
|
174
182
|
script: "my-script",
|
|
175
183
|
|
|
176
|
-
// Optional. Arguments to add to the command
|
|
177
|
-
args: "--my --appended --args",
|
|
184
|
+
// Optional. Arguments to add to the command (same as for runWorkspaceScript)
|
|
185
|
+
args: ["--my", "--appended", "--args"],
|
|
178
186
|
|
|
179
187
|
// Optional. Whether to run the scripts in parallel (default: true)
|
|
180
188
|
parallel: true,
|
|
@@ -187,6 +195,10 @@ const runManyScripts = async () => {
|
|
|
187
195
|
// continue running scripts even if a dependency fails
|
|
188
196
|
ignoreDependencyFailure: false,
|
|
189
197
|
|
|
198
|
+
// Optional. Whether to ignore all output from the scripts.
|
|
199
|
+
// This saves memory when you don't need script output.
|
|
200
|
+
ignoreOutput: false,
|
|
201
|
+
|
|
190
202
|
// Optional, callback when script starts, skips, or exits
|
|
191
203
|
onScriptEvent: (event, { workspace, exitResult }) => {
|
|
192
204
|
// event: "start", "skip", "exit"
|
|
@@ -195,9 +207,9 @@ const runManyScripts = async () => {
|
|
|
195
207
|
|
|
196
208
|
// Get a stream of script output
|
|
197
209
|
for await (const { chunk, metadata } of output.text()) {
|
|
198
|
-
// console.log(chunk); // the content (string)
|
|
210
|
+
// console.log(chunk); // the output chunk's content (string)
|
|
199
211
|
// console.log(metadata.streamName); // "stdout" or "stderr"
|
|
200
|
-
// console.log(metadata.workspace); // the
|
|
212
|
+
// console.log(metadata.workspace); // the Workspace that the output came from
|
|
201
213
|
}
|
|
202
214
|
|
|
203
215
|
// Get final summary data and script exit details after all scripts have completed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-workspaces",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A monorepo management tool for Bun, with a CLI and API to enhance Bun's native workspaces.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.mjs",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"commander": "^12.1.0"
|
|
35
|
+
"commander": "^12.1.0",
|
|
36
|
+
"shell-quote": "^1.8.3"
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -58,7 +58,7 @@ const runScript = handleProjectCommand(
|
|
|
58
58
|
process.exit(1);
|
|
59
59
|
}
|
|
60
60
|
const scriptArgs = postTerminatorArgs.length
|
|
61
|
-
? postTerminatorArgs
|
|
61
|
+
? postTerminatorArgs
|
|
62
62
|
: options.args;
|
|
63
63
|
if (positionalWorkspacePatterns.length && options.workspacePatterns) {
|
|
64
64
|
logger.error(
|
|
@@ -39,8 +39,8 @@ export type RunWorkspaceScriptOptions = {
|
|
|
39
39
|
script: string;
|
|
40
40
|
/** Whether to run the script as an inline command */
|
|
41
41
|
inline?: boolean | InlineScriptOptions;
|
|
42
|
-
/** The arguments to append to the script command */
|
|
43
|
-
args?: string;
|
|
42
|
+
/** The arguments to append to the script command. If passed as a string, the argv will be parsed POSIX-style */
|
|
43
|
+
args?: string | string[];
|
|
44
44
|
/** Set to `true` to ignore all output from the script. This saves memory when you don't need script output. */
|
|
45
45
|
ignoreOutput?: boolean;
|
|
46
46
|
};
|
|
@@ -89,8 +89,8 @@ export type RunScriptAcrossWorkspacesOptions = {
|
|
|
89
89
|
script: string;
|
|
90
90
|
/** Whether to run the script as an inline command */
|
|
91
91
|
inline?: boolean | InlineScriptOptions;
|
|
92
|
-
/** The arguments to append to the script command.
|
|
93
|
-
args?: string;
|
|
92
|
+
/** The arguments to append to the script command. If passed as a string, the argv will be parsed POSIX-style */
|
|
93
|
+
args?: string | string[];
|
|
94
94
|
/** Whether to run the scripts in parallel (default: `true`). Pass `false` to run in series. */
|
|
95
95
|
parallel?: ParallelOption;
|
|
96
96
|
/** When `true`, run scripts so that dependent workspaces run only after their dependencies */
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { parse, quote } from "shell-quote/";
|
|
3
4
|
import { loadRootConfig } from "../../config/index.mjs";
|
|
4
5
|
import { getUserEnvVar } from "../../config/userEnvVars/index.mjs";
|
|
5
6
|
import {
|
|
6
7
|
DEFAULT_TEMP_DIR,
|
|
8
|
+
IS_WINDOWS,
|
|
9
|
+
InvalidJSTypeError,
|
|
7
10
|
expandHomePath,
|
|
8
11
|
isPlainObject,
|
|
12
|
+
validateJSArray,
|
|
9
13
|
validateJSTypes,
|
|
10
14
|
} from "../../internal/core/index.mjs";
|
|
11
15
|
import { logger } from "../../internal/logger/index.mjs";
|
|
@@ -27,6 +31,7 @@ import {
|
|
|
27
31
|
resolveWorkspacePath,
|
|
28
32
|
} from "./projectBase.mjs"; // CONCATENATED MODULE: external "fs"
|
|
29
33
|
// CONCATENATED MODULE: external "path"
|
|
34
|
+
// CONCATENATED MODULE: external "shell-quote/"
|
|
30
35
|
// CONCATENATED MODULE: external "../../config/index.mjs"
|
|
31
36
|
// CONCATENATED MODULE: external "../../config/userEnvVars/index.mjs"
|
|
32
37
|
// CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
@@ -40,6 +45,41 @@ import {
|
|
|
40
45
|
// CONCATENATED MODULE: external "./projectBase.mjs"
|
|
41
46
|
// CONCATENATED MODULE: ./src/project/implementations/fileSystemProject.ts
|
|
42
47
|
|
|
48
|
+
const quoteArg = (arg, shell) =>
|
|
49
|
+
IS_WINDOWS && shell === "system"
|
|
50
|
+
? `"${arg.replace(/"/g, '""')}"`
|
|
51
|
+
: quote([arg]);
|
|
52
|
+
const serializeArgs = (args, metadata, shell) => {
|
|
53
|
+
if (!args || args.length === 0) return "";
|
|
54
|
+
if (Array.isArray(args)) {
|
|
55
|
+
return args
|
|
56
|
+
.map((arg) =>
|
|
57
|
+
quoteArg(interpolateScriptRuntimeMetadata(arg, metadata, shell), shell),
|
|
58
|
+
)
|
|
59
|
+
.join(" ");
|
|
60
|
+
}
|
|
61
|
+
const interpolated = interpolateScriptRuntimeMetadata(args, metadata, shell);
|
|
62
|
+
// Escape backslashes in interpolated values before POSIX parse on Windows,
|
|
63
|
+
// so that path separators survive parse's escape processing (\\→\)
|
|
64
|
+
const parseInput =
|
|
65
|
+
IS_WINDOWS && shell === "system"
|
|
66
|
+
? interpolated.replace(/\\/g, "\\\\")
|
|
67
|
+
: interpolated;
|
|
68
|
+
return parse(parseInput)
|
|
69
|
+
.flatMap((entry) => {
|
|
70
|
+
if (typeof entry === "string") {
|
|
71
|
+
return [quoteArg(entry, shell)];
|
|
72
|
+
}
|
|
73
|
+
if ("comment" in entry) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
if ("pattern" in entry) {
|
|
77
|
+
return [entry.pattern];
|
|
78
|
+
}
|
|
79
|
+
return [entry.op];
|
|
80
|
+
})
|
|
81
|
+
.join(" ");
|
|
82
|
+
};
|
|
43
83
|
class _FileSystemProject extends ProjectBase {
|
|
44
84
|
rootDirectory;
|
|
45
85
|
workspaces;
|
|
@@ -122,11 +162,6 @@ class _FileSystemProject extends ProjectBase {
|
|
|
122
162
|
typeofName: ["boolean", "object"],
|
|
123
163
|
optional: true,
|
|
124
164
|
},
|
|
125
|
-
"args option": {
|
|
126
|
-
value: options.args,
|
|
127
|
-
typeofName: "string",
|
|
128
|
-
optional: true,
|
|
129
|
-
},
|
|
130
165
|
"ignoreOutput option": {
|
|
131
166
|
value: options.ignoreOutput,
|
|
132
167
|
typeofName: "boolean",
|
|
@@ -137,6 +172,23 @@ class _FileSystemProject extends ProjectBase {
|
|
|
137
172
|
throw: true,
|
|
138
173
|
},
|
|
139
174
|
);
|
|
175
|
+
if (options.args !== undefined) {
|
|
176
|
+
if (typeof options.args !== "string" && !Array.isArray(options.args)) {
|
|
177
|
+
throw new InvalidJSTypeError(
|
|
178
|
+
`Type error: args option expects type string | string[], received ${typeof options.args}`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
if (Array.isArray(options.args)) {
|
|
182
|
+
const argsError = validateJSArray({
|
|
183
|
+
value: options.args,
|
|
184
|
+
valueLabel: "args option",
|
|
185
|
+
itemOptions: {
|
|
186
|
+
typeofName: "string",
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
if (argsError) throw argsError;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
140
192
|
if (isPlainObject(options.inline)) {
|
|
141
193
|
validateJSTypes(
|
|
142
194
|
{
|
|
@@ -185,11 +237,7 @@ class _FileSystemProject extends ProjectBase {
|
|
|
185
237
|
workspaceName: workspace.name,
|
|
186
238
|
scriptName: options.inline ? inlineScriptName : options.script,
|
|
187
239
|
};
|
|
188
|
-
const args =
|
|
189
|
-
options.args ?? "",
|
|
190
|
-
scriptRuntimeMetadata,
|
|
191
|
-
shell,
|
|
192
|
-
);
|
|
240
|
+
const args = serializeArgs(options.args, scriptRuntimeMetadata, shell);
|
|
193
241
|
const script = options.inline
|
|
194
242
|
? interpolateScriptRuntimeMetadata(
|
|
195
243
|
options.script,
|
|
@@ -243,11 +291,6 @@ class _FileSystemProject extends ProjectBase {
|
|
|
243
291
|
typeofName: ["boolean", "object"],
|
|
244
292
|
optional: true,
|
|
245
293
|
},
|
|
246
|
-
"args option": {
|
|
247
|
-
value: options.args,
|
|
248
|
-
typeofName: "string",
|
|
249
|
-
optional: true,
|
|
250
|
-
},
|
|
251
294
|
"parallel option": {
|
|
252
295
|
value: options.parallel,
|
|
253
296
|
typeofName: ["boolean", "object"],
|
|
@@ -297,6 +340,23 @@ class _FileSystemProject extends ProjectBase {
|
|
|
297
340
|
},
|
|
298
341
|
);
|
|
299
342
|
}
|
|
343
|
+
if (options.args !== undefined) {
|
|
344
|
+
if (typeof options.args !== "string" && !Array.isArray(options.args)) {
|
|
345
|
+
throw new InvalidJSTypeError(
|
|
346
|
+
`Type error: args option expects type string | string[], received ${typeof options.args}`,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
if (Array.isArray(options.args)) {
|
|
350
|
+
const argsError = validateJSArray({
|
|
351
|
+
value: options.args,
|
|
352
|
+
valueLabel: "args option",
|
|
353
|
+
itemOptions: {
|
|
354
|
+
typeofName: "string",
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
if (argsError) throw argsError;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
300
360
|
if (isPlainObject(options.parallel)) {
|
|
301
361
|
validateJSTypes(
|
|
302
362
|
{
|
|
@@ -384,11 +444,7 @@ class _FileSystemProject extends ProjectBase {
|
|
|
384
444
|
workspaceName: workspace.name,
|
|
385
445
|
scriptName: options.inline ? inlineScriptName : options.script,
|
|
386
446
|
};
|
|
387
|
-
const args =
|
|
388
|
-
options.args ?? "",
|
|
389
|
-
scriptRuntimeMetadata,
|
|
390
|
-
shell,
|
|
391
|
-
);
|
|
447
|
+
const args = serializeArgs(options.args, scriptRuntimeMetadata, shell);
|
|
392
448
|
const script = options.inline
|
|
393
449
|
? interpolateScriptRuntimeMetadata(
|
|
394
450
|
options.script,
|