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 +8 -1
- package/bin/cli.js +1 -1
- package/package.json +7 -3
- package/src/cli/commands/commandsConfig.d.ts +2 -2
- package/src/cli/commands/runScript/handleRunScript.mjs +8 -5
- package/src/cli/commands/runScript/output/outputStyle.d.ts +1 -0
- package/src/cli/commands/runScript/output/outputStyle.mjs +1 -1
- package/src/config/public.d.ts +10 -0
- package/src/config/public.mjs +6 -0
- package/src/config/rootConfig/defineRootConfig.d.ts +11 -0
- package/src/config/rootConfig/defineRootConfig.mjs +6 -0
- package/src/config/util/configLocation.d.ts +7 -1
- package/src/config/util/configLocation.mjs +9 -1
- package/src/config/util/loadConfig.d.ts +3 -1
- package/src/config/util/loadConfig.mjs +41 -4
- package/src/config/util/validateConfig.mjs +1 -1
- package/src/config/workspaceConfig/defineWorkspaceConfig.d.ts +11 -0
- package/src/config/workspaceConfig/defineWorkspaceConfig.mjs +15 -0
- package/src/config/workspaceConfig/workspaceConfig.mjs +14 -1
- package/src/index.d.ts +1 -0
- package/src/index.mjs +2 -1
- package/src/internal/core/language/types/types.d.ts +5 -0
- package/src/project/implementations/memoryProject.d.ts +1 -1
- package/src/workspaces/findWorkspaces.mjs +3 -2
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
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-workspaces",
|
|
3
|
-
"version": "1.
|
|
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
|
-
"
|
|
7
|
-
|
|
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:
|
|
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(
|
|
@@ -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:
|
|
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 = [
|
|
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
|
|
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
|
|
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
|
|
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")}\
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
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";
|
|
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
|
|
@@ -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("
|
|
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) =>
|
|
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}`);
|