bun-workspaces 1.2.0 → 1.3.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/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.2.0",
3
+ "version": "1.3.1",
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",
@@ -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,13 @@
1
+ import type { ShellOption } from "../../project";
2
+ import type { ParallelMaxValue } from "../../runScript";
3
+ import { type ResolvedRootConfig } from "./rootConfig";
4
+ export type RootConfig = {
5
+ defaults?: {
6
+ parallelMax?: ParallelMaxValue;
7
+ shell?: ShellOption;
8
+ includeRootWorkspace?: boolean;
9
+ };
10
+ };
11
+ export declare const defineRootConfig: (
12
+ config: RootConfig,
13
+ ) => 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;