alepha 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/dist/api-jobs/index.d.ts +26 -26
  2. package/dist/api-users/index.d.ts +1 -1
  3. package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
  4. package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
  5. package/dist/cli/index.d.ts +3 -11
  6. package/dist/cli/index.js +106 -74
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/email/index.js +71 -73
  9. package/dist/email/index.js.map +1 -1
  10. package/dist/orm/index.d.ts +1 -1
  11. package/dist/orm/index.js.map +1 -1
  12. package/dist/queue/index.d.ts +4 -4
  13. package/dist/retry/index.d.ts +1 -1
  14. package/dist/retry/index.js +2 -2
  15. package/dist/retry/index.js.map +1 -1
  16. package/dist/scheduler/index.d.ts +6 -6
  17. package/dist/security/index.d.ts +28 -28
  18. package/dist/server/index.js +1 -1
  19. package/dist/server/index.js.map +1 -1
  20. package/dist/server-health/index.d.ts +17 -17
  21. package/dist/server-metrics/index.js +170 -174
  22. package/dist/server-metrics/index.js.map +1 -1
  23. package/dist/server-security/index.d.ts +9 -9
  24. package/dist/vite/index.js +4 -5
  25. package/dist/vite/index.js.map +1 -1
  26. package/dist/websocket/index.d.ts +7 -7
  27. package/package.json +52 -103
  28. package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
  29. package/src/cli/assets/appRouterTs.ts +9 -0
  30. package/src/cli/assets/indexHtml.ts +2 -1
  31. package/src/cli/assets/mainBrowserTs.ts +10 -0
  32. package/src/cli/commands/CoreCommands.ts +6 -5
  33. package/src/cli/commands/DrizzleCommands.ts +65 -57
  34. package/src/cli/commands/VerifyCommands.ts +1 -1
  35. package/src/cli/services/ProjectUtils.ts +44 -38
  36. package/src/orm/providers/DrizzleKitProvider.ts +1 -1
  37. package/src/retry/descriptors/$retry.ts +5 -3
  38. package/src/server/providers/NodeHttpServerProvider.ts +1 -1
  39. package/src/vite/helpers/boot.ts +3 -3
  40. package/dist/api-files/index.cjs +0 -1293
  41. package/dist/api-files/index.cjs.map +0 -1
  42. package/dist/api-files/index.d.cts +0 -829
  43. package/dist/api-jobs/index.cjs +0 -274
  44. package/dist/api-jobs/index.cjs.map +0 -1
  45. package/dist/api-jobs/index.d.cts +0 -654
  46. package/dist/api-notifications/index.cjs +0 -380
  47. package/dist/api-notifications/index.cjs.map +0 -1
  48. package/dist/api-notifications/index.d.cts +0 -289
  49. package/dist/api-parameters/index.cjs +0 -66
  50. package/dist/api-parameters/index.cjs.map +0 -1
  51. package/dist/api-parameters/index.d.cts +0 -84
  52. package/dist/api-users/index.cjs +0 -6009
  53. package/dist/api-users/index.cjs.map +0 -1
  54. package/dist/api-users/index.d.cts +0 -4740
  55. package/dist/api-verifications/index.cjs +0 -407
  56. package/dist/api-verifications/index.cjs.map +0 -1
  57. package/dist/api-verifications/index.d.cts +0 -207
  58. package/dist/batch/index.cjs +0 -408
  59. package/dist/batch/index.cjs.map +0 -1
  60. package/dist/batch/index.d.cts +0 -330
  61. package/dist/bin/index.cjs +0 -17
  62. package/dist/bin/index.cjs.map +0 -1
  63. package/dist/bin/index.d.cts +0 -1
  64. package/dist/bucket/index.cjs +0 -303
  65. package/dist/bucket/index.cjs.map +0 -1
  66. package/dist/bucket/index.d.cts +0 -355
  67. package/dist/cache/index.cjs +0 -241
  68. package/dist/cache/index.cjs.map +0 -1
  69. package/dist/cache/index.d.cts +0 -202
  70. package/dist/cache-redis/index.cjs +0 -84
  71. package/dist/cache-redis/index.cjs.map +0 -1
  72. package/dist/cache-redis/index.d.cts +0 -40
  73. package/dist/cli/chunk-DSlc6foC.cjs +0 -43
  74. package/dist/cli/dist-BBPjuQ56.js +0 -2778
  75. package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
  76. package/dist/cli/index.cjs +0 -1241
  77. package/dist/cli/index.cjs.map +0 -1
  78. package/dist/cli/index.d.cts +0 -422
  79. package/dist/command/index.cjs +0 -693
  80. package/dist/command/index.cjs.map +0 -1
  81. package/dist/command/index.d.cts +0 -340
  82. package/dist/core/index.cjs +0 -2264
  83. package/dist/core/index.cjs.map +0 -1
  84. package/dist/core/index.d.cts +0 -1927
  85. package/dist/datetime/index.cjs +0 -318
  86. package/dist/datetime/index.cjs.map +0 -1
  87. package/dist/datetime/index.d.cts +0 -145
  88. package/dist/email/index.cjs +0 -10874
  89. package/dist/email/index.cjs.map +0 -1
  90. package/dist/email/index.d.cts +0 -186
  91. package/dist/fake/index.cjs +0 -34641
  92. package/dist/fake/index.cjs.map +0 -1
  93. package/dist/fake/index.d.cts +0 -74
  94. package/dist/file/index.cjs +0 -1212
  95. package/dist/file/index.cjs.map +0 -1
  96. package/dist/file/index.d.cts +0 -698
  97. package/dist/lock/index.cjs +0 -226
  98. package/dist/lock/index.cjs.map +0 -1
  99. package/dist/lock/index.d.cts +0 -361
  100. package/dist/lock-redis/index.cjs +0 -113
  101. package/dist/lock-redis/index.cjs.map +0 -1
  102. package/dist/lock-redis/index.d.cts +0 -24
  103. package/dist/logger/index.cjs +0 -521
  104. package/dist/logger/index.cjs.map +0 -1
  105. package/dist/logger/index.d.cts +0 -281
  106. package/dist/orm/index.cjs +0 -2986
  107. package/dist/orm/index.cjs.map +0 -1
  108. package/dist/orm/index.d.cts +0 -2213
  109. package/dist/queue/index.cjs +0 -1044
  110. package/dist/queue/index.cjs.map +0 -1
  111. package/dist/queue/index.d.cts +0 -1265
  112. package/dist/queue-redis/index.cjs +0 -873
  113. package/dist/queue-redis/index.cjs.map +0 -1
  114. package/dist/queue-redis/index.d.cts +0 -82
  115. package/dist/redis/index.cjs +0 -153
  116. package/dist/redis/index.cjs.map +0 -1
  117. package/dist/redis/index.d.cts +0 -82
  118. package/dist/retry/index.cjs +0 -146
  119. package/dist/retry/index.cjs.map +0 -1
  120. package/dist/retry/index.d.cts +0 -172
  121. package/dist/router/index.cjs +0 -111
  122. package/dist/router/index.cjs.map +0 -1
  123. package/dist/router/index.d.cts +0 -46
  124. package/dist/scheduler/index.cjs +0 -576
  125. package/dist/scheduler/index.cjs.map +0 -1
  126. package/dist/scheduler/index.d.cts +0 -145
  127. package/dist/security/index.cjs +0 -2402
  128. package/dist/security/index.cjs.map +0 -1
  129. package/dist/security/index.d.cts +0 -598
  130. package/dist/server/index.cjs +0 -1680
  131. package/dist/server/index.cjs.map +0 -1
  132. package/dist/server/index.d.cts +0 -810
  133. package/dist/server-auth/index.cjs +0 -3146
  134. package/dist/server-auth/index.cjs.map +0 -1
  135. package/dist/server-auth/index.d.cts +0 -1164
  136. package/dist/server-cache/index.cjs +0 -252
  137. package/dist/server-cache/index.cjs.map +0 -1
  138. package/dist/server-cache/index.d.cts +0 -164
  139. package/dist/server-compress/index.cjs +0 -141
  140. package/dist/server-compress/index.cjs.map +0 -1
  141. package/dist/server-compress/index.d.cts +0 -38
  142. package/dist/server-cookies/index.cjs +0 -234
  143. package/dist/server-cookies/index.cjs.map +0 -1
  144. package/dist/server-cookies/index.d.cts +0 -144
  145. package/dist/server-cors/index.cjs +0 -201
  146. package/dist/server-cors/index.cjs.map +0 -1
  147. package/dist/server-cors/index.d.cts +0 -140
  148. package/dist/server-health/index.cjs +0 -62
  149. package/dist/server-health/index.cjs.map +0 -1
  150. package/dist/server-health/index.d.cts +0 -58
  151. package/dist/server-helmet/index.cjs +0 -131
  152. package/dist/server-helmet/index.cjs.map +0 -1
  153. package/dist/server-helmet/index.d.cts +0 -97
  154. package/dist/server-links/index.cjs +0 -992
  155. package/dist/server-links/index.cjs.map +0 -1
  156. package/dist/server-links/index.d.cts +0 -513
  157. package/dist/server-metrics/index.cjs +0 -4535
  158. package/dist/server-metrics/index.cjs.map +0 -1
  159. package/dist/server-metrics/index.d.cts +0 -35
  160. package/dist/server-multipart/index.cjs +0 -237
  161. package/dist/server-multipart/index.cjs.map +0 -1
  162. package/dist/server-multipart/index.d.cts +0 -50
  163. package/dist/server-proxy/index.cjs +0 -186
  164. package/dist/server-proxy/index.cjs.map +0 -1
  165. package/dist/server-proxy/index.d.cts +0 -234
  166. package/dist/server-rate-limit/index.cjs +0 -241
  167. package/dist/server-rate-limit/index.cjs.map +0 -1
  168. package/dist/server-rate-limit/index.d.cts +0 -183
  169. package/dist/server-security/index.cjs +0 -316
  170. package/dist/server-security/index.cjs.map +0 -1
  171. package/dist/server-security/index.d.cts +0 -173
  172. package/dist/server-static/index.cjs +0 -170
  173. package/dist/server-static/index.cjs.map +0 -1
  174. package/dist/server-static/index.d.cts +0 -121
  175. package/dist/server-swagger/index.cjs +0 -1021
  176. package/dist/server-swagger/index.cjs.map +0 -1
  177. package/dist/server-swagger/index.d.cts +0 -382
  178. package/dist/sms/index.cjs +0 -221
  179. package/dist/sms/index.cjs.map +0 -1
  180. package/dist/sms/index.d.cts +0 -130
  181. package/dist/thread/index.cjs +0 -350
  182. package/dist/thread/index.cjs.map +0 -1
  183. package/dist/thread/index.d.cts +0 -260
  184. package/dist/topic/index.cjs +0 -282
  185. package/dist/topic/index.cjs.map +0 -1
  186. package/dist/topic/index.d.cts +0 -523
  187. package/dist/topic-redis/index.cjs +0 -71
  188. package/dist/topic-redis/index.cjs.map +0 -1
  189. package/dist/topic-redis/index.d.cts +0 -42
  190. package/dist/vite/index.cjs +0 -1077
  191. package/dist/vite/index.cjs.map +0 -1
  192. package/dist/vite/index.d.cts +0 -542
  193. package/dist/websocket/index.cjs +0 -1117
  194. package/dist/websocket/index.cjs.map +0 -1
  195. package/dist/websocket/index.d.cts +0 -861
