bun-workspaces 1.0.0-alpha.9 → 1.0.0

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 (233) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +212 -19
  3. package/bin/cli.js +1 -1
  4. package/package.json +24 -8
  5. package/src/cli/commands/commandHandlerUtils.d.ts +45 -0
  6. package/src/cli/commands/commandHandlerUtils.mjs +81 -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 +250 -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 +71 -0
  24. package/src/cli/commands/runScript/output/renderGroupedOutput.mjs +307 -0
  25. package/src/cli/commands/runScript/output/renderPlainOutput.d.ts +22 -0
  26. package/src/cli/commands/runScript/output/renderPlainOutput.mjs +43 -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 +14 -8
  30. package/src/cli/createCli.mjs +94 -39
  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 +38 -2
  34. package/src/cli/globalOptions/globalOptions.mjs +96 -47
  35. package/src/cli/globalOptions/globalOptionsConfig.d.ts +37 -31
  36. package/src/cli/globalOptions/globalOptionsConfig.mjs +32 -30
  37. package/src/cli/globalOptions/index.mjs +1 -1
  38. package/src/cli/index.d.ts +3 -1
  39. package/src/cli/index.mjs +3 -2
  40. package/src/config/index.d.ts +3 -2
  41. package/src/config/index.mjs +3 -3
  42. package/src/config/rootConfig/errors.d.ts +1 -0
  43. package/src/config/rootConfig/errors.mjs +6 -0
  44. package/src/config/rootConfig/index.d.ts +5 -0
  45. package/src/config/rootConfig/index.mjs +5 -0
  46. package/src/config/rootConfig/loadRootConfig.d.ts +3 -0
  47. package/src/config/rootConfig/loadRootConfig.mjs +22 -0
  48. package/src/config/rootConfig/rootConfig.d.ts +17 -0
  49. package/src/config/rootConfig/rootConfig.mjs +43 -0
  50. package/src/config/rootConfig/rootConfigLocation.d.ts +2 -0
  51. package/src/config/rootConfig/rootConfigLocation.mjs +5 -0
  52. package/src/config/rootConfig/rootConfigSchema.d.ts +21 -0
  53. package/src/config/rootConfig/rootConfigSchema.mjs +24 -0
  54. package/src/config/userEnvVars/index.d.ts +1 -0
  55. package/src/config/userEnvVars/index.mjs +1 -0
  56. package/src/config/userEnvVars/userEnvVars.d.ts +13 -0
  57. package/src/config/userEnvVars/userEnvVars.mjs +10 -0
  58. package/src/config/util/ajvTypes.d.ts +10 -0
  59. package/src/config/util/ajvTypes.mjs +2 -0
  60. package/src/config/util/configLocation.d.ts +12 -0
  61. package/src/config/util/configLocation.mjs +11 -0
  62. package/src/config/util/index.d.ts +4 -0
  63. package/src/config/util/index.mjs +3 -0
  64. package/src/config/util/loadConfig.d.ts +16 -0
  65. package/src/config/util/loadConfig.mjs +118 -0
  66. package/src/config/util/validateConfig.d.ts +8 -0
  67. package/src/config/util/validateConfig.mjs +17 -0
  68. package/src/config/workspaceConfig/errors.d.ts +1 -0
  69. package/src/config/workspaceConfig/errors.mjs +6 -0
  70. package/src/config/workspaceConfig/index.d.ts +5 -0
  71. package/src/config/workspaceConfig/index.mjs +5 -0
  72. package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +3 -0
  73. package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +25 -0
  74. package/src/config/workspaceConfig/workspaceConfig.d.ts +22 -0
  75. package/src/config/workspaceConfig/workspaceConfig.mjs +31 -0
  76. package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
  77. package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
  78. package/src/config/workspaceConfig/workspaceConfigSchema.d.ts +25 -0
  79. package/src/config/workspaceConfig/workspaceConfigSchema.mjs +28 -0
  80. package/src/doctor/doctor.d.ts +35 -0
  81. package/src/doctor/doctor.mjs +52 -0
  82. package/src/doctor/index.d.ts +1 -0
  83. package/src/doctor/index.mjs +1 -0
  84. package/src/index.d.ts +37 -3
  85. package/src/index.mjs +16 -3
  86. package/src/internal/bun/bunLock.d.ts +20 -0
  87. package/src/internal/bun/bunLock.mjs +70 -0
  88. package/src/internal/bun/bunVersion.d.ts +21 -0
  89. package/src/internal/bun/bunVersion.mjs +43 -0
  90. package/src/internal/bun/index.d.ts +2 -0
  91. package/src/internal/bun/index.mjs +2 -0
  92. package/src/internal/core/error/error.d.ts +13 -0
  93. package/src/internal/core/error/error.mjs +36 -0
  94. package/src/internal/core/error/index.d.ts +1 -0
  95. package/src/internal/core/error/index.mjs +1 -0
  96. package/src/internal/core/index.d.ts +4 -0
  97. package/src/internal/core/index.mjs +4 -0
  98. package/src/internal/core/json/index.d.ts +2 -0
  99. package/src/internal/core/json/index.mjs +2 -0
  100. package/src/internal/core/json/json.d.ts +49 -0
  101. package/src/internal/core/json/json.mjs +12 -0
  102. package/src/internal/core/json/jsonc.d.ts +9 -0
  103. package/src/internal/core/json/jsonc.mjs +117 -0
  104. package/src/internal/core/language/array/index.d.ts +1 -0
  105. package/src/internal/core/language/array/index.mjs +1 -0
  106. package/src/internal/core/language/array/optionalArray.d.ts +15 -0
  107. package/src/internal/core/language/array/optionalArray.mjs +8 -0
  108. package/src/internal/core/language/asyncIterable/asyncIterableQueue.d.ts +16 -0
  109. package/src/internal/core/language/asyncIterable/asyncIterableQueue.mjs +81 -0
  110. package/src/internal/core/language/asyncIterable/index.d.ts +2 -0
  111. package/src/internal/core/language/asyncIterable/index.mjs +2 -0
  112. package/src/internal/core/language/asyncIterable/mergeAsyncIterables.d.ts +5 -0
  113. package/src/internal/core/language/asyncIterable/mergeAsyncIterables.mjs +27 -0
  114. package/src/internal/core/language/events/typedEventTarget.d.ts +50 -0
  115. package/src/internal/core/language/events/typedEventTarget.mjs +14 -0
  116. package/src/internal/core/language/index.d.ts +5 -0
  117. package/src/internal/core/language/index.mjs +5 -0
  118. package/src/internal/core/language/regex/index.d.ts +1 -0
  119. package/src/internal/core/language/regex/index.mjs +1 -0
  120. package/src/internal/{regex.d.ts → core/language/regex/regex.d.ts} +1 -0
  121. package/src/internal/core/language/regex/regex.mjs +10 -0
  122. package/src/internal/core/language/string/id.d.ts +1 -0
  123. package/src/internal/core/language/string/id.mjs +10 -0
  124. package/src/internal/core/language/string/index.d.ts +1 -0
  125. package/src/internal/core/language/string/index.mjs +1 -0
  126. package/src/internal/core/language/string/utf/eastAsianWidth.d.ts +16 -0
  127. package/src/internal/core/language/string/utf/eastAsianWidth.mjs +326 -0
  128. package/src/internal/core/language/string/utf/visibleLength.d.ts +5 -0
  129. package/src/internal/core/language/string/utf/visibleLength.mjs +29 -0
  130. package/src/internal/core/language/types/index.d.ts +2 -0
  131. package/src/internal/core/language/types/index.mjs +1 -0
  132. package/src/internal/core/language/types/typeof.d.ts +102 -0
  133. package/src/internal/core/language/types/typeof.mjs +123 -0
  134. package/src/internal/core/language/types/types.d.ts +14 -0
  135. package/src/internal/core/language/types/types.mjs +2 -0
  136. package/src/internal/{env.d.ts → core/runtime/env.d.ts} +1 -0
  137. package/src/internal/core/runtime/env.mjs +36 -0
  138. package/src/internal/core/runtime/index.d.ts +5 -0
  139. package/src/internal/core/runtime/index.mjs +5 -0
  140. package/src/internal/core/runtime/onExit.d.ts +4 -0
  141. package/src/internal/core/runtime/onExit.mjs +54 -0
  142. package/src/internal/core/runtime/os.d.ts +4 -0
  143. package/src/internal/core/runtime/os.mjs +7 -0
  144. package/src/internal/core/runtime/tempFile.d.ts +20 -0
  145. package/src/internal/core/runtime/tempFile.mjs +87 -0
  146. package/src/internal/core/runtime/terminal.d.ts +1 -0
  147. package/src/internal/core/runtime/terminal.mjs +4 -0
  148. package/src/internal/generated/ajv/validateRootConfig.mjs +1 -0
  149. package/src/internal/generated/ajv/validateWorkspaceConfig.mjs +1 -0
  150. package/src/internal/logger/index.d.ts +1 -0
  151. package/src/internal/logger/index.mjs +1 -0
  152. package/src/internal/logger/logger.d.ts +39 -0
  153. package/src/internal/logger/logger.mjs +116 -0
  154. package/src/internal/version.d.ts +1 -0
  155. package/src/internal/version.mjs +6 -0
  156. package/src/project/errors.d.ts +5 -1
  157. package/src/project/errors.mjs +10 -3
  158. package/src/project/implementations/fileSystemProject.d.ts +148 -0
  159. package/src/project/implementations/fileSystemProject.mjs +455 -0
  160. package/src/project/implementations/memoryProject.d.ts +41 -0
  161. package/src/project/implementations/memoryProject.mjs +148 -0
  162. package/src/project/implementations/projectBase.d.ts +35 -0
  163. package/src/project/implementations/projectBase.mjs +197 -0
  164. package/src/project/index.d.ts +5 -1
  165. package/src/project/index.mjs +4 -2
  166. package/src/project/project.d.ts +72 -28
  167. package/src/project/project.mjs +6 -72
  168. package/src/runScript/index.d.ts +7 -0
  169. package/src/runScript/index.mjs +7 -0
  170. package/src/runScript/output/index.d.ts +3 -0
  171. package/src/runScript/output/index.mjs +2 -0
  172. package/src/runScript/output/multiProcessOutput.d.ts +14 -0
  173. package/src/runScript/output/multiProcessOutput.mjs +21 -0
  174. package/src/runScript/output/outputStream.d.ts +1 -0
  175. package/src/runScript/output/outputStream.mjs +1 -0
  176. package/src/runScript/output/processOutput.d.ts +33 -0
  177. package/src/runScript/output/processOutput.mjs +124 -0
  178. package/src/runScript/parallel.d.ts +15 -0
  179. package/src/runScript/parallel.mjs +56 -0
  180. package/src/runScript/recursion.d.ts +4 -0
  181. package/src/runScript/recursion.mjs +17 -0
  182. package/src/runScript/runScript.d.ts +45 -0
  183. package/src/runScript/runScript.mjs +89 -0
  184. package/src/runScript/runScripts.d.ts +65 -0
  185. package/src/runScript/runScripts.mjs +263 -0
  186. package/src/runScript/scriptCommand.d.ts +33 -0
  187. package/src/runScript/scriptCommand.mjs +19 -0
  188. package/src/runScript/scriptExecution.d.ts +9 -0
  189. package/src/runScript/scriptExecution.mjs +50 -0
  190. package/src/runScript/scriptRuntimeMetadata.d.ts +73 -0
  191. package/src/runScript/scriptRuntimeMetadata.mjs +61 -0
  192. package/src/runScript/scriptShellOption.d.ts +8 -0
  193. package/src/runScript/scriptShellOption.mjs +39 -0
  194. package/src/runScript/subprocesses.d.ts +11 -0
  195. package/src/runScript/subprocesses.mjs +34 -0
  196. package/src/workspaces/dependencyGraph/cycles.d.ts +9 -0
  197. package/src/workspaces/dependencyGraph/cycles.mjs +91 -0
  198. package/src/workspaces/dependencyGraph/index.d.ts +2 -0
  199. package/src/workspaces/dependencyGraph/index.mjs +2 -0
  200. package/src/workspaces/dependencyGraph/resolveDependencies.d.ts +18 -0
  201. package/src/workspaces/dependencyGraph/resolveDependencies.mjs +52 -0
  202. package/src/workspaces/errors.d.ts +13 -1
  203. package/src/workspaces/errors.mjs +18 -3
  204. package/src/workspaces/findWorkspaces.d.ts +20 -13
  205. package/src/workspaces/findWorkspaces.mjs +208 -57
  206. package/src/workspaces/index.d.ts +4 -3
  207. package/src/workspaces/index.mjs +3 -2
  208. package/src/workspaces/packageJson.d.ts +28 -5
  209. package/src/workspaces/packageJson.mjs +177 -54
  210. package/src/workspaces/workspace.d.ts +19 -13
  211. package/src/workspaces/workspace.mjs +2 -0
  212. package/src/workspaces/workspacePattern.d.ts +21 -0
  213. package/src/workspaces/workspacePattern.mjs +104 -0
  214. package/src/cli/projectCommands/index.d.ts +0 -2
  215. package/src/cli/projectCommands/index.mjs +0 -2
  216. package/src/cli/projectCommands/projectCommandHandlers.d.ts +0 -8
  217. package/src/cli/projectCommands/projectCommandHandlers.mjs +0 -180
  218. package/src/cli/projectCommands/projectCommandsConfig.d.ts +0 -191
  219. package/src/cli/projectCommands/projectCommandsConfig.mjs +0 -100
  220. package/src/config/bunWorkspacesConfig.d.ts +0 -13
  221. package/src/config/bunWorkspacesConfig.mjs +0 -18
  222. package/src/config/configFile.d.ts +0 -3
  223. package/src/config/configFile.mjs +0 -21
  224. package/src/internal/bunVersion.d.ts +0 -14
  225. package/src/internal/bunVersion.mjs +0 -8
  226. package/src/internal/env.mjs +0 -15
  227. package/src/internal/error.d.ts +0 -7
  228. package/src/internal/error.mjs +0 -26
  229. package/src/internal/logger.d.ts +0 -21
  230. package/src/internal/logger.mjs +0 -85
  231. package/src/internal/regex.mjs +0 -3
  232. package/src/project/scriptCommand.d.ts +0 -15
  233. package/src/project/scriptCommand.mjs +0 -18
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,39 +1,232 @@
1
- <img src="./packages/doc-website/src/docs/public/bw-eye.png" alt="bun-workspaces" width="50" />
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>
2
4
 
