bun-workspaces 1.0.1-alpha → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +50 -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 +250 -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 +74 -0
- package/src/cli/commands/runScript/output/renderGroupedOutput.mjs +331 -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 +157 -0
- package/src/cli/fatalErrorLogger.d.ts +1 -0
- package/src/cli/fatalErrorLogger.mjs +7 -0
- package/src/cli/globalOptions/globalOptions.d.ts +42 -0
- package/src/cli/globalOptions/globalOptions.mjs +113 -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 +83 -0
- package/src/cli/middleware.mjs +39 -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,197 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { validateCurrentBunVersion } from "../../internal/bun/index.mjs";
|
|
3
|
+
import { validateJSTypes } from "../../internal/core/index.mjs";
|
|
4
|
+
import { logger } from "../../internal/logger/index.mjs";
|
|
5
|
+
import { createWorkspaceScriptCommand } from "../../runScript/index.mjs";
|
|
6
|
+
import { sortWorkspaces } from "../../workspaces/index.mjs";
|
|
7
|
+
import { matchWorkspacesByPatterns } from "../../workspaces/workspacePattern.mjs";
|
|
8
|
+
import { PROJECT_ERRORS } from "../errors.mjs"; // CONCATENATED MODULE: external "path"
|
|
9
|
+
// CONCATENATED MODULE: external "../../internal/bun/index.mjs"
|
|
10
|
+
// CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
11
|
+
// CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
12
|
+
// CONCATENATED MODULE: external "../../runScript/index.mjs"
|
|
13
|
+
// CONCATENATED MODULE: external "../../workspaces/index.mjs"
|
|
14
|
+
// CONCATENATED MODULE: external "../../workspaces/workspacePattern.mjs"
|
|
15
|
+
// CONCATENATED MODULE: external "../errors.mjs"
|
|
16
|
+
// CONCATENATED MODULE: ./src/project/implementations/projectBase.ts
|
|
17
|
+
|
|
18
|
+
const resolveWorkspacePath = (project, workspace) =>
|
|
19
|
+
path.resolve(project.rootDirectory, workspace.path);
|
|
20
|
+
const ROOT_WORKSPACE_SELECTOR = "@root";
|
|
21
|
+
const resolveRootWorkspaceSelector = (workspacePattern, project) =>
|
|
22
|
+
workspacePattern === ROOT_WORKSPACE_SELECTOR
|
|
23
|
+
? project.rootWorkspace
|
|
24
|
+
: project.findWorkspaceByNameOrAlias(workspacePattern);
|
|
25
|
+
class ProjectBase {
|
|
26
|
+
constructor(_ignoreBunVersion = false) {
|
|
27
|
+
const bunVersionError = validateCurrentBunVersion();
|
|
28
|
+
if (bunVersionError && !_ignoreBunVersion) {
|
|
29
|
+
logger.error(
|
|
30
|
+
bunVersionError.message + " (Features may not work as expected)",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
listWorkspacesWithScript(scriptName) {
|
|
35
|
+
validateJSTypes(
|
|
36
|
+
{
|
|
37
|
+
scriptName: {
|
|
38
|
+
value: scriptName,
|
|
39
|
+
typeofName: "string",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
throw: true,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
return this.workspaces.filter((workspace) =>
|
|
47
|
+
workspace.scripts.includes(scriptName),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
mapScriptsToWorkspaces() {
|
|
51
|
+
const scripts = new Set();
|
|
52
|
+
this.workspaces.forEach((workspace) => {
|
|
53
|
+
workspace.scripts.forEach((script) => scripts.add(script));
|
|
54
|
+
});
|
|
55
|
+
return Array.from(scripts)
|
|
56
|
+
.sort((a, b) => a.localeCompare(b))
|
|
57
|
+
.map((name) => ({
|
|
58
|
+
name,
|
|
59
|
+
workspaces: this.listWorkspacesWithScript(name),
|
|
60
|
+
}))
|
|
61
|
+
.reduce(
|
|
62
|
+
(acc, { name, workspaces }) => ({
|
|
63
|
+
...acc,
|
|
64
|
+
[name]: {
|
|
65
|
+
name,
|
|
66
|
+
workspaces,
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
{},
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
findWorkspaceByName(workspaceName) {
|
|
73
|
+
validateJSTypes(
|
|
74
|
+
{
|
|
75
|
+
workspaceName: {
|
|
76
|
+
value: workspaceName,
|
|
77
|
+
typeofName: "string",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
throw: true,
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
return (
|
|
85
|
+
this.workspaces.find((workspace) => workspace.name === workspaceName) ??
|
|
86
|
+
null
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
findWorkspaceByAlias(alias) {
|
|
90
|
+
validateJSTypes(
|
|
91
|
+
{
|
|
92
|
+
alias: {
|
|
93
|
+
value: alias,
|
|
94
|
+
typeofName: "string",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
throw: true,
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
return (
|
|
102
|
+
this.workspaces.find((workspace) => workspace.aliases.includes(alias)) ??
|
|
103
|
+
null
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
findWorkspaceByNameOrAlias(nameOrAlias) {
|
|
107
|
+
validateJSTypes(
|
|
108
|
+
{
|
|
109
|
+
nameOrAlias: {
|
|
110
|
+
value: nameOrAlias,
|
|
111
|
+
typeofName: "string",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
throw: true,
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
return (
|
|
119
|
+
this.findWorkspaceByName(nameOrAlias) ||
|
|
120
|
+
this.findWorkspaceByAlias(nameOrAlias)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
findWorkspacesByPattern(...workspacePatterns) {
|
|
124
|
+
const workspaces = [];
|
|
125
|
+
if (workspacePatterns.includes(ROOT_WORKSPACE_SELECTOR)) {
|
|
126
|
+
workspaces.push(this.rootWorkspace);
|
|
127
|
+
workspacePatterns = workspacePatterns.filter(
|
|
128
|
+
(pattern) => pattern !== ROOT_WORKSPACE_SELECTOR,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
workspaces.push(
|
|
132
|
+
...sortWorkspaces(
|
|
133
|
+
matchWorkspacesByPatterns(workspacePatterns, this.workspaces),
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
return workspaces;
|
|
137
|
+
}
|
|
138
|
+
createScriptCommand(options) {
|
|
139
|
+
validateJSTypes(
|
|
140
|
+
{
|
|
141
|
+
"workspaceNameOrAlias option": {
|
|
142
|
+
value: options.workspaceNameOrAlias,
|
|
143
|
+
typeofName: "string",
|
|
144
|
+
},
|
|
145
|
+
"scriptName option": {
|
|
146
|
+
value: options.scriptName,
|
|
147
|
+
typeofName: "string",
|
|
148
|
+
},
|
|
149
|
+
"method option": {
|
|
150
|
+
value: options.method,
|
|
151
|
+
typeofName: "string",
|
|
152
|
+
optional: true,
|
|
153
|
+
},
|
|
154
|
+
"args option": {
|
|
155
|
+
value: options.args,
|
|
156
|
+
typeofName: "string",
|
|
157
|
+
optional: true,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
throw: true,
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
const workspace = resolveRootWorkspaceSelector(
|
|
165
|
+
options.workspaceNameOrAlias,
|
|
166
|
+
this,
|
|
167
|
+
);
|
|
168
|
+
if (!workspace) {
|
|
169
|
+
throw new PROJECT_ERRORS.ProjectWorkspaceNotFound(
|
|
170
|
+
`Workspace not found: ${JSON.stringify(options.workspaceNameOrAlias)}`,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
if (!workspace.scripts.includes(options.scriptName)) {
|
|
174
|
+
throw new PROJECT_ERRORS.WorkspaceScriptDoesNotExist(
|
|
175
|
+
`Script not found in workspace ${JSON.stringify(workspace.name)}: ${JSON.stringify(options.scriptName)} (available: ${workspace.scripts.join(", ") || "none"})`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
workspace,
|
|
180
|
+
scriptName: options.scriptName,
|
|
181
|
+
commandDetails: createWorkspaceScriptCommand({
|
|
182
|
+
...options,
|
|
183
|
+
workspace,
|
|
184
|
+
rootDirectory: path.resolve(this.rootDirectory),
|
|
185
|
+
method: options.method,
|
|
186
|
+
args: options.args ?? "",
|
|
187
|
+
}),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export {
|
|
193
|
+
ProjectBase,
|
|
194
|
+
ROOT_WORKSPACE_SELECTOR,
|
|
195
|
+
resolveRootWorkspaceSelector,
|
|
196
|
+
resolveWorkspacePath,
|
|
197
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ResolvedRootConfig, ResolvedWorkspaceConfig } from "../config";
|
|
2
|
+
import type { ScriptCommand, WorkspaceScriptCommandMethod } from "../runScript";
|
|
3
|
+
import type { Workspace } from "../workspaces";
|
|
4
|
+
/** Metadata about a {@link Project}'s script, including the workspaces that have it in their package.json */
|
|
5
|
+
export type WorkspaceScriptMetadata = {
|
|
6
|
+
name: string;
|
|
7
|
+
workspaces: Workspace[];
|
|
8
|
+
};
|
|
9
|
+
/** Arguments for {@link Project.createScriptCommand} */
|
|
10
|
+
export type CreateProjectScriptCommandOptions = {
|
|
11
|
+
/** The workspace to run the script in */
|
|
12
|
+
workspaceNameOrAlias: string;
|
|
13
|
+
/** The name of the script to run */
|
|
14
|
+
scriptName: string;
|
|
15
|
+
/**
|
|
16
|
+
* The method to use to run the script.
|
|
17
|
+
* Either run in the workspace directory or use bun's --filter option.
|
|
18
|
+
* Defaults to "cd".
|
|
19
|
+
*/
|
|
20
|
+
method?: WorkspaceScriptCommandMethod;
|
|
21
|
+
/** The arguments to append to the command */
|
|
22
|
+
args?: string;
|
|
23
|
+
};
|
|
24
|
+
/** Result of {@link Project.createScriptCommand}. Includes a command string that will run a workspace's script. */
|
|
25
|
+
export type CreateProjectScriptCommandResult = {
|
|
26
|
+
/** Data including a command string using the `bun`
|
|
27
|
+
* CLI that will run a workspace's script and the
|
|
28
|
+
* directory to run it in. */
|
|
29
|
+
commandDetails: ScriptCommand;
|
|
30
|
+
/** The name of the script to run */
|
|
31
|
+
scriptName: string;
|
|
32
|
+
/** The workspace that the script belongs to */
|
|
33
|
+
workspace: Workspace;
|
|
34
|
+
};
|
|
35
|
+
/** The config for a project and its workspaces */
|
|
36
|
+
export type ProjectConfig = {
|
|
37
|
+
root: ResolvedRootConfig;
|
|
38
|
+
/** A map of workspace names to their resolved config */
|
|
39
|
+
workspaces: Record<string, ResolvedWorkspaceConfig>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A project contains a collection of workspaces and is the core of `bun-workspaces`'s functionality.
|
|
43
|
+
*
|
|
44
|
+
* Typically based on a root package.json file's `"workspaces"` field and any matching nested package.json files that are found.
|
|
45
|
+
*/
|
|
46
|
+
export interface Project {
|
|
47
|
+
/** The name of the project. This is typically the name of the root package.json unless otherwise provided. */
|
|
48
|
+
name: string;
|
|
49
|
+
/** The root directory of the project */
|
|
50
|
+
rootDirectory: string;
|
|
51
|
+
/** The root workspace of the project */
|
|
52
|
+
rootWorkspace: Workspace;
|
|
53
|
+
/** The list of all workspaces in the project */
|
|
54
|
+
workspaces: Workspace[];
|
|
55
|
+
/** The config for the project and its workspaces */
|
|
56
|
+
config: ProjectConfig;
|
|
57
|
+
/** The means by which the project was created */
|
|
58
|
+
sourceType: "fileSystem" | "memory";
|
|
59
|
+
/** Find a workspace by its package.json name */
|
|
60
|
+
findWorkspaceByName(workspaceName: string): Workspace | null;
|
|
61
|
+
/** Find a workspace by a workspace alias */
|
|
62
|
+
findWorkspaceByAlias(alias: string): Workspace | null;
|
|
63
|
+
/** Find a workspace that matches a workspace's name or an alias if no name matches. */
|
|
64
|
+
findWorkspaceByNameOrAlias(nameOrAlias: string): Workspace | null;
|
|
65
|
+
/** Accepts a wildcard pattern for finding a list of workspaces by their name*/
|
|
66
|
+
findWorkspacesByPattern(workspacePattern: string): Workspace[];
|
|
67
|
+
/** Get an array of all workspaces that have a given script in their package.json */
|
|
68
|
+
listWorkspacesWithScript(scriptName: string): Workspace[];
|
|
69
|
+
/** Get a mapping of all scripts to the workspaces that have them in their package.json */
|
|
70
|
+
mapScriptsToWorkspaces(): Record<string, WorkspaceScriptMetadata>;
|
|
71
|
+
/** Create metadata that can be used to run a workspace's script */
|
|
72
|
+
createScriptCommand(
|
|
73
|
+
options: CreateProjectScriptCommandOptions,
|
|
74
|
+
): CreateProjectScriptCommandResult;
|
|
75
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// CONCATENATED MODULE: ./src/project/project.ts
|
|
2
|
+
/**
|
|
3
|
+
* A project contains a collection of workspaces and is the core of `bun-workspaces`'s functionality.
|
|
4
|
+
*
|
|
5
|
+
* Typically based on a root package.json file's `"workspaces"` field and any matching nested package.json files that are found.
|
|
6
|
+
*/
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./runScript.mjs";
|
|
2
|
+
export * from "./runScripts.mjs";
|
|
3
|
+
export * from "./scriptCommand.mjs";
|
|
4
|
+
export * from "./output/index.mjs";
|
|
5
|
+
export * from "./parallel.mjs";
|
|
6
|
+
export * from "./scriptRuntimeMetadata.mjs";
|
|
7
|
+
export * from "./scriptShellOption.mjs"; // CONCATENATED MODULE: ./src/runScript/index.ts
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ProcessOutput,
|
|
3
|
+
type BytesOutput,
|
|
4
|
+
type TextOutput,
|
|
5
|
+
} from "./processOutput";
|
|
6
|
+
export interface MultiProcessOutput<Metadata extends object = object> {
|
|
7
|
+
bytes(): BytesOutput<Metadata>;
|
|
8
|
+
text(): TextOutput<Metadata>;
|
|
9
|
+
}
|
|
10
|
+
export declare const createMultiProcessOutput: <
|
|
11
|
+
Metadata extends object = object,
|
|
12
|
+
>(
|
|
13
|
+
processes: ProcessOutput<Metadata>[],
|
|
14
|
+
) => MultiProcessOutput<Metadata>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { mergeAsyncIterables } from "../../internal/core/index.mjs"; // CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
2
|
+
// CONCATENATED MODULE: ./src/runScript/output/multiProcessOutput.ts
|
|
3
|
+
|
|
4
|
+
class _MultiProcessOutput {
|
|
5
|
+
processes;
|
|
6
|
+
constructor(processes) {
|
|
7
|
+
this.processes = processes;
|
|
8
|
+
}
|
|
9
|
+
bytes() {
|
|
10
|
+
return mergeAsyncIterables(
|
|
11
|
+
this.processes.map((process) => process.bytes()),
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
text() {
|
|
15
|
+
return mergeAsyncIterables(this.processes.map((process) => process.text()));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const createMultiProcessOutput = (processes) =>
|
|
19
|
+
new _MultiProcessOutput(processes);
|
|
20
|
+
|
|
21
|
+
export { createMultiProcessOutput };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type OutputStreamName = "stdout" | "stderr";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// CONCATENATED MODULE: ./src/runScript/output/outputStream.ts
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type SimpleAsyncIterable } from "../../internal/core";
|
|
2
|
+
export type ByteStream = SimpleAsyncIterable<Uint8Array<ArrayBufferLike>>;
|
|
3
|
+
export type ProcessOutputChunk<
|
|
4
|
+
Chunk = unknown,
|
|
5
|
+
Metadata extends object = object,
|
|
6
|
+
> = {
|
|
7
|
+
/** The metadata for the script that produced the output chunk */
|
|
8
|
+
metadata: Metadata;
|
|
9
|
+
/** The output chunk */
|
|
10
|
+
chunk: Chunk;
|
|
11
|
+
};
|
|
12
|
+
export type ByteChunk<Metadata extends object = object> = ProcessOutputChunk<
|
|
13
|
+
Uint8Array<ArrayBufferLike>,
|
|
14
|
+
Metadata
|
|
15
|
+
>;
|
|
16
|
+
export type TextChunk<Metadata extends object = object> = ProcessOutputChunk<
|
|
17
|
+
string,
|
|
18
|
+
Metadata
|
|
19
|
+
>;
|
|
20
|
+
export type BytesOutput<Metadata extends object = object> = SimpleAsyncIterable<
|
|
21
|
+
ByteChunk<Metadata>
|
|
22
|
+
>;
|
|
23
|
+
export type TextOutput<Metadata extends object = object> = SimpleAsyncIterable<
|
|
24
|
+
TextChunk<Metadata>
|
|
25
|
+
>;
|
|
26
|
+
export interface ProcessOutput<Metadata extends object = object> {
|
|
27
|
+
bytes(): BytesOutput<Metadata>;
|
|
28
|
+
text(): TextOutput<Metadata>;
|
|
29
|
+
}
|
|
30
|
+
export declare const createProcessOutput: <Metadata extends object = object>(
|
|
31
|
+
stream: ByteStream,
|
|
32
|
+
metadata: Metadata,
|
|
33
|
+
) => ProcessOutput<Metadata>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BunWorkspacesError,
|
|
3
|
+
createAsyncIterableQueue,
|
|
4
|
+
defineErrors,
|
|
5
|
+
} from "../../internal/core/index.mjs"; // CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
6
|
+
// CONCATENATED MODULE: ./src/runScript/output/processOutput.ts
|
|
7
|
+
|
|
8
|
+
const ERRORS = defineErrors(
|
|
9
|
+
BunWorkspacesError,
|
|
10
|
+
"OutputStreamStarted",
|
|
11
|
+
"OutputStreamDone",
|
|
12
|
+
);
|
|
13
|
+
class _ProcessOutput {
|
|
14
|
+
constructor(stream, metadata) {
|
|
15
|
+
this.#inputStream = stream;
|
|
16
|
+
this.#metadata = metadata;
|
|
17
|
+
this.#done = new Promise((resolve, reject) => {
|
|
18
|
+
this.#onDone = (error) => {
|
|
19
|
+
if (this.#isDone) return;
|
|
20
|
+
this.#isDone = true;
|
|
21
|
+
this.#byteChunkQueue.close();
|
|
22
|
+
this.#onDone = null;
|
|
23
|
+
if (!this.isCancelled && error) {
|
|
24
|
+
reject(error);
|
|
25
|
+
} else {
|
|
26
|
+
resolve();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
(async () => {
|
|
31
|
+
// Drain the stream immediately to prevent pipe buffer overflow from subprocesses,
|
|
32
|
+
// the queue acting as a() forwarded async iterable in a way.
|
|
33
|
+
try {
|
|
34
|
+
for await (const chunk of stream) {
|
|
35
|
+
if (this.#isCancelled) break;
|
|
36
|
+
this.#byteChunkQueue.push(chunk.slice());
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
this.#error = error;
|
|
40
|
+
} finally {
|
|
41
|
+
this.#onDone?.(this.#error);
|
|
42
|
+
}
|
|
43
|
+
})();
|
|
44
|
+
}
|
|
45
|
+
get done() {
|
|
46
|
+
return this.#done;
|
|
47
|
+
}
|
|
48
|
+
get isCancelled() {
|
|
49
|
+
return this.#isCancelled;
|
|
50
|
+
}
|
|
51
|
+
bytes() {
|
|
52
|
+
this.#onStart();
|
|
53
|
+
const metadata = this.#metadata;
|
|
54
|
+
const byteChunkQueue = this.#byteChunkQueue;
|
|
55
|
+
return (async function* () {
|
|
56
|
+
for await (const chunk of byteChunkQueue) {
|
|
57
|
+
yield {
|
|
58
|
+
metadata,
|
|
59
|
+
chunk,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
}
|
|
64
|
+
text() {
|
|
65
|
+
this.#onStart();
|
|
66
|
+
const metadata = this.#metadata;
|
|
67
|
+
const byteChunkQueue = this.#byteChunkQueue;
|
|
68
|
+
return (async function* () {
|
|
69
|
+
const decoder = new TextDecoder();
|
|
70
|
+
for await (const byteChunk of byteChunkQueue) {
|
|
71
|
+
yield {
|
|
72
|
+
metadata,
|
|
73
|
+
chunk: decoder.decode(byteChunk, {
|
|
74
|
+
stream: true,
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// flush any remaining data in the decoder
|
|
79
|
+
const danglingChunk = decoder.decode();
|
|
80
|
+
if (danglingChunk)
|
|
81
|
+
yield {
|
|
82
|
+
metadata,
|
|
83
|
+
chunk: danglingChunk,
|
|
84
|
+
};
|
|
85
|
+
})();
|
|
86
|
+
}
|
|
87
|
+
async cancel(reason) {
|
|
88
|
+
this.#isCancelled = true;
|
|
89
|
+
this.#onDone?.();
|
|
90
|
+
await this.#inputStream.cancel?.(reason);
|
|
91
|
+
}
|
|
92
|
+
get isDone() {
|
|
93
|
+
return this.#isDone;
|
|
94
|
+
}
|
|
95
|
+
get error() {
|
|
96
|
+
return this.#error;
|
|
97
|
+
}
|
|
98
|
+
#onStart() {
|
|
99
|
+
if (this.#isDone) {
|
|
100
|
+
throw new ERRORS.OutputStreamDone(
|
|
101
|
+
"The output stream has already been closed.",
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (this.#isStarted) {
|
|
105
|
+
throw new ERRORS.OutputStreamStarted(
|
|
106
|
+
"Only one stream can be opened via .bytes() or .text(). This stream has already been opened.",
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
this.#isStarted = true;
|
|
110
|
+
}
|
|
111
|
+
#isStarted = false;
|
|
112
|
+
#done;
|
|
113
|
+
#error = null;
|
|
114
|
+
#onDone = null;
|
|
115
|
+
#isDone = false;
|
|
116
|
+
#isCancelled = false;
|
|
117
|
+
#inputStream;
|
|
118
|
+
#byteChunkQueue = createAsyncIterableQueue();
|
|
119
|
+
#metadata;
|
|
120
|
+
}
|
|
121
|
+
const createProcessOutput = (stream, metadata) =>
|
|
122
|
+
new _ProcessOutput(stream, metadata);
|
|
123
|
+
|
|
124
|
+
export { createProcessOutput };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const PARALLEL_MAX_VALUES: readonly [
|
|
2
|
+
"auto",
|
|
3
|
+
"unbounded",
|
|
4
|
+
"default",
|
|
5
|
+
];
|
|
6
|
+
export type PercentageValue = `${number}%`;
|
|
7
|
+
export type ParallelMaxValue =
|
|
8
|
+
| number
|
|
9
|
+
| (typeof PARALLEL_MAX_VALUES)[number]
|
|
10
|
+
| PercentageValue;
|
|
11
|
+
/** Should always return at least 1 */
|
|
12
|
+
export declare const determineParallelMax: (
|
|
13
|
+
value: ParallelMaxValue,
|
|
14
|
+
errorMessageSuffix?: string,
|
|
15
|
+
) => number;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import {
|
|
3
|
+
getUserEnvVar,
|
|
4
|
+
getUserEnvVarName,
|
|
5
|
+
} from "../config/userEnvVars/index.mjs";
|
|
6
|
+
import { BunWorkspacesError } from "../internal/core/index.mjs"; // CONCATENATED MODULE: external "os"
|
|
7
|
+
// CONCATENATED MODULE: external "../config/userEnvVars/index.mjs"
|
|
8
|
+
// CONCATENATED MODULE: external "../internal/core/index.mjs"
|
|
9
|
+
// CONCATENATED MODULE: ./src/runScript/parallel.ts
|
|
10
|
+
|
|
11
|
+
const PARALLEL_MAX_VALUES = ["auto", "unbounded", "default"];
|
|
12
|
+
/** Should always return at least 1 */ const determineParallelMax = (
|
|
13
|
+
value,
|
|
14
|
+
errorMessageSuffix = "",
|
|
15
|
+
) => {
|
|
16
|
+
if (!isNaN(Number(value))) {
|
|
17
|
+
value = Math.floor(Number(value));
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === "number") {
|
|
20
|
+
if (value < 1 || isNaN(value)) {
|
|
21
|
+
throw new BunWorkspacesError(
|
|
22
|
+
`Parallel max value must be at least 1${errorMessageSuffix}`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return Math.floor(value);
|
|
26
|
+
}
|
|
27
|
+
if (value === "default") {
|
|
28
|
+
const defaultMax = getUserEnvVar("parallelMaxDefault")?.trim();
|
|
29
|
+
if (defaultMax === "default") return determineParallelMax("auto");
|
|
30
|
+
return determineParallelMax(
|
|
31
|
+
defaultMax ?? "auto",
|
|
32
|
+
` (set by env var ${getUserEnvVarName("parallelMaxDefault")})`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (value === "unbounded") {
|
|
36
|
+
return Infinity;
|
|
37
|
+
}
|
|
38
|
+
const cpuCount = Math.max(1, os.availableParallelism());
|
|
39
|
+
if (value === "auto") {
|
|
40
|
+
return cpuCount;
|
|
41
|
+
}
|
|
42
|
+
if (value.endsWith("%")) {
|
|
43
|
+
const percentage = parseFloat(value.slice(0, -1));
|
|
44
|
+
if (isNaN(percentage) || percentage <= 0 || percentage > 100) {
|
|
45
|
+
throw new BunWorkspacesError(
|
|
46
|
+
`Parallel max value must be a number greater than 0 and less than or equal to 100${errorMessageSuffix}`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return Math.max(1, Math.floor((cpuCount * percentage) / 100));
|
|
50
|
+
}
|
|
51
|
+
throw new BunWorkspacesError(
|
|
52
|
+
`Invalid parallel max value: ${JSON.stringify(value)}${errorMessageSuffix}`,
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { PARALLEL_MAX_VALUES, determineParallelMax };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getScriptRuntimeMetadataConfig } from "./scriptRuntimeMetadata.mjs"; // CONCATENATED MODULE: external "./scriptRuntimeMetadata.mjs"
|
|
2
|
+
// CONCATENATED MODULE: ./src/runScript/recursion.ts
|
|
3
|
+
|
|
4
|
+
const checkIsRecursiveScript = (workspaceName, scriptName) => {
|
|
5
|
+
const parentWorkspace =
|
|
6
|
+
process.env[getScriptRuntimeMetadataConfig("workspaceName").envVarName];
|
|
7
|
+
const parentScript =
|
|
8
|
+
process.env[getScriptRuntimeMetadataConfig("scriptName").envVarName];
|
|
9
|
+
if (!parentWorkspace || !parentScript) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (parentWorkspace === workspaceName && parentScript === scriptName) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { checkIsRecursiveScript };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type MultiProcessOutput, type OutputStreamName } from "./output";
|
|
2
|
+
import type { ScriptCommand } from "./scriptCommand";
|
|
3
|
+
import type { ScriptShellOption } from "./scriptShellOption";
|
|
4
|
+
export type RunScriptExit<ScriptMetadata extends object = object> = {
|
|
5
|
+
exitCode: number;
|
|
6
|
+
signal: NodeJS.Signals | null;
|
|
7
|
+
success: boolean;
|
|
8
|
+
/** Whether the script was skipped due to a failed dependency */
|
|
9
|
+
skipped?: boolean;
|
|
10
|
+
startTimeISO: string;
|
|
11
|
+
endTimeISO: string;
|
|
12
|
+
durationMs: number;
|
|
13
|
+
metadata: ScriptMetadata;
|
|
14
|
+
};
|
|
15
|
+
export type RunScriptResult<ScriptMetadata extends object = object> = {
|
|
16
|
+
output: MultiProcessOutput<
|
|
17
|
+
ScriptMetadata & {
|
|
18
|
+
streamName: OutputStreamName;
|
|
19
|
+
}
|
|
20
|
+
>;
|
|
21
|
+
exit: Promise<RunScriptExit<ScriptMetadata>>;
|
|
22
|
+
metadata: ScriptMetadata;
|
|
23
|
+
kill: (exit?: number | NodeJS.Signals) => void;
|
|
24
|
+
};
|
|
25
|
+
export type RunScriptOptions<ScriptMetadata extends object = object> = {
|
|
26
|
+
scriptCommand: ScriptCommand;
|
|
27
|
+
metadata: ScriptMetadata;
|
|
28
|
+
env: Record<string, string>;
|
|
29
|
+
/** The shell to use to run the script. Defaults to "system". */
|
|
30
|
+
shell?: ScriptShellOption;
|
|
31
|
+
/** Set to `true` to ignore all output from the script. This saves memory when you don't need script output. */
|
|
32
|
+
ignoreOutput?: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Run some script and get an async output stream of
|
|
36
|
+
* stdout and stderr chunks and a result object
|
|
37
|
+
* containing exit details.
|
|
38
|
+
*/
|
|
39
|
+
export declare const runScript: <ScriptMetadata extends object = object>({
|
|
40
|
+
scriptCommand,
|
|
41
|
+
metadata,
|
|
42
|
+
env,
|
|
43
|
+
shell,
|
|
44
|
+
ignoreOutput,
|
|
45
|
+
}: RunScriptOptions<ScriptMetadata>) => RunScriptResult<ScriptMetadata>;
|