@storm-software/unbuild 0.25.2 → 0.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +1 -1
  2. package/bin/unbuild.cjs +3402 -0
  3. package/bin/unbuild.js +2709 -62860
  4. package/dist/build.cjs +14 -0
  5. package/dist/{build.d.mts → build.d.cts} +1 -1
  6. package/dist/build.js +14 -20
  7. package/dist/{chunk-WXJPXYHF.mjs → chunk-2RMUO4GG.js} +3 -5
  8. package/dist/chunk-36OA7HRF.cjs +598 -0
  9. package/dist/chunk-3GQAWCBQ.js +13 -0
  10. package/dist/{chunk-BUCFGCTW.js → chunk-4AWYDOEH.cjs} +5 -7
  11. package/dist/chunk-ADWBQYE6.cjs +27 -0
  12. package/dist/chunk-BE5U4XRE.js +63 -0
  13. package/dist/{chunk-SQOZCV36.js → chunk-D5YXD4XE.cjs} +2 -4
  14. package/dist/{chunk-4ENAOJ33.mjs → chunk-ESRR2FD2.js} +2 -4
  15. package/dist/chunk-HYDGJLPG.cjs +2495 -0
  16. package/dist/{chunk-4BAUMYRN.mjs → chunk-JKBKJSU6.js} +2 -4
  17. package/dist/{chunk-PVZYPNLZ.js → chunk-KUMAH6IZ.cjs} +6 -8
  18. package/dist/chunk-LUXNRUAP.cjs +63 -0
  19. package/dist/chunk-ORA4UQMU.cjs +1 -0
  20. package/dist/chunk-OULCUN6I.js +0 -0
  21. package/dist/{chunk-6UMHN4KS.mjs → chunk-RHYLM6VP.js} +3 -5
  22. package/dist/chunk-RWW6C7JH.js +598 -0
  23. package/dist/{chunk-P6LWSWAQ.js → chunk-SHHAZOHN.cjs} +2 -4
  24. package/dist/chunk-T2Q5LQOI.js +2494 -0
  25. package/dist/{chunk-ESGPHEWU.mjs → chunk-T6BV33KD.js} +6 -8
  26. package/dist/chunk-YDYGZTJK.cjs +18 -0
  27. package/dist/clean.cjs +10 -0
  28. package/dist/clean.js +10 -10
  29. package/dist/config.cjs +12 -0
  30. package/dist/{config.d.mts → config.d.cts} +1 -1
  31. package/dist/config.js +12 -12
  32. package/dist/index.cjs +28 -0
  33. package/dist/{index.d.mts → index.d.cts} +4 -4
  34. package/dist/index.js +28 -39
  35. package/dist/types.cjs +2 -0
  36. package/dist/types.js +1 -2
  37. package/package.json +38 -37
  38. package/bin/unbuild.mjs +0 -63530
  39. package/dist/build.mjs +0 -20
  40. package/dist/chunk-3TNHGERR.mjs +0 -49
  41. package/dist/chunk-44VTNVZA.js +0 -29
  42. package/dist/chunk-45FJ3WQ6.js +0 -7528
  43. package/dist/chunk-4HFICKAT.js +0 -451
  44. package/dist/chunk-4IU7LXNH.mjs +0 -4054
  45. package/dist/chunk-523YIUTF.js +0 -19937
  46. package/dist/chunk-7G3WYTPJ.js +0 -6
  47. package/dist/chunk-AMTVM7UD.js +0 -4054
  48. package/dist/chunk-DIRFSBOA.mjs +0 -84
  49. package/dist/chunk-EGCWTBMT.mjs +0 -1120
  50. package/dist/chunk-EKTZK3IJ.mjs +0 -765
  51. package/dist/chunk-FAXWFK7Q.mjs +0 -7528
  52. package/dist/chunk-G6BE6UP3.mjs +0 -2481
  53. package/dist/chunk-K5SQO3GD.mjs +0 -451
  54. package/dist/chunk-MCNTIU52.js +0 -3050
  55. package/dist/chunk-NMYL4VJJ.js +0 -84
  56. package/dist/chunk-NOVWJHZD.mjs +0 -6
  57. package/dist/chunk-Q4GMTWGF.mjs +0 -19937
  58. package/dist/chunk-RBSVNX4W.js +0 -49
  59. package/dist/chunk-RM7SW35Z.js +0 -1120
  60. package/dist/chunk-S532A3LO.js +0 -510
  61. package/dist/chunk-TEEYWCSY.mjs +0 -3050
  62. package/dist/chunk-VJI72AA6.mjs +0 -510
  63. package/dist/chunk-W7YS7HE5.js +0 -765
  64. package/dist/chunk-YIP6AERX.js +0 -2484
  65. package/dist/clean.mjs +0 -10
  66. package/dist/config.mjs +0 -12
  67. package/dist/dist-JWSUGJW5.js +0 -17571
  68. package/dist/dist-LXRVOZWD.mjs +0 -17570
  69. package/dist/esm-2JSYGY2W.js +0 -1716
  70. package/dist/esm-2LICJFKF.mjs +0 -1716
  71. package/dist/execa-2KYLC5PR.mjs +0 -2424
  72. package/dist/execa-QRX32ES4.js +0 -2424
  73. package/dist/index.mjs +0 -39
  74. package/dist/json5-JI6Y4EBT.mjs +0 -10
  75. package/dist/json5-ZRUT32KA.js +0 -10
  76. package/dist/jsonc-2MC7UMCL.js +0 -15
  77. package/dist/jsonc-PDDMSRDH.mjs +0 -15
  78. package/dist/multipart-parser-FQDS23TV.mjs +0 -187
  79. package/dist/multipart-parser-IX66WIWH.js +0 -187
  80. package/dist/toml-IHKP66UV.mjs +0 -10
  81. package/dist/toml-MDHAEB3G.js +0 -10
  82. package/dist/types.mjs +0 -2
  83. package/dist/yaml-GMY56OHD.mjs +0 -10
  84. package/dist/yaml-UTMAXQ2T.js +0 -10
  85. /package/dist/{clean.d.mts → clean.d.cts} +0 -0
  86. /package/dist/{types.d.mts → types.d.cts} +0 -0
