bun-workspaces 0.1.2 → 0.2.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.
- package/.vscode/extensions.json +12 -0
- package/.vscode/settings.json +23 -0
- package/README.md +11 -5
- package/package.json +1 -1
- package/src/cli/projectCommands.ts +20 -9
- package/src/internal/regex.ts +5 -0
- package/src/project/project.ts +9 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"recommendations": [
|
|
3
|
+
"esbenp.prettier-vscode",
|
|
4
|
+
"oven.bun-vscode",
|
|
5
|
+
"streetsidesoftware.code-spell-checker",
|
|
6
|
+
"jasonnutter.vscode-codeowners",
|
|
7
|
+
"EditorConfig.EditorConfig",
|
|
8
|
+
"dbaeumer.vscode-eslint",
|
|
9
|
+
"github.vscode-github-actions",
|
|
10
|
+
"aaron-bond.better-comments"
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.codeActionsOnSave": {
|
|
3
|
+
"source.fixAll.eslint": "explicit"
|
|
4
|
+
},
|
|
5
|
+
"eslint.codeActionsOnSave.rules": ["import/order"],
|
|
6
|
+
"eslint.validate": ["javascript", "typescript"],
|
|
7
|
+
"[typescript]": {
|
|
8
|
+
"editor.formatOnSave": true,
|
|
9
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
10
|
+
},
|
|
11
|
+
"[javascript]": {
|
|
12
|
+
"editor.formatOnSave": true,
|
|
13
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
14
|
+
},
|
|
15
|
+
"[json]": {
|
|
16
|
+
"editor.formatOnSave": true,
|
|
17
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
18
|
+
},
|
|
19
|
+
"[jsonc]": {
|
|
20
|
+
"editor.formatOnSave": true,
|
|
21
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/README.md
CHANGED
|
@@ -26,6 +26,9 @@ bw ls
|
|
|
26
26
|
# List workspace names only
|
|
27
27
|
bw list-workspaces --name-only
|
|
28
28
|
|
|
29
|
+
# Filter list of workspaces with wildcard
|
|
30
|
+
bw list-workspaces "my-*"
|
|
31
|
+
|
|
29
32
|
# List all workspace scripts
|
|
30
33
|
bw list-scripts
|
|
31
34
|
# List script names only
|
|
@@ -43,19 +46,22 @@ bw script-info my-script --workspaces-only
|
|
|
43
46
|
# Run a script for all
|
|
44
47
|
# workspaces that have it
|
|
45
48
|
# in their `scripts` field
|
|
46
|
-
bw run
|
|
49
|
+
bw run my-script
|
|
47
50
|
|
|
48
51
|
# Run a script for a specific workspace
|
|
49
|
-
bw run
|
|
52
|
+
bw run my-script my-workspace
|
|
50
53
|
|
|
51
54
|
# Run a script for multiple workspaces
|
|
52
|
-
bw run
|
|
55
|
+
bw run my-script workspace-a workspace-b
|
|
56
|
+
|
|
57
|
+
# Run a script for workspaces using wildcard
|
|
58
|
+
bw run my-script "my-workspace-*"
|
|
53
59
|
|
|
54
60
|
# Run script in parallel for all workspaces
|
|
55
|
-
bw run
|
|
61
|
+
bw run my-script --parallel
|
|
56
62
|
|
|
57
63
|
# Append args to each script call
|
|
58
|
-
bw run
|
|
64
|
+
bw run my-script --args "--my --args"
|
|
59
65
|
|
|
60
66
|
# Help (--help can also be passed to any command)
|
|
61
67
|
bw help
|
package/package.json
CHANGED
|
@@ -27,11 +27,11 @@ const listWorkspaces = ({
|
|
|
27
27
|
printLines,
|
|
28
28
|
}: ProjectCommandsContext) => {
|
|
29
29
|
program
|
|
30
|
-
.command("list-workspaces")
|
|
30
|
+
.command("list-workspaces [pattern]")
|
|
31
31
|
.aliases(["ls", "list"])
|
|
32
32
|
.description("List all workspaces")
|
|
33
33
|
.option("--name-only", "Only show workspace names")
|
|
34
|
-
.action((options) => {
|
|
34
|
+
.action((pattern, options) => {
|
|
35
35
|
logger.debug("Command: List workspaces");
|
|
36
36
|
|
|
37
37
|
if (options.more) {
|
|
@@ -39,7 +39,10 @@ const listWorkspaces = ({
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const lines: string[] = [];
|
|
42
|
-
|
|
42
|
+
(pattern
|
|
43
|
+
? project.findWorkspacesByPattern(pattern)
|
|
44
|
+
: project.workspaces
|
|
45
|
+
).forEach((workspace) => {
|
|
43
46
|
if (options.nameOnly) {
|
|
44
47
|
lines.push(workspace.name);
|
|
45
48
|
} else {
|
|
@@ -149,24 +152,32 @@ const runScript = ({
|
|
|
149
152
|
.description("Run a script in all workspaces")
|
|
150
153
|
.option("--parallel", "Run the scripts in parallel")
|
|
151
154
|
.option("--args <args>", "Args to append to the script command", "")
|
|
152
|
-
.action(async (script: string,
|
|
155
|
+
.action(async (script: string, _workspaces: string[], options) => {
|
|
153
156
|
logger.debug(
|
|
154
157
|
`Command: Run script ${JSON.stringify(script)} for ${
|
|
155
|
-
|
|
156
|
-
? "workspaces " +
|
|
158
|
+
_workspaces.length
|
|
159
|
+
? "workspaces " + _workspaces.join(", ")
|
|
157
160
|
: "all workspaces"
|
|
158
161
|
} (parallel: ${!!options.parallel}, method: ${JSON.stringify(
|
|
159
162
|
options.method,
|
|
160
163
|
)}, args: ${JSON.stringify(options.args)})`,
|
|
161
164
|
);
|
|
162
165
|
|
|
163
|
-
workspaces =
|
|
164
|
-
?
|
|
166
|
+
const workspaces = _workspaces.length
|
|
167
|
+
? _workspaces.flatMap((workspacePattern) => {
|
|
168
|
+
if (workspacePattern.includes("*")) {
|
|
169
|
+
return project
|
|
170
|
+
.findWorkspacesByPattern(workspacePattern)
|
|
171
|
+
.filter(({ packageJson: { scripts } }) => scripts?.[script])
|
|
172
|
+
.map(({ name }) => name);
|
|
173
|
+
}
|
|
174
|
+
return [workspacePattern];
|
|
175
|
+
})
|
|
165
176
|
: project.listWorkspacesWithScript(script).map(({ name }) => name);
|
|
166
177
|
|
|
167
178
|
if (!workspaces.length) {
|
|
168
179
|
program.error(
|
|
169
|
-
`No workspaces found for script ${JSON.stringify(script)}`,
|
|
180
|
+
`No ${_workspaces.length ? "matching " : ""}workspaces found for script ${JSON.stringify(script)}`,
|
|
170
181
|
);
|
|
171
182
|
}
|
|
172
183
|
|
package/src/project/project.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { createWildcardRegex } from "../internal/regex";
|
|
2
3
|
import { findWorkspacesFromPackage, type Workspace } from "../workspaces";
|
|
3
4
|
import { ERRORS } from "./errors";
|
|
4
5
|
import {
|
|
@@ -32,6 +33,7 @@ export interface Project {
|
|
|
32
33
|
listWorkspacesWithScript(scriptName: string): Workspace[];
|
|
33
34
|
listScriptsWithWorkspaces(): Record<string, ScriptMetadata>;
|
|
34
35
|
findWorkspaceByName(workspaceName: string): Workspace | null;
|
|
36
|
+
findWorkspacesByPattern(workspaceName: string): Workspace[];
|
|
35
37
|
createScriptCommand(
|
|
36
38
|
options: CreateProjectScriptCommandOptions,
|
|
37
39
|
): CreateProjectScriptCommandResult;
|
|
@@ -88,6 +90,13 @@ class _Project implements Project {
|
|
|
88
90
|
);
|
|
89
91
|
}
|
|
90
92
|
|
|
93
|
+
/** Accepts wildcard for finding a list of workspaces */
|
|
94
|
+
findWorkspacesByPattern(workspacePattern: string): Workspace[] {
|
|
95
|
+
if (!workspacePattern) return [];
|
|
96
|
+
const regex = createWildcardRegex(workspacePattern);
|
|
97
|
+
return this.workspaces.filter((workspace) => regex.test(workspace.name));
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
createScriptCommand(
|
|
92
101
|
options: CreateProjectScriptCommandOptions,
|
|
93
102
|
): CreateProjectScriptCommandResult {
|