bun-workspaces 0.2.0 → 1.0.0-alpha

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-workspaces",
3
- "version": "0.2.0",
3
+ "version": "1.0.0-alpha",
4
4
  "main": "src/index.ts",
5
5
  "homepage": "https://github.com/ScottMorse/bun-workspaces#readme",
6
6
  "bin": {
@@ -8,34 +8,34 @@
8
8
  },
9
9
  "custom": {
10
10
  "bunVersion": {
11
- "build": "1.1.38",
11
+ "build": "1.2.22",
12
12
  "libraryConsumer": "^1.1.x"
13
13
  }
14
14
  },
15
15
  "scripts": {
16
- "cli": "NODE_ENV=production bun run bin/cli.js",
17
- "cli:dev": "NODE_ENV=development bun run bin/cli.js",
16
+ "cli": "bun run bin/cli.js",
17
+ "cli:dev": "_BW_RUNTIME_MODE=development bun run bin/cli.js",
18
+ "test": "_BW_RUNTIME_MODE=test bun run bin/cli.js",
18
19
  "type-check": "tsc --noEmit",
19
20
  "lint": "eslint .",
20
21
  "format": "prettier --write .",
21
22
  "format-check": "prettier --check ."
22
23
  },
23
24
  "devDependencies": {
24
- "@types/bun": "^1.1.14",
25
- "@typescript-eslint/eslint-plugin": "^8.17.0",
26
- "@typescript-eslint/parser": "^8.17.0",
25
+ "@types/bun": "^1.2.22",
26
+ "@typescript-eslint/eslint-plugin": "^8.44.1",
27
+ "@typescript-eslint/parser": "^8.44.1",
27
28
  "bun-workspaces": "file:.",
28
- "eslint": "^9.16.0",
29
- "eslint-plugin-import": "^2.31.0",
30
- "prettier": "^3.4.2",
31
- "typescript-eslint": "^8.17.0"
29
+ "eslint": "^9.36.0",
30
+ "eslint-plugin-import": "^2.32.0",
31
+ "prettier": "^3.6.2",
32
+ "typescript-eslint": "^8.44.1"
32
33
  },
33
34
  "dependencies": {
34
35
  "commander": "^12.1.0",
35
- "pino": "^9.5.0",
36
- "pino-pretty": "^13.0.0"
36
+ "glob": "^11.0.3"
37
37
  },
38
38
  "peerDependencies": {
39
- "typescript": "^5.0.0"
39
+ "typescript": "^5.9.2"
40
40
  }
41
41
  }
