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