bun-workspaces 1.0.0-alpha.3 → 1.0.0-alpha.30
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 +131 -77
- package/bin/cli.js +1 -2
- package/package.json +24 -30
- package/src/cli/commands/commandHandlerUtils.d.ts +41 -0
- package/src/cli/commands/commandHandlerUtils.mjs +59 -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 +312 -0
- package/src/cli/commands/commandsConfig.mjs +155 -0
- package/src/cli/commands/handleRunScript.d.ts +3 -0
- package/src/cli/commands/handleRunScript.mjs +217 -0
- package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
- package/src/cli/commands/handleSimpleCommands.mjs +170 -0
- package/src/cli/commands/index.d.ts +2 -0
- package/src/cli/commands/index.mjs +2 -0
- package/src/cli/createCli.d.ts +19 -0
- package/src/cli/createCli.mjs +113 -0
- package/src/cli/fatalErrorLogger.d.ts +1 -0
- package/src/cli/fatalErrorLogger.mjs +7 -0
- package/src/cli/globalOptions/globalOptions.d.ts +38 -0
- package/src/cli/globalOptions/globalOptions.mjs +120 -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/config/bunWorkspacesConfig.d.ts +17 -0
- package/src/config/bunWorkspacesConfig.mjs +50 -0
- package/src/config/configFile.d.ts +8 -0
- package/src/config/configFile.mjs +43 -0
- package/src/config/errors.d.ts +3 -0
- package/src/config/errors.mjs +10 -0
- package/src/config/{index.ts → index.d.ts} +1 -0
- package/src/config/index.mjs +11 -0
- package/src/config/userEnvVars.d.ts +9 -0
- package/src/config/userEnvVars.mjs +9 -0
- package/src/config/workspaceConfig/errors.d.ts +3 -0
- package/src/config/workspaceConfig/errors.mjs +9 -0
- package/src/config/workspaceConfig/index.d.ts +4 -0
- package/src/config/workspaceConfig/index.mjs +4 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +5 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +82 -0
- package/src/config/workspaceConfig/workspaceConfig.d.ts +25 -0
- package/src/config/workspaceConfig/workspaceConfig.mjs +80 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -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 +31 -0
- package/src/index.mjs +9 -0
- package/src/internal/bun/bunLock.d.ts +20 -0
- package/src/internal/bun/bunLock.mjs +72 -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/asyncIterable/asyncIterableQueue.d.ts +15 -0
- package/src/internal/core/asyncIterable/asyncIterableQueue.mjs +73 -0
- package/src/internal/core/asyncIterable/mergeAsyncIterables.d.ts +5 -0
- package/src/internal/core/asyncIterable/mergeAsyncIterables.mjs +27 -0
- package/src/internal/core/error.d.ts +9 -0
- package/src/internal/{error.ts → core/error.mjs} +7 -16
- package/src/internal/core/index.d.ts +7 -0
- package/src/internal/core/index.mjs +6 -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 +9 -0
- package/src/internal/core/json/json.mjs +6 -0
- package/src/internal/core/json/jsonc.d.ts +9 -0
- package/src/internal/core/json/jsonc.mjs +117 -0
- package/src/internal/core/optionalArray.d.ts +15 -0
- package/src/internal/core/optionalArray.mjs +8 -0
- package/src/internal/core/regex.d.ts +3 -0
- package/src/internal/core/regex.mjs +10 -0
- package/src/internal/core/types.d.ts +6 -0
- package/src/internal/core/types.mjs +3 -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 +44 -0
- package/src/internal/logger/logger.mjs +110 -0
- package/src/internal/runtime/env.d.ts +5 -0
- package/src/internal/runtime/env.mjs +29 -0
- package/src/internal/runtime/index.d.ts +2 -0
- package/src/internal/runtime/index.mjs +2 -0
- package/src/internal/runtime/onExit.d.ts +6 -0
- package/src/internal/runtime/onExit.mjs +24 -0
- package/src/internal/runtime/os.d.ts +4 -0
- package/src/internal/runtime/os.mjs +7 -0
- package/src/internal/runtime/tempFile.d.ts +16 -0
- package/src/internal/runtime/tempFile.mjs +50 -0
- package/src/project/errors.d.ts +3 -0
- package/src/project/errors.mjs +9 -0
- package/src/project/implementations/fileSystemProject.d.ts +106 -0
- package/src/project/implementations/fileSystemProject.mjs +227 -0
- package/src/project/implementations/memoryProject.d.ts +32 -0
- package/src/project/implementations/memoryProject.mjs +46 -0
- package/src/project/implementations/projectBase.d.ts +28 -0
- package/src/project/implementations/projectBase.mjs +117 -0
- package/src/project/index.d.ts +5 -0
- package/src/project/index.mjs +4 -0
- package/src/project/project.d.ts +64 -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/outputChunk.d.ts +22 -0
- package/src/runScript/outputChunk.mjs +30 -0
- package/src/runScript/parallel.d.ts +12 -0
- package/src/runScript/parallel.mjs +52 -0
- package/src/runScript/runScript.d.ts +37 -0
- package/src/runScript/runScript.mjs +60 -0
- package/src/runScript/runScripts.d.ts +48 -0
- package/src/runScript/runScripts.mjs +124 -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 +51 -0
- package/src/runScript/scriptRuntimeMetadata.d.ts +75 -0
- package/src/runScript/scriptRuntimeMetadata.mjs +62 -0
- package/src/runScript/scriptShellOption.d.ts +7 -0
- package/src/runScript/scriptShellOption.mjs +36 -0
- package/src/workspaces/errors.d.ts +12 -0
- package/src/workspaces/{errors.ts → errors.mjs} +5 -2
- package/src/workspaces/findWorkspaces.d.ts +22 -0
- package/src/workspaces/findWorkspaces.mjs +168 -0
- package/src/workspaces/index.d.ts +4 -0
- package/src/workspaces/index.mjs +3 -0
- package/src/workspaces/packageJson.d.ts +15 -0
- package/src/workspaces/packageJson.mjs +135 -0
- package/src/workspaces/{workspace.ts → workspace.d.ts} +5 -6
- package/src/workspaces/workspace.mjs +2 -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 -390
- package/src/config/bunWorkspacesConfig.ts +0 -62
- package/src/config/configFile.ts +0 -33
- 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 -180
- 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/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,15 @@
|
|
|
1
|
+
export declare const doctor: (
|
|
2
|
+
context: import("./commandHandlerUtils").GlobalCommandContext,
|
|
3
|
+
) => import("commander").Command;
|
|
4
|
+
export declare const listWorkspaces: (
|
|
5
|
+
context: import("./commandHandlerUtils").ProjectCommandContext,
|
|
6
|
+
) => import("commander").Command;
|
|
7
|
+
export declare const listScripts: (
|
|
8
|
+
context: import("./commandHandlerUtils").ProjectCommandContext,
|
|
9
|
+
) => import("commander").Command;
|
|
10
|
+
export declare const workspaceInfo: (
|
|
11
|
+
context: import("./commandHandlerUtils").ProjectCommandContext,
|
|
12
|
+
) => import("commander").Command;
|
|
13
|
+
export declare const scriptInfo: (
|
|
14
|
+
context: import("./commandHandlerUtils").ProjectCommandContext,
|
|
15
|
+
) => import("commander").Command;
|
|
@@ -0,0 +1,170 @@
|
|
|
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 {
|
|
5
|
+
commandOutputLogger,
|
|
6
|
+
createJsonLines,
|
|
7
|
+
createScriptInfoLines,
|
|
8
|
+
createWorkspaceInfoLines,
|
|
9
|
+
handleGlobalCommand,
|
|
10
|
+
handleProjectCommand,
|
|
11
|
+
} from "./commandHandlerUtils.mjs"; // CONCATENATED MODULE: external "../../doctor/index.mjs"
|
|
12
|
+
// CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
13
|
+
// CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
14
|
+
// CONCATENATED MODULE: external "./commandHandlerUtils.mjs"
|
|
15
|
+
// CONCATENATED MODULE: ./src/cli/commands/handleSimpleCommands.ts
|
|
16
|
+
|
|
17
|
+
const doctor = handleGlobalCommand("doctor", (_, options) => {
|
|
18
|
+
const info = getDoctorInfo();
|
|
19
|
+
if (options.json) {
|
|
20
|
+
commandOutputLogger.info(
|
|
21
|
+
JSON.stringify(info, null, options.pretty ? 2 : undefined),
|
|
22
|
+
);
|
|
23
|
+
} else {
|
|
24
|
+
const createEntryLine = ([key, value]) => {
|
|
25
|
+
const keyName = (
|
|
26
|
+
key[0].toUpperCase() + key.slice(1).replace(/([A-Z])/g, " $1")
|
|
27
|
+
).replace(/os|cpu/gi, (m) => m.toUpperCase());
|
|
28
|
+
return isJsonObject(value)
|
|
29
|
+
? keyName +
|
|
30
|
+
":\n - " +
|
|
31
|
+
Object.entries(value).map(createEntryLine).join("\n - ")
|
|
32
|
+
: `${keyName}: ${value}`;
|
|
33
|
+
};
|
|
34
|
+
commandOutputLogger.info(
|
|
35
|
+
"bun-workspaces\n" + Object.entries(info).map(createEntryLine).join("\n"),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const listWorkspaces = handleProjectCommand(
|
|
40
|
+
"listWorkspaces",
|
|
41
|
+
({ project }, workspacePatterns, options) => {
|
|
42
|
+
logger.debug(
|
|
43
|
+
`Command: List workspaces (options: ${JSON.stringify(options)})`,
|
|
44
|
+
);
|
|
45
|
+
const lines = [];
|
|
46
|
+
if (workspacePatterns?.length && options.workspacePatterns?.length) {
|
|
47
|
+
logger.error(
|
|
48
|
+
"CLI syntax error: Cannot use both inline workspace patterns and --workspace-patterns|-W option",
|
|
49
|
+
);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
const patterns = workspacePatterns?.length
|
|
53
|
+
? workspacePatterns
|
|
54
|
+
: options.workspacePatterns?.split(",");
|
|
55
|
+
const workspaces = patterns?.length
|
|
56
|
+
? project.findWorkspacesByPattern(...patterns)
|
|
57
|
+
: project.workspaces;
|
|
58
|
+
if (options.json) {
|
|
59
|
+
lines.push(
|
|
60
|
+
...createJsonLines(
|
|
61
|
+
options.nameOnly ? workspaces.map(({ name }) => name) : workspaces,
|
|
62
|
+
options,
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
} else {
|
|
66
|
+
workspaces.forEach((workspace) => {
|
|
67
|
+
if (options.nameOnly) {
|
|
68
|
+
lines.push(workspace.name);
|
|
69
|
+
} else {
|
|
70
|
+
lines.push(...createWorkspaceInfoLines(workspace));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (!lines.length && !options.nameOnly) {
|
|
75
|
+
logger.info("No workspaces found");
|
|
76
|
+
}
|
|
77
|
+
if (lines.length) commandOutputLogger.info(lines.join("\n"));
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
const listScripts = handleProjectCommand(
|
|
81
|
+
"listScripts",
|
|
82
|
+
({ project }, options) => {
|
|
83
|
+
logger.debug(`Command: List scripts (options: ${JSON.stringify(options)})`);
|
|
84
|
+
const scripts = project.mapScriptsToWorkspaces();
|
|
85
|
+
const lines = [];
|
|
86
|
+
if (!project.workspaces.length && !options.nameOnly) {
|
|
87
|
+
logger.info("No workspaces found");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!Object.keys(scripts).length && !options.nameOnly) {
|
|
91
|
+
logger.info("No scripts found");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (options.json) {
|
|
95
|
+
lines.push(
|
|
96
|
+
...createJsonLines(
|
|
97
|
+
options.nameOnly
|
|
98
|
+
? Object.keys(scripts)
|
|
99
|
+
: Object.values(scripts).map(({ workspaces, ...rest }) => ({
|
|
100
|
+
...rest,
|
|
101
|
+
workspaces: workspaces.map(({ name }) => name),
|
|
102
|
+
})),
|
|
103
|
+
options,
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
} else {
|
|
107
|
+
Object.values(scripts)
|
|
108
|
+
.sort(({ name: nameA }, { name: nameB }) => nameA.localeCompare(nameB))
|
|
109
|
+
.forEach(({ name, workspaces }) => {
|
|
110
|
+
if (options.nameOnly) {
|
|
111
|
+
lines.push(name);
|
|
112
|
+
} else {
|
|
113
|
+
lines.push(...createScriptInfoLines(name, workspaces));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (lines.length) commandOutputLogger.info(lines.join("\n"));
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
const workspaceInfo = handleProjectCommand(
|
|
121
|
+
"workspaceInfo",
|
|
122
|
+
({ project }, workspaceName, options) => {
|
|
123
|
+
logger.debug(
|
|
124
|
+
`Command: Workspace info for ${workspaceName} (options: ${JSON.stringify(options)})`,
|
|
125
|
+
);
|
|
126
|
+
const workspace = project.findWorkspaceByNameOrAlias(workspaceName);
|
|
127
|
+
if (!workspace) {
|
|
128
|
+
logger.error(`Workspace ${JSON.stringify(workspaceName)} not found`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
commandOutputLogger.info(
|
|
132
|
+
(options.json
|
|
133
|
+
? createJsonLines(workspace, options)
|
|
134
|
+
: createWorkspaceInfoLines(workspace)
|
|
135
|
+
).join("\n"),
|
|
136
|
+
);
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
const scriptInfo = handleProjectCommand(
|
|
140
|
+
"scriptInfo",
|
|
141
|
+
({ project }, script, options) => {
|
|
142
|
+
logger.debug(
|
|
143
|
+
`Command: Script info for ${script} (options: ${JSON.stringify(options)})`,
|
|
144
|
+
);
|
|
145
|
+
const scripts = project.mapScriptsToWorkspaces();
|
|
146
|
+
const scriptMetadata = scripts[script];
|
|
147
|
+
if (!scriptMetadata) {
|
|
148
|
+
logger.error(`Script not found: ${JSON.stringify(script)}`);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
commandOutputLogger.info(
|
|
152
|
+
(options.json
|
|
153
|
+
? createJsonLines(
|
|
154
|
+
options.workspacesOnly
|
|
155
|
+
? scriptMetadata.workspaces.map(({ name }) => name)
|
|
156
|
+
: {
|
|
157
|
+
name: scriptMetadata.name,
|
|
158
|
+
workspaces: scriptMetadata.workspaces.map(({ name }) => name),
|
|
159
|
+
},
|
|
160
|
+
options,
|
|
161
|
+
)
|
|
162
|
+
: options.workspacesOnly
|
|
163
|
+
? scriptMetadata.workspaces.map(({ name }) => name)
|
|
164
|
+
: createScriptInfoLines(script, scriptMetadata.workspaces)
|
|
165
|
+
).join("\n"),
|
|
166
|
+
);
|
|
167
|
+
},
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
export { doctor, listScripts, listWorkspaces, scriptInfo, workspaceInfo };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Command } from "commander";
|
|
2
|
+
export interface RunCliOptions {
|
|
3
|
+
argv?: string | string[];
|
|
4
|
+
/** Should be `true` if args do not include the binary name (e.g. `bunx bun-workspaces`) */
|
|
5
|
+
programmatic?: true;
|
|
6
|
+
}
|
|
7
|
+
export interface CLI {
|
|
8
|
+
run: (options?: RunCliOptions) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export interface CreateCliOptions {
|
|
11
|
+
handleError?: (error: Error) => void;
|
|
12
|
+
postInit?: (program: Command) => unknown;
|
|
13
|
+
defaultCwd?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const createCli: ({
|
|
16
|
+
handleError,
|
|
17
|
+
postInit,
|
|
18
|
+
defaultCwd,
|
|
19
|
+
}?: CreateCliOptions) => CLI;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createCommand } from "commander";
|
|
2
|
+
import package_0 from "../../package.json";
|
|
3
|
+
import { validateCurrentBunVersion } from "../internal/bun/index.mjs";
|
|
4
|
+
import { BunWorkspacesError } from "../internal/core/index.mjs";
|
|
5
|
+
import { logger } from "../internal/logger/index.mjs";
|
|
6
|
+
import {
|
|
7
|
+
defineGlobalCommands,
|
|
8
|
+
defineProjectCommands,
|
|
9
|
+
} from "./commands/index.mjs";
|
|
10
|
+
import { fatalErrorLogger } from "./fatalErrorLogger.mjs";
|
|
11
|
+
import { initializeWithGlobalOptions } from "./globalOptions/index.mjs"; // CONCATENATED MODULE: external "commander"
|
|
12
|
+
// CONCATENATED MODULE: external "../../package.json"
|
|
13
|
+
// CONCATENATED MODULE: external "../internal/bun/index.mjs"
|
|
14
|
+
// CONCATENATED MODULE: external "../internal/core/index.mjs"
|
|
15
|
+
// CONCATENATED MODULE: external "../internal/logger/index.mjs"
|
|
16
|
+
// CONCATENATED MODULE: external "./commands/index.mjs"
|
|
17
|
+
// CONCATENATED MODULE: external "./fatalErrorLogger.mjs"
|
|
18
|
+
// CONCATENATED MODULE: external "./globalOptions/index.mjs"
|
|
19
|
+
// CONCATENATED MODULE: ./src/cli/createCli.ts
|
|
20
|
+
|
|
21
|
+
const createCli = ({
|
|
22
|
+
handleError,
|
|
23
|
+
postInit,
|
|
24
|
+
defaultCwd = process.cwd(),
|
|
25
|
+
} = {}) => {
|
|
26
|
+
const run = async ({ argv = process.argv, programmatic } = {}) => {
|
|
27
|
+
const errorListener =
|
|
28
|
+
handleError ??
|
|
29
|
+
((error) => {
|
|
30
|
+
fatalErrorLogger.error(error);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
});
|
|
33
|
+
process.on("unhandledRejection", errorListener);
|
|
34
|
+
try {
|
|
35
|
+
const program = createCommand("bun-workspaces")
|
|
36
|
+
.description("A CLI on top of native Bun workspaces")
|
|
37
|
+
.version(package_0.version)
|
|
38
|
+
.showHelpAfterError(true);
|
|
39
|
+
postInit?.(program);
|
|
40
|
+
const rawArgs = tempFixCamelCaseOptions(
|
|
41
|
+
typeof argv === "string" ? argv.split(/s+/) : argv,
|
|
42
|
+
);
|
|
43
|
+
const { args, postTerminatorArgs } = (() => {
|
|
44
|
+
const terminatorIndex = rawArgs.findIndex((arg) => arg === "--");
|
|
45
|
+
return {
|
|
46
|
+
args:
|
|
47
|
+
terminatorIndex !== -1
|
|
48
|
+
? rawArgs.slice(0, terminatorIndex)
|
|
49
|
+
: rawArgs,
|
|
50
|
+
postTerminatorArgs:
|
|
51
|
+
terminatorIndex !== -1 ? rawArgs.slice(terminatorIndex + 1) : [],
|
|
52
|
+
};
|
|
53
|
+
})();
|
|
54
|
+
const { project, projectError } = initializeWithGlobalOptions(
|
|
55
|
+
program,
|
|
56
|
+
args,
|
|
57
|
+
defaultCwd,
|
|
58
|
+
);
|
|
59
|
+
const bunVersionError = validateCurrentBunVersion();
|
|
60
|
+
if (bunVersionError) {
|
|
61
|
+
fatalErrorLogger.error(bunVersionError.message);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
defineProjectCommands({
|
|
65
|
+
program,
|
|
66
|
+
project,
|
|
67
|
+
projectError,
|
|
68
|
+
postTerminatorArgs,
|
|
69
|
+
});
|
|
70
|
+
defineGlobalCommands({
|
|
71
|
+
program,
|
|
72
|
+
postTerminatorArgs,
|
|
73
|
+
});
|
|
74
|
+
await program.parseAsync(args, {
|
|
75
|
+
from: programmatic ? "user" : "node",
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof BunWorkspacesError) {
|
|
79
|
+
logger.debug(error);
|
|
80
|
+
fatalErrorLogger.error(error.message);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
} else {
|
|
83
|
+
errorListener(error);
|
|
84
|
+
}
|
|
85
|
+
} finally {
|
|
86
|
+
process.off("unhandledRejection", errorListener);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
run,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* @todo
|
|
95
|
+
* ! Temp backwards support for deprecated camel case options
|
|
96
|
+
* ! Added October 2025, drop support in some reasonable future release
|
|
97
|
+
*/ const tempOptions = {
|
|
98
|
+
"--nameOnly": "--name-only",
|
|
99
|
+
"--noPrefix": "--no-prefix",
|
|
100
|
+
"--configFile": "--config-file",
|
|
101
|
+
"--logLevel": "--log-level",
|
|
102
|
+
};
|
|
103
|
+
const tempFixCamelCaseOptions = (args) =>
|
|
104
|
+
args.map((arg) => {
|
|
105
|
+
for (const [camel, kebab] of Object.entries(tempOptions)) {
|
|
106
|
+
if (arg.startsWith(camel)) {
|
|
107
|
+
return arg.replace(camel, kebab);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return arg;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export { createCli };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fatalErrorLogger: import("../internal/logger").Logger;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createLogger } from "../internal/logger/index.mjs"; // CONCATENATED MODULE: external "../internal/logger/index.mjs"
|
|
2
|
+
// CONCATENATED MODULE: ./src/cli/fatalErrorLogger.ts
|
|
3
|
+
|
|
4
|
+
const fatalErrorLogger = createLogger("fatalError");
|
|
5
|
+
fatalErrorLogger.printLevel = "error";
|
|
6
|
+
|
|
7
|
+
export { fatalErrorLogger };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Command } from "commander";
|
|
2
|
+
export declare const initializeWithGlobalOptions: (
|
|
3
|
+
program: Command,
|
|
4
|
+
args: string[],
|
|
5
|
+
defaultCwd: string,
|
|
6
|
+
) => {
|
|
7
|
+
project: import("../../internal/core").Simplify<{
|
|
8
|
+
readonly rootDirectory: string;
|
|
9
|
+
readonly workspaces: import("../..").Workspace[];
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly sourceType: "fileSystem";
|
|
12
|
+
runWorkspaceScript(
|
|
13
|
+
options: import("../..").RunWorkspaceScriptOptions,
|
|
14
|
+
): import("../..").RunWorkspaceScriptResult;
|
|
15
|
+
runScriptAcrossWorkspaces(
|
|
16
|
+
options: import("../..").RunScriptAcrossWorkspacesOptions,
|
|
17
|
+
): import("../..").RunScriptAcrossWorkspacesResult;
|
|
18
|
+
listWorkspacesWithScript(scriptName: string): import("../..").Workspace[];
|
|
19
|
+
mapScriptsToWorkspaces(): Record<
|
|
20
|
+
string,
|
|
21
|
+
import("../..").WorkspaceScriptMetadata
|
|
22
|
+
>;
|
|
23
|
+
findWorkspaceByName(
|
|
24
|
+
workspaceName: string,
|
|
25
|
+
): import("../..").Workspace | null;
|
|
26
|
+
findWorkspaceByAlias(alias: string): import("../..").Workspace | null;
|
|
27
|
+
findWorkspaceByNameOrAlias(
|
|
28
|
+
nameOrAlias: string,
|
|
29
|
+
): import("../..").Workspace | null;
|
|
30
|
+
findWorkspacesByPattern(
|
|
31
|
+
...workspacePatterns: string[]
|
|
32
|
+
): import("../..").Workspace[];
|
|
33
|
+
createScriptCommand(
|
|
34
|
+
options: import("../..").CreateProjectScriptCommandOptions,
|
|
35
|
+
): import("../..").CreateProjectScriptCommandResult;
|
|
36
|
+
}>;
|
|
37
|
+
projectError: Error | null;
|
|
38
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { Option } from "commander";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_CONFIG_FILE_PATH,
|
|
6
|
+
loadConfigFile,
|
|
7
|
+
} from "../../config/index.mjs";
|
|
8
|
+
import { defineErrors } from "../../internal/core/index.mjs";
|
|
9
|
+
import { logger } from "../../internal/logger/index.mjs";
|
|
10
|
+
import {
|
|
11
|
+
_internalCreateFileSystemProject,
|
|
12
|
+
createMemoryProject,
|
|
13
|
+
} from "../../project/index.mjs";
|
|
14
|
+
import { getCliGlobalOptionConfig } from "./globalOptionsConfig.mjs"; // CONCATENATED MODULE: external "node:fs"
|
|
15
|
+
// CONCATENATED MODULE: external "node:path"
|
|
16
|
+
// CONCATENATED MODULE: external "commander"
|
|
17
|
+
// CONCATENATED MODULE: external "../../config/index.mjs"
|
|
18
|
+
// CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
19
|
+
// CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
20
|
+
// CONCATENATED MODULE: external "../../project/index.mjs"
|
|
21
|
+
// CONCATENATED MODULE: external "./globalOptionsConfig.mjs"
|
|
22
|
+
// CONCATENATED MODULE: ./src/cli/globalOptions/globalOptions.ts
|
|
23
|
+
|
|
24
|
+
const ERRORS = defineErrors(
|
|
25
|
+
"WorkingDirectoryNotFound",
|
|
26
|
+
"WorkingDirectoryNotADirectory",
|
|
27
|
+
);
|
|
28
|
+
const addGlobalOption = (program, optionName, defaultOverride) => {
|
|
29
|
+
const { mainOption, shortOption, description, param, values, defaultValue } =
|
|
30
|
+
getCliGlobalOptionConfig(optionName);
|
|
31
|
+
let option = new Option(
|
|
32
|
+
`${shortOption} ${mainOption}${param ? ` <${param}>` : ""}`,
|
|
33
|
+
description,
|
|
34
|
+
);
|
|
35
|
+
const effectiveDefaultValue = defaultOverride ?? defaultValue;
|
|
36
|
+
if (effectiveDefaultValue) {
|
|
37
|
+
option = option.default(effectiveDefaultValue);
|
|
38
|
+
}
|
|
39
|
+
if (values?.length) {
|
|
40
|
+
option = option.choices(values);
|
|
41
|
+
}
|
|
42
|
+
program.addOption(option);
|
|
43
|
+
};
|
|
44
|
+
const getWorkingDirectoryFromArgs = (program, args, defaultCwd) => {
|
|
45
|
+
addGlobalOption(program, "cwd", defaultCwd);
|
|
46
|
+
program.parseOptions(args);
|
|
47
|
+
return program.opts().cwd;
|
|
48
|
+
};
|
|
49
|
+
const getConfigFileFromArgs = (program, args) => {
|
|
50
|
+
addGlobalOption(program, "configFile");
|
|
51
|
+
program.parseOptions(args);
|
|
52
|
+
return program.opts().configFile;
|
|
53
|
+
};
|
|
54
|
+
const defineGlobalOptions = (program, args, defaultCwd) => {
|
|
55
|
+
const cwd = getWorkingDirectoryFromArgs(program, args, defaultCwd);
|
|
56
|
+
if (!node_fs.existsSync(cwd)) {
|
|
57
|
+
throw new ERRORS.WorkingDirectoryNotFound(
|
|
58
|
+
`Working directory not found at path "${cwd}"`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (!node_fs.statSync(cwd).isDirectory()) {
|
|
62
|
+
throw new ERRORS.WorkingDirectoryNotADirectory(
|
|
63
|
+
`Working directory is not a directory at path "${cwd}"`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const configFilePath = getConfigFileFromArgs(program, args);
|
|
67
|
+
const config = loadConfigFile(configFilePath, cwd);
|
|
68
|
+
if (config) {
|
|
69
|
+
logger.warn(
|
|
70
|
+
// TODO link to docs
|
|
71
|
+
`Using the config file at ${configFilePath || DEFAULT_CONFIG_FILE_PATH} is deprecated. Migrate to the new workspace config file.`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
addGlobalOption(program, "logLevel");
|
|
75
|
+
return {
|
|
76
|
+
cwd,
|
|
77
|
+
config,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const applyGlobalOptions = (options, config) => {
|
|
81
|
+
logger.printLevel = options.logLevel;
|
|
82
|
+
logger.debug("Log level: " + options.logLevel);
|
|
83
|
+
let project;
|
|
84
|
+
let error = null;
|
|
85
|
+
try {
|
|
86
|
+
project = _internalCreateFileSystemProject({
|
|
87
|
+
rootDirectory: options.cwd,
|
|
88
|
+
workspaceAliases: config?.project?.workspaceAliases ?? {},
|
|
89
|
+
});
|
|
90
|
+
logger.debug(
|
|
91
|
+
`Project: ${JSON.stringify(project.name)} (${project.workspaces.length} workspace${project.workspaces.length === 1 ? "" : "s"})`,
|
|
92
|
+
);
|
|
93
|
+
logger.debug("Project root: " + node_path.resolve(project.rootDirectory));
|
|
94
|
+
} catch (_error) {
|
|
95
|
+
error = _error;
|
|
96
|
+
project = createMemoryProject({
|
|
97
|
+
workspaces: [],
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
project,
|
|
102
|
+
projectError: error,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const initializeWithGlobalOptions = (program, args, defaultCwd) => {
|
|
106
|
+
program.allowUnknownOption(true);
|
|
107
|
+
const { cwd, config } = defineGlobalOptions(program, args, defaultCwd);
|
|
108
|
+
program.parseOptions(args);
|
|
109
|
+
program.allowUnknownOption(false);
|
|
110
|
+
const options = program.opts();
|
|
111
|
+
return applyGlobalOptions(
|
|
112
|
+
{
|
|
113
|
+
...options,
|
|
114
|
+
cwd,
|
|
115
|
+
},
|
|
116
|
+
config,
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export { initializeWithGlobalOptions };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type LogLevelSetting } from "../../internal/logger";
|
|
2
|
+
export interface CliGlobalOptions {
|
|
3
|
+
logLevel: LogLevelSetting;
|
|
4
|
+
cwd: string;
|
|
5
|
+
configFile?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CliGlobalOptionConfig {
|
|
8
|
+
mainOption: string;
|
|
9
|
+
shortOption: string;
|
|
10
|
+
description: string;
|
|
11
|
+
defaultValue: string;
|
|
12
|
+
values: LogLevelSetting[] | null;
|
|
13
|
+
param: string;
|
|
14
|
+
}
|
|
15
|
+
export type CliGlobalOptionName = keyof CliGlobalOptions;
|
|
16
|
+
export declare const getCliGlobalOptionConfig: (
|
|
17
|
+
optionName: CliGlobalOptionName,
|
|
18
|
+
) =>
|
|
19
|
+
| {
|
|
20
|
+
readonly mainOption: "--log-level";
|
|
21
|
+
readonly shortOption: "-l";
|
|
22
|
+
readonly description: "Log levels";
|
|
23
|
+
readonly defaultValue: "info";
|
|
24
|
+
readonly values: ["debug", "info", "warn", "error", "silent"];
|
|
25
|
+
readonly param: "level";
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
readonly mainOption: "--cwd";
|
|
29
|
+
readonly shortOption: "-d";
|
|
30
|
+
readonly description: "Working directory";
|
|
31
|
+
readonly defaultValue: ".";
|
|
32
|
+
readonly values: null;
|
|
33
|
+
readonly param: "path";
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
readonly mainOption: "--config-file";
|
|
37
|
+
readonly shortOption: "-c";
|
|
38
|
+
readonly description: "(DEPRECATED) Config file";
|
|
39
|
+
readonly defaultValue: "";
|
|
40
|
+
readonly values: null;
|
|
41
|
+
readonly param: "path";
|
|
42
|
+
};
|
|
43
|
+
export declare const getCliGlobalOptionNames: () => CliGlobalOptionName[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LOG_LEVELS } from "../../internal/logger/index.mjs"; // CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
2
|
+
// CONCATENATED MODULE: ./src/cli/globalOptions/globalOptionsConfig.ts
|
|
3
|
+
|
|
4
|
+
const CLI_GLOBAL_OPTIONS_CONFIG = {
|
|
5
|
+
logLevel: {
|
|
6
|
+
mainOption: "--log-level",
|
|
7
|
+
shortOption: "-l",
|
|
8
|
+
description: "Log levels",
|
|
9
|
+
defaultValue: "info",
|
|
10
|
+
values: [...LOG_LEVELS, "silent"],
|
|
11
|
+
param: "level",
|
|
12
|
+
},
|
|
13
|
+
cwd: {
|
|
14
|
+
mainOption: "--cwd",
|
|
15
|
+
shortOption: "-d",
|
|
16
|
+
description: "Working directory",
|
|
17
|
+
defaultValue: ".",
|
|
18
|
+
values: null,
|
|
19
|
+
param: "path",
|
|
20
|
+
},
|
|
21
|
+
configFile: {
|
|
22
|
+
mainOption: "--config-file",
|
|
23
|
+
shortOption: "-c",
|
|
24
|
+
description: "(DEPRECATED) Config file",
|
|
25
|
+
defaultValue: "",
|
|
26
|
+
values: null,
|
|
27
|
+
param: "path",
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const getCliGlobalOptionConfig = (optionName) =>
|
|
31
|
+
CLI_GLOBAL_OPTIONS_CONFIG[optionName];
|
|
32
|
+
const getCliGlobalOptionNames = () => Object.keys(CLI_GLOBAL_OPTIONS_CONFIG);
|
|
33
|
+
|
|
34
|
+
export { getCliGlobalOptionConfig, getCliGlobalOptionNames };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type LogLevelSetting } from "../internal/logger";
|
|
2
|
+
export interface CliConfig {
|
|
3
|
+
logLevel?: LogLevelSetting;
|
|
4
|
+
}
|
|
5
|
+
export interface ProjectConfig {
|
|
6
|
+
/** @deprecated A map of aliases to a workspace name */
|
|
7
|
+
workspaceAliases?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
/** @deprecated */
|
|
10
|
+
export interface BunWorkspacesConfig {
|
|
11
|
+
cli?: CliConfig;
|
|
12
|
+
project?: ProjectConfig;
|
|
13
|
+
}
|
|
14
|
+
/** @deprecated */
|
|
15
|
+
export declare const validateBunWorkspacesConfig: (
|
|
16
|
+
config: BunWorkspacesConfig,
|
|
17
|
+
) => void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { validateLogLevel } from "../internal/logger/index.mjs";
|
|
2
|
+
import { ERRORS } from "./errors.mjs"; // CONCATENATED MODULE: external "../internal/logger/index.mjs"
|
|
3
|
+
// CONCATENATED MODULE: external "./errors.mjs"
|
|
4
|
+
// CONCATENATED MODULE: ./src/config/bunWorkspacesConfig.ts
|
|
5
|
+
|
|
6
|
+
const isJsonObject = (value) => {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
};
|
|
9
|
+
const validateCliConfig = (cliConfig) => {
|
|
10
|
+
if (!isJsonObject(cliConfig)) {
|
|
11
|
+
throw new ERRORS.InvalidConfigFile(`Config file: "cli" must be an object`);
|
|
12
|
+
}
|
|
13
|
+
if (cliConfig?.logLevel) {
|
|
14
|
+
validateLogLevel(cliConfig.logLevel);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const validateProjectConfig = (projectConfig) => {
|
|
18
|
+
if (!isJsonObject(projectConfig)) {
|
|
19
|
+
throw new ERRORS.InvalidConfigFile(
|
|
20
|
+
`Config file: "project" must be an object`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if (projectConfig?.workspaceAliases !== undefined) {
|
|
24
|
+
if (!isJsonObject(projectConfig.workspaceAliases)) {
|
|
25
|
+
throw new ERRORS.InvalidConfigFile(
|
|
26
|
+
`Config file: project.workspaceAliases must be an object`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
for (const alias of Object.values(projectConfig.workspaceAliases)) {
|
|
30
|
+
if (typeof alias !== "string") {
|
|
31
|
+
throw new ERRORS.InvalidConfigFile(
|
|
32
|
+
`Config file: project.workspaceAliases must be an object with string keys and values`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/** @deprecated */ const validateBunWorkspacesConfig = (config) => {
|
|
39
|
+
if (!isJsonObject(config)) {
|
|
40
|
+
throw new ERRORS.InvalidConfigFile(`Config file: must be an object`);
|
|
41
|
+
}
|
|
42
|
+
if (typeof config.cli !== "undefined") {
|
|
43
|
+
validateCliConfig(config.cli);
|
|
44
|
+
}
|
|
45
|
+
if (typeof config.project !== "undefined") {
|
|
46
|
+
validateProjectConfig(config.project);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { validateBunWorkspacesConfig };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type BunWorkspacesConfig } from "./bunWorkspacesConfig";
|
|
2
|
+
/** @deprecated The default path for the config file */
|
|
3
|
+
export declare const DEFAULT_CONFIG_FILE_PATH = "bw.json";
|
|
4
|
+
/** @deprecated */
|
|
5
|
+
export declare const loadConfigFile: (
|
|
6
|
+
filePath?: string,
|
|
7
|
+
rootDirectory?: string,
|
|
8
|
+
) => BunWorkspacesConfig | null;
|