bun-workspaces 1.4.1 → 1.5.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.
- package/README.md +2 -0
- package/package.json +1 -1
- package/src/ai/mcp/bwMcpServer.d.ts +4 -0
- package/src/ai/mcp/bwMcpServer.mjs +46 -0
- package/src/ai/mcp/core/index.d.ts +3 -0
- package/src/ai/mcp/core/index.mjs +3 -0
- package/src/ai/mcp/core/server.d.ts +14 -0
- package/src/ai/mcp/core/server.mjs +169 -0
- package/src/ai/mcp/core/transport.d.ts +12 -0
- package/src/ai/mcp/core/transport.mjs +45 -0
- package/src/ai/mcp/core/types.d.ts +104 -0
- package/src/ai/mcp/core/types.mjs +11 -0
- package/src/ai/mcp/index.d.ts +2 -0
- package/src/ai/mcp/index.mjs +2 -0
- package/src/ai/mcp/resources.d.ts +6 -0
- package/src/ai/mcp/resources.mjs +98 -0
- package/src/ai/mcp/tools.d.ts +6 -0
- package/src/ai/mcp/tools.mjs +210 -0
- package/src/cli/commands/commandHandlerUtils.mjs +1 -0
- package/src/cli/commands/commands.mjs +3 -0
- package/src/cli/commands/commandsConfig.d.ts +14 -0
- package/src/cli/commands/commandsConfig.mjs +8 -0
- package/src/cli/commands/handleSimpleCommands.mjs +4 -0
- package/src/cli/commands/index.d.ts +1 -0
- package/src/cli/commands/index.mjs +1 -0
- package/src/cli/commands/mcp.d.ts +3 -0
- package/src/cli/commands/mcp.mjs +13 -0
- package/src/cli/commands/runScript/handleRunScript.mjs +8 -0
- package/src/cli/commands/runScript/output/renderGroupedOutput.mjs +4 -2
- package/src/cli/createCli.mjs +1 -0
- package/src/config/public.d.ts +3 -0
- package/src/config/workspaceConfig/workspaceConfig.d.ts +13 -0
- package/src/config/workspaceConfig/workspaceConfig.mjs +11 -1
- package/src/config/workspaceConfig/workspaceConfigSchema.d.ts +24 -0
- package/src/config/workspaceConfig/workspaceConfigSchema.mjs +24 -0
- package/src/internal/core/runtime/onExit.mjs +1 -1
- package/src/internal/docs/apiQuickstart.d.ts +3 -0
- package/src/internal/docs/apiQuickstart.mjs +132 -0
- package/src/internal/docs/cliQuickstart.d.ts +2 -0
- package/src/internal/docs/cliQuickstart.mjs +86 -0
- package/src/internal/docs/index.d.ts +2 -0
- package/src/internal/docs/index.mjs +2 -0
- package/src/internal/generated/aiDocs/.gitkeep.mjs +0 -0
- package/src/internal/generated/aiDocs/docs.d.ts +10 -0
- package/src/internal/generated/aiDocs/docs.mjs +285 -0
- package/src/internal/generated/ajv/validateWorkspaceConfig.mjs +1 -1
- package/src/runScript/subprocesses.mjs +4 -1
- package/src/workspaces/dependencyGraph/index.d.ts +1 -0
- package/src/workspaces/dependencyGraph/index.mjs +2 -1
- package/src/workspaces/dependencyGraph/validateDependencyRules.d.ts +7 -0
- package/src/workspaces/dependencyGraph/validateDependencyRules.mjs +66 -0
- package/src/workspaces/errors.d.ts +1 -0
- package/src/workspaces/errors.mjs +1 -0
- package/src/workspaces/findWorkspaces.d.ts +1 -1
- package/src/workspaces/findWorkspaces.mjs +8 -2
- package/src/workspaces/workspacePattern.d.ts +1 -0
- package/src/workspaces/workspacePattern.mjs +8 -4
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { WORKSPACE_ERRORS } from "../errors.mjs";
|
|
2
|
+
import { matchWorkspacesByPatterns } from "../workspacePattern.mjs"; // CONCATENATED MODULE: external "../errors.mjs"
|
|
3
|
+
// CONCATENATED MODULE: external "../workspacePattern.mjs"
|
|
4
|
+
// CONCATENATED MODULE: ./src/workspaces/dependencyGraph/validateDependencyRules.ts
|
|
5
|
+
|
|
6
|
+
const getTransitiveDeps = (workspaceName, workspaceMap, chain, visited) => {
|
|
7
|
+
const entry = workspaceMap[workspaceName];
|
|
8
|
+
if (!entry) return [];
|
|
9
|
+
const result = [];
|
|
10
|
+
for (const depName of entry.workspace.dependencies) {
|
|
11
|
+
if (visited.has(depName)) continue;
|
|
12
|
+
visited.add(depName);
|
|
13
|
+
const depChain = [...chain, depName];
|
|
14
|
+
result.push({
|
|
15
|
+
name: depName,
|
|
16
|
+
chain: depChain,
|
|
17
|
+
});
|
|
18
|
+
result.push(...getTransitiveDeps(depName, workspaceMap, depChain, visited));
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
const validateWorkspaceDependencyRules = ({ workspaceMap }) => {
|
|
23
|
+
const violations = [];
|
|
24
|
+
for (const [workspaceName, { config }] of Object.entries(workspaceMap)) {
|
|
25
|
+
const rule = config.rules?.workspaceDependencies;
|
|
26
|
+
if (!rule?.allowPatterns && !rule?.denyPatterns) continue;
|
|
27
|
+
const transitiveDeps = getTransitiveDeps(
|
|
28
|
+
workspaceName,
|
|
29
|
+
workspaceMap,
|
|
30
|
+
[workspaceName],
|
|
31
|
+
new Set([workspaceName]),
|
|
32
|
+
);
|
|
33
|
+
for (const { name: depName, chain } of transitiveDeps) {
|
|
34
|
+
const depWorkspace = workspaceMap[depName]?.workspace;
|
|
35
|
+
if (!depWorkspace) continue;
|
|
36
|
+
const chainStr = chain.join(" -> ");
|
|
37
|
+
if (rule.denyPatterns) {
|
|
38
|
+
const isDenied =
|
|
39
|
+
matchWorkspacesByPatterns(rule.denyPatterns, [depWorkspace]).length >
|
|
40
|
+
0;
|
|
41
|
+
if (isDenied) {
|
|
42
|
+
violations.push(
|
|
43
|
+
`"${workspaceName}" violates workspaceDependencies rule: workspace "${depName}" is denied by denyPatterns (dependency chain: ${chainStr})`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (rule.allowPatterns) {
|
|
48
|
+
const isAllowed =
|
|
49
|
+
matchWorkspacesByPatterns(rule.allowPatterns, [depWorkspace]).length >
|
|
50
|
+
0;
|
|
51
|
+
if (!isAllowed) {
|
|
52
|
+
violations.push(
|
|
53
|
+
`"${workspaceName}" violates workspaceDependencies rule: workspace "${depName}" is not permitted by allowPatterns (dependency chain: ${chainStr})`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (violations.length > 0) {
|
|
60
|
+
throw new WORKSPACE_ERRORS.DependencyRuleViolation(
|
|
61
|
+
`Workspace dependency rule violations:\n${violations.map((v) => ` - ${v}`).join("\n")}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { validateWorkspaceDependencyRules };
|
|
@@ -8,7 +8,10 @@ import {
|
|
|
8
8
|
import { BUN_LOCK_ERRORS, readBunLockfile } from "../internal/bun/index.mjs";
|
|
9
9
|
import { BunWorkspacesError } from "../internal/core/index.mjs";
|
|
10
10
|
import { logger } from "../internal/logger/logger.mjs";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
resolveWorkspaceDependencies,
|
|
13
|
+
validateWorkspaceDependencyRules,
|
|
14
|
+
} from "./dependencyGraph/index.mjs";
|
|
12
15
|
import { WORKSPACE_ERRORS } from "./errors.mjs";
|
|
13
16
|
import {
|
|
14
17
|
resolvePackageJsonContent,
|
|
@@ -20,7 +23,7 @@ import {
|
|
|
20
23
|
// CONCATENATED MODULE: external "../internal/bun/index.mjs"
|
|
21
24
|
// CONCATENATED MODULE: external "../internal/core/index.mjs"
|
|
22
25
|
// CONCATENATED MODULE: external "../internal/logger/logger.mjs"
|
|
23
|
-
// CONCATENATED MODULE: external "./dependencyGraph/
|
|
26
|
+
// CONCATENATED MODULE: external "./dependencyGraph/index.mjs"
|
|
24
27
|
// CONCATENATED MODULE: external "./errors.mjs"
|
|
25
28
|
// CONCATENATED MODULE: external "./packageJson.mjs"
|
|
26
29
|
// CONCATENATED MODULE: ./src/workspaces/findWorkspaces.ts
|
|
@@ -176,6 +179,9 @@ const findWorkspaces = ({
|
|
|
176
179
|
bunCatalogs,
|
|
177
180
|
),
|
|
178
181
|
);
|
|
182
|
+
validateWorkspaceDependencyRules({
|
|
183
|
+
workspaceMap,
|
|
184
|
+
});
|
|
179
185
|
validateWorkspaceAliases(workspaces, workspaceAliases, rootWorkspace.name);
|
|
180
186
|
logger.debug(
|
|
181
187
|
`Found ${workspaces.length} workspaces: ${workspaces.map((ws) => ws.name).join(", ")}`,
|
|
@@ -7,6 +7,7 @@ export type WorkspacePattern = {
|
|
|
7
7
|
value: string;
|
|
8
8
|
isNegated: boolean;
|
|
9
9
|
};
|
|
10
|
+
export declare const WORKSPACE_PATTERN_NEGATION_PREFIX = "not:";
|
|
10
11
|
export declare const WORKSPACE_PATTERN_SEPARATOR = ":";
|
|
11
12
|
export declare const parseWorkspacePattern: (
|
|
12
13
|
pattern: string,
|
|
@@ -5,10 +5,13 @@ import { createWildcardRegex, defineErrors } from "../internal/core/index.mjs";
|
|
|
5
5
|
|
|
6
6
|
const TARGETS = ["path", "alias", "name", "tag"];
|
|
7
7
|
const WORKSPACE_PATTERN_ERRORS = defineErrors("InvalidWorkspacePattern");
|
|
8
|
+
const WORKSPACE_PATTERN_NEGATION_PREFIX = "not:";
|
|
8
9
|
const WORKSPACE_PATTERN_SEPARATOR = ":";
|
|
9
10
|
const parseWorkspacePattern = (pattern) => {
|
|
10
|
-
const isNegated = pattern.startsWith(
|
|
11
|
-
const patternValue = isNegated
|
|
11
|
+
const isNegated = pattern.startsWith(WORKSPACE_PATTERN_NEGATION_PREFIX);
|
|
12
|
+
const patternValue = isNegated
|
|
13
|
+
? pattern.slice(WORKSPACE_PATTERN_NEGATION_PREFIX.length)
|
|
14
|
+
: pattern;
|
|
12
15
|
const target = TARGETS.find((target) =>
|
|
13
16
|
patternValue.startsWith(target + WORKSPACE_PATTERN_SEPARATOR),
|
|
14
17
|
);
|
|
@@ -16,7 +19,7 @@ const parseWorkspacePattern = (pattern) => {
|
|
|
16
19
|
return {
|
|
17
20
|
target: "default",
|
|
18
21
|
value: patternValue,
|
|
19
|
-
isNegated
|
|
22
|
+
isNegated,
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
25
|
const value = patternValue.slice(
|
|
@@ -62,7 +65,7 @@ const PATTERN_TARGET_HANDLERS = {
|
|
|
62
65
|
},
|
|
63
66
|
path: (pattern, workspaces) => {
|
|
64
67
|
return workspaces.filter((workspace) =>
|
|
65
|
-
new bun.Glob(pattern.value).match(workspace.path),
|
|
68
|
+
new bun.Glob(pattern.value.replace(/\/+$/, "")).match(workspace.path),
|
|
66
69
|
);
|
|
67
70
|
},
|
|
68
71
|
tag: (pattern, workspaces, wildcardRegex) => {
|
|
@@ -104,6 +107,7 @@ const matchWorkspacesByPatterns = (patterns, workspaces) => {
|
|
|
104
107
|
|
|
105
108
|
export {
|
|
106
109
|
WORKSPACE_PATTERN_ERRORS,
|
|
110
|
+
WORKSPACE_PATTERN_NEGATION_PREFIX,
|
|
107
111
|
WORKSPACE_PATTERN_SEPARATOR,
|
|
108
112
|
matchWorkspacesByPatterns,
|
|
109
113
|
parseWorkspacePattern,
|