bun-workspaces 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (154) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +131 -77
  3. package/bin/cli.js +1 -2
  4. package/package.json +24 -30
  5. package/src/cli/commands/commandHandlerUtils.d.ts +41 -0
  6. package/src/cli/commands/commandHandlerUtils.mjs +59 -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 +312 -0
  10. package/src/cli/commands/commandsConfig.mjs +155 -0
  11. package/src/cli/commands/handleRunScript.d.ts +3 -0
  12. package/src/cli/commands/handleRunScript.mjs +217 -0
  13. package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
  14. package/src/cli/commands/handleSimpleCommands.mjs +170 -0
  15. package/src/cli/commands/index.d.ts +2 -0
  16. package/src/cli/commands/index.mjs +2 -0
  17. package/src/cli/createCli.d.ts +19 -0
  18. package/src/cli/createCli.mjs +113 -0
  19. package/src/cli/fatalErrorLogger.d.ts +1 -0
  20. package/src/cli/fatalErrorLogger.mjs +7 -0
  21. package/src/cli/globalOptions/globalOptions.d.ts +38 -0
  22. package/src/cli/globalOptions/globalOptions.mjs +120 -0
  23. package/src/cli/globalOptions/globalOptionsConfig.d.ts +43 -0
  24. package/src/cli/globalOptions/globalOptionsConfig.mjs +34 -0
  25. package/src/cli/globalOptions/index.d.ts +2 -0
  26. package/src/cli/globalOptions/index.mjs +2 -0
  27. package/src/cli/index.d.ts +3 -0
  28. package/src/cli/index.mjs +3 -0
  29. package/src/config/bunWorkspacesConfig.d.ts +17 -0
  30. package/src/config/bunWorkspacesConfig.mjs +50 -0
  31. package/src/config/configFile.d.ts +8 -0
  32. package/src/config/configFile.mjs +43 -0
  33. package/src/config/errors.d.ts +3 -0
  34. package/src/config/errors.mjs +10 -0
  35. package/src/config/{index.ts → index.d.ts} +1 -0
  36. package/src/config/index.mjs +11 -0
  37. package/src/config/userEnvVars.d.ts +9 -0
  38. package/src/config/userEnvVars.mjs +9 -0
  39. package/src/config/workspaceConfig/errors.d.ts +3 -0
  40. package/src/config/workspaceConfig/errors.mjs +9 -0
  41. package/src/config/workspaceConfig/index.d.ts +4 -0
  42. package/src/config/workspaceConfig/index.mjs +4 -0
  43. package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +5 -0
  44. package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +82 -0
  45. package/src/config/workspaceConfig/workspaceConfig.d.ts +25 -0
  46. package/src/config/workspaceConfig/workspaceConfig.mjs +80 -0
  47. package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
  48. package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
  49. package/src/doctor/doctor.d.ts +35 -0
  50. package/src/doctor/doctor.mjs +52 -0
  51. package/src/doctor/index.d.ts +1 -0
  52. package/src/doctor/index.mjs +1 -0
  53. package/src/index.d.ts +31 -0
  54. package/src/index.mjs +9 -0
  55. package/src/internal/bun/bunLock.d.ts +20 -0
  56. package/src/internal/bun/bunLock.mjs +72 -0
  57. package/src/internal/bun/bunVersion.d.ts +21 -0
  58. package/src/internal/bun/bunVersion.mjs +43 -0
  59. package/src/internal/bun/index.d.ts +2 -0
  60. package/src/internal/bun/index.mjs +2 -0
  61. package/src/internal/core/asyncIterable/asyncIterableQueue.d.ts +15 -0
  62. package/src/internal/core/asyncIterable/asyncIterableQueue.mjs +73 -0
  63. package/src/internal/core/asyncIterable/mergeAsyncIterables.d.ts +5 -0
  64. package/src/internal/core/asyncIterable/mergeAsyncIterables.mjs +27 -0
  65. package/src/internal/core/error.d.ts +9 -0
  66. package/src/internal/{error.ts → core/error.mjs} +7 -16
  67. package/src/internal/core/index.d.ts +7 -0
  68. package/src/internal/core/index.mjs +6 -0
  69. package/src/internal/core/json/index.d.ts +2 -0
  70. package/src/internal/core/json/index.mjs +2 -0
  71. package/src/internal/core/json/json.d.ts +9 -0
  72. package/src/internal/core/json/json.mjs +6 -0
  73. package/src/internal/core/json/jsonc.d.ts +9 -0
  74. package/src/internal/core/json/jsonc.mjs +117 -0
  75. package/src/internal/core/optionalArray.d.ts +15 -0
  76. package/src/internal/core/optionalArray.mjs +8 -0
  77. package/src/internal/core/regex.d.ts +3 -0
  78. package/src/internal/core/regex.mjs +10 -0
  79. package/src/internal/core/types.d.ts +6 -0
  80. package/src/internal/core/types.mjs +3 -0
  81. package/src/internal/logger/index.d.ts +1 -0
  82. package/src/internal/logger/index.mjs +1 -0
  83. package/src/internal/logger/logger.d.ts +44 -0
  84. package/src/internal/logger/logger.mjs +110 -0
  85. package/src/internal/runtime/env.d.ts +5 -0
  86. package/src/internal/runtime/env.mjs +29 -0
  87. package/src/internal/runtime/index.d.ts +2 -0
  88. package/src/internal/runtime/index.mjs +2 -0
  89. package/src/internal/runtime/onExit.d.ts +6 -0
  90. package/src/internal/runtime/onExit.mjs +24 -0
  91. package/src/internal/runtime/os.d.ts +4 -0
  92. package/src/internal/runtime/os.mjs +7 -0
  93. package/src/internal/runtime/tempFile.d.ts +16 -0
  94. package/src/internal/runtime/tempFile.mjs +50 -0
  95. package/src/project/errors.d.ts +3 -0
  96. package/src/project/errors.mjs +9 -0
  97. package/src/project/implementations/fileSystemProject.d.ts +106 -0
  98. package/src/project/implementations/fileSystemProject.mjs +227 -0
  99. package/src/project/implementations/memoryProject.d.ts +32 -0
  100. package/src/project/implementations/memoryProject.mjs +46 -0
  101. package/src/project/implementations/projectBase.d.ts +28 -0
  102. package/src/project/implementations/projectBase.mjs +117 -0
  103. package/src/project/index.d.ts +5 -0
  104. package/src/project/index.mjs +4 -0
  105. package/src/project/project.d.ts +64 -0
  106. package/src/project/project.mjs +6 -0
  107. package/src/runScript/index.d.ts +7 -0
  108. package/src/runScript/index.mjs +7 -0
  109. package/src/runScript/outputChunk.d.ts +22 -0
  110. package/src/runScript/outputChunk.mjs +30 -0
  111. package/src/runScript/parallel.d.ts +12 -0
  112. package/src/runScript/parallel.mjs +52 -0
  113. package/src/runScript/runScript.d.ts +37 -0
  114. package/src/runScript/runScript.mjs +60 -0
  115. package/src/runScript/runScripts.d.ts +48 -0
  116. package/src/runScript/runScripts.mjs +124 -0
  117. package/src/runScript/scriptCommand.d.ts +33 -0
  118. package/src/runScript/scriptCommand.mjs +19 -0
  119. package/src/runScript/scriptExecution.d.ts +9 -0
  120. package/src/runScript/scriptExecution.mjs +51 -0
  121. package/src/runScript/scriptRuntimeMetadata.d.ts +75 -0
  122. package/src/runScript/scriptRuntimeMetadata.mjs +62 -0
  123. package/src/runScript/scriptShellOption.d.ts +7 -0
  124. package/src/runScript/scriptShellOption.mjs +36 -0
  125. package/src/workspaces/errors.d.ts +12 -0
  126. package/src/workspaces/{errors.ts → errors.mjs} +5 -2
  127. package/src/workspaces/findWorkspaces.d.ts +22 -0
  128. package/src/workspaces/findWorkspaces.mjs +168 -0
  129. package/src/workspaces/index.d.ts +4 -0
  130. package/src/workspaces/index.mjs +3 -0
  131. package/src/workspaces/packageJson.d.ts +15 -0
  132. package/src/workspaces/packageJson.mjs +135 -0
  133. package/src/workspaces/{workspace.ts → workspace.d.ts} +5 -6
  134. package/src/workspaces/workspace.mjs +2 -0
  135. package/bun.lock +0 -576
  136. package/src/cli/cli.ts +0 -87
  137. package/src/cli/globalOptions.ts +0 -122
  138. package/src/cli/index.ts +0 -1
  139. package/src/cli/projectCommands.ts +0 -390
  140. package/src/config/bunWorkspacesConfig.ts +0 -62
  141. package/src/config/configFile.ts +0 -33
  142. package/src/index.ts +0 -3
  143. package/src/internal/bunVersion.ts +0 -26
  144. package/src/internal/env.ts +0 -25
  145. package/src/internal/logger.ts +0 -180
  146. package/src/internal/regex.ts +0 -5
  147. package/src/project/errors.ts +0 -6
  148. package/src/project/index.ts +0 -6
  149. package/src/project/project.ts +0 -155
  150. package/src/project/scriptCommand.ts +0 -40
  151. package/src/workspaces/findWorkspaces.ts +0 -137
  152. package/src/workspaces/index.ts +0 -7
  153. package/src/workspaces/packageJson.ts +0 -166
  154. package/tsconfig.json +0 -28
