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.
Files changed (238) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +189 -70
  3. package/bin/cli.js +1 -2
  4. package/package.json +27 -30
  5. package/src/cli/commands/commandHandlerUtils.d.ts +49 -0
  6. package/src/cli/commands/commandHandlerUtils.mjs +91 -0
  7. package/src/cli/commands/commands.d.ts +10 -0
  8. package/src/cli/commands/commands.mjs +23 -0
  9. package/src/cli/commands/commandsConfig.d.ts +351 -0
  10. package/src/cli/commands/commandsConfig.mjs +183 -0
  11. package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
  12. package/src/cli/commands/handleSimpleCommands.mjs +174 -0
  13. package/src/cli/commands/index.d.ts +3 -0
  14. package/src/cli/commands/index.mjs +3 -0
  15. package/src/cli/commands/runScript/handleRunScript.d.ts +3 -0
  16. package/src/cli/commands/runScript/handleRunScript.mjs +249 -0
  17. package/src/cli/commands/runScript/index.d.ts +2 -0
  18. package/src/cli/commands/runScript/index.mjs +2 -0
  19. package/src/cli/commands/runScript/output/index.d.ts +1 -0
  20. package/src/cli/commands/runScript/output/index.mjs +1 -0
  21. package/src/cli/commands/runScript/output/outputStyle.d.ts +8 -0
  22. package/src/cli/commands/runScript/output/outputStyle.mjs +17 -0
  23. package/src/cli/commands/runScript/output/renderGroupedOutput.d.ts +73 -0
  24. package/src/cli/commands/runScript/output/renderGroupedOutput.mjs +308 -0
  25. package/src/cli/commands/runScript/output/renderPlainOutput.d.ts +24 -0
  26. package/src/cli/commands/runScript/output/renderPlainOutput.mjs +44 -0
  27. package/src/cli/commands/runScript/output/sanitizeChunk.d.ts +4 -0
  28. package/src/cli/commands/runScript/output/sanitizeChunk.mjs +101 -0
  29. package/src/cli/createCli.d.ts +25 -0
  30. package/src/cli/createCli.mjs +154 -0
  31. package/src/cli/fatalErrorLogger.d.ts +1 -0
  32. package/src/cli/fatalErrorLogger.mjs +7 -0
  33. package/src/cli/globalOptions/globalOptions.d.ts +40 -0
  34. package/src/cli/globalOptions/globalOptions.mjs +105 -0
  35. package/src/cli/globalOptions/globalOptionsConfig.d.ts +43 -0
  36. package/src/cli/globalOptions/globalOptionsConfig.mjs +34 -0
  37. package/src/cli/globalOptions/index.d.ts +2 -0
  38. package/src/cli/globalOptions/index.mjs +2 -0
  39. package/src/cli/index.d.ts +3 -0
  40. package/src/cli/index.mjs +3 -0
  41. package/src/cli/middleware.d.ts +72 -0
  42. package/src/cli/middleware.mjs +38 -0
  43. package/src/config/index.d.ts +3 -0
  44. package/src/config/index.mjs +3 -0
  45. package/src/config/rootConfig/errors.d.ts +1 -0
  46. package/src/config/rootConfig/errors.mjs +6 -0
  47. package/src/config/rootConfig/index.d.ts +5 -0
  48. package/src/config/rootConfig/index.mjs +5 -0
  49. package/src/config/rootConfig/loadRootConfig.d.ts +3 -0
  50. package/src/config/rootConfig/loadRootConfig.mjs +22 -0
  51. package/src/config/rootConfig/rootConfig.d.ts +17 -0
  52. package/src/config/rootConfig/rootConfig.mjs +43 -0
  53. package/src/config/rootConfig/rootConfigLocation.d.ts +2 -0
  54. package/src/config/rootConfig/rootConfigLocation.mjs +5 -0
  55. package/src/config/rootConfig/rootConfigSchema.d.ts +21 -0
  56. package/src/config/rootConfig/rootConfigSchema.mjs +24 -0
  57. package/src/config/userEnvVars/index.d.ts +1 -0
  58. package/src/config/userEnvVars/index.mjs +1 -0
  59. package/src/config/userEnvVars/userEnvVars.d.ts +13 -0
  60. package/src/config/userEnvVars/userEnvVars.mjs +10 -0
  61. package/src/config/util/ajvTypes.d.ts +10 -0
  62. package/src/config/util/ajvTypes.mjs +2 -0
  63. package/src/config/util/configLocation.d.ts +12 -0
  64. package/src/config/util/configLocation.mjs +11 -0
  65. package/src/config/util/index.d.ts +4 -0
  66. package/src/config/util/index.mjs +3 -0
  67. package/src/config/util/loadConfig.d.ts +16 -0
  68. package/src/config/util/loadConfig.mjs +118 -0
  69. package/src/config/util/validateConfig.d.ts +8 -0
  70. package/src/config/util/validateConfig.mjs +17 -0
  71. package/src/config/workspaceConfig/errors.d.ts +1 -0
  72. package/src/config/workspaceConfig/errors.mjs +6 -0
  73. package/src/config/workspaceConfig/index.d.ts +5 -0
  74. package/src/config/workspaceConfig/index.mjs +5 -0
  75. package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +3 -0
  76. package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +25 -0
  77. package/src/config/workspaceConfig/workspaceConfig.d.ts +22 -0
  78. package/src/config/workspaceConfig/workspaceConfig.mjs +31 -0
  79. package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
  80. package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
  81. package/src/config/workspaceConfig/workspaceConfigSchema.d.ts +25 -0
  82. package/src/config/workspaceConfig/workspaceConfigSchema.mjs +28 -0
  83. package/src/doctor/doctor.d.ts +35 -0
  84. package/src/doctor/doctor.mjs +52 -0
  85. package/src/doctor/index.d.ts +1 -0
  86. package/src/doctor/index.mjs +1 -0
  87. package/src/index.d.ts +37 -0
  88. package/src/index.mjs +16 -0
  89. package/src/internal/bun/bunLock.d.ts +20 -0
  90. package/src/internal/bun/bunLock.mjs +70 -0
  91. package/src/internal/bun/bunVersion.d.ts +21 -0
  92. package/src/internal/bun/bunVersion.mjs +43 -0
  93. package/src/internal/bun/index.d.ts +2 -0
  94. package/src/internal/bun/index.mjs +2 -0
  95. package/src/internal/core/error/error.d.ts +13 -0
  96. package/src/internal/{error.ts → core/error/error.mjs} +16 -18
  97. package/src/internal/core/error/index.d.ts +1 -0
  98. package/src/internal/core/error/index.mjs +1 -0
  99. package/src/internal/core/index.d.ts +4 -0
  100. package/src/internal/core/index.mjs +4 -0
  101. package/src/internal/core/json/index.d.ts +2 -0
  102. package/src/internal/core/json/index.mjs +2 -0
  103. package/src/internal/core/json/json.d.ts +49 -0
  104. package/src/internal/core/json/json.mjs +12 -0
  105. package/src/internal/core/json/jsonc.d.ts +9 -0
  106. package/src/internal/core/json/jsonc.mjs +117 -0
  107. package/src/internal/core/language/array/index.d.ts +1 -0
  108. package/src/internal/core/language/array/index.mjs +1 -0
  109. package/src/internal/core/language/array/optionalArray.d.ts +15 -0
  110. package/src/internal/core/language/array/optionalArray.mjs +8 -0
  111. package/src/internal/core/language/asyncIterable/asyncIterableQueue.d.ts +16 -0
  112. package/src/internal/core/language/asyncIterable/asyncIterableQueue.mjs +81 -0
  113. package/src/internal/core/language/asyncIterable/index.d.ts +2 -0
  114. package/src/internal/core/language/asyncIterable/index.mjs +2 -0
  115. package/src/internal/core/language/asyncIterable/mergeAsyncIterables.d.ts +5 -0
  116. package/src/internal/core/language/asyncIterable/mergeAsyncIterables.mjs +27 -0
  117. package/src/internal/core/language/events/typedEventTarget.d.ts +50 -0
  118. package/src/internal/core/language/events/typedEventTarget.mjs +14 -0
  119. package/src/internal/core/language/index.d.ts +5 -0
  120. package/src/internal/core/language/index.mjs +5 -0
  121. package/src/internal/core/language/regex/index.d.ts +1 -0
  122. package/src/internal/core/language/regex/index.mjs +1 -0
  123. package/src/internal/core/language/regex/regex.d.ts +3 -0
  124. package/src/internal/core/language/regex/regex.mjs +10 -0
  125. package/src/internal/core/language/string/id.d.ts +1 -0
  126. package/src/internal/core/language/string/id.mjs +10 -0
  127. package/src/internal/core/language/string/index.d.ts +1 -0
  128. package/src/internal/core/language/string/index.mjs +1 -0
  129. package/src/internal/core/language/string/utf/eastAsianWidth.d.ts +16 -0
  130. package/src/internal/core/language/string/utf/eastAsianWidth.mjs +326 -0
  131. package/src/internal/core/language/string/utf/visibleLength.d.ts +5 -0
  132. package/src/internal/core/language/string/utf/visibleLength.mjs +29 -0
  133. package/src/internal/core/language/types/index.d.ts +2 -0
  134. package/src/internal/core/language/types/index.mjs +1 -0
  135. package/src/internal/core/language/types/typeof.d.ts +102 -0
  136. package/src/internal/core/language/types/typeof.mjs +123 -0
  137. package/src/internal/core/language/types/types.d.ts +14 -0
  138. package/src/internal/core/language/types/types.mjs +2 -0
  139. package/src/internal/core/runtime/env.d.ts +6 -0
  140. package/src/internal/core/runtime/env.mjs +36 -0
  141. package/src/internal/core/runtime/index.d.ts +5 -0
  142. package/src/internal/core/runtime/index.mjs +5 -0
  143. package/src/internal/core/runtime/onExit.d.ts +4 -0
  144. package/src/internal/core/runtime/onExit.mjs +54 -0
  145. package/src/internal/core/runtime/os.d.ts +4 -0
  146. package/src/internal/core/runtime/os.mjs +7 -0
  147. package/src/internal/core/runtime/tempFile.d.ts +20 -0
  148. package/src/internal/core/runtime/tempFile.mjs +87 -0
  149. package/src/internal/core/runtime/terminal.d.ts +1 -0
  150. package/src/internal/core/runtime/terminal.mjs +4 -0
  151. package/src/internal/generated/ajv/validateRootConfig.mjs +1 -0
  152. package/src/internal/generated/ajv/validateWorkspaceConfig.mjs +1 -0
  153. package/src/internal/logger/index.d.ts +1 -0
  154. package/src/internal/logger/index.mjs +1 -0
  155. package/src/internal/logger/logger.d.ts +45 -0
  156. package/src/internal/logger/logger.mjs +133 -0
  157. package/src/internal/version.d.ts +1 -0
  158. package/src/internal/version.mjs +6 -0
  159. package/src/project/errors.d.ts +5 -0
  160. package/src/project/errors.mjs +10 -0
  161. package/src/project/implementations/fileSystemProject.d.ts +148 -0
  162. package/src/project/implementations/fileSystemProject.mjs +455 -0
  163. package/src/project/implementations/memoryProject.d.ts +41 -0
  164. package/src/project/implementations/memoryProject.mjs +148 -0
  165. package/src/project/implementations/projectBase.d.ts +35 -0
  166. package/src/project/implementations/projectBase.mjs +197 -0
  167. package/src/project/index.d.ts +5 -0
  168. package/src/project/index.mjs +4 -0
  169. package/src/project/project.d.ts +75 -0
  170. package/src/project/project.mjs +6 -0
  171. package/src/runScript/index.d.ts +7 -0
  172. package/src/runScript/index.mjs +7 -0
  173. package/src/runScript/output/index.d.ts +3 -0
  174. package/src/runScript/output/index.mjs +2 -0
  175. package/src/runScript/output/multiProcessOutput.d.ts +14 -0
  176. package/src/runScript/output/multiProcessOutput.mjs +21 -0
  177. package/src/runScript/output/outputStream.d.ts +1 -0
  178. package/src/runScript/output/outputStream.mjs +1 -0
  179. package/src/runScript/output/processOutput.d.ts +33 -0
  180. package/src/runScript/output/processOutput.mjs +124 -0
  181. package/src/runScript/parallel.d.ts +15 -0
  182. package/src/runScript/parallel.mjs +56 -0
  183. package/src/runScript/recursion.d.ts +4 -0
  184. package/src/runScript/recursion.mjs +17 -0
  185. package/src/runScript/runScript.d.ts +45 -0
  186. package/src/runScript/runScript.mjs +89 -0
  187. package/src/runScript/runScripts.d.ts +65 -0
  188. package/src/runScript/runScripts.mjs +263 -0
  189. package/src/runScript/scriptCommand.d.ts +33 -0
  190. package/src/runScript/scriptCommand.mjs +19 -0
  191. package/src/runScript/scriptExecution.d.ts +9 -0
  192. package/src/runScript/scriptExecution.mjs +50 -0
  193. package/src/runScript/scriptRuntimeMetadata.d.ts +73 -0
  194. package/src/runScript/scriptRuntimeMetadata.mjs +61 -0
  195. package/src/runScript/scriptShellOption.d.ts +8 -0
  196. package/src/runScript/scriptShellOption.mjs +39 -0
  197. package/src/runScript/subprocesses.d.ts +11 -0
  198. package/src/runScript/subprocesses.mjs +34 -0
  199. package/src/workspaces/dependencyGraph/cycles.d.ts +9 -0
  200. package/src/workspaces/dependencyGraph/cycles.mjs +91 -0
  201. package/src/workspaces/dependencyGraph/index.d.ts +2 -0
  202. package/src/workspaces/dependencyGraph/index.mjs +2 -0
  203. package/src/workspaces/dependencyGraph/resolveDependencies.d.ts +18 -0
  204. package/src/workspaces/dependencyGraph/resolveDependencies.mjs +52 -0
  205. package/src/workspaces/errors.d.ts +13 -0
  206. package/src/workspaces/errors.mjs +18 -0
  207. package/src/workspaces/findWorkspaces.d.ts +24 -0
  208. package/src/workspaces/findWorkspaces.mjs +217 -0
  209. package/src/workspaces/index.d.ts +4 -0
  210. package/src/workspaces/index.mjs +3 -0
  211. package/src/workspaces/packageJson.d.ts +31 -0
  212. package/src/workspaces/packageJson.mjs +188 -0
  213. package/src/workspaces/{workspace.ts → workspace.d.ts} +11 -6
  214. package/src/workspaces/workspace.mjs +2 -0
  215. package/src/workspaces/workspacePattern.d.ts +21 -0
  216. package/src/workspaces/workspacePattern.mjs +104 -0
  217. package/bun.lock +0 -576
  218. package/src/cli/cli.ts +0 -87
  219. package/src/cli/globalOptions.ts +0 -122
  220. package/src/cli/index.ts +0 -1
  221. package/src/cli/projectCommands.ts +0 -396
  222. package/src/config/bunWorkspacesConfig.ts +0 -62
  223. package/src/config/configFile.ts +0 -33
  224. package/src/config/index.ts +0 -7
  225. package/src/index.ts +0 -3
  226. package/src/internal/bunVersion.ts +0 -26
  227. package/src/internal/env.ts +0 -25
  228. package/src/internal/logger.ts +0 -145
  229. package/src/internal/regex.ts +0 -5
  230. package/src/project/errors.ts +0 -6
  231. package/src/project/index.ts +0 -6
  232. package/src/project/project.ts +0 -155
  233. package/src/project/scriptCommand.ts +0 -40
  234. package/src/workspaces/errors.ts +0 -14
  235. package/src/workspaces/findWorkspaces.ts +0 -137
  236. package/src/workspaces/index.ts +0 -7
  237. package/src/workspaces/packageJson.ts +0 -166
  238. package/tsconfig.json +0 -28
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Scott Morse
3
+ Copyright (c) 2026 Smorsic Labs, LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- This is a CLI meant to help manage [Bun workspaces](https://bun.sh/docs/install/workspaces).
7
+ ### [**See Full Documentation Here**: _https://bunworkspaces.com_](https://bunworkspaces.com)
4
8
 
5
- ## Installation
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
- You can install the CLI in your project or simply use `bunx bun-workspaces`.
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
- ```bash
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
- ### Config file
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
- You can create a config file at `bw.json` in your project root, or you can pass a config file to the CLI with the `--configFile` (or `-c`) option.
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
- #### Example config
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
- In this config, "app-a" is an alias for package "@my-org/application-a" and "app-b" is an alias for package "@my-org/application-b".
24
+ ## Quick Start
21
25
 
22
- CLI log levels are `debug`, `info`, `warn`, and `error` or `silent`. The default log level is `info`. Commands that are intended to print specific output will still print at `silent`, such as `list-workspaces`, `list-scripts`, `workspace-info`, `script-info`, etc., but other logs will be suppressed.
26
+ Installation:
23
27
 
24
- ```json
25
- {
26
- "workspaceAliases": {
27
- "app-a": "@my-org/application-a",
28
- "app-b": "@my-org/application-b"
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
- You can also pass a config file to the CLI with the `-c` or `--configFile` option.
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
- ### Examples
37
+ ### CLI
39
38
 
40
- You might consider making a shorter alias in your `.bashrc`, `.zshrc`, or similar shell configuration file, such as `alias bw="bunx bun-workspaces"`, for convenience.
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
- # List workspace names only
50
- bw list-workspaces --name-only
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
- # Only print list of workspace names that have the script
69
- bw script-info my-script --workspaces-only
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
- # Get JSON output
72
- bw list-workspaces --json --pretty # optionally pretty print JSON
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
- # Run a script for all
78
- # workspaces that have it
79
- # in their `scripts` field
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
- # Run a script for a specific workspace by its package.json name or alias from the config
83
- bw run my-script my-workspace
75
+ # Continue running scripts even if a dependency fails
76
+ bw run lint --dep-order --ignore-dep-failure
84
77
 
85
- # Run a script for multiple workspaces
86
- bw run my-script workspace-a workspace-b
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
- # Run a script for workspaces using wildcard (does not take into account workspace aliases)
89
- bw run my-script "my-workspace-*"
81
+ bw run "bun build" --inline # Run an inline command via the Bun shell
90
82
 
91
- # Run script in parallel for all workspaces
92
- bw run my-script --parallel
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
- # Append args to each script call
95
- bw run my-script --args "--my --args"
88
+ # Use the grouped output style (default when on a TTY)
89
+ bw run my-script --output-style=grouped
96
90
 
97
- # Use the workspace name in args
98
- bw run my-script --args "--my --args=<workspace>"
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
- # Help (--help can also be passed to any command)
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 /path/to/your/project ls
106
- bw --cwd /path/to/your/project run-script my-script
109
+ bw --cwd=/path/to/your/project ls
110
+ bw --cwd=/path/to/your/project run my-script
107
111
 
108
- # Pass --configFile to any command
109
- bw --configFile /path/to/your/config.json ls
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
- # Pass --logLevel to any command (debug, info, warn, error, or silent)
112
- bw --logLevel silent run my-script
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
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env bun
2
- import { createCli } from "bun-workspaces";
3
-
2
+ import { createCli } from "bun-workspaces/src/cli";
4
3
  createCli().run();
package/package.json CHANGED
@@ -1,40 +1,37 @@
1
1
  {
2
2
  "name": "bun-workspaces",
3
- "version": "1.0.1-alpha",
4
- "main": "src/index.ts",
5
- "homepage": "https://github.com/ScottMorse/bun-workspaces#readme",
3
+ "version": "1.0.1",
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
- "custom": {
28
+ "_bwInternal": {
10
29
  "bunVersion": {
11
- "build": "1.2.22",
12
- "libraryConsumer": "^1.1.x"
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,49 @@
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
+ };
17
+ export type ProjectCommandContext = GlobalCommandContext & {
18
+ project: FileSystemProject;
19
+ projectError: Error | null;
20
+ };
21
+ /** Splits workspace patterns by whitespace, but allows escaping spaces via backslash */
22
+ export declare const splitWorkspacePatterns: (
23
+ workspacePatterns: string,
24
+ ) => string[];
25
+ export declare const createWorkspaceInfoLines: (
26
+ workspace: Workspace,
27
+ ) => string[];
28
+ export declare const createScriptInfoLines: (
29
+ script: string,
30
+ workspaces: Workspace[],
31
+ ) => string[];
32
+ export declare const createJsonLines: (
33
+ data: unknown,
34
+ options: {
35
+ pretty: boolean;
36
+ },
37
+ ) => string[];
38
+ export declare const commandOutputLogger: import("../../internal/logger").Logger;
39
+ export declare const handleGlobalCommand: <ActionArgs extends unknown[]>(
40
+ commandName: CliGlobalCommandName,
41
+ handler: (context: GlobalCommandContext, ...actionArgs: ActionArgs) => void,
42
+ ) => (context: GlobalCommandContext) => Command;
43
+ export declare const handleProjectCommand: <ActionArgs extends unknown[]>(
44
+ commandName: CliProjectCommandName,
45
+ handler: (
46
+ context: Omit<ProjectCommandContext, "projectError">,
47
+ ...actionArgs: ActionArgs
48
+ ) => void,
49
+ ) => (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 };