bun-workspaces 1.0.1-alpha → 1.0.2
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 +189 -70
- package/bin/cli.js +1 -2
- package/package.json +27 -30
- package/src/cli/commands/commandHandlerUtils.d.ts +50 -0
- package/src/cli/commands/commandHandlerUtils.mjs +91 -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 +351 -0
- package/src/cli/commands/commandsConfig.mjs +183 -0
- package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
- package/src/cli/commands/handleSimpleCommands.mjs +174 -0
- package/src/cli/commands/index.d.ts +3 -0
- package/src/cli/commands/index.mjs +3 -0
- package/src/cli/commands/runScript/handleRunScript.d.ts +3 -0
- package/src/cli/commands/runScript/handleRunScript.mjs +250 -0
- package/src/cli/commands/runScript/index.d.ts +2 -0
- package/src/cli/commands/runScript/index.mjs +2 -0
- package/src/cli/commands/runScript/output/index.d.ts +1 -0
- package/src/cli/commands/runScript/output/index.mjs +1 -0
- package/src/cli/commands/runScript/output/outputStyle.d.ts +8 -0
- package/src/cli/commands/runScript/output/outputStyle.mjs +17 -0
- package/src/cli/commands/runScript/output/renderGroupedOutput.d.ts +74 -0
- package/src/cli/commands/runScript/output/renderGroupedOutput.mjs +331 -0
- package/src/cli/commands/runScript/output/renderPlainOutput.d.ts +24 -0
- package/src/cli/commands/runScript/output/renderPlainOutput.mjs +44 -0
- package/src/cli/commands/runScript/output/sanitizeChunk.d.ts +4 -0
- package/src/cli/commands/runScript/output/sanitizeChunk.mjs +101 -0
- package/src/cli/createCli.d.ts +25 -0
- package/src/cli/createCli.mjs +157 -0
- package/src/cli/fatalErrorLogger.d.ts +1 -0
- package/src/cli/fatalErrorLogger.mjs +7 -0
- package/src/cli/globalOptions/globalOptions.d.ts +42 -0
- package/src/cli/globalOptions/globalOptions.mjs +113 -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/cli/middleware.d.ts +83 -0
- package/src/cli/middleware.mjs +39 -0
- package/src/config/index.d.ts +3 -0
- package/src/config/index.mjs +3 -0
- package/src/config/rootConfig/errors.d.ts +1 -0
- package/src/config/rootConfig/errors.mjs +6 -0
- package/src/config/rootConfig/index.d.ts +5 -0
- package/src/config/rootConfig/index.mjs +5 -0
- package/src/config/rootConfig/loadRootConfig.d.ts +3 -0
- package/src/config/rootConfig/loadRootConfig.mjs +22 -0
- package/src/config/rootConfig/rootConfig.d.ts +17 -0
- package/src/config/rootConfig/rootConfig.mjs +43 -0
- package/src/config/rootConfig/rootConfigLocation.d.ts +2 -0
- package/src/config/rootConfig/rootConfigLocation.mjs +5 -0
- package/src/config/rootConfig/rootConfigSchema.d.ts +21 -0
- package/src/config/rootConfig/rootConfigSchema.mjs +24 -0
- package/src/config/userEnvVars/index.d.ts +1 -0
- package/src/config/userEnvVars/index.mjs +1 -0
- package/src/config/userEnvVars/userEnvVars.d.ts +13 -0
- package/src/config/userEnvVars/userEnvVars.mjs +10 -0
- package/src/config/util/ajvTypes.d.ts +10 -0
- package/src/config/util/ajvTypes.mjs +2 -0
- package/src/config/util/configLocation.d.ts +12 -0
- package/src/config/util/configLocation.mjs +11 -0
- package/src/config/util/index.d.ts +4 -0
- package/src/config/util/index.mjs +3 -0
- package/src/config/util/loadConfig.d.ts +16 -0
- package/src/config/util/loadConfig.mjs +118 -0
- package/src/config/util/validateConfig.d.ts +8 -0
- package/src/config/util/validateConfig.mjs +17 -0
- package/src/config/workspaceConfig/errors.d.ts +1 -0
- package/src/config/workspaceConfig/errors.mjs +6 -0
- package/src/config/workspaceConfig/index.d.ts +5 -0
- package/src/config/workspaceConfig/index.mjs +5 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +3 -0
- package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +25 -0
- package/src/config/workspaceConfig/workspaceConfig.d.ts +22 -0
- package/src/config/workspaceConfig/workspaceConfig.mjs +31 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
- package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
- package/src/config/workspaceConfig/workspaceConfigSchema.d.ts +25 -0
- package/src/config/workspaceConfig/workspaceConfigSchema.mjs +28 -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 +37 -0
- package/src/index.mjs +16 -0
- package/src/internal/bun/bunLock.d.ts +20 -0
- package/src/internal/bun/bunLock.mjs +70 -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/error/error.d.ts +13 -0
- package/src/internal/{error.ts → core/error/error.mjs} +16 -18
- package/src/internal/core/error/index.d.ts +1 -0
- package/src/internal/core/error/index.mjs +1 -0
- package/src/internal/core/index.d.ts +4 -0
- package/src/internal/core/index.mjs +4 -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 +49 -0
- package/src/internal/core/json/json.mjs +12 -0
- package/src/internal/core/json/jsonc.d.ts +9 -0
- package/src/internal/core/json/jsonc.mjs +117 -0
- package/src/internal/core/language/array/index.d.ts +1 -0
- package/src/internal/core/language/array/index.mjs +1 -0
- package/src/internal/core/language/array/optionalArray.d.ts +15 -0
- package/src/internal/core/language/array/optionalArray.mjs +8 -0
- package/src/internal/core/language/asyncIterable/asyncIterableQueue.d.ts +16 -0
- package/src/internal/core/language/asyncIterable/asyncIterableQueue.mjs +81 -0
- package/src/internal/core/language/asyncIterable/index.d.ts +2 -0
- package/src/internal/core/language/asyncIterable/index.mjs +2 -0
- package/src/internal/core/language/asyncIterable/mergeAsyncIterables.d.ts +5 -0
- package/src/internal/core/language/asyncIterable/mergeAsyncIterables.mjs +27 -0
- package/src/internal/core/language/events/typedEventTarget.d.ts +50 -0
- package/src/internal/core/language/events/typedEventTarget.mjs +14 -0
- package/src/internal/core/language/index.d.ts +5 -0
- package/src/internal/core/language/index.mjs +5 -0
- package/src/internal/core/language/regex/index.d.ts +1 -0
- package/src/internal/core/language/regex/index.mjs +1 -0
- package/src/internal/core/language/regex/regex.d.ts +3 -0
- package/src/internal/core/language/regex/regex.mjs +10 -0
- package/src/internal/core/language/string/id.d.ts +1 -0
- package/src/internal/core/language/string/id.mjs +10 -0
- package/src/internal/core/language/string/index.d.ts +1 -0
- package/src/internal/core/language/string/index.mjs +1 -0
- package/src/internal/core/language/string/utf/eastAsianWidth.d.ts +16 -0
- package/src/internal/core/language/string/utf/eastAsianWidth.mjs +326 -0
- package/src/internal/core/language/string/utf/visibleLength.d.ts +5 -0
- package/src/internal/core/language/string/utf/visibleLength.mjs +29 -0
- package/src/internal/core/language/types/index.d.ts +2 -0
- package/src/internal/core/language/types/index.mjs +1 -0
- package/src/internal/core/language/types/typeof.d.ts +102 -0
- package/src/internal/core/language/types/typeof.mjs +123 -0
- package/src/internal/core/language/types/types.d.ts +14 -0
- package/src/internal/core/language/types/types.mjs +2 -0
- package/src/internal/core/runtime/env.d.ts +6 -0
- package/src/internal/core/runtime/env.mjs +36 -0
- package/src/internal/core/runtime/index.d.ts +5 -0
- package/src/internal/core/runtime/index.mjs +5 -0
- package/src/internal/core/runtime/onExit.d.ts +4 -0
- package/src/internal/core/runtime/onExit.mjs +54 -0
- package/src/internal/core/runtime/os.d.ts +4 -0
- package/src/internal/core/runtime/os.mjs +7 -0
- package/src/internal/core/runtime/tempFile.d.ts +20 -0
- package/src/internal/core/runtime/tempFile.mjs +87 -0
- package/src/internal/core/runtime/terminal.d.ts +1 -0
- package/src/internal/core/runtime/terminal.mjs +4 -0
- package/src/internal/generated/ajv/validateRootConfig.mjs +1 -0
- package/src/internal/generated/ajv/validateWorkspaceConfig.mjs +1 -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 +45 -0
- package/src/internal/logger/logger.mjs +133 -0
- package/src/internal/version.d.ts +1 -0
- package/src/internal/version.mjs +6 -0
- package/src/project/errors.d.ts +5 -0
- package/src/project/errors.mjs +10 -0
- package/src/project/implementations/fileSystemProject.d.ts +148 -0
- package/src/project/implementations/fileSystemProject.mjs +455 -0
- package/src/project/implementations/memoryProject.d.ts +41 -0
- package/src/project/implementations/memoryProject.mjs +148 -0
- package/src/project/implementations/projectBase.d.ts +35 -0
- package/src/project/implementations/projectBase.mjs +197 -0
- package/src/project/index.d.ts +5 -0
- package/src/project/index.mjs +4 -0
- package/src/project/project.d.ts +75 -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/output/index.d.ts +3 -0
- package/src/runScript/output/index.mjs +2 -0
- package/src/runScript/output/multiProcessOutput.d.ts +14 -0
- package/src/runScript/output/multiProcessOutput.mjs +21 -0
- package/src/runScript/output/outputStream.d.ts +1 -0
- package/src/runScript/output/outputStream.mjs +1 -0
- package/src/runScript/output/processOutput.d.ts +33 -0
- package/src/runScript/output/processOutput.mjs +124 -0
- package/src/runScript/parallel.d.ts +15 -0
- package/src/runScript/parallel.mjs +56 -0
- package/src/runScript/recursion.d.ts +4 -0
- package/src/runScript/recursion.mjs +17 -0
- package/src/runScript/runScript.d.ts +45 -0
- package/src/runScript/runScript.mjs +89 -0
- package/src/runScript/runScripts.d.ts +65 -0
- package/src/runScript/runScripts.mjs +263 -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 +50 -0
- package/src/runScript/scriptRuntimeMetadata.d.ts +73 -0
- package/src/runScript/scriptRuntimeMetadata.mjs +61 -0
- package/src/runScript/scriptShellOption.d.ts +8 -0
- package/src/runScript/scriptShellOption.mjs +39 -0
- package/src/runScript/subprocesses.d.ts +11 -0
- package/src/runScript/subprocesses.mjs +34 -0
- package/src/workspaces/dependencyGraph/cycles.d.ts +9 -0
- package/src/workspaces/dependencyGraph/cycles.mjs +91 -0
- package/src/workspaces/dependencyGraph/index.d.ts +2 -0
- package/src/workspaces/dependencyGraph/index.mjs +2 -0
- package/src/workspaces/dependencyGraph/resolveDependencies.d.ts +18 -0
- package/src/workspaces/dependencyGraph/resolveDependencies.mjs +52 -0
- package/src/workspaces/errors.d.ts +13 -0
- package/src/workspaces/errors.mjs +18 -0
- package/src/workspaces/findWorkspaces.d.ts +24 -0
- package/src/workspaces/findWorkspaces.mjs +217 -0
- package/src/workspaces/index.d.ts +4 -0
- package/src/workspaces/index.mjs +3 -0
- package/src/workspaces/packageJson.d.ts +31 -0
- package/src/workspaces/packageJson.mjs +188 -0
- package/src/workspaces/{workspace.ts → workspace.d.ts} +11 -6
- package/src/workspaces/workspace.mjs +2 -0
- package/src/workspaces/workspacePattern.d.ts +21 -0
- package/src/workspaces/workspacePattern.mjs +104 -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 -396
- package/src/config/bunWorkspacesConfig.ts +0 -62
- package/src/config/configFile.ts +0 -33
- package/src/config/index.ts +0 -7
- 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 -145
- 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/errors.ts +0 -14
- 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
package/src/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import rootPackageJson from "../../package.json";
|
|
2
|
-
|
|
3
|
-
export const LIBRARY_CONSUMER_BUN_VERSION =
|
|
4
|
-
rootPackageJson.custom.bunVersion.libraryConsumer;
|
|
5
|
-
|
|
6
|
-
export const BUILD_BUN_VERSION = rootPackageJson.custom.bunVersion.build;
|
|
7
|
-
|
|
8
|
-
export const getRequiredBunVersion = (build?: boolean) =>
|
|
9
|
-
build ? BUILD_BUN_VERSION : LIBRARY_CONSUMER_BUN_VERSION;
|
|
10
|
-
|
|
11
|
-
const _Bun = typeof Bun === "undefined" ? ({} as typeof Bun) : Bun;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Validates that the provided version satisfies the required Bun version
|
|
15
|
-
* specified in the root `package.json`.
|
|
16
|
-
*/
|
|
17
|
-
export const validateBunVersion = (version: string, build?: boolean) =>
|
|
18
|
-
_Bun ? _Bun.semver.satisfies(version, getRequiredBunVersion(build)) : true;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* Validates that the Bun version of the current script satisfies the
|
|
23
|
-
* required Bun version specified in the root `package.json`.
|
|
24
|
-
*/
|
|
25
|
-
export const validateCurrentBunVersion = (build?: boolean) =>
|
|
26
|
-
validateBunVersion(_Bun?.version, build);
|
package/src/internal/env.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const RUNTIME_MODE_VALUES = ["development", "production", "test"] as const;
|
|
2
|
-
|
|
3
|
-
export type RuntimeMode = "development" | "production" | "test";
|
|
4
|
-
|
|
5
|
-
const _RUNTIME_MODE: RuntimeMode = ((process.env
|
|
6
|
-
._BW_RUNTIME_MODE as RuntimeMode) ||
|
|
7
|
-
(process.env.NODE_ENV?.match(/test(ing)?/)
|
|
8
|
-
? "test"
|
|
9
|
-
: process.env.NODE_ENV === "development"
|
|
10
|
-
? "development"
|
|
11
|
-
: "production")) as RuntimeMode;
|
|
12
|
-
|
|
13
|
-
export const RUNTIME_MODE = RUNTIME_MODE_VALUES.includes(_RUNTIME_MODE)
|
|
14
|
-
? _RUNTIME_MODE
|
|
15
|
-
: "production";
|
|
16
|
-
|
|
17
|
-
if (RUNTIME_MODE !== _RUNTIME_MODE) {
|
|
18
|
-
console.error(
|
|
19
|
-
`Env var RUNTIME_MODE has an invalid value: "${_RUNTIME_MODE}". Defaulting to "${RUNTIME_MODE}". Accepted values: ${RUNTIME_MODE_VALUES.join(", ")}.`,
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const IS_TEST = RUNTIME_MODE === "test";
|
|
24
|
-
export const IS_PRODUCTION = RUNTIME_MODE === "production";
|
|
25
|
-
export const IS_DEVELOPMENT = RUNTIME_MODE === "development";
|
package/src/internal/logger.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { IS_PRODUCTION, IS_TEST } from "./env";
|
|
2
|
-
|
|
3
|
-
export const LOG_LEVELS = ["debug", "info", "warn", "error"] as const;
|
|
4
|
-
|
|
5
|
-
const getLevelNumber = (level: LogLevel) => LOG_LEVELS.indexOf(level);
|
|
6
|
-
|
|
7
|
-
export type LogLevel = (typeof LOG_LEVELS)[number];
|
|
8
|
-
|
|
9
|
-
export type LogLevelSetting = LogLevel | "silent";
|
|
10
|
-
|
|
11
|
-
export const validateLogLevel = (level: LogLevelSetting) => {
|
|
12
|
-
if (level === "silent") return;
|
|
13
|
-
if (!LOG_LEVELS.includes(level)) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
`Invalid log level: "${level}". Accepted values: ${LOG_LEVELS.join(", ")}`,
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type LogMetadata = Record<string, any>;
|
|
21
|
-
|
|
22
|
-
export interface Log<
|
|
23
|
-
Message extends string | Error = string,
|
|
24
|
-
Metadata extends LogMetadata = LogMetadata,
|
|
25
|
-
> {
|
|
26
|
-
message: Message;
|
|
27
|
-
level: LogLevel;
|
|
28
|
-
metadata: Metadata;
|
|
29
|
-
time: Date;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type Logger = {
|
|
33
|
-
name: string;
|
|
34
|
-
|
|
35
|
-
log<
|
|
36
|
-
Message extends string | Error = string,
|
|
37
|
-
Metadata extends LogMetadata = LogMetadata,
|
|
38
|
-
>(
|
|
39
|
-
message: Message,
|
|
40
|
-
level: LogLevel,
|
|
41
|
-
metadata?: Metadata,
|
|
42
|
-
): Log<Message, Metadata>;
|
|
43
|
-
|
|
44
|
-
printLevel: LogLevelSetting;
|
|
45
|
-
} & {
|
|
46
|
-
[Level in LogLevel]: <
|
|
47
|
-
Message extends string | Error = string,
|
|
48
|
-
Metadata extends LogMetadata = LogMetadata,
|
|
49
|
-
>(
|
|
50
|
-
message: Message,
|
|
51
|
-
metadata?: Metadata,
|
|
52
|
-
) => Log<Message, Metadata>;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const createLogger = (name: string): Logger => new _Logger(name);
|
|
56
|
-
|
|
57
|
-
class _Logger implements Logger {
|
|
58
|
-
constructor(public name: string) {}
|
|
59
|
-
|
|
60
|
-
log<
|
|
61
|
-
Message extends string | Error = string,
|
|
62
|
-
Metadata extends LogMetadata = LogMetadata,
|
|
63
|
-
>(
|
|
64
|
-
message: Message,
|
|
65
|
-
level: LogLevel,
|
|
66
|
-
metadata?: Metadata,
|
|
67
|
-
): Log<Message, Metadata> {
|
|
68
|
-
const log: Log<Message, Metadata> = {
|
|
69
|
-
message,
|
|
70
|
-
level,
|
|
71
|
-
metadata: metadata ?? ({} as Metadata),
|
|
72
|
-
time: new Date(),
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
if (this.shouldPrint(level)) {
|
|
76
|
-
const formattedMessage = this.formatLogMessage(message, level);
|
|
77
|
-
if (message instanceof Error) {
|
|
78
|
-
message.message = formattedMessage;
|
|
79
|
-
}
|
|
80
|
-
console[level](
|
|
81
|
-
message instanceof Error ? message : formattedMessage,
|
|
82
|
-
...(metadata ? [{ metadata }] : []),
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return log;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
debug<
|
|
90
|
-
Message extends string | Error = string,
|
|
91
|
-
Metadata extends LogMetadata = LogMetadata,
|
|
92
|
-
>(message: Message, metadata?: Metadata): Log<Message, Metadata> {
|
|
93
|
-
return this.log(message, "debug", metadata);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
info<
|
|
97
|
-
Message extends string | Error = string,
|
|
98
|
-
Metadata extends LogMetadata = LogMetadata,
|
|
99
|
-
>(message: Message, metadata?: Metadata): Log<Message, Metadata> {
|
|
100
|
-
return this.log(message, "info", metadata);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
warn<
|
|
104
|
-
Message extends string | Error = string,
|
|
105
|
-
Metadata extends LogMetadata = LogMetadata,
|
|
106
|
-
>(message: Message, metadata?: Metadata): Log<Message, Metadata> {
|
|
107
|
-
return this.log(message, "warn", metadata);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
error<
|
|
111
|
-
Message extends string | Error = string,
|
|
112
|
-
Metadata extends LogMetadata = LogMetadata,
|
|
113
|
-
>(message: Message, metadata?: Metadata): Log<Message, Metadata> {
|
|
114
|
-
return this.log(message, "error", metadata);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get printLevel() {
|
|
118
|
-
return this._printLevel;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
set printLevel(level: LogLevelSetting) {
|
|
122
|
-
this._printLevel = level;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Info prints normally for standard user-facing logs. Debug and Warn are highlighted with a prefix. Errors print as Error instances
|
|
126
|
-
private formatLogMessage(message: Error | string, level: LogLevel): string {
|
|
127
|
-
const content = message instanceof Error ? message.message : message;
|
|
128
|
-
return level === "debug" || level === "warn"
|
|
129
|
-
? `[${this.name} ${level.toUpperCase()}]: ${content}`
|
|
130
|
-
: content;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private _printLevel: LogLevelSetting = IS_PRODUCTION
|
|
134
|
-
? "info"
|
|
135
|
-
: IS_TEST
|
|
136
|
-
? "silent"
|
|
137
|
-
: "debug";
|
|
138
|
-
|
|
139
|
-
private shouldPrint(level: LogLevel): boolean {
|
|
140
|
-
if (this.printLevel === "silent") return false;
|
|
141
|
-
return getLevelNumber(level) >= getLevelNumber(this.printLevel);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export const logger = createLogger("bun-workspaces");
|
package/src/internal/regex.ts
DELETED
package/src/project/errors.ts
DELETED
package/src/project/index.ts
DELETED
package/src/project/project.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { createWildcardRegex } from "../internal/regex";
|
|
3
|
-
import { findWorkspacesFromPackage, type Workspace } from "../workspaces";
|
|
4
|
-
import { ERRORS } from "./errors";
|
|
5
|
-
import {
|
|
6
|
-
createScriptCommand,
|
|
7
|
-
type CreateScriptCommandOptions,
|
|
8
|
-
type ScriptCommand,
|
|
9
|
-
} from "./scriptCommand";
|
|
10
|
-
|
|
11
|
-
export interface ScriptMetadata {
|
|
12
|
-
name: string;
|
|
13
|
-
workspaces: Workspace[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type CreateProjectScriptCommandOptions = Omit<
|
|
17
|
-
CreateScriptCommandOptions,
|
|
18
|
-
"workspace" | "rootDir"
|
|
19
|
-
> & {
|
|
20
|
-
workspaceName: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export interface CreateProjectScriptCommandResult {
|
|
24
|
-
command: ScriptCommand;
|
|
25
|
-
scriptName: string;
|
|
26
|
-
workspace: Workspace;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface Project {
|
|
30
|
-
name: string;
|
|
31
|
-
rootDir: string;
|
|
32
|
-
workspaces: Workspace[];
|
|
33
|
-
listWorkspacesWithScript(scriptName: string): Workspace[];
|
|
34
|
-
listScriptsWithWorkspaces(): Record<string, ScriptMetadata>;
|
|
35
|
-
findWorkspaceByName(workspaceName: string): Workspace | null;
|
|
36
|
-
findWorkspaceByAlias(alias: string): Workspace | null;
|
|
37
|
-
findWorkspaceByNameOrAlias(nameOrAlias: string): Workspace | null;
|
|
38
|
-
findWorkspacesByPattern(workspaceName: string): Workspace[];
|
|
39
|
-
createScriptCommand(
|
|
40
|
-
options: CreateProjectScriptCommandOptions,
|
|
41
|
-
): CreateProjectScriptCommandResult;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface CreateProjectOptions {
|
|
45
|
-
rootDir: string;
|
|
46
|
-
workspaceAliases?: Record<string, string>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
class _Project implements Project {
|
|
50
|
-
public readonly rootDir: string;
|
|
51
|
-
public readonly workspaceAliases?: Record<string, string>;
|
|
52
|
-
public readonly workspaces: Workspace[];
|
|
53
|
-
public readonly name: string;
|
|
54
|
-
constructor(private options: CreateProjectOptions) {
|
|
55
|
-
this.rootDir = options.rootDir;
|
|
56
|
-
this.workspaceAliases = options.workspaceAliases;
|
|
57
|
-
|
|
58
|
-
const { name, workspaces } = findWorkspacesFromPackage({
|
|
59
|
-
rootDir: options.rootDir,
|
|
60
|
-
workspaceAliases: options.workspaceAliases,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
this.name = name;
|
|
64
|
-
this.workspaces = workspaces;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
listWorkspacesWithScript(scriptName: string): Workspace[] {
|
|
68
|
-
return this.workspaces.filter(
|
|
69
|
-
(workspace) => workspace.packageJson.scripts?.[scriptName],
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
listScriptsWithWorkspaces(): Record<string, ScriptMetadata> {
|
|
74
|
-
const scripts = new Set<string>();
|
|
75
|
-
this.workspaces.forEach((workspace) => {
|
|
76
|
-
Object.keys(workspace.packageJson.scripts ?? {}).forEach((script) =>
|
|
77
|
-
scripts.add(script),
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
return Array.from(scripts)
|
|
81
|
-
.sort((a, b) => a.localeCompare(b))
|
|
82
|
-
.map((name) => ({
|
|
83
|
-
name,
|
|
84
|
-
workspaces: this.listWorkspacesWithScript(name),
|
|
85
|
-
}))
|
|
86
|
-
.reduce(
|
|
87
|
-
(acc, { name, workspaces }) => ({
|
|
88
|
-
...acc,
|
|
89
|
-
[name]: { name, workspaces },
|
|
90
|
-
}),
|
|
91
|
-
{} as Record<string, ScriptMetadata>,
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
findWorkspaceByName(workspaceName: string): Workspace | null {
|
|
96
|
-
return (
|
|
97
|
-
this.workspaces.find((workspace) => workspace.name === workspaceName) ??
|
|
98
|
-
null
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
findWorkspaceByAlias(alias: string): Workspace | null {
|
|
103
|
-
return (
|
|
104
|
-
this.workspaces.find((workspace) => workspace.aliases.includes(alias)) ??
|
|
105
|
-
null
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
findWorkspaceByNameOrAlias(nameOrAlias: string): Workspace | null {
|
|
110
|
-
return (
|
|
111
|
-
this.findWorkspaceByName(nameOrAlias) ||
|
|
112
|
-
this.findWorkspaceByAlias(nameOrAlias)
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Accepts wildcard for finding a list of workspaces */
|
|
117
|
-
findWorkspacesByPattern(workspacePattern: string): Workspace[] {
|
|
118
|
-
if (!workspacePattern) return [];
|
|
119
|
-
const regex = createWildcardRegex(workspacePattern);
|
|
120
|
-
return this.workspaces.filter((workspace) => regex.test(workspace.name));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
createScriptCommand(
|
|
124
|
-
options: CreateProjectScriptCommandOptions,
|
|
125
|
-
): CreateProjectScriptCommandResult {
|
|
126
|
-
const workspace = this.findWorkspaceByNameOrAlias(options.workspaceName);
|
|
127
|
-
|
|
128
|
-
if (!workspace) {
|
|
129
|
-
throw new ERRORS.ProjectWorkspaceNotFound(
|
|
130
|
-
`Workspace not found: ${JSON.stringify(options.workspaceName)}`,
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
if (!workspace.packageJson.scripts?.[options.scriptName]) {
|
|
134
|
-
throw new ERRORS.WorkspaceScriptDoesNotExist(
|
|
135
|
-
`Script not found in workspace ${JSON.stringify(
|
|
136
|
-
workspace.name,
|
|
137
|
-
)}: ${JSON.stringify(options.scriptName)} (available: ${
|
|
138
|
-
Object.keys(workspace.packageJson.scripts).join(", ") || "none"
|
|
139
|
-
}`,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
workspace,
|
|
144
|
-
scriptName: options.scriptName,
|
|
145
|
-
command: createScriptCommand({
|
|
146
|
-
...options,
|
|
147
|
-
workspace,
|
|
148
|
-
rootDir: path.resolve(this.rootDir),
|
|
149
|
-
}),
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export const createProject = (options: CreateProjectOptions): Project =>
|
|
155
|
-
new _Project(options);
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import type { Workspace } from "../workspaces";
|
|
3
|
-
|
|
4
|
-
export const SCRIPT_COMMAND_METHODS = ["cd", "filter"] as const;
|
|
5
|
-
|
|
6
|
-
export type ScriptCommandMethod = (typeof SCRIPT_COMMAND_METHODS)[number];
|
|
7
|
-
|
|
8
|
-
export interface CreateScriptCommandOptions {
|
|
9
|
-
method: ScriptCommandMethod;
|
|
10
|
-
scriptName: string;
|
|
11
|
-
args: string;
|
|
12
|
-
workspace: Workspace;
|
|
13
|
-
rootDir: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const spaceArgs = (args: string) => (args ? ` ${args.trim()}` : "");
|
|
17
|
-
|
|
18
|
-
export interface ScriptCommand {
|
|
19
|
-
command: string;
|
|
20
|
-
cwd: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const METHODS: Record<
|
|
24
|
-
ScriptCommandMethod,
|
|
25
|
-
(options: CreateScriptCommandOptions) => ScriptCommand
|
|
26
|
-
> = {
|
|
27
|
-
cd: ({ scriptName, workspace, rootDir, args }) => ({
|
|
28
|
-
cwd: path.resolve(rootDir, workspace.path),
|
|
29
|
-
command: `bun --silent run ${scriptName}${spaceArgs(args)}`,
|
|
30
|
-
}),
|
|
31
|
-
filter: ({ scriptName, workspace, args, rootDir }) => ({
|
|
32
|
-
cwd: rootDir,
|
|
33
|
-
command: `bun --silent run --filter=${JSON.stringify(
|
|
34
|
-
workspace.name,
|
|
35
|
-
)} ${scriptName}${spaceArgs(args)}`,
|
|
36
|
-
}),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const createScriptCommand = (options: CreateScriptCommandOptions) =>
|
|
40
|
-
METHODS[options.method](options);
|
package/src/workspaces/errors.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineErrors } from "../internal/error";
|
|
2
|
-
|
|
3
|
-
export const ERRORS = defineErrors(
|
|
4
|
-
"PackageNotFound",
|
|
5
|
-
"InvalidPackageJson",
|
|
6
|
-
"DuplicateWorkspaceName",
|
|
7
|
-
"InvalidWorkspaceName",
|
|
8
|
-
"NoWorkspaceName",
|
|
9
|
-
"InvalidScripts",
|
|
10
|
-
"InvalidWorkspaces",
|
|
11
|
-
"InvalidWorkspacePattern",
|
|
12
|
-
"AliasConflict",
|
|
13
|
-
"AliasedWorkspaceNotFound",
|
|
14
|
-
);
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import type { ProjectConfig } from "../config";
|
|
4
|
-
import { logger } from "../internal/logger";
|
|
5
|
-
import { ERRORS } from "./errors";
|
|
6
|
-
import {
|
|
7
|
-
resolvePackageJsonContent,
|
|
8
|
-
resolvePackageJsonPath,
|
|
9
|
-
scanWorkspaceGlob,
|
|
10
|
-
} from "./packageJson";
|
|
11
|
-
import type { Workspace } from "./workspace";
|
|
12
|
-
|
|
13
|
-
export interface FindWorkspacesOptions {
|
|
14
|
-
rootDir: string;
|
|
15
|
-
workspaceGlobs: string[];
|
|
16
|
-
workspaceAliases?: ProjectConfig["workspaceAliases"];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const validatePattern = (pattern: string) => {
|
|
20
|
-
if (pattern.startsWith("!")) {
|
|
21
|
-
logger.warn(
|
|
22
|
-
`Negation patterns are not supported by Bun workspaces: ${JSON.stringify(
|
|
23
|
-
pattern,
|
|
24
|
-
)}`,
|
|
25
|
-
);
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const validateWorkspace = (workspace: Workspace, workspaces: Workspace[]) => {
|
|
32
|
-
if (workspaces.find((ws) => ws.path === workspace.path)) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (workspaces.find((ws) => ws.name === workspace.name)) {
|
|
37
|
-
throw new ERRORS.DuplicateWorkspaceName(
|
|
38
|
-
`Duplicate workspace name found: ${JSON.stringify(workspace.name)}`,
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return true;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const findWorkspaces = ({
|
|
46
|
-
rootDir,
|
|
47
|
-
workspaceGlobs,
|
|
48
|
-
workspaceAliases,
|
|
49
|
-
}: FindWorkspacesOptions) => {
|
|
50
|
-
rootDir = path.resolve(rootDir);
|
|
51
|
-
|
|
52
|
-
const workspaces: Workspace[] = [];
|
|
53
|
-
|
|
54
|
-
for (const pattern of workspaceGlobs) {
|
|
55
|
-
if (!validatePattern(pattern)) continue;
|
|
56
|
-
|
|
57
|
-
for (const item of scanWorkspaceGlob(pattern, rootDir)) {
|
|
58
|
-
const packageJsonPath = resolvePackageJsonPath(item);
|
|
59
|
-
if (packageJsonPath) {
|
|
60
|
-
const packageJsonContent = resolvePackageJsonContent(
|
|
61
|
-
packageJsonPath,
|
|
62
|
-
rootDir,
|
|
63
|
-
["name", "scripts"],
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const workspace: Workspace = {
|
|
67
|
-
name: packageJsonContent.name ?? "",
|
|
68
|
-
matchPattern: pattern,
|
|
69
|
-
path: path.relative(rootDir, path.dirname(packageJsonPath)),
|
|
70
|
-
packageJson: packageJsonContent,
|
|
71
|
-
aliases: Object.entries(workspaceAliases ?? {})
|
|
72
|
-
.filter(([_, value]) => value === packageJsonContent.name)
|
|
73
|
-
.map(([key]) => key),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
if (validateWorkspace(workspace, workspaces)) {
|
|
77
|
-
workspaces.push(workspace);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
workspaces.sort(
|
|
84
|
-
(a, b) => a.name.localeCompare(b.name) || a.path.localeCompare(b.path),
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
return { workspaces };
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export const validateWorkspaceAliases = (
|
|
91
|
-
workspaces: Workspace[],
|
|
92
|
-
workspaceAliases: ProjectConfig["workspaceAliases"],
|
|
93
|
-
) => {
|
|
94
|
-
for (const [alias, name] of Object.entries(workspaceAliases ?? {})) {
|
|
95
|
-
if (workspaces.find((ws) => ws.name === alias)) {
|
|
96
|
-
throw new ERRORS.AliasConflict(
|
|
97
|
-
`Alias ${JSON.stringify(alias)} conflicts with workspace name ${JSON.stringify(name)}`,
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
if (!workspaces.find((ws) => ws.name === name)) {
|
|
101
|
-
throw new ERRORS.AliasedWorkspaceNotFound(
|
|
102
|
-
`Workspace ${JSON.stringify(name)} was aliased by ${JSON.stringify(
|
|
103
|
-
alias,
|
|
104
|
-
)} but was not found`,
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export const findWorkspacesFromPackage = ({
|
|
111
|
-
rootDir,
|
|
112
|
-
workspaceAliases,
|
|
113
|
-
}: ProjectConfig & { rootDir: string }) => {
|
|
114
|
-
const packageJsonPath = path.join(rootDir, "package.json");
|
|
115
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
116
|
-
throw new ERRORS.PackageNotFound(
|
|
117
|
-
`No package.json found at ${packageJsonPath}`,
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const packageJson = resolvePackageJsonContent(packageJsonPath, rootDir, [
|
|
122
|
-
"workspaces",
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
const result = findWorkspaces({
|
|
126
|
-
rootDir,
|
|
127
|
-
workspaceGlobs: packageJson.workspaces ?? [],
|
|
128
|
-
workspaceAliases,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
validateWorkspaceAliases(result.workspaces, workspaceAliases);
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
...result,
|
|
135
|
-
name: packageJson.name ?? "",
|
|
136
|
-
};
|
|
137
|
-
};
|
package/src/workspaces/index.ts
DELETED