bun-workspaces 1.0.1-alpha → 1.0.1
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/LICENSE.md +1 -1
- package/README.md +189 -70
- package/bin/cli.js +1 -2
- package/package.json +27 -30
- package/src/cli/commands/commandHandlerUtils.d.ts +49 -0
- package/src/cli/commands/commandHandlerUtils.mjs +91 -0
- package/src/cli/commands/commands.d.ts +10 -0
- package/src/cli/commands/commands.mjs +23 -0
- package/src/cli/commands/commandsConfig.d.ts +351 -0
- package/src/cli/commands/commandsConfig.mjs +183 -0
- package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
- package/src/cli/commands/handleSimpleCommands.mjs +174 -0
- package/src/cli/commands/index.d.ts +3 -0
- package/src/cli/commands/index.mjs +3 -0
- package/src/cli/commands/runScript/handleRunScript.d.ts +3 -0
- package/src/cli/commands/runScript/handleRunScript.mjs +249 -0
- package/src/cli/commands/runScript/index.d.ts +2 -0
- package/src/cli/commands/runScript/index.mjs +2 -0
- package/src/cli/commands/runScript/output/index.d.ts +1 -0
- package/src/cli/commands/runScript/output/index.mjs +1 -0
- package/src/cli/commands/runScript/output/outputStyle.d.ts +8 -0
- package/src/cli/commands/runScript/output/outputStyle.mjs +17 -0
- package/src/cli/commands/runScript/output/renderGroupedOutput.d.ts +73 -0
- package/src/cli/commands/runScript/output/renderGroupedOutput.mjs +308 -0
- package/src/cli/commands/runScript/output/renderPlainOutput.d.ts +24 -0
- package/src/cli/commands/runScript/output/renderPlainOutput.mjs +44 -0
- package/src/cli/commands/runScript/output/sanitizeChunk.d.ts +4 -0
- package/src/cli/commands/runScript/output/sanitizeChunk.mjs +101 -0
- package/src/cli/createCli.d.ts +25 -0
- package/src/cli/createCli.mjs +154 -0
- package/src/cli/fatalErrorLogger.d.ts +1 -0
- package/src/cli/fatalErrorLogger.mjs +7 -0
- package/src/cli/globalOptions/globalOptions.d.ts +40 -0
- package/src/cli/globalOptions/globalOptions.mjs +105 -0
- package/src/cli/globalOptions/globalOptionsConfig.d.ts +43 -0
- package/src/cli/globalOptions/globalOptionsConfig.mjs +34 -0
- package/src/cli/globalOptions/index.d.ts +2 -0
- package/src/cli/globalOptions/index.mjs +2 -0
- package/src/cli/index.d.ts +3 -0
- package/src/cli/index.mjs +3 -0
- package/src/cli/middleware.d.ts +72 -0
- package/src/cli/middleware.mjs +38 -0
- package/src/config/index.d.ts +3 -0
- package/src/config/index.mjs +3 -0
- package/src/config/rootConfig/errors.d.ts +1 -0
- package/src/config/rootConfig/errors.mjs +6 -0
- package/src/config/rootConfig/index.d.ts +5 -0
- package/src/config/rootConfig/index.mjs +5 -0
- package/src/config/rootConfig/loadRootConfig.d.ts +3 -0
- package/src/config/rootConfig/loadRootConfig.mjs +22 -0
- package/src/config/rootConfig/rootConfig.d.ts +17 -0
- package/src/config/rootConfig/rootConfig.mjs +43 -0
- package/src/config/rootConfig/rootConfigLocation.d.ts +2 -0
- package/src/config/rootConfig/rootConfigLocation.mjs +5 -0
- package/src/config/rootConfig/rootConfigSchema.d.ts +21 -0
- package/src/config/rootConfig/rootConfigSchema.mjs +24 -0
- package/src/config/userEnvVars/index.d.ts +1 -0
- package/src/config/userEnvVars/index.mjs +1 -0
- package/src/config/userEnvVars/userEnvVars.d.ts +13 -0
- package/src/config/userEnvVars/userEnvVars.mjs +10 -0
- package/src/config/util/ajvTypes.d.ts +10 -0
- package/src/config/util/ajvTypes.mjs +2 -0
- package/src/config/util/configLocation.d.ts +12 -0
- package/src/config/util/configLocation.mjs +11 -0
- package/src/config/util/index.d.ts +4 -0
- package/src/config/util/index.mjs +3 -0
- package/src/config/util/loadConfig.d.ts +16 -0
- package/src/config/util/loadConfig.mjs +118 -0
- package/src/config/util/validateConfig.d.ts +8 -0
- package/src/config/util/validateConfig.mjs +17 -0
- package/src/config/workspaceConfig/errors.d.ts +1 -0
- package/src/config/workspaceConfig/errors.mjs +6 -0
- package/src/config/workspaceConfig/index.d.ts +5 -0
- package/src/config/workspaceConfig/index.mjs +5 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +3 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +25 -0
- package/src/config/workspaceConfig/workspaceConfig.d.ts +22 -0
- package/src/config/workspaceConfig/workspaceConfig.mjs +31 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
- package/src/config/workspaceConfig/workspaceConfigSchema.d.ts +25 -0
- package/src/config/workspaceConfig/workspaceConfigSchema.mjs +28 -0
- package/src/doctor/doctor.d.ts +35 -0
- package/src/doctor/doctor.mjs +52 -0
- package/src/doctor/index.d.ts +1 -0
- package/src/doctor/index.mjs +1 -0
- package/src/index.d.ts +37 -0
- package/src/index.mjs +16 -0
- package/src/internal/bun/bunLock.d.ts +20 -0
- package/src/internal/bun/bunLock.mjs +70 -0
- package/src/internal/bun/bunVersion.d.ts +21 -0
- package/src/internal/bun/bunVersion.mjs +43 -0
- package/src/internal/bun/index.d.ts +2 -0
- package/src/internal/bun/index.mjs +2 -0
- package/src/internal/core/error/error.d.ts +13 -0
- package/src/internal/{error.ts → core/error/error.mjs} +16 -18
- package/src/internal/core/error/index.d.ts +1 -0
- package/src/internal/core/error/index.mjs +1 -0
- package/src/internal/core/index.d.ts +4 -0
- package/src/internal/core/index.mjs +4 -0
- package/src/internal/core/json/index.d.ts +2 -0
- package/src/internal/core/json/index.mjs +2 -0
- package/src/internal/core/json/json.d.ts +49 -0
- package/src/internal/core/json/json.mjs +12 -0
- package/src/internal/core/json/jsonc.d.ts +9 -0
- package/src/internal/core/json/jsonc.mjs +117 -0
- package/src/internal/core/language/array/index.d.ts +1 -0
- package/src/internal/core/language/array/index.mjs +1 -0
- package/src/internal/core/language/array/optionalArray.d.ts +15 -0
- package/src/internal/core/language/array/optionalArray.mjs +8 -0
- package/src/internal/core/language/asyncIterable/asyncIterableQueue.d.ts +16 -0
- package/src/internal/core/language/asyncIterable/asyncIterableQueue.mjs +81 -0
- package/src/internal/core/language/asyncIterable/index.d.ts +2 -0
- package/src/internal/core/language/asyncIterable/index.mjs +2 -0
- package/src/internal/core/language/asyncIterable/mergeAsyncIterables.d.ts +5 -0
- package/src/internal/core/language/asyncIterable/mergeAsyncIterables.mjs +27 -0
- package/src/internal/core/language/events/typedEventTarget.d.ts +50 -0
- package/src/internal/core/language/events/typedEventTarget.mjs +14 -0
- package/src/internal/core/language/index.d.ts +5 -0
- package/src/internal/core/language/index.mjs +5 -0
- package/src/internal/core/language/regex/index.d.ts +1 -0
- package/src/internal/core/language/regex/index.mjs +1 -0
- package/src/internal/core/language/regex/regex.d.ts +3 -0
- package/src/internal/core/language/regex/regex.mjs +10 -0
- package/src/internal/core/language/string/id.d.ts +1 -0
- package/src/internal/core/language/string/id.mjs +10 -0
- package/src/internal/core/language/string/index.d.ts +1 -0
- package/src/internal/core/language/string/index.mjs +1 -0
- package/src/internal/core/language/string/utf/eastAsianWidth.d.ts +16 -0
- package/src/internal/core/language/string/utf/eastAsianWidth.mjs +326 -0
- package/src/internal/core/language/string/utf/visibleLength.d.ts +5 -0
- package/src/internal/core/language/string/utf/visibleLength.mjs +29 -0
- package/src/internal/core/language/types/index.d.ts +2 -0
- package/src/internal/core/language/types/index.mjs +1 -0
- package/src/internal/core/language/types/typeof.d.ts +102 -0
- package/src/internal/core/language/types/typeof.mjs +123 -0
- package/src/internal/core/language/types/types.d.ts +14 -0
- package/src/internal/core/language/types/types.mjs +2 -0
- package/src/internal/core/runtime/env.d.ts +6 -0
- package/src/internal/core/runtime/env.mjs +36 -0
- package/src/internal/core/runtime/index.d.ts +5 -0
- package/src/internal/core/runtime/index.mjs +5 -0
- package/src/internal/core/runtime/onExit.d.ts +4 -0
- package/src/internal/core/runtime/onExit.mjs +54 -0
- package/src/internal/core/runtime/os.d.ts +4 -0
- package/src/internal/core/runtime/os.mjs +7 -0
- package/src/internal/core/runtime/tempFile.d.ts +20 -0
- package/src/internal/core/runtime/tempFile.mjs +87 -0
- package/src/internal/core/runtime/terminal.d.ts +1 -0
- package/src/internal/core/runtime/terminal.mjs +4 -0
- package/src/internal/generated/ajv/validateRootConfig.mjs +1 -0
- package/src/internal/generated/ajv/validateWorkspaceConfig.mjs +1 -0
- package/src/internal/logger/index.d.ts +1 -0
- package/src/internal/logger/index.mjs +1 -0
- package/src/internal/logger/logger.d.ts +45 -0
- package/src/internal/logger/logger.mjs +133 -0
- package/src/internal/version.d.ts +1 -0
- package/src/internal/version.mjs +6 -0
- package/src/project/errors.d.ts +5 -0
- package/src/project/errors.mjs +10 -0
- package/src/project/implementations/fileSystemProject.d.ts +148 -0
- package/src/project/implementations/fileSystemProject.mjs +455 -0
- package/src/project/implementations/memoryProject.d.ts +41 -0
- package/src/project/implementations/memoryProject.mjs +148 -0
- package/src/project/implementations/projectBase.d.ts +35 -0
- package/src/project/implementations/projectBase.mjs +197 -0
- package/src/project/index.d.ts +5 -0
- package/src/project/index.mjs +4 -0
- package/src/project/project.d.ts +75 -0
- package/src/project/project.mjs +6 -0
- package/src/runScript/index.d.ts +7 -0
- package/src/runScript/index.mjs +7 -0
- package/src/runScript/output/index.d.ts +3 -0
- package/src/runScript/output/index.mjs +2 -0
- package/src/runScript/output/multiProcessOutput.d.ts +14 -0
- package/src/runScript/output/multiProcessOutput.mjs +21 -0
- package/src/runScript/output/outputStream.d.ts +1 -0
- package/src/runScript/output/outputStream.mjs +1 -0
- package/src/runScript/output/processOutput.d.ts +33 -0
- package/src/runScript/output/processOutput.mjs +124 -0
- package/src/runScript/parallel.d.ts +15 -0
- package/src/runScript/parallel.mjs +56 -0
- package/src/runScript/recursion.d.ts +4 -0
- package/src/runScript/recursion.mjs +17 -0
- package/src/runScript/runScript.d.ts +45 -0
- package/src/runScript/runScript.mjs +89 -0
- package/src/runScript/runScripts.d.ts +65 -0
- package/src/runScript/runScripts.mjs +263 -0
- package/src/runScript/scriptCommand.d.ts +33 -0
- package/src/runScript/scriptCommand.mjs +19 -0
- package/src/runScript/scriptExecution.d.ts +9 -0
- package/src/runScript/scriptExecution.mjs +50 -0
- package/src/runScript/scriptRuntimeMetadata.d.ts +73 -0
- package/src/runScript/scriptRuntimeMetadata.mjs +61 -0
- package/src/runScript/scriptShellOption.d.ts +8 -0
- package/src/runScript/scriptShellOption.mjs +39 -0
- package/src/runScript/subprocesses.d.ts +11 -0
- package/src/runScript/subprocesses.mjs +34 -0
- package/src/workspaces/dependencyGraph/cycles.d.ts +9 -0
- package/src/workspaces/dependencyGraph/cycles.mjs +91 -0
- package/src/workspaces/dependencyGraph/index.d.ts +2 -0
- package/src/workspaces/dependencyGraph/index.mjs +2 -0
- package/src/workspaces/dependencyGraph/resolveDependencies.d.ts +18 -0
- package/src/workspaces/dependencyGraph/resolveDependencies.mjs +52 -0
- package/src/workspaces/errors.d.ts +13 -0
- package/src/workspaces/errors.mjs +18 -0
- package/src/workspaces/findWorkspaces.d.ts +24 -0
- package/src/workspaces/findWorkspaces.mjs +217 -0
- package/src/workspaces/index.d.ts +4 -0
- package/src/workspaces/index.mjs +3 -0
- package/src/workspaces/packageJson.d.ts +31 -0
- package/src/workspaces/packageJson.mjs +188 -0
- package/src/workspaces/{workspace.ts → workspace.d.ts} +11 -6
- package/src/workspaces/workspace.mjs +2 -0
- package/src/workspaces/workspacePattern.d.ts +21 -0
- package/src/workspaces/workspacePattern.mjs +104 -0
- package/bun.lock +0 -576
- package/src/cli/cli.ts +0 -87
- package/src/cli/globalOptions.ts +0 -122
- package/src/cli/index.ts +0 -1
- package/src/cli/projectCommands.ts +0 -396
- package/src/config/bunWorkspacesConfig.ts +0 -62
- package/src/config/configFile.ts +0 -33
- package/src/config/index.ts +0 -7
- package/src/index.ts +0 -3
- package/src/internal/bunVersion.ts +0 -26
- package/src/internal/env.ts +0 -25
- package/src/internal/logger.ts +0 -145
- package/src/internal/regex.ts +0 -5
- package/src/project/errors.ts +0 -6
- package/src/project/index.ts +0 -6
- package/src/project/project.ts +0 -155
- package/src/project/scriptCommand.ts +0 -40
- package/src/workspaces/errors.ts +0 -14
- package/src/workspaces/findWorkspaces.ts +0 -137
- package/src/workspaces/index.ts +0 -7
- package/src/workspaces/packageJson.ts +0 -166
- package/tsconfig.json +0 -28
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createMultiProcessOutput,
|
|
3
|
+
createProcessOutput,
|
|
4
|
+
} from "./output/index.mjs";
|
|
5
|
+
import { createScriptExecutor } from "./scriptExecution.mjs";
|
|
6
|
+
import { createSubprocess } from "./subprocesses.mjs"; // CONCATENATED MODULE: external "./output/index.mjs"
|
|
7
|
+
// CONCATENATED MODULE: external "./scriptExecution.mjs"
|
|
8
|
+
// CONCATENATED MODULE: external "./subprocesses.mjs"
|
|
9
|
+
// CONCATENATED MODULE: ./src/runScript/runScript.ts
|
|
10
|
+
|
|
11
|
+
const SIGNAL_MAP = {
|
|
12
|
+
130: "SIGINT",
|
|
13
|
+
143: "SIGTERM",
|
|
14
|
+
129: "SIGHUP",
|
|
15
|
+
131: "SIGQUIT",
|
|
16
|
+
138: "SIGUSR1",
|
|
17
|
+
140: "SIGUSR2",
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Run some script and get an async output stream of
|
|
21
|
+
* stdout and stderr chunks and a result object
|
|
22
|
+
* containing exit details.
|
|
23
|
+
*/ const runScript = ({
|
|
24
|
+
scriptCommand,
|
|
25
|
+
metadata,
|
|
26
|
+
env,
|
|
27
|
+
shell = "system",
|
|
28
|
+
ignoreOutput = false,
|
|
29
|
+
}) => {
|
|
30
|
+
const startTime = new Date();
|
|
31
|
+
const { argv, cleanup } = createScriptExecutor(scriptCommand.command, shell);
|
|
32
|
+
const proc = createSubprocess(argv, {
|
|
33
|
+
cwd: scriptCommand.workingDirectory || process.cwd(),
|
|
34
|
+
env: {
|
|
35
|
+
...process.env,
|
|
36
|
+
...env,
|
|
37
|
+
_BW_SCRIPT_SHELL_OPTION: shell,
|
|
38
|
+
FORCE_COLOR: "1",
|
|
39
|
+
},
|
|
40
|
+
stdout: ignoreOutput ? "ignore" : "pipe",
|
|
41
|
+
stderr: ignoreOutput ? "ignore" : "pipe",
|
|
42
|
+
stdin: "ignore",
|
|
43
|
+
});
|
|
44
|
+
proc.exited.finally(cleanup);
|
|
45
|
+
const processOutput = createMultiProcessOutput([
|
|
46
|
+
createProcessOutput(
|
|
47
|
+
proc.stdout
|
|
48
|
+
? proc.stdout
|
|
49
|
+
: (async function* () {
|
|
50
|
+
/* empty */
|
|
51
|
+
})(),
|
|
52
|
+
{
|
|
53
|
+
...metadata,
|
|
54
|
+
streamName: "stdout",
|
|
55
|
+
},
|
|
56
|
+
),
|
|
57
|
+
createProcessOutput(
|
|
58
|
+
proc.stderr
|
|
59
|
+
? proc.stderr
|
|
60
|
+
: (async function* () {
|
|
61
|
+
/* empty */
|
|
62
|
+
})(),
|
|
63
|
+
{
|
|
64
|
+
...metadata,
|
|
65
|
+
streamName: "stderr",
|
|
66
|
+
},
|
|
67
|
+
),
|
|
68
|
+
]);
|
|
69
|
+
const exit = proc.exited.then((exitCode) => {
|
|
70
|
+
const endTime = new Date();
|
|
71
|
+
return {
|
|
72
|
+
exitCode,
|
|
73
|
+
signal: proc.signalCode ?? SIGNAL_MAP[exitCode] ?? null,
|
|
74
|
+
success: exitCode === 0,
|
|
75
|
+
startTimeISO: startTime.toISOString(),
|
|
76
|
+
endTimeISO: endTime.toISOString(),
|
|
77
|
+
durationMs: endTime.getTime() - startTime.getTime(),
|
|
78
|
+
metadata,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
output: processOutput,
|
|
83
|
+
exit,
|
|
84
|
+
metadata,
|
|
85
|
+
kill: (exit) => proc.kill(exit),
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { runScript };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type MultiProcessOutput, type OutputStreamName } from "./output";
|
|
2
|
+
import { type ParallelMaxValue } from "./parallel";
|
|
3
|
+
import { type RunScriptExit, type RunScriptResult } from "./runScript";
|
|
4
|
+
import { type ScriptCommand } from "./scriptCommand";
|
|
5
|
+
import { type ScriptShellOption } from "./scriptShellOption";
|
|
6
|
+
export type RunScriptsScript<ScriptMetadata extends object = object> = {
|
|
7
|
+
scriptCommand: ScriptCommand;
|
|
8
|
+
metadata: ScriptMetadata;
|
|
9
|
+
env: Record<string, string>;
|
|
10
|
+
/** The shell to use to run the script */
|
|
11
|
+
shell?: ScriptShellOption;
|
|
12
|
+
/** Indices of other scripts in the array that must complete before this one starts */
|
|
13
|
+
dependsOn?: number[];
|
|
14
|
+
/** Set to `true` to ignore all output from the script. This saves memory when you don't need script output. */
|
|
15
|
+
ignoreOutput?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type RunScriptsScriptResult<ScriptMetadata extends object = object> = {
|
|
18
|
+
/** The result of running the script */
|
|
19
|
+
result: RunScriptResult<ScriptMetadata>;
|
|
20
|
+
};
|
|
21
|
+
export type RunScriptsSummary<ScriptMetadata extends object = object> = {
|
|
22
|
+
totalCount: number;
|
|
23
|
+
successCount: number;
|
|
24
|
+
failureCount: number;
|
|
25
|
+
allSuccess: boolean;
|
|
26
|
+
startTimeISO: string;
|
|
27
|
+
endTimeISO: string;
|
|
28
|
+
durationMs: number;
|
|
29
|
+
scriptResults: RunScriptExit<ScriptMetadata>[];
|
|
30
|
+
};
|
|
31
|
+
export type ScriptEventName = "start" | "skip" | "exit";
|
|
32
|
+
export type RunScriptsResult<ScriptMetadata extends object = object> = {
|
|
33
|
+
output: MultiProcessOutput<
|
|
34
|
+
ScriptMetadata & {
|
|
35
|
+
streamName: OutputStreamName;
|
|
36
|
+
}
|
|
37
|
+
>;
|
|
38
|
+
/** Resolves with a results summary after all scripts have exited */
|
|
39
|
+
summary: Promise<RunScriptsSummary<ScriptMetadata>>;
|
|
40
|
+
};
|
|
41
|
+
export type RunScriptsParallelOptions = {
|
|
42
|
+
max: ParallelMaxValue;
|
|
43
|
+
};
|
|
44
|
+
export type RunScriptsOptions<ScriptMetadata extends object = object> = {
|
|
45
|
+
scripts: RunScriptsScript<ScriptMetadata>[];
|
|
46
|
+
parallel: boolean | RunScriptsParallelOptions;
|
|
47
|
+
/** When true, run scripts even if a dependency failed. Default: false (skip them). */
|
|
48
|
+
ignoreDependencyFailure?: boolean;
|
|
49
|
+
/** Set to `true` to ignore all output from the scripts. This saves memory when you don't need script output. */
|
|
50
|
+
ignoreOutput?: boolean;
|
|
51
|
+
/** Callback to invoke when a script event occurs */
|
|
52
|
+
onScriptEvent?: (
|
|
53
|
+
event: ScriptEventName,
|
|
54
|
+
scriptIndex: number,
|
|
55
|
+
result: RunScriptExit<ScriptMetadata> | null,
|
|
56
|
+
) => void;
|
|
57
|
+
};
|
|
58
|
+
/** Run a list of scripts */
|
|
59
|
+
export declare const runScripts: <ScriptMetadata extends object = object>({
|
|
60
|
+
scripts,
|
|
61
|
+
parallel,
|
|
62
|
+
ignoreDependencyFailure,
|
|
63
|
+
ignoreOutput,
|
|
64
|
+
onScriptEvent,
|
|
65
|
+
}: RunScriptsOptions<ScriptMetadata>) => RunScriptsResult<ScriptMetadata>;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { createAsyncIterableQueue } from "../internal/core/index.mjs";
|
|
2
|
+
import { logger } from "../internal/logger/index.mjs";
|
|
3
|
+
import {
|
|
4
|
+
createMultiProcessOutput,
|
|
5
|
+
createProcessOutput,
|
|
6
|
+
} from "./output/index.mjs";
|
|
7
|
+
import { determineParallelMax } from "./parallel.mjs";
|
|
8
|
+
import { runScript } from "./runScript.mjs"; // CONCATENATED MODULE: external "../internal/core/index.mjs"
|
|
9
|
+
// CONCATENATED MODULE: external "../internal/logger/index.mjs"
|
|
10
|
+
// CONCATENATED MODULE: external "./output/index.mjs"
|
|
11
|
+
// CONCATENATED MODULE: external "./parallel.mjs"
|
|
12
|
+
// CONCATENATED MODULE: external "./runScript.mjs"
|
|
13
|
+
// CONCATENATED MODULE: ./src/runScript/runScripts.ts
|
|
14
|
+
|
|
15
|
+
/** Validate dependency indices and detect cycles via DFS */ const validateScriptDependencies =
|
|
16
|
+
(scripts) => {
|
|
17
|
+
const scriptCount = scripts.length;
|
|
18
|
+
for (let i = 0; i < scriptCount; i++) {
|
|
19
|
+
const deps = scripts[i].dependsOn;
|
|
20
|
+
if (!deps) continue;
|
|
21
|
+
for (const dep of deps) {
|
|
22
|
+
if (dep === i) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Script at index ${i} has a self-referencing dependency`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (dep < 0 || dep >= scriptCount) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Script at index ${i} depends on invalid index ${dep} (valid range: 0-${scriptCount - 1})`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const WHITE = 0;
|
|
35
|
+
const GRAY = 1;
|
|
36
|
+
const BLACK = 2;
|
|
37
|
+
const colors = new Array(scriptCount).fill(WHITE);
|
|
38
|
+
const visit = (node, path) => {
|
|
39
|
+
colors[node] = GRAY;
|
|
40
|
+
const deps = scripts[node].dependsOn;
|
|
41
|
+
if (deps) {
|
|
42
|
+
for (const dep of deps) {
|
|
43
|
+
if (colors[dep] === GRAY) {
|
|
44
|
+
const cycleStart = path.indexOf(dep);
|
|
45
|
+
const cycle = path.slice(cycleStart);
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Dependency cycle detected: ${[...cycle, dep].join(" -> ")}`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (colors[dep] === WHITE) {
|
|
51
|
+
visit(dep, [...path, dep]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
colors[node] = BLACK;
|
|
56
|
+
};
|
|
57
|
+
for (let i = 0; i < scriptCount; i++) {
|
|
58
|
+
if (colors[i] === WHITE) {
|
|
59
|
+
visit(i, [i]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/** Run a list of scripts */ const runScripts = ({
|
|
64
|
+
scripts,
|
|
65
|
+
parallel,
|
|
66
|
+
ignoreDependencyFailure = false,
|
|
67
|
+
ignoreOutput = false,
|
|
68
|
+
onScriptEvent,
|
|
69
|
+
}) => {
|
|
70
|
+
validateScriptDependencies(scripts);
|
|
71
|
+
const startTime = new Date();
|
|
72
|
+
const scriptTriggers = scripts.map((_, index) => {
|
|
73
|
+
let trigger = () => {
|
|
74
|
+
void 0;
|
|
75
|
+
};
|
|
76
|
+
const promise = new Promise((res) => {
|
|
77
|
+
trigger = () => res(result);
|
|
78
|
+
});
|
|
79
|
+
const result = {
|
|
80
|
+
promise,
|
|
81
|
+
trigger,
|
|
82
|
+
index,
|
|
83
|
+
};
|
|
84
|
+
return result;
|
|
85
|
+
});
|
|
86
|
+
const scriptResults = scripts.map(() => null);
|
|
87
|
+
const parallelMax =
|
|
88
|
+
parallel === false
|
|
89
|
+
? 1
|
|
90
|
+
: determineParallelMax(
|
|
91
|
+
typeof parallel === "boolean" ? "default" : parallel.max,
|
|
92
|
+
);
|
|
93
|
+
const parallelBatchSize = Math.min(parallelMax, scripts.length);
|
|
94
|
+
const recommendedParallelMax = determineParallelMax("auto");
|
|
95
|
+
if (
|
|
96
|
+
parallel &&
|
|
97
|
+
parallelBatchSize > recommendedParallelMax &&
|
|
98
|
+
process.env._BW_IS_INTERNAL_TEST !== "true"
|
|
99
|
+
) {
|
|
100
|
+
logger.warn(
|
|
101
|
+
`Number of scripts to run in parallel (${parallelBatchSize}) is greater than the available CPUs (${recommendedParallelMax})`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const pendingScripts = new Set(scripts.map((_, i) => i));
|
|
105
|
+
const runningScripts = new Set();
|
|
106
|
+
const completedScripts = new Set();
|
|
107
|
+
const exitResults = scripts.map(() => null);
|
|
108
|
+
const scriptProcessBytes = scripts.map(() => null);
|
|
109
|
+
const createSkippedExit = (index) => {
|
|
110
|
+
const now = new Date().toISOString();
|
|
111
|
+
return {
|
|
112
|
+
exitCode: -1,
|
|
113
|
+
signal: null,
|
|
114
|
+
success: false,
|
|
115
|
+
skipped: true,
|
|
116
|
+
startTimeISO: now,
|
|
117
|
+
endTimeISO: now,
|
|
118
|
+
durationMs: 0,
|
|
119
|
+
metadata: scripts[index].metadata,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
const createSkippedResult = (index) => {
|
|
123
|
+
const skippedExit = createSkippedExit(index);
|
|
124
|
+
exitResults[index] = skippedExit;
|
|
125
|
+
return {
|
|
126
|
+
result: {
|
|
127
|
+
output: createMultiProcessOutput([]),
|
|
128
|
+
exit: Promise.resolve(skippedExit),
|
|
129
|
+
metadata: scripts[index].metadata,
|
|
130
|
+
kill: () => {
|
|
131
|
+
/* empty */
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
const hasDependencyFailure = (index) => {
|
|
137
|
+
const deps = scripts[index].dependsOn;
|
|
138
|
+
if (!deps) return false;
|
|
139
|
+
return deps.some(
|
|
140
|
+
(dep) => exitResults[dep] !== null && !exitResults[dep].success,
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
const areDependenciesMet = (index) => {
|
|
144
|
+
const deps = scripts[index].dependsOn;
|
|
145
|
+
if (!deps) return true;
|
|
146
|
+
return deps.every((dep) => completedScripts.has(dep));
|
|
147
|
+
};
|
|
148
|
+
const scriptOutputQueues = scripts.map(() => ({
|
|
149
|
+
stdout: createAsyncIterableQueue(),
|
|
150
|
+
stderr: createAsyncIterableQueue(),
|
|
151
|
+
}));
|
|
152
|
+
const scheduleReadyScripts = () => {
|
|
153
|
+
let changed = true;
|
|
154
|
+
while (changed) {
|
|
155
|
+
changed = false;
|
|
156
|
+
for (const index of [...pendingScripts]) {
|
|
157
|
+
if (runningScripts.size >= parallelMax) return;
|
|
158
|
+
if (!areDependenciesMet(index)) continue;
|
|
159
|
+
if (!ignoreDependencyFailure && hasDependencyFailure(index)) {
|
|
160
|
+
pendingScripts.delete(index);
|
|
161
|
+
completedScripts.add(index);
|
|
162
|
+
scriptResults[index] = createSkippedResult(index);
|
|
163
|
+
scriptProcessBytes[index] = (async function* () {
|
|
164
|
+
/* empty */
|
|
165
|
+
})();
|
|
166
|
+
scriptOutputQueues[index].stdout.close();
|
|
167
|
+
scriptOutputQueues[index].stderr.close();
|
|
168
|
+
onScriptEvent?.("skip", index, null);
|
|
169
|
+
scriptTriggers[index].trigger();
|
|
170
|
+
changed = true;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
pendingScripts.delete(index);
|
|
174
|
+
runningScripts.add(index);
|
|
175
|
+
const scriptResult = {
|
|
176
|
+
...scripts[index],
|
|
177
|
+
result: runScript({
|
|
178
|
+
...scripts[index],
|
|
179
|
+
env: {
|
|
180
|
+
...scripts[index].env,
|
|
181
|
+
_BW_PARALLEL_MAX: parallelMax.toString(),
|
|
182
|
+
},
|
|
183
|
+
ignoreOutput,
|
|
184
|
+
}),
|
|
185
|
+
};
|
|
186
|
+
scriptResults[index] = scriptResult;
|
|
187
|
+
const bytesOutput = scriptResult.result.output.bytes();
|
|
188
|
+
scriptProcessBytes[index] = bytesOutput;
|
|
189
|
+
(async () => {
|
|
190
|
+
for await (const { chunk, metadata } of bytesOutput) {
|
|
191
|
+
scriptOutputQueues[index][metadata.streamName].push(chunk);
|
|
192
|
+
}
|
|
193
|
+
scriptOutputQueues[index].stdout.close();
|
|
194
|
+
scriptOutputQueues[index].stderr.close();
|
|
195
|
+
})();
|
|
196
|
+
onScriptEvent?.("start", index, null);
|
|
197
|
+
scriptTriggers[index].trigger();
|
|
198
|
+
scriptResult.result.exit.then((exit) => {
|
|
199
|
+
runningScripts.delete(index);
|
|
200
|
+
completedScripts.add(index);
|
|
201
|
+
exitResults[index] = exit;
|
|
202
|
+
onScriptEvent?.("exit", index, exit);
|
|
203
|
+
scheduleReadyScripts();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const multiProcessOutput = createMultiProcessOutput(
|
|
209
|
+
scriptOutputQueues.flatMap(({ stdout, stderr }, index) => [
|
|
210
|
+
createProcessOutput(stdout, {
|
|
211
|
+
...scripts[index].metadata,
|
|
212
|
+
streamName: "stdout",
|
|
213
|
+
}),
|
|
214
|
+
createProcessOutput(stderr, {
|
|
215
|
+
...scripts[index].metadata,
|
|
216
|
+
streamName: "stderr",
|
|
217
|
+
}),
|
|
218
|
+
]),
|
|
219
|
+
);
|
|
220
|
+
const handleScriptProcesses = async () => {
|
|
221
|
+
let pendingScriptCount = scripts.length;
|
|
222
|
+
while (pendingScriptCount > 0) {
|
|
223
|
+
const { index } = await Promise.race(
|
|
224
|
+
scriptTriggers.map((trigger) => trigger.promise),
|
|
225
|
+
);
|
|
226
|
+
pendingScriptCount--;
|
|
227
|
+
scriptTriggers[index].promise = new Promise(() => {
|
|
228
|
+
void 0;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
await Promise.all(
|
|
232
|
+
scriptOutputQueues.flatMap(({ stdout, stderr }) => [
|
|
233
|
+
stdout.closed,
|
|
234
|
+
stderr.closed,
|
|
235
|
+
]),
|
|
236
|
+
);
|
|
237
|
+
await Promise.all(scriptResults.map(({ result }) => result.exit));
|
|
238
|
+
};
|
|
239
|
+
const awaitSummary = async () => {
|
|
240
|
+
scheduleReadyScripts();
|
|
241
|
+
await handleScriptProcesses();
|
|
242
|
+
const scriptExitResults = await Promise.all(
|
|
243
|
+
scripts.map((_, index) => scriptResults[index].result.exit),
|
|
244
|
+
);
|
|
245
|
+
const endTime = new Date();
|
|
246
|
+
return {
|
|
247
|
+
totalCount: scriptExitResults.length,
|
|
248
|
+
successCount: scriptExitResults.filter((exit) => exit.success).length,
|
|
249
|
+
failureCount: scriptExitResults.filter((exit) => !exit.success).length,
|
|
250
|
+
allSuccess: scriptExitResults.every((exit) => exit.success),
|
|
251
|
+
startTimeISO: startTime.toISOString(),
|
|
252
|
+
endTimeISO: endTime.toISOString(),
|
|
253
|
+
durationMs: endTime.getTime() - startTime.getTime(),
|
|
254
|
+
scriptResults: scriptExitResults,
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
return {
|
|
258
|
+
output: multiProcessOutput,
|
|
259
|
+
summary: awaitSummary(),
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export { runScripts };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Workspace } from "../workspaces";
|
|
2
|
+
export declare const WORKSPACE_SCRIPT_COMMAND_METHODS: readonly [
|
|
3
|
+
"cd",
|
|
4
|
+
"filter",
|
|
5
|
+
];
|
|
6
|
+
export type WorkspaceScriptCommandMethod =
|
|
7
|
+
(typeof WORKSPACE_SCRIPT_COMMAND_METHODS)[number];
|
|
8
|
+
/** Basic metadata to run a script, the command string and the directory to run it in */
|
|
9
|
+
export interface ScriptCommand {
|
|
10
|
+
/** The command string to run */
|
|
11
|
+
command: string;
|
|
12
|
+
/** The directory to run the command in */
|
|
13
|
+
workingDirectory: string;
|
|
14
|
+
}
|
|
15
|
+
export interface CreateWorkspaceScriptCommandOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The method to use to run the script.
|
|
18
|
+
* Either run in the workspace directory or use bun's --filter option.
|
|
19
|
+
* Defaults to "cd".
|
|
20
|
+
*/
|
|
21
|
+
method?: WorkspaceScriptCommandMethod;
|
|
22
|
+
/** The name of the script to run */
|
|
23
|
+
scriptName: string;
|
|
24
|
+
/** The arguments to append to the command */
|
|
25
|
+
args: string;
|
|
26
|
+
/** The workspace that the script belongs to */
|
|
27
|
+
workspace: Workspace;
|
|
28
|
+
/** The root directory of the project */
|
|
29
|
+
rootDirectory: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const createWorkspaceScriptCommand: (
|
|
32
|
+
options: CreateWorkspaceScriptCommandOptions,
|
|
33
|
+
) => ScriptCommand;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from "path"; // CONCATENATED MODULE: external "path"
|
|
2
|
+
// CONCATENATED MODULE: ./src/runScript/scriptCommand.ts
|
|
3
|
+
|
|
4
|
+
const WORKSPACE_SCRIPT_COMMAND_METHODS = ["cd", "filter"];
|
|
5
|
+
const spaceArgs = (args) => (args ? ` ${args.trim()}` : "");
|
|
6
|
+
const METHODS = {
|
|
7
|
+
cd: ({ scriptName, workspace, rootDirectory, args }) => ({
|
|
8
|
+
workingDirectory: path.resolve(rootDirectory, workspace.path),
|
|
9
|
+
command: `bun --silent run ${scriptName}${spaceArgs(args)}`,
|
|
10
|
+
}),
|
|
11
|
+
filter: ({ scriptName, workspace, args, rootDirectory }) => ({
|
|
12
|
+
workingDirectory: rootDirectory,
|
|
13
|
+
command: `bun --silent run --filter=${JSON.stringify(workspace.name)} ${scriptName}${spaceArgs(args)}`,
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
const createWorkspaceScriptCommand = (options) =>
|
|
17
|
+
METHODS[options.method ?? "cd"](options);
|
|
18
|
+
|
|
19
|
+
export { WORKSPACE_SCRIPT_COMMAND_METHODS, createWorkspaceScriptCommand };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BunWorkspacesError,
|
|
3
|
+
DEFAULT_TEMP_DIR,
|
|
4
|
+
IS_WINDOWS,
|
|
5
|
+
createShortId,
|
|
6
|
+
} from "../internal/core/index.mjs";
|
|
7
|
+
import { resolveScriptShell } from "./scriptShellOption.mjs"; // CONCATENATED MODULE: external "../internal/core/index.mjs"
|
|
8
|
+
// CONCATENATED MODULE: external "./scriptShellOption.mjs"
|
|
9
|
+
// CONCATENATED MODULE: ./src/runScript/scriptExecution.ts
|
|
10
|
+
|
|
11
|
+
const createWindowsBatchFile = (command) => {
|
|
12
|
+
const fileName = `${createShortId(6)}.cmd`;
|
|
13
|
+
const fileContent = `@echo off\r\n${command}\r\n`;
|
|
14
|
+
return DEFAULT_TEMP_DIR.createFile({
|
|
15
|
+
name: fileName,
|
|
16
|
+
content: fileContent,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const createShellScript = (command) => {
|
|
20
|
+
const fileName = `${createShortId(6)}.sh`;
|
|
21
|
+
return DEFAULT_TEMP_DIR.createFile({
|
|
22
|
+
name: fileName,
|
|
23
|
+
content: command,
|
|
24
|
+
mode: 493,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const createScriptExecutor = (command, shell) => {
|
|
28
|
+
shell = resolveScriptShell(shell);
|
|
29
|
+
if (shell === "bun") {
|
|
30
|
+
const { filePath, cleanup } = createShellScript(command);
|
|
31
|
+
return {
|
|
32
|
+
argv: ["bun", filePath],
|
|
33
|
+
cleanup,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (shell === "system") {
|
|
37
|
+
const { filePath, cleanup } = IS_WINDOWS
|
|
38
|
+
? createWindowsBatchFile(command)
|
|
39
|
+
: createShellScript(command);
|
|
40
|
+
return {
|
|
41
|
+
argv: IS_WINDOWS
|
|
42
|
+
? ["cmd", "/d", "/s", "/c", "call", filePath]
|
|
43
|
+
: ["sh", "-c", filePath],
|
|
44
|
+
cleanup,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
throw new BunWorkspacesError(`Invalid shell option: ${shell}`);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { createScriptExecutor };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ScriptShellOption } from "./scriptShellOption";
|
|
2
|
+
export interface ScriptRuntimeMetadata {
|
|
3
|
+
projectPath: string;
|
|
4
|
+
projectName: string;
|
|
5
|
+
workspacePath: string;
|
|
6
|
+
workspaceRelativePath: string;
|
|
7
|
+
workspaceName: string;
|
|
8
|
+
scriptName: string;
|
|
9
|
+
}
|
|
10
|
+
declare const SCRIPT_RUNTIME_METADATA_CONFIG: {
|
|
11
|
+
readonly projectPath: {
|
|
12
|
+
readonly inlineName: "<projectPath>";
|
|
13
|
+
readonly envVarName: "BW_PROJECT_PATH";
|
|
14
|
+
};
|
|
15
|
+
readonly projectName: {
|
|
16
|
+
readonly inlineName: "<projectName>";
|
|
17
|
+
readonly envVarName: "BW_PROJECT_NAME";
|
|
18
|
+
};
|
|
19
|
+
readonly workspacePath: {
|
|
20
|
+
readonly inlineName: "<workspacePath>";
|
|
21
|
+
readonly envVarName: "BW_WORKSPACE_PATH";
|
|
22
|
+
};
|
|
23
|
+
readonly workspaceRelativePath: {
|
|
24
|
+
readonly inlineName: "<workspaceRelativePath>";
|
|
25
|
+
readonly envVarName: "BW_WORKSPACE_RELATIVE_PATH";
|
|
26
|
+
};
|
|
27
|
+
readonly scriptName: {
|
|
28
|
+
readonly inlineName: "<scriptName>";
|
|
29
|
+
readonly envVarName: "BW_SCRIPT_NAME";
|
|
30
|
+
};
|
|
31
|
+
readonly workspaceName: {
|
|
32
|
+
readonly inlineName: "<workspaceName>";
|
|
33
|
+
readonly envVarName: "BW_WORKSPACE_NAME";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type ScriptRuntimeMetadataKey =
|
|
37
|
+
keyof typeof SCRIPT_RUNTIME_METADATA_CONFIG;
|
|
38
|
+
export declare const getScriptRuntimeMetadataConfig: (
|
|
39
|
+
key: ScriptRuntimeMetadataKey,
|
|
40
|
+
) =>
|
|
41
|
+
| {
|
|
42
|
+
readonly inlineName: "<projectPath>";
|
|
43
|
+
readonly envVarName: "BW_PROJECT_PATH";
|
|
44
|
+
}
|
|
45
|
+
| {
|
|
46
|
+
readonly inlineName: "<projectName>";
|
|
47
|
+
readonly envVarName: "BW_PROJECT_NAME";
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
readonly inlineName: "<workspacePath>";
|
|
51
|
+
readonly envVarName: "BW_WORKSPACE_PATH";
|
|
52
|
+
}
|
|
53
|
+
| {
|
|
54
|
+
readonly inlineName: "<workspaceRelativePath>";
|
|
55
|
+
readonly envVarName: "BW_WORKSPACE_RELATIVE_PATH";
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
readonly inlineName: "<scriptName>";
|
|
59
|
+
readonly envVarName: "BW_SCRIPT_NAME";
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
readonly inlineName: "<workspaceName>";
|
|
63
|
+
readonly envVarName: "BW_WORKSPACE_NAME";
|
|
64
|
+
};
|
|
65
|
+
export declare const createScriptRuntimeEnvVars: (
|
|
66
|
+
metadata: ScriptRuntimeMetadata,
|
|
67
|
+
) => Record<string, string>;
|
|
68
|
+
export declare const interpolateScriptRuntimeMetadata: (
|
|
69
|
+
text: string,
|
|
70
|
+
metadata: ScriptRuntimeMetadata,
|
|
71
|
+
shell: ScriptShellOption,
|
|
72
|
+
) => string;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IS_WINDOWS } from "../internal/core/index.mjs"; // CONCATENATED MODULE: external "../internal/core/index.mjs"
|
|
2
|
+
// CONCATENATED MODULE: ./src/runScript/scriptRuntimeMetadata.ts
|
|
3
|
+
|
|
4
|
+
const SCRIPT_RUNTIME_METADATA_CONFIG = {
|
|
5
|
+
projectPath: {
|
|
6
|
+
inlineName: "<projectPath>",
|
|
7
|
+
envVarName: "BW_PROJECT_PATH",
|
|
8
|
+
},
|
|
9
|
+
projectName: {
|
|
10
|
+
inlineName: "<projectName>",
|
|
11
|
+
envVarName: "BW_PROJECT_NAME",
|
|
12
|
+
},
|
|
13
|
+
workspacePath: {
|
|
14
|
+
inlineName: "<workspacePath>",
|
|
15
|
+
envVarName: "BW_WORKSPACE_PATH",
|
|
16
|
+
},
|
|
17
|
+
workspaceRelativePath: {
|
|
18
|
+
inlineName: "<workspaceRelativePath>",
|
|
19
|
+
envVarName: "BW_WORKSPACE_RELATIVE_PATH",
|
|
20
|
+
},
|
|
21
|
+
scriptName: {
|
|
22
|
+
inlineName: "<scriptName>",
|
|
23
|
+
envVarName: "BW_SCRIPT_NAME",
|
|
24
|
+
},
|
|
25
|
+
workspaceName: {
|
|
26
|
+
inlineName: "<workspaceName>",
|
|
27
|
+
envVarName: "BW_WORKSPACE_NAME",
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const getScriptRuntimeMetadataConfig = (key) =>
|
|
31
|
+
SCRIPT_RUNTIME_METADATA_CONFIG[key];
|
|
32
|
+
const createScriptRuntimeEnvVars = (metadata) =>
|
|
33
|
+
Object.entries(SCRIPT_RUNTIME_METADATA_CONFIG).reduce((acc, [key, value]) => {
|
|
34
|
+
acc[value.envVarName] = metadata[key];
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
const interpolateScriptRuntimeMetadata = (text, metadata, shell) =>
|
|
38
|
+
text.replace(
|
|
39
|
+
new RegExp(
|
|
40
|
+
Object.values(SCRIPT_RUNTIME_METADATA_CONFIG)
|
|
41
|
+
.flatMap((value) => value.inlineName)
|
|
42
|
+
.join("|"),
|
|
43
|
+
"g",
|
|
44
|
+
),
|
|
45
|
+
(match) => {
|
|
46
|
+
const key = Object.entries(SCRIPT_RUNTIME_METADATA_CONFIG).find(
|
|
47
|
+
([_, value]) => value.inlineName === match,
|
|
48
|
+
)?.[0];
|
|
49
|
+
const value = metadata[key];
|
|
50
|
+
if (IS_WINDOWS && shell === "bun") {
|
|
51
|
+
return value.replace(/\\/g, "\\\\");
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
createScriptRuntimeEnvVars,
|
|
59
|
+
getScriptRuntimeMetadataConfig,
|
|
60
|
+
interpolateScriptRuntimeMetadata,
|
|
61
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const SCRIPT_SHELL_OPTIONS: readonly ["bun", "system"];
|
|
2
|
+
export type ScriptShellOption = (typeof SCRIPT_SHELL_OPTIONS)[number];
|
|
3
|
+
export declare const validateScriptShellOption: (
|
|
4
|
+
shell: string,
|
|
5
|
+
fromEnvVar?: boolean,
|
|
6
|
+
) => ScriptShellOption;
|
|
7
|
+
export declare const getScriptShellDefault: () => "bun" | "system";
|
|
8
|
+
export declare const resolveScriptShell: (shell?: string) => ScriptShellOption;
|