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.
Files changed (154) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +131 -77
  3. package/bin/cli.js +1 -2
  4. package/package.json +24 -30
  5. package/src/cli/commands/commandHandlerUtils.d.ts +41 -0
  6. package/src/cli/commands/commandHandlerUtils.mjs +59 -0
  7. package/src/cli/commands/commands.d.ts +10 -0
  8. package/src/cli/commands/commands.mjs +23 -0
  9. package/src/cli/commands/commandsConfig.d.ts +312 -0
  10. package/src/cli/commands/commandsConfig.mjs +155 -0
  11. package/src/cli/commands/handleRunScript.d.ts +3 -0
  12. package/src/cli/commands/handleRunScript.mjs +217 -0
  13. package/src/cli/commands/handleSimpleCommands.d.ts +15 -0
  14. package/src/cli/commands/handleSimpleCommands.mjs +170 -0
  15. package/src/cli/commands/index.d.ts +2 -0
  16. package/src/cli/commands/index.mjs +2 -0
  17. package/src/cli/createCli.d.ts +19 -0
  18. package/src/cli/createCli.mjs +113 -0
  19. package/src/cli/fatalErrorLogger.d.ts +1 -0
  20. package/src/cli/fatalErrorLogger.mjs +7 -0
  21. package/src/cli/globalOptions/globalOptions.d.ts +38 -0
  22. package/src/cli/globalOptions/globalOptions.mjs +120 -0
  23. package/src/cli/globalOptions/globalOptionsConfig.d.ts +43 -0
  24. package/src/cli/globalOptions/globalOptionsConfig.mjs +34 -0
  25. package/src/cli/globalOptions/index.d.ts +2 -0
  26. package/src/cli/globalOptions/index.mjs +2 -0
  27. package/src/cli/index.d.ts +3 -0
  28. package/src/cli/index.mjs +3 -0
  29. package/src/config/bunWorkspacesConfig.d.ts +17 -0
  30. package/src/config/bunWorkspacesConfig.mjs +50 -0
  31. package/src/config/configFile.d.ts +8 -0
  32. package/src/config/configFile.mjs +43 -0
  33. package/src/config/errors.d.ts +3 -0
  34. package/src/config/errors.mjs +10 -0
  35. package/src/config/{index.ts → index.d.ts} +1 -0
  36. package/src/config/index.mjs +11 -0
  37. package/src/config/userEnvVars.d.ts +9 -0
  38. package/src/config/userEnvVars.mjs +9 -0
  39. package/src/config/workspaceConfig/errors.d.ts +3 -0
  40. package/src/config/workspaceConfig/errors.mjs +9 -0
  41. package/src/config/workspaceConfig/index.d.ts +4 -0
  42. package/src/config/workspaceConfig/index.mjs +4 -0
  43. package/src/config/workspaceConfig/loadWorkspaceConfig.d.ts +5 -0
  44. package/src/config/workspaceConfig/loadWorkspaceConfig.mjs +82 -0
  45. package/src/config/workspaceConfig/workspaceConfig.d.ts +25 -0
  46. package/src/config/workspaceConfig/workspaceConfig.mjs +80 -0
  47. package/src/config/workspaceConfig/workspaceConfigLocation.d.ts +2 -0
  48. package/src/config/workspaceConfig/workspaceConfigLocation.mjs +5 -0
  49. package/src/doctor/doctor.d.ts +35 -0
  50. package/src/doctor/doctor.mjs +52 -0
  51. package/src/doctor/index.d.ts +1 -0
  52. package/src/doctor/index.mjs +1 -0
  53. package/src/index.d.ts +31 -0
  54. package/src/index.mjs +9 -0
  55. package/src/internal/bun/bunLock.d.ts +20 -0
  56. package/src/internal/bun/bunLock.mjs +72 -0
  57. package/src/internal/bun/bunVersion.d.ts +21 -0
  58. package/src/internal/bun/bunVersion.mjs +43 -0
  59. package/src/internal/bun/index.d.ts +2 -0
  60. package/src/internal/bun/index.mjs +2 -0
  61. package/src/internal/core/asyncIterable/asyncIterableQueue.d.ts +15 -0
  62. package/src/internal/core/asyncIterable/asyncIterableQueue.mjs +73 -0
  63. package/src/internal/core/asyncIterable/mergeAsyncIterables.d.ts +5 -0
  64. package/src/internal/core/asyncIterable/mergeAsyncIterables.mjs +27 -0
  65. package/src/internal/core/error.d.ts +9 -0
  66. package/src/internal/{error.ts → core/error.mjs} +7 -16
  67. package/src/internal/core/index.d.ts +7 -0
  68. package/src/internal/core/index.mjs +6 -0
  69. package/src/internal/core/json/index.d.ts +2 -0
  70. package/src/internal/core/json/index.mjs +2 -0
  71. package/src/internal/core/json/json.d.ts +9 -0
  72. package/src/internal/core/json/json.mjs +6 -0
  73. package/src/internal/core/json/jsonc.d.ts +9 -0
  74. package/src/internal/core/json/jsonc.mjs +117 -0
  75. package/src/internal/core/optionalArray.d.ts +15 -0
  76. package/src/internal/core/optionalArray.mjs +8 -0
  77. package/src/internal/core/regex.d.ts +3 -0
  78. package/src/internal/core/regex.mjs +10 -0
  79. package/src/internal/core/types.d.ts +6 -0
  80. package/src/internal/core/types.mjs +3 -0
  81. package/src/internal/logger/index.d.ts +1 -0
  82. package/src/internal/logger/index.mjs +1 -0
  83. package/src/internal/logger/logger.d.ts +44 -0
  84. package/src/internal/logger/logger.mjs +110 -0
  85. package/src/internal/runtime/env.d.ts +5 -0
  86. package/src/internal/runtime/env.mjs +29 -0
  87. package/src/internal/runtime/index.d.ts +2 -0
  88. package/src/internal/runtime/index.mjs +2 -0
  89. package/src/internal/runtime/onExit.d.ts +6 -0
  90. package/src/internal/runtime/onExit.mjs +24 -0
  91. package/src/internal/runtime/os.d.ts +4 -0
  92. package/src/internal/runtime/os.mjs +7 -0
  93. package/src/internal/runtime/tempFile.d.ts +16 -0
  94. package/src/internal/runtime/tempFile.mjs +50 -0
  95. package/src/project/errors.d.ts +3 -0
  96. package/src/project/errors.mjs +9 -0
  97. package/src/project/implementations/fileSystemProject.d.ts +106 -0
  98. package/src/project/implementations/fileSystemProject.mjs +227 -0
  99. package/src/project/implementations/memoryProject.d.ts +32 -0
  100. package/src/project/implementations/memoryProject.mjs +46 -0
  101. package/src/project/implementations/projectBase.d.ts +28 -0
  102. package/src/project/implementations/projectBase.mjs +117 -0
  103. package/src/project/index.d.ts +5 -0
  104. package/src/project/index.mjs +4 -0
  105. package/src/project/project.d.ts +64 -0
  106. package/src/project/project.mjs +6 -0
  107. package/src/runScript/index.d.ts +7 -0
  108. package/src/runScript/index.mjs +7 -0
  109. package/src/runScript/outputChunk.d.ts +22 -0
  110. package/src/runScript/outputChunk.mjs +30 -0
  111. package/src/runScript/parallel.d.ts +12 -0
  112. package/src/runScript/parallel.mjs +52 -0
  113. package/src/runScript/runScript.d.ts +37 -0
  114. package/src/runScript/runScript.mjs +60 -0
  115. package/src/runScript/runScripts.d.ts +48 -0
  116. package/src/runScript/runScripts.mjs +124 -0
  117. package/src/runScript/scriptCommand.d.ts +33 -0
  118. package/src/runScript/scriptCommand.mjs +19 -0
  119. package/src/runScript/scriptExecution.d.ts +9 -0
  120. package/src/runScript/scriptExecution.mjs +51 -0
  121. package/src/runScript/scriptRuntimeMetadata.d.ts +75 -0
  122. package/src/runScript/scriptRuntimeMetadata.mjs +62 -0
  123. package/src/runScript/scriptShellOption.d.ts +7 -0
  124. package/src/runScript/scriptShellOption.mjs +36 -0
  125. package/src/workspaces/errors.d.ts +12 -0
  126. package/src/workspaces/{errors.ts → errors.mjs} +5 -2
  127. package/src/workspaces/findWorkspaces.d.ts +22 -0
  128. package/src/workspaces/findWorkspaces.mjs +168 -0
  129. package/src/workspaces/index.d.ts +4 -0
  130. package/src/workspaces/index.mjs +3 -0
  131. package/src/workspaces/packageJson.d.ts +15 -0
  132. package/src/workspaces/packageJson.mjs +135 -0
  133. package/src/workspaces/{workspace.ts → workspace.d.ts} +5 -6
  134. package/src/workspaces/workspace.mjs +2 -0
  135. package/bun.lock +0 -576
  136. package/src/cli/cli.ts +0 -87
  137. package/src/cli/globalOptions.ts +0 -122
  138. package/src/cli/index.ts +0 -1
  139. package/src/cli/projectCommands.ts +0 -390
  140. package/src/config/bunWorkspacesConfig.ts +0 -62
  141. package/src/config/configFile.ts +0 -33
  142. package/src/index.ts +0 -3
  143. package/src/internal/bunVersion.ts +0 -26
  144. package/src/internal/env.ts +0 -25
  145. package/src/internal/logger.ts +0 -180
  146. package/src/internal/regex.ts +0 -5
  147. package/src/project/errors.ts +0 -6
  148. package/src/project/index.ts +0 -6
  149. package/src/project/project.ts +0 -155
  150. package/src/project/scriptCommand.ts +0 -40
  151. package/src/workspaces/findWorkspaces.ts +0 -137
  152. package/src/workspaces/index.ts +0 -7
  153. package/src/workspaces/packageJson.ts +0 -166
  154. package/tsconfig.json +0 -28
