@storm-software/unbuild 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1043 @@
1
+ import {
2
+ clean
3
+ } from "./chunk-IIVTCNH5.mjs";
4
+ import {
5
+ getDefaultBuildPlugins
6
+ } from "./chunk-T5NKX2EJ.mjs";
7
+ import {
8
+ loadConfig
9
+ } from "./chunk-AICX43E6.mjs";
10
+ import {
11
+ COLOR_KEYS,
12
+ LogLevel,
13
+ LogLevelLabel,
14
+ STORM_DEFAULT_DOCS,
15
+ STORM_DEFAULT_HOMEPAGE,
16
+ STORM_DEFAULT_LICENSING,
17
+ correctPaths,
18
+ findWorkspaceRoot,
19
+ formatLogMessage,
20
+ getDefaultConfig,
21
+ getLogLevel,
22
+ getLogLevelLabel,
23
+ getStopwatch,
24
+ isVerbose,
25
+ joinPaths,
26
+ writeDebug,
27
+ writeError,
28
+ writeFatal,
29
+ writeSuccess,
30
+ writeSystem,
31
+ writeTrace,
32
+ writeWarning
33
+ } from "./chunk-B5GGHMTB.mjs";
34
+ import {
35
+ __name
36
+ } from "./chunk-LPEX4YW6.mjs";
37
+
38
+ // src/build.ts
39
+ import { readCachedProjectGraph as readCachedProjectGraph3, writeJsonFile } from "@nx/devkit";
40
+ import { getHelperDependency, HelperDependency } from "@nx/js";
41
+ import { calculateProjectBuildableDependencies as calculateProjectBuildableDependencies2 } from "@nx/js/src/utils/buildable-libs-utils";
42
+
43
+ // ../build-tools/src/plugins/swc.ts
44
+ import { transform } from "@swc/core";
45
+
46
+ // ../build-tools/src/plugins/ts-resolve.ts
47
+ import fs from "node:fs";
48
+ import { builtinModules } from "node:module";
49
+ import path from "node:path";
50
+ import _resolve from "resolve";
51
+
52
+ // ../build-tools/src/plugins/type-definitions.ts
53
+ import { stripIndents } from "@nx/devkit";
54
+ import { relative } from "path";
55
+
56
+ // ../build-tools/src/utilities/copy-assets.ts
57
+ import { readCachedProjectGraph, readProjectsConfigurationFromProjectGraph } from "@nx/devkit";
58
+ import { copyAssets as copyAssetsBase } from "@nx/js";
59
+ import { glob } from "glob";
60
+ import { readFile as readFile2, writeFile } from "node:fs/promises";
61
+
62
+ // ../config-tools/src/config-file/get-config-file.ts
63
+ import { loadConfig as loadConfig2 } from "c12";
64
+ import defu from "defu";
65
+ var getConfigFileByName = /* @__PURE__ */ __name(async (fileName, filePath, options = {}) => {
66
+ const workspacePath = filePath || findWorkspaceRoot(filePath);
67
+ let config = await loadConfig2({
68
+ cwd: workspacePath,
69
+ packageJson: true,
70
+ name: fileName,
71
+ envName: fileName?.toUpperCase(),
72
+ jitiOptions: {
73
+ debug: false,
74
+ fsCache: process.env.STORM_SKIP_CACHE === "true" ? false : joinPaths(process.env.STORM_CACHE_DIR || "node_modules/.cache/storm", "jiti")
75
+ },
76
+ ...options
77
+ });
78
+ if (!config || Object.keys(config).length === 0) {
79
+ config = await loadConfig2({
80
+ cwd: workspacePath,
81
+ packageJson: true,
82
+ name: fileName,
83
+ envName: fileName?.toUpperCase(),
84
+ jitiOptions: {
85
+ debug: false,
86
+ fsCache: process.env.STORM_SKIP_CACHE === "true" ? false : joinPaths(process.env.STORM_CACHE_DIR || "node_modules/.cache/storm", "jiti")
87
+ },
88
+ configFile: fileName,
89
+ ...options
90
+ });
91
+ }
92
+ return config;
93
+ }, "getConfigFileByName");
94
+ var getConfigFile = /* @__PURE__ */ __name(async (filePath, additionalFileNames = []) => {
95
+ const workspacePath = filePath ? filePath : findWorkspaceRoot(filePath);
96
+ const result = await getConfigFileByName("storm", workspacePath);
97
+ let config = result.config;
98
+ const configFile = result.configFile;
99
+ if (config && configFile && Object.keys(config).length > 0) {
100
+ writeSystem(`Found Storm configuration file "${configFile.includes(`${workspacePath}/`) ? configFile.replace(`${workspacePath}/`, "") : configFile}" at "${workspacePath}"`, {
101
+ logLevel: "all"
102
+ });
103
+ }
104
+ if (additionalFileNames && additionalFileNames.length > 0) {
105
+ const results = await Promise.all(additionalFileNames.map((fileName) => getConfigFileByName(fileName, workspacePath)));
106
+ for (const result2 of results) {
107
+ if (result2?.config && result2?.configFile && Object.keys(result2.config).length > 0) {
108
+ writeSystem(`Found alternative configuration file "${result2.configFile.includes(`${workspacePath}/`) ? result2.configFile.replace(`${workspacePath}/`, "") : result2.configFile}" at "${workspacePath}"`, {
109
+ logLevel: "all"
110
+ });
111
+ config = defu(result2.config ?? {}, config ?? {});
112
+ }
113
+ }
114
+ }
115
+ if (!config) {
116
+ return void 0;
117
+ }
118
+ config.configFile = configFile;
119
+ return config;
120
+ }, "getConfigFile");
121
+
122
+ // ../config-tools/src/create-storm-config.ts
123
+ import defu2 from "defu";
124
+
125
+ // ../config-tools/src/env/get-env.ts
126
+ var getConfigEnv = /* @__PURE__ */ __name(() => {
127
+ const prefix = "STORM_";
128
+ let config = {
129
+ extends: process.env[`${prefix}EXTENDS`] || void 0,
130
+ name: process.env[`${prefix}NAME`] || void 0,
131
+ namespace: process.env[`${prefix}NAMESPACE`] || void 0,
132
+ owner: process.env[`${prefix}OWNER`] || void 0,
133
+ bot: {
134
+ name: process.env[`${prefix}BOT_NAME`] || void 0,
135
+ email: process.env[`${prefix}BOT_EMAIL`] || void 0
136
+ },
137
+ organization: process.env[`${prefix}ORGANIZATION`] || void 0,
138
+ packageManager: process.env[`${prefix}PACKAGE_MANAGER`] || void 0,
139
+ license: process.env[`${prefix}LICENSE`] || void 0,
140
+ homepage: process.env[`${prefix}HOMEPAGE`] || void 0,
141
+ docs: process.env[`${prefix}DOCS`] || void 0,
142
+ licensing: process.env[`${prefix}LICENSING`] || void 0,
143
+ timezone: process.env[`${prefix}TIMEZONE`] || process.env.TZ || void 0,
144
+ locale: process.env[`${prefix}LOCALE`] || process.env.LOCALE || void 0,
145
+ configFile: process.env[`${prefix}CONFIG_FILE`] ? correctPaths(process.env[`${prefix}CONFIG_FILE`]) : void 0,
146
+ workspaceRoot: process.env[`${prefix}WORKSPACE_ROOT`] ? correctPaths(process.env[`${prefix}WORKSPACE_ROOT`]) : void 0,
147
+ directories: {
148
+ cache: process.env[`${prefix}CACHE_DIR`] ? correctPaths(process.env[`${prefix}CACHE_DIR`]) : void 0,
149
+ data: process.env[`${prefix}DATA_DIR`] ? correctPaths(process.env[`${prefix}DATA_DIR`]) : void 0,
150
+ config: process.env[`${prefix}CONFIG_DIR`] ? correctPaths(process.env[`${prefix}CONFIG_DIR`]) : void 0,
151
+ temp: process.env[`${prefix}TEMP_DIR`] ? correctPaths(process.env[`${prefix}TEMP_DIR`]) : void 0,
152
+ log: process.env[`${prefix}LOG_DIR`] ? correctPaths(process.env[`${prefix}LOG_DIR`]) : void 0,
153
+ build: process.env[`${prefix}BUILD_DIR`] ? correctPaths(process.env[`${prefix}BUILD_DIR`]) : void 0
154
+ },
155
+ skipCache: process.env[`${prefix}SKIP_CACHE`] !== void 0 ? Boolean(process.env[`${prefix}SKIP_CACHE`]) : void 0,
156
+ env: (process.env[`${prefix}ENV`] ?? process.env.NODE_ENV ?? process.env.ENVIRONMENT) || void 0,
157
+ // ci:
158
+ // process.env[`${prefix}CI`] !== undefined
159
+ // ? Boolean(
160
+ // process.env[`${prefix}CI`] ??
161
+ // process.env.CI ??
162
+ // process.env.CONTINUOUS_INTEGRATION
163
+ // )
164
+ // : undefined,
165
+ repository: process.env[`${prefix}REPOSITORY`] || void 0,
166
+ branch: process.env[`${prefix}BRANCH`] || void 0,
167
+ preid: process.env[`${prefix}PRE_ID`] || void 0,
168
+ externalPackagePatterns: process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] ? JSON.parse(process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`]) : [],
169
+ registry: {
170
+ github: process.env[`${prefix}REGISTRY_GITHUB`] || void 0,
171
+ npm: process.env[`${prefix}REGISTRY_NPM`] || void 0,
172
+ cargo: process.env[`${prefix}REGISTRY_CARGO`] || void 0,
173
+ cyclone: process.env[`${prefix}REGISTRY_CYCLONE`] || void 0,
174
+ container: process.env[`${prefix}REGISTRY_CONTAINER`] || void 0
175
+ },
176
+ logLevel: process.env[`${prefix}LOG_LEVEL`] !== null && process.env[`${prefix}LOG_LEVEL`] !== void 0 ? process.env[`${prefix}LOG_LEVEL`] && Number.isSafeInteger(Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) ? getLogLevelLabel(Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) : process.env[`${prefix}LOG_LEVEL`] : void 0
177
+ };
178
+ const themeNames = Object.keys(process.env).filter((envKey) => envKey.startsWith(`${prefix}COLOR_`) && COLOR_KEYS.every((colorKey) => !envKey.startsWith(`${prefix}COLOR_LIGHT_${colorKey}`) && !envKey.startsWith(`${prefix}COLOR_DARK_${colorKey}`)));
179
+ config.colors = themeNames.length > 0 ? themeNames.reduce((ret, themeName) => {
180
+ ret[themeName] = getThemeColorConfigEnv(prefix, themeName);
181
+ return ret;
182
+ }, {}) : getThemeColorConfigEnv(prefix);
183
+ if (config.docs === STORM_DEFAULT_DOCS) {
184
+ if (config.homepage === STORM_DEFAULT_HOMEPAGE) {
185
+ config.docs = `${STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/docs`;
186
+ } else {
187
+ config.docs = `${config.homepage}/docs`;
188
+ }
189
+ }
190
+ if (config.licensing === STORM_DEFAULT_LICENSING) {
191
+ if (config.homepage === STORM_DEFAULT_HOMEPAGE) {
192
+ config.licensing = `${STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/licensing`;
193
+ } else {
194
+ config.licensing = `${config.homepage}/docs`;
195
+ }
196
+ }
197
+ const serializedConfig = process.env[`${prefix}CONFIG`];
198
+ if (serializedConfig) {
199
+ const parsed = JSON.parse(serializedConfig);
200
+ config = {
201
+ ...config,
202
+ ...parsed,
203
+ colors: {
204
+ ...config.colors,
205
+ ...parsed.colors
206
+ },
207
+ extensions: {
208
+ ...config.extensions,
209
+ ...parsed.extensions
210
+ }
211
+ };
212
+ }
213
+ return config;
214
+ }, "getConfigEnv");
215
+ var getThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, theme) => {
216
+ const themeName = `COLOR_${theme && theme !== "base" ? `${theme}_` : ""}`.toUpperCase();
217
+ return process.env[`${prefix}${themeName}LIGHT_BRAND`] || process.env[`${prefix}${themeName}DARK_BRAND`] ? getMultiThemeColorConfigEnv(prefix + themeName) : getSingleThemeColorConfigEnv(prefix + themeName);
218
+ }, "getThemeColorConfigEnv");
219
+ var getSingleThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
220
+ return {
221
+ dark: process.env[`${prefix}DARK`],
222
+ light: process.env[`${prefix}LIGHT`],
223
+ brand: process.env[`${prefix}BRAND`],
224
+ alternate: process.env[`${prefix}ALTERNATE`],
225
+ accent: process.env[`${prefix}ACCENT`],
226
+ link: process.env[`${prefix}LINK`],
227
+ help: process.env[`${prefix}HELP`],
228
+ success: process.env[`${prefix}SUCCESS`],
229
+ info: process.env[`${prefix}INFO`],
230
+ warning: process.env[`${prefix}WARNING`],
231
+ danger: process.env[`${prefix}DANGER`],
232
+ fatal: process.env[`${prefix}FATAL`],
233
+ positive: process.env[`${prefix}POSITIVE`],
234
+ negative: process.env[`${prefix}NEGATIVE`]
235
+ };
236
+ }, "getSingleThemeColorConfigEnv");
237
+ var getMultiThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
238
+ return {
239
+ light: getBaseThemeColorConfigEnv(`${prefix}_LIGHT_`),
240
+ dark: getBaseThemeColorConfigEnv(`${prefix}_DARK_`)
241
+ };
242
+ }, "getMultiThemeColorConfigEnv");
243
+ var getBaseThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
244
+ return {
245
+ foreground: process.env[`${prefix}FOREGROUND`],
246
+ background: process.env[`${prefix}BACKGROUND`],
247
+ brand: process.env[`${prefix}BRAND`],
248
+ alternate: process.env[`${prefix}ALTERNATE`],
249
+ accent: process.env[`${prefix}ACCENT`],
250
+ link: process.env[`${prefix}LINK`],
251
+ help: process.env[`${prefix}HELP`],
252
+ success: process.env[`${prefix}SUCCESS`],
253
+ info: process.env[`${prefix}INFO`],
254
+ warning: process.env[`${prefix}WARNING`],
255
+ danger: process.env[`${prefix}DANGER`],
256
+ fatal: process.env[`${prefix}FATAL`],
257
+ positive: process.env[`${prefix}POSITIVE`],
258
+ negative: process.env[`${prefix}NEGATIVE`]
259
+ };
260
+ }, "getBaseThemeColorConfigEnv");
261
+
262
+ // ../config-tools/src/env/set-env.ts
263
+ var setExtensionEnv = /* @__PURE__ */ __name((extensionName, extension) => {
264
+ for (const key of Object.keys(extension ?? {})) {
265
+ if (extension[key]) {
266
+ const result = key?.replace(/([A-Z])+/g, (input) => input ? input[0]?.toUpperCase() + input.slice(1) : "").split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
267
+ let extensionKey;
268
+ if (result.length === 0) {
269
+ return;
270
+ }
271
+ if (result.length === 1) {
272
+ extensionKey = result[0]?.toUpperCase() ?? "";
273
+ } else {
274
+ extensionKey = result.reduce((ret, part) => {
275
+ return `${ret}_${part.toLowerCase()}`;
276
+ });
277
+ }
278
+ process.env[`STORM_EXTENSION_${extensionName.toUpperCase()}_${extensionKey.toUpperCase()}`] = extension[key];
279
+ }
280
+ }
281
+ }, "setExtensionEnv");
282
+ var setConfigEnv = /* @__PURE__ */ __name((config) => {
283
+ const prefix = "STORM_";
284
+ if (config.extends) {
285
+ process.env[`${prefix}EXTENDS`] = config.extends;
286
+ }
287
+ if (config.name) {
288
+ process.env[`${prefix}NAME`] = config.name;
289
+ }
290
+ if (config.namespace) {
291
+ process.env[`${prefix}NAMESPACE`] = config.namespace;
292
+ }
293
+ if (config.owner) {
294
+ process.env[`${prefix}OWNER`] = config.owner;
295
+ }
296
+ if (config.bot) {
297
+ process.env[`${prefix}BOT_NAME`] = config.bot.name;
298
+ process.env[`${prefix}BOT_EMAIL`] = config.bot.email;
299
+ }
300
+ if (config.organization) {
301
+ process.env[`${prefix}ORGANIZATION`] = config.organization;
302
+ }
303
+ if (config.packageManager) {
304
+ process.env[`${prefix}PACKAGE_MANAGER`] = config.packageManager;
305
+ }
306
+ if (config.license) {
307
+ process.env[`${prefix}LICENSE`] = config.license;
308
+ }
309
+ if (config.homepage) {
310
+ process.env[`${prefix}HOMEPAGE`] = config.homepage;
311
+ }
312
+ if (config.docs) {
313
+ process.env[`${prefix}DOCS`] = config.docs;
314
+ }
315
+ if (config.licensing) {
316
+ process.env[`${prefix}LICENSING`] = config.licensing;
317
+ }
318
+ if (config.timezone) {
319
+ process.env[`${prefix}TIMEZONE`] = config.timezone;
320
+ process.env.TZ = config.timezone;
321
+ process.env.DEFAULT_TIMEZONE = config.timezone;
322
+ }
323
+ if (config.locale) {
324
+ process.env[`${prefix}LOCALE`] = config.locale;
325
+ process.env.LOCALE = config.locale;
326
+ process.env.DEFAULT_LOCALE = config.locale;
327
+ process.env.LANG = config.locale ? `${config.locale.replaceAll("-", "_")}.UTF-8` : "en_US.UTF-8";
328
+ }
329
+ if (config.configFile) {
330
+ process.env[`${prefix}CONFIG_FILE`] = correctPaths(config.configFile);
331
+ }
332
+ if (config.workspaceRoot) {
333
+ process.env[`${prefix}WORKSPACE_ROOT`] = correctPaths(config.workspaceRoot);
334
+ process.env.NX_WORKSPACE_ROOT = correctPaths(config.workspaceRoot);
335
+ process.env.NX_WORKSPACE_ROOT_PATH = correctPaths(config.workspaceRoot);
336
+ }
337
+ if (config.directories) {
338
+ if (!config.skipCache && config.directories.cache) {
339
+ process.env[`${prefix}CACHE_DIR`] = correctPaths(config.directories.cache);
340
+ }
341
+ if (config.directories.data) {
342
+ process.env[`${prefix}DATA_DIR`] = correctPaths(config.directories.data);
343
+ }
344
+ if (config.directories.config) {
345
+ process.env[`${prefix}CONFIG_DIR`] = correctPaths(config.directories.config);
346
+ }
347
+ if (config.directories.temp) {
348
+ process.env[`${prefix}TEMP_DIR`] = correctPaths(config.directories.temp);
349
+ }
350
+ if (config.directories.log) {
351
+ process.env[`${prefix}LOG_DIR`] = correctPaths(config.directories.log);
352
+ }
353
+ if (config.directories.build) {
354
+ process.env[`${prefix}BUILD_DIR`] = correctPaths(config.directories.build);
355
+ }
356
+ }
357
+ if (config.skipCache !== void 0) {
358
+ process.env[`${prefix}SKIP_CACHE`] = String(config.skipCache);
359
+ if (config.skipCache) {
360
+ process.env.NX_SKIP_NX_CACHE ??= String(config.skipCache);
361
+ process.env.NX_CACHE_PROJECT_GRAPH ??= String(config.skipCache);
362
+ }
363
+ }
364
+ if (config.env) {
365
+ process.env[`${prefix}ENV`] = config.env;
366
+ process.env.NODE_ENV = config.env;
367
+ process.env.ENVIRONMENT = config.env;
368
+ }
369
+ if (config.colors?.base?.light || config.colors?.base?.dark) {
370
+ for (const key of Object.keys(config.colors)) {
371
+ setThemeColorConfigEnv(`${prefix}COLOR_${key}_`, config.colors[key]);
372
+ }
373
+ } else {
374
+ setThemeColorConfigEnv(`${prefix}COLOR_`, config.colors);
375
+ }
376
+ if (config.repository) {
377
+ process.env[`${prefix}REPOSITORY`] = config.repository;
378
+ }
379
+ if (config.branch) {
380
+ process.env[`${prefix}BRANCH`] = config.branch;
381
+ }
382
+ if (config.preid) {
383
+ process.env[`${prefix}PRE_ID`] = String(config.preid);
384
+ }
385
+ if (config.externalPackagePatterns) {
386
+ process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] = JSON.stringify(config.externalPackagePatterns);
387
+ }
388
+ if (config.registry) {
389
+ if (config.registry.github) {
390
+ process.env[`${prefix}REGISTRY_GITHUB`] = String(config.registry.github);
391
+ }
392
+ if (config.registry.npm) {
393
+ process.env[`${prefix}REGISTRY_NPM`] = String(config.registry.npm);
394
+ }
395
+ if (config.registry.cargo) {
396
+ process.env[`${prefix}REGISTRY_CARGO`] = String(config.registry.cargo);
397
+ }
398
+ if (config.registry.cyclone) {
399
+ process.env[`${prefix}REGISTRY_CYCLONE`] = String(config.registry.cyclone);
400
+ }
401
+ if (config.registry.container) {
402
+ process.env[`${prefix}REGISTRY_CONTAINER`] = String(config.registry.cyclone);
403
+ }
404
+ }
405
+ if (config.logLevel) {
406
+ process.env[`${prefix}LOG_LEVEL`] = String(config.logLevel);
407
+ process.env.LOG_LEVEL = String(config.logLevel);
408
+ process.env.NX_VERBOSE_LOGGING = String(getLogLevel(config.logLevel) >= LogLevel.DEBUG ? true : false);
409
+ process.env.RUST_BACKTRACE = getLogLevel(config.logLevel) >= LogLevel.DEBUG ? "full" : "none";
410
+ }
411
+ process.env[`${prefix}CONFIG`] = JSON.stringify(config);
412
+ for (const key of Object.keys(config.extensions ?? {})) {
413
+ config.extensions[key] && Object.keys(config.extensions[key]) && setExtensionEnv(key, config.extensions[key]);
414
+ }
415
+ }, "setConfigEnv");
416
+ var setThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
417
+ return config?.light?.brand || config?.dark?.brand ? setMultiThemeColorConfigEnv(prefix, config) : setSingleThemeColorConfigEnv(prefix, config);
418
+ }, "setThemeColorConfigEnv");
419
+ var setSingleThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
420
+ if (config.dark) {
421
+ process.env[`${prefix}DARK`] = config.dark;
422
+ }
423
+ if (config.light) {
424
+ process.env[`${prefix}LIGHT`] = config.light;
425
+ }
426
+ if (config.brand) {
427
+ process.env[`${prefix}BRAND`] = config.brand;
428
+ }
429
+ if (config.alternate) {
430
+ process.env[`${prefix}ALTERNATE`] = config.alternate;
431
+ }
432
+ if (config.accent) {
433
+ process.env[`${prefix}ACCENT`] = config.accent;
434
+ }
435
+ if (config.link) {
436
+ process.env[`${prefix}LINK`] = config.link;
437
+ }
438
+ if (config.help) {
439
+ process.env[`${prefix}HELP`] = config.help;
440
+ }
441
+ if (config.success) {
442
+ process.env[`${prefix}SUCCESS`] = config.success;
443
+ }
444
+ if (config.info) {
445
+ process.env[`${prefix}INFO`] = config.info;
446
+ }
447
+ if (config.warning) {
448
+ process.env[`${prefix}WARNING`] = config.warning;
449
+ }
450
+ if (config.danger) {
451
+ process.env[`${prefix}DANGER`] = config.danger;
452
+ }
453
+ if (config.fatal) {
454
+ process.env[`${prefix}FATAL`] = config.fatal;
455
+ }
456
+ if (config.positive) {
457
+ process.env[`${prefix}POSITIVE`] = config.positive;
458
+ }
459
+ if (config.negative) {
460
+ process.env[`${prefix}NEGATIVE`] = config.negative;
461
+ }
462
+ }, "setSingleThemeColorConfigEnv");
463
+ var setMultiThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
464
+ return {
465
+ light: setBaseThemeColorConfigEnv(`${prefix}LIGHT_`, config.light),
466
+ dark: setBaseThemeColorConfigEnv(`${prefix}DARK_`, config.dark)
467
+ };
468
+ }, "setMultiThemeColorConfigEnv");
469
+ var setBaseThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
470
+ if (config.foreground) {
471
+ process.env[`${prefix}FOREGROUND`] = config.foreground;
472
+ }
473
+ if (config.background) {
474
+ process.env[`${prefix}BACKGROUND`] = config.background;
475
+ }
476
+ if (config.brand) {
477
+ process.env[`${prefix}BRAND`] = config.brand;
478
+ }
479
+ if (config.alternate) {
480
+ process.env[`${prefix}ALTERNATE`] = config.alternate;
481
+ }
482
+ if (config.accent) {
483
+ process.env[`${prefix}ACCENT`] = config.accent;
484
+ }
485
+ if (config.link) {
486
+ process.env[`${prefix}LINK`] = config.link;
487
+ }
488
+ if (config.help) {
489
+ process.env[`${prefix}HELP`] = config.help;
490
+ }
491
+ if (config.success) {
492
+ process.env[`${prefix}SUCCESS`] = config.success;
493
+ }
494
+ if (config.info) {
495
+ process.env[`${prefix}INFO`] = config.info;
496
+ }
497
+ if (config.warning) {
498
+ process.env[`${prefix}WARNING`] = config.warning;
499
+ }
500
+ if (config.danger) {
501
+ process.env[`${prefix}DANGER`] = config.danger;
502
+ }
503
+ if (config.fatal) {
504
+ process.env[`${prefix}FATAL`] = config.fatal;
505
+ }
506
+ if (config.positive) {
507
+ process.env[`${prefix}POSITIVE`] = config.positive;
508
+ }
509
+ if (config.negative) {
510
+ process.env[`${prefix}NEGATIVE`] = config.negative;
511
+ }
512
+ }, "setBaseThemeColorConfigEnv");
513
+
514
+ // ../config-tools/src/create-storm-config.ts
515
+ var _static_cache = void 0;
516
+ var loadStormConfig = /* @__PURE__ */ __name(async (workspaceRoot) => {
517
+ let config = {};
518
+ if (_static_cache?.data && _static_cache?.timestamp && _static_cache.timestamp >= Date.now() + 3e4) {
519
+ writeTrace(`Configuration cache hit - ${_static_cache.timestamp}`, _static_cache.data);
520
+ return _static_cache.data;
521
+ }
522
+ let _workspaceRoot = workspaceRoot;
523
+ if (!_workspaceRoot) {
524
+ _workspaceRoot = findWorkspaceRoot();
525
+ }
526
+ const configFile = await getConfigFile(_workspaceRoot);
527
+ if (!configFile) {
528
+ writeWarning("No Storm config file found in the current workspace. Please ensure this is the expected behavior - you can add a `storm.json` file to the root of your workspace if it is not.\n", {
529
+ logLevel: "all"
530
+ });
531
+ }
532
+ config = defu2(getConfigEnv(), configFile, getDefaultConfig(_workspaceRoot));
533
+ setConfigEnv(config);
534
+ writeTrace(`\u2699\uFE0F Using Storm configuration:
535
+ ${formatLogMessage(config)}`, config);
536
+ return config;
537
+ }, "loadStormConfig");
538
+
539
+ // ../build-tools/src/utilities/read-nx-config.ts
540
+ import { existsSync } from "node:fs";
541
+ import { readFile } from "node:fs/promises";
542
+ var readNxConfig = /* @__PURE__ */ __name(async (workspaceRoot) => {
543
+ let rootDir = workspaceRoot;
544
+ if (!rootDir) {
545
+ const config = await loadStormConfig();
546
+ rootDir = config.workspaceRoot;
547
+ }
548
+ const nxJsonPath = joinPaths(rootDir, "nx.json");
549
+ if (!existsSync(nxJsonPath)) {
550
+ throw new Error("Cannot find project.json configuration");
551
+ }
552
+ const configContent = await readFile(nxJsonPath, "utf8");
553
+ return JSON.parse(configContent);
554
+ }, "readNxConfig");
555
+
556
+ // ../build-tools/src/utilities/copy-assets.ts
557
+ var copyAssets = /* @__PURE__ */ __name(async (config, assets, outputPath, projectRoot, projectName, sourceRoot, generatePackageJson2 = true, includeSrc = false, banner, footer) => {
558
+ const pendingAssets = Array.from(assets ?? []);
559
+ if (!pendingAssets?.some((asset) => asset?.glob === "*.md")) {
560
+ pendingAssets.push({
561
+ input: projectRoot,
562
+ glob: "*.md",
563
+ output: "/"
564
+ });
565
+ }
566
+ if (generatePackageJson2 === false) {
567
+ pendingAssets.push({
568
+ input: sourceRoot,
569
+ glob: "package.json",
570
+ output: "."
571
+ });
572
+ }
573
+ if (!pendingAssets?.some((asset) => asset?.glob === "LICENSE")) {
574
+ pendingAssets.push({
575
+ input: "",
576
+ glob: "LICENSE",
577
+ output: "."
578
+ });
579
+ }
580
+ if (includeSrc === true) {
581
+ pendingAssets.push({
582
+ input: sourceRoot,
583
+ glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
584
+ output: "src/"
585
+ });
586
+ }
587
+ const nxJson = readNxConfig(config.workspaceRoot);
588
+ const projectGraph = readCachedProjectGraph();
589
+ const projectsConfigurations = readProjectsConfigurationFromProjectGraph(projectGraph);
590
+ if (!projectsConfigurations?.projects?.[projectName]) {
591
+ throw new Error("The Build process failed because the project does not have a valid configuration in the project.json file. Check if the file exists in the root of the project.");
592
+ }
593
+ const buildTarget = projectsConfigurations.projects[projectName].targets?.build;
594
+ if (!buildTarget) {
595
+ throw new Error(`The Build process failed because the project does not have a valid build target in the project.json file. Check if the file exists in the root of the project at ${joinPaths(projectRoot, "project.json")}`);
596
+ }
597
+ const result = await copyAssetsBase({
598
+ assets,
599
+ watch: false,
600
+ outputPath
601
+ }, {
602
+ root: config.workspaceRoot,
603
+ targetName: "build",
604
+ target: buildTarget,
605
+ projectName,
606
+ projectGraph,
607
+ projectsConfigurations,
608
+ nxJsonConfiguration: nxJson,
609
+ cwd: config.workspaceRoot,
610
+ isVerbose: isVerbose(config.logLevel)
611
+ });
612
+ if (!result.success) {
613
+ throw new Error("The Build process failed trying to copy assets");
614
+ }
615
+ if (includeSrc === true) {
616
+ writeDebug(`\u{1F4DD} Adding banner and writing source files: ${joinPaths(outputPath, "src")}`, config);
617
+ const files = await glob([
618
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.ts"),
619
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.tsx"),
620
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.js"),
621
+ joinPaths(config.workspaceRoot, outputPath, "src/**/*.jsx")
622
+ ]);
623
+ await Promise.allSettled(files.map(async (file) => writeFile(file, `${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
624
+
625
+ ${await readFile2(file, "utf8")}
626
+
627
+ ${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`)));
628
+ }
629
+ }, "copyAssets");
630
+
631
+ // ../build-tools/src/utilities/generate-package-json.ts
632
+ import { calculateProjectBuildableDependencies } from "@nx/js/src/utils/buildable-libs-utils";
633
+ import { Glob } from "glob";
634
+ import { existsSync as existsSync2 } from "node:fs";
635
+ import { readFile as readFile3 } from "node:fs/promises";
636
+ import { readCachedProjectGraph as readCachedProjectGraph2 } from "nx/src/project-graph/project-graph";
637
+ var addPackageDependencies = /* @__PURE__ */ __name(async (workspaceRoot, projectRoot, projectName, packageJson) => {
638
+ const projectDependencies = calculateProjectBuildableDependencies(void 0, readCachedProjectGraph2(), workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
639
+ const localPackages = [];
640
+ for (const project of projectDependencies.dependencies.filter((dep) => dep.node.type === "lib" && dep.node.data.root !== projectRoot && dep.node.data.root !== workspaceRoot)) {
641
+ const projectNode = project.node;
642
+ if (projectNode.data.root) {
643
+ const projectPackageJsonPath = joinPaths(workspaceRoot, projectNode.data.root, "package.json");
644
+ if (existsSync2(projectPackageJsonPath)) {
645
+ const projectPackageJsonContent = await readFile3(projectPackageJsonPath, "utf8");
646
+ const projectPackageJson = JSON.parse(projectPackageJsonContent);
647
+ if (projectPackageJson.private !== false) {
648
+ localPackages.push(projectPackageJson);
649
+ }
650
+ }
651
+ }
652
+ }
653
+ if (localPackages.length > 0) {
654
+ writeTrace(`\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`);
655
+ packageJson.peerDependencies = localPackages.reduce((ret, localPackage) => {
656
+ if (!ret[localPackage.name]) {
657
+ ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
658
+ }
659
+ return ret;
660
+ }, packageJson.peerDependencies ?? {});
661
+ packageJson.peerDependenciesMeta = localPackages.reduce((ret, localPackage) => {
662
+ if (!ret[localPackage.name]) {
663
+ ret[localPackage.name] = {
664
+ optional: false
665
+ };
666
+ }
667
+ return ret;
668
+ }, packageJson.peerDependenciesMeta ?? {});
669
+ packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
670
+ if (!ret[localPackage.name]) {
671
+ ret[localPackage.name] = localPackage.version || "0.0.1";
672
+ }
673
+ return ret;
674
+ }, packageJson.peerDependencies ?? {});
675
+ } else {
676
+ writeTrace("\u{1F4E6} No local packages dependencies to add to package.json");
677
+ }
678
+ return packageJson;
679
+ }, "addPackageDependencies");
680
+ var addWorkspacePackageJsonFields = /* @__PURE__ */ __name(async (config, projectRoot, sourceRoot, projectName, includeSrc = false, packageJson) => {
681
+ const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : findWorkspaceRoot();
682
+ const workspacePackageJsonContent = await readFile3(joinPaths(workspaceRoot, "package.json"), "utf8");
683
+ const workspacePackageJson = JSON.parse(workspacePackageJsonContent);
684
+ packageJson.type ??= "module";
685
+ packageJson.sideEffects ??= false;
686
+ if (includeSrc === true) {
687
+ let distSrc = sourceRoot.replace(projectRoot, "");
688
+ if (distSrc.startsWith("/")) {
689
+ distSrc = distSrc.substring(1);
690
+ }
691
+ packageJson.source ??= `${joinPaths(distSrc, "index.ts").replaceAll("\\", "/")}`;
692
+ }
693
+ packageJson.files ??= [
694
+ "dist/**/*"
695
+ ];
696
+ if (includeSrc === true && !packageJson.files.includes("src")) {
697
+ packageJson.files.push("src/**/*");
698
+ }
699
+ packageJson.publishConfig ??= {
700
+ access: "public"
701
+ };
702
+ packageJson.description ??= workspacePackageJson.description;
703
+ packageJson.homepage ??= workspacePackageJson.homepage;
704
+ packageJson.bugs ??= workspacePackageJson.bugs;
705
+ packageJson.license ??= workspacePackageJson.license;
706
+ packageJson.keywords ??= workspacePackageJson.keywords;
707
+ packageJson.funding ??= workspacePackageJson.funding;
708
+ packageJson.author ??= workspacePackageJson.author;
709
+ packageJson.maintainers ??= workspacePackageJson.maintainers;
710
+ if (!packageJson.maintainers && packageJson.author) {
711
+ packageJson.maintainers = [
712
+ packageJson.author
713
+ ];
714
+ }
715
+ packageJson.contributors ??= workspacePackageJson.contributors;
716
+ if (!packageJson.contributors && packageJson.author) {
717
+ packageJson.contributors = [
718
+ packageJson.author
719
+ ];
720
+ }
721
+ packageJson.repository ??= workspacePackageJson.repository;
722
+ packageJson.repository.directory ??= projectRoot ? projectRoot : joinPaths("packages", projectName);
723
+ return packageJson;
724
+ }, "addWorkspacePackageJsonFields");
725
+ var addPackageJsonExport = /* @__PURE__ */ __name((file, type = "module", sourceRoot) => {
726
+ let entry = file.replaceAll("\\", "/");
727
+ if (sourceRoot) {
728
+ entry = entry.replace(sourceRoot, "");
729
+ }
730
+ return {
731
+ "import": {
732
+ "types": `./dist/${entry}.d.${type === "module" ? "ts" : "mts"}`,
733
+ "default": `./dist/${entry}.${type === "module" ? "js" : "mjs"}`
734
+ },
735
+ "require": {
736
+ "types": `./dist/${entry}.d.${type === "commonjs" ? "ts" : "cts"}`,
737
+ "default": `./dist/${entry}.${type === "commonjs" ? "js" : "cjs"}`
738
+ },
739
+ "default": {
740
+ "types": `./dist/${entry}.d.ts`,
741
+ "default": `./dist/${entry}.js`
742
+ }
743
+ };
744
+ }, "addPackageJsonExport");
745
+ var addPackageJsonExports = /* @__PURE__ */ __name(async (sourceRoot, packageJson) => {
746
+ packageJson.exports ??= {};
747
+ const files = await new Glob("**/*.{ts,tsx}", {
748
+ absolute: false,
749
+ cwd: sourceRoot,
750
+ root: sourceRoot
751
+ }).walk();
752
+ files.forEach((file) => {
753
+ addPackageJsonExport(file, packageJson.type, sourceRoot);
754
+ const split = file.split(".");
755
+ split.pop();
756
+ const entry = split.join(".").replaceAll("\\", "/");
757
+ packageJson.exports[`./${entry}`] ??= addPackageJsonExport(entry, packageJson.type, sourceRoot);
758
+ });
759
+ packageJson.main = packageJson.type === "commonjs" ? "./dist/index.js" : "./dist/index.cjs";
760
+ packageJson.module = packageJson.type === "module" ? "./dist/index.js" : "./dist/index.mjs";
761
+ packageJson.types = "./dist/index.d.ts";
762
+ packageJson.exports ??= {};
763
+ packageJson.exports = Object.keys(packageJson.exports).reduce((ret, key) => {
764
+ if (key.endsWith("/index") && !ret[key.replace("/index", "")]) {
765
+ ret[key.replace("/index", "")] = packageJson.exports[key];
766
+ }
767
+ return ret;
768
+ }, packageJson.exports);
769
+ packageJson.exports["./package.json"] ??= "./package.json";
770
+ packageJson.exports["."] = packageJson.exports["."] ?? addPackageJsonExport("index", packageJson.type, sourceRoot);
771
+ return packageJson;
772
+ }, "addPackageJsonExports");
773
+
774
+ // ../build-tools/src/utilities/get-entry-points.ts
775
+ import { glob as glob2 } from "glob";
776
+
777
+ // ../build-tools/src/utilities/task-graph.ts
778
+ import { createTaskGraph, mapTargetDefaultsToDependencies } from "nx/src/tasks-runner/create-task-graph";
779
+
780
+ // src/build.ts
781
+ import defu3 from "defu";
782
+ import { createJiti } from "jiti";
783
+ import { existsSync as existsSync3 } from "node:fs";
784
+ import { readFile as readFile4 } from "node:fs/promises";
785
+ import { relative as relative2 } from "node:path";
786
+ import { findWorkspaceRoot as findWorkspaceRoot2 } from "nx/src/utils/find-workspace-root";
787
+ async function resolveOptions(options) {
788
+ const projectRoot = options.projectRoot;
789
+ if (!projectRoot) {
790
+ throw new Error("Cannot find project root");
791
+ }
792
+ const outputPath = options.outputPath || joinPaths("dist", projectRoot);
793
+ const workspaceRoot = findWorkspaceRoot2(projectRoot);
794
+ if (!workspaceRoot) {
795
+ throw new Error("Cannot find workspace root");
796
+ }
797
+ const config = await loadStormConfig(workspaceRoot.dir);
798
+ writeDebug(" \u2699\uFE0F Resolving build options", config);
799
+ const stopwatch = getStopwatch("Build options resolution");
800
+ if (options.configPath) {
801
+ const configFile = await loadConfig(options.configPath);
802
+ if (configFile) {
803
+ options = defu3(options, configFile);
804
+ }
805
+ }
806
+ const projectGraph = readCachedProjectGraph3();
807
+ const projectJsonPath = joinPaths(config.workspaceRoot, projectRoot, "project.json");
808
+ if (!existsSync3(projectJsonPath)) {
809
+ throw new Error("Cannot find project.json configuration");
810
+ }
811
+ const projectJsonContent = await readFile4(projectJsonPath, "utf8");
812
+ const projectJson = JSON.parse(projectJsonContent);
813
+ const projectName = projectJson.name;
814
+ const packageJsonPath = joinPaths(workspaceRoot.dir, projectRoot, "package.json");
815
+ if (!existsSync3(packageJsonPath)) {
816
+ throw new Error("Cannot find package.json configuration");
817
+ }
818
+ const packageJsonContent = await readFile4(packageJsonPath, "utf8");
819
+ const packageJson = JSON.parse(packageJsonContent);
820
+ let tsconfig = options.tsconfig;
821
+ if (!tsconfig) {
822
+ tsconfig = joinPaths(workspaceRoot.dir, projectRoot, "tsconfig.json");
823
+ }
824
+ if (!existsSync3(tsconfig)) {
825
+ throw new Error("Cannot find tsconfig.json configuration");
826
+ }
827
+ let sourceRoot = projectJson.sourceRoot;
828
+ if (!sourceRoot) {
829
+ sourceRoot = joinPaths(projectRoot, "src");
830
+ }
831
+ if (!existsSync3(sourceRoot)) {
832
+ throw new Error("Cannot find sourceRoot directory");
833
+ }
834
+ const result = calculateProjectBuildableDependencies2(void 0, projectGraph, workspaceRoot.dir, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
835
+ let dependencies = result.dependencies;
836
+ const tsLibDependency = getHelperDependency(HelperDependency.tsc, tsconfig, dependencies, projectGraph, true);
837
+ if (tsLibDependency) {
838
+ dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name);
839
+ dependencies.push(tsLibDependency);
840
+ }
841
+ const jiti = createJiti(config.workspaceRoot, {
842
+ cache: true,
843
+ fsCache: config.skipCache ? false : joinPaths(config.directories.cache || "node_modules/.cache/storm", "jiti"),
844
+ interopDefault: true
845
+ });
846
+ const resolvedOptions = {
847
+ name: projectName,
848
+ config,
849
+ projectRoot,
850
+ sourceRoot,
851
+ projectName,
852
+ tsconfig,
853
+ jiti,
854
+ clean: false,
855
+ entries: [
856
+ {
857
+ builder: "mkdist",
858
+ input: `.${sourceRoot.replace(projectRoot, "")}`,
859
+ outDir: joinPaths(relative2(joinPaths(config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
860
+ declaration: options.emitTypes !== false,
861
+ format: "esm"
862
+ },
863
+ {
864
+ builder: "mkdist",
865
+ input: `.${sourceRoot.replace(projectRoot, "")}`,
866
+ outDir: joinPaths(relative2(joinPaths(config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
867
+ declaration: options.emitTypes !== false,
868
+ format: "cjs",
869
+ ext: "cjs"
870
+ }
871
+ ],
872
+ declaration: options.emitTypes !== false ? "compatible" : false,
873
+ failOnWarn: false,
874
+ sourcemap: options.sourcemap ?? !!options.debug,
875
+ outDir: outputPath,
876
+ parallel: true,
877
+ stub: false,
878
+ stubOptions: {
879
+ jiti: {}
880
+ },
881
+ externals: options.external ?? [],
882
+ dependencies: [],
883
+ peerDependencies: [],
884
+ devDependencies: [],
885
+ hooks: {},
886
+ alias: {},
887
+ replace: {},
888
+ rollup: {
889
+ replace: {},
890
+ alias: {},
891
+ json: {},
892
+ commonjs: {
893
+ sourceMap: options.sourcemap ?? true
894
+ },
895
+ emitCJS: true,
896
+ cjsBridge: true,
897
+ dts: {
898
+ respectExternal: true,
899
+ tsconfig
900
+ },
901
+ output: {
902
+ banner: options.banner || `
903
+ // \u26A1 Built by Storm Software
904
+ `,
905
+ footer: options.footer
906
+ },
907
+ resolve: {
908
+ preferBuiltins: true,
909
+ extensions: [
910
+ ".cjs",
911
+ ".mjs",
912
+ ".js",
913
+ ".jsx",
914
+ ".ts",
915
+ ".tsx",
916
+ ".json"
917
+ ]
918
+ },
919
+ esbuild: {
920
+ minify: options.minify !== false,
921
+ splitting: options.splitting !== false,
922
+ treeShaking: options.treeShaking !== false,
923
+ color: true,
924
+ logLevel: config.logLevel === LogLevelLabel.FATAL ? LogLevelLabel.ERROR : isVerbose() ? "verbose" : config.logLevel
925
+ }
926
+ }
927
+ };
928
+ dependencies = dependencies.filter((dep) => dep.node.type === "npm" || dep.node.type === "lib" || dep.node.type === "app");
929
+ if (dependencies.length > 0) {
930
+ resolvedOptions.dependencies = dependencies.map((dep) => dep.name);
931
+ }
932
+ if (packageJson.devDependencies) {
933
+ resolvedOptions.devDependencies = Object.keys(packageJson.devDependencies);
934
+ }
935
+ if (packageJson.peerDependencies) {
936
+ resolvedOptions.peerDependencies = Object.keys(packageJson.peerDependencies);
937
+ }
938
+ if (options.rollup) {
939
+ let rollup = {};
940
+ if (typeof options.rollup === "string") {
941
+ const rollupFile = await loadConfig(options.rollup);
942
+ if (rollupFile) {
943
+ rollup = rollupFile;
944
+ }
945
+ } else {
946
+ rollup = options.rollup;
947
+ }
948
+ resolvedOptions.rollup = defu3(resolvedOptions.rollup ?? {}, rollup);
949
+ }
950
+ resolvedOptions.hooks = {
951
+ "rollup:options": /* @__PURE__ */ __name(async (ctx, opts) => {
952
+ opts.plugins = options.plugins ?? await getDefaultBuildPlugins(options, resolvedOptions);
953
+ }, "rollup:options")
954
+ };
955
+ stopwatch();
956
+ return resolvedOptions;
957
+ }
958
+ __name(resolveOptions, "resolveOptions");
959
+ async function generatePackageJson(options) {
960
+ if (options.generatePackageJson !== false && existsSync3(joinPaths(options.projectRoot, "package.json"))) {
961
+ writeDebug(" \u270D\uFE0F Writing package.json file", options.config);
962
+ const stopwatch = getStopwatch("Write package.json file");
963
+ const packageJsonPath = joinPaths(options.projectRoot, "project.json");
964
+ if (!existsSync3(packageJsonPath)) {
965
+ throw new Error("Cannot find package.json configuration");
966
+ }
967
+ let packageJsonContent = await readFile4(joinPaths(options.config.workspaceRoot, options.projectRoot, "package.json"), "utf8");
968
+ if (!packageJsonContent) {
969
+ throw new Error("Cannot find package.json configuration file");
970
+ }
971
+ let packageJson = JSON.parse(packageJsonContent);
972
+ packageJson = await addPackageDependencies(options.config.workspaceRoot, options.projectRoot, options.projectName, packageJson);
973
+ packageJson = await addWorkspacePackageJsonFields(options.config, options.projectRoot, options.sourceRoot, options.projectName, false, packageJson);
974
+ await writeJsonFile(joinPaths(options.outDir, "package.json"), await addPackageJsonExports(options.sourceRoot, packageJson));
975
+ stopwatch();
976
+ }
977
+ return options;
978
+ }
979
+ __name(generatePackageJson, "generatePackageJson");
980
+ async function resolveUnbuild(options) {
981
+ writeTrace(`Resolving Unbuild package with Jiti`, options.config);
982
+ try {
983
+ return options.jiti.import("unbuild");
984
+ } catch (error) {
985
+ writeError(" \u274C An error occurred while resolving the Unbuild package", options.config);
986
+ throw new Error("An error occurred while resolving the Unbuild package", {
987
+ cause: error
988
+ });
989
+ }
990
+ }
991
+ __name(resolveUnbuild, "resolveUnbuild");
992
+ async function executeUnbuild(options) {
993
+ writeDebug(` \u{1F680} Running ${options.name} (${options.projectRoot}) build`, options.config);
994
+ const stopwatch = getStopwatch(`${options.name} (${options.projectRoot}) build`);
995
+ try {
996
+ const unbuild = await resolveUnbuild(options);
997
+ await unbuild.build(options.projectRoot, false, {
998
+ ...options,
999
+ rootDir: options.projectRoot
1000
+ });
1001
+ } finally {
1002
+ stopwatch();
1003
+ }
1004
+ return options;
1005
+ }
1006
+ __name(executeUnbuild, "executeUnbuild");
1007
+ async function copyBuildAssets(options) {
1008
+ writeDebug(` \u{1F4CB} Copying asset files to output directory: ${options.outDir}`, options.config);
1009
+ const stopwatch = getStopwatch(`${options.name} asset copy`);
1010
+ await copyAssets(options.config, options.assets ?? [], options.outDir, options.projectRoot, options.projectName, options.sourceRoot, options.generatePackageJson, options.includeSrc);
1011
+ stopwatch();
1012
+ return options;
1013
+ }
1014
+ __name(copyBuildAssets, "copyBuildAssets");
1015
+ async function cleanOutputPath(options) {
1016
+ if (options.clean !== false && options.outDir) {
1017
+ await clean(options.name, options.outDir, options.config);
1018
+ }
1019
+ return options;
1020
+ }
1021
+ __name(cleanOutputPath, "cleanOutputPath");
1022
+ async function build(options) {
1023
+ writeDebug(` \u26A1 Executing Storm Unbuild pipeline`);
1024
+ const stopwatch = getStopwatch("Unbuild pipeline");
1025
+ try {
1026
+ const resolvedOptions = await resolveOptions(options);
1027
+ await cleanOutputPath(resolvedOptions);
1028
+ await generatePackageJson(resolvedOptions);
1029
+ await executeUnbuild(resolvedOptions);
1030
+ await copyBuildAssets(resolvedOptions);
1031
+ writeSuccess(` \u{1F3C1} The ${resolvedOptions.name} build completed successfully`, resolvedOptions.config);
1032
+ } catch (error) {
1033
+ writeFatal(" \u274C Fatal errors occurred during the build that could not be recovered from. The build process has been terminated.");
1034
+ throw error;
1035
+ } finally {
1036
+ stopwatch();
1037
+ }
1038
+ }
1039
+ __name(build, "build");
1040
+
1041
+ export {
1042
+ build
1043
+ };