elit 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +275 -128
  2. package/dist/build.d.mts +10 -1
  3. package/dist/build.d.ts +10 -1
  4. package/dist/build.js +670 -1
  5. package/dist/build.mjs +641 -1
  6. package/dist/chokidar.d.mts +134 -0
  7. package/dist/chokidar.d.ts +134 -0
  8. package/dist/chokidar.js +240 -0
  9. package/dist/chokidar.mjs +221 -0
  10. package/dist/cli.js +2792 -495
  11. package/dist/dom.d.mts +10 -3
  12. package/dist/dom.d.ts +10 -3
  13. package/dist/dom.js +676 -1
  14. package/dist/dom.mjs +647 -1
  15. package/dist/el.d.mts +16 -36
  16. package/dist/el.d.ts +16 -36
  17. package/dist/el.js +789 -1
  18. package/dist/el.mjs +583 -1
  19. package/dist/fs.d.mts +255 -0
  20. package/dist/fs.d.ts +255 -0
  21. package/dist/fs.js +513 -0
  22. package/dist/fs.mjs +469 -0
  23. package/dist/hmr.js +112 -1
  24. package/dist/hmr.mjs +91 -1
  25. package/dist/http.d.mts +163 -0
  26. package/dist/http.d.ts +163 -0
  27. package/dist/http.js +632 -0
  28. package/dist/http.mjs +605 -0
  29. package/dist/https.d.mts +108 -0
  30. package/dist/https.d.ts +108 -0
  31. package/dist/https.js +907 -0
  32. package/dist/https.mjs +901 -0
  33. package/dist/index.d.mts +613 -33
  34. package/dist/index.d.ts +613 -33
  35. package/dist/index.js +2589 -1
  36. package/dist/index.mjs +2312 -1
  37. package/dist/mime-types.d.mts +48 -0
  38. package/dist/mime-types.d.ts +48 -0
  39. package/dist/mime-types.js +197 -0
  40. package/dist/mime-types.mjs +166 -0
  41. package/dist/path.d.mts +163 -0
  42. package/dist/path.d.ts +163 -0
  43. package/dist/path.js +350 -0
  44. package/dist/path.mjs +310 -0
  45. package/dist/router.d.mts +3 -1
  46. package/dist/router.d.ts +3 -1
  47. package/dist/router.js +830 -1
  48. package/dist/router.mjs +801 -1
  49. package/dist/runtime.d.mts +97 -0
  50. package/dist/runtime.d.ts +97 -0
  51. package/dist/runtime.js +43 -0
  52. package/dist/runtime.mjs +15 -0
  53. package/dist/server.d.mts +5 -1
  54. package/dist/server.d.ts +5 -1
  55. package/dist/server.js +3267 -1
  56. package/dist/server.mjs +3241 -1
  57. package/dist/state.d.mts +3 -1
  58. package/dist/state.d.ts +3 -1
  59. package/dist/state.js +1036 -1
  60. package/dist/state.mjs +992 -1
  61. package/dist/style.d.mts +47 -1
  62. package/dist/style.d.ts +47 -1
  63. package/dist/style.js +551 -1
  64. package/dist/style.mjs +483 -1
  65. package/dist/{types-DOAdFFJB.d.ts → types-C0nGi6MX.d.mts} +29 -13
  66. package/dist/{types-DOAdFFJB.d.mts → types-Du6kfwTm.d.ts} +29 -13
  67. package/dist/types.d.mts +452 -3
  68. package/dist/types.d.ts +452 -3
  69. package/dist/types.js +18 -1
  70. package/dist/ws.d.mts +195 -0
  71. package/dist/ws.d.ts +195 -0
  72. package/dist/ws.js +380 -0
  73. package/dist/ws.mjs +358 -0
  74. package/dist/wss.d.mts +108 -0
  75. package/dist/wss.d.ts +108 -0
  76. package/dist/wss.js +1306 -0
  77. package/dist/wss.mjs +1300 -0
  78. package/package.json +53 -6
  79. package/dist/client.d.mts +0 -9
  80. package/dist/client.d.ts +0 -9
  81. package/dist/client.js +0 -1
  82. package/dist/client.mjs +0 -1
