elit 3.6.6 → 3.6.7
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.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/dist/build.cjs +421 -331
- package/dist/build.d.ts +1 -19
- package/dist/build.js +420 -330
- package/dist/build.mjs +420 -330
- package/dist/chokidar.cjs +219 -182
- package/dist/chokidar.d.ts +25 -10
- package/dist/chokidar.js +217 -182
- package/dist/chokidar.mjs +218 -183
- package/dist/cli.cjs +22439 -21563
- package/dist/cli.d.ts +19 -37
- package/dist/cli.mjs +24113 -23252
- package/dist/config.cjs +357 -350
- package/dist/config.d.ts +17 -245
- package/dist/config.js +520 -515
- package/dist/config.mjs +346 -341
- package/dist/contracts-BeW9k0yZ.d.ts +54 -0
- package/dist/contracts-D7KIS-TK.d.ts +36 -0
- package/dist/coverage.cjs +448 -485
- package/dist/coverage.d.ts +13 -62
- package/dist/coverage.js +447 -484
- package/dist/coverage.mjs +447 -484
- package/dist/database.cjs +819 -828
- package/dist/database.d.ts +8 -24
- package/dist/database.js +818 -829
- package/dist/database.mjs +818 -829
- package/dist/desktop-auto-render.cjs +1700 -1523
- package/dist/desktop-auto-render.d.ts +4 -12
- package/dist/desktop-auto-render.js +1695 -1518
- package/dist/desktop-auto-render.mjs +1696 -1519
- package/dist/desktop.cjs +3 -1
- package/dist/desktop.d.ts +4 -1
- package/dist/desktop.js +1 -1
- package/dist/desktop.mjs +1 -1
- package/dist/dev-build.cjs +830 -0
- package/dist/dev-build.d.ts +53 -0
- package/dist/dev-build.js +3318 -0
- package/dist/dev-build.mjs +797 -0
- package/dist/dom.cjs +717 -591
- package/dist/dom.d.ts +2 -17
- package/dist/dom.js +714 -588
- package/dist/dom.mjs +716 -590
- package/dist/el.cjs +62 -52
- package/dist/el.d.ts +5 -12
- package/dist/el.js +60 -52
- package/dist/el.mjs +60 -52
- package/dist/fs.cjs +72 -63
- package/dist/fs.d.ts +22 -19
- package/dist/fs.js +71 -62
- package/dist/fs.mjs +71 -62
- package/dist/hmr.cjs +40 -14
- package/dist/hmr.d.ts +11 -23
- package/dist/hmr.js +38 -14
- package/dist/hmr.mjs +38 -14
- package/dist/http.cjs +251 -99
- package/dist/http.d.ts +38 -104
- package/dist/http.js +249 -99
- package/dist/http.mjs +249 -99
- package/dist/https.cjs +524 -228
- package/dist/https.d.ts +44 -36
- package/dist/https.js +520 -226
- package/dist/https.mjs +522 -228
- package/dist/index.cjs +7502 -7691
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7486 -7677
- package/dist/index.mjs +7497 -7687
- package/dist/mime-types.cjs +10 -4
- package/dist/mime-types.d.ts +8 -11
- package/dist/mime-types.js +9 -3
- package/dist/mime-types.mjs +9 -3
- package/dist/native.cjs +8616 -8870
- package/dist/native.d.ts +7 -10
- package/dist/native.js +8682 -8936
- package/dist/native.mjs +8615 -8869
- package/dist/path.cjs +83 -77
- package/dist/path.d.ts +29 -29
- package/dist/path.js +82 -76
- package/dist/path.mjs +82 -76
- package/dist/pm.cjs +3300 -0
- package/dist/pm.d.ts +256 -0
- package/dist/pm.js +5638 -0
- package/dist/pm.mjs +3196 -0
- package/dist/preview-build.cjs +712 -0
- package/dist/preview-build.d.ts +59 -0
- package/dist/preview-build.js +3194 -0
- package/dist/preview-build.mjs +676 -0
- package/dist/render-context.cjs +13 -2
- package/dist/render-context.d.ts +9 -34
- package/dist/render-context.js +11 -2
- package/dist/render-context.mjs +11 -2
- package/dist/router.cjs +787 -646
- package/dist/router.d.ts +8 -14
- package/dist/router.js +786 -645
- package/dist/router.mjs +786 -645
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/server.cjs +3254 -2684
- package/dist/server.d.ts +47 -5
- package/dist/server.js +3427 -2859
- package/dist/server.mjs +3397 -2829
- package/dist/smtp-server.cjs +16 -3
- package/dist/smtp-server.d.ts +12 -26
- package/dist/smtp-server.js +18 -5
- package/dist/smtp-server.mjs +16 -3
- package/dist/state-DvEkDehk.d.ts +195 -0
- package/dist/state.cjs +768 -659
- package/dist/state.d.ts +11 -71
- package/dist/state.js +760 -651
- package/dist/state.mjs +767 -658
- package/dist/style.cjs +1011 -968
- package/dist/style.d.ts +13 -127
- package/dist/style.js +1009 -970
- package/dist/style.mjs +1011 -971
- package/dist/test-reporter.cjs +332 -316
- package/dist/test-reporter.d.ts +28 -33
- package/dist/test-reporter.js +328 -312
- package/dist/test-reporter.mjs +328 -312
- package/dist/test-runtime.cjs +927 -968
- package/dist/test-runtime.d.ts +24 -99
- package/dist/test-runtime.js +922 -965
- package/dist/test-runtime.mjs +922 -965
- package/dist/test.cjs +4428 -4273
- package/dist/test.d.ts +2 -8
- package/dist/test.js +4307 -4154
- package/dist/test.mjs +4419 -4267
- package/dist/types-BONVzPtp.d.ts +59 -0
- package/dist/types-BR4wMiVx.d.ts +32 -0
- package/dist/types-C4gKykuG.d.ts +23 -0
- package/dist/types-CIhpN1-K.d.ts +64 -0
- package/dist/types-Ckj8md_j.d.ts +84 -0
- package/dist/types-CpjQTAkX.d.ts +24 -0
- package/dist/types-D0LjrYjS.d.ts +14 -0
- package/dist/types-DAisuVr5.d.ts +75 -0
- package/dist/types-tJn88E1N.d.ts +242 -0
- package/dist/types.d.ts +50 -237
- package/dist/universal.cjs +1 -1
- package/dist/universal.d.ts +1 -7
- package/dist/universal.js +1 -1
- package/dist/universal.mjs +1 -1
- package/dist/websocket-XfyK23zD.d.ts +119 -0
- package/dist/ws.cjs +129 -108
- package/dist/ws.d.ts +21 -131
- package/dist/ws.js +128 -109
- package/dist/ws.mjs +128 -109
- package/dist/wss.cjs +757 -479
- package/dist/wss.d.ts +31 -28
- package/dist/wss.js +755 -479
- package/dist/wss.mjs +758 -482
- package/package.json +8 -1
- package/vendor/epaint-0.31.1/src/image.rs +418 -0
- package/dist/server-uMQvZAll.d.ts +0 -458
package/dist/build.mjs
CHANGED
|
@@ -6,7 +6,19 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
// src/
|
|
9
|
+
// src/build/constants.ts
|
|
10
|
+
var defaultOptions = {
|
|
11
|
+
outDir: "dist",
|
|
12
|
+
minify: true,
|
|
13
|
+
sourcemap: false,
|
|
14
|
+
target: "es2020",
|
|
15
|
+
format: "esm",
|
|
16
|
+
treeshake: true,
|
|
17
|
+
logging: true,
|
|
18
|
+
external: []
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/shares/runtime.ts
|
|
10
22
|
var runtime = (() => {
|
|
11
23
|
if (typeof Deno !== "undefined") return "deno";
|
|
12
24
|
if (typeof Bun !== "undefined") return "bun";
|
|
@@ -16,7 +28,15 @@ var isNode = runtime === "node";
|
|
|
16
28
|
var isBun = runtime === "bun";
|
|
17
29
|
var isDeno = runtime === "deno";
|
|
18
30
|
|
|
19
|
-
// src/fs.ts
|
|
31
|
+
// src/server/fs/node-modules.ts
|
|
32
|
+
var fs;
|
|
33
|
+
var fsPromises;
|
|
34
|
+
if (isNode || isBun) {
|
|
35
|
+
fs = __require("fs");
|
|
36
|
+
fsPromises = __require("fs/promises");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/server/fs/utils.ts
|
|
20
40
|
function parseOptions(options, defaultValue) {
|
|
21
41
|
return typeof options === "string" ? { encoding: options } : options || defaultValue;
|
|
22
42
|
}
|
|
@@ -35,12 +55,37 @@ function dataToUint8Array(data) {
|
|
|
35
55
|
}
|
|
36
56
|
return data;
|
|
37
57
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
function createStatsFromDenoFileInfo(info) {
|
|
59
|
+
return {
|
|
60
|
+
isFile: () => info.isFile,
|
|
61
|
+
isDirectory: () => info.isDirectory,
|
|
62
|
+
isBlockDevice: () => false,
|
|
63
|
+
isCharacterDevice: () => false,
|
|
64
|
+
isSymbolicLink: () => info.isSymlink || false,
|
|
65
|
+
isFIFO: () => false,
|
|
66
|
+
isSocket: () => false,
|
|
67
|
+
dev: info.dev || 0,
|
|
68
|
+
ino: info.ino || 0,
|
|
69
|
+
mode: info.mode || 0,
|
|
70
|
+
nlink: info.nlink || 1,
|
|
71
|
+
uid: info.uid || 0,
|
|
72
|
+
gid: info.gid || 0,
|
|
73
|
+
rdev: 0,
|
|
74
|
+
size: info.size,
|
|
75
|
+
blksize: info.blksize || 4096,
|
|
76
|
+
blocks: info.blocks || Math.ceil(info.size / 512),
|
|
77
|
+
atimeMs: info.atime?.getTime() || Date.now(),
|
|
78
|
+
mtimeMs: info.mtime?.getTime() || Date.now(),
|
|
79
|
+
ctimeMs: info.birthtime?.getTime() || Date.now(),
|
|
80
|
+
birthtimeMs: info.birthtime?.getTime() || Date.now(),
|
|
81
|
+
atime: info.atime || /* @__PURE__ */ new Date(),
|
|
82
|
+
mtime: info.mtime || /* @__PURE__ */ new Date(),
|
|
83
|
+
ctime: info.birthtime || /* @__PURE__ */ new Date(),
|
|
84
|
+
birthtime: info.birthtime || /* @__PURE__ */ new Date()
|
|
85
|
+
};
|
|
43
86
|
}
|
|
87
|
+
|
|
88
|
+
// src/server/fs/file-ops.ts
|
|
44
89
|
function readFileSync(path, options) {
|
|
45
90
|
const opts = parseOptions(options, {});
|
|
46
91
|
if (isNode || isBun) {
|
|
@@ -76,6 +121,8 @@ function statSync(path) {
|
|
|
76
121
|
}
|
|
77
122
|
throw new Error("Unsupported runtime");
|
|
78
123
|
}
|
|
124
|
+
|
|
125
|
+
// src/server/fs/directory-ops.ts
|
|
79
126
|
function mkdirSync(path, options) {
|
|
80
127
|
const opts = typeof options === "number" ? { mode: options } : options || {};
|
|
81
128
|
if (isNode || isBun) {
|
|
@@ -84,6 +131,8 @@ function mkdirSync(path, options) {
|
|
|
84
131
|
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
85
132
|
}
|
|
86
133
|
}
|
|
134
|
+
|
|
135
|
+
// src/server/fs/path-ops.ts
|
|
87
136
|
function copyFileSync(src, dest, flags) {
|
|
88
137
|
if (isNode || isBun) {
|
|
89
138
|
fs.copyFileSync(src, dest, flags);
|
|
@@ -91,67 +140,34 @@ function copyFileSync(src, dest, flags) {
|
|
|
91
140
|
Deno.copyFileSync(src, dest);
|
|
92
141
|
}
|
|
93
142
|
}
|
|
94
|
-
function createStatsFromDenoFileInfo(info) {
|
|
95
|
-
return {
|
|
96
|
-
isFile: () => info.isFile,
|
|
97
|
-
isDirectory: () => info.isDirectory,
|
|
98
|
-
isBlockDevice: () => false,
|
|
99
|
-
isCharacterDevice: () => false,
|
|
100
|
-
isSymbolicLink: () => info.isSymlink || false,
|
|
101
|
-
isFIFO: () => false,
|
|
102
|
-
isSocket: () => false,
|
|
103
|
-
dev: info.dev || 0,
|
|
104
|
-
ino: info.ino || 0,
|
|
105
|
-
mode: info.mode || 0,
|
|
106
|
-
nlink: info.nlink || 1,
|
|
107
|
-
uid: info.uid || 0,
|
|
108
|
-
gid: info.gid || 0,
|
|
109
|
-
rdev: 0,
|
|
110
|
-
size: info.size,
|
|
111
|
-
blksize: info.blksize || 4096,
|
|
112
|
-
blocks: info.blocks || Math.ceil(info.size / 512),
|
|
113
|
-
atimeMs: info.atime?.getTime() || Date.now(),
|
|
114
|
-
mtimeMs: info.mtime?.getTime() || Date.now(),
|
|
115
|
-
ctimeMs: info.birthtime?.getTime() || Date.now(),
|
|
116
|
-
birthtimeMs: info.birthtime?.getTime() || Date.now(),
|
|
117
|
-
atime: info.atime || /* @__PURE__ */ new Date(),
|
|
118
|
-
mtime: info.mtime || /* @__PURE__ */ new Date(),
|
|
119
|
-
ctime: info.birthtime || /* @__PURE__ */ new Date(),
|
|
120
|
-
birthtime: info.birthtime || /* @__PURE__ */ new Date()
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
143
|
|
|
124
|
-
// src/path.ts
|
|
144
|
+
// src/server/path/platform.ts
|
|
125
145
|
function getSeparator(isWin) {
|
|
126
146
|
return isWin ? "\\" : "/";
|
|
127
147
|
}
|
|
128
148
|
function getCwd() {
|
|
129
149
|
if (isNode || isBun) {
|
|
130
150
|
return process.cwd();
|
|
131
|
-
}
|
|
151
|
+
}
|
|
152
|
+
if (isDeno) {
|
|
132
153
|
return Deno.cwd();
|
|
133
154
|
}
|
|
134
155
|
return "/";
|
|
135
156
|
}
|
|
157
|
+
var isWindows = (() => {
|
|
158
|
+
if (isNode) {
|
|
159
|
+
return process.platform === "win32";
|
|
160
|
+
}
|
|
161
|
+
if (isDeno) {
|
|
162
|
+
return Deno.build.os === "windows";
|
|
163
|
+
}
|
|
164
|
+
return typeof process !== "undefined" && process.platform === "win32";
|
|
165
|
+
})();
|
|
166
|
+
|
|
167
|
+
// src/server/path/operations.ts
|
|
136
168
|
function findLastSeparator(path) {
|
|
137
169
|
return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
138
170
|
}
|
|
139
|
-
function createPathOps(isWin) {
|
|
140
|
-
return {
|
|
141
|
-
sep: getSeparator(isWin),
|
|
142
|
-
delimiter: isWin ? ";" : ":",
|
|
143
|
-
normalize: (path) => normalizePath(path, isWin),
|
|
144
|
-
join: (...paths) => joinPaths(paths, isWin),
|
|
145
|
-
resolve: (...paths) => resolvePaths(paths, isWin),
|
|
146
|
-
isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
|
|
147
|
-
relative: (from, to) => relativePath(from, to, isWin),
|
|
148
|
-
dirname: (path) => getDirname(path, isWin),
|
|
149
|
-
basename: (path, ext) => getBasename(path, ext, isWin),
|
|
150
|
-
extname: (path) => getExtname(path),
|
|
151
|
-
parse: (path) => parsePath(path, isWin),
|
|
152
|
-
format: (pathObject) => formatPath(pathObject, isWin)
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
171
|
function isAbsolutePosix(path) {
|
|
156
172
|
return path.length > 0 && path[0] === "/";
|
|
157
173
|
}
|
|
@@ -172,28 +188,18 @@ function isAbsoluteWin(path) {
|
|
|
172
188
|
}
|
|
173
189
|
return false;
|
|
174
190
|
}
|
|
175
|
-
var isWindows = (() => {
|
|
176
|
-
if (isNode) {
|
|
177
|
-
return process.platform === "win32";
|
|
178
|
-
} else if (isDeno) {
|
|
179
|
-
return Deno.build.os === "windows";
|
|
180
|
-
}
|
|
181
|
-
return typeof process !== "undefined" && process.platform === "win32";
|
|
182
|
-
})();
|
|
183
|
-
var posix = createPathOps(false);
|
|
184
|
-
var win32 = createPathOps(true);
|
|
185
191
|
function normalizePath(path, isWin) {
|
|
186
192
|
if (path.length === 0) return ".";
|
|
187
193
|
const separator = getSeparator(isWin);
|
|
188
194
|
const isAbsolute = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
|
|
189
195
|
const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
|
|
190
|
-
|
|
196
|
+
const normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
|
|
191
197
|
const parts = normalized.split(separator);
|
|
192
198
|
const result = [];
|
|
193
|
-
for (let
|
|
194
|
-
const part = parts[
|
|
199
|
+
for (let index = 0; index < parts.length; index++) {
|
|
200
|
+
const part = parts[index];
|
|
195
201
|
if (part === "" || part === ".") {
|
|
196
|
-
if (
|
|
202
|
+
if (index === 0 && isAbsolute) result.push("");
|
|
197
203
|
continue;
|
|
198
204
|
}
|
|
199
205
|
if (part === "..") {
|
|
@@ -208,21 +214,21 @@ function normalizePath(path, isWin) {
|
|
|
208
214
|
result.push(part);
|
|
209
215
|
}
|
|
210
216
|
}
|
|
211
|
-
let
|
|
212
|
-
if (
|
|
217
|
+
let finalPath = result.join(separator);
|
|
218
|
+
if (finalPath.length === 0) {
|
|
213
219
|
return isAbsolute ? separator : ".";
|
|
214
220
|
}
|
|
215
|
-
if (trailingSeparator &&
|
|
216
|
-
|
|
221
|
+
if (trailingSeparator && finalPath[finalPath.length - 1] !== separator) {
|
|
222
|
+
finalPath += separator;
|
|
217
223
|
}
|
|
218
|
-
return
|
|
224
|
+
return finalPath;
|
|
219
225
|
}
|
|
220
226
|
function joinPaths(paths, isWin) {
|
|
221
227
|
if (paths.length === 0) return ".";
|
|
222
228
|
const separator = getSeparator(isWin);
|
|
223
229
|
let joined = "";
|
|
224
|
-
for (let
|
|
225
|
-
const path = paths[
|
|
230
|
+
for (let index = 0; index < paths.length; index++) {
|
|
231
|
+
const path = paths[index];
|
|
226
232
|
if (path && path.length > 0) {
|
|
227
233
|
if (joined.length === 0) {
|
|
228
234
|
joined = path;
|
|
@@ -237,43 +243,43 @@ function joinPaths(paths, isWin) {
|
|
|
237
243
|
function resolvePaths(paths, isWin) {
|
|
238
244
|
const separator = getSeparator(isWin);
|
|
239
245
|
let resolved = "";
|
|
240
|
-
let
|
|
241
|
-
for (let
|
|
242
|
-
const path = paths[
|
|
246
|
+
let absolute = false;
|
|
247
|
+
for (let index = paths.length - 1; index >= 0 && !absolute; index--) {
|
|
248
|
+
const path = paths[index];
|
|
243
249
|
if (path && path.length > 0) {
|
|
244
250
|
resolved = path + (resolved.length > 0 ? separator + resolved : "");
|
|
245
|
-
|
|
251
|
+
absolute = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
|
|
246
252
|
}
|
|
247
253
|
}
|
|
248
|
-
if (!
|
|
254
|
+
if (!absolute) {
|
|
249
255
|
const cwd = getCwd();
|
|
250
256
|
resolved = cwd + (resolved.length > 0 ? separator + resolved : "");
|
|
251
257
|
}
|
|
252
258
|
return normalizePath(resolved, isWin);
|
|
253
259
|
}
|
|
254
260
|
function relativePath(from, to, isWin) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (
|
|
261
|
+
const resolvedFrom = resolvePaths([from], isWin);
|
|
262
|
+
const resolvedTo = resolvePaths([to], isWin);
|
|
263
|
+
if (resolvedFrom === resolvedTo) return "";
|
|
258
264
|
const separator = getSeparator(isWin);
|
|
259
|
-
const fromParts =
|
|
260
|
-
const toParts =
|
|
261
|
-
let commonLength = 0;
|
|
265
|
+
const fromParts = resolvedFrom.split(separator).filter((part) => part.length > 0);
|
|
266
|
+
const toParts = resolvedTo.split(separator).filter((part) => part.length > 0);
|
|
262
267
|
const minLength = Math.min(fromParts.length, toParts.length);
|
|
263
|
-
|
|
264
|
-
|
|
268
|
+
let commonLength = 0;
|
|
269
|
+
for (let index = 0; index < minLength; index++) {
|
|
270
|
+
if (fromParts[index] === toParts[index]) {
|
|
265
271
|
commonLength++;
|
|
266
272
|
} else {
|
|
267
273
|
break;
|
|
268
274
|
}
|
|
269
275
|
}
|
|
270
|
-
const upCount = fromParts.length - commonLength;
|
|
271
276
|
const result = [];
|
|
272
|
-
|
|
277
|
+
const upCount = fromParts.length - commonLength;
|
|
278
|
+
for (let index = 0; index < upCount; index++) {
|
|
273
279
|
result.push("..");
|
|
274
280
|
}
|
|
275
|
-
for (let
|
|
276
|
-
result.push(toParts[
|
|
281
|
+
for (let index = commonLength; index < toParts.length; index++) {
|
|
282
|
+
result.push(toParts[index]);
|
|
277
283
|
}
|
|
278
284
|
return result.join(separator) || ".";
|
|
279
285
|
}
|
|
@@ -281,15 +287,15 @@ function getDirname(path, isWin) {
|
|
|
281
287
|
if (path.length === 0) return ".";
|
|
282
288
|
const separator = getSeparator(isWin);
|
|
283
289
|
const normalized = normalizePath(path, isWin);
|
|
284
|
-
const
|
|
285
|
-
if (
|
|
286
|
-
if (
|
|
287
|
-
return normalized.slice(0,
|
|
290
|
+
const lastSeparatorIndex = normalized.lastIndexOf(separator);
|
|
291
|
+
if (lastSeparatorIndex === -1) return ".";
|
|
292
|
+
if (lastSeparatorIndex === 0) return separator;
|
|
293
|
+
return normalized.slice(0, lastSeparatorIndex);
|
|
288
294
|
}
|
|
289
295
|
function getBasename(path, ext, isWin) {
|
|
290
296
|
if (path.length === 0) return "";
|
|
291
|
-
const
|
|
292
|
-
let base =
|
|
297
|
+
const lastSeparatorIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
|
|
298
|
+
let base = lastSeparatorIndex === -1 ? path : path.slice(lastSeparatorIndex + 1);
|
|
293
299
|
if (ext && base.endsWith(ext)) {
|
|
294
300
|
base = base.slice(0, base.length - ext.length);
|
|
295
301
|
}
|
|
@@ -297,8 +303,8 @@ function getBasename(path, ext, isWin) {
|
|
|
297
303
|
}
|
|
298
304
|
function getExtname(path) {
|
|
299
305
|
const lastDotIndex = path.lastIndexOf(".");
|
|
300
|
-
const
|
|
301
|
-
if (lastDotIndex === -1 || lastDotIndex <
|
|
306
|
+
const lastSeparatorIndex = findLastSeparator(path);
|
|
307
|
+
if (lastDotIndex === -1 || lastDotIndex < lastSeparatorIndex || lastDotIndex === path.length - 1) {
|
|
302
308
|
return "";
|
|
303
309
|
}
|
|
304
310
|
return path.slice(lastDotIndex);
|
|
@@ -314,10 +320,8 @@ function parsePath(path, isWin) {
|
|
|
314
320
|
} else if (path[0] === "\\" || path[0] === "/") {
|
|
315
321
|
root = "\\";
|
|
316
322
|
}
|
|
317
|
-
} else {
|
|
318
|
-
|
|
319
|
-
root = "/";
|
|
320
|
-
}
|
|
323
|
+
} else if (path[0] === "/") {
|
|
324
|
+
root = "/";
|
|
321
325
|
}
|
|
322
326
|
const dir = getDirname(path, isWin);
|
|
323
327
|
const base = getBasename(path, void 0, isWin);
|
|
@@ -333,6 +337,26 @@ function formatPath(pathObject, isWin) {
|
|
|
333
337
|
if (dir === pathObject.root) return dir + base;
|
|
334
338
|
return dir + separator + base;
|
|
335
339
|
}
|
|
340
|
+
function createPathOps(isWin) {
|
|
341
|
+
return {
|
|
342
|
+
sep: getSeparator(isWin),
|
|
343
|
+
delimiter: isWin ? ";" : ":",
|
|
344
|
+
normalize: (path) => normalizePath(path, isWin),
|
|
345
|
+
join: (...paths) => joinPaths(paths, isWin),
|
|
346
|
+
resolve: (...paths) => resolvePaths(paths, isWin),
|
|
347
|
+
isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
|
|
348
|
+
relative: (from, to) => relativePath(from, to, isWin),
|
|
349
|
+
dirname: (path) => getDirname(path, isWin),
|
|
350
|
+
basename: (path, ext) => getBasename(path, ext, isWin),
|
|
351
|
+
extname: (path) => getExtname(path),
|
|
352
|
+
parse: (path) => parsePath(path, isWin),
|
|
353
|
+
format: (pathObject) => formatPath(pathObject, isWin)
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// src/server/path/index.ts
|
|
358
|
+
var posix = createPathOps(false);
|
|
359
|
+
var win32 = createPathOps(true);
|
|
336
360
|
function join(...paths) {
|
|
337
361
|
return joinPaths(paths, isWindows);
|
|
338
362
|
}
|
|
@@ -349,7 +373,141 @@ function extname(path) {
|
|
|
349
373
|
return getExtname(path);
|
|
350
374
|
}
|
|
351
375
|
|
|
352
|
-
// src/
|
|
376
|
+
// src/build/helpers.ts
|
|
377
|
+
function ensureDir(dirPath) {
|
|
378
|
+
try {
|
|
379
|
+
mkdirSync(dirPath, { recursive: true });
|
|
380
|
+
} catch {
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function calculateBuildMetrics(startTime, outputPath) {
|
|
384
|
+
const buildTime = Date.now() - startTime;
|
|
385
|
+
const stats = statSync(outputPath);
|
|
386
|
+
return { buildTime, size: stats.size };
|
|
387
|
+
}
|
|
388
|
+
function readFileAsString(filePath) {
|
|
389
|
+
const contentBuffer = readFileSync(filePath, "utf-8");
|
|
390
|
+
return typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString("utf-8");
|
|
391
|
+
}
|
|
392
|
+
function resolveBuildPaths(config) {
|
|
393
|
+
const entryPath = resolve(config.entry);
|
|
394
|
+
const outDir = resolve(config.outDir);
|
|
395
|
+
let outFile = config.outFile;
|
|
396
|
+
if (!outFile) {
|
|
397
|
+
const baseName = basename(config.entry, extname(config.entry));
|
|
398
|
+
const ext = config.format === "cjs" ? ".cjs" : ".js";
|
|
399
|
+
outFile = baseName + ext;
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
entryPath,
|
|
403
|
+
outDir,
|
|
404
|
+
outFile,
|
|
405
|
+
outputPath: join(outDir, outFile)
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function createDefine(config) {
|
|
409
|
+
const define = {};
|
|
410
|
+
if (!config.env) {
|
|
411
|
+
return define;
|
|
412
|
+
}
|
|
413
|
+
Object.entries(config.env).forEach(([key, value]) => {
|
|
414
|
+
if (key.startsWith("VITE_")) {
|
|
415
|
+
define[`import.meta.env.${key}`] = JSON.stringify(value);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
if (config.env.MODE) {
|
|
419
|
+
define["import.meta.env.MODE"] = JSON.stringify(config.env.MODE);
|
|
420
|
+
}
|
|
421
|
+
define["import.meta.env.DEV"] = JSON.stringify(config.env.MODE !== "production");
|
|
422
|
+
define["import.meta.env.PROD"] = JSON.stringify(config.env.MODE === "production");
|
|
423
|
+
return define;
|
|
424
|
+
}
|
|
425
|
+
function copyBuildFiles(config, outDir) {
|
|
426
|
+
if (!config.copy || config.copy.length === 0) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (config.logging) {
|
|
430
|
+
console.log("\n\u{1F4E6} Copying files...");
|
|
431
|
+
}
|
|
432
|
+
for (const copyItem of config.copy) {
|
|
433
|
+
const fromPath = resolve(copyItem.from);
|
|
434
|
+
const toPath = resolve(outDir, copyItem.to);
|
|
435
|
+
const targetDir = dirname(toPath);
|
|
436
|
+
if (!existsSync(targetDir)) {
|
|
437
|
+
ensureDir(targetDir);
|
|
438
|
+
}
|
|
439
|
+
if (!existsSync(fromPath)) {
|
|
440
|
+
if (config.logging) {
|
|
441
|
+
console.warn(` \u26A0 File not found: ${copyItem.from}`);
|
|
442
|
+
}
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (copyItem.transform) {
|
|
446
|
+
const content = readFileAsString(fromPath);
|
|
447
|
+
const transformed = copyItem.transform(content, config);
|
|
448
|
+
writeFileSync(toPath, transformed);
|
|
449
|
+
} else {
|
|
450
|
+
copyFileSync(fromPath, toPath);
|
|
451
|
+
}
|
|
452
|
+
if (config.logging) {
|
|
453
|
+
console.log(` \u2713 ${copyItem.from} \u2192 ${copyItem.to}`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function formatBytes(bytes) {
|
|
458
|
+
if (bytes === 0) {
|
|
459
|
+
return "0 B";
|
|
460
|
+
}
|
|
461
|
+
const k = 1024;
|
|
462
|
+
const sizes = ["B", "KB", "MB", "GB"];
|
|
463
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
464
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/build/logging.ts
|
|
468
|
+
function logBuildInfo(config, outputPath) {
|
|
469
|
+
console.log("\n\u{1F528} Building...");
|
|
470
|
+
console.log(` Entry: ${config.entry}`);
|
|
471
|
+
console.log(` Output: ${outputPath}`);
|
|
472
|
+
console.log(` Format: ${config.format}`);
|
|
473
|
+
console.log(` Target: ${config.target}`);
|
|
474
|
+
}
|
|
475
|
+
function logBuildSuccess(buildTime, size) {
|
|
476
|
+
console.log("\n\u2705 Build successful!");
|
|
477
|
+
console.log(` Time: ${buildTime}ms`);
|
|
478
|
+
console.log(` Size: ${formatBytes(size)}`);
|
|
479
|
+
}
|
|
480
|
+
function logMetafileSummary(result) {
|
|
481
|
+
if (!result?.metafile) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const inputs = Object.keys(result.metafile.inputs).length;
|
|
485
|
+
console.log(` Files: ${inputs} input(s)`);
|
|
486
|
+
const outputKeys = Object.keys(result.metafile.outputs);
|
|
487
|
+
if (outputKeys.length === 0) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const mainOutput = result.metafile.outputs[outputKeys[0]];
|
|
491
|
+
if (!mainOutput?.inputs) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const sortedInputs = Object.entries(mainOutput.inputs).sort(([, a], [, b]) => {
|
|
495
|
+
const aBytes = a.bytesInOutput || 0;
|
|
496
|
+
const bBytes = b.bytesInOutput || 0;
|
|
497
|
+
return bBytes - aBytes;
|
|
498
|
+
}).slice(0, 5);
|
|
499
|
+
if (sortedInputs.length === 0) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
console.log("\n \u{1F4CA} Top 5 largest modules:");
|
|
503
|
+
sortedInputs.forEach(([file, info]) => {
|
|
504
|
+
const fileName = file.split(/[/\\]/).pop() || file;
|
|
505
|
+
const infoBytes = info.bytesInOutput || 0;
|
|
506
|
+
console.log(` ${fileName.padEnd(30)} ${formatBytes(infoBytes)}`);
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/shares/workspace-package/package-json.ts
|
|
353
511
|
function readPackageJson(filePath) {
|
|
354
512
|
try {
|
|
355
513
|
const packageJsonBuffer = readFileSync(filePath, "utf-8");
|
|
@@ -359,13 +517,14 @@ function readPackageJson(filePath) {
|
|
|
359
517
|
return void 0;
|
|
360
518
|
}
|
|
361
519
|
}
|
|
362
|
-
|
|
520
|
+
|
|
521
|
+
// src/shares/workspace-package/roots.ts
|
|
522
|
+
function findPackageDirectory(startDir, resolveMatch) {
|
|
363
523
|
let currentDir = resolve(startDir);
|
|
364
524
|
while (true) {
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return currentDir;
|
|
525
|
+
const match = resolveMatch(currentDir);
|
|
526
|
+
if (match) {
|
|
527
|
+
return match;
|
|
369
528
|
}
|
|
370
529
|
const parentDir = dirname(currentDir);
|
|
371
530
|
if (parentDir === currentDir) {
|
|
@@ -374,20 +533,21 @@ function findWorkspacePackageRoot(startDir, packageName) {
|
|
|
374
533
|
currentDir = parentDir;
|
|
375
534
|
}
|
|
376
535
|
}
|
|
536
|
+
function findWorkspacePackageRoot(startDir, packageName) {
|
|
537
|
+
return findPackageDirectory(startDir, (currentDir) => {
|
|
538
|
+
const packageJsonPath = join(currentDir, "package.json");
|
|
539
|
+
const packageJson = existsSync(packageJsonPath) ? readPackageJson(packageJsonPath) : void 0;
|
|
540
|
+
return packageJson?.name === packageName ? currentDir : void 0;
|
|
541
|
+
});
|
|
542
|
+
}
|
|
377
543
|
function findInstalledPackageRoot(startDir, packageName) {
|
|
378
|
-
|
|
379
|
-
while (true) {
|
|
544
|
+
return findPackageDirectory(startDir, (currentDir) => {
|
|
380
545
|
const candidate = join(currentDir, "node_modules", ...packageName.split("/"));
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
const parentDir = dirname(currentDir);
|
|
385
|
-
if (parentDir === currentDir) {
|
|
386
|
-
return void 0;
|
|
387
|
-
}
|
|
388
|
-
currentDir = parentDir;
|
|
389
|
-
}
|
|
546
|
+
return existsSync(candidate) ? candidate : void 0;
|
|
547
|
+
});
|
|
390
548
|
}
|
|
549
|
+
|
|
550
|
+
// src/shares/workspace-package/candidates.ts
|
|
391
551
|
function getWorkspacePackageImportCandidates(packageRoot, specifier, options = {}) {
|
|
392
552
|
const subpath = specifier === "elit" ? "index" : specifier.slice("elit/".length);
|
|
393
553
|
const builtCandidates = options.preferredBuiltFormat === "cjs" ? [
|
|
@@ -405,14 +565,24 @@ function getWorkspacePackageImportCandidates(packageRoot, specifier, options = {
|
|
|
405
565
|
];
|
|
406
566
|
return options.preferBuilt ? [...builtCandidates, ...sourceCandidates] : [...sourceCandidates, ...builtCandidates];
|
|
407
567
|
}
|
|
568
|
+
|
|
569
|
+
// src/shares/workspace-package/resolve.ts
|
|
570
|
+
function isWorkspacePackageSpecifier(specifier) {
|
|
571
|
+
return specifier === "elit" || specifier.startsWith("elit/");
|
|
572
|
+
}
|
|
408
573
|
function resolveWorkspacePackageImport(specifier, startDir, options = {}) {
|
|
409
|
-
if (
|
|
574
|
+
if (!isWorkspacePackageSpecifier(specifier)) {
|
|
410
575
|
return void 0;
|
|
411
576
|
}
|
|
412
|
-
const packageRoots =
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
577
|
+
const packageRoots = /* @__PURE__ */ new Set();
|
|
578
|
+
const workspacePackageRoot = findWorkspacePackageRoot(startDir, "elit");
|
|
579
|
+
const installedPackageRoot = findInstalledPackageRoot(startDir, "elit");
|
|
580
|
+
if (workspacePackageRoot) {
|
|
581
|
+
packageRoots.add(workspacePackageRoot);
|
|
582
|
+
}
|
|
583
|
+
if (installedPackageRoot) {
|
|
584
|
+
packageRoots.add(installedPackageRoot);
|
|
585
|
+
}
|
|
416
586
|
for (const packageRoot of packageRoots) {
|
|
417
587
|
for (const candidate of getWorkspacePackageImportCandidates(packageRoot, specifier, options)) {
|
|
418
588
|
if (existsSync(candidate)) {
|
|
@@ -423,22 +593,7 @@ function resolveWorkspacePackageImport(specifier, startDir, options = {}) {
|
|
|
423
593
|
return void 0;
|
|
424
594
|
}
|
|
425
595
|
|
|
426
|
-
// src/build.ts
|
|
427
|
-
function ensureDir(dirPath) {
|
|
428
|
-
try {
|
|
429
|
-
mkdirSync(dirPath, { recursive: true });
|
|
430
|
-
} catch (error) {
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
function calculateBuildMetrics(startTime, outputPath) {
|
|
434
|
-
const buildTime = Date.now() - startTime;
|
|
435
|
-
const stats = statSync(outputPath);
|
|
436
|
-
return { buildTime, size: stats.size };
|
|
437
|
-
}
|
|
438
|
-
function readFileAsString(filePath) {
|
|
439
|
-
const contentBuffer = readFileSync(filePath, "utf-8");
|
|
440
|
-
return typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString("utf-8");
|
|
441
|
-
}
|
|
596
|
+
// src/build/plugins.ts
|
|
442
597
|
function createWorkspacePackagePlugin(entryDir, options = {}) {
|
|
443
598
|
return {
|
|
444
599
|
name: "workspace-package-self-reference",
|
|
@@ -450,6 +605,31 @@ function createWorkspacePackagePlugin(entryDir, options = {}) {
|
|
|
450
605
|
}
|
|
451
606
|
};
|
|
452
607
|
}
|
|
608
|
+
function createBrowserOnlyPlugin() {
|
|
609
|
+
return {
|
|
610
|
+
name: "browser-only",
|
|
611
|
+
setup(build2) {
|
|
612
|
+
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)$/ }, () => {
|
|
613
|
+
return { path: "node-builtin", external: true, sideEffects: false };
|
|
614
|
+
});
|
|
615
|
+
build2.onResolve({ filter: /^(chokidar|esbuild|mime-types|open|ws|fs\/promises)$/ }, () => {
|
|
616
|
+
return { path: "server-dep", external: true, sideEffects: false };
|
|
617
|
+
});
|
|
618
|
+
build2.onLoad({ filter: /server|config|cli/ }, () => ({
|
|
619
|
+
contents: "export default {};"
|
|
620
|
+
}));
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function createBuildPlugins(entryPath, platform) {
|
|
625
|
+
const workspacePackagePlugin = createWorkspacePackagePlugin(dirname(entryPath), {
|
|
626
|
+
preferBuilt: platform === "browser",
|
|
627
|
+
preferredBuiltFormat: platform === "browser" ? "esm" : void 0
|
|
628
|
+
});
|
|
629
|
+
return platform === "browser" ? [workspacePackagePlugin, createBrowserOnlyPlugin()] : [workspacePackagePlugin];
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/build/runtime-builders.ts
|
|
453
633
|
function getMinifyOptions(minify) {
|
|
454
634
|
return minify ? {
|
|
455
635
|
minifyWhitespace: true,
|
|
@@ -460,206 +640,123 @@ function getMinifyOptions(minify) {
|
|
|
460
640
|
keepNames: false
|
|
461
641
|
} : {};
|
|
462
642
|
}
|
|
463
|
-
function
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
643
|
+
async function buildWithNode(context) {
|
|
644
|
+
const { build: esbuild } = await import("esbuild");
|
|
645
|
+
const { config, paths, platform, plugins, define, startTime } = context;
|
|
646
|
+
const baseOptions = {
|
|
647
|
+
entryPoints: [paths.entryPath],
|
|
648
|
+
bundle: true,
|
|
649
|
+
outfile: paths.outputPath,
|
|
650
|
+
format: config.format,
|
|
651
|
+
target: config.target,
|
|
652
|
+
minify: config.minify,
|
|
653
|
+
sourcemap: config.sourcemap,
|
|
654
|
+
external: config.external,
|
|
655
|
+
treeShaking: config.treeshake,
|
|
656
|
+
globalName: config.globalName,
|
|
657
|
+
platform,
|
|
658
|
+
plugins,
|
|
659
|
+
define,
|
|
660
|
+
logLevel: config.logging ? "info" : "silent",
|
|
661
|
+
metafile: true,
|
|
662
|
+
mainFields: platform === "browser" ? ["browser", "module", "main"] : ["module", "main"]
|
|
663
|
+
};
|
|
664
|
+
const esbuildOptions = {
|
|
665
|
+
...baseOptions,
|
|
666
|
+
...getMinifyOptions(config.minify)
|
|
667
|
+
};
|
|
668
|
+
if (config.resolve?.alias) {
|
|
669
|
+
esbuildOptions.resolve = { alias: config.resolve.alias };
|
|
670
|
+
}
|
|
671
|
+
const result = await esbuild(esbuildOptions);
|
|
672
|
+
const { buildTime, size } = calculateBuildMetrics(startTime, paths.outputPath);
|
|
673
|
+
return { result, buildTime, size };
|
|
674
|
+
}
|
|
675
|
+
async function buildWithBun(context) {
|
|
676
|
+
const { config, paths, plugins, define, startTime } = context;
|
|
677
|
+
const result = await Bun.build({
|
|
678
|
+
entrypoints: [paths.entryPath],
|
|
679
|
+
outdir: paths.outDir,
|
|
680
|
+
target: "bun",
|
|
681
|
+
format: config.format === "cjs" ? "cjs" : "esm",
|
|
682
|
+
minify: config.minify,
|
|
683
|
+
sourcemap: config.sourcemap ? "external" : "none",
|
|
684
|
+
external: config.external,
|
|
685
|
+
naming: paths.outFile,
|
|
686
|
+
define,
|
|
687
|
+
plugins
|
|
688
|
+
});
|
|
689
|
+
if (!result.success) {
|
|
690
|
+
throw new Error("Bun build failed: " + JSON.stringify(result.logs));
|
|
691
|
+
}
|
|
692
|
+
const { buildTime, size } = calculateBuildMetrics(startTime, paths.outputPath);
|
|
693
|
+
return { result, buildTime, size };
|
|
694
|
+
}
|
|
695
|
+
async function buildWithDeno(context) {
|
|
696
|
+
const { config, paths, startTime } = context;
|
|
697
|
+
const result = await Deno.emit(paths.entryPath, {
|
|
698
|
+
bundle: "module",
|
|
699
|
+
check: false,
|
|
700
|
+
compilerOptions: {
|
|
701
|
+
target: config.target,
|
|
702
|
+
module: config.format === "cjs" ? "commonjs" : "esnext",
|
|
703
|
+
sourceMap: config.sourcemap
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
const bundledCode = result.files["deno:///bundle.js"];
|
|
707
|
+
if (bundledCode) {
|
|
708
|
+
await Deno.writeTextFile(paths.outputPath, bundledCode);
|
|
709
|
+
}
|
|
710
|
+
const { buildTime, size } = calculateBuildMetrics(startTime, paths.outputPath);
|
|
711
|
+
return { result, buildTime, size };
|
|
469
712
|
}
|
|
470
|
-
function
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
713
|
+
async function runRuntimeBuild(context) {
|
|
714
|
+
if (runtime === "node") {
|
|
715
|
+
return buildWithNode(context);
|
|
716
|
+
}
|
|
717
|
+
if (runtime === "bun") {
|
|
718
|
+
return buildWithBun(context);
|
|
719
|
+
}
|
|
720
|
+
return buildWithDeno(context);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// src/build/build.ts
|
|
724
|
+
function resolveBuildPlatform(config) {
|
|
725
|
+
return config.platform || (config.format === "cjs" ? "node" : "browser");
|
|
475
726
|
}
|
|
476
|
-
var defaultOptions = {
|
|
477
|
-
outDir: "dist",
|
|
478
|
-
minify: true,
|
|
479
|
-
sourcemap: false,
|
|
480
|
-
target: "es2020",
|
|
481
|
-
format: "esm",
|
|
482
|
-
treeshake: true,
|
|
483
|
-
logging: true,
|
|
484
|
-
external: []
|
|
485
|
-
};
|
|
486
727
|
async function build(options) {
|
|
487
728
|
const config = { ...defaultOptions, ...options };
|
|
488
729
|
const startTime = Date.now();
|
|
489
730
|
if (!config.entry) {
|
|
490
731
|
throw new Error("Entry file is required");
|
|
491
732
|
}
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
let outFile = config.outFile;
|
|
495
|
-
if (!outFile) {
|
|
496
|
-
const baseName = basename(config.entry, extname(config.entry));
|
|
497
|
-
const ext = config.format === "cjs" ? ".cjs" : ".js";
|
|
498
|
-
outFile = baseName + ext;
|
|
499
|
-
}
|
|
500
|
-
const outputPath = join(outDir, outFile);
|
|
501
|
-
ensureDir(outDir);
|
|
733
|
+
const paths = resolveBuildPaths(config);
|
|
734
|
+
ensureDir(paths.outDir);
|
|
502
735
|
if (config.logging) {
|
|
503
|
-
logBuildInfo(config, outputPath);
|
|
736
|
+
logBuildInfo(config, paths.outputPath);
|
|
504
737
|
}
|
|
505
|
-
const browserOnlyPlugin = {
|
|
506
|
-
name: "browser-only",
|
|
507
|
-
setup(build2) {
|
|
508
|
-
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)$/ }, () => {
|
|
509
|
-
return { path: "node-builtin", external: true, sideEffects: false };
|
|
510
|
-
});
|
|
511
|
-
build2.onResolve({ filter: /^(chokidar|esbuild|mime-types|open|ws|fs\/promises)$/ }, () => {
|
|
512
|
-
return { path: "server-dep", external: true, sideEffects: false };
|
|
513
|
-
});
|
|
514
|
-
build2.onLoad({ filter: /server|config|cli/ }, () => ({
|
|
515
|
-
contents: "export default {};"
|
|
516
|
-
}));
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
738
|
try {
|
|
520
|
-
const platform =
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
739
|
+
const platform = resolveBuildPlatform(config);
|
|
740
|
+
const plugins = createBuildPlugins(paths.entryPath, platform);
|
|
741
|
+
const define = createDefine(config);
|
|
742
|
+
const { result, buildTime, size } = await runRuntimeBuild({
|
|
743
|
+
config,
|
|
744
|
+
paths,
|
|
745
|
+
platform,
|
|
746
|
+
plugins,
|
|
747
|
+
define,
|
|
748
|
+
startTime
|
|
524
749
|
});
|
|
525
|
-
const plugins = platform === "browser" ? [workspacePackagePlugin, browserOnlyPlugin] : [workspacePackagePlugin];
|
|
526
|
-
const define = {};
|
|
527
|
-
if (config.env) {
|
|
528
|
-
Object.entries(config.env).forEach(([key, value]) => {
|
|
529
|
-
if (key.startsWith("VITE_")) {
|
|
530
|
-
define[`import.meta.env.${key}`] = JSON.stringify(value);
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
if (config.env.MODE) {
|
|
534
|
-
define["import.meta.env.MODE"] = JSON.stringify(config.env.MODE);
|
|
535
|
-
}
|
|
536
|
-
define["import.meta.env.DEV"] = JSON.stringify(config.env.MODE !== "production");
|
|
537
|
-
define["import.meta.env.PROD"] = JSON.stringify(config.env.MODE === "production");
|
|
538
|
-
}
|
|
539
|
-
let result;
|
|
540
|
-
let buildTime;
|
|
541
|
-
let size;
|
|
542
|
-
if (runtime === "node") {
|
|
543
|
-
const { build: esbuild } = await import("esbuild");
|
|
544
|
-
const baseOptions = {
|
|
545
|
-
entryPoints: [entryPath],
|
|
546
|
-
bundle: true,
|
|
547
|
-
outfile: outputPath,
|
|
548
|
-
format: config.format,
|
|
549
|
-
target: config.target,
|
|
550
|
-
minify: config.minify,
|
|
551
|
-
sourcemap: config.sourcemap,
|
|
552
|
-
external: config.external,
|
|
553
|
-
treeShaking: config.treeshake,
|
|
554
|
-
globalName: config.globalName,
|
|
555
|
-
platform,
|
|
556
|
-
plugins,
|
|
557
|
-
define,
|
|
558
|
-
logLevel: config.logging ? "info" : "silent",
|
|
559
|
-
metafile: true,
|
|
560
|
-
// Prioritize browser field for browser builds
|
|
561
|
-
mainFields: platform === "browser" ? ["browser", "module", "main"] : ["module", "main"]
|
|
562
|
-
};
|
|
563
|
-
const esbuildOptions = {
|
|
564
|
-
...baseOptions,
|
|
565
|
-
...getMinifyOptions(config.minify)
|
|
566
|
-
};
|
|
567
|
-
if (config.resolve?.alias) {
|
|
568
|
-
esbuildOptions.resolve = { alias: config.resolve.alias };
|
|
569
|
-
}
|
|
570
|
-
result = await esbuild(esbuildOptions);
|
|
571
|
-
({ buildTime, size } = calculateBuildMetrics(startTime, outputPath));
|
|
572
|
-
} else if (runtime === "bun") {
|
|
573
|
-
result = await Bun.build({
|
|
574
|
-
entrypoints: [entryPath],
|
|
575
|
-
outdir: outDir,
|
|
576
|
-
target: "bun",
|
|
577
|
-
format: config.format === "cjs" ? "cjs" : "esm",
|
|
578
|
-
minify: config.minify,
|
|
579
|
-
sourcemap: config.sourcemap ? "external" : "none",
|
|
580
|
-
external: config.external,
|
|
581
|
-
naming: outFile,
|
|
582
|
-
define,
|
|
583
|
-
plugins
|
|
584
|
-
});
|
|
585
|
-
if (!result.success) {
|
|
586
|
-
throw new Error("Bun build failed: " + JSON.stringify(result.logs));
|
|
587
|
-
}
|
|
588
|
-
({ buildTime, size } = calculateBuildMetrics(startTime, outputPath));
|
|
589
|
-
} else {
|
|
590
|
-
result = await Deno.emit(entryPath, {
|
|
591
|
-
bundle: "module",
|
|
592
|
-
check: false,
|
|
593
|
-
compilerOptions: {
|
|
594
|
-
target: config.target,
|
|
595
|
-
module: config.format === "cjs" ? "commonjs" : "esnext",
|
|
596
|
-
sourceMap: config.sourcemap
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
const bundledCode = result.files["deno:///bundle.js"];
|
|
600
|
-
if (bundledCode) {
|
|
601
|
-
await Deno.writeTextFile(outputPath, bundledCode);
|
|
602
|
-
}
|
|
603
|
-
({ buildTime, size } = calculateBuildMetrics(startTime, outputPath));
|
|
604
|
-
}
|
|
605
750
|
if (config.logging) {
|
|
606
751
|
logBuildSuccess(buildTime, size);
|
|
607
|
-
|
|
608
|
-
const inputs = Object.keys(result.metafile.inputs).length;
|
|
609
|
-
console.log(` Files: ${inputs} input(s)`);
|
|
610
|
-
const outputKeys = Object.keys(result.metafile.outputs);
|
|
611
|
-
if (outputKeys.length > 0) {
|
|
612
|
-
const mainOutput = result.metafile.outputs[outputKeys[0]];
|
|
613
|
-
if (mainOutput && mainOutput.inputs) {
|
|
614
|
-
const sortedInputs = Object.entries(mainOutput.inputs).sort(([, a], [, b]) => {
|
|
615
|
-
const aBytes = a.bytesInOutput || 0;
|
|
616
|
-
const bBytes = b.bytesInOutput || 0;
|
|
617
|
-
return bBytes - aBytes;
|
|
618
|
-
}).slice(0, 5);
|
|
619
|
-
if (sortedInputs.length > 0) {
|
|
620
|
-
console.log("\n \u{1F4CA} Top 5 largest modules:");
|
|
621
|
-
sortedInputs.forEach(([file, info]) => {
|
|
622
|
-
const fileName = file.split(/[/\\]/).pop() || file;
|
|
623
|
-
const infoBytes = info.bytesInOutput || 0;
|
|
624
|
-
console.log(` ${fileName.padEnd(30)} ${formatBytes(infoBytes)}`);
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
752
|
+
logMetafileSummary(result);
|
|
630
753
|
}
|
|
631
754
|
const buildResult = {
|
|
632
|
-
outputPath,
|
|
755
|
+
outputPath: paths.outputPath,
|
|
633
756
|
buildTime,
|
|
634
757
|
size
|
|
635
758
|
};
|
|
636
|
-
|
|
637
|
-
if (config.logging) {
|
|
638
|
-
console.log("\n\u{1F4E6} Copying files...");
|
|
639
|
-
}
|
|
640
|
-
for (const copyItem of config.copy) {
|
|
641
|
-
const fromPath = resolve(copyItem.from);
|
|
642
|
-
const toPath = resolve(outDir, copyItem.to);
|
|
643
|
-
const targetDir = dirname(toPath);
|
|
644
|
-
if (!existsSync(targetDir)) {
|
|
645
|
-
ensureDir(targetDir);
|
|
646
|
-
}
|
|
647
|
-
if (existsSync(fromPath)) {
|
|
648
|
-
if (copyItem.transform) {
|
|
649
|
-
const content = readFileAsString(fromPath);
|
|
650
|
-
const transformed = copyItem.transform(content, config);
|
|
651
|
-
writeFileSync(toPath, transformed);
|
|
652
|
-
} else {
|
|
653
|
-
copyFileSync(fromPath, toPath);
|
|
654
|
-
}
|
|
655
|
-
if (config.logging) {
|
|
656
|
-
console.log(` \u2713 ${copyItem.from} \u2192 ${copyItem.to}`);
|
|
657
|
-
}
|
|
658
|
-
} else if (config.logging) {
|
|
659
|
-
console.warn(` \u26A0 File not found: ${copyItem.from}`);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
759
|
+
copyBuildFiles(config, paths.outDir);
|
|
663
760
|
if (config.onBuildEnd) {
|
|
664
761
|
await config.onBuildEnd(buildResult);
|
|
665
762
|
}
|
|
@@ -675,13 +772,6 @@ async function build(options) {
|
|
|
675
772
|
throw error;
|
|
676
773
|
}
|
|
677
774
|
}
|
|
678
|
-
function formatBytes(bytes) {
|
|
679
|
-
if (bytes === 0) return "0 B";
|
|
680
|
-
const k = 1024;
|
|
681
|
-
const sizes = ["B", "KB", "MB", "GB"];
|
|
682
|
-
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
683
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
684
|
-
}
|
|
685
775
|
export {
|
|
686
776
|
build
|
|
687
777
|
};
|