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,40 @@
|
|
|
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
|
+
readonly config: import("../../project").ProjectConfig;
|
|
13
|
+
readonly rootWorkspace: import("../..").Workspace;
|
|
14
|
+
runWorkspaceScript(
|
|
15
|
+
options: import("../..").RunWorkspaceScriptOptions,
|
|
16
|
+
): import("../..").RunWorkspaceScriptResult;
|
|
17
|
+
runScriptAcrossWorkspaces(
|
|
18
|
+
options: import("../..").RunScriptAcrossWorkspacesOptions,
|
|
19
|
+
): import("../..").RunScriptAcrossWorkspacesResult;
|
|
20
|
+
listWorkspacesWithScript(scriptName: string): import("../..").Workspace[];
|
|
21
|
+
mapScriptsToWorkspaces(): Record<
|
|
22
|
+
string,
|
|
23
|
+
import("../..").WorkspaceScriptMetadata
|
|
24
|
+
>;
|
|
25
|
+
findWorkspaceByName(
|
|
26
|
+
workspaceName: string,
|
|
27
|
+
): import("../..").Workspace | null;
|
|
28
|
+
findWorkspaceByAlias(alias: string): import("../..").Workspace | null;
|
|
29
|
+
findWorkspaceByNameOrAlias(
|
|
30
|
+
nameOrAlias: string,
|
|
31
|
+
): import("../..").Workspace | null;
|
|
32
|
+
findWorkspacesByPattern(
|
|
33
|
+
...workspacePatterns: string[]
|
|
34
|
+
): import("../..").Workspace[];
|
|
35
|
+
createScriptCommand(
|
|
36
|
+
options: import("../..").CreateProjectScriptCommandOptions,
|
|
37
|
+
): import("../..").CreateProjectScriptCommandResult;
|
|
38
|
+
}>;
|
|
39
|
+
projectError: Error | null;
|
|
40
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { Option } from "commander";
|
|
4
|
+
import { defineErrors } from "../../internal/core/index.mjs";
|
|
5
|
+
import { logger } from "../../internal/logger/index.mjs";
|
|
6
|
+
import {
|
|
7
|
+
createFileSystemProject,
|
|
8
|
+
createMemoryProject,
|
|
9
|
+
} from "../../project/index.mjs";
|
|
10
|
+
import { getCliGlobalOptionConfig } from "./globalOptionsConfig.mjs"; // CONCATENATED MODULE: external "fs"
|
|
11
|
+
// CONCATENATED MODULE: external "path"
|
|
12
|
+
// CONCATENATED MODULE: external "commander"
|
|
13
|
+
// CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
14
|
+
// CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
15
|
+
// CONCATENATED MODULE: external "../../project/index.mjs"
|
|
16
|
+
// CONCATENATED MODULE: external "./globalOptionsConfig.mjs"
|
|
17
|
+
// CONCATENATED MODULE: ./src/cli/globalOptions/globalOptions.ts
|
|
18
|
+
|
|
19
|
+
const ERRORS = defineErrors(
|
|
20
|
+
"WorkingDirectoryNotFound",
|
|
21
|
+
"WorkingDirectoryNotADirectory",
|
|
22
|
+
);
|
|
23
|
+
const addGlobalOption = (program, optionName, defaultOverride) => {
|
|
24
|
+
const { mainOption, shortOption, description, param, values, defaultValue } =
|
|
25
|
+
getCliGlobalOptionConfig(optionName);
|
|
26
|
+
let option = new Option(
|
|
27
|
+
`${shortOption} ${mainOption}${param ? ` <${param}>` : ""}`,
|
|
28
|
+
description,
|
|
29
|
+
);
|
|
30
|
+
const effectiveDefaultValue = defaultOverride ?? defaultValue;
|
|
31
|
+
if (effectiveDefaultValue) {
|
|
32
|
+
option = option.default(effectiveDefaultValue);
|
|
33
|
+
}
|
|
34
|
+
if (values?.length) {
|
|
35
|
+
option = option.choices(values);
|
|
36
|
+
}
|
|
37
|
+
program.addOption(option);
|
|
38
|
+
if (!param) {
|
|
39
|
+
program.option(
|
|
40
|
+
mainOption.replace(/^--/, "--no-"),
|
|
41
|
+
`Set ${mainOption} as false`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const getWorkingDirectoryFromArgs = (program, args, defaultCwd) => {
|
|
46
|
+
addGlobalOption(program, "cwd", defaultCwd);
|
|
47
|
+
program.parseOptions(args);
|
|
48
|
+
return program.opts().cwd;
|
|
49
|
+
};
|
|
50
|
+
const defineGlobalOptions = (program, args, defaultCwd) => {
|
|
51
|
+
const cwd = getWorkingDirectoryFromArgs(program, args, defaultCwd);
|
|
52
|
+
if (!fs.existsSync(cwd)) {
|
|
53
|
+
throw new ERRORS.WorkingDirectoryNotFound(
|
|
54
|
+
`Working directory not found at path "${cwd}"`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (!fs.statSync(cwd).isDirectory()) {
|
|
58
|
+
throw new ERRORS.WorkingDirectoryNotADirectory(
|
|
59
|
+
`Working directory is not a directory at path "${cwd}"`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
addGlobalOption(program, "logLevel");
|
|
63
|
+
addGlobalOption(program, "includeRoot");
|
|
64
|
+
return {
|
|
65
|
+
cwd,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const applyGlobalOptions = (options) => {
|
|
69
|
+
logger.printLevel = options.logLevel;
|
|
70
|
+
logger.debug("Log level: " + options.logLevel);
|
|
71
|
+
let project;
|
|
72
|
+
let error = null;
|
|
73
|
+
try {
|
|
74
|
+
project = createFileSystemProject({
|
|
75
|
+
rootDirectory: options.cwd,
|
|
76
|
+
includeRootWorkspace: options.includeRoot,
|
|
77
|
+
});
|
|
78
|
+
logger.debug(
|
|
79
|
+
`Project: ${JSON.stringify(project.name)} (${project.workspaces.length} workspace${project.workspaces.length === 1 ? "" : "s"})`,
|
|
80
|
+
);
|
|
81
|
+
logger.debug("Project root: " + path.resolve(project.rootDirectory));
|
|
82
|
+
} catch (_error) {
|
|
83
|
+
error = _error;
|
|
84
|
+
project = createMemoryProject({
|
|
85
|
+
workspaces: [],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
project,
|
|
90
|
+
projectError: error,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const initializeWithGlobalOptions = (program, args, defaultCwd) => {
|
|
94
|
+
program.allowUnknownOption(true);
|
|
95
|
+
const { cwd } = defineGlobalOptions(program, args, defaultCwd);
|
|
96
|
+
program.parseOptions(args);
|
|
97
|
+
program.allowUnknownOption(false);
|
|
98
|
+
const options = program.opts();
|
|
99
|
+
return applyGlobalOptions({
|
|
100
|
+
...options,
|
|
101
|
+
cwd,
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { initializeWithGlobalOptions };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type LogLevelSetting } from "../../internal/logger";
|
|
2
|
+
export interface CliGlobalOptions {
|
|
3
|
+
logLevel: LogLevelSetting;
|
|
4
|
+
cwd: string;
|
|
5
|
+
includeRoot: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface CliGlobalOptionConfig {
|
|
8
|
+
mainOption: string;
|
|
9
|
+
shortOption: string;
|
|
10
|
+
description: string;
|
|
11
|
+
defaultValue: string;
|
|
12
|
+
values: string[] | 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: "--include-root";
|
|
37
|
+
readonly shortOption: "-r";
|
|
38
|
+
readonly description: "Include the root workspace as a normal workspace";
|
|
39
|
+
readonly defaultValue: "";
|
|
40
|
+
readonly values: null;
|
|
41
|
+
readonly param: "";
|
|
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
|
+
includeRoot: {
|
|
22
|
+
mainOption: "--include-root",
|
|
23
|
+
shortOption: "-r",
|
|
24
|
+
description: "Include the root workspace as a normal workspace",
|
|
25
|
+
defaultValue: "",
|
|
26
|
+
values: null,
|
|
27
|
+
param: "",
|
|
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,72 @@
|
|
|
1
|
+
import type { Command as CommanderProgram } from "commander";
|
|
2
|
+
import type { FileSystemProject } from "../project";
|
|
3
|
+
import type { CliCommandName, CliGlobalCommandName } from "./commands";
|
|
4
|
+
import type {
|
|
5
|
+
GlobalCommandContext,
|
|
6
|
+
ProjectCommandContext,
|
|
7
|
+
} from "./commands/commandHandlerUtils";
|
|
8
|
+
export type InitProgramContext = {
|
|
9
|
+
commanderProgram: CommanderProgram;
|
|
10
|
+
argv: string[];
|
|
11
|
+
};
|
|
12
|
+
export type ProcessArgvContext = {
|
|
13
|
+
args: string[];
|
|
14
|
+
postTerminatorArgs: string[];
|
|
15
|
+
};
|
|
16
|
+
export type FindProjectContext = {
|
|
17
|
+
commanderProgram: CommanderProgram;
|
|
18
|
+
project: FileSystemProject;
|
|
19
|
+
projectError: Error | null;
|
|
20
|
+
};
|
|
21
|
+
export type PreParseContext = {
|
|
22
|
+
commanderProgram: CommanderProgram;
|
|
23
|
+
args: string[];
|
|
24
|
+
project: FileSystemProject;
|
|
25
|
+
projectError: Error | null;
|
|
26
|
+
};
|
|
27
|
+
export type PostParseContext = {
|
|
28
|
+
commanderProgram: CommanderProgram;
|
|
29
|
+
args: string[];
|
|
30
|
+
project: FileSystemProject;
|
|
31
|
+
projectError: Error | null;
|
|
32
|
+
};
|
|
33
|
+
export type CommandMiddlewareContext<C extends CliCommandName> = {
|
|
34
|
+
commanderProgram: CommanderProgram;
|
|
35
|
+
commandName: C;
|
|
36
|
+
commandContext: C extends CliGlobalCommandName
|
|
37
|
+
? GlobalCommandContext
|
|
38
|
+
: ProjectCommandContext;
|
|
39
|
+
commanderActionArgs: unknown[];
|
|
40
|
+
};
|
|
41
|
+
export type CommandMiddleware = <C extends CliCommandName>(
|
|
42
|
+
context: CommandMiddlewareContext<C>,
|
|
43
|
+
) => CommanderProgram;
|
|
44
|
+
export type PostCleanupContext = {
|
|
45
|
+
commanderProgram: CommanderProgram;
|
|
46
|
+
args: string[];
|
|
47
|
+
project: FileSystemProject;
|
|
48
|
+
projectError: Error | null;
|
|
49
|
+
};
|
|
50
|
+
export type CliMiddleware = {
|
|
51
|
+
/** The first callback when the Commander program is created */
|
|
52
|
+
initProgram: (context: InitProgramContext) => CommanderProgram;
|
|
53
|
+
/** Before the true parsing, just splitting the argv into args and post-terminator args */
|
|
54
|
+
processArgv: (context: ProcessArgvContext) => CommanderProgram;
|
|
55
|
+
/** After the project has been initialized from global options */
|
|
56
|
+
findProject: (context: FindProjectContext) => CommanderProgram;
|
|
57
|
+
/** Before the Commander program parses the args */
|
|
58
|
+
preParse: (context: PreParseContext) => CommanderProgram;
|
|
59
|
+
/** After the Commander program has parsed the args (runs in finally block) */
|
|
60
|
+
postParse: (context: PostParseContext) => CommanderProgram;
|
|
61
|
+
/** Before a command is handled */
|
|
62
|
+
preHandleCommand: CommandMiddleware;
|
|
63
|
+
/** After a command is handled */
|
|
64
|
+
postHandleCommand: CommandMiddleware;
|
|
65
|
+
/** After the program has been parsed */
|
|
66
|
+
catchError: (error: Error) => unknown;
|
|
67
|
+
};
|
|
68
|
+
export type CliMiddlewareOptions = Partial<CliMiddleware>;
|
|
69
|
+
export declare const resolveMiddleware: (
|
|
70
|
+
defaultMiddleware: CliMiddlewareOptions,
|
|
71
|
+
runMiddleware: CliMiddlewareOptions,
|
|
72
|
+
) => CliMiddleware;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineErrors } from "../internal/core/index.mjs";
|
|
2
|
+
import { logger } from "../internal/logger/index.mjs"; // CONCATENATED MODULE: external "../internal/core/index.mjs"
|
|
3
|
+
// CONCATENATED MODULE: external "../internal/logger/index.mjs"
|
|
4
|
+
// CONCATENATED MODULE: ./src/cli/middleware.ts
|
|
5
|
+
|
|
6
|
+
const MIDDLEWARE_ERRORS = defineErrors("MiddlewareHandlerFailed");
|
|
7
|
+
const resolveMiddleware = (defaultMiddleware, runMiddleware) =>
|
|
8
|
+
Object.keys({
|
|
9
|
+
catchError: null,
|
|
10
|
+
initProgram: null,
|
|
11
|
+
processArgv: null,
|
|
12
|
+
findProject: null,
|
|
13
|
+
preParse: null,
|
|
14
|
+
postParse: null,
|
|
15
|
+
preHandleCommand: null,
|
|
16
|
+
postHandleCommand: null,
|
|
17
|
+
}).reduce((acc, _key) => {
|
|
18
|
+
const key = _key;
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
acc[key] = (ctx) => {
|
|
21
|
+
try {
|
|
22
|
+
let result = defaultMiddleware?.[key]?.(ctx);
|
|
23
|
+
result = runMiddleware?.[key]?.(ctx);
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
return result;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
logger.error(
|
|
28
|
+
new MIDDLEWARE_ERRORS.MiddlewareHandlerFailed(
|
|
29
|
+
`Error in middleware handler "${key}"`,
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
|
|
38
|
+
export { resolveMiddleware };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ROOT_CONFIG_ERRORS: import("../../internal/core").DefinedErrors<"InvalidRootConfig">;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { defineErrors } from "../../internal/core/index.mjs"; // CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
2
|
+
// CONCATENATED MODULE: ./src/config/rootConfig/errors.ts
|
|
3
|
+
|
|
4
|
+
const ROOT_CONFIG_ERRORS = defineErrors("InvalidRootConfig");
|
|
5
|
+
|
|
6
|
+
export { ROOT_CONFIG_ERRORS };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { loadConfig } from "../util/loadConfig.mjs";
|
|
2
|
+
import { createDefaultRootConfig, resolveRootConfig } from "./rootConfig.mjs";
|
|
3
|
+
import {
|
|
4
|
+
ROOT_CONFIG_FILE_NAME,
|
|
5
|
+
ROOT_CONFIG_PACKAGE_JSON_KEY,
|
|
6
|
+
} from "./rootConfigLocation.mjs"; // CONCATENATED MODULE: external "../util/loadConfig.mjs"
|
|
7
|
+
// CONCATENATED MODULE: external "./rootConfig.mjs"
|
|
8
|
+
// CONCATENATED MODULE: external "./rootConfigLocation.mjs"
|
|
9
|
+
// CONCATENATED MODULE: ./src/config/rootConfig/loadRootConfig.ts
|
|
10
|
+
|
|
11
|
+
const loadRootConfig = (rootDirectory) => {
|
|
12
|
+
const config = loadConfig(
|
|
13
|
+
"root",
|
|
14
|
+
rootDirectory,
|
|
15
|
+
ROOT_CONFIG_FILE_NAME,
|
|
16
|
+
ROOT_CONFIG_PACKAGE_JSON_KEY,
|
|
17
|
+
(content) => resolveRootConfig(content),
|
|
18
|
+
);
|
|
19
|
+
return config ?? createDefaultRootConfig();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { loadRootConfig };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type FromSchema } from "json-schema-to-ts";
|
|
2
|
+
import { type ScriptShellOption } from "../../runScript";
|
|
3
|
+
import type { ROOT_CONFIG_JSON_SCHEMA } from "./rootConfigSchema";
|
|
4
|
+
export type RootConfig = FromSchema<typeof ROOT_CONFIG_JSON_SCHEMA>;
|
|
5
|
+
export type ResolvedRootConfig = {
|
|
6
|
+
defaults: {
|
|
7
|
+
parallelMax: number;
|
|
8
|
+
shell: ScriptShellOption;
|
|
9
|
+
/** `undefined` means the value was not set in the input config */
|
|
10
|
+
includeRootWorkspace: boolean | undefined;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const validateRootConfig: (config: RootConfig) => void;
|
|
14
|
+
export declare const createDefaultRootConfig: () => ResolvedRootConfig;
|
|
15
|
+
export declare const resolveRootConfig: (
|
|
16
|
+
config: RootConfig,
|
|
17
|
+
) => ResolvedRootConfig;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import validateRootConfig from "../../internal/generated/ajv/validateRootConfig.mjs";
|
|
2
|
+
import {
|
|
3
|
+
determineParallelMax,
|
|
4
|
+
resolveScriptShell,
|
|
5
|
+
} from "../../runScript/index.mjs";
|
|
6
|
+
import { getUserEnvVar } from "../userEnvVars/index.mjs";
|
|
7
|
+
import { executeValidator } from "../util/validateConfig.mjs";
|
|
8
|
+
import { ROOT_CONFIG_ERRORS } from "./errors.mjs"; // CONCATENATED MODULE: external "../../internal/generated/ajv/validateRootConfig.mjs"
|
|
9
|
+
// CONCATENATED MODULE: external "../../runScript/index.mjs"
|
|
10
|
+
// CONCATENATED MODULE: external "../userEnvVars/index.mjs"
|
|
11
|
+
// CONCATENATED MODULE: external "../util/validateConfig.mjs"
|
|
12
|
+
// CONCATENATED MODULE: external "./errors.mjs"
|
|
13
|
+
// CONCATENATED MODULE: ./src/config/rootConfig/rootConfig.ts
|
|
14
|
+
|
|
15
|
+
const rootConfig_validateRootConfig = (config) =>
|
|
16
|
+
executeValidator(
|
|
17
|
+
validateRootConfig,
|
|
18
|
+
"RootConfig",
|
|
19
|
+
config,
|
|
20
|
+
ROOT_CONFIG_ERRORS.InvalidRootConfig,
|
|
21
|
+
);
|
|
22
|
+
const createDefaultRootConfig = () => resolveRootConfig({});
|
|
23
|
+
const resolveRootConfig = (config) => {
|
|
24
|
+
rootConfig_validateRootConfig(config);
|
|
25
|
+
return {
|
|
26
|
+
defaults: {
|
|
27
|
+
parallelMax: determineParallelMax(
|
|
28
|
+
config.defaults?.parallelMax ?? "default",
|
|
29
|
+
" (set by root config)",
|
|
30
|
+
),
|
|
31
|
+
shell: resolveScriptShell(config.defaults?.shell),
|
|
32
|
+
includeRootWorkspace:
|
|
33
|
+
config.defaults?.includeRootWorkspace ??
|
|
34
|
+
getUserEnvVar("includeRootWorkspaceDefault") === "true",
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
createDefaultRootConfig,
|
|
41
|
+
resolveRootConfig,
|
|
42
|
+
rootConfig_validateRootConfig as validateRootConfig,
|
|
43
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const ROOT_CONFIG_JSON_SCHEMA: {
|
|
2
|
+
readonly type: "object";
|
|
3
|
+
readonly additionalProperties: false;
|
|
4
|
+
readonly properties: {
|
|
5
|
+
readonly defaults: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly additionalProperties: false;
|
|
8
|
+
readonly properties: {
|
|
9
|
+
readonly parallelMax: {
|
|
10
|
+
readonly type: readonly ["number", "string"];
|
|
11
|
+
};
|
|
12
|
+
readonly shell: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
};
|
|
15
|
+
readonly includeRootWorkspace: {
|
|
16
|
+
readonly type: "boolean";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// CONCATENATED MODULE: ./src/config/rootConfig/rootConfigSchema.ts
|
|
2
|
+
const ROOT_CONFIG_JSON_SCHEMA = {
|
|
3
|
+
type: "object",
|
|
4
|
+
additionalProperties: false,
|
|
5
|
+
properties: {
|
|
6
|
+
defaults: {
|
|
7
|
+
type: "object",
|
|
8
|
+
additionalProperties: false,
|
|
9
|
+
properties: {
|
|
10
|
+
parallelMax: {
|
|
11
|
+
type: ["number", "string"],
|
|
12
|
+
},
|
|
13
|
+
shell: {
|
|
14
|
+
type: "string",
|
|
15
|
+
},
|
|
16
|
+
includeRootWorkspace: {
|
|
17
|
+
type: "boolean",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { ROOT_CONFIG_JSON_SCHEMA };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./userEnvVars";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./userEnvVars.mjs"; // CONCATENATED MODULE: ./src/config/userEnvVars/index.ts
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const USER_ENV_VARS: {
|
|
2
|
+
readonly parallelMaxDefault: "BW_PARALLEL_MAX_DEFAULT";
|
|
3
|
+
readonly scriptShellDefault: "BW_SHELL_DEFAULT";
|
|
4
|
+
readonly includeRootWorkspaceDefault: "BW_INCLUDE_ROOT_WORKSPACE_DEFAULT";
|
|
5
|
+
};
|
|
6
|
+
export type UserEnvVarName = keyof typeof USER_ENV_VARS;
|
|
7
|
+
export declare const getUserEnvVar: (key: UserEnvVarName) => string | undefined;
|
|
8
|
+
export declare const getUserEnvVarName: (
|
|
9
|
+
key: UserEnvVarName,
|
|
10
|
+
) =>
|
|
11
|
+
| "BW_PARALLEL_MAX_DEFAULT"
|
|
12
|
+
| "BW_SHELL_DEFAULT"
|
|
13
|
+
| "BW_INCLUDE_ROOT_WORKSPACE_DEFAULT";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// CONCATENATED MODULE: ./src/config/userEnvVars/userEnvVars.ts
|
|
2
|
+
const USER_ENV_VARS = {
|
|
3
|
+
parallelMaxDefault: "BW_PARALLEL_MAX_DEFAULT",
|
|
4
|
+
scriptShellDefault: "BW_SHELL_DEFAULT",
|
|
5
|
+
includeRootWorkspaceDefault: "BW_INCLUDE_ROOT_WORKSPACE_DEFAULT",
|
|
6
|
+
};
|
|
7
|
+
const getUserEnvVar = (key) => process.env[USER_ENV_VARS[key]];
|
|
8
|
+
const getUserEnvVarName = (key) => USER_ENV_VARS[key];
|
|
9
|
+
|
|
10
|
+
export { USER_ENV_VARS, getUserEnvVar, getUserEnvVarName };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type AjvJsonSchemaErrorObject = {
|
|
2
|
+
instancePath?: string;
|
|
3
|
+
schemaPath?: string;
|
|
4
|
+
keyword?: string;
|
|
5
|
+
params?: Record<string, unknown>;
|
|
6
|
+
message?: string;
|
|
7
|
+
};
|
|
8
|
+
export type AjvSchemaValidator<T = unknown> = ((data: unknown) => data is T) & {
|
|
9
|
+
errors?: AjvJsonSchemaErrorObject[] | null;
|
|
10
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const CONFIG_LOCATION_TYPES: string[];
|
|
2
|
+
export type ConfigLocationType = (typeof CONFIG_LOCATION_TYPES)[number];
|
|
3
|
+
export type ConfigLocation = {
|
|
4
|
+
type: ConfigLocationType;
|
|
5
|
+
content: unknown;
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const createConfigLocationPath: (
|
|
9
|
+
locationType: ConfigLocationType,
|
|
10
|
+
name: string,
|
|
11
|
+
packageJsonKey: string,
|
|
12
|
+
) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// CONCATENATED MODULE: ./src/config/util/configLocation.ts
|
|
2
|
+
const CONFIG_LOCATION_TYPES = ["jsoncFile", "jsonFile", "packageJson"];
|
|
3
|
+
const CONFIG_LOCATION_PATHS = {
|
|
4
|
+
jsoncFile: (name) => `${name}.jsonc`,
|
|
5
|
+
jsonFile: (name) => `${name}.json`,
|
|
6
|
+
packageJson: (_, packageJsonKey) => `package.json["${packageJsonKey}"]`,
|
|
7
|
+
};
|
|
8
|
+
const createConfigLocationPath = (locationType, name, packageJsonKey) =>
|
|
9
|
+
CONFIG_LOCATION_PATHS[locationType](name, packageJsonKey);
|
|
10
|
+
|
|
11
|
+
export { CONFIG_LOCATION_TYPES, createConfigLocationPath };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type AnyFunction } from "../../internal/core";
|
|
2
|
+
import { type ConfigLocation } from "./configLocation";
|
|
3
|
+
export declare const InvalidJSONError: typeof import("../..").BunWorkspacesError;
|
|
4
|
+
export declare const getConfigLocation: (
|
|
5
|
+
name: string,
|
|
6
|
+
directory: string,
|
|
7
|
+
fileName: string,
|
|
8
|
+
packageJsonKey: string,
|
|
9
|
+
) => ConfigLocation | null;
|
|
10
|
+
export declare const loadConfig: <ProcessContent extends AnyFunction>(
|
|
11
|
+
name: string,
|
|
12
|
+
directory: string,
|
|
13
|
+
fileName: string,
|
|
14
|
+
packageJsonKey: string,
|
|
15
|
+
processContent: ProcessContent,
|
|
16
|
+
) => ReturnType<ProcessContent> | null;
|