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,174 @@
|
|
|
1
|
+
import { getDoctorInfo } from "../../doctor/index.mjs";
|
|
2
|
+
import { isJSONObject } from "../../internal/core/index.mjs";
|
|
3
|
+
import { logger } from "../../internal/logger/index.mjs";
|
|
4
|
+
import { ROOT_WORKSPACE_SELECTOR } from "../../project/index.mjs";
|
|
5
|
+
import {
|
|
6
|
+
commandOutputLogger,
|
|
7
|
+
createJsonLines,
|
|
8
|
+
createScriptInfoLines,
|
|
9
|
+
createWorkspaceInfoLines,
|
|
10
|
+
handleGlobalCommand,
|
|
11
|
+
handleProjectCommand,
|
|
12
|
+
splitWorkspacePatterns,
|
|
13
|
+
} from "./commandHandlerUtils.mjs"; // CONCATENATED MODULE: external "../../doctor/index.mjs"
|
|
14
|
+
// CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
15
|
+
// CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
16
|
+
// CONCATENATED MODULE: external "../../project/index.mjs"
|
|
17
|
+
// CONCATENATED MODULE: external "./commandHandlerUtils.mjs"
|
|
18
|
+
// CONCATENATED MODULE: ./src/cli/commands/handleSimpleCommands.ts
|
|
19
|
+
|
|
20
|
+
const doctor = handleGlobalCommand("doctor", (_, options) => {
|
|
21
|
+
logger.debug(`Options: ${JSON.stringify(options)}`);
|
|
22
|
+
const info = getDoctorInfo();
|
|
23
|
+
if (options.json) {
|
|
24
|
+
commandOutputLogger.info(
|
|
25
|
+
JSON.stringify(info, null, options.pretty ? 2 : undefined),
|
|
26
|
+
);
|
|
27
|
+
} else {
|
|
28
|
+
const createEntryLine = ([key, value]) => {
|
|
29
|
+
const keyName = (
|
|
30
|
+
key[0].toUpperCase() + key.slice(1).replace(/([A-Z])/g, " $1")
|
|
31
|
+
).replace(/os|cpu/gi, (m) => m.toUpperCase());
|
|
32
|
+
return isJSONObject(value)
|
|
33
|
+
? keyName +
|
|
34
|
+
":\n - " +
|
|
35
|
+
Object.entries(value).map(createEntryLine).join("\n - ")
|
|
36
|
+
: `${keyName}: ${value}`;
|
|
37
|
+
};
|
|
38
|
+
commandOutputLogger.info(
|
|
39
|
+
"bun-workspaces\n" + Object.entries(info).map(createEntryLine).join("\n"),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const listWorkspaces = handleProjectCommand(
|
|
44
|
+
"listWorkspaces",
|
|
45
|
+
({ project }, positionalWorkspacePatterns, options) => {
|
|
46
|
+
logger.debug(`Options: ${JSON.stringify(options)}`);
|
|
47
|
+
const lines = [];
|
|
48
|
+
if (
|
|
49
|
+
positionalWorkspacePatterns?.length &&
|
|
50
|
+
options.workspacePatterns?.length
|
|
51
|
+
) {
|
|
52
|
+
logger.error(
|
|
53
|
+
"CLI syntax error: Cannot use both inline workspace patterns and --workspace-patterns|-W option",
|
|
54
|
+
);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
const patterns = positionalWorkspacePatterns?.length
|
|
58
|
+
? positionalWorkspacePatterns
|
|
59
|
+
: splitWorkspacePatterns(options.workspacePatterns ?? "");
|
|
60
|
+
const workspaces = patterns?.length
|
|
61
|
+
? project.findWorkspacesByPattern(...patterns)
|
|
62
|
+
: project.workspaces;
|
|
63
|
+
if (options.json) {
|
|
64
|
+
lines.push(
|
|
65
|
+
...createJsonLines(
|
|
66
|
+
options.nameOnly ? workspaces.map(({ name }) => name) : workspaces,
|
|
67
|
+
options,
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
} else {
|
|
71
|
+
workspaces.forEach((workspace) => {
|
|
72
|
+
if (options.nameOnly) {
|
|
73
|
+
lines.push(workspace.name);
|
|
74
|
+
} else {
|
|
75
|
+
lines.push(...createWorkspaceInfoLines(workspace));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (!lines.length && !options.nameOnly) {
|
|
80
|
+
logger.info("No workspaces found");
|
|
81
|
+
}
|
|
82
|
+
if (lines.length) commandOutputLogger.info(lines.join("\n"));
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
const listScripts = handleProjectCommand(
|
|
86
|
+
"listScripts",
|
|
87
|
+
({ project }, options) => {
|
|
88
|
+
logger.debug(`Options: ${JSON.stringify(options)}`);
|
|
89
|
+
const scripts = project.mapScriptsToWorkspaces();
|
|
90
|
+
const lines = [];
|
|
91
|
+
if (!project.workspaces.length && !options.nameOnly) {
|
|
92
|
+
logger.info("No workspaces found");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!Object.keys(scripts).length && !options.nameOnly) {
|
|
96
|
+
logger.info("No scripts found");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (options.json) {
|
|
100
|
+
lines.push(
|
|
101
|
+
...createJsonLines(
|
|
102
|
+
options.nameOnly
|
|
103
|
+
? Object.keys(scripts)
|
|
104
|
+
: Object.values(scripts).map(({ workspaces, ...rest }) => ({
|
|
105
|
+
...rest,
|
|
106
|
+
workspaces: workspaces.map(({ name }) => name),
|
|
107
|
+
})),
|
|
108
|
+
options,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
Object.values(scripts)
|
|
113
|
+
.sort(({ name: nameA }, { name: nameB }) => nameA.localeCompare(nameB))
|
|
114
|
+
.forEach(({ name, workspaces }) => {
|
|
115
|
+
if (options.nameOnly) {
|
|
116
|
+
lines.push(name);
|
|
117
|
+
} else {
|
|
118
|
+
lines.push(...createScriptInfoLines(name, workspaces));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (lines.length) commandOutputLogger.info(lines.join("\n"));
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
const workspaceInfo = handleProjectCommand(
|
|
126
|
+
"workspaceInfo",
|
|
127
|
+
({ project }, workspaceName, options) => {
|
|
128
|
+
logger.debug(`Options: ${JSON.stringify(options)}`);
|
|
129
|
+
const workspace =
|
|
130
|
+
workspaceName === ROOT_WORKSPACE_SELECTOR
|
|
131
|
+
? project.rootWorkspace
|
|
132
|
+
: project.findWorkspaceByNameOrAlias(workspaceName);
|
|
133
|
+
if (!workspace) {
|
|
134
|
+
logger.error(`Workspace ${JSON.stringify(workspaceName)} not found`);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
commandOutputLogger.info(
|
|
138
|
+
(options.json
|
|
139
|
+
? createJsonLines(workspace, options)
|
|
140
|
+
: createWorkspaceInfoLines(workspace)
|
|
141
|
+
).join("\n"),
|
|
142
|
+
);
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
const scriptInfo = handleProjectCommand(
|
|
146
|
+
"scriptInfo",
|
|
147
|
+
({ project }, script, options) => {
|
|
148
|
+
logger.debug(`Options: ${JSON.stringify(options)}`);
|
|
149
|
+
const scripts = project.mapScriptsToWorkspaces();
|
|
150
|
+
const scriptMetadata = scripts[script];
|
|
151
|
+
if (!scriptMetadata) {
|
|
152
|
+
logger.error(`Script not found: ${JSON.stringify(script)}`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
commandOutputLogger.info(
|
|
156
|
+
(options.json
|
|
157
|
+
? createJsonLines(
|
|
158
|
+
options.workspacesOnly
|
|
159
|
+
? scriptMetadata.workspaces.map(({ name }) => name)
|
|
160
|
+
: {
|
|
161
|
+
name: scriptMetadata.name,
|
|
162
|
+
workspaces: scriptMetadata.workspaces.map(({ name }) => name),
|
|
163
|
+
},
|
|
164
|
+
options,
|
|
165
|
+
)
|
|
166
|
+
: options.workspacesOnly
|
|
167
|
+
? scriptMetadata.workspaces.map(({ name }) => name)
|
|
168
|
+
: createScriptInfoLines(script, scriptMetadata.workspaces)
|
|
169
|
+
).join("\n"),
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
export { doctor, listScripts, listWorkspaces, scriptInfo, workspaceInfo };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { logger } from "../../../internal/logger/index.mjs";
|
|
4
|
+
import {
|
|
5
|
+
handleProjectCommand,
|
|
6
|
+
splitWorkspacePatterns,
|
|
7
|
+
} from "../commandHandlerUtils.mjs";
|
|
8
|
+
import { DEFAULT_GROUPED_LINES } from "../commandsConfig.mjs";
|
|
9
|
+
import {
|
|
10
|
+
getDefaultOutputStyle,
|
|
11
|
+
validateOutputStyle,
|
|
12
|
+
} from "./output/outputStyle.mjs";
|
|
13
|
+
import {
|
|
14
|
+
createScriptEvent,
|
|
15
|
+
createScriptEventTarget,
|
|
16
|
+
renderGroupedOutput,
|
|
17
|
+
} from "./output/renderGroupedOutput.mjs";
|
|
18
|
+
import { renderPlainOutput } from "./output/renderPlainOutput.mjs"; // CONCATENATED MODULE: external "fs"
|
|
19
|
+
// CONCATENATED MODULE: external "path"
|
|
20
|
+
// CONCATENATED MODULE: external "../../../internal/logger/index.mjs"
|
|
21
|
+
// CONCATENATED MODULE: external "../commandHandlerUtils.mjs"
|
|
22
|
+
// CONCATENATED MODULE: external "../commandsConfig.mjs"
|
|
23
|
+
// CONCATENATED MODULE: external "./output/outputStyle.mjs"
|
|
24
|
+
// CONCATENATED MODULE: external "./output/renderGroupedOutput.mjs"
|
|
25
|
+
// CONCATENATED MODULE: external "./output/renderPlainOutput.mjs"
|
|
26
|
+
// CONCATENATED MODULE: ./src/cli/commands/runScript/handleRunScript.ts
|
|
27
|
+
|
|
28
|
+
const runScript = handleProjectCommand(
|
|
29
|
+
"runScript",
|
|
30
|
+
async (
|
|
31
|
+
{ project, postTerminatorArgs, outputWriters },
|
|
32
|
+
positionalScript,
|
|
33
|
+
positionalWorkspacePatterns,
|
|
34
|
+
options,
|
|
35
|
+
) => {
|
|
36
|
+
options.inlineName = options.inlineName?.trim();
|
|
37
|
+
options.args = options.args?.trim();
|
|
38
|
+
options.jsonOutfile = options.jsonOutfile?.trim();
|
|
39
|
+
options.parallel =
|
|
40
|
+
typeof options.parallel === "string"
|
|
41
|
+
? options.parallel.trim()
|
|
42
|
+
: options.parallel;
|
|
43
|
+
if (positionalScript && options.script) {
|
|
44
|
+
// If script is provided via options, then the first positional argument is actually a workspace pattern
|
|
45
|
+
positionalWorkspacePatterns.splice(0, 0, positionalScript);
|
|
46
|
+
}
|
|
47
|
+
const script = options.script || positionalScript;
|
|
48
|
+
if (postTerminatorArgs.length && options.args) {
|
|
49
|
+
logger.error(
|
|
50
|
+
"CLI syntax error: Cannot use both --args and inline script args after --",
|
|
51
|
+
);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
const scriptArgs = postTerminatorArgs.length
|
|
55
|
+
? postTerminatorArgs.join(" ")
|
|
56
|
+
: options.args;
|
|
57
|
+
if (positionalWorkspacePatterns.length && options.workspacePatterns) {
|
|
58
|
+
logger.error(
|
|
59
|
+
"CLI syntax error: Cannot use both inline workspace patterns and --workspace-patterns|-W option",
|
|
60
|
+
);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
const workspacePatterns = positionalWorkspacePatterns?.length
|
|
64
|
+
? positionalWorkspacePatterns
|
|
65
|
+
: splitWorkspacePatterns(options.workspacePatterns ?? "");
|
|
66
|
+
logger.debug(
|
|
67
|
+
`Command: Run ${options.inline ? "inline " : ""}script ${JSON.stringify(script)} for ${workspacePatterns.length ? "workspaces " + workspacePatterns.join(", ") : "all workspaces"}`,
|
|
68
|
+
);
|
|
69
|
+
logger.debug(`Options: ${JSON.stringify(options)}`);
|
|
70
|
+
const scriptEventTarget = createScriptEventTarget();
|
|
71
|
+
const { output, summary, workspaces } = project.runScriptAcrossWorkspaces({
|
|
72
|
+
workspacePatterns: workspacePatterns.length
|
|
73
|
+
? workspacePatterns
|
|
74
|
+
: undefined,
|
|
75
|
+
script,
|
|
76
|
+
inline: options.inline
|
|
77
|
+
? options.inlineName || options.shell
|
|
78
|
+
? {
|
|
79
|
+
scriptName: options.inlineName,
|
|
80
|
+
shell: options.shell,
|
|
81
|
+
}
|
|
82
|
+
: true
|
|
83
|
+
: undefined,
|
|
84
|
+
args: scriptArgs,
|
|
85
|
+
dependencyOrder: options.depOrder,
|
|
86
|
+
ignoreDependencyFailure: options.ignoreDepFailure,
|
|
87
|
+
ignoreOutput: logger.printLevel === "silent",
|
|
88
|
+
onScriptEvent: (event, { workspace, exitResult }) => {
|
|
89
|
+
setTimeout(() =>
|
|
90
|
+
// place at end of call stack so listeners in render func receive event
|
|
91
|
+
scriptEventTarget.dispatchEvent(
|
|
92
|
+
createScriptEvent[event]({
|
|
93
|
+
workspace,
|
|
94
|
+
exitResult,
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
},
|
|
99
|
+
parallel:
|
|
100
|
+
typeof options.parallel === "boolean" ||
|
|
101
|
+
typeof options.parallel === "undefined"
|
|
102
|
+
? undefined
|
|
103
|
+
: options.parallel === "true"
|
|
104
|
+
? true
|
|
105
|
+
: options.parallel === "false"
|
|
106
|
+
? false
|
|
107
|
+
: {
|
|
108
|
+
max: options.parallel,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const scriptName = options.inline
|
|
112
|
+
? options.inlineName || "(inline)"
|
|
113
|
+
: script;
|
|
114
|
+
logger.debug(`Script name: ${scriptName}`);
|
|
115
|
+
const stripDisruptiveControls = workspaces.length > 1 || !!options.parallel;
|
|
116
|
+
logger.debug(`Strip disruptive controls: ${stripDisruptiveControls}`);
|
|
117
|
+
let groupedLines = DEFAULT_GROUPED_LINES;
|
|
118
|
+
if (options.groupedLines) {
|
|
119
|
+
if (options.groupedLines === "all") {
|
|
120
|
+
groupedLines = "all";
|
|
121
|
+
} else {
|
|
122
|
+
const parsedGroupedLines = parseInt(options.groupedLines);
|
|
123
|
+
if (parsedGroupedLines <= 0 || isNaN(parsedGroupedLines)) {
|
|
124
|
+
logger.error(
|
|
125
|
+
`Invalid max grouped lines value: ${options.groupedLines}. Must be a positive number or "all".`,
|
|
126
|
+
);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
groupedLines = parsedGroupedLines;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
logger.debug(`Effective grouped lines: ${JSON.stringify(groupedLines)}`);
|
|
133
|
+
if (!options.prefix) {
|
|
134
|
+
logger.warn(
|
|
135
|
+
"--no-prefix is deprecated and will be removed in a future version. Use --output-style=plain instead.",
|
|
136
|
+
);
|
|
137
|
+
if (!options.outputStyle) {
|
|
138
|
+
options.outputStyle = "plain";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const outputStyleHandlers = {
|
|
142
|
+
grouped: () =>
|
|
143
|
+
renderGroupedOutput(
|
|
144
|
+
workspaces,
|
|
145
|
+
output,
|
|
146
|
+
summary,
|
|
147
|
+
scriptEventTarget,
|
|
148
|
+
groupedLines,
|
|
149
|
+
outputWriters,
|
|
150
|
+
),
|
|
151
|
+
prefixed: () =>
|
|
152
|
+
renderPlainOutput(output, outputWriters, {
|
|
153
|
+
prefix: true,
|
|
154
|
+
stripDisruptiveControls,
|
|
155
|
+
}),
|
|
156
|
+
plain: () =>
|
|
157
|
+
renderPlainOutput(output, outputWriters, {
|
|
158
|
+
prefix: false,
|
|
159
|
+
stripDisruptiveControls,
|
|
160
|
+
}),
|
|
161
|
+
};
|
|
162
|
+
const outputStyle = options.outputStyle
|
|
163
|
+
? validateOutputStyle(options.outputStyle)
|
|
164
|
+
: getDefaultOutputStyle();
|
|
165
|
+
logger.debug(`Effective output style: ${outputStyle}`);
|
|
166
|
+
await outputStyleHandlers[outputStyle]();
|
|
167
|
+
const exitResults = await summary;
|
|
168
|
+
exitResults.scriptResults.forEach(
|
|
169
|
+
({ success, metadata: { workspace }, exitCode }) => {
|
|
170
|
+
const isSkipped = exitCode === -1;
|
|
171
|
+
if (isSkipped) {
|
|
172
|
+
logger.info(
|
|
173
|
+
`➖ ${workspace.name}: ${scriptName} (skipped due to dependency failure)`,
|
|
174
|
+
);
|
|
175
|
+
} else {
|
|
176
|
+
logger.info(
|
|
177
|
+
`${success ? "✅" : "❌"} ${workspace.name}: ${scriptName}${exitCode ? ` (exited with code ${exitCode})` : ""}`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
const s = exitResults.scriptResults.length === 1 ? "" : "s";
|
|
183
|
+
const skippedCount = exitResults.scriptResults.filter(
|
|
184
|
+
({ exitCode }) => exitCode === -1,
|
|
185
|
+
).length;
|
|
186
|
+
const skippedMessage = skippedCount ? ` (${skippedCount} skipped)` : "";
|
|
187
|
+
if (exitResults.failureCount) {
|
|
188
|
+
const message = `${exitResults.failureCount} of ${exitResults.scriptResults.length} script${s} failed${skippedMessage}`;
|
|
189
|
+
logger.info(message);
|
|
190
|
+
} else {
|
|
191
|
+
logger.info(
|
|
192
|
+
`${exitResults.scriptResults.length} script${s} ran successfully${skippedMessage}`,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (options.jsonOutfile) {
|
|
196
|
+
const fullOutputPath = path.resolve(
|
|
197
|
+
project.rootDirectory,
|
|
198
|
+
options.jsonOutfile,
|
|
199
|
+
);
|
|
200
|
+
// Check if can make directory
|
|
201
|
+
const jsonOutputDir = path.dirname(fullOutputPath);
|
|
202
|
+
if (!fs.existsSync(jsonOutputDir)) {
|
|
203
|
+
try {
|
|
204
|
+
logger.debug(
|
|
205
|
+
`Creating JSON output file directory "${jsonOutputDir}"`,
|
|
206
|
+
);
|
|
207
|
+
fs.mkdirSync(jsonOutputDir, {
|
|
208
|
+
recursive: true,
|
|
209
|
+
});
|
|
210
|
+
} catch (error) {
|
|
211
|
+
logger.error(
|
|
212
|
+
`Failed to create JSON output file directory "${jsonOutputDir}": ${error}`,
|
|
213
|
+
);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
} else if (fs.statSync(jsonOutputDir).isFile()) {
|
|
217
|
+
logger.error(
|
|
218
|
+
`Given JSON output file directory "${jsonOutputDir}" is an existing file`,
|
|
219
|
+
);
|
|
220
|
+
process.exit(1);
|
|
221
|
+
}
|
|
222
|
+
// Check if can make file
|
|
223
|
+
if (
|
|
224
|
+
fs.existsSync(fullOutputPath) &&
|
|
225
|
+
fs.statSync(fullOutputPath).isDirectory()
|
|
226
|
+
) {
|
|
227
|
+
logger.error(
|
|
228
|
+
`Given JSON output file path "${fullOutputPath}" is an existing directory`,
|
|
229
|
+
);
|
|
230
|
+
process.exit(1);
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
logger.debug(`Writing JSON output file "${fullOutputPath}"`);
|
|
234
|
+
fs.writeFileSync(fullOutputPath, JSON.stringify(exitResults, null, 2));
|
|
235
|
+
} catch (error) {
|
|
236
|
+
logger.error(
|
|
237
|
+
`Failed to write JSON output file "${fullOutputPath}": ${error}`,
|
|
238
|
+
);
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
241
|
+
logger.info(`JSON output written to ${fullOutputPath}`);
|
|
242
|
+
}
|
|
243
|
+
if (exitResults.failureCount) {
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
export { runScript };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./renderPlainOutput";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./renderPlainOutput.mjs"; // CONCATENATED MODULE: ./src/cli/commands/runScript/output/index.ts
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const OUTPUT_STYLE_VALUES: readonly [
|
|
2
|
+
"grouped",
|
|
3
|
+
"prefixed",
|
|
4
|
+
"plain",
|
|
5
|
+
];
|
|
6
|
+
export type OutputStyleName = (typeof OUTPUT_STYLE_VALUES)[number];
|
|
7
|
+
export declare const getDefaultOutputStyle: () => OutputStyleName;
|
|
8
|
+
export declare const validateOutputStyle: (style: string) => OutputStyleName;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BunWorkspacesError } from "../../../../internal/core/error/index.mjs";
|
|
2
|
+
import { IS_TTY } from "../../../../internal/core/runtime/terminal.mjs"; // CONCATENATED MODULE: external "../../../../internal/core/error/index.mjs"
|
|
3
|
+
// CONCATENATED MODULE: external "../../../../internal/core/runtime/terminal.mjs"
|
|
4
|
+
// CONCATENATED MODULE: ./src/cli/commands/runScript/output/outputStyle.ts
|
|
5
|
+
|
|
6
|
+
const OUTPUT_STYLE_VALUES = ["grouped", "prefixed", "plain"];
|
|
7
|
+
const getDefaultOutputStyle = () => (IS_TTY ? "grouped" : "prefixed");
|
|
8
|
+
const validateOutputStyle = (style) => {
|
|
9
|
+
if (!OUTPUT_STYLE_VALUES.includes(style)) {
|
|
10
|
+
throw new BunWorkspacesError(
|
|
11
|
+
`Invalid output style: "${style}" (accepted values: ${OUTPUT_STYLE_VALUES.join(", ")})`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return style;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { OUTPUT_STYLE_VALUES, getDefaultOutputStyle, validateOutputStyle };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type TypedEvent,
|
|
3
|
+
TypedEventTarget,
|
|
4
|
+
} from "../../../../internal/core/language/events/typedEventTarget";
|
|
5
|
+
import type {
|
|
6
|
+
RunScriptAcrossWorkspacesOutput,
|
|
7
|
+
RunWorkspaceScriptMetadata,
|
|
8
|
+
} from "../../../../project";
|
|
9
|
+
import type {
|
|
10
|
+
RunScriptExit,
|
|
11
|
+
RunScriptsSummary,
|
|
12
|
+
ScriptEventName,
|
|
13
|
+
} from "../../../../runScript";
|
|
14
|
+
import type { Workspace } from "../../../../workspaces";
|
|
15
|
+
import type { WriteOutputOptions } from "../../../createCli";
|
|
16
|
+
type ScriptEvent = TypedEvent<
|
|
17
|
+
ScriptEventName,
|
|
18
|
+
{
|
|
19
|
+
workspace: Workspace;
|
|
20
|
+
exitResult: RunScriptExit<RunWorkspaceScriptMetadata> | null;
|
|
21
|
+
}
|
|
22
|
+
>;
|
|
23
|
+
declare class ScriptEventTarget extends TypedEventTarget<{
|
|
24
|
+
[key in ScriptEvent["type"]]: ScriptEvent;
|
|
25
|
+
}> {}
|
|
26
|
+
export declare const createScriptEventTarget: () => ScriptEventTarget;
|
|
27
|
+
export declare const createScriptEvent: {
|
|
28
|
+
start: (
|
|
29
|
+
properties: Omit<
|
|
30
|
+
{
|
|
31
|
+
type: ScriptEventName;
|
|
32
|
+
} & {
|
|
33
|
+
workspace: Workspace;
|
|
34
|
+
exitResult: RunScriptExit<RunWorkspaceScriptMetadata> | null;
|
|
35
|
+
},
|
|
36
|
+
"type"
|
|
37
|
+
>,
|
|
38
|
+
options?: EventInit,
|
|
39
|
+
) => ScriptEvent;
|
|
40
|
+
skip: (
|
|
41
|
+
properties: Omit<
|
|
42
|
+
{
|
|
43
|
+
type: ScriptEventName;
|
|
44
|
+
} & {
|
|
45
|
+
workspace: Workspace;
|
|
46
|
+
exitResult: RunScriptExit<RunWorkspaceScriptMetadata> | null;
|
|
47
|
+
},
|
|
48
|
+
"type"
|
|
49
|
+
>,
|
|
50
|
+
options?: EventInit,
|
|
51
|
+
) => ScriptEvent;
|
|
52
|
+
exit: (
|
|
53
|
+
properties: Omit<
|
|
54
|
+
{
|
|
55
|
+
type: ScriptEventName;
|
|
56
|
+
} & {
|
|
57
|
+
workspace: Workspace;
|
|
58
|
+
exitResult: RunScriptExit<RunWorkspaceScriptMetadata> | null;
|
|
59
|
+
},
|
|
60
|
+
"type"
|
|
61
|
+
>,
|
|
62
|
+
options?: EventInit,
|
|
63
|
+
) => ScriptEvent;
|
|
64
|
+
};
|
|
65
|
+
export declare const renderGroupedOutput: (
|
|
66
|
+
workspaces: Workspace[],
|
|
67
|
+
output: RunScriptAcrossWorkspacesOutput,
|
|
68
|
+
summary: Promise<RunScriptsSummary<RunWorkspaceScriptMetadata>>,
|
|
69
|
+
scriptEventTarget: ScriptEventTarget,
|
|
70
|
+
activeScriptLines: number | "all",
|
|
71
|
+
outputWriters: Required<WriteOutputOptions>,
|
|
72
|
+
) => Promise<void>;
|
|
73
|
+
export {};
|