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 +1 -1
- package/package.json +7 -3
- package/src/config/public.d.ts +10 -0
- package/src/config/public.mjs +6 -0
- package/src/config/rootConfig/defineRootConfig.d.ts +13 -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/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.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
|
-
"
|
|
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",
|
|
@@ -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:
|
|
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;
|