bun-workspaces 1.1.2 → 1.3.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/README.md CHANGED
@@ -6,7 +6,14 @@
6
6
 
7
7
  ### [**See Full Documentation Here**: _https://bunworkspaces.com_](https://bunworkspaces.com)
8
8
 
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.
9
+ **Big Recent Updates!**
10
+
11
+ - Version 1 is here after the initial alpha! 🍔🍔👁️🍔🍔
12
+ - You can demo the CLI [directly in the browser](https://bunworkspaces.com/web-cli)
13
+ - There's now [an official blog](https://bunworkspaces.com/blog/bun-workspaces-v1) to cover noteworthy releases and more!
14
+ <hr/>
15
+
16
+ This is a CLI and TypeScript API to enhance your monorepo development with Bun's [native workspaces](https://bun.sh/docs/install/workspaces) feature for nested JavaScript/TypeScript packages.
10
17
 
11
18
  - Works right away, with no boilerplate required 🍔🍴
12
19
  - Get metadata about your monorepo 🤖
package/bin/cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env bun
2
- import { createCli } from "bun-workspaces/src/cli";
2
+ import { createCli } from "bun-workspaces/cli";
3
3
  createCli().run();
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "bun-workspaces",
3
- "version": "1.1.2",
3
+ "version": "1.3.0",
4
4
  "description": "A monorepo management tool for Bun, with a CLI and API to enhance Bun's native workspaces.",
5
5
  "license": "MIT",
6
- "main": "src/index.mjs",
7
- "types": "src/index.d.ts",
6
+ "exports": {
7
+ ".": "./src/index.mjs",
8
+ "./cli": "./src/cli/index.mjs",
9
+ "./config": "./src/config/public.mjs"
10
+ },
11
+ "types": "./src/index.d.ts",
8
12
  "homepage": "https://bunworkspaces.com",
9
13
  "repository": {
10
14
  "type": "git",
@@ -148,7 +148,7 @@ export declare const CLI_COMMANDS_CONFIG: {
148
148
  readonly outputStyle: {
149
149
  readonly flags: ["-o", "--output-style <style>"];
150
150
  readonly description: "The output style to use";
151
- readonly values: ["grouped", "prefixed", "plain"];
151
+ readonly values: ["grouped", "prefixed", "plain", "none"];
152
152
  };
153
153
  readonly groupedLines: {
154
154
  readonly flags: ["-L", "--grouped-lines <count>"];
@@ -309,7 +309,7 @@ export declare const getCliCommandConfig: (commandName: CliCommandName) =>
309
309
  readonly outputStyle: {
310
310
  readonly flags: ["-o", "--output-style <style>"];
311
311
  readonly description: "The output style to use";
312
- readonly values: ["grouped", "prefixed", "plain"];
312
+ readonly values: ["grouped", "prefixed", "plain", "none"];
313
313
  };
314
314
  readonly groupedLines: {
315
315
  readonly flags: ["-L", "--grouped-lines <count>"];
@@ -73,6 +73,10 @@ const runScript = handleProjectCommand(
73
73
  `Command: Run ${options.inline ? "inline " : ""}script ${JSON.stringify(script)} for ${workspacePatterns.length ? "workspaces " + workspacePatterns.join(", ") : "all workspaces"}`,
74
74
  );
75
75
  logger.debug(`Options: ${JSON.stringify(options)}`);
76
+ const outputStyle = options.outputStyle
77
+ ? validateOutputStyle(options.outputStyle)
78
+ : getDefaultOutputStyle();
79
+ logger.debug(`Effective output style: ${outputStyle}`);
76
80
  const scriptEventTarget = createScriptEventTarget();
77
81
  const { output, summary, workspaces } = project.runScriptAcrossWorkspaces({
78
82
  workspacePatterns: workspacePatterns.length
@@ -90,7 +94,7 @@ const runScript = handleProjectCommand(
90
94
  args: scriptArgs,
91
95
  dependencyOrder: options.depOrder,
92
96
  ignoreDependencyFailure: options.ignoreDepFailure,
93
- ignoreOutput: logger.printLevel === "silent",
97
+ ignoreOutput: outputStyle === "none",
94
98
  onScriptEvent: (event, { workspace, exitResult }) => {
95
99
  setTimeout(() =>
96
100
  // place at end of call stack so listeners in render func receive event
@@ -168,11 +172,10 @@ const runScript = handleProjectCommand(
168
172
  prefix: false,
169
173
  stripDisruptiveControls,
170
174
  }),
175
+ none: async () => {
176
+ // no-op
177
+ },
171
178
  };
172
- const outputStyle = options.outputStyle
173
- ? validateOutputStyle(options.outputStyle)
174
- : getDefaultOutputStyle();
175
- logger.debug(`Effective output style: ${outputStyle}`);
176
179
  await outputStyleHandlers[outputStyle]();
177
180
  const exitResults = await summary;
178
181
  exitResults.scriptResults.forEach(
@@ -2,6 +2,7 @@ export declare const OUTPUT_STYLE_VALUES: readonly [
2
2
  "grouped",
3
3
  "prefixed",
4
4
  "plain",
5
+ "none",
5
6
  ];
6
7
  export type OutputStyleName = (typeof OUTPUT_STYLE_VALUES)[number];
7
8
  export declare const getDefaultOutputStyle: () => OutputStyleName;
@@ -3,7 +3,7 @@ import { IS_TTY } from "../../../../internal/core/runtime/terminal.mjs"; // CONC
3
3
  // CONCATENATED MODULE: external "../../../../internal/core/runtime/terminal.mjs"
4
4
  // CONCATENATED MODULE: ./src/cli/commands/runScript/output/outputStyle.ts
5
5
 
6
- const OUTPUT_STYLE_VALUES = ["grouped", "prefixed", "plain"];
6
+ const OUTPUT_STYLE_VALUES = ["grouped", "prefixed", "plain", "none"];
7
7
  const getDefaultOutputStyle = () => (IS_TTY ? "grouped" : "prefixed");
8
8
  const validateOutputStyle = (style) => {
9
9
  if (!OUTPUT_STYLE_VALUES.includes(style)) {
@@ -0,0 +1,10 @@
1
+ export type { ResolvedRootConfig } from "./rootConfig";
2
+ export type { ResolvedWorkspaceConfig } from "./workspaceConfig";
3
+ export {
4
+ type RootConfig,
5
+ defineRootConfig,
6
+ } from "./rootConfig/defineRootConfig";
7
+ export {
8
+ type WorkspaceConfig,
9
+ defineWorkspaceConfig,
10
+ } from "./workspaceConfig/defineWorkspaceConfig";
@@ -0,0 +1,6 @@
1
+ import { defineRootConfig } from "./rootConfig/defineRootConfig.mjs";
2
+ import { defineWorkspaceConfig } from "./workspaceConfig/defineWorkspaceConfig.mjs"; // CONCATENATED MODULE: external "./rootConfig/defineRootConfig.mjs"
3
+ // CONCATENATED MODULE: external "./workspaceConfig/defineWorkspaceConfig.mjs"
4
+ // CONCATENATED MODULE: ./src/config/public.ts
5
+
6
+ export { defineRootConfig, defineWorkspaceConfig };
@@ -0,0 +1,11 @@
1
+ import { type ResolvedRootConfig } from "./rootConfig";
2
+ export type RootConfig = {
3
+ defaults?: {
4
+ parallelMax?: number | string;
5
+ shell?: string;
6
+ includeRootWorkspace?: boolean;
7
+ };
8
+ };
9
+ export declare const defineRootConfig: (
10
+ config: RootConfig,
11
+ ) => ResolvedRootConfig;
@@ -0,0 +1,6 @@
1
+ import { resolveRootConfig } from "./rootConfig.mjs"; // CONCATENATED MODULE: external "./rootConfig.mjs"
2
+ // CONCATENATED MODULE: ./src/config/rootConfig/defineRootConfig.ts
3
+
4
+ const defineRootConfig = (config) => resolveRootConfig(config);
5
+
6
+ export { defineRootConfig };
@@ -1,4 +1,10 @@
1
- export declare const CONFIG_LOCATION_TYPES: string[];
1
+ export declare const CONFIG_LOCATION_TYPES: readonly [
2
+ "tsFile",
3
+ "jsFile",
4
+ "jsoncFile",
5
+ "jsonFile",
6
+ "packageJson",
7
+ ];
2
8
  export type ConfigLocationType = (typeof CONFIG_LOCATION_TYPES)[number];
3
9
  export type ConfigLocation = {
4
10
  type: ConfigLocationType;
@@ -1,6 +1,14 @@
1
1
  // CONCATENATED MODULE: ./src/config/util/configLocation.ts
2
- const CONFIG_LOCATION_TYPES = ["jsoncFile", "jsonFile", "packageJson"];
2
+ const CONFIG_LOCATION_TYPES = [
3
+ "tsFile",
4
+ "jsFile",
5
+ "jsoncFile",
6
+ "jsonFile",
7
+ "packageJson",
8
+ ];
3
9
  const CONFIG_LOCATION_PATHS = {
10
+ tsFile: (name) => `${name}.ts`,
11
+ jsFile: (name) => `${name}.js`,
4
12
  jsoncFile: (name) => `${name}.jsonc`,
5
13
  jsonFile: (name) => `${name}.json`,
6
14
  packageJson: (_, packageJsonKey) => `package.json["${packageJsonKey}"]`,
@@ -1,6 +1,8 @@
1
1
  import { type AnyFunction } from "../../internal/core";
2
2
  import { type ConfigLocation } from "./configLocation";
3
- export declare const InvalidJSONError: typeof import("../..").BunWorkspacesError;
3
+ export declare const LOAD_CONFIG_ERRORS: import("../../internal/core").DefinedErrors<
4
+ "InvalidJSON" | "NoExportError" | "ModuleLoadFailure"
5
+ >;
4
6
  export declare const getConfigLocation: (
5
7
  name: string,
6
8
  directory: string,
@@ -12,15 +12,52 @@ import {
12
12
  // CONCATENATED MODULE: external "./configLocation.mjs"
13
13
  // CONCATENATED MODULE: ./src/config/util/loadConfig.ts
14
14
 
15
- const InvalidJSONError = defineErrors("InvalidJSON").InvalidJSON;
15
+ const LOAD_CONFIG_ERRORS = defineErrors(
16
+ "InvalidJSON",
17
+ "NoExportError",
18
+ "ModuleLoadFailure",
19
+ );
16
20
  const parseJSON = (jsonString, path) => {
17
21
  try {
18
22
  return parseJSONC(jsonString);
19
23
  } catch (error) {
20
- throw new InvalidJSONError(`Invalid JSON at ${path}: ${error.message}`);
24
+ throw new LOAD_CONFIG_ERRORS.InvalidJSON(
25
+ `Invalid JSON at ${path}: ${error.message}`,
26
+ );
27
+ }
28
+ };
29
+ const parseModule = (locationType, directory, fileName) => {
30
+ const configFilePath = path_0.join(
31
+ directory,
32
+ createConfigLocationPath(locationType, fileName, ""),
33
+ );
34
+ if (fs.existsSync(configFilePath)) {
35
+ let content;
36
+ try {
37
+ // eslint-disable-next-line
38
+ const module = require(configFilePath);
39
+ content = module.default;
40
+ } catch (error) {
41
+ throw new LOAD_CONFIG_ERRORS.ModuleLoadFailure(
42
+ `Failed to load module at ${configFilePath}: ${error.message}`,
43
+ );
44
+ }
45
+ if (!content) {
46
+ throw new LOAD_CONFIG_ERRORS.NoExportError(
47
+ `No default export found in ${configFilePath}. Expected config object.`,
48
+ );
49
+ }
50
+ return {
51
+ type: locationType,
52
+ content,
53
+ path: path_0.relative(process.cwd(), configFilePath),
54
+ };
21
55
  }
56
+ return null;
22
57
  };
23
58
  const LOCATION_FINDERS = {
59
+ tsFile: (directory, fileName) => parseModule("tsFile", directory, fileName),
60
+ jsFile: (directory, fileName) => parseModule("jsFile", directory, fileName),
24
61
  jsoncFile: (directory, fileName) => {
25
62
  const configFilePath = path_0.join(
26
63
  directory,
@@ -93,7 +130,7 @@ const getConfigLocation = (name, directory, fileName, packageJsonKey) => {
93
130
  }
94
131
  if (locations.length > 1) {
95
132
  logger.warn(
96
- `Found multiple ${name} configs:\n${locations.map((location) => " " + location.path).join("\n")}\n Using config at ${locations[0]?.path}`,
133
+ `Found multiple ${name} configs:\n${locations.map((location) => " " + location.path).join("\n")}\nUsing config at ${locations[0]?.path}`,
97
134
  );
98
135
  }
99
136
  return locations[0] ?? null;
@@ -115,4 +152,4 @@ const loadConfig = (
115
152
  return processContent(location.content);
116
153
  };
117
154
 
118
- export { InvalidJSONError, getConfigLocation, loadConfig };
155
+ export { LOAD_CONFIG_ERRORS, getConfigLocation, loadConfig };
@@ -9,7 +9,7 @@ const executeValidator = (validator, name, config, ErrorType) => {
9
9
  if (!isValid) {
10
10
  const multipleErrors = (validator.errors?.length ?? 0) > 1;
11
11
  throw new ErrorType(
12
- `Root config is invalid:${multipleErrors ? "\n" : ""}${validator.errors?.map((error) => `${multipleErrors ? " " : " "}${`config${error.instancePath?.replace(/[/|\\](\d+)/g, "[$1]").replaceAll(/[/|\\]/g, ".") ?? ""}`.replace(/^config[^.]/, "config.")} ${error.message?.replace(/NOT/g, "not")}${suffixAdditionalPropertyName(error)}`).join("\n")}`,
12
+ `${name.replace("Config", "")} config is invalid:${multipleErrors ? "\n" : ""}${validator.errors?.map((error) => `${multipleErrors ? " " : " "}${`config${error.instancePath?.replace(/[/|\\](\d+)/g, "[$1]").replaceAll(/[/|\\]/g, ".") ?? ""}`.replace(/^config[^.]/, "config.")} ${error.message?.replace(/NOT/g, "not")}${suffixAdditionalPropertyName(error)}`).join("\n")}`,
13
13
  );
14
14
  }
15
15
  };
@@ -0,0 +1,11 @@
1
+ import {
2
+ type ResolvedWorkspaceConfig,
3
+ type ScriptConfig,
4
+ } from "./workspaceConfig";
5
+ export type WorkspaceConfig = {
6
+ alias?: string | string[];
7
+ scripts?: Record<string, ScriptConfig>;
8
+ };
9
+ export declare const defineWorkspaceConfig: (
10
+ config: WorkspaceConfig,
11
+ ) => ResolvedWorkspaceConfig;
@@ -0,0 +1,15 @@
1
+ import { resolveWorkspaceConfig } from "./workspaceConfig.mjs"; // CONCATENATED MODULE: external "./workspaceConfig.mjs"
2
+ // CONCATENATED MODULE: ./src/config/workspaceConfig/defineWorkspaceConfig.ts
3
+
4
+ const defineWorkspaceConfig = (config) => {
5
+ if (Array.isArray(config.aliases)) {
6
+ const { aliases, ...rest } = config;
7
+ return resolveWorkspaceConfig({
8
+ ...rest,
9
+ alias: aliases,
10
+ });
11
+ }
12
+ return resolveWorkspaceConfig(config);
13
+ };
14
+
15
+ export { defineWorkspaceConfig };
@@ -12,10 +12,23 @@ const workspaceConfig_validateWorkspaceConfig = (config) =>
12
12
  executeValidator(
13
13
  validate,
14
14
  "WorkspaceConfig",
15
- config,
15
+ {
16
+ ...config,
17
+ },
16
18
  WORKSPACE_CONFIG_ERRORS.InvalidWorkspaceConfig,
17
19
  );
18
20
  const resolveWorkspaceConfig = (config) => {
21
+ if (Array.isArray(config.aliases)) {
22
+ const { aliases, ...rest } = config;
23
+ workspaceConfig_validateWorkspaceConfig({
24
+ ...rest,
25
+ alias: aliases,
26
+ });
27
+ return {
28
+ aliases,
29
+ ...rest,
30
+ };
31
+ }
19
32
  workspaceConfig_validateWorkspaceConfig(config);
20
33
  return {
21
34
  aliases: resolveOptionalArray(config.alias ?? []),
package/src/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export {
24
24
  type ScriptEventMetadata,
25
25
  type OnScriptEventCallback,
26
26
  } from "./project";
27
+ export * from "./config/public";
27
28
  export {
28
29
  type ScriptEventName,
29
30
  type OutputStreamName,
package/src/index.mjs CHANGED
@@ -3,7 +3,8 @@ import {
3
3
  createMemoryProject,
4
4
  } from "./project/index.mjs";
5
5
  import { BunWorkspacesError } from "./internal/core/index.mjs";
6
- import { setLogLevel } from "./internal/logger/index.mjs"; // CONCATENATED MODULE: external "./project/index.mjs"
6
+ import { setLogLevel } from "./internal/logger/index.mjs";
7
+ export * from "./config/public.mjs"; // CONCATENATED MODULE: external "./project/index.mjs"
7
8
  // CONCATENATED MODULE: external "./internal/core/index.mjs"
8
9
  // CONCATENATED MODULE: external "./internal/logger/index.mjs"
9
10
  // CONCATENATED MODULE: ./src/index.ts
@@ -12,3 +12,8 @@ export type RequiredDeep<T> = T extends object
12
12
  [K in keyof T]: RequiredDeep<T[K]>;
13
13
  }>
14
14
  : T;
15
+ export type PartialDeep<T> = T extends object
16
+ ? Partial<{
17
+ [K in keyof T]: PartialDeep<T[K]>;
18
+ }>
19
+ : T;
@@ -21,7 +21,7 @@ declare class _MemoryProject extends ProjectBase implements Project {
21
21
  readonly name: string;
22
22
  readonly sourceType = "memory";
23
23
  readonly config: {
24
- root: import("../../config").ResolvedRootConfig;
24
+ root: import("../..").ResolvedRootConfig;
25
25
  workspaces: {};
26
26
  };
27
27
  readonly rootWorkspace: Workspace;
@@ -125,8 +125,9 @@ const findWorkspaces = ({
125
125
  path.dirname(packageJsonPath),
126
126
  );
127
127
  const matchPattern =
128
- workspaceGlobs.find((glob) => new bun.Glob(glob).match(relativePath)) ??
129
- "";
128
+ workspaceGlobs.find((glob) =>
129
+ new bun.Glob(glob.replace(/\/+$/, "")).match(relativePath),
130
+ ) ?? "";
130
131
  const isRootWorkspace = workspacePath === rootDirectory;
131
132
  if (!matchPattern && !isRootWorkspace) {
132
133
  logger.debug(`No match pattern found for ${relativePath}`);