@@ -0,0 +1,2495 @@
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(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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
+ var _chunkKUMAH6IZcjs = require('./chunk-KUMAH6IZ.cjs');
4
+
5
+
6
+ var _chunkADWBQYE6cjs = require('./chunk-ADWBQYE6.cjs');
7
+
8
+
9
+ var _chunkLUXNRUAPcjs = require('./chunk-LUXNRUAP.cjs');
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ var _chunk36OA7HRFcjs = require('./chunk-36OA7HRF.cjs');
32
+
33
+
34
+
35
+ var _chunkYDYGZTJKcjs = require('./chunk-YDYGZTJK.cjs');
36
+
37
+ // src/build.ts
38
+ var _devkit = require('@nx/devkit');
39
+ var _js = require('@nx/js');
40
+ var _buildablelibsutils = require('@nx/js/src/utils/buildable-libs-utils');
41
+
42
+ // ../build-tools/src/plugins/swc.ts
43
+ var _core = require('@swc/core');
44
+
45
+ // ../build-tools/src/plugins/ts-resolve.ts
46
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
47
+ var _module = require('module'); var _module2 = _interopRequireDefault(_module);
48
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
49
+ var _resolve2 = require('resolve'); var _resolve3 = _interopRequireDefault(_resolve2);
50
+
51
+ // ../build-tools/src/plugins/type-definitions.ts
52
+
53
+
54
+
55
+ // ../build-tools/src/utilities/copy-assets.ts
56
+
57
+
58
+
59
+ // ../config-tools/src/logger/create-logger.ts
60
+ var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
61
+ async function createLogger(config) {
62
+ const workspaceRoot = _chunk36OA7HRFcjs.findWorkspaceRoot.call(void 0, );
63
+ if (!workspaceRoot) {
64
+ throw new Error("Cannot find workspace root");
65
+ }
66
+ const writeFatal = _chunk36OA7HRFcjs.getLogFn.call(void 0, _chunk36OA7HRFcjs.LogLevel.FATAL, config, _chalk2.default);
67
+ const writeError = _chunk36OA7HRFcjs.getLogFn.call(void 0, _chunk36OA7HRFcjs.LogLevel.ERROR, config, _chalk2.default);
68
+ const writeWarning2 = _chunk36OA7HRFcjs.getLogFn.call(void 0, _chunk36OA7HRFcjs.LogLevel.WARN, config, _chalk2.default);
69
+ const writeInfo = _chunk36OA7HRFcjs.getLogFn.call(void 0, _chunk36OA7HRFcjs.LogLevel.INFO, config, _chalk2.default);
70
+ const writeSuccess = _chunk36OA7HRFcjs.getLogFn.call(void 0, _chunk36OA7HRFcjs.LogLevel.SUCCESS, config, _chalk2.default);
71
+ const writeDebug2 = _chunk36OA7HRFcjs.getLogFn.call(void 0, _chunk36OA7HRFcjs.LogLevel.DEBUG, config, _chalk2.default);
72
+ const writeTrace2 = _chunk36OA7HRFcjs.getLogFn.call(void 0, _chunk36OA7HRFcjs.LogLevel.DEBUG, config, _chalk2.default);
73
+ return {
74
+ fatal: writeFatal,
75
+ error: writeError,
76
+ warning: writeWarning2,
77
+ info: writeInfo,
78
+ success: writeSuccess,
79
+ debug: writeDebug2,
80
+ trace: writeTrace2,
81
+ getStopwatch: _chunk36OA7HRFcjs.getStopwatch
82
+ };
83
+ }
84
+ _chunkYDYGZTJKcjs.__name.call(void 0, createLogger, "createLogger");
85
+
86
+ // ../build-tools/src/utilities/copy-assets.ts
87
+ var _glob = require('glob');
88
+ var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
89
+
90
+ // ../config-tools/src/config-file/get-config-file.ts
91
+ var _c12 = require('c12');
92
+ var _defu = require('defu'); var _defu2 = _interopRequireDefault(_defu);
93
+ var getConfigFileByName = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (fileName, filePath, options = {}) => {
94
+ const workspacePath = filePath || _chunk36OA7HRFcjs.findWorkspaceRoot.call(void 0, filePath);
95
+ let config = await _c12.loadConfig.call(void 0, {
96
+ cwd: workspacePath,
97
+ packageJson: true,
98
+ name: fileName,
99
+ envName: _optionalChain([fileName, 'optionalAccess', _2 => _2.toUpperCase, 'call', _3 => _3()]),
100
+ jitiOptions: {
101
+ debug: false,
102
+ fsCache: process.env.STORM_SKIP_CACHE === "true" ? false : _chunk36OA7HRFcjs.joinPaths.call(void 0, process.env.STORM_CACHE_DIR || "node_modules/.cache/storm", "jiti")
103
+ },
104
+ ...options
105
+ });
106
+ if (!config || Object.keys(config).length === 0) {
107
+ config = await _c12.loadConfig.call(void 0, {
108
+ cwd: workspacePath,
109
+ packageJson: true,
110
+ name: fileName,
111
+ envName: _optionalChain([fileName, 'optionalAccess', _4 => _4.toUpperCase, 'call', _5 => _5()]),
112
+ jitiOptions: {
113
+ debug: false,
114
+ fsCache: process.env.STORM_SKIP_CACHE === "true" ? false : _chunk36OA7HRFcjs.joinPaths.call(void 0, process.env.STORM_CACHE_DIR || "node_modules/.cache/storm", "jiti")
115
+ },
116
+ configFile: fileName,
117
+ ...options
118
+ });
119
+ }
120
+ return config;
121
+ }, "getConfigFileByName");
122
+ var getConfigFile = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (filePath, additionalFileNames = []) => {
123
+ const workspacePath = filePath ? filePath : _chunk36OA7HRFcjs.findWorkspaceRoot.call(void 0, filePath);
124
+ const result = await getConfigFileByName("storm", workspacePath);
125
+ let config = result.config;
126
+ const configFile = result.configFile;
127
+ if (config && configFile && Object.keys(config).length > 0) {
128
+ _chunk36OA7HRFcjs.writeSystem.call(void 0, `Found Storm configuration file "${configFile.includes(`${workspacePath}/`) ? configFile.replace(`${workspacePath}/`, "") : configFile}" at "${workspacePath}"`, {
129
+ logLevel: "all"
130
+ });
131
+ }
132
+ if (additionalFileNames && additionalFileNames.length > 0) {
133
+ const results = await Promise.all(additionalFileNames.map((fileName) => getConfigFileByName(fileName, workspacePath)));
134
+ for (const result2 of results) {
135
+ if (_optionalChain([result2, 'optionalAccess', _6 => _6.config]) && _optionalChain([result2, 'optionalAccess', _7 => _7.configFile]) && Object.keys(result2.config).length > 0) {
136
+ _chunk36OA7HRFcjs.writeSystem.call(void 0, `Found alternative configuration file "${result2.configFile.includes(`${workspacePath}/`) ? result2.configFile.replace(`${workspacePath}/`, "") : result2.configFile}" at "${workspacePath}"`, {
137
+ logLevel: "all"
138
+ });
139
+ config = _defu2.default.call(void 0, _nullishCoalesce(result2.config, () => ( {})), _nullishCoalesce(config, () => ( {})));
140
+ }
141
+ }
142
+ }
143
+ if (!config) {
144
+ return void 0;
145
+ }
146
+ config.configFile = configFile;
147
+ return config;
148
+ }, "getConfigFile");
149
+
150
+ // ../config-tools/src/create-storm-config.ts
151
+
152
+
153
+ // ../config-tools/src/env/get-env.ts
154
+ var getConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, () => {
155
+ const prefix = "STORM_";
156
+ let config = {
157
+ extends: process.env[`${prefix}EXTENDS`] || void 0,
158
+ name: process.env[`${prefix}NAME`] || void 0,
159
+ namespace: process.env[`${prefix}NAMESPACE`] || void 0,
160
+ owner: process.env[`${prefix}OWNER`] || void 0,
161
+ bot: {
162
+ name: process.env[`${prefix}BOT_NAME`] || void 0,
163
+ email: process.env[`${prefix}BOT_EMAIL`] || void 0
164
+ },
165
+ organization: process.env[`${prefix}ORGANIZATION`] || void 0,
166
+ packageManager: process.env[`${prefix}PACKAGE_MANAGER`] || void 0,
167
+ license: process.env[`${prefix}LICENSE`] || void 0,
168
+ homepage: process.env[`${prefix}HOMEPAGE`] || void 0,
169
+ docs: process.env[`${prefix}DOCS`] || void 0,
170
+ licensing: process.env[`${prefix}LICENSING`] || void 0,
171
+ timezone: process.env[`${prefix}TIMEZONE`] || process.env.TZ || void 0,
172
+ locale: process.env[`${prefix}LOCALE`] || process.env.LOCALE || void 0,
173
+ configFile: process.env[`${prefix}CONFIG_FILE`] ? _chunk36OA7HRFcjs.correctPaths.call(void 0, process.env[`${prefix}CONFIG_FILE`]) : void 0,
174
+ workspaceRoot: process.env[`${prefix}WORKSPACE_ROOT`] ? _chunk36OA7HRFcjs.correctPaths.call(void 0, process.env[`${prefix}WORKSPACE_ROOT`]) : void 0,
175
+ directories: {
176
+ cache: process.env[`${prefix}CACHE_DIR`] ? _chunk36OA7HRFcjs.correctPaths.call(void 0, process.env[`${prefix}CACHE_DIR`]) : void 0,
177
+ data: process.env[`${prefix}DATA_DIR`] ? _chunk36OA7HRFcjs.correctPaths.call(void 0, process.env[`${prefix}DATA_DIR`]) : void 0,
178
+ config: process.env[`${prefix}CONFIG_DIR`] ? _chunk36OA7HRFcjs.correctPaths.call(void 0, process.env[`${prefix}CONFIG_DIR`]) : void 0,
179
+ temp: process.env[`${prefix}TEMP_DIR`] ? _chunk36OA7HRFcjs.correctPaths.call(void 0, process.env[`${prefix}TEMP_DIR`]) : void 0,
180
+ log: process.env[`${prefix}LOG_DIR`] ? _chunk36OA7HRFcjs.correctPaths.call(void 0, process.env[`${prefix}LOG_DIR`]) : void 0,
181
+ build: process.env[`${prefix}BUILD_DIR`] ? _chunk36OA7HRFcjs.correctPaths.call(void 0, process.env[`${prefix}BUILD_DIR`]) : void 0
182
+ },
183
+ skipCache: process.env[`${prefix}SKIP_CACHE`] !== void 0 ? Boolean(process.env[`${prefix}SKIP_CACHE`]) : void 0,
184
+ env: (_nullishCoalesce(_nullishCoalesce(process.env[`${prefix}ENV`], () => ( process.env.NODE_ENV)), () => ( process.env.ENVIRONMENT))) || void 0,
185
+ // ci:
186
+ // process.env[`${prefix}CI`] !== undefined
187
+ // ? Boolean(
188
+ // process.env[`${prefix}CI`] ??
189
+ // process.env.CI ??
190
+ // process.env.CONTINUOUS_INTEGRATION
191
+ // )
192
+ // : undefined,
193
+ repository: process.env[`${prefix}REPOSITORY`] || void 0,
194
+ branch: process.env[`${prefix}BRANCH`] || void 0,
195
+ preid: process.env[`${prefix}PRE_ID`] || void 0,
196
+ externalPackagePatterns: process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] ? JSON.parse(process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`]) : [],
197
+ registry: {
198
+ github: process.env[`${prefix}REGISTRY_GITHUB`] || void 0,
199
+ npm: process.env[`${prefix}REGISTRY_NPM`] || void 0,
200
+ cargo: process.env[`${prefix}REGISTRY_CARGO`] || void 0,
201
+ cyclone: process.env[`${prefix}REGISTRY_CYCLONE`] || void 0,
202
+ container: process.env[`${prefix}REGISTRY_CONTAINER`] || void 0
203
+ },
204
+ 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`])) ? _chunk36OA7HRFcjs.getLogLevelLabel.call(void 0, Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) : process.env[`${prefix}LOG_LEVEL`] : void 0
205
+ };
206
+ const themeNames = Object.keys(process.env).filter((envKey) => envKey.startsWith(`${prefix}COLOR_`) && _chunk36OA7HRFcjs.COLOR_KEYS.every((colorKey) => !envKey.startsWith(`${prefix}COLOR_LIGHT_${colorKey}`) && !envKey.startsWith(`${prefix}COLOR_DARK_${colorKey}`)));
207
+ config.colors = themeNames.length > 0 ? themeNames.reduce((ret, themeName) => {
208
+ ret[themeName] = getThemeColorConfigEnv(prefix, themeName);
209
+ return ret;
210
+ }, {}) : getThemeColorConfigEnv(prefix);
211
+ if (config.docs === _chunk36OA7HRFcjs.STORM_DEFAULT_DOCS) {
212
+ if (config.homepage === _chunk36OA7HRFcjs.STORM_DEFAULT_HOMEPAGE) {
213
+ config.docs = `${_chunk36OA7HRFcjs.STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/docs`;
214
+ } else {
215
+ config.docs = `${config.homepage}/docs`;
216
+ }
217
+ }
218
+ if (config.licensing === _chunk36OA7HRFcjs.STORM_DEFAULT_LICENSING) {
219
+ if (config.homepage === _chunk36OA7HRFcjs.STORM_DEFAULT_HOMEPAGE) {
220
+ config.licensing = `${_chunk36OA7HRFcjs.STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/licensing`;
221
+ } else {
222
+ config.licensing = `${config.homepage}/docs`;
223
+ }
224
+ }
225
+ const serializedConfig = process.env[`${prefix}CONFIG`];
226
+ if (serializedConfig) {
227
+ const parsed = JSON.parse(serializedConfig);
228
+ config = {
229
+ ...config,
230
+ ...parsed,
231
+ colors: {
232
+ ...config.colors,
233
+ ...parsed.colors
234
+ },
235
+ extensions: {
236
+ ...config.extensions,
237
+ ...parsed.extensions
238
+ }
239
+ };
240
+ }
241
+ return config;
242
+ }, "getConfigEnv");
243
+ var getThemeColorConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (prefix, theme) => {
244
+ const themeName = `COLOR_${theme && theme !== "base" ? `${theme}_` : ""}`.toUpperCase();
245
+ return process.env[`${prefix}${themeName}LIGHT_BRAND`] || process.env[`${prefix}${themeName}DARK_BRAND`] ? getMultiThemeColorConfigEnv(prefix + themeName) : getSingleThemeColorConfigEnv(prefix + themeName);
246
+ }, "getThemeColorConfigEnv");
247
+ var getSingleThemeColorConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (prefix) => {
248
+ return {
249
+ dark: process.env[`${prefix}DARK`],
250
+ light: process.env[`${prefix}LIGHT`],
251
+ brand: process.env[`${prefix}BRAND`],
252
+ alternate: process.env[`${prefix}ALTERNATE`],
253
+ accent: process.env[`${prefix}ACCENT`],
254
+ link: process.env[`${prefix}LINK`],
255
+ help: process.env[`${prefix}HELP`],
256
+ success: process.env[`${prefix}SUCCESS`],
257
+ info: process.env[`${prefix}INFO`],
258
+ warning: process.env[`${prefix}WARNING`],
259
+ danger: process.env[`${prefix}DANGER`],
260
+ fatal: process.env[`${prefix}FATAL`],
261
+ positive: process.env[`${prefix}POSITIVE`],
262
+ negative: process.env[`${prefix}NEGATIVE`]
263
+ };
264
+ }, "getSingleThemeColorConfigEnv");
265
+ var getMultiThemeColorConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (prefix) => {
266
+ return {
267
+ light: getBaseThemeColorConfigEnv(`${prefix}_LIGHT_`),
268
+ dark: getBaseThemeColorConfigEnv(`${prefix}_DARK_`)
269
+ };
270
+ }, "getMultiThemeColorConfigEnv");
271
+ var getBaseThemeColorConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (prefix) => {
272
+ return {
273
+ foreground: process.env[`${prefix}FOREGROUND`],
274
+ background: process.env[`${prefix}BACKGROUND`],
275
+ brand: process.env[`${prefix}BRAND`],
276
+ alternate: process.env[`${prefix}ALTERNATE`],
277
+ accent: process.env[`${prefix}ACCENT`],
278
+ link: process.env[`${prefix}LINK`],
279
+ help: process.env[`${prefix}HELP`],
280
+ success: process.env[`${prefix}SUCCESS`],
281
+ info: process.env[`${prefix}INFO`],
282
+ warning: process.env[`${prefix}WARNING`],
283
+ danger: process.env[`${prefix}DANGER`],
284
+ fatal: process.env[`${prefix}FATAL`],
285
+ positive: process.env[`${prefix}POSITIVE`],
286
+ negative: process.env[`${prefix}NEGATIVE`]
287
+ };
288
+ }, "getBaseThemeColorConfigEnv");
289
+
290
+ // ../config-tools/src/env/set-env.ts
291
+ var setExtensionEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (extensionName, extension) => {
292
+ for (const key of Object.keys(_nullishCoalesce(extension, () => ( {})))) {
293
+ if (extension[key]) {
294
+ const result = _nullishCoalesce(_optionalChain([key, 'optionalAccess', _8 => _8.replace, 'call', _9 => _9(/([A-Z])+/g, (input) => input ? _optionalChain([input, 'access', _10 => _10[0], 'optionalAccess', _11 => _11.toUpperCase, 'call', _12 => _12()]) + input.slice(1) : ""), 'access', _13 => _13.split, 'call', _14 => _14(/(?=[A-Z])|[.\-\s_]/), 'access', _15 => _15.map, 'call', _16 => _16((x) => x.toLowerCase())]), () => ( []));
295
+ let extensionKey;
296
+ if (result.length === 0) {
297
+ return;
298
+ }
299
+ if (result.length === 1) {
300
+ extensionKey = _nullishCoalesce(_optionalChain([result, 'access', _17 => _17[0], 'optionalAccess', _18 => _18.toUpperCase, 'call', _19 => _19()]), () => ( ""));
301
+ } else {
302
+ extensionKey = result.reduce((ret, part) => {
303
+ return `${ret}_${part.toLowerCase()}`;
304
+ });
305
+ }
306
+ process.env[`STORM_EXTENSION_${extensionName.toUpperCase()}_${extensionKey.toUpperCase()}`] = extension[key];
307
+ }
308
+ }
309
+ }, "setExtensionEnv");
310
+ var setConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (config) => {
311
+ const prefix = "STORM_";
312
+ if (config.extends) {
313
+ process.env[`${prefix}EXTENDS`] = config.extends;
314
+ }
315
+ if (config.name) {
316
+ process.env[`${prefix}NAME`] = config.name;
317
+ }
318
+ if (config.namespace) {
319
+ process.env[`${prefix}NAMESPACE`] = config.namespace;
320
+ }
321
+ if (config.owner) {
322
+ process.env[`${prefix}OWNER`] = config.owner;
323
+ }
324
+ if (config.bot) {
325
+ process.env[`${prefix}BOT_NAME`] = config.bot.name;
326
+ process.env[`${prefix}BOT_EMAIL`] = config.bot.email;
327
+ }
328
+ if (config.organization) {
329
+ process.env[`${prefix}ORGANIZATION`] = config.organization;
330
+ }
331
+ if (config.packageManager) {
332
+ process.env[`${prefix}PACKAGE_MANAGER`] = config.packageManager;
333
+ }
334
+ if (config.license) {
335
+ process.env[`${prefix}LICENSE`] = config.license;
336
+ }
337
+ if (config.homepage) {
338
+ process.env[`${prefix}HOMEPAGE`] = config.homepage;
339
+ }
340
+ if (config.docs) {
341
+ process.env[`${prefix}DOCS`] = config.docs;
342
+ }
343
+ if (config.licensing) {
344
+ process.env[`${prefix}LICENSING`] = config.licensing;
345
+ }
346
+ if (config.timezone) {
347
+ process.env[`${prefix}TIMEZONE`] = config.timezone;
348
+ process.env.TZ = config.timezone;
349
+ process.env.DEFAULT_TIMEZONE = config.timezone;
350
+ }
351
+ if (config.locale) {
352
+ process.env[`${prefix}LOCALE`] = config.locale;
353
+ process.env.LOCALE = config.locale;
354
+ process.env.DEFAULT_LOCALE = config.locale;
355
+ process.env.LANG = config.locale ? `${config.locale.replaceAll("-", "_")}.UTF-8` : "en_US.UTF-8";
356
+ }
357
+ if (config.configFile) {
358
+ process.env[`${prefix}CONFIG_FILE`] = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.configFile);
359
+ }
360
+ if (config.workspaceRoot) {
361
+ process.env[`${prefix}WORKSPACE_ROOT`] = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.workspaceRoot);
362
+ process.env.NX_WORKSPACE_ROOT = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.workspaceRoot);
363
+ process.env.NX_WORKSPACE_ROOT_PATH = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.workspaceRoot);
364
+ }
365
+ if (config.directories) {
366
+ if (!config.skipCache && config.directories.cache) {
367
+ process.env[`${prefix}CACHE_DIR`] = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.directories.cache);
368
+ }
369
+ if (config.directories.data) {
370
+ process.env[`${prefix}DATA_DIR`] = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.directories.data);
371
+ }
372
+ if (config.directories.config) {
373
+ process.env[`${prefix}CONFIG_DIR`] = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.directories.config);
374
+ }
375
+ if (config.directories.temp) {
376
+ process.env[`${prefix}TEMP_DIR`] = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.directories.temp);
377
+ }
378
+ if (config.directories.log) {
379
+ process.env[`${prefix}LOG_DIR`] = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.directories.log);
380
+ }
381
+ if (config.directories.build) {
382
+ process.env[`${prefix}BUILD_DIR`] = _chunk36OA7HRFcjs.correctPaths.call(void 0, config.directories.build);
383
+ }
384
+ }
385
+ if (config.skipCache !== void 0) {
386
+ process.env[`${prefix}SKIP_CACHE`] = String(config.skipCache);
387
+ if (config.skipCache) {
388
+ process.env.NX_SKIP_NX_CACHE ??= String(config.skipCache);
389
+ process.env.NX_CACHE_PROJECT_GRAPH ??= String(config.skipCache);
390
+ }
391
+ }
392
+ if (config.env) {
393
+ process.env[`${prefix}ENV`] = config.env;
394
+ process.env.NODE_ENV = config.env;
395
+ process.env.ENVIRONMENT = config.env;
396
+ }
397
+ if (_optionalChain([config, 'access', _20 => _20.colors, 'optionalAccess', _21 => _21.base, 'optionalAccess', _22 => _22.light]) || _optionalChain([config, 'access', _23 => _23.colors, 'optionalAccess', _24 => _24.base, 'optionalAccess', _25 => _25.dark])) {
398
+ for (const key of Object.keys(config.colors)) {
399
+ setThemeColorConfigEnv(`${prefix}COLOR_${key}_`, config.colors[key]);
400
+ }
401
+ } else {
402
+ setThemeColorConfigEnv(`${prefix}COLOR_`, config.colors);
403
+ }
404
+ if (config.repository) {
405
+ process.env[`${prefix}REPOSITORY`] = config.repository;
406
+ }
407
+ if (config.branch) {
408
+ process.env[`${prefix}BRANCH`] = config.branch;
409
+ }
410
+ if (config.preid) {
411
+ process.env[`${prefix}PRE_ID`] = String(config.preid);
412
+ }
413
+ if (config.externalPackagePatterns) {
414
+ process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] = JSON.stringify(config.externalPackagePatterns);
415
+ }
416
+ if (config.registry) {
417
+ if (config.registry.github) {
418
+ process.env[`${prefix}REGISTRY_GITHUB`] = String(config.registry.github);
419
+ }
420
+ if (config.registry.npm) {
421
+ process.env[`${prefix}REGISTRY_NPM`] = String(config.registry.npm);
422
+ }
423
+ if (config.registry.cargo) {
424
+ process.env[`${prefix}REGISTRY_CARGO`] = String(config.registry.cargo);
425
+ }
426
+ if (config.registry.cyclone) {
427
+ process.env[`${prefix}REGISTRY_CYCLONE`] = String(config.registry.cyclone);
428
+ }
429
+ if (config.registry.container) {
430
+ process.env[`${prefix}REGISTRY_CONTAINER`] = String(config.registry.cyclone);
431
+ }
432
+ }
433
+ if (config.logLevel) {
434
+ process.env[`${prefix}LOG_LEVEL`] = String(config.logLevel);
435
+ process.env.LOG_LEVEL = String(config.logLevel);
436
+ process.env.NX_VERBOSE_LOGGING = String(_chunk36OA7HRFcjs.getLogLevel.call(void 0, config.logLevel) >= _chunk36OA7HRFcjs.LogLevel.DEBUG ? true : false);
437
+ process.env.RUST_BACKTRACE = _chunk36OA7HRFcjs.getLogLevel.call(void 0, config.logLevel) >= _chunk36OA7HRFcjs.LogLevel.DEBUG ? "full" : "none";
438
+ }
439
+ process.env[`${prefix}CONFIG`] = JSON.stringify(config);
440
+ for (const key of Object.keys(_nullishCoalesce(config.extensions, () => ( {})))) {
441
+ config.extensions[key] && Object.keys(config.extensions[key]) && setExtensionEnv(key, config.extensions[key]);
442
+ }
443
+ }, "setConfigEnv");
444
+ var setThemeColorConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (prefix, config) => {
445
+ return _optionalChain([config, 'optionalAccess', _26 => _26.light, 'optionalAccess', _27 => _27.brand]) || _optionalChain([config, 'optionalAccess', _28 => _28.dark, 'optionalAccess', _29 => _29.brand]) ? setMultiThemeColorConfigEnv(prefix, config) : setSingleThemeColorConfigEnv(prefix, config);
446
+ }, "setThemeColorConfigEnv");
447
+ var setSingleThemeColorConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (prefix, config) => {
448
+ if (config.dark) {
449
+ process.env[`${prefix}DARK`] = config.dark;
450
+ }
451
+ if (config.light) {
452
+ process.env[`${prefix}LIGHT`] = config.light;
453
+ }
454
+ if (config.brand) {
455
+ process.env[`${prefix}BRAND`] = config.brand;
456
+ }
457
+ if (config.alternate) {
458
+ process.env[`${prefix}ALTERNATE`] = config.alternate;
459
+ }
460
+ if (config.accent) {
461
+ process.env[`${prefix}ACCENT`] = config.accent;
462
+ }
463
+ if (config.link) {
464
+ process.env[`${prefix}LINK`] = config.link;
465
+ }
466
+ if (config.help) {
467
+ process.env[`${prefix}HELP`] = config.help;
468
+ }
469
+ if (config.success) {
470
+ process.env[`${prefix}SUCCESS`] = config.success;
471
+ }
472
+ if (config.info) {
473
+ process.env[`${prefix}INFO`] = config.info;
474
+ }
475
+ if (config.warning) {
476
+ process.env[`${prefix}WARNING`] = config.warning;
477
+ }
478
+ if (config.danger) {
479
+ process.env[`${prefix}DANGER`] = config.danger;
480
+ }
481
+ if (config.fatal) {
482
+ process.env[`${prefix}FATAL`] = config.fatal;
483
+ }
484
+ if (config.positive) {
485
+ process.env[`${prefix}POSITIVE`] = config.positive;
486
+ }
487
+ if (config.negative) {
488
+ process.env[`${prefix}NEGATIVE`] = config.negative;
489
+ }
490
+ }, "setSingleThemeColorConfigEnv");
491
+ var setMultiThemeColorConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (prefix, config) => {
492
+ return {
493
+ light: setBaseThemeColorConfigEnv(`${prefix}LIGHT_`, config.light),
494
+ dark: setBaseThemeColorConfigEnv(`${prefix}DARK_`, config.dark)
495
+ };
496
+ }, "setMultiThemeColorConfigEnv");
497
+ var setBaseThemeColorConfigEnv = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (prefix, config) => {
498
+ if (config.foreground) {
499
+ process.env[`${prefix}FOREGROUND`] = config.foreground;
500
+ }
501
+ if (config.background) {
502
+ process.env[`${prefix}BACKGROUND`] = config.background;
503
+ }
504
+ if (config.brand) {
505
+ process.env[`${prefix}BRAND`] = config.brand;
506
+ }
507
+ if (config.alternate) {
508
+ process.env[`${prefix}ALTERNATE`] = config.alternate;
509
+ }
510
+ if (config.accent) {
511
+ process.env[`${prefix}ACCENT`] = config.accent;
512
+ }
513
+ if (config.link) {
514
+ process.env[`${prefix}LINK`] = config.link;
515
+ }
516
+ if (config.help) {
517
+ process.env[`${prefix}HELP`] = config.help;
518
+ }
519
+ if (config.success) {
520
+ process.env[`${prefix}SUCCESS`] = config.success;
521
+ }
522
+ if (config.info) {
523
+ process.env[`${prefix}INFO`] = config.info;
524
+ }
525
+ if (config.warning) {
526
+ process.env[`${prefix}WARNING`] = config.warning;
527
+ }
528
+ if (config.danger) {
529
+ process.env[`${prefix}DANGER`] = config.danger;
530
+ }
531
+ if (config.fatal) {
532
+ process.env[`${prefix}FATAL`] = config.fatal;
533
+ }
534
+ if (config.positive) {
535
+ process.env[`${prefix}POSITIVE`] = config.positive;
536
+ }
537
+ if (config.negative) {
538
+ process.env[`${prefix}NEGATIVE`] = config.negative;
539
+ }
540
+ }, "setBaseThemeColorConfigEnv");
541
+
542
+ // ../config-tools/src/create-storm-config.ts
543
+ var _static_cache = void 0;
544
+ var loadStormConfig = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (workspaceRoot) => {
545
+ let config = {};
546
+ if (_optionalChain([_static_cache, 'optionalAccess', _30 => _30.data]) && _optionalChain([_static_cache, 'optionalAccess', _31 => _31.timestamp]) && _static_cache.timestamp >= Date.now() + 3e4) {
547
+ _chunk36OA7HRFcjs.writeTrace.call(void 0, `Configuration cache hit - ${_static_cache.timestamp}`, _static_cache.data);
548
+ return _static_cache.data;
549
+ }
550
+ let _workspaceRoot = workspaceRoot;
551
+ if (!_workspaceRoot) {
552
+ _workspaceRoot = _chunk36OA7HRFcjs.findWorkspaceRoot.call(void 0, );
553
+ }
554
+ const configFile = await getConfigFile(_workspaceRoot);
555
+ if (!configFile) {
556
+ _chunk36OA7HRFcjs.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", {
557
+ logLevel: "all"
558
+ });
559
+ }
560
+ config = _defu2.default.call(void 0, getConfigEnv(), configFile, _chunk36OA7HRFcjs.getDefaultConfig.call(void 0, _workspaceRoot));
561
+ setConfigEnv(config);
562
+ _chunk36OA7HRFcjs.writeTrace.call(void 0, `\u2699\uFE0F Using Storm configuration:
563
+ ${_chunk36OA7HRFcjs.formatLogMessage.call(void 0, config)}`, config);
564
+ return config;
565
+ }, "loadStormConfig");
566
+
567
+ // ../build-tools/src/utilities/read-nx-config.ts
568
+
569
+
570
+ var readNxConfig = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (workspaceRoot) => {
571
+ let rootDir = workspaceRoot;
572
+ if (!rootDir) {
573
+ const config = await loadStormConfig();
574
+ rootDir = config.workspaceRoot;
575
+ }
576
+ const nxJsonPath = _chunk36OA7HRFcjs.joinPaths.call(void 0, rootDir, "nx.json");
577
+ if (!_fs.existsSync.call(void 0, nxJsonPath)) {
578
+ throw new Error("Cannot find project.json configuration");
579
+ }
580
+ const configContent = await _promises.readFile.call(void 0, nxJsonPath, "utf8");
581
+ return JSON.parse(configContent);
582
+ }, "readNxConfig");
583
+
584
+ // ../build-tools/src/utilities/copy-assets.ts
585
+ var copyAssets = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (config, assets, outputPath, projectRoot, projectName, sourceRoot, generatePackageJson2 = true, includeSrc = false, banner, footer) => {
586
+ const pendingAssets = Array.from(_nullishCoalesce(assets, () => ( [])));
587
+ if (!_optionalChain([pendingAssets, 'optionalAccess', _32 => _32.some, 'call', _33 => _33((asset) => _optionalChain([asset, 'optionalAccess', _34 => _34.glob]) === "*.md")])) {
588
+ pendingAssets.push({
589
+ input: projectRoot,
590
+ glob: "*.md",
591
+ output: "/"
592
+ });
593
+ }
594
+ if (generatePackageJson2 === false) {
595
+ pendingAssets.push({
596
+ input: sourceRoot,
597
+ glob: "package.json",
598
+ output: "."
599
+ });
600
+ }
601
+ if (!_optionalChain([pendingAssets, 'optionalAccess', _35 => _35.some, 'call', _36 => _36((asset) => _optionalChain([asset, 'optionalAccess', _37 => _37.glob]) === "LICENSE")])) {
602
+ pendingAssets.push({
603
+ input: "",
604
+ glob: "LICENSE",
605
+ output: "."
606
+ });
607
+ }
608
+ if (includeSrc === true) {
609
+ pendingAssets.push({
610
+ input: sourceRoot,
611
+ glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
612
+ output: "src/"
613
+ });
614
+ }
615
+ const nxJson = readNxConfig(config.workspaceRoot);
616
+ const projectGraph = _devkit.readCachedProjectGraph.call(void 0, );
617
+ const projectsConfigurations = _devkit.readProjectsConfigurationFromProjectGraph.call(void 0, projectGraph);
618
+ if (!_optionalChain([projectsConfigurations, 'optionalAccess', _38 => _38.projects, 'optionalAccess', _39 => _39[projectName]])) {
619
+ 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.");
620
+ }
621
+ const buildTarget = _optionalChain([projectsConfigurations, 'access', _40 => _40.projects, 'access', _41 => _41[projectName], 'access', _42 => _42.targets, 'optionalAccess', _43 => _43.build]);
622
+ if (!buildTarget) {
623
+ 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 ${_chunk36OA7HRFcjs.joinPaths.call(void 0, projectRoot, "project.json")}`);
624
+ }
625
+ const result = await _js.copyAssets.call(void 0, {
626
+ assets,
627
+ watch: false,
628
+ outputPath
629
+ }, {
630
+ root: config.workspaceRoot,
631
+ targetName: "build",
632
+ target: buildTarget,
633
+ projectName,
634
+ projectGraph,
635
+ projectsConfigurations,
636
+ nxJsonConfiguration: nxJson,
637
+ cwd: config.workspaceRoot,
638
+ isVerbose: _chunk36OA7HRFcjs.isVerbose.call(void 0, config.logLevel)
639
+ });
640
+ if (!result.success) {
641
+ throw new Error("The Build process failed trying to copy assets");
642
+ }
643
+ if (includeSrc === true) {
644
+ _chunk36OA7HRFcjs.writeDebug.call(void 0, `\u{1F4DD} Adding banner and writing source files: ${_chunk36OA7HRFcjs.joinPaths.call(void 0, outputPath, "src")}`, config);
645
+ const files = await _glob.glob.call(void 0, [
646
+ _chunk36OA7HRFcjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.ts"),
647
+ _chunk36OA7HRFcjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.tsx"),
648
+ _chunk36OA7HRFcjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.js"),
649
+ _chunk36OA7HRFcjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.jsx")
650
+ ]);
651
+ await Promise.allSettled(files.map(async (file) => _promises.writeFile.call(void 0, file, `${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
652
+
653
+ ${await _promises.readFile.call(void 0, file, "utf8")}
654
+
655
+ ${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`)));
656
+ }
657
+ }, "copyAssets");
658
+
659
+ // ../build-tools/src/utilities/generate-package-json.ts
660
+
661
+
662
+
663
+
664
+ var _projectgraph = require('nx/src/project-graph/project-graph');
665
+ var addPackageDependencies = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (workspaceRoot, projectRoot, projectName, packageJson) => {
666
+ const projectDependencies = _buildablelibsutils.calculateProjectBuildableDependencies.call(void 0, void 0, _projectgraph.readCachedProjectGraph.call(void 0, ), workspaceRoot, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
667
+ const localPackages = [];
668
+ for (const project of projectDependencies.dependencies.filter((dep) => dep.node.type === "lib" && dep.node.data.root !== projectRoot && dep.node.data.root !== workspaceRoot)) {
669
+ const projectNode = project.node;
670
+ if (projectNode.data.root) {
671
+ const projectPackageJsonPath = _chunk36OA7HRFcjs.joinPaths.call(void 0, workspaceRoot, projectNode.data.root, "package.json");
672
+ if (_fs.existsSync.call(void 0, projectPackageJsonPath)) {
673
+ const projectPackageJsonContent = await _promises.readFile.call(void 0, projectPackageJsonPath, "utf8");
674
+ const projectPackageJson = JSON.parse(projectPackageJsonContent);
675
+ if (projectPackageJson.private !== false) {
676
+ localPackages.push(projectPackageJson);
677
+ }
678
+ }
679
+ }
680
+ }
681
+ if (localPackages.length > 0) {
682
+ _chunk36OA7HRFcjs.writeTrace.call(void 0, `\u{1F4E6} Adding local packages to package.json: ${localPackages.map((p) => p.name).join(", ")}`);
683
+ packageJson.peerDependencies = localPackages.reduce((ret, localPackage) => {
684
+ if (!ret[localPackage.name]) {
685
+ ret[localPackage.name] = `>=${localPackage.version || "0.0.1"}`;
686
+ }
687
+ return ret;
688
+ }, _nullishCoalesce(packageJson.peerDependencies, () => ( {})));
689
+ packageJson.peerDependenciesMeta = localPackages.reduce((ret, localPackage) => {
690
+ if (!ret[localPackage.name]) {
691
+ ret[localPackage.name] = {
692
+ optional: false
693
+ };
694
+ }
695
+ return ret;
696
+ }, _nullishCoalesce(packageJson.peerDependenciesMeta, () => ( {})));
697
+ packageJson.devDependencies = localPackages.reduce((ret, localPackage) => {
698
+ if (!ret[localPackage.name]) {
699
+ ret[localPackage.name] = localPackage.version || "0.0.1";
700
+ }
701
+ return ret;
702
+ }, _nullishCoalesce(packageJson.peerDependencies, () => ( {})));
703
+ } else {
704
+ _chunk36OA7HRFcjs.writeTrace.call(void 0, "\u{1F4E6} No local packages dependencies to add to package.json");
705
+ }
706
+ return packageJson;
707
+ }, "addPackageDependencies");
708
+ var addWorkspacePackageJsonFields = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (config, projectRoot, sourceRoot, projectName, includeSrc = false, packageJson) => {
709
+ const workspaceRoot = config.workspaceRoot ? config.workspaceRoot : _chunk36OA7HRFcjs.findWorkspaceRoot.call(void 0, );
710
+ const workspacePackageJsonContent = await _promises.readFile.call(void 0, _chunk36OA7HRFcjs.joinPaths.call(void 0, workspaceRoot, "package.json"), "utf8");
711
+ const workspacePackageJson = JSON.parse(workspacePackageJsonContent);
712
+ packageJson.type ??= "module";
713
+ packageJson.sideEffects ??= false;
714
+ if (includeSrc === true) {
715
+ let distSrc = sourceRoot.replace(projectRoot, "");
716
+ if (distSrc.startsWith("/")) {
717
+ distSrc = distSrc.substring(1);
718
+ }
719
+ packageJson.source ??= `${_chunk36OA7HRFcjs.joinPaths.call(void 0, distSrc, "index.ts").replaceAll("\\", "/")}`;
720
+ }
721
+ packageJson.files ??= [
722
+ "dist/**/*"
723
+ ];
724
+ if (includeSrc === true && !packageJson.files.includes("src")) {
725
+ packageJson.files.push("src/**/*");
726
+ }
727
+ packageJson.publishConfig ??= {
728
+ access: "public"
729
+ };
730
+ packageJson.description ??= workspacePackageJson.description;
731
+ packageJson.homepage ??= workspacePackageJson.homepage;
732
+ packageJson.bugs ??= workspacePackageJson.bugs;
733
+ packageJson.license ??= workspacePackageJson.license;
734
+ packageJson.keywords ??= workspacePackageJson.keywords;
735
+ packageJson.funding ??= workspacePackageJson.funding;
736
+ packageJson.author ??= workspacePackageJson.author;
737
+ packageJson.maintainers ??= workspacePackageJson.maintainers;
738
+ if (!packageJson.maintainers && packageJson.author) {
739
+ packageJson.maintainers = [
740
+ packageJson.author
741
+ ];
742
+ }
743
+ packageJson.contributors ??= workspacePackageJson.contributors;
744
+ if (!packageJson.contributors && packageJson.author) {
745
+ packageJson.contributors = [
746
+ packageJson.author
747
+ ];
748
+ }
749
+ packageJson.repository ??= workspacePackageJson.repository;
750
+ packageJson.repository.directory ??= projectRoot ? projectRoot : _chunk36OA7HRFcjs.joinPaths.call(void 0, "packages", projectName);
751
+ return packageJson;
752
+ }, "addWorkspacePackageJsonFields");
753
+ var addPackageJsonExport = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (file, type = "module", sourceRoot) => {
754
+ let entry = file.replaceAll("\\", "/");
755
+ if (sourceRoot) {
756
+ entry = entry.replace(sourceRoot, "");
757
+ }
758
+ return {
759
+ "import": {
760
+ "types": `./dist/${entry}.d.${type === "module" ? "ts" : "mts"}`,
761
+ "default": `./dist/${entry}.${type === "module" ? "js" : "mjs"}`
762
+ },
763
+ "require": {
764
+ "types": `./dist/${entry}.d.${type === "commonjs" ? "ts" : "cts"}`,
765
+ "default": `./dist/${entry}.${type === "commonjs" ? "js" : "cjs"}`
766
+ },
767
+ "default": {
768
+ "types": `./dist/${entry}.d.ts`,
769
+ "default": `./dist/${entry}.js`
770
+ }
771
+ };
772
+ }, "addPackageJsonExport");
773
+ var addPackageJsonExports = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (sourceRoot, packageJson) => {
774
+ packageJson.exports ??= {};
775
+ const files = await new (0, _glob.Glob)("**/*.{ts,tsx}", {
776
+ absolute: false,
777
+ cwd: sourceRoot,
778
+ root: sourceRoot
779
+ }).walk();
780
+ files.forEach((file) => {
781
+ addPackageJsonExport(file, packageJson.type, sourceRoot);
782
+ const split = file.split(".");
783
+ split.pop();
784
+ const entry = split.join(".").replaceAll("\\", "/");
785
+ packageJson.exports[`./${entry}`] ??= addPackageJsonExport(entry, packageJson.type, sourceRoot);
786
+ });
787
+ packageJson.main = packageJson.type === "commonjs" ? "./dist/index.js" : "./dist/index.cjs";
788
+ packageJson.module = packageJson.type === "module" ? "./dist/index.js" : "./dist/index.mjs";
789
+ packageJson.types = "./dist/index.d.ts";
790
+ packageJson.exports ??= {};
791
+ packageJson.exports = Object.keys(packageJson.exports).reduce((ret, key) => {
792
+ if (key.endsWith("/index") && !ret[key.replace("/index", "")]) {
793
+ ret[key.replace("/index", "")] = packageJson.exports[key];
794
+ }
795
+ return ret;
796
+ }, packageJson.exports);
797
+ packageJson.exports["./package.json"] ??= "./package.json";
798
+ packageJson.exports["."] = _nullishCoalesce(packageJson.exports["."], () => ( addPackageJsonExport("index", packageJson.type, sourceRoot)));
799
+ return packageJson;
800
+ }, "addPackageJsonExports");
801
+
802
+ // ../build-tools/src/utilities/get-entry-points.ts
803
+
804
+
805
+ // ../build-tools/src/utilities/task-graph.ts
806
+ var _createtaskgraph = require('nx/src/tasks-runner/create-task-graph');
807
+
808
+ // src/build.ts
809
+
810
+ var _jiti = require('jiti');
811
+
812
+
813
+
814
+ var _findworkspaceroot = require('nx/src/utils/find-workspace-root');
815
+
816
+ // ../../node_modules/.pnpm/unbuild@3.3.1_sass@1.83.4_typescript@5.7.3/node_modules/unbuild/dist/shared/unbuild.B2_7OVir.mjs
817
+
818
+
819
+ var _pathe = require('pathe');
820
+ var _utils = require('consola/utils');
821
+ var _consola = require('consola'); var _consola2 = _interopRequireDefault(_consola);
822
+
823
+ var _hookable = require('hookable');
824
+ var _prettybytes = require('pretty-bytes'); var _prettybytes2 = _interopRequireDefault(_prettybytes);
825
+ var _tinyglobby = require('tinyglobby');
826
+
827
+
828
+ var _rollup = require('rollup');
829
+ var _rollupplugindts = require('rollup-plugin-dts'); var _rollupplugindts2 = _interopRequireDefault(_rollupplugindts);
830
+ var _plugincommonjs = require('@rollup/plugin-commonjs'); var _plugincommonjs2 = _interopRequireDefault(_plugincommonjs);
831
+ var _pluginnoderesolve = require('@rollup/plugin-node-resolve');
832
+ var _pluginalias = require('@rollup/plugin-alias'); var _pluginalias2 = _interopRequireDefault(_pluginalias);
833
+ var _pluginreplace = require('@rollup/plugin-replace'); var _pluginreplace2 = _interopRequireDefault(_pluginreplace);
834
+ var _utils3 = require('pathe/utils');
835
+ var _mlly = require('mlly');
836
+ var _esbuild = require('esbuild');
837
+ var _pluginutils = require('@rollup/pluginutils');
838
+ var _pluginjson = require('@rollup/plugin-json'); var _pluginjson2 = _interopRequireDefault(_pluginjson);
839
+ var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
840
+ var _untyped = require('untyped');
841
+ var _babelplugin = require('untyped/babel-plugin'); var _babelplugin2 = _interopRequireDefault(_babelplugin);
842
+ var _scule = require('scule');
843
+ var _mkdist = require('mkdist');
844
+ function definePreset(preset) {
845
+ return preset;
846
+ }
847
+ _chunkYDYGZTJKcjs.__name.call(void 0, definePreset, "definePreset");
848
+ var autoPreset = definePreset(() => {
849
+ return {
850
+ hooks: {
851
+ "build:prepare"(ctx) {
852
+ if (!ctx.pkg || ctx.options.entries.length > 0) {
853
+ return;
854
+ }
855
+ const sourceFiles = listRecursively(_pathe.join.call(void 0, ctx.options.rootDir, "src"));
856
+ const res = inferEntries(ctx.pkg, sourceFiles, ctx.options.rootDir);
857
+ for (const message of res.warnings) {
858
+ warn(ctx, message);
859
+ }
860
+ ctx.options.entries.push(...res.entries);
861
+ if (res.cjs) {
862
+ ctx.options.rollup.emitCJS = true;
863
+ }
864
+ if (ctx.options.declaration === void 0) {
865
+ ctx.options.declaration = res.dts ? "compatible" : false;
866
+ }
867
+ _consola.consola.info(
868
+ "Automatically detected entries:",
869
+ _utils.colors.cyan(
870
+ ctx.options.entries.map(
871
+ (e) => _utils.colors.bold(
872
+ e.input.replace(ctx.options.rootDir + "/", "").replace(/\/$/, "/*")
873
+ )
874
+ ).join(", ")
875
+ ),
876
+ _utils.colors.gray(
877
+ ["esm", res.cjs && "cjs", res.dts && "dts"].filter(Boolean).map((tag) => `[${tag}]`).join(" ")
878
+ )
879
+ );
880
+ }
881
+ }
882
+ };
883
+ });
884
+ function inferEntries(pkg, sourceFiles, rootDir) {
885
+ const warnings = [];
886
+ sourceFiles.sort((a, b) => a.split("/").length - b.split("/").length);
887
+ const outputs = extractExportFilenames(pkg.exports);
888
+ if (pkg.bin) {
889
+ const binaries = typeof pkg.bin === "string" ? [pkg.bin] : Object.values(pkg.bin);
890
+ for (const file of binaries) {
891
+ outputs.push({ file });
892
+ }
893
+ }
894
+ if (pkg.main) {
895
+ outputs.push({ file: pkg.main });
896
+ }
897
+ if (pkg.module) {
898
+ outputs.push({ type: "esm", file: pkg.module });
899
+ }
900
+ if (pkg.types || pkg.typings) {
901
+ outputs.push({ file: pkg.types || pkg.typings });
902
+ }
903
+ const isESMPkg = pkg.type === "module";
904
+ for (const output of outputs.filter((o) => !o.type)) {
905
+ const isJS = output.file.endsWith(".js");
906
+ if (isESMPkg && isJS || output.file.endsWith(".mjs")) {
907
+ output.type = "esm";
908
+ } else if (!isESMPkg && isJS || output.file.endsWith(".cjs")) {
909
+ output.type = "cjs";
910
+ }
911
+ }
912
+ let cjs = false;
913
+ let dts2 = false;
914
+ const entries = [];
915
+ for (const output of outputs) {
916
+ const outputSlug = output.file.replace(
917
+ /(\*[^/\\]*|\.d\.(m|c)?ts|\.\w+)$/,
918
+ ""
919
+ );
920
+ const isDir = outputSlug.endsWith("/");
921
+ if (isDir && ["./", "/"].includes(outputSlug)) {
922
+ continue;
923
+ }
924
+ const possiblePaths = getEntrypointPaths(outputSlug);
925
+ const input = possiblePaths.reduce((source, d) => {
926
+ if (source) {
927
+ return source;
928
+ }
929
+ const SOURCE_RE = new RegExp(
930
+ `(?<=/|$)${d}${isDir ? "" : String.raw`\.\w+`}$`
931
+ );
932
+ return _optionalChain([sourceFiles, 'access', _44 => _44.find, 'call', _45 => _45((i) => SOURCE_RE.test(i)), 'optionalAccess', _46 => _46.replace, 'call', _47 => _47(/(\.d\.(m|c)?ts|\.\w+)$/, "")]);
933
+ }, void 0);
934
+ if (!input) {
935
+ if (!_fs.existsSync.call(void 0, _pathe.resolve.call(void 0, rootDir || ".", output.file))) {
936
+ warnings.push(`Could not find entrypoint for \`${output.file}\``);
937
+ }
938
+ continue;
939
+ }
940
+ if (output.type === "cjs") {
941
+ cjs = true;
942
+ }
943
+ const entry = entries.find((i) => i.input === input) || entries[entries.push({ input }) - 1];
944
+ if (/\.d\.(m|c)?ts$/.test(output.file)) {
945
+ dts2 = true;
946
+ }
947
+ if (isDir) {
948
+ entry.outDir = outputSlug;
949
+ entry.format = output.type;
950
+ }
951
+ }
952
+ return { entries, cjs, dts: dts2, warnings };
953
+ }
954
+ _chunkYDYGZTJKcjs.__name.call(void 0, inferEntries, "inferEntries");
955
+ var getEntrypointPaths = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (path2) => {
956
+ const segments = _pathe.normalize.call(void 0, path2).split("/");
957
+ return segments.map((_, index) => segments.slice(index).join("/")).filter(Boolean);
958
+ }, "getEntrypointPaths");
959
+ async function ensuredir(path2) {
960
+ await _promises2.default.mkdir(_pathe.dirname.call(void 0, path2), { recursive: true });
961
+ }
962
+ _chunkYDYGZTJKcjs.__name.call(void 0, ensuredir, "ensuredir");
963
+ function warn(ctx, message) {
964
+ if (ctx.warnings.has(message)) {
965
+ return;
966
+ }
967
+ _consola.consola.debug("[unbuild] [warn]", message);
968
+ ctx.warnings.add(message);
969
+ }
970
+ _chunkYDYGZTJKcjs.__name.call(void 0, warn, "warn");
971
+ async function symlink(from, to, force = true) {
972
+ await ensuredir(to);
973
+ if (force) {
974
+ await _promises2.default.unlink(to).catch(() => {
975
+ });
976
+ }
977
+ await _promises2.default.symlink(from, to, "junction");
978
+ }
979
+ _chunkYDYGZTJKcjs.__name.call(void 0, symlink, "symlink");
980
+ function dumpObject(obj) {
981
+ return "{ " + Object.keys(obj).map((key) => `${key}: ${JSON.stringify(obj[key])}`).join(", ") + " }";
982
+ }
983
+ _chunkYDYGZTJKcjs.__name.call(void 0, dumpObject, "dumpObject");
984
+ function getpkg(id = "") {
985
+ const s = id.split("/");
986
+ return s[0][0] === "@" ? `${s[0]}/${s[1]}` : s[0];
987
+ }
988
+ _chunkYDYGZTJKcjs.__name.call(void 0, getpkg, "getpkg");
989
+ async function rmdir(dir) {
990
+ await _promises2.default.unlink(dir).catch(() => {
991
+ });
992
+ await _promises2.default.rm(dir, { recursive: true, force: true }).catch(() => {
993
+ });
994
+ }
995
+ _chunkYDYGZTJKcjs.__name.call(void 0, rmdir, "rmdir");
996
+ function listRecursively(path2) {
997
+ const filenames = /* @__PURE__ */ new Set();
998
+ const walk = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (path22) => {
999
+ const files = _fs.readdirSync.call(void 0, path22);
1000
+ for (const file of files) {
1001
+ const fullPath = _pathe.resolve.call(void 0, path22, file);
1002
+ if (_fs.statSync.call(void 0, fullPath).isDirectory()) {
1003
+ filenames.add(fullPath + "/");
1004
+ walk(fullPath);
1005
+ } else {
1006
+ filenames.add(fullPath);
1007
+ }
1008
+ }
1009
+ }, "walk");
1010
+ walk(path2);
1011
+ return [...filenames];
1012
+ }
1013
+ _chunkYDYGZTJKcjs.__name.call(void 0, listRecursively, "listRecursively");
1014
+ async function resolvePreset(preset, rootDir) {
1015
+ if (preset === "auto") {
1016
+ preset = autoPreset;
1017
+ } else if (typeof preset === "string") {
1018
+ preset = await _jiti.createJiti.call(void 0, rootDir, { interopDefault: true }).import(preset, {
1019
+ default: true
1020
+ }) || {};
1021
+ }
1022
+ if (typeof preset === "function") {
1023
+ preset = preset();
1024
+ }
1025
+ return preset;
1026
+ }
1027
+ _chunkYDYGZTJKcjs.__name.call(void 0, resolvePreset, "resolvePreset");
1028
+ function inferExportType(condition, previousConditions = [], filename = "") {
1029
+ if (filename) {
1030
+ if (filename.endsWith(".d.ts")) {
1031
+ return "esm";
1032
+ }
1033
+ if (filename.endsWith(".mjs")) {
1034
+ return "esm";
1035
+ }
1036
+ if (filename.endsWith(".cjs")) {
1037
+ return "cjs";
1038
+ }
1039
+ }
1040
+ switch (condition) {
1041
+ case "import": {
1042
+ return "esm";
1043
+ }
1044
+ case "require": {
1045
+ return "cjs";
1046
+ }
1047
+ default: {
1048
+ if (previousConditions.length === 0) {
1049
+ return "esm";
1050
+ }
1051
+ const [newCondition, ...rest] = previousConditions;
1052
+ return inferExportType(newCondition, rest, filename);
1053
+ }
1054
+ }
1055
+ }
1056
+ _chunkYDYGZTJKcjs.__name.call(void 0, inferExportType, "inferExportType");
1057
+ function extractExportFilenames(exports, conditions = []) {
1058
+ if (!exports) {
1059
+ return [];
1060
+ }
1061
+ if (typeof exports === "string") {
1062
+ return [{ file: exports, type: "esm" }];
1063
+ }
1064
+ return Object.entries(exports).filter(([subpath]) => !subpath.endsWith(".json")).flatMap(
1065
+ ([condition, exports2]) => typeof exports2 === "string" ? {
1066
+ file: exports2,
1067
+ type: inferExportType(condition, conditions, exports2)
1068
+ } : extractExportFilenames(exports2, [...conditions, condition])
1069
+ );
1070
+ }
1071
+ _chunkYDYGZTJKcjs.__name.call(void 0, extractExportFilenames, "extractExportFilenames");
1072
+ function arrayIncludes(arr, searchElement) {
1073
+ return arr.some(
1074
+ (entry) => entry instanceof RegExp ? entry.test(searchElement) : entry === searchElement
1075
+ );
1076
+ }
1077
+ _chunkYDYGZTJKcjs.__name.call(void 0, arrayIncludes, "arrayIncludes");
1078
+ function removeExtension(filename) {
1079
+ return filename.replace(/\.(js|mjs|cjs|ts|mts|cts|json|jsx|tsx)$/, "");
1080
+ }
1081
+ _chunkYDYGZTJKcjs.__name.call(void 0, removeExtension, "removeExtension");
1082
+ function inferPkgExternals(pkg) {
1083
+ const externals = [
1084
+ ...Object.keys(pkg.dependencies || {}),
1085
+ ...Object.keys(pkg.peerDependencies || {}),
1086
+ ...Object.keys(pkg.devDependencies || {}).filter(
1087
+ (dep) => dep.startsWith("@types/")
1088
+ ),
1089
+ ...Object.keys(pkg.optionalDependencies || {})
1090
+ ];
1091
+ if (pkg.name) {
1092
+ externals.push(pkg.name);
1093
+ if (pkg.exports) {
1094
+ for (const subpath of Object.keys(pkg.exports)) {
1095
+ if (subpath.startsWith("./")) {
1096
+ externals.push(pathToRegex(`${pkg.name}/${subpath.slice(2)}`));
1097
+ }
1098
+ }
1099
+ }
1100
+ }
1101
+ if (pkg.imports) {
1102
+ for (const importName of Object.keys(pkg.imports)) {
1103
+ if (importName.startsWith("#")) {
1104
+ externals.push(pathToRegex(importName));
1105
+ }
1106
+ }
1107
+ }
1108
+ return [...new Set(externals)];
1109
+ }
1110
+ _chunkYDYGZTJKcjs.__name.call(void 0, inferPkgExternals, "inferPkgExternals");
1111
+ function pathToRegex(path2) {
1112
+ return path2.includes("*") ? new RegExp(
1113
+ `^${path2.replace(/\./g, String.raw`\.`).replace(/\*/g, ".*")}$`
1114
+ ) : path2;
1115
+ }
1116
+ _chunkYDYGZTJKcjs.__name.call(void 0, pathToRegex, "pathToRegex");
1117
+ function withTrailingSlash(path2) {
1118
+ return path2.endsWith("/") ? path2 : `${path2}/`;
1119
+ }
1120
+ _chunkYDYGZTJKcjs.__name.call(void 0, withTrailingSlash, "withTrailingSlash");
1121
+ function validateDependencies(ctx) {
1122
+ const usedDependencies = /* @__PURE__ */ new Set();
1123
+ const unusedDependencies = new Set(
1124
+ Object.keys(ctx.pkg.dependencies || {})
1125
+ );
1126
+ const implicitDependencies = /* @__PURE__ */ new Set();
1127
+ for (const id of ctx.usedImports) {
1128
+ unusedDependencies.delete(id);
1129
+ usedDependencies.add(id);
1130
+ }
1131
+ if (Array.isArray(ctx.options.dependencies)) {
1132
+ for (const id of ctx.options.dependencies) {
1133
+ unusedDependencies.delete(id);
1134
+ }
1135
+ }
1136
+ for (const id of usedDependencies) {
1137
+ if (!arrayIncludes(ctx.options.externals, id) && !id.startsWith("chunks/") && !ctx.options.dependencies.includes(getpkg(id)) && !ctx.options.peerDependencies.includes(getpkg(id))) {
1138
+ implicitDependencies.add(id);
1139
+ }
1140
+ }
1141
+ if (unusedDependencies.size > 0) {
1142
+ warn(
1143
+ ctx,
1144
+ "Potential unused dependencies found: " + [...unusedDependencies].map((id) => _utils.colors.cyan(id)).join(", ")
1145
+ );
1146
+ }
1147
+ if (implicitDependencies.size > 0 && !ctx.options.rollup.inlineDependencies) {
1148
+ warn(
1149
+ ctx,
1150
+ "Potential implicit dependencies found: " + [...implicitDependencies].map((id) => _utils.colors.cyan(id)).join(", ")
1151
+ );
1152
+ }
1153
+ }
1154
+ _chunkYDYGZTJKcjs.__name.call(void 0, validateDependencies, "validateDependencies");
1155
+ function validatePackage(pkg, rootDir, ctx) {
1156
+ if (!pkg) {
1157
+ return;
1158
+ }
1159
+ const filenames = new Set(
1160
+ [
1161
+ ...typeof pkg.bin === "string" ? [pkg.bin] : Object.values(pkg.bin || {}),
1162
+ pkg.main,
1163
+ pkg.module,
1164
+ pkg.types,
1165
+ pkg.typings,
1166
+ ...extractExportFilenames(pkg.exports).map((i) => i.file)
1167
+ ].map((i) => i && _pathe.resolve.call(void 0, rootDir, i.replace(/\/[^/]*\*.*$/, "")))
1168
+ );
1169
+ const missingOutputs = [];
1170
+ for (const filename of filenames) {
1171
+ if (filename && !filename.includes("*") && !_fs.existsSync.call(void 0, filename)) {
1172
+ missingOutputs.push(filename.replace(rootDir + "/", ""));
1173
+ }
1174
+ }
1175
+ if (missingOutputs.length > 0) {
1176
+ warn(
1177
+ ctx,
1178
+ `Potential missing package.json files: ${missingOutputs.map((o) => _utils.colors.cyan(o)).join(", ")}`
1179
+ );
1180
+ }
1181
+ }
1182
+ _chunkYDYGZTJKcjs.__name.call(void 0, validatePackage, "validatePackage");
1183
+ var SHEBANG_RE = /^#![^\n]*/;
1184
+ function shebangPlugin() {
1185
+ return {
1186
+ name: "unbuild-shebang",
1187
+ async writeBundle(options, bundle) {
1188
+ for (const [fileName, output] of Object.entries(bundle)) {
1189
+ if (output.type !== "chunk") {
1190
+ continue;
1191
+ }
1192
+ if (_optionalChain([output, 'access', _48 => _48.code, 'optionalAccess', _49 => _49.match, 'call', _50 => _50(SHEBANG_RE)])) {
1193
+ const outFile = _pathe.resolve.call(void 0, options.dir, fileName);
1194
+ await makeExecutable(outFile);
1195
+ }
1196
+ }
1197
+ }
1198
+ };
1199
+ }
1200
+ _chunkYDYGZTJKcjs.__name.call(void 0, shebangPlugin, "shebangPlugin");
1201
+ function removeShebangPlugin() {
1202
+ return {
1203
+ name: "unbuild-remove-shebang",
1204
+ renderChunk(code) {
1205
+ return code.replace(SHEBANG_RE, "");
1206
+ }
1207
+ };
1208
+ }
1209
+ _chunkYDYGZTJKcjs.__name.call(void 0, removeShebangPlugin, "removeShebangPlugin");
1210
+ async function makeExecutable(filePath) {
1211
+ await _fs.promises.chmod(
1212
+ filePath,
1213
+ 493
1214
+ /* rwx r-x r-x */
1215
+ ).catch(() => {
1216
+ });
1217
+ }
1218
+ _chunkYDYGZTJKcjs.__name.call(void 0, makeExecutable, "makeExecutable");
1219
+ function getShebang(code, append = "\n") {
1220
+ const m = code.match(SHEBANG_RE);
1221
+ return m ? m + append : "";
1222
+ }
1223
+ _chunkYDYGZTJKcjs.__name.call(void 0, getShebang, "getShebang");
1224
+ var DefaultLoaders = {
1225
+ ".js": "js",
1226
+ ".mjs": "js",
1227
+ ".cjs": "js",
1228
+ ".ts": "ts",
1229
+ ".mts": "ts",
1230
+ ".cts": "ts",
1231
+ ".tsx": "tsx",
1232
+ ".jsx": "jsx"
1233
+ };
1234
+ function esbuild(options) {
1235
+ const {
1236
+ include = new RegExp(Object.keys(DefaultLoaders).join("|")),
1237
+ exclude = /node_modules/,
1238
+ loaders: loaderOptions,
1239
+ ...esbuildOptions
1240
+ } = options;
1241
+ const loaders = { ...DefaultLoaders };
1242
+ if (loaderOptions) {
1243
+ for (const [key, value] of Object.entries(loaderOptions)) {
1244
+ if (typeof value === "string") {
1245
+ loaders[key] = value;
1246
+ } else if (value === false) {
1247
+ delete loaders[key];
1248
+ }
1249
+ }
1250
+ }
1251
+ const getLoader = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (id = "") => {
1252
+ return loaders[_pathe.extname.call(void 0, id)];
1253
+ }, "getLoader");
1254
+ const filter = _pluginutils.createFilter.call(void 0, include, exclude);
1255
+ return {
1256
+ name: "esbuild",
1257
+ async transform(code, id) {
1258
+ if (!filter(id)) {
1259
+ return null;
1260
+ }
1261
+ const loader = getLoader(id);
1262
+ if (!loader) {
1263
+ return null;
1264
+ }
1265
+ const result = await _esbuild.transform.call(void 0, code, {
1266
+ ...esbuildOptions,
1267
+ loader,
1268
+ sourcefile: id
1269
+ });
1270
+ printWarnings(id, result, this);
1271
+ return {
1272
+ code: result.code || "",
1273
+ map: result.map || null
1274
+ };
1275
+ },
1276
+ async renderChunk(code, { fileName }) {
1277
+ if (!options.minify) {
1278
+ return null;
1279
+ }
1280
+ if (/\.d\.(c|m)?tsx?$/.test(fileName)) {
1281
+ return null;
1282
+ }
1283
+ const loader = getLoader(fileName);
1284
+ if (!loader) {
1285
+ return null;
1286
+ }
1287
+ const result = await _esbuild.transform.call(void 0, code, {
1288
+ ...esbuildOptions,
1289
+ loader,
1290
+ sourcefile: fileName,
1291
+ minify: true
1292
+ });
1293
+ return {
1294
+ code: result.code || "",
1295
+ map: result.map || null
1296
+ };
1297
+ }
1298
+ };
1299
+ }
1300
+ _chunkYDYGZTJKcjs.__name.call(void 0, esbuild, "esbuild");
1301
+ function printWarnings(id, result, plugin) {
1302
+ if (result.warnings) {
1303
+ for (const warning of result.warnings) {
1304
+ let message = "[esbuild]";
1305
+ if (warning.location) {
1306
+ message += ` (${_pathe.relative.call(void 0, process.cwd(), id)}:${warning.location.line}:${warning.location.column})`;
1307
+ }
1308
+ message += ` ${warning.text}`;
1309
+ plugin.warn(message);
1310
+ }
1311
+ }
1312
+ }
1313
+ _chunkYDYGZTJKcjs.__name.call(void 0, printWarnings, "printWarnings");
1314
+ var EXPORT_DEFAULT = "export default ";
1315
+ function JSONPlugin(options) {
1316
+ const plugin = _pluginjson2.default.call(void 0, options);
1317
+ return {
1318
+ ...plugin,
1319
+ name: "unbuild-json",
1320
+ transform(code, id) {
1321
+ const res = plugin.transform.call(this, code, id);
1322
+ if (res && typeof res !== "string" && "code" in res && res.code && res.code.startsWith(EXPORT_DEFAULT)) {
1323
+ res.code = res.code.replace(EXPORT_DEFAULT, "module.exports = ");
1324
+ }
1325
+ return res;
1326
+ }
1327
+ };
1328
+ }
1329
+ _chunkYDYGZTJKcjs.__name.call(void 0, JSONPlugin, "JSONPlugin");
1330
+ var defaults = {
1331
+ include: [/\.(md|txt|css|htm|html)$/],
1332
+ exclude: []
1333
+ };
1334
+ function rawPlugin(opts = {}) {
1335
+ opts = { ...opts, ...defaults };
1336
+ const filter = _pluginutils.createFilter.call(void 0, opts.include, opts.exclude);
1337
+ return {
1338
+ name: "unbuild-raw",
1339
+ transform(code, id) {
1340
+ if (filter(id)) {
1341
+ return {
1342
+ code: `export default ${JSON.stringify(code)}`,
1343
+ map: null
1344
+ };
1345
+ }
1346
+ }
1347
+ };
1348
+ }
1349
+ _chunkYDYGZTJKcjs.__name.call(void 0, rawPlugin, "rawPlugin");
1350
+ function cjsPlugin(_opts) {
1351
+ return {
1352
+ name: "unbuild-cjs",
1353
+ renderChunk(code, _chunk, opts) {
1354
+ if (opts.format === "es") {
1355
+ return CJSToESM(code);
1356
+ }
1357
+ return null;
1358
+ }
1359
+ };
1360
+ }
1361
+ _chunkYDYGZTJKcjs.__name.call(void 0, cjsPlugin, "cjsPlugin");
1362
+ function fixCJSExportTypePlugin() {
1363
+ return {
1364
+ name: "unbuild-fix-cjs-export-type",
1365
+ renderChunk(code, info, opts) {
1366
+ if (info.type !== "chunk" || !info.fileName.endsWith(".d.cts") || !info.isEntry || _optionalChain([info, 'access', _51 => _51.exports, 'optionalAccess', _52 => _52.length]) !== 1 || info.exports[0] !== "default") {
1367
+ return;
1368
+ }
1369
+ return code.replace(
1370
+ /(?<=(?<=[;}]|^)\s*export\s*){\s*([\w$]+)\s*as\s+default\s*}/,
1371
+ `= $1`
1372
+ );
1373
+ }
1374
+ };
1375
+ }
1376
+ _chunkYDYGZTJKcjs.__name.call(void 0, fixCJSExportTypePlugin, "fixCJSExportTypePlugin");
1377
+ var CJSyntaxRe = /__filename|__dirname|require\(|require\.resolve\(/;
1378
+ var CJSShim = `
1379
+
1380
+ // -- Unbuild CommonJS Shims --
1381
+ import __cjs_url__ from 'url';
1382
+ import __cjs_path__ from 'path';
1383
+ import __cjs_mod__ from 'module';
1384
+ const __filename = __cjs_url__.fileURLToPath(import.meta.url);
1385
+ const __dirname = __cjs_path__.dirname(__filename);
1386
+ const require = __cjs_mod__.createRequire(import.meta.url);
1387
+ `;
1388
+ function CJSToESM(code) {
1389
+ if (code.includes(CJSShim) || !CJSyntaxRe.test(code)) {
1390
+ return null;
1391
+ }
1392
+ const lastESMImport = _mlly.findStaticImports.call(void 0, code).pop();
1393
+ const indexToAppend = lastESMImport ? lastESMImport.end : 0;
1394
+ const s = new (0, _magicstring2.default)(code);
1395
+ s.appendRight(indexToAppend, CJSShim);
1396
+ return {
1397
+ code: s.toString(),
1398
+ map: s.generateMap()
1399
+ };
1400
+ }
1401
+ _chunkYDYGZTJKcjs.__name.call(void 0, CJSToESM, "CJSToESM");
1402
+ var DEFAULT_EXTENSIONS = [
1403
+ ".ts",
1404
+ ".tsx",
1405
+ ".mts",
1406
+ ".cts",
1407
+ ".mjs",
1408
+ ".cjs",
1409
+ ".js",
1410
+ ".jsx",
1411
+ ".json"
1412
+ ];
1413
+ function resolveAliases(ctx) {
1414
+ const aliases = {
1415
+ [ctx.pkg.name]: ctx.options.rootDir,
1416
+ ...ctx.options.alias
1417
+ };
1418
+ if (ctx.options.rollup.alias) {
1419
+ if (Array.isArray(ctx.options.rollup.alias.entries)) {
1420
+ Object.assign(
1421
+ aliases,
1422
+ Object.fromEntries(
1423
+ ctx.options.rollup.alias.entries.map((entry) => {
1424
+ return [entry.find, entry.replacement];
1425
+ })
1426
+ )
1427
+ );
1428
+ } else {
1429
+ Object.assign(
1430
+ aliases,
1431
+ ctx.options.rollup.alias.entries || ctx.options.rollup.alias
1432
+ );
1433
+ }
1434
+ }
1435
+ return aliases;
1436
+ }
1437
+ _chunkYDYGZTJKcjs.__name.call(void 0, resolveAliases, "resolveAliases");
1438
+ function getChunkFilename(ctx, chunk, ext) {
1439
+ if (chunk.isDynamicEntry) {
1440
+ return `chunks/[name].${ext}`;
1441
+ }
1442
+ return `shared/${ctx.options.name}.[hash].${ext}`;
1443
+ }
1444
+ _chunkYDYGZTJKcjs.__name.call(void 0, getChunkFilename, "getChunkFilename");
1445
+ function getRollupOptions(ctx) {
1446
+ const _aliases = resolveAliases(ctx);
1447
+ return {
1448
+ input: Object.fromEntries(
1449
+ ctx.options.entries.filter((entry) => entry.builder === "rollup").map((entry) => [
1450
+ entry.name,
1451
+ _pathe.resolve.call(void 0, ctx.options.rootDir, entry.input)
1452
+ ])
1453
+ ),
1454
+ output: [
1455
+ ctx.options.rollup.emitCJS && {
1456
+ dir: _pathe.resolve.call(void 0, ctx.options.rootDir, ctx.options.outDir),
1457
+ entryFileNames: "[name].cjs",
1458
+ chunkFileNames: /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (chunk) => getChunkFilename(ctx, chunk, "cjs"), "chunkFileNames"),
1459
+ format: "cjs",
1460
+ exports: "auto",
1461
+ interop: "compat",
1462
+ generatedCode: { constBindings: true },
1463
+ externalLiveBindings: false,
1464
+ freeze: false,
1465
+ sourcemap: ctx.options.sourcemap,
1466
+ ...ctx.options.rollup.output
1467
+ },
1468
+ {
1469
+ dir: _pathe.resolve.call(void 0, ctx.options.rootDir, ctx.options.outDir),
1470
+ entryFileNames: "[name].mjs",
1471
+ chunkFileNames: /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (chunk) => getChunkFilename(ctx, chunk, "mjs"), "chunkFileNames"),
1472
+ format: "esm",
1473
+ exports: "auto",
1474
+ generatedCode: { constBindings: true },
1475
+ externalLiveBindings: false,
1476
+ freeze: false,
1477
+ sourcemap: ctx.options.sourcemap,
1478
+ ...ctx.options.rollup.output
1479
+ }
1480
+ ].filter(Boolean),
1481
+ external(originalId) {
1482
+ const resolvedId = _utils3.resolveAlias.call(void 0, originalId, _aliases);
1483
+ const pkgName = _optionalChain([_mlly.parseNodeModulePath.call(void 0, resolvedId), 'optionalAccess', _53 => _53.name]) || _optionalChain([_mlly.parseNodeModulePath.call(void 0, originalId), 'optionalAccess', _54 => _54.name]) || getpkg(originalId);
1484
+ if (arrayIncludes(ctx.options.externals, pkgName) || arrayIncludes(ctx.options.externals, originalId) || arrayIncludes(ctx.options.externals, resolvedId)) {
1485
+ return true;
1486
+ }
1487
+ for (const id of [originalId, resolvedId]) {
1488
+ if (id[0] === "." || _pathe.isAbsolute.call(void 0, id) || /src[/\\]/.test(id) || id.startsWith(ctx.pkg.name)) {
1489
+ return false;
1490
+ }
1491
+ }
1492
+ if (ctx.options.rollup.inlineDependencies === true || Array.isArray(ctx.options.rollup.inlineDependencies) && (arrayIncludes(ctx.options.rollup.inlineDependencies, pkgName) || arrayIncludes(ctx.options.rollup.inlineDependencies, originalId) || arrayIncludes(ctx.options.rollup.inlineDependencies, resolvedId))) {
1493
+ return false;
1494
+ }
1495
+ warn(ctx, `Implicitly bundling "${originalId}"`);
1496
+ return false;
1497
+ },
1498
+ onwarn(warning, rollupWarn) {
1499
+ if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
1500
+ rollupWarn(warning);
1501
+ }
1502
+ },
1503
+ plugins: [
1504
+ ctx.options.rollup.replace && _pluginreplace2.default.call(void 0, {
1505
+ ...ctx.options.rollup.replace,
1506
+ values: {
1507
+ ...ctx.options.replace,
1508
+ ...ctx.options.rollup.replace.values
1509
+ }
1510
+ }),
1511
+ ctx.options.rollup.alias && _pluginalias2.default.call(void 0, {
1512
+ ...ctx.options.rollup.alias,
1513
+ entries: _aliases
1514
+ }),
1515
+ ctx.options.rollup.resolve && _pluginnoderesolve.nodeResolve.call(void 0, {
1516
+ extensions: DEFAULT_EXTENSIONS,
1517
+ exportConditions: ["production"],
1518
+ ...ctx.options.rollup.resolve
1519
+ }),
1520
+ ctx.options.rollup.json && JSONPlugin({
1521
+ ...ctx.options.rollup.json
1522
+ }),
1523
+ shebangPlugin(),
1524
+ ctx.options.rollup.esbuild && esbuild({
1525
+ sourcemap: ctx.options.sourcemap,
1526
+ ...ctx.options.rollup.esbuild
1527
+ }),
1528
+ ctx.options.rollup.commonjs && _plugincommonjs2.default.call(void 0, {
1529
+ extensions: DEFAULT_EXTENSIONS,
1530
+ ...ctx.options.rollup.commonjs
1531
+ }),
1532
+ ctx.options.rollup.preserveDynamicImports && {
1533
+ renderDynamicImport() {
1534
+ return { left: "import(", right: ")" };
1535
+ }
1536
+ },
1537
+ ctx.options.rollup.cjsBridge && cjsPlugin(),
1538
+ rawPlugin()
1539
+ ].filter(Boolean)
1540
+ };
1541
+ }
1542
+ _chunkYDYGZTJKcjs.__name.call(void 0, getRollupOptions, "getRollupOptions");
1543
+ async function rollupStub(ctx) {
1544
+ const babelPlugins = _optionalChain([ctx, 'access', _55 => _55.options, 'access', _56 => _56.stubOptions, 'access', _57 => _57.jiti, 'access', _58 => _58.transformOptions, 'optionalAccess', _59 => _59.babel, 'optionalAccess', _60 => _60.plugins]);
1545
+ const importedBabelPlugins = [];
1546
+ const serializedJitiOptions = JSON.stringify(
1547
+ {
1548
+ ...ctx.options.stubOptions.jiti,
1549
+ alias: {
1550
+ ...resolveAliases(ctx),
1551
+ ...ctx.options.stubOptions.jiti.alias
1552
+ },
1553
+ transformOptions: {
1554
+ ...ctx.options.stubOptions.jiti.transformOptions,
1555
+ babel: {
1556
+ ..._optionalChain([ctx, 'access', _61 => _61.options, 'access', _62 => _62.stubOptions, 'access', _63 => _63.jiti, 'access', _64 => _64.transformOptions, 'optionalAccess', _65 => _65.babel]),
1557
+ plugins: "__$BABEL_PLUGINS"
1558
+ }
1559
+ }
1560
+ },
1561
+ null,
1562
+ 2
1563
+ ).replace(
1564
+ '"__$BABEL_PLUGINS"',
1565
+ Array.isArray(babelPlugins) ? "[" + babelPlugins.map((plugin, i) => {
1566
+ if (Array.isArray(plugin)) {
1567
+ const [name, ...args] = plugin;
1568
+ importedBabelPlugins.push(name);
1569
+ return `[` + [
1570
+ `plugin${i}`,
1571
+ ...args.map((val) => JSON.stringify(val))
1572
+ ].join(", ") + "]";
1573
+ } else {
1574
+ importedBabelPlugins.push(plugin);
1575
+ return `plugin${i}`;
1576
+ }
1577
+ }).join(",") + "]" : "[]"
1578
+ );
1579
+ for (const entry of ctx.options.entries.filter(
1580
+ (entry2) => entry2.builder === "rollup"
1581
+ )) {
1582
+ const output = _pathe.resolve.call(void 0,
1583
+ ctx.options.rootDir,
1584
+ ctx.options.outDir,
1585
+ entry.name
1586
+ );
1587
+ const isESM = ctx.pkg.type === "module";
1588
+ const resolvedEntry = _mlly.fileURLToPath.call(void 0, ctx.jiti.esmResolve(entry.input));
1589
+ const resolvedEntryWithoutExt = resolvedEntry.slice(
1590
+ 0,
1591
+ Math.max(0, resolvedEntry.length - _pathe.extname.call(void 0, resolvedEntry).length)
1592
+ );
1593
+ const resolvedEntryForTypeImport = isESM ? `${resolvedEntry.replace(/(\.m?)(ts)$/, "$1js")}` : resolvedEntryWithoutExt;
1594
+ const code = await _fs.promises.readFile(resolvedEntry, "utf8");
1595
+ const shebang = getShebang(code);
1596
+ await _promises.mkdir.call(void 0, _pathe.dirname.call(void 0, output), { recursive: true });
1597
+ if (ctx.options.rollup.emitCJS) {
1598
+ const jitiCJSPath = _pathe.relative.call(void 0,
1599
+ _pathe.dirname.call(void 0, output),
1600
+ await _mlly.resolvePath.call(void 0, "jiti", {
1601
+ url: _chunkYDYGZTJKcjs.importMetaUrl,
1602
+ conditions: ["node", "require"]
1603
+ })
1604
+ );
1605
+ await _promises.writeFile.call(void 0,
1606
+ output + ".cjs",
1607
+ shebang + [
1608
+ `const { createJiti } = require(${JSON.stringify(jitiCJSPath)})`,
1609
+ ...importedBabelPlugins.map(
1610
+ (plugin, i) => `const plugin${i} = require(${JSON.stringify(plugin)})`
1611
+ ),
1612
+ "",
1613
+ `const jiti = createJiti(__filename, ${serializedJitiOptions})`,
1614
+ "",
1615
+ `/** @type {import(${JSON.stringify(
1616
+ resolvedEntryForTypeImport
1617
+ )})} */`,
1618
+ `module.exports = jiti(${JSON.stringify(resolvedEntry)})`
1619
+ ].join("\n")
1620
+ );
1621
+ }
1622
+ const namedExports = await _mlly.resolveModuleExportNames.call(void 0,
1623
+ resolvedEntry,
1624
+ {
1625
+ extensions: DEFAULT_EXTENSIONS
1626
+ }
1627
+ ).catch((error) => {
1628
+ warn(ctx, `Cannot analyze ${resolvedEntry} for exports:` + error);
1629
+ return [];
1630
+ });
1631
+ const hasDefaultExport = namedExports.includes("default") || namedExports.length === 0;
1632
+ const jitiESMPath = _pathe.relative.call(void 0,
1633
+ _pathe.dirname.call(void 0, output),
1634
+ await _mlly.resolvePath.call(void 0, "jiti", {
1635
+ url: _chunkYDYGZTJKcjs.importMetaUrl,
1636
+ conditions: ["node", "import"]
1637
+ })
1638
+ );
1639
+ await _promises.writeFile.call(void 0,
1640
+ output + ".mjs",
1641
+ shebang + [
1642
+ `import { createJiti } from ${JSON.stringify(jitiESMPath)};`,
1643
+ ...importedBabelPlugins.map(
1644
+ (plugin, i) => `import plugin${i} from ${JSON.stringify(plugin)}`
1645
+ ),
1646
+ "",
1647
+ `const jiti = createJiti(import.meta.url, ${serializedJitiOptions})`,
1648
+ "",
1649
+ `/** @type {import(${JSON.stringify(resolvedEntryForTypeImport)})} */`,
1650
+ `const _module = await jiti.import(${JSON.stringify(
1651
+ resolvedEntry
1652
+ )});`,
1653
+ hasDefaultExport ? "\nexport default _module?.default ?? _module;" : "",
1654
+ ...namedExports.filter((name) => name !== "default").map((name) => `export const ${name} = _module.${name};`)
1655
+ ].join("\n")
1656
+ );
1657
+ if (ctx.options.declaration) {
1658
+ const dtsContent = [
1659
+ `export * from ${JSON.stringify(resolvedEntryForTypeImport)};`,
1660
+ hasDefaultExport ? `export { default } from ${JSON.stringify(resolvedEntryForTypeImport)};` : ""
1661
+ ].join("\n");
1662
+ await _promises.writeFile.call(void 0, output + ".d.cts", dtsContent);
1663
+ await _promises.writeFile.call(void 0, output + ".d.mts", dtsContent);
1664
+ if (ctx.options.declaration === "compatible" || ctx.options.declaration === true) {
1665
+ await _promises.writeFile.call(void 0, output + ".d.ts", dtsContent);
1666
+ }
1667
+ }
1668
+ if (shebang) {
1669
+ await makeExecutable(output + ".cjs");
1670
+ await makeExecutable(output + ".mjs");
1671
+ }
1672
+ }
1673
+ }
1674
+ _chunkYDYGZTJKcjs.__name.call(void 0, rollupStub, "rollupStub");
1675
+ function rollupWatch(rollupOptions) {
1676
+ const watcher = _rollup.watch.call(void 0, rollupOptions);
1677
+ let inputs;
1678
+ if (Array.isArray(rollupOptions.input)) {
1679
+ inputs = rollupOptions.input;
1680
+ } else if (typeof rollupOptions.input === "string") {
1681
+ inputs = [rollupOptions.input];
1682
+ } else {
1683
+ inputs = Object.keys(rollupOptions.input || {});
1684
+ }
1685
+ _consola2.default.info(
1686
+ `[unbuild] [rollup] Starting watchers for entries: ${inputs.map((input) => "./" + _pathe.relative.call(void 0, process.cwd(), input)).join(", ")}`
1687
+ );
1688
+ _consola2.default.warn(
1689
+ "[unbuild] [rollup] Watch mode is experimental and may be unstable"
1690
+ );
1691
+ watcher.on("change", (id, { event }) => {
1692
+ _consola2.default.info(`${_utils.colors.cyan(_pathe.relative.call(void 0, ".", id))} was ${event}d`);
1693
+ });
1694
+ watcher.on("restart", () => {
1695
+ _consola2.default.info(_utils.colors.gray("[unbuild] [rollup] Rebuilding bundle"));
1696
+ });
1697
+ watcher.on("event", (event) => {
1698
+ if (event.code === "END") {
1699
+ _consola2.default.success(_utils.colors.green("[unbuild] [rollup] Rebuild finished\n"));
1700
+ }
1701
+ });
1702
+ }
1703
+ _chunkYDYGZTJKcjs.__name.call(void 0, rollupWatch, "rollupWatch");
1704
+ async function rollupBuild(ctx) {
1705
+ if (ctx.options.stub) {
1706
+ await rollupStub(ctx);
1707
+ await ctx.hooks.callHook("rollup:done", ctx);
1708
+ return;
1709
+ }
1710
+ const rollupOptions = getRollupOptions(ctx);
1711
+ await ctx.hooks.callHook("rollup:options", ctx, rollupOptions);
1712
+ if (Object.keys(rollupOptions.input).length === 0) {
1713
+ await ctx.hooks.callHook("rollup:done", ctx);
1714
+ return;
1715
+ }
1716
+ const buildResult = await _rollup.rollup.call(void 0, rollupOptions);
1717
+ await ctx.hooks.callHook("rollup:build", ctx, buildResult);
1718
+ const allOutputOptions = rollupOptions.output;
1719
+ for (const outputOptions of allOutputOptions) {
1720
+ const { output } = await buildResult.write(outputOptions);
1721
+ const chunkFileNames = /* @__PURE__ */ new Set();
1722
+ const outputChunks = output.filter(
1723
+ (e) => e.type === "chunk"
1724
+ );
1725
+ for (const entry of outputChunks) {
1726
+ chunkFileNames.add(entry.fileName);
1727
+ for (const id of entry.imports) {
1728
+ ctx.usedImports.add(id);
1729
+ }
1730
+ if (entry.isEntry) {
1731
+ ctx.buildEntries.push({
1732
+ chunks: entry.imports.filter(
1733
+ (i) => outputChunks.find((c) => c.fileName === i)
1734
+ ),
1735
+ modules: Object.entries(entry.modules).map(([id, mod]) => ({
1736
+ id,
1737
+ bytes: mod.renderedLength
1738
+ })),
1739
+ path: entry.fileName,
1740
+ bytes: Buffer.byteLength(entry.code, "utf8"),
1741
+ exports: entry.exports
1742
+ });
1743
+ }
1744
+ }
1745
+ for (const chunkFileName of chunkFileNames) {
1746
+ ctx.usedImports.delete(chunkFileName);
1747
+ }
1748
+ }
1749
+ if (ctx.options.watch) {
1750
+ rollupWatch(rollupOptions);
1751
+ if (ctx.options.declaration && ctx.options.watch) {
1752
+ _consola2.default.warn("`rollup` DTS builder does not support watch mode yet.");
1753
+ }
1754
+ return;
1755
+ }
1756
+ if (ctx.options.declaration) {
1757
+ rollupOptions.plugins = [
1758
+ ...rollupOptions.plugins,
1759
+ _rollupplugindts2.default.call(void 0, ctx.options.rollup.dts),
1760
+ removeShebangPlugin(),
1761
+ ctx.options.rollup.emitCJS && fixCJSExportTypePlugin()
1762
+ ].filter(Boolean);
1763
+ await ctx.hooks.callHook("rollup:dts:options", ctx, rollupOptions);
1764
+ const typesBuild2 = await _rollup.rollup.call(void 0, rollupOptions);
1765
+ await ctx.hooks.callHook("rollup:dts:build", ctx, typesBuild2);
1766
+ if (ctx.options.rollup.emitCJS) {
1767
+ await typesBuild2.write({
1768
+ dir: _pathe.resolve.call(void 0, ctx.options.rootDir, ctx.options.outDir),
1769
+ entryFileNames: "[name].d.cts",
1770
+ chunkFileNames: /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (chunk) => getChunkFilename(ctx, chunk, "d.cts"), "chunkFileNames")
1771
+ });
1772
+ }
1773
+ await typesBuild2.write({
1774
+ dir: _pathe.resolve.call(void 0, ctx.options.rootDir, ctx.options.outDir),
1775
+ entryFileNames: "[name].d.mts",
1776
+ chunkFileNames: /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (chunk) => getChunkFilename(ctx, chunk, "d.mts"), "chunkFileNames")
1777
+ });
1778
+ if (ctx.options.declaration === true || ctx.options.declaration === "compatible") {
1779
+ await typesBuild2.write({
1780
+ dir: _pathe.resolve.call(void 0, ctx.options.rootDir, ctx.options.outDir),
1781
+ entryFileNames: "[name].d.ts",
1782
+ chunkFileNames: /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (chunk) => getChunkFilename(ctx, chunk, "d.ts"), "chunkFileNames")
1783
+ });
1784
+ }
1785
+ }
1786
+ await ctx.hooks.callHook("rollup:done", ctx);
1787
+ }
1788
+ _chunkYDYGZTJKcjs.__name.call(void 0, rollupBuild, "rollupBuild");
1789
+ async function typesBuild(ctx) {
1790
+ const entries = ctx.options.entries.filter(
1791
+ (entry) => entry.builder === "untyped"
1792
+ );
1793
+ await ctx.hooks.callHook("untyped:entries", ctx, entries);
1794
+ for (const entry of entries) {
1795
+ const options = {
1796
+ jiti: {
1797
+ interopDefault: true,
1798
+ transformOptions: {
1799
+ babel: {
1800
+ plugins: [_babelplugin2.default]
1801
+ }
1802
+ }
1803
+ }
1804
+ };
1805
+ await ctx.hooks.callHook("untyped:entry:options", ctx, entry, options);
1806
+ const untypedJiti = _jiti.createJiti.call(void 0, ctx.options.rootDir, options.jiti);
1807
+ const distDir = entry.outDir;
1808
+ let rawSchema = await untypedJiti.import(_pathe.resolve.call(void 0, ctx.options.rootDir, entry.input), {
1809
+ try: true
1810
+ }) || {};
1811
+ const rawSchemaKeys = Object.keys(rawSchema);
1812
+ if (rawSchemaKeys.length === 1 && rawSchemaKeys[0] === "default") {
1813
+ rawSchema = rawSchema.default;
1814
+ }
1815
+ const defaults2 = entry.defaults || {};
1816
+ const schema = await _untyped.resolveSchema.call(void 0, rawSchema, defaults2);
1817
+ await ctx.hooks.callHook("untyped:entry:schema", ctx, entry, schema);
1818
+ const outputs = {
1819
+ markdown: {
1820
+ fileName: _pathe.resolve.call(void 0, distDir, `${entry.name}.md`),
1821
+ contents: _untyped.generateMarkdown.call(void 0, schema)
1822
+ },
1823
+ schema: {
1824
+ fileName: `${entry.name}.schema.json`,
1825
+ contents: JSON.stringify(schema, null, 2)
1826
+ },
1827
+ defaults: {
1828
+ fileName: `${entry.name}.defaults.json`,
1829
+ contents: JSON.stringify(defaults2, null, 2)
1830
+ },
1831
+ declaration: entry.declaration ? {
1832
+ fileName: `${entry.name}.d.ts`,
1833
+ contents: _untyped.generateTypes.call(void 0, schema, {
1834
+ interfaceName: _scule.pascalCase.call(void 0, entry.name + "-schema")
1835
+ })
1836
+ } : void 0
1837
+ };
1838
+ await ctx.hooks.callHook("untyped:entry:outputs", ctx, entry, outputs);
1839
+ for (const output of Object.values(outputs)) {
1840
+ if (!output) continue;
1841
+ await _promises.writeFile.call(void 0,
1842
+ _pathe.resolve.call(void 0, distDir, output.fileName),
1843
+ output.contents,
1844
+ "utf8"
1845
+ );
1846
+ }
1847
+ }
1848
+ await ctx.hooks.callHook("untyped:done", ctx);
1849
+ if (entries.length > 0 && ctx.options.watch) {
1850
+ _consola2.default.warn("`untyped` builder does not support watch mode yet.");
1851
+ }
1852
+ }
1853
+ _chunkYDYGZTJKcjs.__name.call(void 0, typesBuild, "typesBuild");
1854
+ async function mkdistBuild(ctx) {
1855
+ const entries = ctx.options.entries.filter(
1856
+ (e) => e.builder === "mkdist"
1857
+ );
1858
+ await ctx.hooks.callHook("mkdist:entries", ctx, entries);
1859
+ for (const entry of entries) {
1860
+ const distDir = entry.outDir;
1861
+ if (ctx.options.stub) {
1862
+ await rmdir(distDir);
1863
+ await symlink(entry.input, distDir);
1864
+ } else {
1865
+ const mkdistOptions = {
1866
+ rootDir: ctx.options.rootDir,
1867
+ srcDir: entry.input,
1868
+ distDir,
1869
+ cleanDist: false,
1870
+ ...entry
1871
+ };
1872
+ await ctx.hooks.callHook(
1873
+ "mkdist:entry:options",
1874
+ ctx,
1875
+ entry,
1876
+ mkdistOptions
1877
+ );
1878
+ const output = await _mkdist.mkdist.call(void 0, mkdistOptions);
1879
+ ctx.buildEntries.push({
1880
+ path: distDir,
1881
+ chunks: output.writtenFiles.map((p) => _pathe.relative.call(void 0, ctx.options.outDir, p))
1882
+ });
1883
+ await ctx.hooks.callHook("mkdist:entry:build", ctx, entry, output);
1884
+ if (output.errors) {
1885
+ for (const error of output.errors) {
1886
+ warn(
1887
+ ctx,
1888
+ `mkdist build failed for \`${_pathe.relative.call(void 0, ctx.options.rootDir, error.filename)}\`:
1889
+ ${error.errors.map((e) => ` - ${e}`).join("\n")}`
1890
+ );
1891
+ }
1892
+ }
1893
+ }
1894
+ }
1895
+ await ctx.hooks.callHook("mkdist:done", ctx);
1896
+ if (entries.length > 0 && ctx.options.watch) {
1897
+ _consola2.default.warn("`mkdist` builder does not support watch mode yet.");
1898
+ }
1899
+ }
1900
+ _chunkYDYGZTJKcjs.__name.call(void 0, mkdistBuild, "mkdistBuild");
1901
+ var copy = _fs.promises.cp || _fs.promises.copyFile;
1902
+ async function copyBuild(ctx) {
1903
+ const entries = ctx.options.entries.filter(
1904
+ (e) => e.builder === "copy"
1905
+ );
1906
+ await ctx.hooks.callHook("copy:entries", ctx, entries);
1907
+ for (const entry of entries) {
1908
+ const distDir = entry.outDir;
1909
+ if (ctx.options.stub) {
1910
+ await rmdir(distDir);
1911
+ await symlink(entry.input, distDir);
1912
+ } else {
1913
+ const patterns = Array.isArray(entry.pattern) ? entry.pattern : [entry.pattern || "**"];
1914
+ const paths = await _tinyglobby.glob.call(void 0, patterns, {
1915
+ cwd: _pathe.resolve.call(void 0, ctx.options.rootDir, entry.input),
1916
+ absolute: false
1917
+ });
1918
+ const outputList = await Promise.allSettled(
1919
+ paths.map(async (path2) => {
1920
+ const src = _pathe.resolve.call(void 0, ctx.options.rootDir, entry.input, path2);
1921
+ const dist = _pathe.resolve.call(void 0, ctx.options.rootDir, distDir, path2);
1922
+ await copy(src, dist);
1923
+ return dist;
1924
+ })
1925
+ );
1926
+ for (const output of outputList) {
1927
+ if (output.status === "rejected") {
1928
+ warn(ctx, output.reason);
1929
+ }
1930
+ }
1931
+ ctx.buildEntries.push({
1932
+ path: distDir,
1933
+ chunks: outputList.filter(({ status }) => status === "fulfilled").map(
1934
+ (p) => _pathe.relative.call(void 0,
1935
+ ctx.options.outDir,
1936
+ p.value
1937
+ )
1938
+ )
1939
+ });
1940
+ }
1941
+ }
1942
+ await ctx.hooks.callHook("copy:done", ctx);
1943
+ if (entries.length > 0 && ctx.options.watch) {
1944
+ _consola2.default.warn("`untyped` builder does not support watch mode yet.");
1945
+ }
1946
+ }
1947
+ _chunkYDYGZTJKcjs.__name.call(void 0, copyBuild, "copyBuild");
1948
+ async function build(rootDir, stub, inputConfig = {}) {
1949
+ rootDir = _pathe.resolve.call(void 0, process.cwd(), rootDir || ".");
1950
+ const jiti = _jiti.createJiti.call(void 0, rootDir);
1951
+ const _buildConfig = await jiti.import(_optionalChain([inputConfig, 'optionalAccess', _66 => _66.config]) || "./build.config", {
1952
+ try: !inputConfig.config,
1953
+ default: true
1954
+ }) || {};
1955
+ const buildConfigs = (Array.isArray(_buildConfig) ? _buildConfig : [_buildConfig]).filter(Boolean);
1956
+ const pkg = await jiti.import("./package.json", {
1957
+ try: true,
1958
+ default: true
1959
+ }) || {};
1960
+ const cleanedDirs = [];
1961
+ const _watchMode = inputConfig.watch === true;
1962
+ const _stubMode = !_watchMode && (stub || inputConfig.stub === true);
1963
+ for (const buildConfig of buildConfigs) {
1964
+ await _build(
1965
+ rootDir,
1966
+ inputConfig,
1967
+ buildConfig,
1968
+ pkg,
1969
+ cleanedDirs,
1970
+ _stubMode,
1971
+ _watchMode
1972
+ );
1973
+ }
1974
+ }
1975
+ _chunkYDYGZTJKcjs.__name.call(void 0, build, "build");
1976
+ async function _build(rootDir, inputConfig = {}, buildConfig, pkg, cleanedDirs, _stubMode, _watchMode) {
1977
+ const preset = await resolvePreset(
1978
+ buildConfig.preset || _optionalChain([pkg, 'access', _67 => _67.unbuild, 'optionalAccess', _68 => _68.preset]) || _optionalChain([pkg, 'access', _69 => _69.build, 'optionalAccess', _70 => _70.preset]) || inputConfig.preset || "auto",
1979
+ rootDir
1980
+ );
1981
+ const options = _defu.defu.call(void 0,
1982
+ buildConfig,
1983
+ pkg.unbuild || pkg.build,
1984
+ inputConfig,
1985
+ preset,
1986
+ {
1987
+ name: (_optionalChain([pkg, 'optionalAccess', _71 => _71.name]) || "").split("/").pop() || "default",
1988
+ rootDir,
1989
+ entries: [],
1990
+ clean: true,
1991
+ declaration: void 0,
1992
+ outDir: "dist",
1993
+ stub: _stubMode,
1994
+ stubOptions: {
1995
+ /**
1996
+ * See https://github.com/unjs/jiti#%EF%B8%8F-options
1997
+ */
1998
+ jiti: {
1999
+ interopDefault: true,
2000
+ alias: {}
2001
+ }
2002
+ },
2003
+ watch: _watchMode,
2004
+ watchOptions: _watchMode ? {
2005
+ exclude: "node_modules/**",
2006
+ include: "src/**"
2007
+ } : void 0,
2008
+ externals: [
2009
+ ..._module2.default.builtinModules,
2010
+ ..._module2.default.builtinModules.map((m) => "node:" + m)
2011
+ ],
2012
+ dependencies: [],
2013
+ devDependencies: [],
2014
+ peerDependencies: [],
2015
+ alias: {},
2016
+ replace: {},
2017
+ failOnWarn: true,
2018
+ sourcemap: false,
2019
+ rollup: {
2020
+ emitCJS: false,
2021
+ watch: false,
2022
+ cjsBridge: false,
2023
+ inlineDependencies: false,
2024
+ preserveDynamicImports: true,
2025
+ output: {
2026
+ // https://v8.dev/features/import-attributes
2027
+ importAttributesKey: "with"
2028
+ },
2029
+ // Plugins
2030
+ replace: {
2031
+ preventAssignment: true
2032
+ },
2033
+ alias: {},
2034
+ resolve: {
2035
+ preferBuiltins: true
2036
+ },
2037
+ json: {
2038
+ preferConst: true
2039
+ },
2040
+ commonjs: {
2041
+ ignoreTryCatch: true
2042
+ },
2043
+ esbuild: { target: "esnext" },
2044
+ dts: {
2045
+ // https://github.com/Swatinem/rollup-plugin-dts/issues/143
2046
+ compilerOptions: { preserveSymlinks: false },
2047
+ respectExternal: true
2048
+ }
2049
+ },
2050
+ parallel: false
2051
+ }
2052
+ );
2053
+ options.outDir = _pathe.resolve.call(void 0, options.rootDir, options.outDir);
2054
+ const jiti = _jiti.createJiti.call(void 0, options.rootDir, { interopDefault: true });
2055
+ const ctx = {
2056
+ options,
2057
+ jiti,
2058
+ warnings: /* @__PURE__ */ new Set(),
2059
+ pkg,
2060
+ buildEntries: [],
2061
+ usedImports: /* @__PURE__ */ new Set(),
2062
+ hooks: _hookable.createHooks.call(void 0, )
2063
+ };
2064
+ if (preset.hooks) {
2065
+ ctx.hooks.addHooks(preset.hooks);
2066
+ }
2067
+ if (inputConfig.hooks) {
2068
+ ctx.hooks.addHooks(inputConfig.hooks);
2069
+ }
2070
+ if (buildConfig.hooks) {
2071
+ ctx.hooks.addHooks(buildConfig.hooks);
2072
+ }
2073
+ await ctx.hooks.callHook("build:prepare", ctx);
2074
+ options.entries = options.entries.map(
2075
+ (entry) => typeof entry === "string" ? { input: entry } : entry
2076
+ );
2077
+ for (const entry of options.entries) {
2078
+ if (typeof entry.name !== "string") {
2079
+ let relativeInput = _pathe.isAbsolute.call(void 0, entry.input) ? _pathe.relative.call(void 0, rootDir, entry.input) : _pathe.normalize.call(void 0, entry.input);
2080
+ if (relativeInput.startsWith("./")) {
2081
+ relativeInput = relativeInput.slice(2);
2082
+ }
2083
+ entry.name = removeExtension(relativeInput.replace(/^src\//, ""));
2084
+ }
2085
+ if (!entry.input) {
2086
+ throw new Error("Missing entry input: " + dumpObject(entry));
2087
+ }
2088
+ if (!entry.builder) {
2089
+ entry.builder = entry.input.endsWith("/") ? "mkdist" : "rollup";
2090
+ }
2091
+ if (options.declaration !== void 0 && entry.declaration === void 0) {
2092
+ entry.declaration = options.declaration;
2093
+ }
2094
+ entry.input = _pathe.resolve.call(void 0, options.rootDir, entry.input);
2095
+ entry.outDir = _pathe.resolve.call(void 0, options.rootDir, entry.outDir || options.outDir);
2096
+ }
2097
+ options.dependencies = Object.keys(pkg.dependencies || {});
2098
+ options.peerDependencies = Object.keys(pkg.peerDependencies || {});
2099
+ options.devDependencies = Object.keys(pkg.devDependencies || {});
2100
+ options.externals.push(...inferPkgExternals(pkg));
2101
+ options.externals = [...new Set(options.externals)];
2102
+ await ctx.hooks.callHook("build:before", ctx);
2103
+ _consola.consola.info(
2104
+ _utils.colors.cyan(`${options.stub ? "Stubbing" : "Building"} ${options.name}`)
2105
+ );
2106
+ if (process.env.DEBUG) {
2107
+ _consola.consola.info(`${_utils.colors.bold("Root dir:")} ${options.rootDir}
2108
+ ${_utils.colors.bold("Entries:")}
2109
+ ${options.entries.map((entry) => " " + dumpObject(entry)).join("\n ")}
2110
+ `);
2111
+ }
2112
+ if (options.clean) {
2113
+ for (const dir of new Set(
2114
+ options.entries.map((e) => e.outDir).filter(Boolean).sort()
2115
+ )) {
2116
+ if (dir === options.rootDir || options.rootDir.startsWith(withTrailingSlash(dir)) || cleanedDirs.some((c) => dir.startsWith(c))) {
2117
+ continue;
2118
+ }
2119
+ cleanedDirs.push(dir);
2120
+ _consola.consola.info(
2121
+ `Cleaning dist directory: \`./${_pathe.relative.call(void 0, process.cwd(), dir)}\``
2122
+ );
2123
+ await rmdir(dir);
2124
+ await _fs.promises.mkdir(dir, { recursive: true });
2125
+ }
2126
+ }
2127
+ const buildTasks = [
2128
+ typesBuild,
2129
+ // untyped
2130
+ mkdistBuild,
2131
+ // mkdist
2132
+ rollupBuild,
2133
+ // rollup
2134
+ copyBuild
2135
+ // copy
2136
+ ];
2137
+ if (options.parallel) {
2138
+ await Promise.all(buildTasks.map((task) => task(ctx)));
2139
+ } else {
2140
+ for (const task of buildTasks) {
2141
+ await task(ctx);
2142
+ }
2143
+ }
2144
+ if (options.stub || options.watch) {
2145
+ await ctx.hooks.callHook("build:done", ctx);
2146
+ return;
2147
+ }
2148
+ _consola.consola.success(_utils.colors.green("Build succeeded for " + options.name));
2149
+ const outFiles = await _tinyglobby.glob.call(void 0, ["**"], { cwd: options.outDir });
2150
+ for (const file of outFiles) {
2151
+ let entry = ctx.buildEntries.find((e) => e.path === file);
2152
+ if (!entry) {
2153
+ entry = {
2154
+ path: file,
2155
+ chunk: true
2156
+ };
2157
+ ctx.buildEntries.push(entry);
2158
+ }
2159
+ if (!entry.bytes) {
2160
+ const stat = await _fs.promises.stat(_pathe.resolve.call(void 0, options.outDir, file));
2161
+ entry.bytes = stat.size;
2162
+ }
2163
+ }
2164
+ const rPath = /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, (p) => _pathe.relative.call(void 0, process.cwd(), _pathe.resolve.call(void 0, options.outDir, p)), "rPath");
2165
+ for (const entry of ctx.buildEntries.filter((e) => !e.chunk)) {
2166
+ let totalBytes = entry.bytes || 0;
2167
+ for (const chunk of entry.chunks || []) {
2168
+ totalBytes += _optionalChain([ctx, 'access', _72 => _72.buildEntries, 'access', _73 => _73.find, 'call', _74 => _74((e) => e.path === chunk), 'optionalAccess', _75 => _75.bytes]) || 0;
2169
+ }
2170
+ let line = ` ${_utils.colors.bold(rPath(entry.path))} (` + [
2171
+ totalBytes && `total size: ${_utils.colors.cyan(_prettybytes2.default.call(void 0, totalBytes))}`,
2172
+ entry.bytes && `chunk size: ${_utils.colors.cyan(_prettybytes2.default.call(void 0, entry.bytes))}`,
2173
+ _optionalChain([entry, 'access', _76 => _76.exports, 'optionalAccess', _77 => _77.length]) && `exports: ${_utils.colors.gray(entry.exports.join(", "))}`
2174
+ ].filter(Boolean).join(", ") + ")";
2175
+ if (_optionalChain([entry, 'access', _78 => _78.chunks, 'optionalAccess', _79 => _79.length])) {
2176
+ line += "\n" + entry.chunks.map((p) => {
2177
+ const chunk = ctx.buildEntries.find((e) => e.path === p) || {};
2178
+ return _utils.colors.gray(
2179
+ " \u2514\u2500 " + rPath(p) + _utils.colors.bold(
2180
+ chunk.bytes ? ` (${_prettybytes2.default.call(void 0, _optionalChain([chunk, 'optionalAccess', _80 => _80.bytes]))})` : ""
2181
+ )
2182
+ );
2183
+ }).join("\n");
2184
+ }
2185
+ if (_optionalChain([entry, 'access', _81 => _81.modules, 'optionalAccess', _82 => _82.length])) {
2186
+ line += "\n" + entry.modules.filter((m) => m.id.includes("node_modules")).sort((a, b) => (b.bytes || 0) - (a.bytes || 0)).map((m) => {
2187
+ return _utils.colors.gray(
2188
+ " \u{1F4E6} " + rPath(m.id) + _utils.colors.bold(m.bytes ? ` (${_prettybytes2.default.call(void 0, m.bytes)})` : "")
2189
+ );
2190
+ }).join("\n");
2191
+ }
2192
+ _consola.consola.log(entry.chunk ? _utils.colors.gray(line) : line);
2193
+ }
2194
+ console.log(
2195
+ "\u03A3 Total dist size (byte size):",
2196
+ _utils.colors.cyan(
2197
+ _prettybytes2.default.call(void 0, ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0))
2198
+ )
2199
+ );
2200
+ validateDependencies(ctx);
2201
+ validatePackage(pkg, rootDir, ctx);
2202
+ await ctx.hooks.callHook("build:done", ctx);
2203
+ _consola.consola.log("");
2204
+ if (ctx.warnings.size > 0) {
2205
+ _consola.consola.warn(
2206
+ "Build is done with some warnings:\n\n" + [...ctx.warnings].map((msg) => "- " + msg).join("\n")
2207
+ );
2208
+ if (ctx.options.failOnWarn) {
2209
+ _consola.consola.error(
2210
+ "Exiting with code (1). You can change this behavior by setting `failOnWarn: false` ."
2211
+ );
2212
+ process.exit(1);
2213
+ }
2214
+ }
2215
+ }
2216
+ _chunkYDYGZTJKcjs.__name.call(void 0, _build, "_build");
2217
+
2218
+ // ../../node_modules/.pnpm/unbuild@3.3.1_sass@1.83.4_typescript@5.7.3/node_modules/unbuild/dist/index.mjs
2219
+
2220
+
2221
+
2222
+
2223
+
2224
+
2225
+
2226
+
2227
+
2228
+
2229
+
2230
+
2231
+
2232
+
2233
+
2234
+
2235
+
2236
+
2237
+
2238
+
2239
+
2240
+
2241
+
2242
+
2243
+
2244
+
2245
+
2246
+
2247
+ // src/build.ts
2248
+ async function resolveOptions(options) {
2249
+ const projectRoot = options.projectRoot;
2250
+ if (!projectRoot) {
2251
+ throw new Error("Cannot find project root");
2252
+ }
2253
+ const outputPath = options.outputPath || _chunk36OA7HRFcjs.joinPaths.call(void 0, "dist", projectRoot);
2254
+ const workspaceRoot = _findworkspaceroot.findWorkspaceRoot.call(void 0, projectRoot);
2255
+ if (!workspaceRoot) {
2256
+ throw new Error("Cannot find workspace root");
2257
+ }
2258
+ const config = await loadStormConfig(workspaceRoot.dir);
2259
+ const logger = await createLogger(config);
2260
+ logger.debug(" \u2699\uFE0F Resolving build options");
2261
+ const stopwatch = logger.getStopwatch("Build options resolution");
2262
+ if (options.configPath) {
2263
+ const configFile = await _chunkLUXNRUAPcjs.loadConfig.call(void 0, options.configPath);
2264
+ if (configFile) {
2265
+ options = _defu2.default.call(void 0, options, configFile);
2266
+ }
2267
+ }
2268
+ const projectGraph = _devkit.readCachedProjectGraph.call(void 0, );
2269
+ const projectJsonPath = _chunk36OA7HRFcjs.joinPaths.call(void 0, config.workspaceRoot, projectRoot, "project.json");
2270
+ if (!_fs.existsSync.call(void 0, projectJsonPath)) {
2271
+ throw new Error("Cannot find project.json configuration");
2272
+ }
2273
+ const projectJsonContent = await _promises.readFile.call(void 0, projectJsonPath, "utf8");
2274
+ const projectJson = JSON.parse(projectJsonContent);
2275
+ const projectName = projectJson.name;
2276
+ const packageJsonPath = _chunk36OA7HRFcjs.joinPaths.call(void 0, workspaceRoot.dir, projectRoot, "package.json");
2277
+ if (!_fs.existsSync.call(void 0, packageJsonPath)) {
2278
+ throw new Error("Cannot find package.json configuration");
2279
+ }
2280
+ const packageJsonContent = await _promises.readFile.call(void 0, packageJsonPath, "utf8");
2281
+ const packageJson = JSON.parse(packageJsonContent);
2282
+ let tsconfig = options.tsconfig;
2283
+ if (!tsconfig) {
2284
+ tsconfig = _chunk36OA7HRFcjs.joinPaths.call(void 0, workspaceRoot.dir, projectRoot, "tsconfig.json");
2285
+ }
2286
+ if (!_fs.existsSync.call(void 0, tsconfig)) {
2287
+ throw new Error("Cannot find tsconfig.json configuration");
2288
+ }
2289
+ let sourceRoot = projectJson.sourceRoot;
2290
+ if (!sourceRoot) {
2291
+ sourceRoot = _chunk36OA7HRFcjs.joinPaths.call(void 0, projectRoot, "src");
2292
+ }
2293
+ if (!_fs.existsSync.call(void 0, sourceRoot)) {
2294
+ throw new Error("Cannot find sourceRoot directory");
2295
+ }
2296
+ const result = _buildablelibsutils.calculateProjectBuildableDependencies.call(void 0, void 0, projectGraph, workspaceRoot.dir, projectName, process.env.NX_TASK_TARGET_TARGET || "build", process.env.NX_TASK_TARGET_CONFIGURATION || "production", true);
2297
+ let dependencies = result.dependencies;
2298
+ const tsLibDependency = _js.getHelperDependency.call(void 0, _js.HelperDependency.tsc, tsconfig, dependencies, projectGraph, true);
2299
+ if (tsLibDependency) {
2300
+ dependencies = dependencies.filter((deps) => deps.name !== tsLibDependency.name);
2301
+ dependencies.push(tsLibDependency);
2302
+ }
2303
+ const jiti = _jiti.createJiti.call(void 0, config.workspaceRoot, {
2304
+ fsCache: config.skipCache ? false : _chunk36OA7HRFcjs.joinPaths.call(void 0, config.directories.cache || "node_modules/.cache/storm", "jiti"),
2305
+ interopDefault: true
2306
+ });
2307
+ const resolvedOptions = {
2308
+ name: projectName,
2309
+ config,
2310
+ projectRoot,
2311
+ sourceRoot,
2312
+ projectName,
2313
+ tsconfig,
2314
+ jiti,
2315
+ logger,
2316
+ clean: false,
2317
+ entries: [
2318
+ {
2319
+ builder: "mkdist",
2320
+ input: `.${sourceRoot.replace(projectRoot, "")}`,
2321
+ outDir: _chunk36OA7HRFcjs.joinPaths.call(void 0, _path.relative.call(void 0, _chunk36OA7HRFcjs.joinPaths.call(void 0, config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
2322
+ declaration: options.emitTypes !== false,
2323
+ format: "esm"
2324
+ },
2325
+ {
2326
+ builder: "mkdist",
2327
+ input: `.${sourceRoot.replace(projectRoot, "")}`,
2328
+ outDir: _chunk36OA7HRFcjs.joinPaths.call(void 0, _path.relative.call(void 0, _chunk36OA7HRFcjs.joinPaths.call(void 0, config.workspaceRoot, projectRoot), config.workspaceRoot).replaceAll("\\", "/"), outputPath, "dist").replaceAll("\\", "/"),
2329
+ declaration: options.emitTypes !== false,
2330
+ format: "cjs",
2331
+ ext: "cjs"
2332
+ }
2333
+ ],
2334
+ declaration: options.emitTypes !== false ? "compatible" : false,
2335
+ failOnWarn: false,
2336
+ sourcemap: _nullishCoalesce(options.sourcemap, () => ( !!options.debug)),
2337
+ outDir: outputPath,
2338
+ parallel: true,
2339
+ stub: false,
2340
+ stubOptions: {
2341
+ jiti: {}
2342
+ },
2343
+ externals: _nullishCoalesce(options.external, () => ( [])),
2344
+ dependencies: [],
2345
+ peerDependencies: [],
2346
+ devDependencies: [],
2347
+ hooks: {},
2348
+ alias: {},
2349
+ replace: {},
2350
+ rollup: {
2351
+ replace: {},
2352
+ alias: {},
2353
+ json: {},
2354
+ commonjs: {
2355
+ sourceMap: _nullishCoalesce(options.sourcemap, () => ( true))
2356
+ },
2357
+ emitCJS: true,
2358
+ cjsBridge: true,
2359
+ dts: {
2360
+ respectExternal: true,
2361
+ tsconfig
2362
+ },
2363
+ output: {
2364
+ banner: options.banner || `
2365
+ // \u26A1 Built by Storm Software
2366
+ `,
2367
+ footer: options.footer
2368
+ },
2369
+ resolve: {
2370
+ preferBuiltins: true,
2371
+ extensions: [
2372
+ ".cjs",
2373
+ ".mjs",
2374
+ ".js",
2375
+ ".jsx",
2376
+ ".ts",
2377
+ ".tsx",
2378
+ ".json"
2379
+ ]
2380
+ },
2381
+ esbuild: {
2382
+ minify: options.minify !== false,
2383
+ splitting: options.splitting !== false,
2384
+ treeShaking: options.treeShaking !== false,
2385
+ color: true,
2386
+ logLevel: config.logLevel === _chunk36OA7HRFcjs.LogLevelLabel.FATAL ? _chunk36OA7HRFcjs.LogLevelLabel.ERROR : _chunk36OA7HRFcjs.isVerbose.call(void 0, ) ? "verbose" : config.logLevel
2387
+ }
2388
+ }
2389
+ };
2390
+ dependencies = dependencies.filter((dep) => dep.node.type === "npm" || dep.node.type === "lib" || dep.node.type === "app");
2391
+ if (dependencies.length > 0) {
2392
+ resolvedOptions.dependencies = dependencies.map((dep) => dep.name);
2393
+ }
2394
+ if (packageJson.devDependencies) {
2395
+ resolvedOptions.devDependencies = Object.keys(packageJson.devDependencies);
2396
+ }
2397
+ if (packageJson.peerDependencies) {
2398
+ resolvedOptions.peerDependencies = Object.keys(packageJson.peerDependencies);
2399
+ }
2400
+ if (options.rollup) {
2401
+ let rollup2 = {};
2402
+ if (typeof options.rollup === "string") {
2403
+ const rollupFile = await _chunkLUXNRUAPcjs.loadConfig.call(void 0, options.rollup);
2404
+ if (rollupFile) {
2405
+ rollup2 = rollupFile;
2406
+ }
2407
+ } else {
2408
+ rollup2 = options.rollup;
2409
+ }
2410
+ resolvedOptions.rollup = _defu2.default.call(void 0, _nullishCoalesce(resolvedOptions.rollup, () => ( {})), rollup2);
2411
+ }
2412
+ resolvedOptions.hooks = {
2413
+ "rollup:options": /* @__PURE__ */ _chunkYDYGZTJKcjs.__name.call(void 0, async (ctx, opts) => {
2414
+ opts.plugins = await _asyncNullishCoalesce(options.plugins, async () => ( await _chunkADWBQYE6cjs.getDefaultBuildPlugins.call(void 0, options, resolvedOptions)));
2415
+ }, "rollup:options")
2416
+ };
2417
+ stopwatch();
2418
+ return resolvedOptions;
2419
+ }
2420
+ _chunkYDYGZTJKcjs.__name.call(void 0, resolveOptions, "resolveOptions");
2421
+ async function generatePackageJson(options) {
2422
+ if (options.generatePackageJson !== false && _fs.existsSync.call(void 0, _chunk36OA7HRFcjs.joinPaths.call(void 0, options.projectRoot, "package.json"))) {
2423
+ options.logger.debug(" \u270D\uFE0F Writing package.json file");
2424
+ const stopwatch = options.logger.getStopwatch("Write package.json file");
2425
+ const packageJsonPath = _chunk36OA7HRFcjs.joinPaths.call(void 0, options.projectRoot, "project.json");
2426
+ if (!_fs.existsSync.call(void 0, packageJsonPath)) {
2427
+ throw new Error("Cannot find package.json configuration");
2428
+ }
2429
+ let packageJsonContent = await _promises.readFile.call(void 0, _chunk36OA7HRFcjs.joinPaths.call(void 0, options.config.workspaceRoot, options.projectRoot, "package.json"), "utf8");
2430
+ if (!packageJsonContent) {
2431
+ throw new Error("Cannot find package.json configuration file");
2432
+ }
2433
+ let packageJson = JSON.parse(packageJsonContent);
2434
+ packageJson = await addPackageDependencies(options.config.workspaceRoot, options.projectRoot, options.projectName, packageJson);
2435
+ packageJson = await addWorkspacePackageJsonFields(options.config, options.projectRoot, options.sourceRoot, options.projectName, false, packageJson);
2436
+ await _devkit.writeJsonFile.call(void 0, _chunk36OA7HRFcjs.joinPaths.call(void 0, options.outDir, "package.json"), await addPackageJsonExports(options.sourceRoot, packageJson));
2437
+ stopwatch();
2438
+ }
2439
+ return options;
2440
+ }
2441
+ _chunkYDYGZTJKcjs.__name.call(void 0, generatePackageJson, "generatePackageJson");
2442
+ async function executeUnbuild(options) {
2443
+ options.logger.debug(` \u{1F680} Running ${options.name} (${options.projectRoot}) build`);
2444
+ const stopwatch = options.logger.getStopwatch(`${options.name} (${options.projectRoot}) build`);
2445
+ try {
2446
+ await build(options.projectRoot, false, {
2447
+ ...options,
2448
+ rootDir: options.projectRoot
2449
+ });
2450
+ } finally {
2451
+ stopwatch();
2452
+ }
2453
+ return options;
2454
+ }
2455
+ _chunkYDYGZTJKcjs.__name.call(void 0, executeUnbuild, "executeUnbuild");
2456
+ async function copyBuildAssets(options) {
2457
+ options.logger.debug(` \u{1F4CB} Copying asset files to output directory: ${options.outDir}`);
2458
+ const stopwatch = options.logger.getStopwatch(`${options.name} asset copy`);
2459
+ await copyAssets(options.config, _nullishCoalesce(options.assets, () => ( [])), options.outDir, options.projectRoot, options.projectName, options.sourceRoot, options.generatePackageJson, options.includeSrc);
2460
+ stopwatch();
2461
+ return options;
2462
+ }
2463
+ _chunkYDYGZTJKcjs.__name.call(void 0, copyBuildAssets, "copyBuildAssets");
2464
+ async function cleanOutputPath(options) {
2465
+ if (options.clean !== false && options.outDir) {
2466
+ options.logger.debug(` \u{1F9F9} Cleaning ${options.name} output path: ${options.outDir}`);
2467
+ const stopwatch = options.logger.getStopwatch(`${options.name} output clean`);
2468
+ await _chunkKUMAH6IZcjs.cleanDirectories.call(void 0, options.name, options.outDir, options.config);
2469
+ stopwatch();
2470
+ }
2471
+ return options;
2472
+ }
2473
+ _chunkYDYGZTJKcjs.__name.call(void 0, cleanOutputPath, "cleanOutputPath");
2474
+ async function build2(options) {
2475
+ const resolvedOptions = await resolveOptions(options);
2476
+ resolvedOptions.logger.debug(` \u26A1 Executing Storm Unbuild pipeline`);
2477
+ const stopwatch = resolvedOptions.logger.getStopwatch("Unbuild pipeline");
2478
+ try {
2479
+ await cleanOutputPath(resolvedOptions);
2480
+ await generatePackageJson(resolvedOptions);
2481
+ await executeUnbuild(resolvedOptions);
2482
+ await copyBuildAssets(resolvedOptions);
2483
+ resolvedOptions.logger.success(` \u{1F3C1} The ${resolvedOptions.name} build completed successfully`);
2484
+ } catch (error) {
2485
+ resolvedOptions.logger.fatal(" \u274C Fatal errors occurred during the build that could not be recovered from. The build process has been terminated.");
2486
+ throw error;
2487
+ } finally {
2488
+ stopwatch();
2489
+ }
2490
+ }
2491
+ _chunkYDYGZTJKcjs.__name.call(void 0, build2, "build");
2492
+
2493
+
2494
+
2495
+ exports.build = build2;