package/src/cli/cli.ts CHANGED
@@ -7,7 +7,6 @@ import {
7
7
  import { logger } from "../internal/logger";
8
8
  import { initializeWithGlobalOptions } from "./globalOptions";
9
9
  import { defineProjectCommands } from "./projectCommands";
10
- import { OUTPUT_CONFIG } from "./output";
11
10
 
12
11
  export interface RunCliOptions {
13
12
  argv?: string | string[];
@@ -18,16 +17,12 @@ export interface CliProgram {
18
17
  }
19
18
 
20
19
  export interface CreateCliProgramOptions {
21
- writeOut?: (s: string) => void;
22
- writeErr?: (s: string) => void;
23
20
  handleError?: (error: Error) => void;
24
21
  postInit?: (program: Command) => unknown;
25
22
  defaultCwd?: string;
26
23
  }
27
24
 
28
25
  export const createCliProgram = ({
29
- writeOut = OUTPUT_CONFIG.writeOut,
30
- writeErr = OUTPUT_CONFIG.writeErr,
31
26
  handleError,
32
27
  postInit,
33
28
  defaultCwd = process.cwd(),
@@ -48,8 +43,9 @@ export const createCliProgram = ({
48
43
  .description("CLI for utilities for Bun workspaces")
49
44
  .version(packageJson.version)
50
45
  .configureOutput({
51
- writeOut,
52
- writeErr,
46
+ writeOut: (s) => logger.info(s),
47
+ writeErr: (s) =>
48
+ s.startsWith("Usage") ? logger.info(s) : logger.error(s),
53
49
  });
54
50
 
55
51
  postInit?.(program);
@@ -75,7 +71,6 @@ export const createCliProgram = ({
75
71
  defineProjectCommands({
76
72
  program,
77
73
  project,
78
- printLines: (...lines: string[]) => writeOut(lines.join("\n") + "\n"),
79
74
  });
80
75
 
81
76
  await program.parseAsync(args);
@@ -1,22 +1,48 @@
1
1
  import path from "path";
2
2
  import { type Command, Option } from "commander";
3
- import { logger } from "../internal/logger";
3
+ import { loadConfigFile, type BunWorkspacesConfig } from "../config";
4
+ import { LOG_LEVELS, logger, type LogLevelSetting } from "../internal/logger";
4
5
  import { createProject } from "../project";
5
6
 
6
- const LOG_LEVELS = ["silent", "error", "warn", "info", "debug"] as const;
7
-
8
- export type LogLevel = (typeof LOG_LEVELS)[number];
9
-
10
7
  export interface CliGlobalOptions {
11
- logLevel: LogLevel;
8
+ logLevel: LogLevelSetting;
12
9
  cwd: string;
10
+ configFile?: string;
13
11
  }
14
12
 
15
13
  export type CliGlobalOptionName = keyof CliGlobalOptions;
16
14
 
17
- const defineGlobalOptions = (program: Command, defaultCwd: string) => {
15
+ const getWorkingDirectory = (
16
+ program: Command,
17
+ args: string[],
18
+ defaultCwd: string,
19
+ ) => {
20
+ program.addOption(
21
+ new Option("-d --cwd <path>", "Working directory").default(defaultCwd),
22
+ );
23
+ program.parseOptions(args);
24
+ return program.opts().cwd;
25
+ };
26
+
27
+ const getConfig = (program: Command, args: string[]) => {
28
+ program.addOption(new Option("-c --configFile <path>", "Config file"));
29
+ program.parseOptions(args);
30
+ return program.opts().configFile;
31
+ };
32
+
33
+ const defineGlobalOptions = (
34
+ program: Command,
35
+ args: string[],
36
+ defaultCwd: string,
37
+ ) => {
38
+ const cwd = getWorkingDirectory(program, args, defaultCwd);
39
+
40
+ const configFilePath = getConfig(program, args);
41
+
42
+ const config = loadConfigFile(configFilePath, cwd);
43
+
18
44
  const globalOptions: {
19
- [K in CliGlobalOptionName]: {
45
+ [K in Exclude<CliGlobalOptionName, "configFile" | "cwd">]: {
20
46
  shortName: string;
21
47
  description: string;
22
48
  defaultValue: CliGlobalOptions[K];
@@ -27,36 +53,39 @@ const defineGlobalOptions = (program: Command, defaultCwd: string) => {
27
53
  logLevel: {
28
54
  shortName: "l",
29
55
  description: "Log levels",
30
- defaultValue: logger.level as LogLevel,
31
- values: LOG_LEVELS,
56
+ defaultValue:
57
+ config?.cli?.logLevel ?? (logger.printLevel as LogLevelSetting),
58
+ values: [...LOG_LEVELS, "silent"],
32
59
  param: "level",
33
60
  },
34
- cwd: {
35
- shortName: "d",
36
- description: "Working directory",
37
- defaultValue: defaultCwd ?? process.cwd(),
38
- param: "dir",
39
- },
40
61
  };
41
62
 
42
63
  Object.entries(globalOptions).forEach(
43
- ([name, { shortName, description, defaultValue, param, values }]) => {
64
+ ([name, { shortName, description, param, values, defaultValue }]) => {
44
65
  const option = new Option(
45
66
  `-${shortName} --${name}${param ? ` <${param}>` : ""}`,
46
67
  description,
47
68
  ).default(defaultValue);
48
69
 
49
- program.addOption(values?.length ? option.choices(values) : option);
70
+ program.addOption(
71
+ values?.length ? option.choices(values as string[]) : option,
72
+ );
50
73
  },
51
74
  );
75
+
76
+ return { cwd, config };
52
77
  };
53
78
 
54
- const applyGlobalOptions = (options: CliGlobalOptions) => {
55
- logger.level = options.logLevel;
79
+ const applyGlobalOptions = (
80
+ options: CliGlobalOptions,
81
+ config: BunWorkspacesConfig | null,
82
+ ) => {
83
+ logger.printLevel = options.logLevel;
56
84
  logger.debug("Log level: " + options.logLevel);
57
85
 
58
86
  const project = createProject({
59
87
  rootDir: options.cwd,
88
+ workspaceAliases: config?.project?.workspaceAliases ?? {},
60
89
  });
61
90
 
62
91
  logger.debug(
@@ -74,11 +103,20 @@ export const initializeWithGlobalOptions = (
74
103
  args: string[],
75
104
  defaultCwd: string,
76
105
  ) => {
77
- defineGlobalOptions(program, defaultCwd);
78
-
79
106
  program.allowUnknownOption(true);
107
+
108
+ const { cwd, config } = defineGlobalOptions(program, args, defaultCwd);
109
+
80
110
  program.parseOptions(args);
81
111
  program.allowUnknownOption(false);
82
112
 
83
- return applyGlobalOptions(program.opts() as CliGlobalOptions);
113
+ const options = program.opts() as CliGlobalOptions;
114
+
115
+ return applyGlobalOptions(
116
+ {
117
+ ...options,
118
+ cwd,
119
+ },
120
+ config,
121
+ );
84
122
  };