@@ -1,1077 +0,0 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
28
- let vite = require("vite");
29
- let node_fs_promises = require("node:fs/promises");
30
- let node_path = require("node:path");
31
- node_path = __toESM(node_path);
32
- let alepha = require("alepha");
33
- let node_module = require("node:module");
34
- node_module = __toESM(node_module);
35
- let vite_bundle_analyzer = require("vite-bundle-analyzer");
36
- let node_fs = require("node:fs");
37
- let node_util = require("node:util");
38
- let node_zlib = require("node:zlib");
39
- let node_url = require("node:url");
40
-
41
- //#region src/vite/helpers/boot.ts
42
- /**
43
- * Remember:
44
- * At first, functions was inside alepha/vite package, but it's now used in alepha too.
45
- * For avoiding cli -> vite, all code moved here.
46
- */
47
- /**
48
- * Find browser/client entry file path.
49
- */
50
- const getClientEntry = async (root = process.cwd()) => {
51
- const indexPath = (0, node_path.join)(root, "index.html");
52
- try {
53
- return extractFirstModuleScriptSrc(await (0, node_fs_promises.readFile)(indexPath, "utf8")).replace(/\\/g, "/");
54
- } catch {
55
- return;
56
- }
57
- };
58
- /**
59
- * Find server entry file path.
60
- */
61
- const getServerEntry = async (root = process.cwd(), explicitEntry) => {
62
- if (explicitEntry) {
63
- const explicitPath = (0, node_path.join)(root, explicitEntry);
64
- try {
65
- await (0, node_fs_promises.access)(explicitPath);
66
- return explicitPath;
67
- } catch {
68
- throw new alepha.AlephaError(`Explicit server entry file "${explicitEntry}" not found.`);
69
- }
70
- }
71
- for (const entry of [
72
- "src/index.server.ts",
73
- "src/main.server.ts",
74
- "src/server-entry.ts",
75
- "src/index.server.tsx",
76
- "src/main.server.tsx",
77
- "src/server-entry.tsx",
78
- "src/main.ts",
79
- "src/main.tsx"
80
- ]) try {
81
- const path$1 = (0, node_path.join)(root, entry).replace(/\\/g, "/");
82
- await (0, node_fs_promises.access)(path$1);
83
- return path$1;
84
- } catch {}
85
- const clientEntry = await getClientEntry(root);
86
- if (clientEntry) return clientEntry;
87
- throw new alepha.AlephaError(`Could not find a server entry file.`);
88
- };
89
- /**
90
- * Extract first module script src from HTML.
91
- */
92
- function extractFirstModuleScriptSrc(html) {
93
- const scriptRegex = /<script\b[^>]*>[\s\S]*?<\/script>/gi;
94
- let match = scriptRegex.exec(html);
95
- while (match) {
96
- const tag = match[0];
97
- if (/type=["']module["']/i.test(tag)) {
98
- const entry = tag.match(/\bsrc=["']([^"']+)["']/i)?.[1];
99
- if (entry) {
100
- if (entry.startsWith("/")) return entry.substring(1);
101
- return entry;
102
- }
103
- }
104
- match = scriptRegex.exec(html);
105
- }
106
- throw new alepha.AlephaError(`No module script found in the provided HTML.`);
107
- }
108
- const boot = {
109
- getClientEntry,
110
- getServerEntry
111
- };
112
-
113
- //#endregion
114
- //#region src/vite/helpers/createBufferedLogger.ts
115
- /**
116
- * Creates a Vite logger that buffers all messages instead of printing them.
117
- * Useful for silent builds that only show output on failure.
118
- *
119
- * @example
120
- * ```ts
121
- * const logger = createBufferedLogger();
122
- * try {
123
- * await viteBuild({ customLogger: logger, logLevel: 'info' });
124
- * } catch (error) {
125
- * logger.flush(); // Print all buffered logs
126
- * throw error;
127
- * }
128
- * ```
129
- */
130
- function createBufferedLogger() {
131
- const entries = [];
132
- const loggedErrors = /* @__PURE__ */ new WeakSet();
133
- const warnedMessages = /* @__PURE__ */ new Set();
134
- let hasWarned = false;
135
- return {
136
- get hasWarned() {
137
- return hasWarned;
138
- },
139
- info(msg) {
140
- entries.push({
141
- level: "info",
142
- msg,
143
- timestamp: /* @__PURE__ */ new Date()
144
- });
145
- },
146
- warn(msg) {
147
- hasWarned = true;
148
- entries.push({
149
- level: "warn",
150
- msg,
151
- timestamp: /* @__PURE__ */ new Date()
152
- });
153
- },
154
- warnOnce(msg) {
155
- if (warnedMessages.has(msg)) return;
156
- warnedMessages.add(msg);
157
- hasWarned = true;
158
- entries.push({
159
- level: "warn",
160
- msg,
161
- timestamp: /* @__PURE__ */ new Date()
162
- });
163
- },
164
- error(msg, options) {
165
- if (options?.error) loggedErrors.add(options.error);
166
- entries.push({
167
- level: "error",
168
- msg,
169
- timestamp: /* @__PURE__ */ new Date()
170
- });
171
- },
172
- clearScreen() {},
173
- hasErrorLogged(error) {
174
- return loggedErrors.has(error);
175
- },
176
- flush() {
177
- for (const entry of entries) {
178
- const prefix = entry.level === "error" ? "\x1B[31m✖\x1B[0m" : entry.level === "warn" ? "\x1B[33m⚠\x1B[0m" : "\x1B[36mℹ\x1B[0m";
179
- console.log(`${prefix} ${entry.msg}`);
180
- }
181
- },
182
- getEntries() {
183
- return [...entries];
184
- },
185
- clear() {
186
- entries.length = 0;
187
- warnedMessages.clear();
188
- hasWarned = false;
189
- }
190
- };
191
- }
192
-
193
- //#endregion
194
- //#region src/vite/helpers/fileExists.ts
195
- const fileExists = async (path$1) => {
196
- return await (0, node_fs_promises.access)((0, node_path.join)(process.cwd(), path$1)).then(() => true).catch(() => false);
197
- };
198
-
199
- //#endregion
200
- //#region src/vite/helpers/importVite.ts
201
- const importVite = async () => {
202
- try {
203
- return (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("rolldown-vite");
204
- } catch (_error) {
205
- try {
206
- return (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("vite");
207
- } catch (_error$1) {
208
- throw new Error("Vite is not installed. Please install it with `npm install vite`.");
209
- }
210
- }
211
- };
212
-
213
- //#endregion
214
- //#region src/vite/plugins/viteCompress.ts
215
- const gzipCompress = (0, node_util.promisify)(node_zlib.gzip);
216
- const brotliCompress = (0, node_util.promisify)(node_zlib.brotliCompress);
217
- function viteCompress(options = {}) {
218
- const { disabled = false, filter = /\.(js|mjs|cjs|css|wasm|svg)$/ } = options;
219
- return {
220
- name: "compress",
221
- apply: "build",
222
- async writeBundle(outputOptions, bundle) {
223
- if (disabled) return;
224
- const now = Date.now();
225
- const outputDir = outputOptions.dir || (0, node_path.resolve)(process.cwd(), "dist");
226
- const files = Object.keys(bundle).filter((fileName) => {
227
- if (typeof filter === "function") return filter(fileName);
228
- return filter.test(fileName);
229
- }).map((fileName) => ({
230
- fileName,
231
- filePath: (0, node_path.join)(outputDir, fileName)
232
- }));
233
- const compressionTasks = [];
234
- for (const { filePath } of files) compressionTasks.push(compressFile(options, filePath));
235
- await Promise.all(compressionTasks);
236
- this.info(`Compressed ${files.length} file${files.length > 1 ? "s" : ""} in ${Date.now() - now}ms.`);
237
- }
238
- };
239
- }
240
- async function compressFile(options = {}, filePath) {
241
- const { brotli = true, gzip = true } = options;
242
- const compressionTasks = [];
243
- const fileContentPromise = node_fs.promises.readFile(filePath);
244
- if (gzip) {
245
- const gzipOptions = typeof gzip === "object" ? gzip : { level: 9 };
246
- compressionTasks.push(fileContentPromise.then(async (content) => {
247
- const compressed = await gzipCompress(content, gzipOptions);
248
- await node_fs.promises.writeFile(`${filePath}.gz`, compressed);
249
- }));
250
- }
251
- if (brotli) {
252
- const brotliOptions = typeof brotli === "object" ? brotli : {};
253
- compressionTasks.push(fileContentPromise.then(async (content) => {
254
- const compressed = await brotliCompress(content, brotliOptions);
255
- await node_fs.promises.writeFile(`${filePath}.br`, compressed);
256
- }));
257
- }
258
- await Promise.all(compressionTasks);
259
- }
260
-
261
- //#endregion
262
- //#region src/vite/tasks/buildClient.ts
263
- /**
264
- * Build client-side bundle with Vite.
265
- *
266
- * This task compiles the browser/client code for production,
267
- * including code splitting, minification, and optional compression.
268
- */
269
- async function buildClient(opts) {
270
- const { build: viteBuild, mergeConfig } = await importVite();
271
- const plugins = [];
272
- const compress = opts.precompress ? typeof opts.precompress === "object" ? opts.precompress : {} : void 0;
273
- if (opts.stats) plugins.push((0, vite_bundle_analyzer.analyzer)({ analyzerMode: "static" }));
274
- if (opts.precompress && compress) plugins.push(viteCompress(compress));
275
- const logger = opts.silent ? createBufferedLogger() : void 0;
276
- const viteBuildClientConfig = {
277
- mode: "production",
278
- logLevel: opts.silent ? "silent" : void 0,
279
- define: { "process.env.NODE_ENV": "\"production\"" },
280
- publicDir: "public",
281
- build: {
282
- chunkSizeWarningLimit: 1e3,
283
- outDir: opts.dist,
284
- rollupOptions: { output: {
285
- entryFileNames: "entry.[hash].js",
286
- chunkFileNames: "chunk.[hash].js",
287
- assetFileNames: "asset.[hash][extname]"
288
- } }
289
- },
290
- esbuild: { legalComments: "none" },
291
- customLogger: logger,
292
- plugins
293
- };
294
- try {
295
- await viteBuild(mergeConfig(viteBuildClientConfig, opts.config ?? {}));
296
- } catch (error) {
297
- logger?.flush();
298
- throw error;
299
- }
300
- }
301
-
302
- //#endregion
303
- //#region src/vite/tasks/generateExternals.ts
304
- /**
305
- * Generate minimal package.json with pinned external dependencies.
306
- *
307
- * This task creates a package.json in the dist directory containing
308
- * only the external dependencies needed at runtime, with their versions
309
- * pinned to the currently installed versions.
310
- */
311
- async function generateExternals(opts) {
312
- const require$1 = node_module.default.createRequire(__filename);
313
- const deps = {};
314
- for (const dep of opts.externals) try {
315
- const pkgPath = `${require$1.resolve(dep).split(`node_modules/${dep}`)[0]}node_modules/${dep}/package.json`;
316
- deps[dep] = `^${JSON.parse(await (0, node_fs_promises.readFile)(pkgPath, "utf-8")).version}`;
317
- } catch (_err) {
318
- console.warn(`[generateExternals] Cannot find '${dep}' in node_modules`);
319
- }
320
- const minimalPkg = {
321
- type: "module",
322
- main: "index.js",
323
- dependencies: deps
324
- };
325
- await (0, node_fs_promises.mkdir)(opts.distDir, { recursive: true });
326
- await (0, node_fs_promises.writeFile)((0, node_path.join)(opts.distDir, "package.json"), JSON.stringify(minimalPkg, null, 2), "utf-8");
327
- }
328
-
329
- //#endregion
330
- //#region src/vite/tasks/buildServer.ts
331
- /**
332
- * Build server-side SSR bundle with Vite.
333
- *
334
- * This task compiles the server code for production,
335
- * generates the externals package.json, and creates
336
- * the dist/index.js entry wrapper.
337
- */
338
- async function buildServer(opts) {
339
- const { build: viteBuild, mergeConfig } = await importVite();
340
- const plugins = [];
341
- if (opts.stats) plugins.push((0, vite_bundle_analyzer.analyzer)({ analyzerMode: "static" }));
342
- const logger = opts.silent ? createBufferedLogger() : void 0;
343
- const viteBuildServerConfig = {
344
- mode: "production",
345
- logLevel: opts.silent ? "silent" : void 0,
346
- define: { "process.env.NODE_ENV": "\"production\"" },
347
- publicDir: false,
348
- ssr: { noExternal: true },
349
- build: {
350
- ssr: opts.entry,
351
- outDir: `${opts.distDir}/server`,
352
- minify: true,
353
- chunkSizeWarningLimit: 1e4,
354
- rollupOptions: { output: {
355
- entryFileNames: "[hash].js",
356
- chunkFileNames: "[hash].js",
357
- assetFileNames: "[hash][extname]",
358
- format: "esm"
359
- } }
360
- },
361
- esbuild: {
362
- legalComments: "none",
363
- keepNames: true
364
- },
365
- customLogger: logger,
366
- plugins
367
- };
368
- let result;
369
- try {
370
- result = await viteBuild(mergeConfig(viteBuildServerConfig, opts.config || {}));
371
- } catch (error) {
372
- logger?.flush();
373
- throw error;
374
- }
375
- const externals = result.resolvedConfig?.ssr?.external ?? [];
376
- await generateExternals({
377
- distDir: opts.distDir,
378
- externals
379
- });
380
- const entryFile = extractEntryFromBundle(opts.entry, result);
381
- let template = "";
382
- if (opts.clientDir) template = `process.env.REACT_SERVER_TEMPLATE ??= \`${(await (0, node_fs_promises.readFile)(`${opts.distDir}/${opts.clientDir}/index.html`, "utf-8")).replace(/>\s*</g, "><").trim()}\`;\n`;
383
- await (0, node_fs_promises.writeFile)(`${opts.distDir}/index.js`, `// This file was automatically generated. DO NOT MODIFY.
384
- // Changes to this file will be lost when the code is regenerated.
385
- \nprocess.env.NODE_ENV ??= 'production';
386
- ${template}\nawait import('./server/${entryFile}');`.trim());
387
- return { entryFile };
388
- }
389
- /**
390
- * Extract entry filename from Vite build result.
391
- */
392
- function extractEntryFromBundle(entry, result) {
393
- const entryFilePath = entry.startsWith("/") ? entry : (0, node_path.join)(process.cwd(), entry);
394
- const entryFile = (Array.isArray(result) ? result[0] : result).output.find((it) => "facadeModuleId" in it && it.facadeModuleId === entryFilePath)?.fileName;
395
- if (!entryFile) throw new alepha.AlephaError(`Could not find the entry file "${entryFilePath}" in the build output. Please check your entry file and try again.`);
396
- return entryFile;
397
- }
398
-
399
- //#endregion
400
- //#region src/vite/helpers/importAlepha.ts
401
- /**
402
- * Import Alepha instance from a transpiled server entry file.
403
- */
404
- const importAlepha = async (entry, options) => {
405
- if (global.__cli_alepha) return global.__cli_alepha;
406
- const { loadEnv } = await importVite();
407
- const env = loadEnv("development", process.cwd(), "");
408
- for (const key in env) process.env[key] = env[key];
409
- if (options?.env) for (const key in options.env) process.env[key] = options.env[key];
410
- process.env.ALEPHA_CLI_IMPORT = "true";
411
- process.env.LOG_LEVEL = "error";
412
- process.env.LOG_FORMAT = "pretty";
413
- process.env.NODE_ENV = "production";
414
- const mod = await import((0, node_url.pathToFileURL)((0, node_path.join)(process.cwd(), entry)).href);
415
- if (mod.default) return mod.default;
416
- const alepha$1 = global.__cli_alepha;
417
- if (!alepha$1) throw new alepha.AlephaError("Alepha instance not found. Ensure Alepha is initialized.");
418
- return alepha$1;
419
- };
420
-
421
- //#endregion
422
- //#region src/vite/tasks/copyAssets.ts
423
- /**
424
- * Copy assets from Alepha packages to the build output directory.
425
- *
426
- * This task loads the built Alepha application, reads the
427
- * `alepha.build.assets` state to find packages with assets,
428
- * and copies their `/assets` directories to the build output.
429
- *
430
- * Used by modules like AlephaServerSwagger to distribute UI files.
431
- */
432
- async function copyAssets(opts) {
433
- const root = process.cwd();
434
- const assets = (await importAlepha(opts.entry)).state.get("alepha.build.assets");
435
- if (!assets || assets.length === 0) return;
436
- const require$1 = (0, node_module.createRequire)((0, node_path.join)(root, opts.entry));
437
- const buildAssetsDir = (0, node_path.join)(root, `${opts.distDir}/assets`);
438
- await (0, node_fs_promises.mkdir)(buildAssetsDir).catch(() => null);
439
- for (const pkgName of assets ?? []) await (0, node_fs_promises.cp)((0, node_path.resolve)((0, node_path.dirname)(require$1.resolve(`${pkgName}/package.json`)), "assets"), buildAssetsDir, { recursive: true });
440
- }
441
-
442
- //#endregion
443
- //#region src/vite/tasks/generateCloudflare.ts
444
- const WARNING_COMMENT$1 = "// This file was automatically generated. DO NOT MODIFY.\n// Changes to this file will be lost when the code is regenerated.\n";
445
- /**
446
- * Generate Cloudflare Workers deployment configuration.
447
- *
448
- * This task creates:
449
- * - wrangler.jsonc with worker configuration
450
- * - worker.js entry point for Cloudflare Workers
451
- */
452
- async function generateCloudflare(opts = {}) {
453
- const dist = opts.distDir ?? "dist";
454
- const root = process.cwd();
455
- const parts = root.split("/");
456
- const wrangler = {
457
- name: parts[parts.length - 1],
458
- main: "./worker.js",
459
- compatibility_flags: ["nodejs_compat"],
460
- compatibility_date: "2025-11-17"
461
- };
462
- (0, node_fs.writeFileSync)((0, node_path.join)(root, dist, "wrangler.jsonc"), JSON.stringify(wrangler, null, 2));
463
- const workerCode = `
464
- process.env.ALEPHA_SERVERLESS = "true";
465
-
466
- await import("./index.js");
467
-
468
- export default {
469
- fetch: async (request, env, ctx) => {
470
-
471
- await __alepha.start();
472
- const ev = { req: request, res: undefined };
473
- await __alepha.events.emit("web:request", ev);
474
- return ev.res;
475
- },
476
- };
477
- `.trim();
478
- (0, node_fs.writeFileSync)((0, node_path.join)(root, dist, "worker.js"), `${WARNING_COMMENT$1}\n${workerCode}`.trim());
479
- }
480
-
481
- //#endregion
482
- //#region src/vite/tasks/generateDocker.ts
483
- /**
484
- * Generate Docker deployment configuration.
485
- *
486
- * This task creates:
487
- * - Dockerfile with configurable Node image
488
- * - Copies drizzle migrations if they exist
489
- */
490
- async function generateDocker(opts = {}) {
491
- const distDir = opts.distDir ?? "dist";
492
- const image = opts.image ?? "node:24-alpine";
493
- const command = opts.command ?? "node";
494
- if (await fileExists("drizzle")) await (0, node_fs_promises.cp)("drizzle", `${distDir}/drizzle`, { recursive: true });
495
- const dockerfile = `# This file was automatically generated. DO NOT MODIFY.
496
- # Changes to this file will be lost when the code is regenerated.
497
- FROM ${image}
498
- WORKDIR /app
499
-
500
- COPY . .
501
-
502
- CMD ["${command}", "index.js"]
503
- `;
504
- await (0, node_fs_promises.writeFile)(`${distDir}/Dockerfile`, dockerfile);
505
- }
506
-
507
- //#endregion
508
- //#region src/vite/tasks/generateSitemap.ts
509
- /**
510
- * Generate sitemap.xml from Alepha page descriptors.
511
- *
512
- * This task loads the built Alepha application,
513
- * queries all page descriptors, and generates a sitemap.xml
514
- * containing URLs for all accessible pages.
515
- */
516
- async function generateSitemap(opts) {
517
- const alepha$1 = await importAlepha(opts.entry, { env: opts.template ? { REACT_SERVER_TEMPLATE: opts.template } : {} });
518
- if (!alepha$1.isConfigured()) {
519
- await alepha$1.events.emit("configure", alepha$1);
520
- alepha$1.configured = true;
521
- }
522
- return generateSitemapFromAlepha(alepha$1, opts.baseUrl);
523
- }
524
- function generateSitemapFromAlepha(alepha$1, baseUrl) {
525
- const pages = alepha$1.descriptors("page");
526
- const urls = [];
527
- for (const page of pages) {
528
- const options = page.options;
529
- if (options.children) continue;
530
- if (!options.schema?.params) {
531
- const path$1 = options.path || "";
532
- const url = `${baseUrl.replace(/\/$/, "")}${path$1 === "" ? "/" : path$1}`;
533
- urls.push(url);
534
- } else if (options.static && typeof options.static === "object" && options.static.entries) for (const entry of options.static.entries) {
535
- const path$1 = buildPathFromParams(options.path || "", entry.params || {});
536
- const url = `${baseUrl.replace(/\/$/, "")}${path$1}`;
537
- urls.push(url);
538
- }
539
- }
540
- return buildSitemapXml(urls);
541
- }
542
- function buildPathFromParams(pathPattern, params) {
543
- let path$1 = pathPattern;
544
- for (const [key, value] of Object.entries(params)) path$1 = path$1.replace(`:${key}`, String(value));
545
- return path$1 || "/";
546
- }
547
- function buildSitemapXml(urls) {
548
- const lastMod = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
549
- return `<?xml version="1.0" encoding="UTF-8"?>
550
- <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
551
- ${urls.map((url) => ` <url>\n <loc>${escapeXml(url)}</loc>\n\t\t<lastmod>${lastMod}</lastmod>\n </url>`).join("\n")}
552
- </urlset>`;
553
- }
554
- function escapeXml(str) {
555
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
556
- }
557
-
558
- //#endregion
559
- //#region src/vite/tasks/generateVercel.ts
560
- const WARNING_COMMENT = "// This file was automatically generated. DO NOT MODIFY.\n// Changes to this file will be lost when the code is regenerated.\n";
561
- /**
562
- * Generate Vercel deployment configuration.
563
- *
564
- * This task creates:
565
- * - vercel.json with route rewrites
566
- * - api/index.js entry point for Vercel serverless function
567
- * - .vercel/project.json if VERCEL_PROJECT_ID and VERCEL_ORG_ID are set
568
- */
569
- async function generateVercel(opts = {}) {
570
- const distDir = opts.distDir ?? "dist";
571
- const clientDir = opts.clientDir ?? "public";
572
- const { loadEnv } = await importVite();
573
- const env = loadEnv("production", process.cwd(), "");
574
- if (!(0, node_fs.existsSync)(`${distDir}/api`)) (0, node_fs.mkdirSync)(`${distDir}/api`);
575
- (0, node_fs.writeFileSync)(`${distDir}/api/index.js`, `${WARNING_COMMENT}
576
- import "../index.js";
577
-
578
- export default async function (req, res) {
579
- \tawait __alepha.start();
580
- \t__alepha.events.emit("node:request", { req, res });
581
- }
582
- `);
583
- (0, node_fs.writeFileSync)(`${distDir}/vercel.json`, JSON.stringify({
584
- ...opts?.config?.config,
585
- rewrites: [{
586
- source: "/(.*)",
587
- destination: "/api/index.js"
588
- }],
589
- buildCommand: "",
590
- installCommand: "",
591
- outputDirectory: clientDir
592
- }, null, " "));
593
- const projectId = env.VERCEL_PROJECT_ID ?? opts.config?.projectId;
594
- const projectName = env.VERCEL_PROJECT_NAME ?? opts.config?.projectName;
595
- const orgId = env.VERCEL_ORG_ID ?? opts.config?.orgId;
596
- if (projectId && orgId) {
597
- try {
598
- (0, node_fs.mkdirSync)(`${distDir}/.vercel`, { recursive: true });
599
- } catch (_e) {}
600
- (0, node_fs.writeFileSync)(`${distDir}/.vercel/project.json`, JSON.stringify({
601
- projectId,
602
- projectName,
603
- orgId
604
- }, null, " "));
605
- }
606
- if (!(0, node_fs.existsSync)(`${distDir}/${clientDir}`)) {
607
- (0, node_fs.mkdirSync)(`${distDir}/${clientDir}`, { recursive: true });
608
- (0, node_fs.writeFileSync)(`${distDir}/${clientDir}/.keep`, "");
609
- }
610
- }
611
-
612
- //#endregion
613
- //#region src/vite/tasks/prerenderPages.ts
614
- /**
615
- * Pre-render static pages defined in the Alepha application.
616
- *
617
- * This task loads the built Alepha application, queries all page
618
- * descriptors with `static: true`, and generates static HTML files
619
- * for each page. Supports pages with parameterized routes via
620
- * `static.entries` configuration.
621
- */
622
- async function prerenderPages(opts) {
623
- const alepha$1 = await importAlepha(opts.entry);
624
- if (!alepha$1.isConfigured()) {
625
- await alepha$1.events.emit("configure", alepha$1);
626
- alepha$1.configured = true;
627
- }
628
- return await prerenderFromAlepha(alepha$1, opts.dist, opts.compress);
629
- }
630
- async function prerenderFromAlepha(alepha$1, dist, compress) {
631
- let count = 0;
632
- const pages = alepha$1.descriptors("page");
633
- for (const page of pages) {
634
- const options = page.options;
635
- if (options.children) continue;
636
- if (!options.static) continue;
637
- const config = typeof options.static === "object" ? options.static : {};
638
- if (!options.schema?.params) {
639
- count += 1;
640
- await renderFile(page, {}, dist, compress);
641
- continue;
642
- }
643
- if (config.entries) for (const entry of config.entries) {
644
- count += 1;
645
- await renderFile(page, entry, dist, compress);
646
- }
647
- }
648
- return { count };
649
- }
650
- async function renderFile(page, options, dist, compress) {
651
- const { html, state } = await page.render({
652
- html: true,
653
- ...options
654
- });
655
- const pathname = state.url.pathname;
656
- const filepath = `${dist}${pathname === "/" ? "/index" : pathname}.html`;
657
- await (0, node_fs_promises.mkdir)(filepath.substring(0, filepath.lastIndexOf("/")), { recursive: true });
658
- await (0, node_fs_promises.writeFile)(filepath, html);
659
- if (compress) await compressFile(typeof compress === "object" ? compress : {}, filepath);
660
- }
661
-
662
- //#endregion
663
- //#region src/vite/tasks/runAlepha.ts
664
- /**
665
- * Create an Alepha runner for development.
666
- *
667
- * The runner manages the lifecycle of an Alepha application during
668
- * Vite dev server operation, handling start/stop/restart and HMR.
669
- */
670
- function createAlephaRunner(opts) {
671
- return new AlephaRunner({
672
- root: process.cwd().replace(/\\/g, "/"),
673
- started: false,
674
- log: opts.debug ? (...msg) => console.log(...msg) : () => {},
675
- entry: opts.entry,
676
- onReload: () => {}
677
- });
678
- }
679
- var AlephaRunner = class {
680
- state;
681
- constructor(state) {
682
- this.state = state;
683
- }
684
- /**
685
- * Set resolved Vite config.
686
- */
687
- setConfig(config) {
688
- this.state.config = config;
689
- }
690
- /**
691
- * Check if SSR is enabled for the running app.
692
- */
693
- isSsrEnabled() {
694
- if (!this.state.app) return false;
695
- return this.state.app.state.get("alepha.react.server.ssr") ?? false;
696
- }
697
- /**
698
- * Check if app is started.
699
- */
700
- get isStarted() {
701
- return this.state.started;
702
- }
703
- /**
704
- * Get the running Alepha app instance.
705
- */
706
- get app() {
707
- return this.state.app;
708
- }
709
- /**
710
- * Start the Alepha application.
711
- */
712
- async start(server) {
713
- const { loadEnv } = await importVite();
714
- if (this.state.started) {
715
- await this.restart(server, true);
716
- return;
717
- }
718
- if (!this.state.config) {
719
- this.state.log("[DEBUG] No config - skip starting");
720
- return;
721
- }
722
- this.state.onReload?.();
723
- this.state.log("[DEBUG] Starting Alepha app...");
724
- this.state.started = false;
725
- this.state.app = void 0;
726
- const fileUrl = (0, node_url.pathToFileURL)(`${node_path.default.resolve(this.state.config.root, this.state.entry)}`).href;
727
- const env = loadEnv("development", this.state.config.root, "");
728
- const before = { ...process.env };
729
- for (const key in env) process.env[key] = env[key];
730
- process.env.NODE_ENV ??= "development";
731
- process.env.VITE_ALEPHA_DEV = "true";
732
- process.env.SERVER_HOST ??= typeof server.config.server.host === "string" ? server.config.server.host : "localhost";
733
- process.env.SERVER_PORT ??= String(server.config.server.port || "5173");
734
- try {
735
- const now = Date.now();
736
- await server.ssrLoadModule(fileUrl);
737
- this.state.log(`[DEBUG] Alepha app loaded in ${Date.now() - now}ms`);
738
- await new Promise((r) => setTimeout(r, 10));
739
- this.state.app = globalThis.__alepha;
740
- if (!this.state.app) {
741
- this.state.log("[DEBUG] No app found - skip starting");
742
- return;
743
- }
744
- this.state.app.state.set("alepha.node.server", server.httpServer);
745
- await this.state.app.start();
746
- this.state.started = true;
747
- process.env = { ...before };
748
- this.state.log("[DEBUG] Starting Done!");
749
- } catch (e) {
750
- if (e instanceof Error) {
751
- let it = e;
752
- do {
753
- server.ssrFixStacktrace(it);
754
- it = it.cause;
755
- } while (it instanceof Error);
756
- server.ssrFixStacktrace(e);
757
- if (e.cause instanceof Error) server.ssrFixStacktrace(e.cause);
758
- this.state.app?.log?.error("App failed to start:", e);
759
- this.state.app?.log?.info("Waiting for changes to restart...");
760
- }
761
- this.state.log("[DEBUG] Alepha app start error");
762
- this.state.started = false;
763
- }
764
- }
765
- /**
766
- * Stop the Alepha application.
767
- */
768
- async stop() {
769
- if (this.state.app?.stop && this.state.started) {
770
- this.state.log("[DEBUG] Stopping Alepha app...");
771
- await this.state.app.stop();
772
- this.state.started = false;
773
- this.state.log("[DEBUG] Stopping Done!");
774
- } else this.state.log("[DEBUG] Alepha app not started - skip stop");
775
- }
776
- /**
777
- * Restart the Alepha application.
778
- *
779
- * @returns true if the restart was skipped due to locking
780
- */
781
- async restart(server, invalidate) {
782
- if (this.state.lock) {
783
- this.state.log("[DEBUG] STILL LOCKING");
784
- return true;
785
- }
786
- this.state.log("[DEBUG] LOCK RESTART");
787
- this.state.lock = Promise.withResolvers();
788
- const now = Date.now();
789
- this.state.log("[DEBUG] RESTART");
790
- await this.stop();
791
- this.state.log(`[DEBUG] RESTART (stop) in ${Date.now() - now}ms`);
792
- if (invalidate) server.moduleGraph.invalidateAll();
793
- await this.start(server);
794
- this.state.log(`[DEBUG] RESTART OK in ${Date.now() - now}ms`);
795
- setTimeout(() => {
796
- this.state.log("[DEBUG] UNLOCK RESTART");
797
- this.state.lock?.resolve();
798
- this.state.lock = void 0;
799
- }, 500);
800
- return false;
801
- }
802
- /**
803
- * Send reload event to client.
804
- */
805
- sendReload(server) {
806
- server.ws.send({
807
- type: "custom",
808
- event: "alepha:reload",
809
- data: {}
810
- });
811
- }
812
- };
813
- /**
814
- * Check if a URL path is a Vite internal file.
815
- */
816
- function isViteInternalPath(pathname) {
817
- const [path$1] = pathname.split("?");
818
- if (path$1.startsWith("/@") || path$1.startsWith("/src") || path$1.includes("/node_modules/")) return true;
819
- return false;
820
- }
821
-
822
- //#endregion
823
- //#region src/vite/plugins/viteAlephaBuild.ts
824
- /**
825
- * Alepha build plugin for Vite.
826
- *
827
- * This plugin orchestrates the complete build process:
828
- * 1. Build client (if index.html exists)
829
- * 2. Build server (SSR)
830
- * 3. Copy assets from packages
831
- * 4. Pre-render static pages (if enabled)
832
- * 5. Generate sitemap (if enabled)
833
- * 6. Generate deployment config (Vercel/Cloudflare/Docker)
834
- *
835
- * Build mode can be controlled via ALEPHA_BUILD_MODE env var for CLI integration.
836
- */
837
- async function viteAlephaBuild(options = {}) {
838
- const entry = options.serverEntry ?? await boot.getServerEntry();
839
- const distDir = "dist";
840
- const clientDir = "public";
841
- let rootConfig = {};
842
- return {
843
- name: "alepha-build",
844
- apply: "build",
845
- config(config, ctx) {
846
- if (process.env.ALEPHA_BUILD_MODE === "cli") return;
847
- if (!process.env.VITE_DOUBLE_BUILD_DONE) rootConfig = config;
848
- if (ctx.isSsrBuild || !process.env.VITE_DOUBLE_BUILD_DONE) config.publicDir = false;
849
- else config.publicDir = "public";
850
- },
851
- async buildStart() {
852
- const buildMode = process.env.ALEPHA_BUILD_MODE;
853
- if (buildMode === "cli") return;
854
- if (process.env.VITE_DOUBLE_BUILD_DONE === "true") return;
855
- process.env.VITE_DOUBLE_BUILD_DONE = "true";
856
- const hasClient = options.client !== false && await fileExists("index.html");
857
- const buildClientOptions = typeof options.client === "object" ? options.client : {};
858
- const stats = options.stats ?? process.env.ALEPHA_BUILD_STATS === "true";
859
- if (buildMode === "client") {
860
- if (hasClient) await buildClient({
861
- ...buildClientOptions,
862
- config: rootConfig,
863
- dist: `${distDir}/${clientDir}`,
864
- stats
865
- });
866
- process.exit(0);
867
- }
868
- if (buildMode === "server") {
869
- if (entry) {
870
- let clientBuilt = false;
871
- try {
872
- await (0, node_fs_promises.readFile)(`${distDir}/${clientDir}/index.html`, "utf-8");
873
- clientBuilt = true;
874
- } catch {}
875
- await buildServer({
876
- config: { base: rootConfig.base || "" },
877
- entry,
878
- distDir,
879
- clientDir: clientBuilt ? clientDir : void 0,
880
- stats
881
- });
882
- }
883
- process.exit(0);
884
- }
885
- if (hasClient) await buildClient({
886
- ...buildClientOptions,
887
- config: rootConfig,
888
- dist: `${distDir}/${clientDir}`,
889
- stats
890
- });
891
- let template = "";
892
- if (hasClient) template = await (0, node_fs_promises.readFile)(`${distDir}/${clientDir}/index.html`, "utf-8");
893
- if (entry) {
894
- await buildServer({
895
- config: { base: rootConfig.base || "" },
896
- entry,
897
- distDir,
898
- clientDir: hasClient ? clientDir : void 0,
899
- stats
900
- });
901
- if (hasClient && options.serverEntry !== false) await (0, node_fs_promises.unlink)(`${distDir}/${clientDir}/index.html`);
902
- await copyAssets({
903
- entry: `${distDir}/index.js`,
904
- distDir
905
- });
906
- }
907
- if (buildClientOptions.sitemap && entry) await (0, node_fs_promises.writeFile)(`${distDir}/${clientDir}/sitemap.xml`, await generateSitemap({
908
- entry: `${distDir}/index.js`,
909
- baseUrl: buildClientOptions.sitemap.hostname
910
- }));
911
- if (buildClientOptions.prerender && template) await prerenderPages({
912
- dist: `${distDir}/${clientDir}`,
913
- entry: `${distDir}/index.js`,
914
- compress: buildClientOptions.precompress
915
- });
916
- if (options.vercel) await generateVercel({
917
- distDir,
918
- clientDir,
919
- config: typeof options.vercel === "boolean" ? {} : options.vercel
920
- });
921
- if (options.cloudflare) await generateCloudflare({ distDir });
922
- if (options.docker) await generateDocker({
923
- distDir,
924
- ...typeof options.docker === "boolean" ? {} : options.docker
925
- });
926
- process.exit(0);
927
- }
928
- };
929
- }
930
-
931
- //#endregion
932
- //#region src/vite/plugins/viteAlephaDev.ts
933
- /**
934
- * Plug Alepha into Vite development server.
935
- *
936
- * This plugin manages the Alepha application lifecycle during development,
937
- * handling hot module replacement and request forwarding.
938
- */
939
- async function viteAlephaDev(options = {}) {
940
- let entry = options.serverEntry;
941
- if (!entry) {
942
- entry = await boot.getServerEntry();
943
- if (!entry) return {
944
- name: "alepha-dev",
945
- apply: "serve",
946
- config() {}
947
- };
948
- }
949
- const runner = createAlephaRunner({
950
- entry,
951
- debug: options.debug
952
- });
953
- return {
954
- name: "alepha-dev",
955
- apply: "serve",
956
- configResolved(resolvedConfig) {
957
- runner.setConfig(resolvedConfig);
958
- },
959
- async handleHotUpdate(ctx) {
960
- if (options.debug) console.log("[DEBUG] HMR", ctx.file);
961
- if (ctx.file.includes("/.idea/")) return [];
962
- const isServerOnly = !ctx.modules[0]?._clientModule;
963
- const isBrowserOnly = !ctx.modules[0]?._ssrModule;
964
- const isSsrEnabled = runner.isSsrEnabled();
965
- if (isBrowserOnly) {
966
- if (options.debug) console.log("[DEBUG] HMR - browser only - no reason to reload server");
967
- return;
968
- }
969
- const root = process.cwd().replace(/\\/g, "/");
970
- const invalidate = !ctx.file.startsWith(root);
971
- if (invalidate && options.debug) console.log("[DEBUG] HMR - outside root - invalidate all");
972
- if (!isSsrEnabled && isServerOnly) {
973
- await runner.restart(ctx.server, invalidate);
974
- return [];
975
- }
976
- if (isSsrEnabled && ctx.modules[0]) {
977
- if (await runner.restart(ctx.server, invalidate)) return [];
978
- if (!runner.isStarted) {
979
- if (options.debug) console.log("[DEBUG] HMR - abort due to app not started");
980
- return [];
981
- }
982
- if (isServerOnly && runner.isStarted) {
983
- runner.sendReload(ctx.server);
984
- return [];
985
- }
986
- }
987
- },
988
- async configureServer(server) {
989
- server.middlewares.use((req, res, next) => {
990
- if (runner.isStarted && runner.app && req.url && !isViteInternalPath(req.url)) {
991
- let ended = false;
992
- const writeHead = res.writeHead.bind(res);
993
- res.writeHead = (...args) => {
994
- ended = true;
995
- return writeHead(args[0], args[1], args[2]);
996
- };
997
- return runner.app.events.emit("node:request", {
998
- req,
999
- res
1000
- }).then(() => {
1001
- if (!ended) next();
1002
- });
1003
- }
1004
- next();
1005
- });
1006
- server.config.logger.info = (msg) => {
1007
- runner.app?.log?.info(msg.trim());
1008
- };
1009
- server.config.logger.clearScreen = () => {};
1010
- await runner.start(server);
1011
- },
1012
- async closeBundle() {}
1013
- };
1014
- }
1015
-
1016
- //#endregion
1017
- //#region src/vite/plugins/viteAlepha.ts
1018
- function viteAlepha(options = {}) {
1019
- if (process.env.NODE_ENV === "test") return [];
1020
- const plugins = [];
1021
- if (options.react !== false) try {
1022
- const { default: viteReact } = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("@vitejs/plugin-react");
1023
- plugins.push(viteReact());
1024
- } catch (e) {}
1025
- plugins.push(viteAlephaDev(options), viteAlephaBuild(options));
1026
- plugins[alepha.OPTIONS] = options;
1027
- return plugins;
1028
- }
1029
-
1030
- //#endregion
1031
- //#region src/vite/index.ts
1032
- /**
1033
- * Plugin vite for Alepha framework.
1034
- *
1035
- * This module provides Vite plugins and configurations to integrate Alepha applications with Vite's build and development processes.
1036
- *
1037
- * @example
1038
- * ```ts
1039
- * import { defineConfig } from "vite";
1040
- * import { viteAlepha } from "alepha/vite";
1041
- *
1042
- * export default defineConfig({
1043
- * plugins: [viteAlepha()],
1044
- * // other Vite configurations...
1045
- * });
1046
- * ```
1047
- *
1048
- * @module alepha.vite
1049
- */
1050
-
1051
- //#endregion
1052
- exports.AlephaRunner = AlephaRunner;
1053
- exports.boot = boot;
1054
- exports.buildClient = buildClient;
1055
- exports.buildServer = buildServer;
1056
- exports.compressFile = compressFile;
1057
- exports.copyAssets = copyAssets;
1058
- exports.createAlephaRunner = createAlephaRunner;
1059
- exports.createBufferedLogger = createBufferedLogger;
1060
- Object.defineProperty(exports, 'defineConfig', {
1061
- enumerable: true,
1062
- get: function () {
1063
- return vite.defineConfig;
1064
- }
1065
- });
1066
- exports.generateCloudflare = generateCloudflare;
1067
- exports.generateDocker = generateDocker;
1068
- exports.generateExternals = generateExternals;
1069
- exports.generateSitemap = generateSitemap;
1070
- exports.generateVercel = generateVercel;
1071
- exports.isViteInternalPath = isViteInternalPath;
1072
- exports.prerenderPages = prerenderPages;
1073
- exports.viteAlepha = viteAlepha;
1074
- exports.viteAlephaBuild = viteAlephaBuild;
1075
- exports.viteAlephaDev = viteAlephaDev;
1076
- exports.viteCompress = viteCompress;
1077
- //# sourceMappingURL=index.cjs.map