@@ -0,0 +1,312 @@
1
+ export interface CliCommandConfig {
2
+ command: string;
3
+ isGlobal: boolean;
4
+ aliases: string[];
5
+ description: string;
6
+ options: Record<
7
+ string,
8
+ {
9
+ flags: string[];
10
+ description: string;
11
+ values?: string[];
12
+ }
13
+ >;
14
+ }
15
+ export type CliCommandName = keyof typeof CLI_COMMANDS_CONFIG;
16
+ export type CliGlobalCommandName = {
17
+ [K in CliCommandName]: (typeof CLI_COMMANDS_CONFIG)[K] extends {
18
+ isGlobal: true;
19
+ }
20
+ ? K
21
+ : never;
22
+ }[CliCommandName];
23
+ export type CliProjectCommandName = Exclude<
24
+ CliCommandName,
25
+ CliGlobalCommandName
26
+ >;
27
+ export declare const CLI_COMMANDS_CONFIG: {
28
+ readonly doctor: {
29
+ readonly command: "doctor";
30
+ readonly isGlobal: true;
31
+ readonly aliases: [];
32
+ readonly description: "Print diagnostic information";
33
+ readonly options: {
34
+ readonly json: {
35
+ readonly flags: ["-j", "--json"];
36
+ readonly description: "Output as JSON";
37
+ };
38
+ readonly pretty: {
39
+ readonly flags: ["-p", "--pretty"];
40
+ readonly description: "Pretty print JSON";
41
+ };
42
+ };
43
+ };
44
+ readonly listWorkspaces: {
45
+ readonly command: "list-workspaces [workspacePatterns...]";
46
+ readonly isGlobal: false;
47
+ readonly aliases: ["ls", "list"];
48
+ readonly description: "List all workspaces";
49
+ readonly options: {
50
+ readonly workspacePatterns: {
51
+ readonly flags: ["-W", "--workspace-patterns <patterns>"];
52
+ readonly description: "Workspace patterns to filter workspaces by, separated by commas";
53
+ };
54
+ readonly nameOnly: {
55
+ readonly flags: ["-n", "--name-only"];
56
+ readonly description: "Only show workspace names";
57
+ };
58
+ readonly json: {
59
+ readonly flags: ["-j", "--json"];
60
+ readonly description: "Output as JSON";
61
+ };
62
+ readonly pretty: {
63
+ readonly flags: ["-p", "--pretty"];
64
+ readonly description: "Pretty print JSON";
65
+ };
66
+ };
67
+ };
68
+ readonly listScripts: {
69
+ readonly command: "list-scripts";
70
+ readonly isGlobal: false;
71
+ readonly aliases: ["ls-scripts"];
72
+ readonly description: "List all scripts available with their workspaces";
73
+ readonly options: {
74
+ readonly nameOnly: {
75
+ readonly flags: ["-n", "--name-only"];
76
+ readonly description: "Only show script names";
77
+ };
78
+ readonly json: {
79
+ readonly flags: ["-j", "--json"];
80
+ readonly description: "Output as JSON";
81
+ };
82
+ readonly pretty: {
83
+ readonly flags: ["-p", "--pretty"];
84
+ readonly description: "Pretty print JSON";
85
+ };
86
+ };
87
+ };
88
+ readonly workspaceInfo: {
89
+ readonly command: "workspace-info <workspaceName>";
90
+ readonly isGlobal: false;
91
+ readonly aliases: ["info"];
92
+ readonly description: "Show information about a workspace";
93
+ readonly options: {
94
+ readonly json: {
95
+ readonly flags: ["-j", "--json"];
96
+ readonly description: "Output as JSON";
97
+ };
98
+ readonly pretty: {
99
+ readonly flags: ["-p", "--pretty"];
100
+ readonly description: "Pretty print JSON";
101
+ };
102
+ };
103
+ };
104
+ readonly scriptInfo: {
105
+ readonly command: "script-info <script>";
106
+ readonly isGlobal: false;
107
+ readonly aliases: [];
108
+ readonly description: "Show information about a script";
109
+ readonly options: {
110
+ readonly workspacesOnly: {
111
+ readonly flags: ["-w", "--workspaces-only"];
112
+ readonly description: "Only show script's workspace names";
113
+ };
114
+ readonly json: {
115
+ readonly flags: ["-j", "--json"];
116
+ readonly description: "Output as JSON";
117
+ };
118
+ readonly pretty: {
119
+ readonly flags: ["-p", "--pretty"];
120
+ readonly description: "Pretty print JSON";
121
+ };
122
+ };
123
+ };
124
+ readonly runScript: {
125
+ readonly command: "run-script [script] [workspacePatterns...]";
126
+ readonly isGlobal: false;
127
+ readonly aliases: ["run"];
128
+ readonly description: 'Run a script in all workspaces that have it in their "scripts" field in package.json';
129
+ readonly options: {
130
+ readonly script: {
131
+ readonly flags: ["-S", "--script <script>"];
132
+ readonly description: "The script to run.";
133
+ };
134
+ readonly workspacePatterns: {
135
+ readonly flags: ["-W", "--workspace-patterns <patterns>"];
136
+ readonly description: "Workspace patterns to filter workspaces by, separated by commas";
137
+ };
138
+ readonly parallel: {
139
+ readonly flags: ["-P", "--parallel [max]"];
140
+ readonly description: "Run the scripts in parallel. Pass an optional number, percentage, or keyword: default | auto | unbounded";
141
+ };
142
+ readonly args: {
143
+ readonly flags: ["-a", "--args <args>"];
144
+ readonly description: "Args to append to the script command";
145
+ };
146
+ readonly noPrefix: {
147
+ readonly flags: ["-N", "--no-prefix"];
148
+ readonly description: "Do not prefix the workspace name to the script output";
149
+ };
150
+ readonly inline: {
151
+ readonly flags: ["-i", "--inline"];
152
+ readonly description: "Run the script as an inline command from the workspace directory";
153
+ };
154
+ readonly inlineName: {
155
+ readonly flags: ["-I", "--inline-name <name>"];
156
+ readonly description: "An optional name for the script when --inline is passed";
157
+ };
158
+ readonly shell: {
159
+ readonly flags: ["-s", "--shell <shell>"];
160
+ readonly values: ["bun", "system", "default"];
161
+ readonly description: "When using --inline, the shell to use to run the script";
162
+ };
163
+ readonly jsonOutfile: {
164
+ readonly flags: ["-j", "--json-outfile <file>"];
165
+ readonly description: "Output results in a JSON file";
166
+ };
167
+ };
168
+ };
169
+ };
170
+ export declare const getCliCommandConfig: (commandName: CliCommandName) =>
171
+ | {
172
+ readonly command: "doctor";
173
+ readonly isGlobal: true;
174
+ readonly aliases: [];
175
+ readonly description: "Print diagnostic information";
176
+ readonly options: {
177
+ readonly json: {
178
+ readonly flags: ["-j", "--json"];
179
+ readonly description: "Output as JSON";
180
+ };
181
+ readonly pretty: {
182
+ readonly flags: ["-p", "--pretty"];
183
+ readonly description: "Pretty print JSON";
184
+ };
185
+ };
186
+ }
187
+ | {
188
+ readonly command: "list-workspaces [workspacePatterns...]";
189
+ readonly isGlobal: false;
190
+ readonly aliases: ["ls", "list"];
191
+ readonly description: "List all workspaces";
192
+ readonly options: {
193
+ readonly workspacePatterns: {
194
+ readonly flags: ["-W", "--workspace-patterns <patterns>"];
195
+ readonly description: "Workspace patterns to filter workspaces by, separated by commas";
196
+ };
197
+ readonly nameOnly: {
198
+ readonly flags: ["-n", "--name-only"];
199
+ readonly description: "Only show workspace names";
200
+ };
201
+ readonly json: {
202
+ readonly flags: ["-j", "--json"];
203
+ readonly description: "Output as JSON";
204
+ };
205
+ readonly pretty: {
206
+ readonly flags: ["-p", "--pretty"];
207
+ readonly description: "Pretty print JSON";
208
+ };
209
+ };
210
+ }
211
+ | {
212
+ readonly command: "list-scripts";
213
+ readonly isGlobal: false;
214
+ readonly aliases: ["ls-scripts"];
215
+ readonly description: "List all scripts available with their workspaces";
216
+ readonly options: {
217
+ readonly nameOnly: {
218
+ readonly flags: ["-n", "--name-only"];
219
+ readonly description: "Only show script names";
220
+ };
221
+ readonly json: {
222
+ readonly flags: ["-j", "--json"];
223
+ readonly description: "Output as JSON";
224
+ };
225
+ readonly pretty: {
226
+ readonly flags: ["-p", "--pretty"];
227
+ readonly description: "Pretty print JSON";
228
+ };
229
+ };
230
+ }
231
+ | {
232
+ readonly command: "workspace-info <workspaceName>";
233
+ readonly isGlobal: false;
234
+ readonly aliases: ["info"];
235
+ readonly description: "Show information about a workspace";
236
+ readonly options: {
237
+ readonly json: {
238
+ readonly flags: ["-j", "--json"];
239
+ readonly description: "Output as JSON";
240
+ };
241
+ readonly pretty: {
242
+ readonly flags: ["-p", "--pretty"];
243
+ readonly description: "Pretty print JSON";
244
+ };
245
+ };
246
+ }
247
+ | {
248
+ readonly command: "script-info <script>";
249
+ readonly isGlobal: false;
250
+ readonly aliases: [];
251
+ readonly description: "Show information about a script";
252
+ readonly options: {
253
+ readonly workspacesOnly: {
254
+ readonly flags: ["-w", "--workspaces-only"];
255
+ readonly description: "Only show script's workspace names";
256
+ };
257
+ readonly json: {
258
+ readonly flags: ["-j", "--json"];
259
+ readonly description: "Output as JSON";
260
+ };
261
+ readonly pretty: {
262
+ readonly flags: ["-p", "--pretty"];
263
+ readonly description: "Pretty print JSON";
264
+ };
265
+ };
266
+ }
267
+ | {
268
+ readonly command: "run-script [script] [workspacePatterns...]";
269
+ readonly isGlobal: false;
270
+ readonly aliases: ["run"];
271
+ readonly description: 'Run a script in all workspaces that have it in their "scripts" field in package.json';
272
+ readonly options: {
273
+ readonly script: {
274
+ readonly flags: ["-S", "--script <script>"];
275
+ readonly description: "The script to run.";
276
+ };
277
+ readonly workspacePatterns: {
278
+ readonly flags: ["-W", "--workspace-patterns <patterns>"];
279
+ readonly description: "Workspace patterns to filter workspaces by, separated by commas";
280
+ };
281
+ readonly parallel: {
282
+ readonly flags: ["-P", "--parallel [max]"];
283
+ readonly description: "Run the scripts in parallel. Pass an optional number, percentage, or keyword: default | auto | unbounded";
284
+ };
285
+ readonly args: {
286
+ readonly flags: ["-a", "--args <args>"];
287
+ readonly description: "Args to append to the script command";
288
+ };
289
+ readonly noPrefix: {
290
+ readonly flags: ["-N", "--no-prefix"];
291
+ readonly description: "Do not prefix the workspace name to the script output";
292
+ };
293
+ readonly inline: {
294
+ readonly flags: ["-i", "--inline"];
295
+ readonly description: "Run the script as an inline command from the workspace directory";
296
+ };
297
+ readonly inlineName: {
298
+ readonly flags: ["-I", "--inline-name <name>"];
299
+ readonly description: "An optional name for the script when --inline is passed";
300
+ };
301
+ readonly shell: {
302
+ readonly flags: ["-s", "--shell <shell>"];
303
+ readonly values: ["bun", "system", "default"];
304
+ readonly description: "When using --inline, the shell to use to run the script";
305
+ };
306
+ readonly jsonOutfile: {
307
+ readonly flags: ["-j", "--json-outfile <file>"];
308
+ readonly description: "Output results in a JSON file";
309
+ };
310
+ };
311
+ };
312
+ export declare const getCliCommandNames: () => CliCommandName[];
@@ -0,0 +1,155 @@
1
+ import { SCRIPT_SHELL_OPTIONS } from "../../runScript/scriptShellOption.mjs"; // CONCATENATED MODULE: external "../../runScript/scriptShellOption.mjs"
2
+ // CONCATENATED MODULE: ./src/cli/commands/commandsConfig.ts
3
+
4
+ const CLI_COMMANDS_CONFIG = {
5
+ doctor: {
6
+ command: "doctor",
7
+ isGlobal: true,
8
+ aliases: [],
9
+ description: "Print diagnostic information",
10
+ options: {
11
+ json: {
12
+ flags: ["-j", "--json"],
13
+ description: "Output as JSON",
14
+ },
15
+ pretty: {
16
+ flags: ["-p", "--pretty"],
17
+ description: "Pretty print JSON",
18
+ },
19
+ },
20
+ },
21
+ listWorkspaces: {
22
+ command: "list-workspaces [workspacePatterns...]",
23
+ isGlobal: false,
24
+ aliases: ["ls", "list"],
25
+ description: "List all workspaces",
26
+ options: {
27
+ workspacePatterns: {
28
+ flags: ["-W", "--workspace-patterns <patterns>"],
29
+ description:
30
+ "Workspace patterns to filter workspaces by, separated by commas",
31
+ },
32
+ nameOnly: {
33
+ flags: ["-n", "--name-only"],
34
+ description: "Only show workspace names",
35
+ },
36
+ json: {
37
+ flags: ["-j", "--json"],
38
+ description: "Output as JSON",
39
+ },
40
+ pretty: {
41
+ flags: ["-p", "--pretty"],
42
+ description: "Pretty print JSON",
43
+ },
44
+ },
45
+ },
46
+ listScripts: {
47
+ command: "list-scripts",
48
+ isGlobal: false,
49
+ aliases: ["ls-scripts"],
50
+ description: "List all scripts available with their workspaces",
51
+ options: {
52
+ nameOnly: {
53
+ flags: ["-n", "--name-only"],
54
+ description: "Only show script names",
55
+ },
56
+ json: {
57
+ flags: ["-j", "--json"],
58
+ description: "Output as JSON",
59
+ },
60
+ pretty: {
61
+ flags: ["-p", "--pretty"],
62
+ description: "Pretty print JSON",
63
+ },
64
+ },
65
+ },
66
+ workspaceInfo: {
67
+ command: "workspace-info <workspaceName>",
68
+ isGlobal: false,
69
+ aliases: ["info"],
70
+ description: "Show information about a workspace",
71
+ options: {
72
+ json: {
73
+ flags: ["-j", "--json"],
74
+ description: "Output as JSON",
75
+ },
76
+ pretty: {
77
+ flags: ["-p", "--pretty"],
78
+ description: "Pretty print JSON",
79
+ },
80
+ },
81
+ },
82
+ scriptInfo: {
83
+ command: "script-info <script>",
84
+ isGlobal: false,
85
+ aliases: [],
86
+ description: "Show information about a script",
87
+ options: {
88
+ workspacesOnly: {
89
+ flags: ["-w", "--workspaces-only"],
90
+ description: "Only show script's workspace names",
91
+ },
92
+ json: {
93
+ flags: ["-j", "--json"],
94
+ description: "Output as JSON",
95
+ },
96
+ pretty: {
97
+ flags: ["-p", "--pretty"],
98
+ description: "Pretty print JSON",
99
+ },
100
+ },
101
+ },
102
+ runScript: {
103
+ command: "run-script [script] [workspacePatterns...]",
104
+ isGlobal: false,
105
+ aliases: ["run"],
106
+ description:
107
+ 'Run a script in all workspaces that have it in their "scripts" field in package.json',
108
+ options: {
109
+ script: {
110
+ flags: ["-S", "--script <script>"],
111
+ description: "The script to run.",
112
+ },
113
+ workspacePatterns: {
114
+ flags: ["-W", "--workspace-patterns <patterns>"],
115
+ description:
116
+ "Workspace patterns to filter workspaces by, separated by commas",
117
+ },
118
+ parallel: {
119
+ flags: ["-P", "--parallel [max]"],
120
+ description:
121
+ "Run the scripts in parallel. Pass an optional number, percentage, or keyword: default | auto | unbounded",
122
+ },
123
+ args: {
124
+ flags: ["-a", "--args <args>"],
125
+ description: "Args to append to the script command",
126
+ },
127
+ noPrefix: {
128
+ flags: ["-N", "--no-prefix"],
129
+ description: "Do not prefix the workspace name to the script output",
130
+ },
131
+ inline: {
132
+ flags: ["-i", "--inline"],
133
+ description:
134
+ "Run the script as an inline command from the workspace directory",
135
+ },
136
+ inlineName: {
137
+ flags: ["-I", "--inline-name <name>"],
138
+ description: "An optional name for the script when --inline is passed",
139
+ },
140
+ shell: {
141
+ flags: ["-s", "--shell <shell>"],
142
+ values: [...SCRIPT_SHELL_OPTIONS, "default"],
143
+ description: `When using --inline, the shell to use to run the script`,
144
+ },
145
+ jsonOutfile: {
146
+ flags: ["-j", "--json-outfile <file>"],
147
+ description: "Output results in a JSON file",
148
+ },
149
+ },
150
+ },
151
+ };
152
+ const getCliCommandConfig = (commandName) => CLI_COMMANDS_CONFIG[commandName];
153
+ const getCliCommandNames = () => Object.keys(CLI_COMMANDS_CONFIG);
154
+
155
+ export { CLI_COMMANDS_CONFIG, getCliCommandConfig, getCliCommandNames };
@@ -0,0 +1,3 @@
1
+ export declare const runScript: (
2
+ context: import("./commandHandlerUtils").ProjectCommandContext,
3
+ ) => import("commander").Command;
@@ -0,0 +1,217 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { logger } from "../../internal/logger/index.mjs";
4
+ import { sortWorkspaces } from "../../workspaces/index.mjs";
5
+ import {
6
+ commandOutputLogger,
7
+ handleProjectCommand,
8
+ } from "./commandHandlerUtils.mjs"; // CONCATENATED MODULE: external "fs"
9
+ // CONCATENATED MODULE: external "path"
10
+ // CONCATENATED MODULE: external "../../internal/logger/index.mjs"
11
+ // CONCATENATED MODULE: external "../../workspaces/index.mjs"
12
+ // CONCATENATED MODULE: external "./commandHandlerUtils.mjs"
13
+ // CONCATENATED MODULE: ./src/cli/commands/handleRunScript.ts
14
+
15
+ const runScript = handleProjectCommand(
16
+ "runScript",
17
+ async (
18
+ { project, postTerminatorArgs },
19
+ _script,
20
+ _workspacePatterns,
21
+ options,
22
+ ) => {
23
+ options.inlineName = options.inlineName?.trim();
24
+ options.args = options.args?.trim();
25
+ options.jsonOutfile = options.jsonOutfile?.trim();
26
+ options.parallel =
27
+ typeof options.parallel === "string"
28
+ ? options.parallel.trim()
29
+ : options.parallel;
30
+ if (_script && options.script) {
31
+ _workspacePatterns.splice(0, 0, _script);
32
+ }
33
+ const script = options.script || _script;
34
+ if (postTerminatorArgs.length && options.args) {
35
+ logger.error(
36
+ "CLI syntax error: Cannot use both --args and inline script args after --",
37
+ );
38
+ process.exit(1);
39
+ }
40
+ const scriptArgs = postTerminatorArgs.length
41
+ ? postTerminatorArgs.join(" ")
42
+ : options.args;
43
+ if (_workspacePatterns.length && options.workspacePatterns) {
44
+ logger.error(
45
+ "CLI syntax error: Cannot use both inline workspace patterns and --workspace-patterns|-W option",
46
+ );
47
+ process.exit(1);
48
+ }
49
+ const workspacePatterns = _workspacePatterns?.length
50
+ ? _workspacePatterns
51
+ : (options.workspacePatterns?.split(",") ?? []);
52
+ logger.debug(
53
+ `Command: Run script ${JSON.stringify(script)} for ${workspacePatterns.length ? "workspaces " + workspacePatterns.join(", ") : "all workspaces"} (parallel: ${!!options.parallel}, args: ${JSON.stringify(scriptArgs)})`,
54
+ );
55
+ let workspaces = workspacePatterns.length
56
+ ? workspacePatterns
57
+ .flatMap((workspacePattern) => {
58
+ if (workspacePattern.includes("*")) {
59
+ return project
60
+ .findWorkspacesByPattern(workspacePattern)
61
+ .filter(
62
+ (workspace) =>
63
+ options.inline || workspace.scripts.includes(script),
64
+ )
65
+ .map(({ name }) => name);
66
+ }
67
+ return [workspacePattern];
68
+ })
69
+ .map((workspaceName) => {
70
+ const workspace = project.findWorkspaceByNameOrAlias(workspaceName);
71
+ if (!workspace) {
72
+ logger.error(
73
+ `Workspace name or alias not found: ${JSON.stringify(workspaceName)}`,
74
+ );
75
+ process.exit(1);
76
+ }
77
+ return workspace;
78
+ })
79
+ .filter(Boolean)
80
+ : options.inline
81
+ ? project.workspaces
82
+ : project.listWorkspacesWithScript(script);
83
+ workspaces = sortWorkspaces(workspaces);
84
+ if (!workspaces.length) {
85
+ if (
86
+ workspacePatterns.length === 1 &&
87
+ !workspacePatterns[0].includes("*")
88
+ ) {
89
+ logger.error(
90
+ `Workspace not found: ${JSON.stringify(workspacePatterns[0])}`,
91
+ );
92
+ } else {
93
+ logger.error(
94
+ `No ${workspacePatterns.length ? "matching " : ""}workspaces found${options.inline ? " in the project" : " with script " + JSON.stringify(script)}`,
95
+ );
96
+ }
97
+ process.exit(1);
98
+ }
99
+ if (
100
+ !options.inline &&
101
+ !workspaces.some((workspace) => workspace.scripts.includes(script))
102
+ ) {
103
+ logger.error(
104
+ `Script not found in target workspace${workspaces.length === 1 ? "" : "s"}: ${JSON.stringify(script)}`,
105
+ );
106
+ process.exit(1);
107
+ }
108
+ workspaces.sort((a, b) => a.path.localeCompare(b.path));
109
+ const { output, summary } = project.runScriptAcrossWorkspaces({
110
+ workspacePatterns: workspaces.map(({ name }) => name),
111
+ script,
112
+ inline: options.inline
113
+ ? options.inlineName || options.shell
114
+ ? {
115
+ scriptName: options.inlineName,
116
+ shell: options.shell,
117
+ }
118
+ : true
119
+ : undefined,
120
+ args: scriptArgs,
121
+ parallel:
122
+ typeof options.parallel === "boolean" ||
123
+ typeof options.parallel === "undefined"
124
+ ? options.parallel
125
+ : options.parallel === "true"
126
+ ? true
127
+ : options.parallel === "false"
128
+ ? false
129
+ : {
130
+ max: options.parallel,
131
+ },
132
+ });
133
+ const scriptName = options.inline
134
+ ? options.inlineName || "(inline)"
135
+ : script;
136
+ const handleOutput = async () => {
137
+ if (logger.printLevel === "silent") return;
138
+ for await (const { outputChunk, scriptMetadata } of output) {
139
+ commandOutputLogger.logOutput(
140
+ outputChunk.decode(),
141
+ "info",
142
+ process[outputChunk.streamName],
143
+ options.prefix
144
+ ? `[${scriptMetadata.workspace.name}:${scriptName}] `
145
+ : "",
146
+ );
147
+ }
148
+ };
149
+ handleOutput();
150
+ const exitResults = await summary;
151
+ exitResults.scriptResults.forEach(
152
+ ({ success, metadata: { workspace }, exitCode }) => {
153
+ logger.info(
154
+ `${success ? "✅" : "❌"} ${workspace.name}: ${scriptName}${exitCode ? ` (exited with code ${exitCode})` : ""}`,
155
+ );
156
+ },
157
+ );
158
+ const s = exitResults.scriptResults.length === 1 ? "" : "s";
159
+ if (exitResults.failureCount) {
160
+ const message = `${exitResults.failureCount} of ${exitResults.scriptResults.length} script${s} failed`;
161
+ logger.info(message);
162
+ } else {
163
+ logger.info(
164
+ `${exitResults.scriptResults.length} script${s} ran successfully`,
165
+ );
166
+ }
167
+ if (options.jsonOutfile) {
168
+ const fullOutputPath = path.resolve(
169
+ project.rootDirectory,
170
+ options.jsonOutfile,
171
+ );
172
+ // Check if can make directory
173
+ const jsonOutputDir = path.dirname(fullOutputPath);
174
+ if (!fs.existsSync(jsonOutputDir)) {
175
+ try {
176
+ fs.mkdirSync(jsonOutputDir, {
177
+ recursive: true,
178
+ });
179
+ } catch (error) {
180
+ logger.error(
181
+ `Failed to create JSON output file directory "${jsonOutputDir}": ${error}`,
182
+ );
183
+ process.exit(1);
184
+ }
185
+ } else if (fs.statSync(jsonOutputDir).isFile()) {
186
+ logger.error(
187
+ `Given JSON output file directory "${jsonOutputDir}" is an existing file`,
188
+ );
189
+ process.exit(1);
190
+ }
191
+ // Check if can make file
192
+ if (
193
+ fs.existsSync(fullOutputPath) &&
194
+ fs.statSync(fullOutputPath).isDirectory()
195
+ ) {
196
+ logger.error(
197
+ `Given JSON output file path "${fullOutputPath}" is an existing directory`,
198
+ );
199
+ process.exit(1);
200
+ }
201
+ try {
202
+ fs.writeFileSync(fullOutputPath, JSON.stringify(exitResults, null, 2));
203
+ } catch (error) {
204
+ logger.error(
205
+ `Failed to write JSON output file "${fullOutputPath}": ${error}`,
206
+ );
207
+ process.exit(1);
208
+ }
209
+ logger.info(`JSON output written to ${fullOutputPath}`);
210
+ }
211
+ if (exitResults.failureCount) {
212
+ process.exit(1);
213
+ }
214
+ },
215
+ );
216
+
217
+ export { runScript };