bun-workspaces 1.4.0 → 1.5.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 (56) hide show
  1. package/README.md +2 -0
  2. package/package.json +13 -4
  3. package/src/ai/mcp/bwMcpServer.d.ts +4 -0
  4. package/src/ai/mcp/bwMcpServer.mjs +46 -0
  5. package/src/ai/mcp/core/index.d.ts +3 -0
  6. package/src/ai/mcp/core/index.mjs +3 -0
  7. package/src/ai/mcp/core/server.d.ts +14 -0
  8. package/src/ai/mcp/core/server.mjs +169 -0
  9. package/src/ai/mcp/core/transport.d.ts +12 -0
  10. package/src/ai/mcp/core/transport.mjs +45 -0
  11. package/src/ai/mcp/core/types.d.ts +104 -0
  12. package/src/ai/mcp/core/types.mjs +11 -0
  13. package/src/ai/mcp/index.d.ts +2 -0
  14. package/src/ai/mcp/index.mjs +2 -0
  15. package/src/ai/mcp/resources.d.ts +6 -0
  16. package/src/ai/mcp/resources.mjs +98 -0
  17. package/src/ai/mcp/tools.d.ts +6 -0
  18. package/src/ai/mcp/tools.mjs +210 -0
  19. package/src/cli/commands/commandHandlerUtils.mjs +1 -0
  20. package/src/cli/commands/commands.mjs +3 -0
  21. package/src/cli/commands/commandsConfig.d.ts +14 -0
  22. package/src/cli/commands/commandsConfig.mjs +8 -0
  23. package/src/cli/commands/handleSimpleCommands.mjs +4 -0
  24. package/src/cli/commands/index.d.ts +1 -0
  25. package/src/cli/commands/index.mjs +1 -0
  26. package/src/cli/commands/mcp.d.ts +3 -0
  27. package/src/cli/commands/mcp.mjs +13 -0
  28. package/src/cli/commands/runScript/handleRunScript.mjs +8 -0
  29. package/src/cli/commands/runScript/output/renderGroupedOutput.mjs +4 -2
  30. package/src/cli/createCli.mjs +1 -0
  31. package/src/config/public.d.ts +3 -0
  32. package/src/config/workspaceConfig/workspaceConfig.d.ts +13 -0
  33. package/src/config/workspaceConfig/workspaceConfig.mjs +11 -1
  34. package/src/config/workspaceConfig/workspaceConfigSchema.d.ts +24 -0
  35. package/src/config/workspaceConfig/workspaceConfigSchema.mjs +24 -0
  36. package/src/internal/docs/apiQuickstart.d.ts +3 -0
  37. package/src/internal/docs/apiQuickstart.mjs +132 -0
  38. package/src/internal/docs/cliQuickstart.d.ts +2 -0
  39. package/src/internal/docs/cliQuickstart.mjs +86 -0
  40. package/src/internal/docs/index.d.ts +2 -0
  41. package/src/internal/docs/index.mjs +2 -0
  42. package/src/internal/generated/aiDocs/.gitkeep.mjs +0 -0
  43. package/src/internal/generated/aiDocs/docs.d.ts +10 -0
  44. package/src/internal/generated/aiDocs/docs.mjs +285 -0
  45. package/src/internal/generated/ajv/validateWorkspaceConfig.mjs +1 -1
  46. package/src/runScript/subprocesses.mjs +1 -0
  47. package/src/workspaces/dependencyGraph/index.d.ts +1 -0
  48. package/src/workspaces/dependencyGraph/index.mjs +2 -1
  49. package/src/workspaces/dependencyGraph/validateDependencyRules.d.ts +7 -0
  50. package/src/workspaces/dependencyGraph/validateDependencyRules.mjs +66 -0
  51. package/src/workspaces/errors.d.ts +1 -0
  52. package/src/workspaces/errors.mjs +1 -0
  53. package/src/workspaces/findWorkspaces.d.ts +1 -1
  54. package/src/workspaces/findWorkspaces.mjs +8 -2
  55. package/src/workspaces/workspacePattern.d.ts +1 -0
  56. 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 };
@@ -10,4 +10,5 @@ export declare const WORKSPACE_ERRORS: import("../internal/core").DefinedErrors<
10
10
  | "AliasConflict"
11
11
  | "AliasedWorkspaceNotFound"
12
12
  | "RootWorkspaceNotFound"
13
+ | "DependencyRuleViolation"
13
14
  >;
@@ -13,6 +13,7 @@ const WORKSPACE_ERRORS = defineErrors(
13
13
  "AliasConflict",
14
14
  "AliasedWorkspaceNotFound",
15
15
  "RootWorkspaceNotFound",
16
+ "DependencyRuleViolation",
16
17
  );
17
18
 
18
19
  export { WORKSPACE_ERRORS };
@@ -1,4 +1,4 @@
1
- import { type WorkspaceMap } from "./dependencyGraph/resolveDependencies";
1
+ import { type WorkspaceMap } from "./dependencyGraph";
2
2
  import type { Workspace } from "./workspace";
3
3
  export interface FindWorkspacesOptions {
4
4
  rootDirectory: string;
@@ -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 { resolveWorkspaceDependencies } from "./dependencyGraph/resolveDependencies.mjs";
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/resolveDependencies.mjs"
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 ? pattern.slice(1) : pattern;
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: pattern.startsWith("!"),
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,