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
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,113 +1,232 @@
|
|
|
1
|
+
<a href="https://bunworkspaces.com">
|
|
2
|
+
<img src="./packages/doc-website/src/pages/public/images/png/bwunster-bg-banner-wide_3000x900.png" alt="bun-workspaces" width="100%" />
|
|
3
|
+
</a>
|
|
4
|
+
|
|
1
5
|
# bun-workspaces
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
### [**See Full Documentation Here**: _https://bunworkspaces.com_](https://bunworkspaces.com)
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
A CLI and API to enhance your monorepo development with Bun's [native workspaces](https://bun.sh/docs/install/workspaces) feature for nested JavaScript/TypeScript packages.
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
- Works right away, with no boilerplate required 🍔🍴
|
|
12
|
+
- Get metadata about your monorepo 🤖
|
|
13
|
+
- Run package.json scripts across workspaces 📋
|
|
14
|
+
- Run inline [Bun Shell](https://bun.com/docs/runtime/shell) scripts in workspaces 🐚
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
$ bun add --dev bun-workspaces
|
|
11
|
-
$ bunx bun-workspaces --help
|
|
12
|
-
```
|
|
16
|
+
This is a tool to help manage a Bun monorepo, offering features beyond what [Bun's --filter feature](https://bun.com/docs/pm/filter) can do. It can be used to get a variety of metadata about your project and run scripts across your workspaces with advanced control.
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
To get started, all you need is a repo using [Bun's workspaces feature](https://bun.sh/docs/install/workspaces) for nested JavaScript/TypeScript packages.
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
This package is unopinionated and works with any project structure you want. Think of this as a power suit you can snap onto native workspaces, rather than whole new monorepo framework.
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
Start running some [CLI commands](https://bunworkspaces.com/cli) right away in your repo, or take full advantage of the [scripting API](https://bunworkspaces.com/api) and its features.
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
## Quick Start
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
Installation:
|
|
23
27
|
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
"cli": {
|
|
31
|
-
"logLevel": "warn"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
28
|
+
```bash
|
|
29
|
+
$ # Install to use the API and/or lock your CLI version for your project
|
|
30
|
+
$ bun add --dev bun-workspaces
|
|
31
|
+
$ # Start using the CLI with or without the installation step
|
|
32
|
+
$ bunx bun-workspaces --help
|
|
34
33
|
```
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
Note that you need to run `bun install` in your project for `bun-workspaces` to find your project's workspaces. This is because it reads `bun.lock`. This also means that if you update your workspaces, such as changing their name, you must run `bun install` for the change to reflect.
|
|
37
36
|
|
|
38
|
-
###
|
|
37
|
+
### CLI
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
[Full CLI documentation here](https://bunworkspaces.com/cli)
|
|
41
40
|
|
|
42
41
|
```bash
|
|
42
|
+
# You can add this to .bashrc, .zshrc, or similar.
|
|
43
|
+
# You can also invoke "bw" in your root package.json scripts.
|
|
43
44
|
alias bw="bunx bun-workspaces"
|
|
44
45
|
|
|
45
|
-
# List all workspaces
|
|
46
|
+
# List all workspaces in your project
|
|
46
47
|
bw list-workspaces
|
|
47
|
-
bw ls
|
|
48
48
|
|
|
49
|
-
#
|
|
50
|
-
bw
|
|
51
|
-
|
|
52
|
-
# Filter list of workspaces with wildcard
|
|
53
|
-
bw list-workspaces "my-*"
|
|
54
|
-
|
|
55
|
-
# List all workspace scripts
|
|
56
|
-
bw list-scripts
|
|
57
|
-
|
|
58
|
-
# List script names only
|
|
59
|
-
bw list-scripts --name-only
|
|
49
|
+
# ls is an alias for list-workspaces
|
|
50
|
+
bw ls --json --pretty # Output as formatted JSON
|
|
60
51
|
|
|
61
52
|
# Get info about a workspace
|
|
62
53
|
bw workspace-info my-workspace
|
|
63
|
-
bw info my-workspace
|
|
54
|
+
bw info my-workspace --json --pretty # info is alias for workspace-info
|
|
64
55
|
|
|
65
|
-
# Get info about a script
|
|
56
|
+
# Get info about a script, such as the workspaces that have it
|
|
66
57
|
bw script-info my-script
|
|
67
58
|
|
|
68
|
-
#
|
|
69
|
-
|
|
59
|
+
# Run the lint script for all workspaces
|
|
60
|
+
# that have it in their package.json "scripts" field
|
|
61
|
+
bw run-script lint
|
|
62
|
+
|
|
63
|
+
# run is an alias for run-script
|
|
64
|
+
bw run lint my-workspace # Run for a single workspace
|
|
65
|
+
bw run lint my-workspace-a my-workspace-b # Run for multiple workspaces
|
|
66
|
+
bw run lint my-alias-a my-alias-b # Run by alias (set by optional config)
|
|
70
67
|
|
|
71
|
-
#
|
|
72
|
-
bw
|
|
73
|
-
bw list-scripts --json
|
|
74
|
-
bw workspace-info my-workspace --json
|
|
75
|
-
bw script-info my-script --json
|
|
68
|
+
bw run lint "my-workspace-*" # Run for matching workspace names
|
|
69
|
+
bw run lint "alias:my-alias-pattern-*" "path:my-glob/**/*" # Use matching specifiers
|
|
76
70
|
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
|
|
80
|
-
bw run my-script
|
|
71
|
+
# A workspace's script will wait until any workspaces it depends on have completed
|
|
72
|
+
# Similar to Bun's --filter behavior
|
|
73
|
+
bw run lint --dep-order
|
|
81
74
|
|
|
82
|
-
#
|
|
83
|
-
bw run
|
|
75
|
+
# Continue running scripts even if a dependency fails
|
|
76
|
+
bw run lint --dep-order --ignore-dep-failure
|
|
84
77
|
|
|
85
|
-
#
|
|
86
|
-
bw run my-
|
|
78
|
+
bw run lint --args="--my-appended-args" # Add args to each script call
|
|
79
|
+
bw run lint --args="--my-arg=<workspaceName>" # Use the workspace name in args
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
bw run my-script "my-workspace-*"
|
|
81
|
+
bw run "bun build" --inline # Run an inline command via the Bun shell
|
|
90
82
|
|
|
91
|
-
#
|
|
92
|
-
bw run
|
|
83
|
+
# Scripts run in parallel by default
|
|
84
|
+
bw run lint --parallel=false # Run in series
|
|
85
|
+
bw run lint --parallel=2 # Run in parallel with a max of 2 concurrent scripts
|
|
86
|
+
bw run lint --parallel=auto # Default, based on number of available logical CPUs
|
|
93
87
|
|
|
94
|
-
#
|
|
95
|
-
bw run my-script --
|
|
88
|
+
# Use the grouped output style (default when on a TTY)
|
|
89
|
+
bw run my-script --output-style=grouped
|
|
96
90
|
|
|
97
|
-
#
|
|
98
|
-
bw run my-script --
|
|
91
|
+
# Set the max preview lines for script output in grouped output style
|
|
92
|
+
bw run my-script --output-style=grouped --grouped-lines=all
|
|
93
|
+
bw run my-script --output-style=grouped --grouped-lines=10
|
|
99
94
|
|
|
100
|
-
#
|
|
95
|
+
# Use simple script output with workspace prefixes (default when not on a TTY)
|
|
96
|
+
bw run my-script --output-style=prefixed
|
|
97
|
+
|
|
98
|
+
# Use the plain output style (no workspace prefixes)
|
|
99
|
+
bw run my-script --output-style=plain
|
|
100
|
+
|
|
101
|
+
# Show usage (you can pass --help to any command)
|
|
101
102
|
bw help
|
|
102
103
|
bw --help
|
|
103
104
|
|
|
105
|
+
# Show version
|
|
106
|
+
bw --version
|
|
107
|
+
|
|
104
108
|
# Pass --cwd to any command
|
|
105
|
-
bw --cwd
|
|
106
|
-
bw --cwd
|
|
109
|
+
bw --cwd=/path/to/your/project ls
|
|
110
|
+
bw --cwd=/path/to/your/project run my-script
|
|
107
111
|
|
|
108
|
-
# Pass --
|
|
109
|
-
bw --
|
|
112
|
+
# Pass --log-level to any command (debug, info, warn, error, or silent)
|
|
113
|
+
bw --log-level=silent run my-script
|
|
114
|
+
```
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
### API
|
|
117
|
+
|
|
118
|
+
[Full API documentation here](https://bunworkspaces.com/api)
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { createFileSystemProject } from "bun-workspaces";
|
|
122
|
+
|
|
123
|
+
// A Project contains the core functionality of bun-workspaces.
|
|
124
|
+
// Below defaults to process.cwd() for the project root directory
|
|
125
|
+
// Pass { rootDirectory: "path/to/your/project" } to use a different root directory
|
|
126
|
+
const project = createFileSystemProject();
|
|
127
|
+
|
|
128
|
+
// A Workspace that matches the name or alias "my-workspace"
|
|
129
|
+
const myWorkspace = project.findWorkspaceByNameOrAlias("my-workspace");
|
|
130
|
+
|
|
131
|
+
// Array of workspaces whose names match the wildcard pattern
|
|
132
|
+
const wildcardWorkspaces = project.findWorkspacesByPattern("my-workspace-*");
|
|
133
|
+
|
|
134
|
+
// Array of workspaces that have "my-script" in their package.json "scripts"
|
|
135
|
+
const workspacesWithScript = project.listWorkspacesWithScript("my-script");
|
|
136
|
+
|
|
137
|
+
// Run a script in a workspace
|
|
138
|
+
const runSingleScript = async () => {
|
|
139
|
+
const { output, exit } = project.runWorkspaceScript({
|
|
140
|
+
workspaceNameOrAlias: "my-workspace",
|
|
141
|
+
script: "my-script",
|
|
142
|
+
args: "--my --appended --args", // optional, arguments to add to the command
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Get a stream of the script subprocess's output
|
|
146
|
+
for await (const { chunk, metadata } of output.text()) {
|
|
147
|
+
// console.log(chunk); // the content (string)
|
|
148
|
+
// console.log(metadata.streamName); // "stdout" or "stderr"
|
|
149
|
+
// console.log(metadata.workspace); // the workspace that the output came from
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Get data about the script execution after it exits
|
|
153
|
+
const exitResult = await exit;
|
|
154
|
+
|
|
155
|
+
// exitResult.exitCode // The exit code (number)
|
|
156
|
+
// exitResult.signal // The exit signal (string), or null
|
|
157
|
+
// exitResult.success // true if exit code was 0
|
|
158
|
+
// exitResult.startTimeISO // Start time (string)
|
|
159
|
+
// exitResult.endTimeISO // End time (string)
|
|
160
|
+
// exitResult.durationMs // Duration in milliseconds (number)
|
|
161
|
+
// exitResult.metadata.workspace // The target workspace (Workspace)
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// Run a script in all workspaces that have it in their package.json "scripts" field
|
|
165
|
+
const runManyScripts = async () => {
|
|
166
|
+
const { output, summary } = project.runScriptAcrossWorkspaces({
|
|
167
|
+
// Optional. This will run in all matching workspaces that have my-script
|
|
168
|
+
// Accepts same values as the CLI run-script command's workspace patterns
|
|
169
|
+
// When not provided, all workspaces that have the script will be used.
|
|
170
|
+
workspacePatterns: ["my-workspace", "my-name-pattern-*"],
|
|
171
|
+
|
|
172
|
+
// Required. The package.json "scripts" field name to run
|
|
173
|
+
script: "my-script",
|
|
174
|
+
|
|
175
|
+
// Optional. Arguments to add to the command
|
|
176
|
+
args: "--my --appended --args",
|
|
177
|
+
|
|
178
|
+
// Optional. Whether to run the scripts in parallel (default: true)
|
|
179
|
+
parallel: true,
|
|
180
|
+
|
|
181
|
+
// Optional. When true, a workspace's script will wait
|
|
182
|
+
// until any workspaces it depends on have completed
|
|
183
|
+
dependencyOrder: false,
|
|
184
|
+
|
|
185
|
+
// Optional. When true and dependencyOrder is true,
|
|
186
|
+
// continue running scripts even if a dependency fails
|
|
187
|
+
ignoreDependencyFailure: false,
|
|
188
|
+
|
|
189
|
+
// Optional, callback when script starts, skips, or exits
|
|
190
|
+
onScriptEvent: (event, { workspace, exitResult }) => {
|
|
191
|
+
// event: "start", "skip", "exit"
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Get a stream of script output
|
|
196
|
+
for await (const { chunk, metadata } of output.text()) {
|
|
197
|
+
// console.log(chunk); // the content (string)
|
|
198
|
+
// console.log(metadata.streamName); // "stdout" or "stderr"
|
|
199
|
+
// console.log(metadata.workspace); // the workspace that the output came from
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Get final summary data and script exit details after all scripts have completed
|
|
203
|
+
const summaryResult = await summary;
|
|
204
|
+
|
|
205
|
+
// summaryResult.totalCount // Total number of scripts
|
|
206
|
+
// summaryResult.allSuccess // true if all scripts succeeded
|
|
207
|
+
// summaryResult.successCount // Number of scripts that succeeded
|
|
208
|
+
// summaryResult.failureCount // Number of scripts that failed
|
|
209
|
+
// summaryResult.startTimeISO // Start time (string)
|
|
210
|
+
// summaryResult.endTimeISO // End time (string)
|
|
211
|
+
// summaryResult.durationMs // Total duration in milliseconds (number)
|
|
212
|
+
|
|
213
|
+
// The exit details of each workspace script
|
|
214
|
+
for (const exitResult of summaryResult.scriptResults) {
|
|
215
|
+
// exitResult.exitCode // The exit code (number)
|
|
216
|
+
// exitResult.signal // The exit signal (string), or null
|
|
217
|
+
// exitResult.success // true if exit code was 0
|
|
218
|
+
// exitResult.startTimeISO // Start time (ISO string)
|
|
219
|
+
// exitResult.endTimeISO // End time (ISO string)
|
|
220
|
+
// exitResult.durationMs // Duration in milliseconds (number)
|
|
221
|
+
// exitResult.metadata.workspace // The target workspace (Workspace)
|
|
222
|
+
}
|
|
223
|
+
};
|
|
113
224
|
```
|
|
225
|
+
|
|
226
|
+
_`bun-workspaces` is independent from the [Bun](https://bun.sh) project and is not affiliated with or endorsed by Anthropic. This project aims to enhance the experience of Bun for its users._
|
|
227
|
+
|
|
228
|
+
Developed By:
|
|
229
|
+
|
|
230
|
+
<a href="https://smorsic.io" target="_blank" rel="noopener noreferrer">
|
|
231
|
+
<img src="./packages/doc-website/src/pages/public/images/png/smorsic-banner_light_803x300.png" alt="Smorsic Labs logo" width="280" />
|
|
232
|
+
</a>
|
package/bin/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -1,40 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-workspaces",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "A monorepo management tool for Bun, with a CLI and API to enhance Bun's native workspaces.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "src/index.mjs",
|
|
7
|
+
"types": "src/index.d.ts",
|
|
8
|
+
"homepage": "https://bunworkspaces.com",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/bun-workspaces/bun-workspaces.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"bun",
|
|
15
|
+
"workspace",
|
|
16
|
+
"workspaces",
|
|
17
|
+
"monorepo",
|
|
18
|
+
"cli",
|
|
19
|
+
"api"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"bun": "^1.2.0"
|
|
23
|
+
},
|
|
6
24
|
"bin": {
|
|
7
|
-
"bun-workspaces": "bin/cli.js"
|
|
25
|
+
"bun-workspaces": "bin/cli.js",
|
|
26
|
+
"bw": "bin/cli.js"
|
|
8
27
|
},
|
|
9
|
-
"
|
|
28
|
+
"_bwInternal": {
|
|
10
29
|
"bunVersion": {
|
|
11
|
-
"build": "1.
|
|
12
|
-
"libraryConsumer": "^1.
|
|
30
|
+
"build": "1.3.5",
|
|
31
|
+
"libraryConsumer": "^1.2.0"
|
|
13
32
|
}
|
|
14
33
|
},
|
|
15
|
-
"scripts": {
|
|
16
|
-
"cli": "bun run bin/cli.js",
|
|
17
|
-
"cli:dev": "_BW_RUNTIME_MODE=development bun run bin/cli.js",
|
|
18
|
-
"type-check": "tsc --noEmit",
|
|
19
|
-
"lint": "eslint .",
|
|
20
|
-
"format": "prettier --write .",
|
|
21
|
-
"format-check": "prettier --check ."
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@types/bun": "^1.2.22",
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "^8.44.1",
|
|
26
|
-
"@typescript-eslint/parser": "^8.44.1",
|
|
27
|
-
"bun-workspaces": "file:.",
|
|
28
|
-
"eslint": "^9.36.0",
|
|
29
|
-
"eslint-plugin-import": "^2.32.0",
|
|
30
|
-
"prettier": "^3.6.2",
|
|
31
|
-
"typescript-eslint": "^8.44.1"
|
|
32
|
-
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"commander": "^12.1.0"
|
|
35
|
-
"glob": "^11.0.3"
|
|
36
|
-
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"typescript": "^5.9.2"
|
|
35
|
+
"commander": "^12.1.0"
|
|
39
36
|
}
|
|
40
37
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Command } from "commander";
|
|
2
|
+
import type { FileSystemProject } from "../../project/implementations/fileSystemProject";
|
|
3
|
+
import type { Workspace } from "../../workspaces";
|
|
4
|
+
import type { WriteOutputOptions } from "../createCli";
|
|
5
|
+
import type { CliMiddleware } from "../middleware";
|
|
6
|
+
import {
|
|
7
|
+
type CliGlobalCommandName,
|
|
8
|
+
type CliProjectCommandName,
|
|
9
|
+
} from "./commandsConfig";
|
|
10
|
+
/** @todo DRY use of output text in cases such as having no workspaces/scripts */
|
|
11
|
+
export type GlobalCommandContext = {
|
|
12
|
+
program: Command;
|
|
13
|
+
postTerminatorArgs: string[];
|
|
14
|
+
middleware: CliMiddleware;
|
|
15
|
+
outputWriters: Required<WriteOutputOptions>;
|
|
16
|
+
terminalWidth: number;
|
|
17
|
+
};
|
|
18
|
+
export type ProjectCommandContext = GlobalCommandContext & {
|
|
19
|
+
project: FileSystemProject;
|
|
20
|
+
projectError: Error | null;
|
|
21
|
+
};
|
|
22
|
+
/** Splits workspace patterns by whitespace, but allows escaping spaces via backslash */
|
|
23
|
+
export declare const splitWorkspacePatterns: (
|
|
24
|
+
workspacePatterns: string,
|
|
25
|
+
) => string[];
|
|
26
|
+
export declare const createWorkspaceInfoLines: (
|
|
27
|
+
workspace: Workspace,
|
|
28
|
+
) => string[];
|
|
29
|
+
export declare const createScriptInfoLines: (
|
|
30
|
+
script: string,
|
|
31
|
+
workspaces: Workspace[],
|
|
32
|
+
) => string[];
|
|
33
|
+
export declare const createJsonLines: (
|
|
34
|
+
data: unknown,
|
|
35
|
+
options: {
|
|
36
|
+
pretty: boolean;
|
|
37
|
+
},
|
|
38
|
+
) => string[];
|
|
39
|
+
export declare const commandOutputLogger: import("../../internal/logger").Logger;
|
|
40
|
+
export declare const handleGlobalCommand: <ActionArgs extends unknown[]>(
|
|
41
|
+
commandName: CliGlobalCommandName,
|
|
42
|
+
handler: (context: GlobalCommandContext, ...actionArgs: ActionArgs) => void,
|
|
43
|
+
) => (context: GlobalCommandContext) => Command;
|
|
44
|
+
export declare const handleProjectCommand: <ActionArgs extends unknown[]>(
|
|
45
|
+
commandName: CliProjectCommandName,
|
|
46
|
+
handler: (
|
|
47
|
+
context: Omit<ProjectCommandContext, "projectError">,
|
|
48
|
+
...actionArgs: ActionArgs
|
|
49
|
+
) => void,
|
|
50
|
+
) => (context: ProjectCommandContext) => Command;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Option } from "commander";
|
|
2
|
+
import { BunWorkspacesError } from "../../internal/core/error/index.mjs";
|
|
3
|
+
import { createLogger, logger } from "../../internal/logger/index.mjs";
|
|
4
|
+
import { getCliCommandConfig } from "./commandsConfig.mjs"; // CONCATENATED MODULE: external "commander"
|
|
5
|
+
// CONCATENATED MODULE: external "../../internal/core/error/index.mjs"
|
|
6
|
+
// CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
7
|
+
// CONCATENATED MODULE: external "./commandsConfig.mjs"
|
|
8
|
+
// CONCATENATED MODULE: ./src/cli/commands/commandHandlerUtils.ts
|
|
9
|
+
|
|
10
|
+
/** Splits workspace patterns by whitespace, but allows escaping spaces via backslash */ const splitWorkspacePatterns =
|
|
11
|
+
(workspacePatterns) =>
|
|
12
|
+
workspacePatterns
|
|
13
|
+
.split(/(?<!\\)\s+/)
|
|
14
|
+
.filter(Boolean)
|
|
15
|
+
.map((pattern) => pattern.replace(/\\\s/g, " "));
|
|
16
|
+
const createWorkspaceInfoLines = (workspace) => [
|
|
17
|
+
`Workspace: ${workspace.name}${workspace.isRoot ? " (root)" : ""}`,
|
|
18
|
+
` - Aliases: ${workspace.aliases.join(", ")}`,
|
|
19
|
+
` - Path: ${workspace.path}`,
|
|
20
|
+
` - Glob Match: ${workspace.matchPattern}`,
|
|
21
|
+
` - Scripts: ${workspace.scripts.join(", ")}`,
|
|
22
|
+
` - Dependencies: ${workspace.dependencies.join(", ")}`,
|
|
23
|
+
` - Dependents: ${workspace.dependents.join(", ")}`,
|
|
24
|
+
];
|
|
25
|
+
const createScriptInfoLines = (script, workspaces) => [
|
|
26
|
+
`Script: ${script}`,
|
|
27
|
+
...workspaces.map((workspace) => ` - ${workspace.name}`),
|
|
28
|
+
];
|
|
29
|
+
const createJsonLines = (data, options) =>
|
|
30
|
+
JSON.stringify(data, null, options.pretty ? 2 : undefined).split("\n");
|
|
31
|
+
const commandOutputLogger = createLogger("");
|
|
32
|
+
commandOutputLogger.printLevel = "info";
|
|
33
|
+
const handleCommand = (commandName, handler) => (context) => {
|
|
34
|
+
const config = getCliCommandConfig(commandName);
|
|
35
|
+
let { program } = context;
|
|
36
|
+
program = program
|
|
37
|
+
.command(config.command)
|
|
38
|
+
.aliases(config.aliases)
|
|
39
|
+
.description(config.description);
|
|
40
|
+
for (const { flags, description, values } of Object.values(config.options)) {
|
|
41
|
+
const option = new Option(flags.join(", "), description);
|
|
42
|
+
if (values?.length) {
|
|
43
|
+
option.choices(values);
|
|
44
|
+
}
|
|
45
|
+
program.addOption(option);
|
|
46
|
+
}
|
|
47
|
+
program = program.action(async (...actionArgs) => {
|
|
48
|
+
try {
|
|
49
|
+
logger.debug(`Handling command: ${commandName}`);
|
|
50
|
+
const middlewareContext = {
|
|
51
|
+
commanderProgram: program,
|
|
52
|
+
commandName,
|
|
53
|
+
commandContext: context,
|
|
54
|
+
commanderActionArgs: actionArgs,
|
|
55
|
+
};
|
|
56
|
+
program = context.middleware.preHandleCommand(middlewareContext);
|
|
57
|
+
await handler(context, ...actionArgs);
|
|
58
|
+
program = context.middleware.postHandleCommand(middlewareContext);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
context.middleware.catchError(error);
|
|
61
|
+
if (error instanceof BunWorkspacesError) {
|
|
62
|
+
logger.error(error.message);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return program;
|
|
69
|
+
};
|
|
70
|
+
const handleGlobalCommand = (commandName, handler) => (context) =>
|
|
71
|
+
handleCommand(commandName, handler)(context);
|
|
72
|
+
const handleProjectCommand = (commandName, handler) => (context) =>
|
|
73
|
+
handleCommand(commandName, async (context, ...actionArgs) => {
|
|
74
|
+
const { projectError } = context;
|
|
75
|
+
if (projectError) {
|
|
76
|
+
context.middleware.catchError(projectError);
|
|
77
|
+
logger.error(projectError.message);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
await handler(context, ...actionArgs);
|
|
81
|
+
})(context);
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
commandOutputLogger,
|
|
85
|
+
createJsonLines,
|
|
86
|
+
createScriptInfoLines,
|
|
87
|
+
createWorkspaceInfoLines,
|
|
88
|
+
handleGlobalCommand,
|
|
89
|
+
handleProjectCommand,
|
|
90
|
+
splitWorkspacePatterns,
|
|
91
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GlobalCommandContext,
|
|
3
|
+
ProjectCommandContext,
|
|
4
|
+
} from "./commandHandlerUtils";
|
|
5
|
+
export declare const defineGlobalCommands: (
|
|
6
|
+
context: GlobalCommandContext,
|
|
7
|
+
) => void;
|
|
8
|
+
export declare const defineProjectCommands: (
|
|
9
|
+
context: ProjectCommandContext,
|
|
10
|
+
) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
doctor,
|
|
3
|
+
listScripts,
|
|
4
|
+
listWorkspaces,
|
|
5
|
+
scriptInfo,
|
|
6
|
+
workspaceInfo,
|
|
7
|
+
} from "./handleSimpleCommands.mjs";
|
|
8
|
+
import { runScript } from "./runScript/index.mjs"; // CONCATENATED MODULE: external "./handleSimpleCommands.mjs"
|
|
9
|
+
// CONCATENATED MODULE: external "./runScript/index.mjs"
|
|
10
|
+
// CONCATENATED MODULE: ./src/cli/commands/commands.ts
|
|
11
|
+
|
|
12
|
+
const defineGlobalCommands = (context) => {
|
|
13
|
+
doctor(context);
|
|
14
|
+
};
|
|
15
|
+
const defineProjectCommands = (context) => {
|
|
16
|
+
listWorkspaces(context);
|
|
17
|
+
listScripts(context);
|
|
18
|
+
workspaceInfo(context);
|
|
19
|
+
scriptInfo(context);
|
|
20
|
+
runScript(context);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { defineGlobalCommands, defineProjectCommands };
|