package/dist/build.js CHANGED
@@ -1 +1,670 @@
1
- "use strict";var e=require("esbuild"),t=require("fs"),o=require("path"),n={outDir:"dist",minify:!0,sourcemap:!1,target:"es2020",format:"esm",treeshake:!0,logging:!0,external:[]};function i(e){if(0===e)return"0 B";let t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(2))+" "+["B","KB","MB","GB"][t]}exports.build=async function(r){let l={...n,...r},s=Date.now();if(!l.entry)throw new Error("Entry file is required");let a=o.resolve(l.entry),c=o.resolve(l.outDir),g=l.outFile;if(!g){g=o.basename(l.entry,o.extname(l.entry))+("cjs"===l.format?".cjs":".js")}let f=o.join(c,g);try{t.mkdirSync(c,{recursive:!0})}catch{}l.logging&&(console.log("\n🔨 Building..."),console.log(` Entry: ${l.entry}`),console.log(` Output: ${f}`),console.log(` Format: ${l.format}`),console.log(` Target: ${l.target}`));let u={name:"browser-only",setup(e){e.onResolve({filter:/^(node:.*|fs|path|http|https|url|os|child_process|net|tls|crypto|stream|util|events|buffer|zlib|readline|process|assert|constants|dns|domain|punycode|querystring|repl|string_decoder|sys|timers|tty|v8|vm)$/},()=>({path:"node-builtin",external:!0,sideEffects:!1})),e.onResolve({filter:/^(chokidar|esbuild|mime-types|open|ws|fs\/promises)$/},()=>({path:"server-dep",external:!0,sideEffects:!1})),e.onLoad({filter:/[\\/](server|config|cli)\.ts$/},()=>({contents:"export {}",loader:"js"}))}};try{let n=l.platform||("cjs"===l.format?"node":"browser"),r="browser"===n?[u]:[],g={};l.env&&(Object.entries(l.env).forEach(([e,t])=>{e.startsWith("VITE_")&&(g[`import.meta.env.${e}`]=JSON.stringify(t))}),l.env.MODE&&(g["import.meta.env.MODE"]=JSON.stringify(l.env.MODE)),g["import.meta.env.DEV"]=JSON.stringify("production"!==l.env.MODE),g["import.meta.env.PROD"]=JSON.stringify("production"===l.env.MODE));let m=await e.build({entryPoints:[a],bundle:!0,outfile:f,format:l.format,target:l.target,minify:l.minify,sourcemap:l.sourcemap,external:l.external,treeShaking:l.treeshake,globalName:l.globalName,platform:n,plugins:r,define:g,logLevel:l.logging?"info":"silent",metafile:!0,...l.minify&&{minifyWhitespace:!0,minifyIdentifiers:!0,minifySyntax:!0,legalComments:"none",mangleProps:/^_/,keepNames:!1}}),p=Date.now()-s,y=t.statSync(f).size;if(l.logging&&(console.log("\n✅ Build successful!"),console.log(` Time: ${p}ms`),console.log(` Size: ${i(y)}`),m.metafile)){let e=Object.keys(m.metafile.inputs).length;console.log(` Files: ${e} input(s)`);let t=Object.keys(m.metafile.outputs);if(t.length>0){let e=m.metafile.outputs[t[0]];if(e&&e.inputs){let t=Object.entries(e.inputs).sort(([,e],[,t])=>t.bytesInOutput-e.bytesInOutput).slice(0,5);t.length>0&&(console.log("\n 📊 Top 5 largest modules:"),t.forEach(([e,t])=>{let o=e.split(/[/\\]/).pop()||e;console.log(` ${o.padEnd(30)} ${i(t.bytesInOutput)}`)}))}}}let d={outputPath:f,buildTime:p,size:y};if(l.copy&&l.copy.length>0){l.logging&&console.log("\n📦 Copying files...");for(let e of l.copy){let n=o.resolve(e.from),i=o.resolve(c,e.to),r=o.dirname(i);if(t.existsSync(r)||t.mkdirSync(r,{recursive:!0}),t.existsSync(n)){if(e.transform){let o=t.readFileSync(n,"utf-8"),r=e.transform(o,l);t.writeFileSync(i,r)}else t.copyFileSync(n,i);l.logging&&console.log(` ✓ ${e.from} → ${e.to}`)}else l.logging&&console.warn(` ⚠ File not found: ${e.from}`)}}return l.onBuildEnd&&await l.onBuildEnd(d),l.logging&&console.log(""),d}catch(e){throw l.logging&&(console.error("\n❌ Build failed:"),console.error(e)),e}};
1
+ "use strict";
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 __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/build.ts
31
+ var build_exports = {};
32
+ __export(build_exports, {
33
+ build: () => build
34
+ });
35
+ module.exports = __toCommonJS(build_exports);
36
+
37
+ // src/runtime.ts
38
+ var runtime = (() => {
39
+ if (typeof Deno !== "undefined") return "deno";
40
+ if (typeof Bun !== "undefined") return "bun";
41
+ return "node";
42
+ })();
43
+ var isNode = runtime === "node";
44
+ var isBun = runtime === "bun";
45
+ var isDeno = runtime === "deno";
46
+
47
+ // src/fs.ts
48
+ function parseOptions(options, defaultValue) {
49
+ return typeof options === "string" ? { encoding: options } : options || defaultValue;
50
+ }
51
+ function decodeContent(content, encoding) {
52
+ if (encoding) {
53
+ return new TextDecoder(encoding).decode(content);
54
+ }
55
+ return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
56
+ }
57
+ function dataToUint8Array(data) {
58
+ if (typeof data === "string") {
59
+ return new TextEncoder().encode(data);
60
+ }
61
+ if (data instanceof Buffer) {
62
+ return new Uint8Array(data);
63
+ }
64
+ return data;
65
+ }
66
+ var fs;
67
+ var fsPromises;
68
+ if (isNode) {
69
+ fs = require("fs");
70
+ fsPromises = require("fs/promises");
71
+ }
72
+ function readFileSync(path, options) {
73
+ const opts = parseOptions(options, {});
74
+ if (isNode) {
75
+ return fs.readFileSync(path, opts);
76
+ } else if (isBun) {
77
+ const file = Bun.file(path);
78
+ const content = file.arrayBuffer();
79
+ return decodeContent(content, opts.encoding);
80
+ } else if (isDeno) {
81
+ const content = Deno.readFileSync(path);
82
+ return decodeContent(content, opts.encoding);
83
+ }
84
+ throw new Error("Unsupported runtime");
85
+ }
86
+ function writeFileSync(path, data, options) {
87
+ const opts = parseOptions(options, {});
88
+ if (isNode) {
89
+ fs.writeFileSync(path, data, opts);
90
+ } else if (isBun) {
91
+ Bun.write(path, data);
92
+ } else if (isDeno) {
93
+ Deno.writeFileSync(path, dataToUint8Array(data));
94
+ }
95
+ }
96
+ function existsSync(path) {
97
+ try {
98
+ statSync(path);
99
+ return true;
100
+ } catch {
101
+ return false;
102
+ }
103
+ }
104
+ function statSync(path) {
105
+ if (isNode) {
106
+ return fs.statSync(path);
107
+ } else if (isBun) {
108
+ const file = Bun.file(path);
109
+ const size = file.size;
110
+ try {
111
+ file.arrayBuffer();
112
+ } catch {
113
+ throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
114
+ }
115
+ return createStatsObject(path, size, false);
116
+ } else if (isDeno) {
117
+ const info = Deno.statSync(path);
118
+ return createStatsFromDenoFileInfo(info);
119
+ }
120
+ throw new Error("Unsupported runtime");
121
+ }
122
+ function mkdirSync(path, options) {
123
+ const opts = typeof options === "number" ? { mode: options } : options || {};
124
+ if (isNode) {
125
+ fs.mkdirSync(path, opts);
126
+ } else if (isBun) {
127
+ Deno.mkdirSync(path, { recursive: opts.recursive });
128
+ } else if (isDeno) {
129
+ Deno.mkdirSync(path, { recursive: opts.recursive });
130
+ }
131
+ }
132
+ function copyFileSync(src, dest, flags) {
133
+ if (isNode) {
134
+ fs.copyFileSync(src, dest, flags);
135
+ } else if (isBun) {
136
+ Deno.copyFileSync(src, dest);
137
+ } else if (isDeno) {
138
+ Deno.copyFileSync(src, dest);
139
+ }
140
+ }
141
+ function createStatsObject(_path, size, isDir) {
142
+ const now = Date.now();
143
+ return {
144
+ isFile: () => !isDir,
145
+ isDirectory: () => isDir,
146
+ isBlockDevice: () => false,
147
+ isCharacterDevice: () => false,
148
+ isSymbolicLink: () => false,
149
+ isFIFO: () => false,
150
+ isSocket: () => false,
151
+ dev: 0,
152
+ ino: 0,
153
+ mode: isDir ? 16877 : 33188,
154
+ nlink: 1,
155
+ uid: 0,
156
+ gid: 0,
157
+ rdev: 0,
158
+ size,
159
+ blksize: 4096,
160
+ blocks: Math.ceil(size / 512),
161
+ atimeMs: now,
162
+ mtimeMs: now,
163
+ ctimeMs: now,
164
+ birthtimeMs: now,
165
+ atime: new Date(now),
166
+ mtime: new Date(now),
167
+ ctime: new Date(now),
168
+ birthtime: new Date(now)
169
+ };
170
+ }
171
+ function createStatsFromDenoFileInfo(info) {
172
+ return {
173
+ isFile: () => info.isFile,
174
+ isDirectory: () => info.isDirectory,
175
+ isBlockDevice: () => false,
176
+ isCharacterDevice: () => false,
177
+ isSymbolicLink: () => info.isSymlink || false,
178
+ isFIFO: () => false,
179
+ isSocket: () => false,
180
+ dev: info.dev || 0,
181
+ ino: info.ino || 0,
182
+ mode: info.mode || 0,
183
+ nlink: info.nlink || 1,
184
+ uid: info.uid || 0,
185
+ gid: info.gid || 0,
186
+ rdev: 0,
187
+ size: info.size,
188
+ blksize: info.blksize || 4096,
189
+ blocks: info.blocks || Math.ceil(info.size / 512),
190
+ atimeMs: info.atime?.getTime() || Date.now(),
191
+ mtimeMs: info.mtime?.getTime() || Date.now(),
192
+ ctimeMs: info.birthtime?.getTime() || Date.now(),
193
+ birthtimeMs: info.birthtime?.getTime() || Date.now(),
194
+ atime: info.atime || /* @__PURE__ */ new Date(),
195
+ mtime: info.mtime || /* @__PURE__ */ new Date(),
196
+ ctime: info.birthtime || /* @__PURE__ */ new Date(),
197
+ birthtime: info.birthtime || /* @__PURE__ */ new Date()
198
+ };
199
+ }
200
+
201
+ // src/path.ts
202
+ function getSeparator(isWin) {
203
+ return isWin ? "\\" : "/";
204
+ }
205
+ function getCwd() {
206
+ if (isNode || isBun) {
207
+ return process.cwd();
208
+ } else if (isDeno) {
209
+ return Deno.cwd();
210
+ }
211
+ return "/";
212
+ }
213
+ function findLastSeparator(path) {
214
+ return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
215
+ }
216
+ function createPathOps(isWin) {
217
+ return {
218
+ sep: getSeparator(isWin),
219
+ delimiter: isWin ? ";" : ":",
220
+ normalize: (path) => normalizePath(path, isWin),
221
+ join: (...paths) => joinPaths(paths, isWin),
222
+ resolve: (...paths) => resolvePaths(paths, isWin),
223
+ isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
224
+ relative: (from, to) => relativePath(from, to, isWin),
225
+ dirname: (path) => getDirname(path, isWin),
226
+ basename: (path, ext) => getBasename(path, ext, isWin),
227
+ extname: (path) => getExtname(path),
228
+ parse: (path) => parsePath(path, isWin),
229
+ format: (pathObject) => formatPath(pathObject, isWin)
230
+ };
231
+ }
232
+ function isAbsolutePosix(path) {
233
+ return path.length > 0 && path[0] === "/";
234
+ }
235
+ function isAbsoluteWin(path) {
236
+ const len = path.length;
237
+ if (len === 0) return false;
238
+ const code = path.charCodeAt(0);
239
+ if (code === 47 || code === 92) {
240
+ return true;
241
+ }
242
+ if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
243
+ if (len > 2 && path.charCodeAt(1) === 58) {
244
+ const code2 = path.charCodeAt(2);
245
+ if (code2 === 47 || code2 === 92) {
246
+ return true;
247
+ }
248
+ }
249
+ }
250
+ return false;
251
+ }
252
+ var isWindows = (() => {
253
+ if (isNode) {
254
+ return process.platform === "win32";
255
+ } else if (isDeno) {
256
+ return Deno.build.os === "windows";
257
+ }
258
+ return typeof process !== "undefined" && process.platform === "win32";
259
+ })();
260
+ var posix = createPathOps(false);
261
+ var win32 = createPathOps(true);
262
+ function normalizePath(path, isWin) {
263
+ if (path.length === 0) return ".";
264
+ const separator = getSeparator(isWin);
265
+ const isAbsolute = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
266
+ const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
267
+ let normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
268
+ const parts = normalized.split(separator);
269
+ const result = [];
270
+ for (let i = 0; i < parts.length; i++) {
271
+ const part = parts[i];
272
+ if (part === "" || part === ".") {
273
+ if (i === 0 && isAbsolute) result.push("");
274
+ continue;
275
+ }
276
+ if (part === "..") {
277
+ if (result.length > 0 && result[result.length - 1] !== "..") {
278
+ if (!(result.length === 1 && result[0] === "")) {
279
+ result.pop();
280
+ }
281
+ } else if (!isAbsolute) {
282
+ result.push("..");
283
+ }
284
+ } else {
285
+ result.push(part);
286
+ }
287
+ }
288
+ let final = result.join(separator);
289
+ if (final.length === 0) {
290
+ return isAbsolute ? separator : ".";
291
+ }
292
+ if (trailingSeparator && final[final.length - 1] !== separator) {
293
+ final += separator;
294
+ }
295
+ return final;
296
+ }
297
+ function joinPaths(paths, isWin) {
298
+ if (paths.length === 0) return ".";
299
+ const separator = getSeparator(isWin);
300
+ let joined = "";
301
+ for (let i = 0; i < paths.length; i++) {
302
+ const path = paths[i];
303
+ if (path && path.length > 0) {
304
+ if (joined.length === 0) {
305
+ joined = path;
306
+ } else {
307
+ joined += separator + path;
308
+ }
309
+ }
310
+ }
311
+ if (joined.length === 0) return ".";
312
+ return normalizePath(joined, isWin);
313
+ }
314
+ function resolvePaths(paths, isWin) {
315
+ const separator = getSeparator(isWin);
316
+ let resolved = "";
317
+ let isAbsolute = false;
318
+ for (let i = paths.length - 1; i >= 0 && !isAbsolute; i--) {
319
+ const path = paths[i];
320
+ if (path && path.length > 0) {
321
+ resolved = path + (resolved.length > 0 ? separator + resolved : "");
322
+ isAbsolute = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
323
+ }
324
+ }
325
+ if (!isAbsolute) {
326
+ const cwd = getCwd();
327
+ resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
328
+ }
329
+ return normalizePath(resolved, isWin);
330
+ }
331
+ function relativePath(from, to, isWin) {
332
+ from = resolvePaths([from], isWin);
333
+ to = resolvePaths([to], isWin);
334
+ if (from === to) return "";
335
+ const separator = getSeparator(isWin);
336
+ const fromParts = from.split(separator).filter((p) => p.length > 0);
337
+ const toParts = to.split(separator).filter((p) => p.length > 0);
338
+ let commonLength = 0;
339
+ const minLength = Math.min(fromParts.length, toParts.length);
340
+ for (let i = 0; i < minLength; i++) {
341
+ if (fromParts[i] === toParts[i]) {
342
+ commonLength++;
343
+ } else {
344
+ break;
345
+ }
346
+ }
347
+ const upCount = fromParts.length - commonLength;
348
+ const result = [];
349
+ for (let i = 0; i < upCount; i++) {
350
+ result.push("..");
351
+ }
352
+ for (let i = commonLength; i < toParts.length; i++) {
353
+ result.push(toParts[i]);
354
+ }
355
+ return result.join(separator) || ".";
356
+ }
357
+ function getDirname(path, isWin) {
358
+ if (path.length === 0) return ".";
359
+ const separator = getSeparator(isWin);
360
+ const normalized = normalizePath(path, isWin);
361
+ const lastSepIndex = normalized.lastIndexOf(separator);
362
+ if (lastSepIndex === -1) return ".";
363
+ if (lastSepIndex === 0) return separator;
364
+ return normalized.slice(0, lastSepIndex);
365
+ }
366
+ function getBasename(path, ext, isWin) {
367
+ if (path.length === 0) return "";
368
+ const lastSepIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
369
+ let base = lastSepIndex === -1 ? path : path.slice(lastSepIndex + 1);
370
+ if (ext && base.endsWith(ext)) {
371
+ base = base.slice(0, base.length - ext.length);
372
+ }
373
+ return base;
374
+ }
375
+ function getExtname(path) {
376
+ const lastDotIndex = path.lastIndexOf(".");
377
+ const lastSepIndex = findLastSeparator(path);
378
+ if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex === path.length - 1) {
379
+ return "";
380
+ }
381
+ return path.slice(lastDotIndex);
382
+ }
383
+ function parsePath(path, isWin) {
384
+ let root = "";
385
+ if (isWin) {
386
+ if (path.length >= 2 && path[1] === ":") {
387
+ root = path.slice(0, 2);
388
+ if (path.length > 2 && (path[2] === "\\" || path[2] === "/")) {
389
+ root += "\\";
390
+ }
391
+ } else if (path[0] === "\\" || path[0] === "/") {
392
+ root = "\\";
393
+ }
394
+ } else {
395
+ if (path[0] === "/") {
396
+ root = "/";
397
+ }
398
+ }
399
+ const dir = getDirname(path, isWin);
400
+ const base = getBasename(path, void 0, isWin);
401
+ const ext = getExtname(path);
402
+ const name = ext ? base.slice(0, base.length - ext.length) : base;
403
+ return { root, dir, base, ext, name };
404
+ }
405
+ function formatPath(pathObject, isWin) {
406
+ const separator = getSeparator(isWin);
407
+ const dir = pathObject.dir || pathObject.root || "";
408
+ const base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
409
+ if (!dir) return base;
410
+ if (dir === pathObject.root) return dir + base;
411
+ return dir + separator + base;
412
+ }
413
+ function join(...paths) {
414
+ return joinPaths(paths, isWindows);
415
+ }
416
+ function resolve(...paths) {
417
+ return resolvePaths(paths, isWindows);
418
+ }
419
+ function dirname(path) {
420
+ return getDirname(path, isWindows);
421
+ }
422
+ function basename(path, ext) {
423
+ return getBasename(path, ext, isWindows);
424
+ }
425
+ function extname(path) {
426
+ return getExtname(path);
427
+ }
428
+
429
+ // src/build.ts
430
+ function ensureDir(dirPath) {
431
+ try {
432
+ mkdirSync(dirPath, { recursive: true });
433
+ } catch (error) {
434
+ }
435
+ }
436
+ function calculateBuildMetrics(startTime, outputPath) {
437
+ const buildTime = Date.now() - startTime;
438
+ const stats = statSync(outputPath);
439
+ return { buildTime, size: stats.size };
440
+ }
441
+ function readFileAsString(filePath) {
442
+ const contentBuffer = readFileSync(filePath, "utf-8");
443
+ return typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString("utf-8");
444
+ }
445
+ function getMinifyOptions(minify) {
446
+ return minify ? {
447
+ minifyWhitespace: true,
448
+ minifyIdentifiers: true,
449
+ minifySyntax: true,
450
+ legalComments: "none",
451
+ mangleProps: /^_/,
452
+ keepNames: false
453
+ } : {};
454
+ }
455
+ function logBuildInfo(config, outputPath) {
456
+ console.log("\n\u{1F528} Building...");
457
+ console.log(` Entry: ${config.entry}`);
458
+ console.log(` Output: ${outputPath}`);
459
+ console.log(` Format: ${config.format}`);
460
+ console.log(` Target: ${config.target}`);
461
+ }
462
+ function logBuildSuccess(buildTime, size) {
463
+ console.log(`
464
+ \u2705 Build successful!`);
465
+ console.log(` Time: ${buildTime}ms`);
466
+ console.log(` Size: ${formatBytes(size)}`);
467
+ }
468
+ var defaultOptions = {
469
+ outDir: "dist",
470
+ minify: true,
471
+ sourcemap: false,
472
+ target: "es2020",
473
+ format: "esm",
474
+ treeshake: true,
475
+ logging: true,
476
+ external: []
477
+ };
478
+ async function build(options) {
479
+ const config = { ...defaultOptions, ...options };
480
+ const startTime = Date.now();
481
+ if (!config.entry) {
482
+ throw new Error("Entry file is required");
483
+ }
484
+ const entryPath = resolve(config.entry);
485
+ const outDir = resolve(config.outDir);
486
+ let outFile = config.outFile;
487
+ if (!outFile) {
488
+ const baseName = basename(config.entry, extname(config.entry));
489
+ const ext = config.format === "cjs" ? ".cjs" : ".js";
490
+ outFile = baseName + ext;
491
+ }
492
+ const outputPath = join(outDir, outFile);
493
+ ensureDir(outDir);
494
+ if (config.logging) {
495
+ logBuildInfo(config, outputPath);
496
+ }
497
+ const browserOnlyPlugin = {
498
+ name: "browser-only",
499
+ setup(build2) {
500
+ build2.onResolve({ filter: /^(node:.*|fs|path|http|https|url|os|child_process|net|tls|crypto|stream|util|events|buffer|zlib|readline|process|assert|constants|dns|domain|punycode|querystring|repl|string_decoder|sys|timers|tty|v8|vm)$/ }, () => {
501
+ return { path: "node-builtin", external: true, sideEffects: false };
502
+ });
503
+ build2.onResolve({ filter: /^(chokidar|esbuild|mime-types|open|ws|fs\/promises)$/ }, () => {
504
+ return { path: "server-dep", external: true, sideEffects: false };
505
+ });
506
+ build2.onLoad({ filter: /[\\/](server|config|cli)\.ts$/ }, () => {
507
+ return {
508
+ contents: "export {}",
509
+ loader: "js"
510
+ };
511
+ });
512
+ }
513
+ };
514
+ try {
515
+ const platform = config.platform || (config.format === "cjs" ? "node" : "browser");
516
+ const plugins = platform === "browser" ? [browserOnlyPlugin] : [];
517
+ const define = {};
518
+ if (config.env) {
519
+ Object.entries(config.env).forEach(([key, value]) => {
520
+ if (key.startsWith("VITE_")) {
521
+ define[`import.meta.env.${key}`] = JSON.stringify(value);
522
+ }
523
+ });
524
+ if (config.env.MODE) {
525
+ define["import.meta.env.MODE"] = JSON.stringify(config.env.MODE);
526
+ }
527
+ define["import.meta.env.DEV"] = JSON.stringify(config.env.MODE !== "production");
528
+ define["import.meta.env.PROD"] = JSON.stringify(config.env.MODE === "production");
529
+ }
530
+ let result;
531
+ let buildTime;
532
+ let size;
533
+ if (runtime === "node") {
534
+ const { build: esbuild } = await import("esbuild");
535
+ result = await esbuild({
536
+ entryPoints: [entryPath],
537
+ bundle: true,
538
+ outfile: outputPath,
539
+ format: config.format,
540
+ target: config.target,
541
+ minify: config.minify,
542
+ sourcemap: config.sourcemap,
543
+ external: config.external,
544
+ treeShaking: config.treeshake,
545
+ globalName: config.globalName,
546
+ platform,
547
+ plugins,
548
+ define,
549
+ logLevel: config.logging ? "info" : "silent",
550
+ metafile: true,
551
+ // Additional optimizations
552
+ ...getMinifyOptions(config.minify)
553
+ });
554
+ ({ buildTime, size } = calculateBuildMetrics(startTime, outputPath));
555
+ } else if (runtime === "bun") {
556
+ result = await Bun.build({
557
+ entrypoints: [entryPath],
558
+ outdir: outDir,
559
+ target: "bun",
560
+ format: config.format === "cjs" ? "cjs" : "esm",
561
+ minify: config.minify,
562
+ sourcemap: config.sourcemap ? "external" : "none",
563
+ external: config.external,
564
+ naming: outFile,
565
+ define
566
+ });
567
+ if (!result.success) {
568
+ throw new Error("Bun build failed: " + JSON.stringify(result.logs));
569
+ }
570
+ ({ buildTime, size } = calculateBuildMetrics(startTime, outputPath));
571
+ } else {
572
+ result = await Deno.emit(entryPath, {
573
+ bundle: "module",
574
+ check: false,
575
+ compilerOptions: {
576
+ target: config.target,
577
+ module: config.format === "cjs" ? "commonjs" : "esnext",
578
+ sourceMap: config.sourcemap
579
+ }
580
+ });
581
+ const bundledCode = result.files["deno:///bundle.js"];
582
+ if (bundledCode) {
583
+ await Deno.writeTextFile(outputPath, bundledCode);
584
+ }
585
+ ({ buildTime, size } = calculateBuildMetrics(startTime, outputPath));
586
+ }
587
+ if (config.logging) {
588
+ logBuildSuccess(buildTime, size);
589
+ if (runtime === "node" && result.metafile) {
590
+ const inputs = Object.keys(result.metafile.inputs).length;
591
+ console.log(` Files: ${inputs} input(s)`);
592
+ const outputKeys = Object.keys(result.metafile.outputs);
593
+ if (outputKeys.length > 0) {
594
+ const mainOutput = result.metafile.outputs[outputKeys[0]];
595
+ if (mainOutput && mainOutput.inputs) {
596
+ const sortedInputs = Object.entries(mainOutput.inputs).sort(([, a], [, b]) => {
597
+ const aBytes = a.bytesInOutput || 0;
598
+ const bBytes = b.bytesInOutput || 0;
599
+ return bBytes - aBytes;
600
+ }).slice(0, 5);
601
+ if (sortedInputs.length > 0) {
602
+ console.log("\n \u{1F4CA} Top 5 largest modules:");
603
+ sortedInputs.forEach(([file, info]) => {
604
+ const fileName = file.split(/[/\\]/).pop() || file;
605
+ const infoBytes = info.bytesInOutput || 0;
606
+ console.log(` ${fileName.padEnd(30)} ${formatBytes(infoBytes)}`);
607
+ });
608
+ }
609
+ }
610
+ }
611
+ }
612
+ }
613
+ const buildResult = {
614
+ outputPath,
615
+ buildTime,
616
+ size
617
+ };
618
+ if (config.copy && config.copy.length > 0) {
619
+ if (config.logging) {
620
+ console.log("\n\u{1F4E6} Copying files...");
621
+ }
622
+ for (const copyItem of config.copy) {
623
+ const fromPath = resolve(copyItem.from);
624
+ const toPath = resolve(outDir, copyItem.to);
625
+ const targetDir = dirname(toPath);
626
+ if (!existsSync(targetDir)) {
627
+ ensureDir(targetDir);
628
+ }
629
+ if (existsSync(fromPath)) {
630
+ if (copyItem.transform) {
631
+ const content = readFileAsString(fromPath);
632
+ const transformed = copyItem.transform(content, config);
633
+ writeFileSync(toPath, transformed);
634
+ } else {
635
+ copyFileSync(fromPath, toPath);
636
+ }
637
+ if (config.logging) {
638
+ console.log(` \u2713 ${copyItem.from} \u2192 ${copyItem.to}`);
639
+ }
640
+ } else if (config.logging) {
641
+ console.warn(` \u26A0 File not found: ${copyItem.from}`);
642
+ }
643
+ }
644
+ }
645
+ if (config.onBuildEnd) {
646
+ await config.onBuildEnd(buildResult);
647
+ }
648
+ if (config.logging) {
649
+ console.log("");
650
+ }
651
+ return buildResult;
652
+ } catch (error) {
653
+ if (config.logging) {
654
+ console.error("\n\u274C Build failed:");
655
+ console.error(error);
656
+ }
657
+ throw error;
658
+ }
659
+ }
660
+ function formatBytes(bytes) {
661
+ if (bytes === 0) return "0 B";
662
+ const k = 1024;
663
+ const sizes = ["B", "KB", "MB", "GB"];
664
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
665
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
666
+ }
667
+ // Annotate the CommonJS export names for ESM import in node:
668
+ 0 && (module.exports = {
669
+ build
670
+ });