@storm-software/tsdown 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1015 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+ var _chunkEPTKG5AHcjs = require('./chunk-EPTKG5AH.cjs');
24
+
25
+
26
+ var _chunk5KRF6IVWcjs = require('./chunk-5KRF6IVW.cjs');
27
+
28
+
29
+ var _chunkUSNT2KNTcjs = require('./chunk-USNT2KNT.cjs');
30
+
31
+ // src/build.ts
32
+ var _node = require('@humanfs/node');
33
+ var _devkit = require('@nx/devkit');
34
+
35
+ // ../build-tools/src/config.ts
36
+ var DEFAULT_ENVIRONMENT = "production";
37
+ var DEFAULT_TARGET = "esnext";
38
+ var DEFAULT_ORGANIZATION = "storm-software";
39
+
40
+ // ../build-tools/src/plugins/swc.ts
41
+ var _core = require('@swc/core');
42
+
43
+ // ../build-tools/src/plugins/ts-resolve.ts
44
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
45
+ var _module = require('module');
46
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
47
+ var _resolve2 = require('resolve'); var _resolve3 = _interopRequireDefault(_resolve2);
48
+
49
+ // ../build-tools/src/plugins/type-definitions.ts
50
+
51
+
52
+
53
+ // ../build-tools/src/utilities/copy-assets.ts
54
+
55
+
56
+ var _js = require('@nx/js');
57
+ var _glob = require('glob');
58
+
59
+ // ../build-tools/src/utilities/read-nx-config.ts
60
+
61
+
62
+ // ../config-tools/src/config-file/get-config-file.ts
63
+ var _c12 = require('c12');
64
+ var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);
65
+ var getConfigFileByName = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (fileName, filePath, options = {}) => {
66
+ const workspacePath = filePath || _chunkEPTKG5AHcjs.findWorkspaceRoot.call(void 0, filePath);
67
+ let config = _c12.loadConfig.call(void 0, {
68
+ cwd: workspacePath,
69
+ packageJson: true,
70
+ name: fileName,
71
+ envName: _optionalChain([fileName, 'optionalAccess', _ => _.toUpperCase, 'call', _2 => _2()]),
72
+ jitiOptions: {
73
+ debug: false,
74
+ cache: process.env.STORM_SKIP_CACHE === "true" ? false : _chunkEPTKG5AHcjs.joinPaths.call(void 0, process.env.STORM_CACHE_DIR || "node_modules/.cache", "storm")
75
+ },
76
+ ...options
77
+ });
78
+ if (!config || Object.keys(config).length === 0) {
79
+ config = _c12.loadConfig.call(void 0, {
80
+ cwd: workspacePath,
81
+ packageJson: true,
82
+ name: fileName,
83
+ envName: _optionalChain([fileName, 'optionalAccess', _3 => _3.toUpperCase, 'call', _4 => _4()]),
84
+ jitiOptions: {
85
+ debug: false,
86
+ cache: process.env.STORM_SKIP_CACHE === "true" ? false : _chunkEPTKG5AHcjs.joinPaths.call(void 0, process.env.STORM_CACHE_DIR || "node_modules/.cache", "storm")
87
+ },
88
+ configFile: fileName,
89
+ ...options
90
+ });
91
+ }
92
+ return config;
93
+ }, "getConfigFileByName");
94
+ var getConfigFile = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (filePath, additionalFileNames = []) => {
95
+ const workspacePath = filePath ? filePath : _chunkEPTKG5AHcjs.findWorkspaceRoot.call(void 0, 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
+ _chunkEPTKG5AHcjs.writeSystem.call(void 0, `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 (_optionalChain([result2, 'optionalAccess', _5 => _5.config]) && _optionalChain([result2, 'optionalAccess', _6 => _6.configFile]) && Object.keys(result2.config).length > 0) {
108
+ _chunkEPTKG5AHcjs.writeSystem.call(void 0, `Found alternative configuration file "${result2.configFile.includes(`${workspacePath}/`) ? result2.configFile.replace(`${workspacePath}/`, "") : result2.configFile}" at "${workspacePath}"`, {
109
+ logLevel: "all"
110
+ });
111
+ config = _defu2.default.call(void 0, _nullishCoalesce(result2.config, () => ( {})), _nullishCoalesce(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
+
124
+
125
+ // ../config-tools/src/env/get-env.ts
126
+ var getConfigEnv = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, () => {
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`] ? _chunkEPTKG5AHcjs.correctPaths.call(void 0, process.env[`${prefix}CONFIG_FILE`]) : void 0,
146
+ workspaceRoot: process.env[`${prefix}WORKSPACE_ROOT`] ? _chunkEPTKG5AHcjs.correctPaths.call(void 0, process.env[`${prefix}WORKSPACE_ROOT`]) : void 0,
147
+ directories: {
148
+ cache: process.env[`${prefix}CACHE_DIR`] ? _chunkEPTKG5AHcjs.correctPaths.call(void 0, process.env[`${prefix}CACHE_DIR`]) : void 0,
149
+ data: process.env[`${prefix}DATA_DIR`] ? _chunkEPTKG5AHcjs.correctPaths.call(void 0, process.env[`${prefix}DATA_DIR`]) : void 0,
150
+ config: process.env[`${prefix}CONFIG_DIR`] ? _chunkEPTKG5AHcjs.correctPaths.call(void 0, process.env[`${prefix}CONFIG_DIR`]) : void 0,
151
+ temp: process.env[`${prefix}TEMP_DIR`] ? _chunkEPTKG5AHcjs.correctPaths.call(void 0, process.env[`${prefix}TEMP_DIR`]) : void 0,
152
+ log: process.env[`${prefix}LOG_DIR`] ? _chunkEPTKG5AHcjs.correctPaths.call(void 0, process.env[`${prefix}LOG_DIR`]) : void 0,
153
+ build: process.env[`${prefix}BUILD_DIR`] ? _chunkEPTKG5AHcjs.correctPaths.call(void 0, 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: (_nullishCoalesce(_nullishCoalesce(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`])) ? _chunkEPTKG5AHcjs.getLogLevelLabel.call(void 0, 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_`) && _chunkEPTKG5AHcjs.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 === _chunkEPTKG5AHcjs.STORM_DEFAULT_DOCS) {
184
+ if (config.homepage === _chunkEPTKG5AHcjs.STORM_DEFAULT_HOMEPAGE) {
185
+ config.docs = `${_chunkEPTKG5AHcjs.STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/docs`;
186
+ } else {
187
+ config.docs = `${config.homepage}/docs`;
188
+ }
189
+ }
190
+ if (config.licensing === _chunkEPTKG5AHcjs.STORM_DEFAULT_LICENSING) {
191
+ if (config.homepage === _chunkEPTKG5AHcjs.STORM_DEFAULT_HOMEPAGE) {
192
+ config.licensing = `${_chunkEPTKG5AHcjs.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__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (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__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (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__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (prefix) => {
238
+ return {
239
+ light: getBaseThemeColorConfigEnv(`${prefix}_LIGHT_`),
240
+ dark: getBaseThemeColorConfigEnv(`${prefix}_DARK_`)
241
+ };
242
+ }, "getMultiThemeColorConfigEnv");
243
+ var getBaseThemeColorConfigEnv = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (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__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (extensionName, extension) => {
264
+ for (const key of Object.keys(_nullishCoalesce(extension, () => ( {})))) {
265
+ if (extension[key]) {
266
+ const result = _nullishCoalesce(_optionalChain([key, 'optionalAccess', _7 => _7.replace, 'call', _8 => _8(/([A-Z])+/g, (input) => input ? _optionalChain([input, 'access', _9 => _9[0], 'optionalAccess', _10 => _10.toUpperCase, 'call', _11 => _11()]) + input.slice(1) : ""), 'access', _12 => _12.split, 'call', _13 => _13(/(?=[A-Z])|[.\-\s_]/), 'access', _14 => _14.map, 'call', _15 => _15((x) => x.toLowerCase())]), () => ( []));
267
+ let extensionKey;
268
+ if (result.length === 0) {
269
+ return;
270
+ }
271
+ if (result.length === 1) {
272
+ extensionKey = _nullishCoalesce(_optionalChain([result, 'access', _16 => _16[0], 'optionalAccess', _17 => _17.toUpperCase, 'call', _18 => _18()]), () => ( ""));
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__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (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`] = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.configFile);
331
+ }
332
+ if (config.workspaceRoot) {
333
+ process.env[`${prefix}WORKSPACE_ROOT`] = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.workspaceRoot);
334
+ process.env.NX_WORKSPACE_ROOT = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.workspaceRoot);
335
+ process.env.NX_WORKSPACE_ROOT_PATH = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.workspaceRoot);
336
+ }
337
+ if (config.directories) {
338
+ if (!config.skipCache && config.directories.cache) {
339
+ process.env[`${prefix}CACHE_DIR`] = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.directories.cache);
340
+ }
341
+ if (config.directories.data) {
342
+ process.env[`${prefix}DATA_DIR`] = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.directories.data);
343
+ }
344
+ if (config.directories.config) {
345
+ process.env[`${prefix}CONFIG_DIR`] = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.directories.config);
346
+ }
347
+ if (config.directories.temp) {
348
+ process.env[`${prefix}TEMP_DIR`] = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.directories.temp);
349
+ }
350
+ if (config.directories.log) {
351
+ process.env[`${prefix}LOG_DIR`] = _chunkEPTKG5AHcjs.correctPaths.call(void 0, config.directories.log);
352
+ }
353
+ if (config.directories.build) {
354
+ process.env[`${prefix}BUILD_DIR`] = _chunkEPTKG5AHcjs.correctPaths.call(void 0, 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 (_optionalChain([config, 'access', _19 => _19.colors, 'optionalAccess', _20 => _20.base, 'optionalAccess', _21 => _21.light]) || _optionalChain([config, 'access', _22 => _22.colors, 'optionalAccess', _23 => _23.base, 'optionalAccess', _24 => _24.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(_chunkEPTKG5AHcjs.getLogLevel.call(void 0, config.logLevel) >= _chunkEPTKG5AHcjs.LogLevel.DEBUG ? true : false);
409
+ process.env.RUST_BACKTRACE = _chunkEPTKG5AHcjs.getLogLevel.call(void 0, config.logLevel) >= _chunkEPTKG5AHcjs.LogLevel.DEBUG ? "full" : "none";
410
+ }
411
+ process.env[`${prefix}CONFIG`] = JSON.stringify(config);
412
+ for (const key of Object.keys(_nullishCoalesce(config.extensions, () => ( {})))) {
413
+ config.extensions[key] && Object.keys(config.extensions[key]) && setExtensionEnv(key, config.extensions[key]);
414
+ }
415
+ }, "setConfigEnv");
416
+ var setThemeColorConfigEnv = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (prefix, config) => {
417
+ return _optionalChain([config, 'optionalAccess', _25 => _25.light, 'optionalAccess', _26 => _26.brand]) || _optionalChain([config, 'optionalAccess', _27 => _27.dark, 'optionalAccess', _28 => _28.brand]) ? setMultiThemeColorConfigEnv(prefix, config) : setSingleThemeColorConfigEnv(prefix, config);
418
+ }, "setThemeColorConfigEnv");
419
+ var setSingleThemeColorConfigEnv = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (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__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (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__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (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__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (workspaceRoot) => {
517
+ let config = {};
518
+ if (_optionalChain([_static_cache, 'optionalAccess', _29 => _29.data]) && _optionalChain([_static_cache, 'optionalAccess', _30 => _30.timestamp]) && _static_cache.timestamp >= Date.now() + 3e4) {
519
+ _chunkEPTKG5AHcjs.writeTrace.call(void 0, `Configuration cache hit - ${_static_cache.timestamp}`, _static_cache.data);
520
+ return _static_cache.data;
521
+ }
522
+ let _workspaceRoot = workspaceRoot;
523
+ if (!_workspaceRoot) {
524
+ _workspaceRoot = _chunkEPTKG5AHcjs.findWorkspaceRoot.call(void 0, );
525
+ }
526
+ const configFile = await getConfigFile(_workspaceRoot);
527
+ if (!configFile) {
528
+ _chunkEPTKG5AHcjs.writeWarning.call(void 0, "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.default.call(void 0, getConfigEnv(), configFile, _chunkEPTKG5AHcjs.getDefaultConfig.call(void 0, _workspaceRoot));
533
+ setConfigEnv(config);
534
+ _chunkEPTKG5AHcjs.writeTrace.call(void 0, `\u2699\uFE0F Using Storm configuration:
535
+ ${_chunkEPTKG5AHcjs.formatLogMessage.call(void 0, config)}`, config);
536
+ return config;
537
+ }, "loadStormConfig");
538
+
539
+ // ../build-tools/src/utilities/read-nx-config.ts
540
+ var readNxConfig = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (workspaceRoot) => {
541
+ let rootDir = workspaceRoot;
542
+ if (!rootDir) {
543
+ const config = await loadStormConfig();
544
+ rootDir = config.workspaceRoot;
545
+ }
546
+ const nxJsonPath = _chunkEPTKG5AHcjs.joinPaths.call(void 0, rootDir, "nx.json");
547
+ if (!await _node.hfs.isFile(nxJsonPath)) {
548
+ throw new Error("Cannot find project.json configuration");
549
+ }
550
+ return _node.hfs.json(nxJsonPath);
551
+ }, "readNxConfig");
552
+
553
+ // ../build-tools/src/utilities/copy-assets.ts
554
+ var copyAssets = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (config, assets, outputPath, projectRoot, projectName, sourceRoot, generatePackageJson2 = true, includeSrc = false, banner, footer) => {
555
+ const pendingAssets = Array.from(_nullishCoalesce(assets, () => ( [])));
556
+ if (!_optionalChain([pendingAssets, 'optionalAccess', _31 => _31.some, 'call', _32 => _32((asset) => _optionalChain([asset, 'optionalAccess', _33 => _33.glob]) === "*.md")])) {
557
+ pendingAssets.push({
558
+ input: projectRoot,
559
+ glob: "*.md",
560
+ output: "/"
561
+ });
562
+ }
563
+ if (generatePackageJson2 === false) {
564
+ pendingAssets.push({
565
+ input: sourceRoot,
566
+ glob: "package.json",
567
+ output: "."
568
+ });
569
+ }
570
+ if (!_optionalChain([pendingAssets, 'optionalAccess', _34 => _34.some, 'call', _35 => _35((asset) => _optionalChain([asset, 'optionalAccess', _36 => _36.glob]) === "LICENSE")])) {
571
+ pendingAssets.push({
572
+ input: "",
573
+ glob: "LICENSE",
574
+ output: "."
575
+ });
576
+ }
577
+ if (includeSrc === true) {
578
+ pendingAssets.push({
579
+ input: sourceRoot,
580
+ glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
581
+ output: "src/"
582
+ });
583
+ }
584
+ const nxJson = readNxConfig(config.workspaceRoot);
585
+ const projectGraph = await _devkit.createProjectGraphAsync.call(void 0, {
586
+ exitOnError: true
587
+ });
588
+ const projectsConfigurations = _devkit.readProjectsConfigurationFromProjectGraph.call(void 0, projectGraph);
589
+ if (!_optionalChain([projectsConfigurations, 'optionalAccess', _37 => _37.projects, 'optionalAccess', _38 => _38[projectName]])) {
590
+ 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.");
591
+ }
592
+ const buildTarget = _optionalChain([projectsConfigurations, 'access', _39 => _39.projects, 'access', _40 => _40[projectName], 'optionalAccess', _41 => _41.targets, 'optionalAccess', _42 => _42.build]);
593
+ if (!buildTarget) {
594
+ 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 ${_chunkEPTKG5AHcjs.joinPaths.call(void 0, projectRoot, "project.json")}`);
595
+ }
596
+ const result = await _js.copyAssets.call(void 0, {
597
+ assets,
598
+ watch: false,
599
+ outputPath
600
+ }, {
601
+ root: config.workspaceRoot,
602
+ targetName: "build",
603
+ target: buildTarget,
604
+ projectName,
605
+ projectGraph,
606
+ projectsConfigurations,
607
+ nxJsonConfiguration: nxJson,
608
+ cwd: config.workspaceRoot,
609
+ isVerbose: _chunkEPTKG5AHcjs.isVerbose.call(void 0, config.logLevel)
610
+ });
611
+ if (!result.success) {
612
+ throw new Error("The Build process failed trying to copy assets");
613
+ }
614
+ if (includeSrc === true) {
615
+ _chunkEPTKG5AHcjs.writeDebug.call(void 0, `\u{1F4DD} Adding banner and writing source files: ${_chunkEPTKG5AHcjs.joinPaths.call(void 0, outputPath, "src")}`, config);
616
+ const files = await _glob.glob.call(void 0, [
617
+ _chunkEPTKG5AHcjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.ts"),
618
+ _chunkEPTKG5AHcjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.tsx"),
619
+ _chunkEPTKG5AHcjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.js"),
620
+ _chunkEPTKG5AHcjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.jsx")
621
+ ]);
622
+ await Promise.allSettled(files.map(async (file) => _node.hfs.write(file, `${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
623
+
624
+ ${await _node.hfs.text(file)}
625
+
626
+ ${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`)));
627
+ }
628
+ }, "copyAssets");
629
+
630
+ // ../build-tools/src/utilities/generate-package-json.ts
631
+
632
+ var _buildablelibsutils = require('@nx/js/src/utils/buildable-libs-utils');
633
+
634
+ var _projectgraph = require('nx/src/project-graph/project-graph');
635
+ var addPackageDependencies = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (workspaceRoot, projectRoot, projectName, packageJson) => {
636
+ const projectGraph = await _projectgraph.createProjectGraphAsync.call(void 0, {
637
+ exitOnError: true
638
+ });
639
+ const projectConfigurations = _projectgraph.readProjectsConfigurationFromProjectGraph.call(void 0, projectGraph);
640
+ if (!_optionalChain([projectConfigurations, 'optionalAccess', _43 => _43.projects, 'optionalAccess', _44 => _44[projectName]])) {
641
+ 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.");
642
+ }
643
+ const projectJsonPath = _chunkEPTKG5AHcjs.joinPaths.call(void 0, workspaceRoot, projectRoot, "project.json");
644
+ if (!await _node.hfs.isFile(projectJsonPath)) {
645
+ throw new Error("Cannot find project.json configuration");
646
+ }
647
+ if (!_optionalChain([projectConfigurations, 'optionalAccess', _45 => _45.projects, 'optionalAccess', _46 => _46[projectName]])) {
648
+ 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.");
649
+ }
650
+ const projectDependencies = _buildablelibsutils.calculateProjectBuildableDependencies.call(void 0, void 0, projectGraph, workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
651
+ const localPackages = [];
652
+ for (const project of projectDependencies.dependencies.filter((dep) => dep.node.type === "lib" && dep.node.data.root !== projectRoot && dep.node.data.root !== workspaceRoot)) {
653
+ const projectNode = project.node;
654
+ if (projectNode.data.root) {
655
+ const projectPackageJsonPath = _chunkEPTKG5AHcjs.joinPaths.call(void 0, workspaceRoot, projectNode.data.root, "package.json");
656
+ if (await _node.hfs.isFile(projectPackageJsonPath)) {
657
+ const projectPackageJson = await _node.hfs.json(projectPackageJsonPath);
658
+ if (projectPackageJson.private !== false) {
659
+ localPackages.push(projectPackageJson);
660
+ }
661
+ }
662
+ }
663
+ }
664
+ if (localPackages.length > 0) {
665
+ _chunkEPTKG5AHcjs.writeTrace.call(void 0, `\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`);
666
+ packageJson.peerDependencies = localPackages.reduce((ret, localPackage) => {
667
+ if (!ret[localPackage.name]) {
668
+ ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
669
+ }
670
+ return ret;
671
+ }, _nullishCoalesce(packageJson.peerDependencies, () => ( {})));
672
+ packageJson.peerDependenciesMeta = localPackages.reduce((ret, localPackage) => {
673
+ if (!ret[localPackage.name]) {
674
+ ret[localPackage.name] = {
675
+ optional: false
676
+ };
677
+ }
678
+ return ret;
679
+ }, _nullishCoalesce(packageJson.peerDependenciesMeta, () => ( {})));
680
+ packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
681
+ if (!ret[localPackage.name]) {
682
+ ret[localPackage.name] = localPackage.version || "0.0.1";
683
+ }
684
+ return ret;
685
+ }, _nullishCoalesce(packageJson.peerDependencies, () => ( {})));
686
+ } else {
687
+ _chunkEPTKG5AHcjs.writeTrace.call(void 0, "\u{1F4E6} No local packages dependencies to add to package.json");
688
+ }
689
+ return packageJson;
690
+ }, "addPackageDependencies");
691
+ var addWorkspacePackageJsonFields = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (config, projectRoot, sourceRoot, projectName, includeSrc = false, packageJson) => {
692
+ const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : _chunkEPTKG5AHcjs.findWorkspaceRoot.call(void 0, );
693
+ const workspacePackageJson = await _node.hfs.json(_chunkEPTKG5AHcjs.joinPaths.call(void 0, workspaceRoot, "package.json"));
694
+ packageJson.type ??= "module";
695
+ packageJson.sideEffects ??= false;
696
+ if (includeSrc === true) {
697
+ let distSrc = sourceRoot.replace(projectRoot, "");
698
+ if (distSrc.startsWith("/")) {
699
+ distSrc = distSrc.substring(1);
700
+ }
701
+ packageJson.source ??= `${_chunkEPTKG5AHcjs.joinPaths.call(void 0, distSrc, "index.ts").replaceAll("\\", "/")}`;
702
+ }
703
+ packageJson.files ??= [
704
+ "dist/**/*"
705
+ ];
706
+ if (includeSrc === true && !packageJson.files.includes("src")) {
707
+ packageJson.files.push("src/**/*");
708
+ }
709
+ packageJson.publishConfig ??= {
710
+ access: "public"
711
+ };
712
+ packageJson.description ??= workspacePackageJson.description;
713
+ packageJson.homepage ??= workspacePackageJson.homepage;
714
+ packageJson.bugs ??= workspacePackageJson.bugs;
715
+ packageJson.license ??= workspacePackageJson.license;
716
+ packageJson.keywords ??= workspacePackageJson.keywords;
717
+ packageJson.funding ??= workspacePackageJson.funding;
718
+ packageJson.author ??= workspacePackageJson.author;
719
+ packageJson.maintainers ??= workspacePackageJson.maintainers;
720
+ if (!packageJson.maintainers && packageJson.author) {
721
+ packageJson.maintainers = [
722
+ packageJson.author
723
+ ];
724
+ }
725
+ packageJson.contributors ??= workspacePackageJson.contributors;
726
+ if (!packageJson.contributors && packageJson.author) {
727
+ packageJson.contributors = [
728
+ packageJson.author
729
+ ];
730
+ }
731
+ packageJson.repository ??= workspacePackageJson.repository;
732
+ packageJson.repository.directory ??= projectRoot ? projectRoot : _chunkEPTKG5AHcjs.joinPaths.call(void 0, "packages", projectName);
733
+ return packageJson;
734
+ }, "addWorkspacePackageJsonFields");
735
+ var addPackageJsonExport = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (file, type = "module", sourceRoot) => {
736
+ let entry = file.replaceAll("\\", "/");
737
+ if (sourceRoot) {
738
+ entry = entry.replace(sourceRoot, "");
739
+ }
740
+ return {
741
+ "import": {
742
+ "types": `./dist/${entry}.d.${type === "module" ? "ts" : "mts"}`,
743
+ "default": `./dist/${entry}.${type === "module" ? "js" : "mjs"}`
744
+ },
745
+ "require": {
746
+ "types": `./dist/${entry}.d.${type === "commonjs" ? "ts" : "cts"}`,
747
+ "default": `./dist/${entry}.${type === "commonjs" ? "js" : "cjs"}`
748
+ },
749
+ "default": {
750
+ "types": `./dist/${entry}.d.ts`,
751
+ "default": `./dist/${entry}.js`
752
+ }
753
+ };
754
+ }, "addPackageJsonExport");
755
+
756
+ // ../build-tools/src/utilities/get-entry-points.ts
757
+
758
+ var getEntryPoints = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (config, projectRoot, sourceRoot, entry, emitOnAll = false) => {
759
+ const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : _chunkEPTKG5AHcjs.findWorkspaceRoot.call(void 0, );
760
+ const entryPoints = [];
761
+ if (entry) {
762
+ if (Array.isArray(entry)) {
763
+ entryPoints.push(...entry);
764
+ } else if (typeof entry === "string") {
765
+ entryPoints.push(entry);
766
+ } else {
767
+ entryPoints.push(...Object.values(entry));
768
+ }
769
+ }
770
+ if (emitOnAll) {
771
+ entryPoints.push(_chunkEPTKG5AHcjs.joinPaths.call(void 0, workspaceRoot, sourceRoot || projectRoot, "**/*.{ts,tsx}"));
772
+ }
773
+ const results = [];
774
+ for (const entryPoint in entryPoints) {
775
+ if (entryPoint.includes("*")) {
776
+ const files = await _glob.glob.call(void 0, entryPoint, {
777
+ withFileTypes: true
778
+ });
779
+ results.push(...files.reduce((ret, filePath) => {
780
+ const result = _chunkEPTKG5AHcjs.correctPaths.call(void 0, _chunkEPTKG5AHcjs.joinPaths.call(void 0, filePath.path, filePath.name).replaceAll(_chunkEPTKG5AHcjs.correctPaths.call(void 0, workspaceRoot), "").replaceAll(_chunkEPTKG5AHcjs.correctPaths.call(void 0, projectRoot), ""));
781
+ if (result) {
782
+ _chunkEPTKG5AHcjs.writeDebug.call(void 0, `Trying to add entry point ${result} at "${_chunkEPTKG5AHcjs.joinPaths.call(void 0, filePath.path, filePath.name)}"`, config);
783
+ if (!results.includes(result)) {
784
+ results.push(result);
785
+ }
786
+ }
787
+ return ret;
788
+ }, []));
789
+ } else {
790
+ results.push(entryPoint);
791
+ }
792
+ }
793
+ return results;
794
+ }, "getEntryPoints");
795
+
796
+ // ../build-tools/src/utilities/get-env.ts
797
+ var getEnv = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, (builder, options) => {
798
+ return {
799
+ STORM_BUILD: builder,
800
+ STORM_ORG: options.orgName || DEFAULT_ORGANIZATION,
801
+ STORM_NAME: options.name,
802
+ STORM_ENV: options.envName || DEFAULT_ENVIRONMENT,
803
+ STORM_PLATFORM: options.platform,
804
+ STORM_FORMAT: JSON.stringify(options.format),
805
+ STORM_TARGET: JSON.stringify(options.target),
806
+ ...options.env
807
+ };
808
+ }, "getEnv");
809
+
810
+ // ../build-tools/src/utilities/task-graph.ts
811
+ var _createtaskgraph = require('nx/src/tasks-runner/create-task-graph');
812
+
813
+ // src/build.ts
814
+
815
+ var _findworkspaceroot = require('nx/src/utils/find-workspace-root');
816
+ var _tsdown = require('tsdown');
817
+ var resolveOptions = /* @__PURE__ */ _chunkUSNT2KNTcjs.__name.call(void 0, async (userOptions) => {
818
+ const projectRoot = userOptions.projectRoot;
819
+ const workspaceRoot = _findworkspaceroot.findWorkspaceRoot.call(void 0, projectRoot);
820
+ if (!workspaceRoot) {
821
+ throw new Error("Cannot find Nx workspace root");
822
+ }
823
+ const config = await loadStormConfig(workspaceRoot.dir);
824
+ _chunkEPTKG5AHcjs.writeDebug.call(void 0, " \u2699\uFE0F Resolving build options", config);
825
+ const stopwatch = _chunkEPTKG5AHcjs.getStopwatch.call(void 0, "Build options resolution");
826
+ const projectGraph = await _devkit.createProjectGraphAsync.call(void 0, {
827
+ exitOnError: true
828
+ });
829
+ const projectJsonPath = _chunkEPTKG5AHcjs.joinPaths.call(void 0, workspaceRoot.dir, projectRoot, "project.json");
830
+ if (!await _node.hfs.isFile(projectJsonPath)) {
831
+ throw new Error("Cannot find project.json configuration");
832
+ }
833
+ const projectJson = await _node.hfs.json(projectJsonPath);
834
+ const projectName = projectJson.name;
835
+ const projectConfigurations = _devkit.readProjectsConfigurationFromProjectGraph.call(void 0, projectGraph);
836
+ if (!_optionalChain([projectConfigurations, 'optionalAccess', _47 => _47.projects, 'optionalAccess', _48 => _48[projectName]])) {
837
+ 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.");
838
+ }
839
+ const options = _defu2.default.call(void 0, userOptions, _chunk5KRF6IVWcjs.DEFAULT_BUILD_OPTIONS);
840
+ options.name ??= `${projectName}-${options.format}`;
841
+ options.target ??= DEFAULT_TARGET;
842
+ const packageJsonPath = _chunkEPTKG5AHcjs.joinPaths.call(void 0, workspaceRoot.dir, options.projectRoot, "package.json");
843
+ if (!await _node.hfs.isFile(packageJsonPath)) {
844
+ throw new Error("Cannot find package.json configuration");
845
+ }
846
+ const env = getEnv("tsdown", options);
847
+ const result = {
848
+ ...options,
849
+ config,
850
+ ...userOptions,
851
+ tsconfig: _chunkEPTKG5AHcjs.joinPaths.call(void 0, projectRoot, userOptions.tsconfig ? userOptions.tsconfig.replace(projectRoot, "") : "tsconfig.json"),
852
+ format: options.format || "cjs",
853
+ entryPoints: await getEntryPoints(config, projectRoot, projectJson.sourceRoot, userOptions.entry || [
854
+ "./src/index.ts"
855
+ ], userOptions.emitOnAll),
856
+ outdir: userOptions.outputPath || _chunkEPTKG5AHcjs.joinPaths.call(void 0, "dist", projectRoot),
857
+ plugins: [],
858
+ name: userOptions.name || projectName,
859
+ projectConfigurations,
860
+ projectName,
861
+ projectGraph,
862
+ sourceRoot: userOptions.sourceRoot || projectJson.sourceRoot || _chunkEPTKG5AHcjs.joinPaths.call(void 0, projectRoot, "src"),
863
+ minify: userOptions.minify || !userOptions.debug,
864
+ verbose: userOptions.verbose || _chunkEPTKG5AHcjs.isVerbose.call(void 0, ) || userOptions.debug === true,
865
+ includeSrc: userOptions.includeSrc === true,
866
+ metafile: userOptions.metafile !== false,
867
+ generatePackageJson: userOptions.generatePackageJson !== false,
868
+ clean: userOptions.clean !== false,
869
+ emitOnAll: userOptions.emitOnAll === true,
870
+ dts: userOptions.emitTypes === true ? {
871
+ transformer: "oxc"
872
+ } : userOptions.emitTypes,
873
+ bundleDts: userOptions.emitTypes,
874
+ assets: _nullishCoalesce(userOptions.assets, () => ( [])),
875
+ shims: userOptions.injectShims !== true,
876
+ bundle: userOptions.bundle !== false,
877
+ watch: userOptions.watch === true,
878
+ define: {
879
+ STORM_FORMAT: JSON.stringify(options.format || "cjs"),
880
+ ...options.format === "cjs" && options.injectShims ? {
881
+ "import.meta.url": "importMetaUrl"
882
+ } : {},
883
+ ...options.define,
884
+ ...Object.keys(env || {}).reduce((res, key) => {
885
+ const value = JSON.stringify(env[key]);
886
+ return {
887
+ ...res,
888
+ [`process.env.${key}`]: value,
889
+ [`import.meta.env.${key}`]: value
890
+ };
891
+ }, {})
892
+ }
893
+ };
894
+ stopwatch();
895
+ return result;
896
+ }, "resolveOptions");
897
+ async function generatePackageJson(options) {
898
+ if (options.generatePackageJson !== false && await _node.hfs.isFile(_chunkEPTKG5AHcjs.joinPaths.call(void 0, options.projectRoot, "package.json"))) {
899
+ _chunkEPTKG5AHcjs.writeDebug.call(void 0, " \u270D\uFE0F Writing package.json file", options.config);
900
+ const stopwatch = _chunkEPTKG5AHcjs.getStopwatch.call(void 0, "Write package.json file");
901
+ const packageJsonPath = _chunkEPTKG5AHcjs.joinPaths.call(void 0, options.projectRoot, "project.json");
902
+ if (!await _node.hfs.isFile(packageJsonPath)) {
903
+ throw new Error("Cannot find package.json configuration");
904
+ }
905
+ let packageJson = await _node.hfs.json(_chunkEPTKG5AHcjs.joinPaths.call(void 0, options.config.workspaceRoot, options.projectRoot, "package.json"));
906
+ if (!packageJson) {
907
+ throw new Error("Cannot find package.json configuration file");
908
+ }
909
+ packageJson = await addPackageDependencies(options.config.workspaceRoot, options.projectRoot, options.projectName, packageJson);
910
+ packageJson = await addWorkspacePackageJsonFields(options.config, options.projectRoot, options.sourceRoot, options.projectName, false, packageJson);
911
+ packageJson.exports ??= {};
912
+ packageJson.exports["./package.json"] ??= "./package.json";
913
+ packageJson.exports["."] ??= addPackageJsonExport("index", packageJson.type, options.sourceRoot);
914
+ let entryPoints = [
915
+ {
916
+ in: "./src/index.ts",
917
+ out: "./src/index.ts"
918
+ }
919
+ ];
920
+ if (options.entryPoints) {
921
+ if (Array.isArray(options.entryPoints)) {
922
+ entryPoints = options.entryPoints.map((entryPoint) => typeof entryPoint === "string" ? {
923
+ in: entryPoint,
924
+ out: entryPoint
925
+ } : entryPoint);
926
+ }
927
+ for (const entryPoint of entryPoints) {
928
+ const split = entryPoint.out.split(".");
929
+ split.pop();
930
+ const entry = split.join(".").replaceAll("\\", "/");
931
+ packageJson.exports[`./${entry}`] ??= addPackageJsonExport(entry, packageJson.type, options.sourceRoot);
932
+ }
933
+ }
934
+ packageJson.main = packageJson.type === "commonjs" ? "./dist/index.js" : "./dist/index.cjs";
935
+ packageJson.module = packageJson.type === "module" ? "./dist/index.js" : "./dist/index.mjs";
936
+ packageJson.types = "./dist/index.d.ts";
937
+ packageJson.exports = Object.keys(packageJson.exports).reduce((ret, key) => {
938
+ if (key.endsWith("/index") && !ret[key.replace("/index", "")]) {
939
+ ret[key.replace("/index", "")] = packageJson.exports[key];
940
+ }
941
+ return ret;
942
+ }, packageJson.exports);
943
+ await _devkit.writeJsonFile.call(void 0, _chunkEPTKG5AHcjs.joinPaths.call(void 0, options.outdir, "package.json"), packageJson);
944
+ stopwatch();
945
+ }
946
+ return options;
947
+ }
948
+ _chunkUSNT2KNTcjs.__name.call(void 0, generatePackageJson, "generatePackageJson");
949
+ async function executeTSDown(options) {
950
+ _chunkEPTKG5AHcjs.writeDebug.call(void 0, ` \u{1F680} Running ${options.name} build`, options.config);
951
+ const stopwatch = _chunkEPTKG5AHcjs.getStopwatch.call(void 0, `${options.name} build`);
952
+ await _tsdown.build.call(void 0, {
953
+ ...options,
954
+ entry: options.entryPoints,
955
+ outDir: options.outdir,
956
+ config: false
957
+ });
958
+ stopwatch();
959
+ return options;
960
+ }
961
+ _chunkUSNT2KNTcjs.__name.call(void 0, executeTSDown, "executeTSDown");
962
+ async function copyBuildAssets(options) {
963
+ _chunkEPTKG5AHcjs.writeDebug.call(void 0, ` \u{1F4CB} Copying asset files to output directory: ${options.outdir}`, options.config);
964
+ const stopwatch = _chunkEPTKG5AHcjs.getStopwatch.call(void 0, `${options.name} asset copy`);
965
+ await copyAssets(options.config, _nullishCoalesce(options.assets, () => ( [])), options.outdir, options.projectRoot, options.projectName, options.sourceRoot, true, false);
966
+ stopwatch();
967
+ return options;
968
+ }
969
+ _chunkUSNT2KNTcjs.__name.call(void 0, copyBuildAssets, "copyBuildAssets");
970
+ async function reportResults(options) {
971
+ _chunkEPTKG5AHcjs.writeSuccess.call(void 0, ` \u{1F4E6} The ${options.name} build completed successfully`, options.config);
972
+ }
973
+ _chunkUSNT2KNTcjs.__name.call(void 0, reportResults, "reportResults");
974
+ async function cleanOutputPath(options) {
975
+ if (options.clean !== false && options.outdir) {
976
+ await _chunkEPTKG5AHcjs.clean.call(void 0, options.name, options.outdir, options.config);
977
+ }
978
+ return options;
979
+ }
980
+ _chunkUSNT2KNTcjs.__name.call(void 0, cleanOutputPath, "cleanOutputPath");
981
+ async function build(options) {
982
+ _chunkEPTKG5AHcjs.writeDebug.call(void 0, ` \u26A1 Executing Storm TSDown pipeline`);
983
+ const stopwatch = _chunkEPTKG5AHcjs.getStopwatch.call(void 0, "TSDown pipeline");
984
+ try {
985
+ const opts = Array.isArray(options) ? options : [
986
+ options
987
+ ];
988
+ if (opts.length === 0) {
989
+ throw new Error("No build options were provided");
990
+ }
991
+ const resolved = await Promise.all(opts.map(async (opt) => await resolveOptions(opt)));
992
+ if (resolved.length > 0) {
993
+ await cleanOutputPath(resolved[0]);
994
+ await generatePackageJson(resolved[0]);
995
+ await Promise.all(resolved.map(async (opt) => {
996
+ await executeTSDown(opt);
997
+ await copyBuildAssets(opt);
998
+ await reportResults(opt);
999
+ }));
1000
+ } else {
1001
+ _chunkEPTKG5AHcjs.writeWarning.call(void 0, " \u{1F6A7} No options were passed to TSBuild. Please check the parameters passed to the `build` function.");
1002
+ }
1003
+ _chunkEPTKG5AHcjs.writeSuccess.call(void 0, " \u{1F3C1} TSDown pipeline build completed successfully");
1004
+ } catch (error) {
1005
+ _chunkEPTKG5AHcjs.writeFatal.call(void 0, " \u274C Fatal errors occurred during the build that could not be recovered from. The build process has been terminated.");
1006
+ throw error;
1007
+ } finally {
1008
+ stopwatch();
1009
+ }
1010
+ }
1011
+ _chunkUSNT2KNTcjs.__name.call(void 0, build, "build");
1012
+
1013
+
1014
+
1015
+ exports.build = build;