@@ -0,0 +1,73 @@
1
+ // CONCATENATED MODULE: ./src/internal/core/asyncIterable/asyncIterableQueue.ts
2
+ const createAsyncIterableQueue = () => {
3
+ let pendingResolveIdle = null;
4
+ const items = [];
5
+ let isDone = false;
6
+ const push = (value) => {
7
+ if (isDone) return;
8
+ if (pendingResolveIdle) {
9
+ const resolveIdle = pendingResolveIdle;
10
+ pendingResolveIdle = null;
11
+ resolveIdle({
12
+ value,
13
+ done: false,
14
+ });
15
+ } else {
16
+ items.push({
17
+ type: "value",
18
+ value,
19
+ });
20
+ }
21
+ };
22
+ const close = () => {
23
+ if (isDone) return;
24
+ isDone = true;
25
+ if (pendingResolveIdle) {
26
+ const resolveIdle = pendingResolveIdle;
27
+ pendingResolveIdle = null;
28
+ resolveIdle({
29
+ value: undefined,
30
+ done: true,
31
+ });
32
+ } else {
33
+ items.push({
34
+ type: "done",
35
+ });
36
+ }
37
+ };
38
+ const asyncIterator = {
39
+ next: () => {
40
+ if (items.length > 0) {
41
+ const item = items.shift();
42
+ if (item.type === "done") {
43
+ isDone = true;
44
+ return Promise.resolve({
45
+ value: undefined,
46
+ done: true,
47
+ });
48
+ }
49
+ return Promise.resolve({
50
+ value: item.value,
51
+ done: false,
52
+ });
53
+ }
54
+ if (isDone) {
55
+ return Promise.resolve({
56
+ value: undefined,
57
+ done: true,
58
+ });
59
+ }
60
+ return new Promise((resolve) => {
61
+ pendingResolveIdle = resolve;
62
+ });
63
+ },
64
+ };
65
+ const iterator = {
66
+ [Symbol.asyncIterator]: () => asyncIterator,
67
+ push,
68
+ close,
69
+ };
70
+ return iterator;
71
+ };
72
+
73
+ export { createAsyncIterableQueue };
@@ -0,0 +1,5 @@
1
+ import type { SimpleAsyncIterable } from "../types";
2
+ /** Run multiple async iterables in parallel and yield the results in the order they are completed. */
3
+ export declare const mergeAsyncIterables: <T>(
4
+ iterables: SimpleAsyncIterable<T>[],
5
+ ) => SimpleAsyncIterable<T>;
@@ -0,0 +1,27 @@
1
+ // CONCATENATED MODULE: ./src/internal/core/asyncIterable/mergeAsyncIterables.ts
2
+ /** Run multiple async iterables in parallel and yield the results in the order they are completed. */ const mergeAsyncIterables =
3
+ (iterables) => ({
4
+ async *[Symbol.asyncIterator]() {
5
+ const iterators = iterables.map((it) => it[Symbol.asyncIterator]());
6
+ const callNext = (index) =>
7
+ iterators[index].next().then((result) => ({
8
+ index,
9
+ result,
10
+ }));
11
+ const nextCalls = iterators.map((_, i) => callNext(i));
12
+ let activeCount = iterators.length;
13
+ while (activeCount > 0) {
14
+ const { index, result } = await Promise.race(nextCalls);
15
+ if (result.done) {
16
+ activeCount--;
17
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
18
+ nextCalls[index] = new Promise(() => {});
19
+ continue;
20
+ }
21
+ nextCalls[index] = callNext(index);
22
+ yield result.value;
23
+ }
24
+ },
25
+ });
26
+
27
+ export { mergeAsyncIterables };
@@ -0,0 +1,9 @@
1
+ export declare class BunWorkspacesError extends Error {
2
+ name: string;
3
+ }
4
+ export type DefinedErrors<ErrorName extends string> = {
5
+ [name in ErrorName]: typeof BunWorkspacesError;
6
+ };
7
+ export declare const defineErrors: <ErrorName extends string>(
8
+ ...errors: ErrorName[]
9
+ ) => DefinedErrors<ErrorName>;
@@ -1,38 +1,29 @@
1
- export class BunWorkspacesError extends Error {
1
+ // CONCATENATED MODULE: ./src/internal/core/error.ts
2
+ class BunWorkspacesError extends Error {
2
3
  name = "BunWorkspacesError";
3
4
  }
4
-
5
- export type DefinedErrors<ErrorName extends string> = {
6
- [name in ErrorName]: typeof BunWorkspacesError;
7
- };
8
-
9
- export const defineErrors = <ErrorName extends string>(
10
- ...errors: ErrorName[]
11
- ): DefinedErrors<ErrorName> =>
5
+ const defineErrors = (...errors) =>
12
6
  errors.reduce((acc, error) => {
13
7
  acc[error] = class extends BunWorkspacesError {
14
- constructor(message?: string) {
8
+ constructor(message) {
15
9
  super(message);
16
10
  this.name = error;
17
11
  }
18
12
  name = error;
19
13
  };
20
-
21
14
  Object.defineProperty(acc[error].prototype.constructor, "name", {
22
15
  value: error,
23
16
  });
24
-
25
17
  Object.defineProperty(acc[error].constructor, "name", {
26
18
  value: error,
27
19
  });
28
-
29
20
  Object.defineProperty(acc[error].prototype, "name", {
30
21
  value: error,
31
22
  });
32
-
33
23
  Object.defineProperty(acc[error], "name", {
34
24
  value: error,
35
25
  });
36
-
37
26
  return acc;
38
- }, {} as DefinedErrors<ErrorName>);
27
+ }, {});
28
+
29
+ export { BunWorkspacesError, defineErrors };
@@ -0,0 +1,7 @@
1
+ export * from "./asyncIterable/asyncIterableQueue";
2
+ export type * from "./types";
3
+ export * from "./error";
4
+ export * from "./json/json";
5
+ export * from "./asyncIterable/mergeAsyncIterables";
6
+ export * from "./optionalArray";
7
+ export * from "./regex";
@@ -0,0 +1,6 @@
1
+ export * from "./asyncIterable/asyncIterableQueue.mjs";
2
+ export * from "./error.mjs";
3
+ export * from "./json/json.mjs";
4
+ export * from "./asyncIterable/mergeAsyncIterables.mjs";
5
+ export * from "./optionalArray.mjs";
6
+ export * from "./regex.mjs"; // CONCATENATED MODULE: ./src/internal/core/index.ts
@@ -0,0 +1,2 @@
1
+ export * from "./json";
2
+ export * from "./jsonc";
@@ -0,0 +1,2 @@
1
+ export * from "./json.mjs";
2
+ export * from "./jsonc.mjs"; // CONCATENATED MODULE: ./src/internal/core/json/index.ts
@@ -0,0 +1,9 @@
1
+ export type JSONData = JSONPrimitive | JSONObject | JSONArray;
2
+ export type JSONPrimitive = string | number | boolean | null;
3
+ export interface JSONObject {
4
+ [key: string]: JSONData;
5
+ }
6
+ export type JSONArray = JSONData[];
7
+ export declare const isJsonObject: <T extends JSONObject = JSONObject>(
8
+ value: unknown,
9
+ ) => value is T;
@@ -0,0 +1,6 @@
1
+ // CONCATENATED MODULE: ./src/internal/core/json/json.ts
2
+ const isJsonObject = (value) => {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ };
5
+
6
+ export { isJsonObject };
@@ -0,0 +1,9 @@
1
+ export declare const convertJsoncToJson: (
2
+ jsonString: string,
3
+ {
4
+ whitespace,
5
+ }?: {
6
+ whitespace?: boolean | undefined;
7
+ },
8
+ ) => string;
9
+ export declare const parseJsonc: (jsonString: string) => any;
@@ -0,0 +1,117 @@
1
+ // CONCATENATED MODULE: ./src/internal/core/json/jsonc.ts
2
+ // Code based on package strip-json-comments
3
+ const stripWithoutWhitespace = () => "";
4
+ // Replace all characters except ASCII spaces, tabs and line endings with regular spaces to ensure valid JSON output.
5
+ const stripWithWhitespace = (string, start, end) =>
6
+ string.slice(start, end).replace(/[^ \t\r\n]/g, " ");
7
+ const isEscaped = (jsonString, quotePosition) => {
8
+ let index = quotePosition - 1;
9
+ let backslashCount = 0;
10
+ while (jsonString[index] === "\\") {
11
+ index -= 1;
12
+ backslashCount += 1;
13
+ }
14
+ return Boolean(backslashCount % 2);
15
+ };
16
+ const convertJsoncToJson = (jsonString, { whitespace = true } = {}) => {
17
+ if (typeof jsonString !== "string") {
18
+ throw new TypeError(
19
+ `Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``,
20
+ );
21
+ }
22
+ const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
23
+ let isInsideString = false;
24
+ let inComment = null;
25
+ let offset = 0;
26
+ let buffer = "";
27
+ let result = "";
28
+ let commaIndex = -1;
29
+ for (let index = 0; index < jsonString.length; index++) {
30
+ const currentCharacter = jsonString[index];
31
+ const nextCharacter = jsonString[index + 1];
32
+ if (!inComment && currentCharacter === '"') {
33
+ // Enter or exit string
34
+ const escaped = isEscaped(jsonString, index);
35
+ if (!escaped) {
36
+ isInsideString = !isInsideString;
37
+ }
38
+ }
39
+ if (isInsideString) {
40
+ continue;
41
+ }
42
+ if (!inComment && currentCharacter + nextCharacter === "//") {
43
+ // Enter single-line comment
44
+ buffer += jsonString.slice(offset, index);
45
+ offset = index;
46
+ inComment = "single";
47
+ index++;
48
+ } else if (
49
+ inComment === "single" &&
50
+ currentCharacter + nextCharacter === "\r\n"
51
+ ) {
52
+ // Exit single-line comment via \r\n
53
+ index++;
54
+ inComment = null;
55
+ buffer += strip(jsonString, offset, index);
56
+ offset = index;
57
+ continue;
58
+ } else if (inComment === "single" && currentCharacter === "\n") {
59
+ // Exit single-line comment via \n
60
+ inComment = null;
61
+ buffer += strip(jsonString, offset, index);
62
+ offset = index;
63
+ } else if (!inComment && currentCharacter + nextCharacter === "/*") {
64
+ // Enter multiline comment
65
+ buffer += jsonString.slice(offset, index);
66
+ offset = index;
67
+ inComment = "multi";
68
+ index++;
69
+ continue;
70
+ } else if (
71
+ inComment === "multi" &&
72
+ currentCharacter + nextCharacter === "*/"
73
+ ) {
74
+ // Exit multiline comment
75
+ index++;
76
+ inComment = null;
77
+ buffer += strip(jsonString, offset, index + 1);
78
+ offset = index + 1;
79
+ continue;
80
+ } else if (!inComment) {
81
+ if (commaIndex !== -1) {
82
+ if (currentCharacter === "}" || currentCharacter === "]") {
83
+ // Strip trailing comma
84
+ buffer += jsonString.slice(offset, index);
85
+ result += strip(buffer, 0, 1) + buffer.slice(1);
86
+ buffer = "";
87
+ offset = index;
88
+ commaIndex = -1;
89
+ } else if (
90
+ currentCharacter !== " " &&
91
+ currentCharacter !== "\t" &&
92
+ currentCharacter !== "\r" &&
93
+ currentCharacter !== "\n"
94
+ ) {
95
+ // Hit non-whitespace following a comma; comma is not trailing
96
+ buffer += jsonString.slice(offset, index);
97
+ offset = index;
98
+ commaIndex = -1;
99
+ }
100
+ } else if (currentCharacter === ",") {
101
+ // Flush buffer prior to this point, and save new comma index
102
+ result += buffer + jsonString.slice(offset, index);
103
+ buffer = "";
104
+ offset = index;
105
+ commaIndex = index;
106
+ }
107
+ }
108
+ }
109
+ const remaining =
110
+ inComment === "single"
111
+ ? strip(jsonString, offset)
112
+ : jsonString.slice(offset);
113
+ return result + buffer + remaining;
114
+ };
115
+ const parseJsonc = (jsonString) => JSON.parse(convertJsoncToJson(jsonString));
116
+
117
+ export { convertJsoncToJson, parseJsonc };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A value that may be its type T or an array of T.
3
+ */
4
+ export type OptionalArray<
5
+ T = unknown,
6
+ IncludeReadonly extends boolean = false,
7
+ > = IncludeReadonly extends true ? T | T[] | readonly T[] : T | T[];
8
+ export type ResolvedOptionalArray<T extends OptionalArray> =
9
+ T extends (infer Item)[] ? Item[] : T[];
10
+ export type ResolvedOptionalArrayItem<T extends OptionalArray> =
11
+ T extends (infer Item)[] ? Item : T;
12
+ /** Resolve `OptionalArray<T>` to `T[]` */
13
+ export declare const resolveOptionalArray: <T extends OptionalArray>(
14
+ value: T,
15
+ ) => ResolvedOptionalArray<T>;
@@ -0,0 +1,8 @@
1
+ // CONCATENATED MODULE: ./src/internal/core/optionalArray.ts
2
+ /**
3
+ * A value that may be its type T or an array of T.
4
+ */ /** Resolve `OptionalArray<T>` to `T[]` */ const resolveOptionalArray = (
5
+ value,
6
+ ) => (value === undefined ? [] : Array.isArray(value) ? value : [value]);
7
+
8
+ export { resolveOptionalArray };
@@ -0,0 +1,3 @@
1
+ export declare const createRawPattern: (pattern: string) => string;
2
+ export declare const createWildcardRegex: (pattern: string) => RegExp;
3
+ export declare const sanitizeAnsi: (text: string) => string;
@@ -0,0 +1,10 @@
1
+ // CONCATENATED MODULE: ./src/internal/core/regex.ts
2
+ const createRawPattern = (pattern) =>
3
+ pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+ const createWildcardRegex = (pattern) =>
5
+ new RegExp(`^${pattern.split("*").map(createRawPattern).join(".*")}$`);
6
+ const sanitizeAnsi = (
7
+ text, // eslint-disable-next-line no-control-regex
8
+ ) => text.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
9
+
10
+ export { createRawPattern, createWildcardRegex, sanitizeAnsi };
@@ -0,0 +1,6 @@
1
+ /** Does not change an object type, but remaps it for cleaner Intellisense only */
2
+ export type Simplify<T extends object> = {
3
+ [K in keyof T]: T[K];
4
+ };
5
+ /** A normal `AsyncIterable` that is only intended for `for await` style iteration */
6
+ export type SimpleAsyncIterable<T> = AsyncIterable<T, void, undefined>;
@@ -0,0 +1,3 @@
1
+ // CONCATENATED MODULE: ./src/internal/core/types.ts
2
+ /** Does not change an object type, but remaps it for cleaner Intellisense only */
3
+ /** A normal `AsyncIterable` that is only intended for `for await` style iteration */
@@ -0,0 +1 @@
1
+ export * from "./logger";
@@ -0,0 +1 @@
1
+ export * from "./logger.mjs"; // CONCATENATED MODULE: ./src/internal/logger/index.ts
@@ -0,0 +1,44 @@
1
+ export declare const LOG_LEVELS: readonly ["debug", "info", "warn", "error"];
2
+ export type LogLevel = (typeof LOG_LEVELS)[number];
3
+ export type LogLevelSetting = LogLevel | "silent";
4
+ export declare const validateLogLevel: (level: LogLevelSetting) => void;
5
+ export type LogMetadata = Record<string, unknown>;
6
+ export interface Log<
7
+ Message extends string | Error = string,
8
+ Metadata extends LogMetadata = LogMetadata,
9
+ > {
10
+ message: Message;
11
+ level: LogLevel;
12
+ metadata: Metadata;
13
+ time: Date;
14
+ }
15
+ export type Logger = {
16
+ name: string;
17
+ log<
18
+ Message extends string | Error = string,
19
+ Metadata extends LogMetadata = LogMetadata,
20
+ >(
21
+ message: Message,
22
+ level: LogLevel,
23
+ metadata?: Metadata,
24
+ ): Log<Message, Metadata>;
25
+ logOutput(
26
+ chunk: Uint8Array | string,
27
+ level: LogLevel,
28
+ stream: NodeJS.WriteStream,
29
+ prefix: string,
30
+ ): Log<string, Record<string, unknown>>;
31
+ printLevel: LogLevelSetting;
32
+ } & {
33
+ [Level in LogLevel]: <
34
+ Message extends string | Error = string,
35
+ Metadata extends LogMetadata = LogMetadata,
36
+ >(
37
+ message: Message,
38
+ metadata?: Metadata,
39
+ ) => Log<Message, Metadata>;
40
+ };
41
+ export declare const createLogger: (name: string) => Logger;
42
+ export declare const logger: Logger;
43
+ /** Set the global logging level. Defaults to "info" or "error" when `NODE_ENV` is "test" */
44
+ export declare const setLogLevel: (level: LogLevelSetting) => void;
@@ -0,0 +1,110 @@
1
+ import { defineErrors } from "../core/index.mjs";
2
+ import { IS_TEST } from "../runtime/index.mjs"; // CONCATENATED MODULE: external "../core/index.mjs"
3
+ // CONCATENATED MODULE: external "../runtime/index.mjs"
4
+ // CONCATENATED MODULE: ./src/internal/logger/logger.ts
5
+
6
+ const LOG_LEVELS = ["debug", "info", "warn", "error"];
7
+ const getLevelNumber = (level) => LOG_LEVELS.indexOf(level);
8
+ const ERRORS = defineErrors("InvalidLogLevel");
9
+ const validateLogLevel = (level) => {
10
+ if (level === "silent") return;
11
+ if (!LOG_LEVELS.includes(level)) {
12
+ throw new ERRORS.InvalidLogLevel(
13
+ `Invalid log level: "${level}". Accepted values: ${LOG_LEVELS.join(", ")}`,
14
+ );
15
+ }
16
+ };
17
+ const createLogger = (name) => new _Logger(name);
18
+ class _Logger {
19
+ name;
20
+ constructor(name) {
21
+ this.name = name;
22
+ }
23
+ log(message, level, metadata) {
24
+ const log = {
25
+ message,
26
+ level,
27
+ metadata: metadata ?? {},
28
+ time: new Date(),
29
+ };
30
+ if (this.shouldPrint(level)) {
31
+ const formattedMessage = this.formatLogMessage(message, level);
32
+ if (message instanceof Error) {
33
+ message.message = formattedMessage;
34
+ }
35
+ // eslint-disable-next-line no-console
36
+ console[level](
37
+ message instanceof Error ? message : formattedMessage,
38
+ ...(metadata
39
+ ? [
40
+ {
41
+ metadata,
42
+ },
43
+ ]
44
+ : []),
45
+ );
46
+ }
47
+ return log;
48
+ }
49
+ logOutput(chunk, level, stream, prefix) {
50
+ const message =
51
+ typeof chunk === "string"
52
+ ? chunk.trim()
53
+ : new TextDecoder().decode(chunk).trim();
54
+ const log = {
55
+ message,
56
+ level,
57
+ metadata: {
58
+ stream,
59
+ isLogOutput: true,
60
+ },
61
+ time: new Date(),
62
+ };
63
+ if (!this.shouldPrint(level)) {
64
+ return log;
65
+ }
66
+ const linePrefix = `${prefix}\x1b[0m`;
67
+ const lines = message.split(/\r?\n/);
68
+ lines.forEach((line) => {
69
+ if (line) stream.write(linePrefix + line + "\n");
70
+ });
71
+ return log;
72
+ }
73
+ debug(message, metadata) {
74
+ return this.log(message, "debug", metadata);
75
+ }
76
+ info(message, metadata) {
77
+ return this.log(message, "info", metadata);
78
+ }
79
+ warn(message, metadata) {
80
+ return this.log(message, "warn", metadata);
81
+ }
82
+ error(message, metadata) {
83
+ return this.log(message, "error", metadata);
84
+ }
85
+ get printLevel() {
86
+ return this._printLevel;
87
+ }
88
+ set printLevel(level) {
89
+ this._printLevel = level;
90
+ }
91
+ // Info prints normally for standard user-facing logs. Debug and Warn are highlighted with a prefix. Errors print as Error instances
92
+ formatLogMessage(message, level) {
93
+ const content = message instanceof Error ? message.message : message;
94
+ return level === "debug" || level === "warn"
95
+ ? `[${this.name} ${level.toUpperCase()}]: ${content}`
96
+ : content;
97
+ }
98
+ _printLevel = IS_TEST ? "error" : "info";
99
+ shouldPrint(level) {
100
+ if (this.printLevel === "silent") return false;
101
+ return getLevelNumber(level) >= getLevelNumber(this.printLevel);
102
+ }
103
+ }
104
+ const logger = createLogger("bun-workspaces");
105
+ /** Set the global logging level. Defaults to "info" or "error" when `NODE_ENV` is "test" */ const setLogLevel =
106
+ (level) => {
107
+ logger.printLevel = level;
108
+ };
109
+
110
+ export { LOG_LEVELS, createLogger, logger, setLogLevel, validateLogLevel };
@@ -0,0 +1,5 @@
1
+ export type RuntimeMode = "development" | "production" | "test";
2
+ export declare const RUNTIME_MODE: RuntimeMode;
3
+ export declare const IS_TEST: boolean;
4
+ export declare const IS_PRODUCTION: boolean;
5
+ export declare const IS_DEVELOPMENT: boolean;
@@ -0,0 +1,29 @@
1
+ // CONCATENATED MODULE: ./src/internal/runtime/env.ts
2
+ /* eslint-disable no-console */ const _process =
3
+ typeof process === "undefined"
4
+ ? {
5
+ env: {},
6
+ }
7
+ : process;
8
+ const RUNTIME_MODE_VALUES = ["development", "production", "test"];
9
+ const _RUNTIME_MODE =
10
+ _process.env._BW_RUNTIME_MODE ||
11
+ (process.env.NODE_ENV?.match(/test(ing | s)?/)
12
+ ? "test"
13
+ : process.env.NODE_ENV === "development"
14
+ ? "development"
15
+ : "production");
16
+ const RUNTIME_MODE = RUNTIME_MODE_VALUES.includes(_RUNTIME_MODE)
17
+ ? _RUNTIME_MODE
18
+ : "production";
19
+ if (RUNTIME_MODE !== _RUNTIME_MODE) {
20
+ // eslint-disable-next-line no-console
21
+ console.error(
22
+ `Env var _BW_RUNTIME_MODE has an invalid value: "${_RUNTIME_MODE}". Defaulting to "${RUNTIME_MODE}". Accepted values: ${RUNTIME_MODE_VALUES.join(", ")}.`,
23
+ );
24
+ }
25
+ const IS_TEST = RUNTIME_MODE === "test";
26
+ const IS_PRODUCTION = RUNTIME_MODE === "production";
27
+ const IS_DEVELOPMENT = RUNTIME_MODE === "development";
28
+
29
+ export { IS_DEVELOPMENT, IS_PRODUCTION, IS_TEST, RUNTIME_MODE };
@@ -0,0 +1,2 @@
1
+ export * from "./env";
2
+ export * from "./os";
@@ -0,0 +1,2 @@
1
+ export * from "./env.mjs";
2
+ export * from "./os.mjs"; // CONCATENATED MODULE: ./src/internal/runtime/index.ts
@@ -0,0 +1,6 @@
1
+ import type { ProcessEventMap } from "node:process";
2
+ export declare const runOnExit: <
3
+ F extends (exit?: keyof ProcessEventMap | number) => unknown,
4
+ >(
5
+ fn: F,
6
+ ) => void;
@@ -0,0 +1,24 @@
1
+ // CONCATENATED MODULE: ./src/internal/runtime/onExit.ts
2
+ const runOnExit = (fn) => {
3
+ let ran = false;
4
+ const run = (exit) => {
5
+ if (ran) return;
6
+ ran = true;
7
+ fn(exit);
8
+ };
9
+ const onExit = (exit) => {
10
+ run(exit);
11
+ process.removeListener("exit", onExit);
12
+ };
13
+ process.on("exit", onExit);
14
+ for (const signal of [`SIGINT`, `SIGUSR1`, `SIGUSR2`, `SIGTERM`]) {
15
+ const onSignal = (signal) => {
16
+ run(signal);
17
+ process.removeListener(signal, onSignal);
18
+ process.kill(process.pid, signal);
19
+ };
20
+ process.on(signal, onSignal);
21
+ }
22
+ };
23
+
24
+ export { runOnExit };
@@ -0,0 +1,4 @@
1
+ export declare const IS_WINDOWS: boolean;
2
+ export declare const IS_MACOS: boolean;
3
+ export declare const IS_LINUX: boolean;
4
+ export declare const IS_UNIX: boolean;
@@ -0,0 +1,7 @@
1
+ // CONCATENATED MODULE: ./src/internal/runtime/os.ts
2
+ const IS_WINDOWS = process.platform === "win32";
3
+ const IS_MACOS = process.platform === "darwin";
4
+ const IS_LINUX = process.platform === "linux";
5
+ const IS_UNIX = IS_MACOS || IS_LINUX;
6
+
7
+ export { IS_LINUX, IS_MACOS, IS_UNIX, IS_WINDOWS };
@@ -0,0 +1,16 @@
1
+ import fs from "node:fs";
2
+ export declare const createTempDir: (clean?: boolean) => void;
3
+ export declare const createTempFilePath: (fileName: string) => string;
4
+ export type CreateTempFileOptions = {
5
+ fileName: string;
6
+ fileContent: string;
7
+ mode?: fs.Mode;
8
+ };
9
+ export declare const createTempFile: ({
10
+ fileName,
11
+ fileContent,
12
+ mode,
13
+ }: CreateTempFileOptions) => {
14
+ filePath: string;
15
+ cleanup: () => void;
16
+ };