3
5
  # bun-workspaces
4
6
 
5
- This is a CLI that works on top of native [Bun workspaces](https://bun.sh/docs/install/workspaces) with no additional setup required. Get metadata about your workspaces and scripts, and run scripts across your workspaces.
7
+ ### [**See Full Documentation Here**: _https://bunworkspaces.com_](https://bunworkspaces.com)
6
8
 
7
- ### **[See Full Documentation Here](https://bunworkspaces.com)**
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.
10
+
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 🐚
15
+
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.
17
+
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.
19
+
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.
21
+
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.
8
23
 
9
24
  ## Quick Start
10
25
 
11
- You can install the CLI in your project or simply use `bunx bun-workspaces`.
26
+ Installation:
12
27
 
13
28
  ```bash
29
+ $ # Install to use the API and/or lock your CLI version for your project
14
30
  $ bun add --dev bun-workspaces
31
+ $ # Start using the CLI with or without the installation step
15
32
  $ bunx bun-workspaces --help
16
33
  ```
17
34
 
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.
36
+
37
+ ### CLI
38
+
39
+ [Full CLI documentation here](https://bunworkspaces.com/cli)
40
+
18
41
  ```bash
42
+ # You can add this to .bashrc, .zshrc, or similar.
43
+ # You can also invoke "bw" in your root package.json scripts.
19
44
  alias bw="bunx bun-workspaces"
20
45
 
21
- # Usage (--help can also be passed to any command)
46
+ # List all workspaces in your project
47
+ bw list-workspaces
48
+
49
+ # ls is an alias for list-workspaces
50
+ bw ls --json --pretty # Output as formatted JSON
51
+
52
+ # Get info about a workspace
53
+ bw workspace-info my-workspace
54
+ bw info my-workspace --json --pretty # info is alias for workspace-info
55
+
56
+ # Get info about a script, such as the workspaces that have it
57
+ bw script-info my-script
58
+
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)
67
+
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
70
+
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
74
+
75
+ # Continue running scripts even if a dependency fails
76
+ bw run lint --dep-order --ignore-dep-failure
77
+
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
80
+
81
+ bw run "bun build" --inline # Run an inline command via the Bun shell
82
+
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
87
+
88
+ # Use the grouped output style (default when on a TTY)
89
+ bw run my-script --output-style=grouped
90
+
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
94
+
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)
22
102
  bw help
23
103
  bw --help
24
104
 
25
- # Get JSON metadata
26
- bw list-workspaces --json --pretty # optionally pretty print JSON
27
- bw list-scripts --json
28
- bw workspace-info my-workspace --json
29
- bw script-info my-script --json
30
-
31
- # Run scripts across workspaces
32
- bw run my-script
33
- bw run my-script my-workspace
34
- bw run my-script workspace-a workspace-b
35
- bw run my-script "my-workspace-*"
36
- bw run my-script --parallel
37
- bw run my-script --args "--my --args"
38
- bw run my-script --args "--my --args=<workspace>"
105
+ # Show version
106
+ bw --version
107
+
108
+ # Pass --cwd to any command
109
+ bw --cwd=/path/to/your/project ls
110
+ bw --cwd=/path/to/your/project run my-script
111
+
112
+ # Pass --log-level to any command (debug, info, warn, error, or silent)
113
+ bw --log-level=silent run my-script
39
114
  ```
115
+
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
+ };
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,3 +1,3 @@
1
1
  #!/usr/bin/env bun
2
- import { createCli } from "bun-workspaces";
2
+ import { createCli } from "bun-workspaces/src/cli";
3
3
  createCli().run();
package/package.json CHANGED
@@ -1,21 +1,37 @@
1
1
  {
2
2
  "name": "bun-workspaces",
3
- "version": "1.0.0-alpha.9",
3
+ "version": "1.0.0",
4
+ "description": "A monorepo management tool for Bun, with a CLI and API to enhance Bun's native workspaces.",
4
5
  "license": "MIT",
5
6
  "main": "src/index.mjs",
6
7
  "types": "src/index.d.ts",
7
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
+ },
8
24
  "bin": {
9
- "bun-workspaces": "bin/cli.js"
25
+ "bun-workspaces": "bin/cli.js",
26
+ "bw": "bin/cli.js"
10
27
  },
11
- "custom": {
28
+ "_bwInternal": {
12
29
  "bunVersion": {
13
- "build": "1.3.0",
14
- "libraryConsumer": "^1.1.x"
30
+ "build": "1.3.5",
31
+ "libraryConsumer": "^1.2.0"
15
32
  }
16
33
  },
17
34
  "dependencies": {
18
- "commander": "^12.1.0",
19
- "glob": "^11.0.3"
35
+ "commander": "^12.1.0"
20
36
  }
21
- }
37
+ }
@@ -0,0 +1,45 @@
1
+ import { type Command } from "commander";
2
+ import type { FileSystemProject } from "../../project/implementations/fileSystemProject";
3
+ import type { Workspace } from "../../workspaces";
4
+ import {
5
+ type CliGlobalCommandName,
6
+ type CliProjectCommandName,
7
+ } from "./commandsConfig";
8
+ /** @todo DRY use of output text in cases such as having no workspaces/scripts */
9
+ export interface GlobalCommandContext {
10
+ program: Command;
11
+ postTerminatorArgs: string[];
12
+ }
13
+ export type ProjectCommandContext = GlobalCommandContext & {
14
+ project: FileSystemProject;
15
+ projectError: Error | null;
16
+ };
17
+ /** Splits workspace patterns by whitespace, but allows escaping spaces via backslash */
18
+ export declare const splitWorkspacePatterns: (
19
+ workspacePatterns: string,
20
+ ) => string[];
21
+ export declare const createWorkspaceInfoLines: (
22
+ workspace: Workspace,
23
+ ) => string[];
24
+ export declare const createScriptInfoLines: (
25
+ script: string,
26
+ workspaces: Workspace[],
27
+ ) => string[];
28
+ export declare const createJsonLines: (
29
+ data: unknown,
30
+ options: {
31
+ pretty: boolean;
32
+ },
33
+ ) => string[];
34
+ export declare const commandOutputLogger: import("../../internal/logger").Logger;
35
+ export declare const handleGlobalCommand: <ActionArgs extends unknown[]>(
36
+ commandName: CliGlobalCommandName,
37
+ handler: (context: GlobalCommandContext, ...actionArgs: ActionArgs) => void,
38
+ ) => (context: GlobalCommandContext) => Command;
39
+ export declare const handleProjectCommand: <ActionArgs extends unknown[]>(
40
+ commandName: CliProjectCommandName,
41
+ handler: (
42
+ context: Omit<ProjectCommandContext, "projectError">,
43
+ ...actionArgs: ActionArgs
44
+ ) => void,
45
+ ) => (context: ProjectCommandContext) => Command;
@@ -0,0 +1,81 @@
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
+ await handler(context, ...actionArgs);
51
+ } catch (error) {
52
+ if (error instanceof BunWorkspacesError) {
53
+ logger.error(error.message);
54
+ process.exit(1);
55
+ }
56
+ throw error;
57
+ }
58
+ });
59
+ return program;
60
+ };
61
+ const handleGlobalCommand = (commandName, handler) => (context) =>
62
+ handleCommand(commandName, handler)(context);
63
+ const handleProjectCommand = (commandName, handler) => (context) =>
64
+ handleCommand(commandName, async (context, ...actionArgs) => {
65
+ const { projectError } = context;
66
+ if (projectError) {
67
+ logger.error(projectError.message);
68
+ process.exit(1);
69
+ }
70
+ await handler(context, ...actionArgs);
71
+ })(context);
72
+
73
+ export {
74
+ commandOutputLogger,
75
+ createJsonLines,
76
+ createScriptInfoLines,
77
+ createWorkspaceInfoLines,
78
+ handleGlobalCommand,
79
+ handleProjectCommand,
80
+ splitWorkspacePatterns,
81
+ };
@@ -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 };