bun-workspaces 1.0.0-alpha.3 → 1.0.0-alpha.30
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/LICENSE.md +1 -1
- package/README.md +131 -77
- package/bin/cli.js +1 -2
- package/package.json +24 -30
- package/src/cli/commands/commandHandlerUtils.d.ts +41 -0
- package/src/cli/commands/commandHandlerUtils.mjs +59 -0
- package/src/cli/commands/commands.d.ts +10 -0
- package/src/cli/commands/commands.mjs +23 -0
- package/src/cli/commands/commandsConfig.d.ts +312 -0
- package/src/cli/commands/commandsConfig.mjs +155 -0
- package/src/cli/commands/handleRunScript.d.ts +3 -0
- package/src/cli/commands/handleRunScript.mjs +217 -0
- package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
- package/src/cli/commands/handleSimpleCommands.mjs +170 -0
- package/src/cli/commands/index.d.ts +2 -0
- package/src/cli/commands/index.mjs +2 -0
- package/src/cli/createCli.d.ts +19 -0
- package/src/cli/createCli.mjs +113 -0
- package/src/cli/fatalErrorLogger.d.ts +1 -0
- package/src/cli/fatalErrorLogger.mjs +7 -0
- package/src/cli/globalOptions/globalOptions.d.ts +38 -0
- package/src/cli/globalOptions/globalOptions.mjs +120 -0
- package/src/cli/globalOptions/globalOptionsConfig.d.ts +43 -0
- package/src/cli/globalOptions/globalOptionsConfig.mjs +34 -0
- package/src/cli/globalOptions/index.d.ts +2 -0
- package/src/cli/globalOptions/index.mjs +2 -0
- package/src/cli/index.d.ts +3 -0
- package/src/cli/index.mjs +3 -0
- package/src/config/bunWorkspacesConfig.d.ts +17 -0
- package/src/config/bunWorkspacesConfig.mjs +50 -0
- package/src/config/configFile.d.ts +8 -0
- package/src/config/configFile.mjs +43 -0
- package/src/config/errors.d.ts +3 -0
- package/src/config/errors.mjs +10 -0
- package/src/config/{index.ts → index.d.ts} +1 -0
- package/src/config/index.mjs +11 -0
- package/src/config/userEnvVars.d.ts +9 -0
- package/src/config/userEnvVars.mjs +9 -0
- package/src/config/workspaceConfig/errors.d.ts +3 -0
- package/src/config/workspaceConfig/errors.mjs +9 -0
- package/src/config/workspaceConfig/index.d.ts +4 -0
- package/src/config/workspaceConfig/index.mjs +4 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +5 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +82 -0
- package/src/config/workspaceConfig/workspaceConfig.d.ts +25 -0
- package/src/config/workspaceConfig/workspaceConfig.mjs +80 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
- package/src/doctor/doctor.d.ts +35 -0
- package/src/doctor/doctor.mjs +52 -0
- package/src/doctor/index.d.ts +1 -0
- package/src/doctor/index.mjs +1 -0
- package/src/index.d.ts +31 -0
- package/src/index.mjs +9 -0
- package/src/internal/bun/bunLock.d.ts +20 -0
- package/src/internal/bun/bunLock.mjs +72 -0
- package/src/internal/bun/bunVersion.d.ts +21 -0
- package/src/internal/bun/bunVersion.mjs +43 -0
- package/src/internal/bun/index.d.ts +2 -0
- package/src/internal/bun/index.mjs +2 -0
- package/src/internal/core/asyncIterable/asyncIterableQueue.d.ts +15 -0
- package/src/internal/core/asyncIterable/asyncIterableQueue.mjs +73 -0
- package/src/internal/core/asyncIterable/mergeAsyncIterables.d.ts +5 -0
- package/src/internal/core/asyncIterable/mergeAsyncIterables.mjs +27 -0
- package/src/internal/core/error.d.ts +9 -0
- package/src/internal/{error.ts → core/error.mjs} +7 -16
- package/src/internal/core/index.d.ts +7 -0
- package/src/internal/core/index.mjs +6 -0
- package/src/internal/core/json/index.d.ts +2 -0
- package/src/internal/core/json/index.mjs +2 -0
- package/src/internal/core/json/json.d.ts +9 -0
- package/src/internal/core/json/json.mjs +6 -0
- package/src/internal/core/json/jsonc.d.ts +9 -0
- package/src/internal/core/json/jsonc.mjs +117 -0
- package/src/internal/core/optionalArray.d.ts +15 -0
- package/src/internal/core/optionalArray.mjs +8 -0
- package/src/internal/core/regex.d.ts +3 -0
- package/src/internal/core/regex.mjs +10 -0
- package/src/internal/core/types.d.ts +6 -0
- package/src/internal/core/types.mjs +3 -0
- package/src/internal/logger/index.d.ts +1 -0
- package/src/internal/logger/index.mjs +1 -0
- package/src/internal/logger/logger.d.ts +44 -0
- package/src/internal/logger/logger.mjs +110 -0
- package/src/internal/runtime/env.d.ts +5 -0
- package/src/internal/runtime/env.mjs +29 -0
- package/src/internal/runtime/index.d.ts +2 -0
- package/src/internal/runtime/index.mjs +2 -0
- package/src/internal/runtime/onExit.d.ts +6 -0
- package/src/internal/runtime/onExit.mjs +24 -0
- package/src/internal/runtime/os.d.ts +4 -0
- package/src/internal/runtime/os.mjs +7 -0
- package/src/internal/runtime/tempFile.d.ts +16 -0
- package/src/internal/runtime/tempFile.mjs +50 -0
- package/src/project/errors.d.ts +3 -0
- package/src/project/errors.mjs +9 -0
- package/src/project/implementations/fileSystemProject.d.ts +106 -0
- package/src/project/implementations/fileSystemProject.mjs +227 -0
- package/src/project/implementations/memoryProject.d.ts +32 -0
- package/src/project/implementations/memoryProject.mjs +46 -0
- package/src/project/implementations/projectBase.d.ts +28 -0
- package/src/project/implementations/projectBase.mjs +117 -0
- package/src/project/index.d.ts +5 -0
- package/src/project/index.mjs +4 -0
- package/src/project/project.d.ts +64 -0
- package/src/project/project.mjs +6 -0
- package/src/runScript/index.d.ts +7 -0
- package/src/runScript/index.mjs +7 -0
- package/src/runScript/outputChunk.d.ts +22 -0
- package/src/runScript/outputChunk.mjs +30 -0
- package/src/runScript/parallel.d.ts +12 -0
- package/src/runScript/parallel.mjs +52 -0
- package/src/runScript/runScript.d.ts +37 -0
- package/src/runScript/runScript.mjs +60 -0
- package/src/runScript/runScripts.d.ts +48 -0
- package/src/runScript/runScripts.mjs +124 -0
- package/src/runScript/scriptCommand.d.ts +33 -0
- package/src/runScript/scriptCommand.mjs +19 -0
- package/src/runScript/scriptExecution.d.ts +9 -0
- package/src/runScript/scriptExecution.mjs +51 -0
- package/src/runScript/scriptRuntimeMetadata.d.ts +75 -0
- package/src/runScript/scriptRuntimeMetadata.mjs +62 -0
- package/src/runScript/scriptShellOption.d.ts +7 -0
- package/src/runScript/scriptShellOption.mjs +36 -0
- package/src/workspaces/errors.d.ts +12 -0
- package/src/workspaces/{errors.ts → errors.mjs} +5 -2
- package/src/workspaces/findWorkspaces.d.ts +22 -0
- package/src/workspaces/findWorkspaces.mjs +168 -0
- package/src/workspaces/index.d.ts +4 -0
- package/src/workspaces/index.mjs +3 -0
- package/src/workspaces/packageJson.d.ts +15 -0
- package/src/workspaces/packageJson.mjs +135 -0
- package/src/workspaces/{workspace.ts → workspace.d.ts} +5 -6
- package/src/workspaces/workspace.mjs +2 -0
- package/bun.lock +0 -576
- package/src/cli/cli.ts +0 -87
- package/src/cli/globalOptions.ts +0 -122
- package/src/cli/index.ts +0 -1
- package/src/cli/projectCommands.ts +0 -390
- package/src/config/bunWorkspacesConfig.ts +0 -62
- package/src/config/configFile.ts +0 -33
- package/src/index.ts +0 -3
- package/src/internal/bunVersion.ts +0 -26
- package/src/internal/env.ts +0 -25
- package/src/internal/logger.ts +0 -180
- package/src/internal/regex.ts +0 -5
- package/src/project/errors.ts +0 -6
- package/src/project/index.ts +0 -6
- package/src/project/project.ts +0 -155
- package/src/project/scriptCommand.ts +0 -40
- package/src/workspaces/findWorkspaces.ts +0 -137
- package/src/workspaces/index.ts +0 -7
- package/src/workspaces/packageJson.ts +0 -166
- package/tsconfig.json +0 -28
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { validateBunWorkspacesConfig } from "./bunWorkspacesConfig.mjs";
|
|
4
|
+
import { ERRORS } from "./errors.mjs"; // CONCATENATED MODULE: external "fs"
|
|
5
|
+
// CONCATENATED MODULE: external "path"
|
|
6
|
+
// CONCATENATED MODULE: external "./bunWorkspacesConfig.mjs"
|
|
7
|
+
// CONCATENATED MODULE: external "./errors.mjs"
|
|
8
|
+
// CONCATENATED MODULE: ./src/config/configFile.ts
|
|
9
|
+
|
|
10
|
+
/** @deprecated The default path for the config file */ const DEFAULT_CONFIG_FILE_PATH =
|
|
11
|
+
"bw.json";
|
|
12
|
+
/** @deprecated */ const loadConfigFile = (filePath, rootDirectory = ".") => {
|
|
13
|
+
if (!filePath) {
|
|
14
|
+
const defaultFilePath = path.resolve(
|
|
15
|
+
rootDirectory,
|
|
16
|
+
DEFAULT_CONFIG_FILE_PATH,
|
|
17
|
+
);
|
|
18
|
+
if (fs.existsSync(defaultFilePath)) {
|
|
19
|
+
filePath = defaultFilePath;
|
|
20
|
+
} else {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
filePath = path.resolve(rootDirectory, filePath);
|
|
25
|
+
if (!fs.existsSync(filePath)) {
|
|
26
|
+
throw new ERRORS.ConfigFileNotFound(
|
|
27
|
+
`Config file not found at path "${filePath}"`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const configFile = fs.readFileSync(filePath, "utf8");
|
|
31
|
+
let json = null;
|
|
32
|
+
try {
|
|
33
|
+
json = JSON.parse(configFile);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new ERRORS.InvalidConfigFileFormat(
|
|
36
|
+
`Failed to parse config file at path "${filePath}": ${error.message}`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (json) validateBunWorkspacesConfig(json);
|
|
40
|
+
return json;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { DEFAULT_CONFIG_FILE_PATH, loadConfigFile };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineErrors } from "../internal/core/index.mjs"; // CONCATENATED MODULE: external "../internal/core/index.mjs"
|
|
2
|
+
// CONCATENATED MODULE: ./src/config/errors.ts
|
|
3
|
+
|
|
4
|
+
const ERRORS = defineErrors(
|
|
5
|
+
"ConfigFileNotFound",
|
|
6
|
+
"InvalidConfigFile",
|
|
7
|
+
"InvalidConfigFileFormat",
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export { ERRORS };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { validateBunWorkspacesConfig } from "./bunWorkspacesConfig.mjs";
|
|
2
|
+
import { DEFAULT_CONFIG_FILE_PATH, loadConfigFile } from "./configFile.mjs";
|
|
3
|
+
export * from "./workspaceConfig/index.mjs"; // CONCATENATED MODULE: external "./bunWorkspacesConfig.mjs"
|
|
4
|
+
// CONCATENATED MODULE: external "./configFile.mjs"
|
|
5
|
+
// CONCATENATED MODULE: ./src/config/index.ts
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
DEFAULT_CONFIG_FILE_PATH,
|
|
9
|
+
loadConfigFile,
|
|
10
|
+
validateBunWorkspacesConfig,
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const USER_ENV_VARS: {
|
|
2
|
+
readonly parallelMaxDefault: "BW_PARALLEL_MAX_DEFAULT";
|
|
3
|
+
readonly scriptShellDefault: "BW_SHELL_DEFAULT";
|
|
4
|
+
};
|
|
5
|
+
export type UserEnvVarName = keyof typeof USER_ENV_VARS;
|
|
6
|
+
export declare const getUserEnvVar: (key: UserEnvVarName) => string | undefined;
|
|
7
|
+
export declare const getUserEnvVarName: (
|
|
8
|
+
key: UserEnvVarName,
|
|
9
|
+
) => "BW_PARALLEL_MAX_DEFAULT" | "BW_SHELL_DEFAULT";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// CONCATENATED MODULE: ./src/config/userEnvVars.ts
|
|
2
|
+
const USER_ENV_VARS = {
|
|
3
|
+
parallelMaxDefault: "BW_PARALLEL_MAX_DEFAULT",
|
|
4
|
+
scriptShellDefault: "BW_SHELL_DEFAULT",
|
|
5
|
+
};
|
|
6
|
+
const getUserEnvVar = (key) => process.env[USER_ENV_VARS[key]];
|
|
7
|
+
const getUserEnvVarName = (key) => USER_ENV_VARS[key];
|
|
8
|
+
|
|
9
|
+
export { USER_ENV_VARS, getUserEnvVar, getUserEnvVarName };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineErrors } from "../../internal/core/index.mjs"; // CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
2
|
+
// CONCATENATED MODULE: ./src/config/workspaceConfig/errors.ts
|
|
3
|
+
|
|
4
|
+
const WORKSPACE_CONFIG_ERRORS = defineErrors(
|
|
5
|
+
"InvalidWorkspaceConfig",
|
|
6
|
+
"InvalidWorkspaceConfigFileFormat",
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export { WORKSPACE_CONFIG_ERRORS };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const getPackageJsonConfig: (workspacePath: string) => any;
|
|
2
|
+
export declare const getFileConfig: (workspacePath: string) => any;
|
|
3
|
+
export declare const loadWorkspaceConfig: (
|
|
4
|
+
workspacePath: string,
|
|
5
|
+
) => import("./workspaceConfig").ResolvedWorkspaceConfig | null;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { logger } from "../../internal/logger/index.mjs";
|
|
4
|
+
import { WORKSPACE_ERRORS } from "../../workspaces/index.mjs";
|
|
5
|
+
import { WORKSPACE_CONFIG_ERRORS } from "./errors.mjs";
|
|
6
|
+
import {
|
|
7
|
+
resolveWorkspaceConfig,
|
|
8
|
+
validateWorkspaceConfig,
|
|
9
|
+
} from "./workspaceConfig.mjs";
|
|
10
|
+
import {
|
|
11
|
+
WORKSPACE_CONFIG_FILE_PATH,
|
|
12
|
+
WORKSPACE_CONFIG_PACKAGE_JSON_KEY,
|
|
13
|
+
} from "./workspaceConfigLocation.mjs"; // CONCATENATED MODULE: external "fs"
|
|
14
|
+
// CONCATENATED MODULE: external "path"
|
|
15
|
+
// CONCATENATED MODULE: external "../../internal/logger/index.mjs"
|
|
16
|
+
// CONCATENATED MODULE: external "../../workspaces/index.mjs"
|
|
17
|
+
// CONCATENATED MODULE: external "./errors.mjs"
|
|
18
|
+
// CONCATENATED MODULE: external "./workspaceConfig.mjs"
|
|
19
|
+
// CONCATENATED MODULE: external "./workspaceConfigLocation.mjs"
|
|
20
|
+
// CONCATENATED MODULE: ./src/config/workspaceConfig/loadWorkspaceConfig.ts
|
|
21
|
+
|
|
22
|
+
const getPackageJsonConfig = (workspacePath) => {
|
|
23
|
+
const packageJsonPath = path.resolve(workspacePath, "package.json");
|
|
24
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
29
|
+
return packageJson[WORKSPACE_CONFIG_PACKAGE_JSON_KEY] ?? null;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new WORKSPACE_ERRORS.InvalidPackageJson(
|
|
32
|
+
`Failed to parse workspace package.json at path "${packageJsonPath}": ${error.message}`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const getFileConfig = (workspacePath) => {
|
|
37
|
+
const configFilePath = path.resolve(
|
|
38
|
+
workspacePath,
|
|
39
|
+
WORKSPACE_CONFIG_FILE_PATH,
|
|
40
|
+
);
|
|
41
|
+
if (!fs.existsSync(configFilePath)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(fs.readFileSync(configFilePath, "utf8"));
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw new WORKSPACE_CONFIG_ERRORS.InvalidWorkspaceConfigFileFormat(
|
|
48
|
+
`Failed to parse workspace config file at path "${configFilePath}": ${error.message}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const loadWorkspaceConfig = (workspacePath) => {
|
|
53
|
+
let packageJsonConfig = null;
|
|
54
|
+
let fileConfig = null;
|
|
55
|
+
try {
|
|
56
|
+
packageJsonConfig = getPackageJsonConfig(workspacePath);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
logger.error(error);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
fileConfig = getFileConfig(workspacePath);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
logger.error(error);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (fileConfig && packageJsonConfig) {
|
|
68
|
+
logger.warn(
|
|
69
|
+
`Found config for workspace at path "${workspacePath}" in both package.json and ${WORKSPACE_CONFIG_FILE_PATH}. The config in ${WORKSPACE_CONFIG_FILE_PATH} will be used.`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const rawConfig = fileConfig ?? packageJsonConfig;
|
|
73
|
+
if (!rawConfig) return null;
|
|
74
|
+
const errors = validateWorkspaceConfig(rawConfig);
|
|
75
|
+
if (errors.length) {
|
|
76
|
+
errors.forEach((error) => logger.error(error.message));
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return resolveWorkspaceConfig(rawConfig);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export { getFileConfig, getPackageJsonConfig, loadWorkspaceConfig };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type OptionalArray,
|
|
3
|
+
type BunWorkspacesError,
|
|
4
|
+
} from "../../internal/core";
|
|
5
|
+
export interface ScriptConfig {
|
|
6
|
+
order?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface WorkspaceConfig {
|
|
9
|
+
alias?: OptionalArray<string>;
|
|
10
|
+
/** The configuration for specific scripts in the workspace */
|
|
11
|
+
scripts?: Record<string, ScriptConfig>;
|
|
12
|
+
}
|
|
13
|
+
export interface ResolvedWorkspaceConfig {
|
|
14
|
+
aliases: string[];
|
|
15
|
+
scripts: Record<string, ScriptConfig>;
|
|
16
|
+
}
|
|
17
|
+
export declare const validateWorkspaceConfig: (
|
|
18
|
+
config: WorkspaceConfig,
|
|
19
|
+
) => BunWorkspacesError[];
|
|
20
|
+
export declare const resolveWorkspaceConfig: (
|
|
21
|
+
config: WorkspaceConfig,
|
|
22
|
+
) => ResolvedWorkspaceConfig;
|
|
23
|
+
export declare const createWorkspaceConfig: (
|
|
24
|
+
config?: WorkspaceConfig,
|
|
25
|
+
) => ResolvedWorkspaceConfig;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isJsonObject,
|
|
3
|
+
resolveOptionalArray,
|
|
4
|
+
} from "../../internal/core/index.mjs";
|
|
5
|
+
import { WORKSPACE_CONFIG_ERRORS } from "./errors.mjs"; // CONCATENATED MODULE: external "../../internal/core/index.mjs"
|
|
6
|
+
// CONCATENATED MODULE: external "./errors.mjs"
|
|
7
|
+
// CONCATENATED MODULE: ./src/config/workspaceConfig/workspaceConfig.ts
|
|
8
|
+
|
|
9
|
+
const validateScriptConfig = (value, keyName) => {
|
|
10
|
+
if (!isJsonObject(value)) {
|
|
11
|
+
return new WORKSPACE_CONFIG_ERRORS.InvalidWorkspaceConfig(
|
|
12
|
+
`"${keyName}" in workspace config must be an object`,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if ("order" in value && typeof value.order !== "number") {
|
|
16
|
+
return new WORKSPACE_CONFIG_ERRORS.InvalidWorkspaceConfig(
|
|
17
|
+
`The "order" value in workspace config ${keyName} must be a number`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
const VALIDATIONS = {
|
|
23
|
+
alias: (value) => {
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
for (const item of value) {
|
|
26
|
+
if (typeof item !== "string") {
|
|
27
|
+
return new WORKSPACE_CONFIG_ERRORS.InvalidWorkspaceConfig(
|
|
28
|
+
`Workspace config alias must be a a string or array of strings`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
} else if (typeof value !== "string") {
|
|
34
|
+
return new WORKSPACE_CONFIG_ERRORS.InvalidWorkspaceConfig(
|
|
35
|
+
`Workspace config alias must be a string or array of strings`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
},
|
|
40
|
+
scripts: (value) => {
|
|
41
|
+
if (!isJsonObject(value)) {
|
|
42
|
+
return new WORKSPACE_CONFIG_ERRORS.InvalidWorkspaceConfig(
|
|
43
|
+
`Workspace config "scripts" must be an object`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
for (const [key, val] of Object.entries(value)) {
|
|
47
|
+
const error = validateScriptConfig(val, `"${key}" in "scripts"`);
|
|
48
|
+
if (error) return error;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const validateWorkspaceConfig = (config) => {
|
|
54
|
+
if (!isJsonObject(config)) {
|
|
55
|
+
return [
|
|
56
|
+
new WORKSPACE_CONFIG_ERRORS.InvalidWorkspaceConfig(
|
|
57
|
+
`Workspace config must be an object`,
|
|
58
|
+
),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
const errors = [];
|
|
62
|
+
for (const [key, value] of Object.entries(config)) {
|
|
63
|
+
const error = VALIDATIONS[key](value);
|
|
64
|
+
if (error) errors.push(error);
|
|
65
|
+
}
|
|
66
|
+
return errors;
|
|
67
|
+
};
|
|
68
|
+
const resolveWorkspaceConfig = (config) => {
|
|
69
|
+
return {
|
|
70
|
+
aliases: resolveOptionalArray(config.alias ?? []),
|
|
71
|
+
scripts: config.scripts ?? {},
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const createWorkspaceConfig = (config) => resolveWorkspaceConfig(config ?? {});
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
createWorkspaceConfig,
|
|
78
|
+
resolveWorkspaceConfig,
|
|
79
|
+
validateWorkspaceConfig,
|
|
80
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Simplify } from "../internal/core";
|
|
2
|
+
declare const getBinaryInfo: () => {
|
|
3
|
+
binary: {
|
|
4
|
+
exec: string;
|
|
5
|
+
path: string | null;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
declare const getShellInfo: () => {
|
|
9
|
+
shell: {
|
|
10
|
+
binary: string | null;
|
|
11
|
+
terminal: string | null;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
declare const getSystemInfo: () => {
|
|
15
|
+
os: {
|
|
16
|
+
type: string;
|
|
17
|
+
platform: NodeJS.Platform;
|
|
18
|
+
arch: NodeJS.Architecture;
|
|
19
|
+
release: string;
|
|
20
|
+
version: string;
|
|
21
|
+
cpuCount: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
declare const getVersionInfo: () => {
|
|
25
|
+
version: string;
|
|
26
|
+
bunVersion: string;
|
|
27
|
+
};
|
|
28
|
+
export type DoctorInfo = Simplify<
|
|
29
|
+
ReturnType<typeof getVersionInfo> &
|
|
30
|
+
ReturnType<typeof getBinaryInfo> &
|
|
31
|
+
ReturnType<typeof getSystemInfo> &
|
|
32
|
+
ReturnType<typeof getShellInfo>
|
|
33
|
+
>;
|
|
34
|
+
export declare const getDoctorInfo: () => DoctorInfo;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import os from "os";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import package_0 from "../../package.json"; // CONCATENATED MODULE: external "fs"
|
|
5
|
+
// CONCATENATED MODULE: external "os"
|
|
6
|
+
// CONCATENATED MODULE: external "path"
|
|
7
|
+
// CONCATENATED MODULE: external "../../package.json"
|
|
8
|
+
// CONCATENATED MODULE: ./src/doctor/doctor.ts
|
|
9
|
+
|
|
10
|
+
const getBinaryInfo = () => {
|
|
11
|
+
const argv = process.argv.slice(0);
|
|
12
|
+
let binaryPath = argv[1] ?? null;
|
|
13
|
+
try {
|
|
14
|
+
binaryPath = path.relative(process.cwd(), fs.realpathSync(binaryPath));
|
|
15
|
+
} catch {
|
|
16
|
+
binaryPath = null;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
binary: {
|
|
20
|
+
exec: process.execPath,
|
|
21
|
+
path: binaryPath,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const getShellInfo = () => ({
|
|
26
|
+
shell: {
|
|
27
|
+
binary: process.env.SHELL ?? null,
|
|
28
|
+
terminal: process.env.TERM ?? null,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const getSystemInfo = () => ({
|
|
32
|
+
os: {
|
|
33
|
+
type: os.type(),
|
|
34
|
+
platform: process.platform,
|
|
35
|
+
arch: process.arch,
|
|
36
|
+
release: os.release(),
|
|
37
|
+
version: os.version(),
|
|
38
|
+
cpuCount: os.cpus().length,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const getVersionInfo = () => ({
|
|
42
|
+
version: package_0.version,
|
|
43
|
+
bunVersion: Bun.version_with_sha,
|
|
44
|
+
});
|
|
45
|
+
const getDoctorInfo = () => ({
|
|
46
|
+
...getVersionInfo(),
|
|
47
|
+
...getBinaryInfo(),
|
|
48
|
+
...getSystemInfo(),
|
|
49
|
+
...getShellInfo(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export { getDoctorInfo };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./doctor";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./doctor.mjs"; // CONCATENATED MODULE: ./src/doctor/index.ts
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createFileSystemProject,
|
|
3
|
+
createMemoryProject,
|
|
4
|
+
type Project,
|
|
5
|
+
type FileSystemProject,
|
|
6
|
+
type MemoryProject,
|
|
7
|
+
type CreateFileSystemProjectOptions,
|
|
8
|
+
type CreateMemoryProjectOptions,
|
|
9
|
+
type CreateProjectScriptCommandOptions,
|
|
10
|
+
type CreateProjectScriptCommandResult,
|
|
11
|
+
type WorkspaceScriptMetadata,
|
|
12
|
+
type RunWorkspaceScriptMetadata,
|
|
13
|
+
type RunWorkspaceScriptOptions,
|
|
14
|
+
type RunWorkspaceScriptResult,
|
|
15
|
+
type InlineScriptOptions,
|
|
16
|
+
type RunScriptAcrossWorkspacesOptions,
|
|
17
|
+
type RunScriptAcrossWorkspacesResult,
|
|
18
|
+
type ParallelOption,
|
|
19
|
+
type ShellOption,
|
|
20
|
+
} from "./project";
|
|
21
|
+
export {
|
|
22
|
+
type OutputChunk,
|
|
23
|
+
type OutputStreamName,
|
|
24
|
+
type PercentageValue,
|
|
25
|
+
type ParallelMaxValue,
|
|
26
|
+
type WorkspaceScriptCommandMethod,
|
|
27
|
+
type RunScriptsParallelOptions,
|
|
28
|
+
} from "./runScript";
|
|
29
|
+
export { type Workspace } from "./workspaces";
|
|
30
|
+
export { type SimpleAsyncIterable } from "./internal/core";
|
|
31
|
+
export { setLogLevel, type LogLevelSetting } from "./internal/logger";
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFileSystemProject,
|
|
3
|
+
createMemoryProject,
|
|
4
|
+
} from "./project/index.mjs";
|
|
5
|
+
import { setLogLevel } from "./internal/logger/index.mjs"; // CONCATENATED MODULE: external "./project/index.mjs"
|
|
6
|
+
// CONCATENATED MODULE: external "./internal/logger/index.mjs"
|
|
7
|
+
// CONCATENATED MODULE: ./src/index.ts
|
|
8
|
+
|
|
9
|
+
export { createFileSystemProject, createMemoryProject, setLogLevel };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type BunWorkspacesError } from "../core";
|
|
2
|
+
export declare const BUN_LOCK_ERRORS: import("../core").DefinedErrors<
|
|
3
|
+
"BunLockNotFound" | "MalformedBunLock" | "UnsupportedBunLockVersion"
|
|
4
|
+
>;
|
|
5
|
+
export type RelevantBunLockWorkspace = {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
export type RelevantBunLock = {
|
|
9
|
+
lockfileVersion: number;
|
|
10
|
+
workspaces: Record<string, RelevantBunLockWorkspace>;
|
|
11
|
+
};
|
|
12
|
+
export declare const SUPPORTED_BUN_LOCK_VERSIONS: readonly [1];
|
|
13
|
+
export declare const parseBunLock: (
|
|
14
|
+
jsonString: string,
|
|
15
|
+
/** Only for error message */
|
|
16
|
+
bunLockPath?: string,
|
|
17
|
+
) => RelevantBunLock | BunWorkspacesError;
|
|
18
|
+
export declare const readBunLockfile: (
|
|
19
|
+
directory: string,
|
|
20
|
+
) => RelevantBunLock | BunWorkspacesError;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { defineErrors, isJsonObject } from "../core/index.mjs";
|
|
4
|
+
import { parseJsonc } from "../core/json/index.mjs"; // CONCATENATED MODULE: external "fs"
|
|
5
|
+
// CONCATENATED MODULE: external "path"
|
|
6
|
+
// CONCATENATED MODULE: external "../core/index.mjs"
|
|
7
|
+
// CONCATENATED MODULE: external "../core/json/index.mjs"
|
|
8
|
+
// CONCATENATED MODULE: ./src/internal/bun/bunLock.ts
|
|
9
|
+
|
|
10
|
+
const BUN_LOCK_ERRORS = defineErrors(
|
|
11
|
+
"BunLockNotFound",
|
|
12
|
+
"MalformedBunLock",
|
|
13
|
+
"UnsupportedBunLockVersion",
|
|
14
|
+
);
|
|
15
|
+
const SUPPORTED_BUN_LOCK_VERSIONS = [1];
|
|
16
|
+
const parseBunLock = (
|
|
17
|
+
jsonString,
|
|
18
|
+
/** Only for error message */ bunLockPath,
|
|
19
|
+
) => {
|
|
20
|
+
let bunLockJson = null;
|
|
21
|
+
try {
|
|
22
|
+
bunLockJson = parseJsonc(jsonString);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return new BUN_LOCK_ERRORS.MalformedBunLock(
|
|
25
|
+
`Failed to parse bun lockfile ${bunLockPath ? `at "${bunLockPath}"` : ""}: ${error.message}`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (!isJsonObject(bunLockJson)) {
|
|
29
|
+
return new BUN_LOCK_ERRORS.MalformedBunLock(
|
|
30
|
+
`Bun lockfile ${bunLockPath ? `at "${bunLockPath}"` : ""} is not a valid JSON object`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (bunLockJson.lockfileVersion !== SUPPORTED_BUN_LOCK_VERSIONS[0]) {
|
|
34
|
+
return new BUN_LOCK_ERRORS.UnsupportedBunLockVersion(
|
|
35
|
+
`Unsupported bun lockfile version ${bunLockPath ? `at "${bunLockPath}"` : ""}: ${bunLockJson.lockfileVersion ?? "(could not find property lockfileVersion)"} (Supported: ${SUPPORTED_BUN_LOCK_VERSIONS.join(", ")})`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (typeof bunLockJson.lockfileVersion !== "number") {
|
|
39
|
+
return new BUN_LOCK_ERRORS.MalformedBunLock(
|
|
40
|
+
`Bun lockfile ${bunLockPath ? `at "${bunLockPath}"` : ""} has an invalid lockfileVersion field of type ${typeof bunLockJson.lockfileVersion}: ${bunLockJson.lockfileVersion}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (bunLockJson.workspaces && typeof bunLockJson.workspaces !== "object") {
|
|
44
|
+
return new BUN_LOCK_ERRORS.MalformedBunLock(
|
|
45
|
+
`Bun lockfile ${bunLockPath ? `at "${bunLockPath}"` : ""} has an invalid workspaces field of type ${typeof bunLockJson.workspaces}: ${bunLockJson.workspaces}`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
lockfileVersion: bunLockJson.lockfileVersion,
|
|
50
|
+
workspaces: bunLockJson.workspaces ?? {},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const readBunLockfile = (directory) => {
|
|
54
|
+
const bunLockPath = path.join(
|
|
55
|
+
directory.replace(/(\/*)?bun.lock$/, ""),
|
|
56
|
+
"bun.lock",
|
|
57
|
+
);
|
|
58
|
+
if (!fs.existsSync(bunLockPath)) {
|
|
59
|
+
return new BUN_LOCK_ERRORS.BunLockNotFound(
|
|
60
|
+
`Did not find bun lockfile at "${bunLockPath}"`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const jsonString = fs.readFileSync(bunLockPath, "utf8");
|
|
64
|
+
return parseBunLock(jsonString, bunLockPath);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
BUN_LOCK_ERRORS,
|
|
69
|
+
SUPPORTED_BUN_LOCK_VERSIONS,
|
|
70
|
+
parseBunLock,
|
|
71
|
+
readBunLockfile,
|
|
72
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const LIBRARY_CONSUMER_BUN_VERSION: string;
|
|
2
|
+
export declare const BUILD_BUN_VERSION: string;
|
|
3
|
+
export declare const BUN_VERSION_ERRORS: import("../core").DefinedErrors<
|
|
4
|
+
"InvalidBunVersion" | "NotBunRuntime"
|
|
5
|
+
>;
|
|
6
|
+
export declare const getRequiredBunVersion: (isBuild?: boolean) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Validates that the provided version satisfies the required Bun version
|
|
9
|
+
* specified in the root `package.json`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const validateBunVersion: (
|
|
12
|
+
version: string,
|
|
13
|
+
isBuild?: boolean,
|
|
14
|
+
) => import("../core").BunWorkspacesError | null;
|
|
15
|
+
/**
|
|
16
|
+
* Validates that the Bun version of the current script satisfies the
|
|
17
|
+
* required Bun version specified in the root `package.json`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const validateCurrentBunVersion: (
|
|
20
|
+
build?: boolean,
|
|
21
|
+
) => import("../core").BunWorkspacesError | null;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import package_0 from "../../../package.json";
|
|
2
|
+
import { defineErrors } from "../core/index.mjs"; // CONCATENATED MODULE: external "../../../package.json"
|
|
3
|
+
// CONCATENATED MODULE: external "../core/index.mjs"
|
|
4
|
+
// CONCATENATED MODULE: ./src/internal/bun/bunVersion.ts
|
|
5
|
+
|
|
6
|
+
const LIBRARY_CONSUMER_BUN_VERSION =
|
|
7
|
+
package_0._bwInternal.bunVersion.libraryConsumer;
|
|
8
|
+
const BUILD_BUN_VERSION = package_0._bwInternal.bunVersion.build;
|
|
9
|
+
const BUN_VERSION_ERRORS = defineErrors("InvalidBunVersion", "NotBunRuntime");
|
|
10
|
+
const getRequiredBunVersion = (isBuild) =>
|
|
11
|
+
isBuild
|
|
12
|
+
? BUILD_BUN_VERSION.replace(/\.\d+$/, ".x")
|
|
13
|
+
: LIBRARY_CONSUMER_BUN_VERSION;
|
|
14
|
+
const _Bun = typeof Bun === "undefined" ? null : Bun;
|
|
15
|
+
/**
|
|
16
|
+
* Validates that the provided version satisfies the required Bun version
|
|
17
|
+
* specified in the root `package.json`.
|
|
18
|
+
*/ const validateBunVersion = (version, isBuild) =>
|
|
19
|
+
_Bun
|
|
20
|
+
? _Bun.semver.satisfies(version, getRequiredBunVersion(isBuild))
|
|
21
|
+
? null
|
|
22
|
+
: new BUN_VERSION_ERRORS.InvalidBunVersion(
|
|
23
|
+
isBuild
|
|
24
|
+
? `Expected Bun version ${getRequiredBunVersion(isBuild)} for build`
|
|
25
|
+
: `Bun version ${version} is not supported by bun-workspaces. Supported: ${getRequiredBunVersion(isBuild)}`,
|
|
26
|
+
)
|
|
27
|
+
: new BUN_VERSION_ERRORS.NotBunRuntime(
|
|
28
|
+
`bun-workspaces is not running in a Bun runtime. Expected Bun version ${getRequiredBunVersion(isBuild)}`,
|
|
29
|
+
);
|
|
30
|
+
/**
|
|
31
|
+
* Validates that the Bun version of the current script satisfies the
|
|
32
|
+
* required Bun version specified in the root `package.json`.
|
|
33
|
+
*/ const validateCurrentBunVersion = (build) =>
|
|
34
|
+
validateBunVersion(_Bun?.version ?? "(Error: not Bun runtime)", build);
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
BUILD_BUN_VERSION,
|
|
38
|
+
BUN_VERSION_ERRORS,
|
|
39
|
+
LIBRARY_CONSUMER_BUN_VERSION,
|
|
40
|
+
getRequiredBunVersion,
|
|
41
|
+
validateBunVersion,
|
|
42
|
+
validateCurrentBunVersion,
|
|
43
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SimpleAsyncIterable } from "../types";
|
|
2
|
+
export type AsyncQueueItem<T> =
|
|
3
|
+
| {
|
|
4
|
+
type: "value";
|
|
5
|
+
value: T;
|
|
6
|
+
}
|
|
7
|
+
| {
|
|
8
|
+
type: "done";
|
|
9
|
+
};
|
|
10
|
+
export declare const createAsyncIterableQueue: <
|
|
11
|
+
T,
|
|
12
|
+
>() => SimpleAsyncIterable<T> & {
|
|
13
|
+
push: (value: T) => void;
|
|
14
|
+
close: () => void;
|
|
15
|
+
};
|