elit 3.2.1 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.d.mts +1 -3
- package/dist/cli.js +219 -725
- package/dist/config.d.ts.map +1 -1
- package/dist/database.d.mts +1 -0
- package/dist/database.d.ts +1 -0
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +5 -13
- package/dist/database.mjs +5 -13
- package/dist/{server-BFOHbYb6.d.ts → server-DTsu88db.d.ts} +1 -12
- package/dist/{server-BPVoq5Xi.d.mts → server-SjfPJEWf.d.mts} +1 -12
- package/dist/server.d.mts +1 -3
- package/dist/server.d.ts +0 -10
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +209 -684
- package/dist/server.mjs +209 -682
- package/dist/types.d.mts +0 -10
- package/dist/types.d.ts +0 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +3 -11
- package/src/database.ts +6 -14
- package/src/server.ts +1 -28
- package/src/types.ts +0 -3
package/dist/cli.js
CHANGED
|
@@ -121,205 +121,205 @@ async function processDenoEntriesAsync(iterator, withFileTypes) {
|
|
|
121
121
|
}
|
|
122
122
|
return entries;
|
|
123
123
|
}
|
|
124
|
-
async function readFile(
|
|
124
|
+
async function readFile(path, options) {
|
|
125
125
|
const opts = parseOptions(options, {});
|
|
126
126
|
if (isNode) {
|
|
127
|
-
return fsPromises.readFile(
|
|
127
|
+
return fsPromises.readFile(path, opts);
|
|
128
128
|
} else if (isBun) {
|
|
129
|
-
const file = Bun.file(
|
|
129
|
+
const file = Bun.file(path);
|
|
130
130
|
const content = await file.arrayBuffer();
|
|
131
131
|
return decodeContent(content, opts.encoding);
|
|
132
132
|
} else if (isDeno) {
|
|
133
|
-
const content = await Deno.readFile(
|
|
133
|
+
const content = await Deno.readFile(path);
|
|
134
134
|
return decodeContent(content, opts.encoding);
|
|
135
135
|
}
|
|
136
136
|
throw new Error("Unsupported runtime");
|
|
137
137
|
}
|
|
138
|
-
function readFileSync(
|
|
138
|
+
function readFileSync(path, options) {
|
|
139
139
|
const opts = parseOptions(options, {});
|
|
140
140
|
if (isNode) {
|
|
141
|
-
return fs.readFileSync(
|
|
141
|
+
return fs.readFileSync(path, opts);
|
|
142
142
|
} else if (isBun) {
|
|
143
|
-
const file = Bun.file(
|
|
143
|
+
const file = Bun.file(path);
|
|
144
144
|
const content = file.arrayBuffer();
|
|
145
145
|
return decodeContent(content, opts.encoding);
|
|
146
146
|
} else if (isDeno) {
|
|
147
|
-
const content = Deno.readFileSync(
|
|
147
|
+
const content = Deno.readFileSync(path);
|
|
148
148
|
return decodeContent(content, opts.encoding);
|
|
149
149
|
}
|
|
150
150
|
throw new Error("Unsupported runtime");
|
|
151
151
|
}
|
|
152
|
-
async function writeFile(
|
|
152
|
+
async function writeFile(path, data, options) {
|
|
153
153
|
const opts = parseOptions(options, {});
|
|
154
154
|
if (isNode) {
|
|
155
|
-
return fsPromises.writeFile(
|
|
155
|
+
return fsPromises.writeFile(path, data, opts);
|
|
156
156
|
} else if (isBun) {
|
|
157
|
-
await Bun.write(
|
|
157
|
+
await Bun.write(path, data);
|
|
158
158
|
} else if (isDeno) {
|
|
159
|
-
await Deno.writeFile(
|
|
159
|
+
await Deno.writeFile(path, dataToUint8Array(data));
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
function writeFileSync(
|
|
162
|
+
function writeFileSync(path, data, options) {
|
|
163
163
|
const opts = parseOptions(options, {});
|
|
164
164
|
if (isNode) {
|
|
165
|
-
fs.writeFileSync(
|
|
165
|
+
fs.writeFileSync(path, data, opts);
|
|
166
166
|
} else if (isBun) {
|
|
167
|
-
Bun.write(
|
|
167
|
+
Bun.write(path, data);
|
|
168
168
|
} else if (isDeno) {
|
|
169
|
-
Deno.writeFileSync(
|
|
169
|
+
Deno.writeFileSync(path, dataToUint8Array(data));
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
async function appendFile(
|
|
172
|
+
async function appendFile(path, data, options) {
|
|
173
173
|
const opts = parseOptions(options, {});
|
|
174
174
|
if (isNode) {
|
|
175
|
-
return fsPromises.appendFile(
|
|
175
|
+
return fsPromises.appendFile(path, data, opts);
|
|
176
176
|
} else {
|
|
177
|
-
if (await exists(
|
|
178
|
-
const existing = await readFile(
|
|
177
|
+
if (await exists(path)) {
|
|
178
|
+
const existing = await readFile(path);
|
|
179
179
|
const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
|
|
180
|
-
await writeFile(
|
|
180
|
+
await writeFile(path, combined, opts);
|
|
181
181
|
} else {
|
|
182
|
-
await writeFile(
|
|
182
|
+
await writeFile(path, data, opts);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
function appendFileSync(
|
|
186
|
+
function appendFileSync(path, data, options) {
|
|
187
187
|
const opts = parseOptions(options, {});
|
|
188
188
|
if (isNode) {
|
|
189
|
-
fs.appendFileSync(
|
|
189
|
+
fs.appendFileSync(path, data, opts);
|
|
190
190
|
} else {
|
|
191
|
-
if (existsSync(
|
|
192
|
-
const existing = readFileSync(
|
|
191
|
+
if (existsSync(path)) {
|
|
192
|
+
const existing = readFileSync(path);
|
|
193
193
|
const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
|
|
194
|
-
writeFileSync(
|
|
194
|
+
writeFileSync(path, combined, opts);
|
|
195
195
|
} else {
|
|
196
|
-
writeFileSync(
|
|
196
|
+
writeFileSync(path, data, opts);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
async function exists(
|
|
200
|
+
async function exists(path) {
|
|
201
201
|
try {
|
|
202
|
-
await stat(
|
|
202
|
+
await stat(path);
|
|
203
203
|
return true;
|
|
204
204
|
} catch {
|
|
205
205
|
return false;
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
function existsSync(
|
|
208
|
+
function existsSync(path) {
|
|
209
209
|
try {
|
|
210
|
-
statSync(
|
|
210
|
+
statSync(path);
|
|
211
211
|
return true;
|
|
212
212
|
} catch {
|
|
213
213
|
return false;
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
|
-
async function stat(
|
|
216
|
+
async function stat(path) {
|
|
217
217
|
if (isNode) {
|
|
218
|
-
return fsPromises.stat(
|
|
218
|
+
return fsPromises.stat(path);
|
|
219
219
|
} else if (isBun) {
|
|
220
|
-
const file = Bun.file(
|
|
220
|
+
const file = Bun.file(path);
|
|
221
221
|
const size = file.size;
|
|
222
222
|
const exists2 = await file.exists();
|
|
223
223
|
if (!exists2) {
|
|
224
|
-
throw new Error(`ENOENT: no such file or directory, stat '${
|
|
224
|
+
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
225
225
|
}
|
|
226
|
-
return createStatsObject(
|
|
226
|
+
return createStatsObject(path, size, false);
|
|
227
227
|
} else if (isDeno) {
|
|
228
|
-
const info = await Deno.stat(
|
|
228
|
+
const info = await Deno.stat(path);
|
|
229
229
|
return createStatsFromDenoFileInfo(info);
|
|
230
230
|
}
|
|
231
231
|
throw new Error("Unsupported runtime");
|
|
232
232
|
}
|
|
233
|
-
function statSync(
|
|
233
|
+
function statSync(path) {
|
|
234
234
|
if (isNode) {
|
|
235
|
-
return fs.statSync(
|
|
235
|
+
return fs.statSync(path);
|
|
236
236
|
} else if (isBun) {
|
|
237
|
-
const file = Bun.file(
|
|
237
|
+
const file = Bun.file(path);
|
|
238
238
|
const size = file.size;
|
|
239
239
|
try {
|
|
240
240
|
file.arrayBuffer();
|
|
241
241
|
} catch {
|
|
242
|
-
throw new Error(`ENOENT: no such file or directory, stat '${
|
|
242
|
+
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
243
243
|
}
|
|
244
|
-
return createStatsObject(
|
|
244
|
+
return createStatsObject(path, size, false);
|
|
245
245
|
} else if (isDeno) {
|
|
246
|
-
const info = Deno.statSync(
|
|
246
|
+
const info = Deno.statSync(path);
|
|
247
247
|
return createStatsFromDenoFileInfo(info);
|
|
248
248
|
}
|
|
249
249
|
throw new Error("Unsupported runtime");
|
|
250
250
|
}
|
|
251
|
-
async function mkdir(
|
|
251
|
+
async function mkdir(path, options) {
|
|
252
252
|
const opts = typeof options === "number" ? { mode: options } : options || {};
|
|
253
253
|
if (isNode) {
|
|
254
|
-
await fsPromises.mkdir(
|
|
254
|
+
await fsPromises.mkdir(path, opts);
|
|
255
255
|
} else if (isBun) {
|
|
256
|
-
await Deno.mkdir(
|
|
256
|
+
await Deno.mkdir(path, { recursive: opts.recursive });
|
|
257
257
|
} else if (isDeno) {
|
|
258
|
-
await Deno.mkdir(
|
|
258
|
+
await Deno.mkdir(path, { recursive: opts.recursive });
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
|
-
function mkdirSync(
|
|
261
|
+
function mkdirSync(path, options) {
|
|
262
262
|
const opts = typeof options === "number" ? { mode: options } : options || {};
|
|
263
263
|
if (isNode) {
|
|
264
|
-
fs.mkdirSync(
|
|
264
|
+
fs.mkdirSync(path, opts);
|
|
265
265
|
} else if (isBun) {
|
|
266
|
-
Deno.mkdirSync(
|
|
266
|
+
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
267
267
|
} else if (isDeno) {
|
|
268
|
-
Deno.mkdirSync(
|
|
268
|
+
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
-
async function readdir(
|
|
271
|
+
async function readdir(path, options) {
|
|
272
272
|
const opts = parseOptions(options, {});
|
|
273
273
|
if (isNode) {
|
|
274
|
-
return fsPromises.readdir(
|
|
274
|
+
return fsPromises.readdir(path, opts);
|
|
275
275
|
} else if (isBunOrDeno) {
|
|
276
|
-
return processDenoEntriesAsync(Deno.readDir(
|
|
276
|
+
return processDenoEntriesAsync(Deno.readDir(path), opts.withFileTypes);
|
|
277
277
|
}
|
|
278
278
|
throw new Error("Unsupported runtime");
|
|
279
279
|
}
|
|
280
|
-
function readdirSync(
|
|
280
|
+
function readdirSync(path, options) {
|
|
281
281
|
const opts = parseOptions(options, {});
|
|
282
282
|
if (isNode) {
|
|
283
|
-
return fs.readdirSync(
|
|
283
|
+
return fs.readdirSync(path, opts);
|
|
284
284
|
} else if (isBunOrDeno) {
|
|
285
|
-
return processDenoEntries(Deno.readDirSync(
|
|
285
|
+
return processDenoEntries(Deno.readDirSync(path), opts.withFileTypes);
|
|
286
286
|
}
|
|
287
287
|
throw new Error("Unsupported runtime");
|
|
288
288
|
}
|
|
289
|
-
async function unlink(
|
|
289
|
+
async function unlink(path) {
|
|
290
290
|
if (isNode) {
|
|
291
|
-
return fsPromises.unlink(
|
|
291
|
+
return fsPromises.unlink(path);
|
|
292
292
|
} else if (isBun) {
|
|
293
|
-
await Deno.remove(
|
|
293
|
+
await Deno.remove(path);
|
|
294
294
|
} else if (isDeno) {
|
|
295
|
-
await Deno.remove(
|
|
295
|
+
await Deno.remove(path);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
-
function unlinkSync(
|
|
298
|
+
function unlinkSync(path) {
|
|
299
299
|
if (isNode) {
|
|
300
|
-
fs.unlinkSync(
|
|
300
|
+
fs.unlinkSync(path);
|
|
301
301
|
} else if (isBun) {
|
|
302
|
-
Deno.removeSync(
|
|
302
|
+
Deno.removeSync(path);
|
|
303
303
|
} else if (isDeno) {
|
|
304
|
-
Deno.removeSync(
|
|
304
|
+
Deno.removeSync(path);
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
async function rmdir(
|
|
307
|
+
async function rmdir(path, options) {
|
|
308
308
|
if (isNode) {
|
|
309
|
-
return fsPromises.rmdir(
|
|
309
|
+
return fsPromises.rmdir(path, options);
|
|
310
310
|
} else if (isBun) {
|
|
311
|
-
await Deno.remove(
|
|
311
|
+
await Deno.remove(path, { recursive: options?.recursive });
|
|
312
312
|
} else if (isDeno) {
|
|
313
|
-
await Deno.remove(
|
|
313
|
+
await Deno.remove(path, { recursive: options?.recursive });
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
-
function rmdirSync(
|
|
316
|
+
function rmdirSync(path, options) {
|
|
317
317
|
if (isNode) {
|
|
318
|
-
fs.rmdirSync(
|
|
318
|
+
fs.rmdirSync(path, options);
|
|
319
319
|
} else if (isBun) {
|
|
320
|
-
Deno.removeSync(
|
|
320
|
+
Deno.removeSync(path, { recursive: options?.recursive });
|
|
321
321
|
} else if (isDeno) {
|
|
322
|
-
Deno.removeSync(
|
|
322
|
+
Deno.removeSync(path, { recursive: options?.recursive });
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
async function rename(oldPath, newPath) {
|
|
@@ -358,27 +358,27 @@ function copyFileSync(src, dest, flags) {
|
|
|
358
358
|
Deno.copyFileSync(src, dest);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
async function realpath(
|
|
361
|
+
async function realpath(path, options) {
|
|
362
362
|
if (isNode) {
|
|
363
|
-
return fsPromises.realpath(
|
|
363
|
+
return fsPromises.realpath(path, options);
|
|
364
364
|
} else if (isBun) {
|
|
365
|
-
const
|
|
366
|
-
return
|
|
365
|
+
const fs2 = require("fs/promises");
|
|
366
|
+
return fs2.realpath(path, options);
|
|
367
367
|
} else if (isDeno) {
|
|
368
|
-
return await Deno.realPath(
|
|
368
|
+
return await Deno.realPath(path);
|
|
369
369
|
}
|
|
370
|
-
return
|
|
370
|
+
return path;
|
|
371
371
|
}
|
|
372
|
-
function realpathSync(
|
|
372
|
+
function realpathSync(path, options) {
|
|
373
373
|
if (isNode) {
|
|
374
|
-
return fs.realpathSync(
|
|
374
|
+
return fs.realpathSync(path, options);
|
|
375
375
|
} else if (isBun) {
|
|
376
|
-
const
|
|
377
|
-
return
|
|
376
|
+
const fs2 = require("fs");
|
|
377
|
+
return fs2.realpathSync(path, options);
|
|
378
378
|
} else if (isDeno) {
|
|
379
|
-
return Deno.realPathSync(
|
|
379
|
+
return Deno.realPathSync(path);
|
|
380
380
|
}
|
|
381
|
-
return
|
|
381
|
+
return path;
|
|
382
382
|
}
|
|
383
383
|
function createStatsObject(_path, size, isDir) {
|
|
384
384
|
const now = Date.now();
|
|
@@ -540,38 +540,38 @@ function getCwd() {
|
|
|
540
540
|
}
|
|
541
541
|
return "/";
|
|
542
542
|
}
|
|
543
|
-
function findLastSeparator(
|
|
544
|
-
return Math.max(
|
|
543
|
+
function findLastSeparator(path) {
|
|
544
|
+
return Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
545
545
|
}
|
|
546
546
|
function createPathOps(isWin) {
|
|
547
547
|
return {
|
|
548
548
|
sep: getSeparator(isWin),
|
|
549
549
|
delimiter: isWin ? ";" : ":",
|
|
550
|
-
normalize: (
|
|
550
|
+
normalize: (path) => normalizePath(path, isWin),
|
|
551
551
|
join: (...paths) => joinPaths(paths, isWin),
|
|
552
552
|
resolve: (...paths) => resolvePaths(paths, isWin),
|
|
553
|
-
isAbsolute: (
|
|
553
|
+
isAbsolute: (path) => isWin ? isAbsoluteWin(path) : isAbsolutePosix(path),
|
|
554
554
|
relative: (from, to) => relativePath(from, to, isWin),
|
|
555
|
-
dirname: (
|
|
556
|
-
basename: (
|
|
557
|
-
extname: (
|
|
558
|
-
parse: (
|
|
555
|
+
dirname: (path) => getDirname(path, isWin),
|
|
556
|
+
basename: (path, ext) => getBasename(path, ext, isWin),
|
|
557
|
+
extname: (path) => getExtname(path),
|
|
558
|
+
parse: (path) => parsePath(path, isWin),
|
|
559
559
|
format: (pathObject) => formatPath(pathObject, isWin)
|
|
560
560
|
};
|
|
561
561
|
}
|
|
562
|
-
function isAbsolutePosix(
|
|
563
|
-
return
|
|
562
|
+
function isAbsolutePosix(path) {
|
|
563
|
+
return path.length > 0 && path[0] === "/";
|
|
564
564
|
}
|
|
565
|
-
function isAbsoluteWin(
|
|
566
|
-
const len =
|
|
565
|
+
function isAbsoluteWin(path) {
|
|
566
|
+
const len = path.length;
|
|
567
567
|
if (len === 0) return false;
|
|
568
|
-
const code =
|
|
568
|
+
const code = path.charCodeAt(0);
|
|
569
569
|
if (code === 47 || code === 92) {
|
|
570
570
|
return true;
|
|
571
571
|
}
|
|
572
572
|
if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
573
|
-
if (len > 2 &&
|
|
574
|
-
const code2 =
|
|
573
|
+
if (len > 2 && path.charCodeAt(1) === 58) {
|
|
574
|
+
const code2 = path.charCodeAt(2);
|
|
575
575
|
if (code2 === 47 || code2 === 92) {
|
|
576
576
|
return true;
|
|
577
577
|
}
|
|
@@ -579,12 +579,12 @@ function isAbsoluteWin(path2) {
|
|
|
579
579
|
}
|
|
580
580
|
return false;
|
|
581
581
|
}
|
|
582
|
-
function normalizePath(
|
|
583
|
-
if (
|
|
582
|
+
function normalizePath(path, isWin) {
|
|
583
|
+
if (path.length === 0) return ".";
|
|
584
584
|
const separator = getSeparator(isWin);
|
|
585
|
-
const isAbsolute2 = isWin ? isAbsoluteWin(
|
|
586
|
-
const trailingSeparator =
|
|
587
|
-
let normalized =
|
|
585
|
+
const isAbsolute2 = isWin ? isAbsoluteWin(path) : isAbsolutePosix(path);
|
|
586
|
+
const trailingSeparator = path[path.length - 1] === separator || isWin && path[path.length - 1] === "/";
|
|
587
|
+
let normalized = path.replace(isWin ? /[\/\\]+/g : /\/+/g, separator);
|
|
588
588
|
const parts = normalized.split(separator);
|
|
589
589
|
const result = [];
|
|
590
590
|
for (let i = 0; i < parts.length; i++) {
|
|
@@ -619,12 +619,12 @@ function joinPaths(paths, isWin) {
|
|
|
619
619
|
const separator = getSeparator(isWin);
|
|
620
620
|
let joined = "";
|
|
621
621
|
for (let i = 0; i < paths.length; i++) {
|
|
622
|
-
const
|
|
623
|
-
if (
|
|
622
|
+
const path = paths[i];
|
|
623
|
+
if (path && path.length > 0) {
|
|
624
624
|
if (joined.length === 0) {
|
|
625
|
-
joined =
|
|
625
|
+
joined = path;
|
|
626
626
|
} else {
|
|
627
|
-
joined += separator +
|
|
627
|
+
joined += separator + path;
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
}
|
|
@@ -636,9 +636,9 @@ function resolvePaths(paths, isWin) {
|
|
|
636
636
|
let resolved = "";
|
|
637
637
|
let isAbsolute2 = false;
|
|
638
638
|
for (let i = paths.length - 1; i >= 0 && !isAbsolute2; i--) {
|
|
639
|
-
const
|
|
640
|
-
if (
|
|
641
|
-
resolved =
|
|
639
|
+
const path = paths[i];
|
|
640
|
+
if (path && path.length > 0) {
|
|
641
|
+
resolved = path + (resolved.length > 0 ? separator + resolved : "");
|
|
642
642
|
isAbsolute2 = isWin ? isAbsoluteWin(resolved) : isAbsolutePosix(resolved);
|
|
643
643
|
}
|
|
644
644
|
}
|
|
@@ -674,51 +674,51 @@ function relativePath(from, to, isWin) {
|
|
|
674
674
|
}
|
|
675
675
|
return result.join(separator) || ".";
|
|
676
676
|
}
|
|
677
|
-
function getDirname(
|
|
678
|
-
if (
|
|
677
|
+
function getDirname(path, isWin) {
|
|
678
|
+
if (path.length === 0) return ".";
|
|
679
679
|
const separator = getSeparator(isWin);
|
|
680
|
-
const normalized = normalizePath(
|
|
680
|
+
const normalized = normalizePath(path, isWin);
|
|
681
681
|
const lastSepIndex = normalized.lastIndexOf(separator);
|
|
682
682
|
if (lastSepIndex === -1) return ".";
|
|
683
683
|
if (lastSepIndex === 0) return separator;
|
|
684
684
|
return normalized.slice(0, lastSepIndex);
|
|
685
685
|
}
|
|
686
|
-
function getBasename(
|
|
687
|
-
if (
|
|
688
|
-
const lastSepIndex = isWin ? findLastSeparator(
|
|
689
|
-
let base = lastSepIndex === -1 ?
|
|
686
|
+
function getBasename(path, ext, isWin) {
|
|
687
|
+
if (path.length === 0) return "";
|
|
688
|
+
const lastSepIndex = isWin ? findLastSeparator(path) : path.lastIndexOf("/");
|
|
689
|
+
let base = lastSepIndex === -1 ? path : path.slice(lastSepIndex + 1);
|
|
690
690
|
if (ext && base.endsWith(ext)) {
|
|
691
691
|
base = base.slice(0, base.length - ext.length);
|
|
692
692
|
}
|
|
693
693
|
return base;
|
|
694
694
|
}
|
|
695
|
-
function getExtname(
|
|
696
|
-
const lastDotIndex =
|
|
697
|
-
const lastSepIndex = findLastSeparator(
|
|
698
|
-
if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex ===
|
|
695
|
+
function getExtname(path) {
|
|
696
|
+
const lastDotIndex = path.lastIndexOf(".");
|
|
697
|
+
const lastSepIndex = findLastSeparator(path);
|
|
698
|
+
if (lastDotIndex === -1 || lastDotIndex < lastSepIndex || lastDotIndex === path.length - 1) {
|
|
699
699
|
return "";
|
|
700
700
|
}
|
|
701
|
-
return
|
|
701
|
+
return path.slice(lastDotIndex);
|
|
702
702
|
}
|
|
703
|
-
function parsePath(
|
|
703
|
+
function parsePath(path, isWin) {
|
|
704
704
|
let root = "";
|
|
705
705
|
if (isWin) {
|
|
706
|
-
if (
|
|
707
|
-
root =
|
|
708
|
-
if (
|
|
706
|
+
if (path.length >= 2 && path[1] === ":") {
|
|
707
|
+
root = path.slice(0, 2);
|
|
708
|
+
if (path.length > 2 && (path[2] === "\\" || path[2] === "/")) {
|
|
709
709
|
root += "\\";
|
|
710
710
|
}
|
|
711
|
-
} else if (
|
|
711
|
+
} else if (path[0] === "\\" || path[0] === "/") {
|
|
712
712
|
root = "\\";
|
|
713
713
|
}
|
|
714
714
|
} else {
|
|
715
|
-
if (
|
|
715
|
+
if (path[0] === "/") {
|
|
716
716
|
root = "/";
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
|
-
const dir = getDirname(
|
|
720
|
-
const base = getBasename(
|
|
721
|
-
const ext = getExtname(
|
|
719
|
+
const dir = getDirname(path, isWin);
|
|
720
|
+
const base = getBasename(path, void 0, isWin);
|
|
721
|
+
const ext = getExtname(path);
|
|
722
722
|
const name = ext ? base.slice(0, base.length - ext.length) : base;
|
|
723
723
|
return { root, dir, base, ext, name };
|
|
724
724
|
}
|
|
@@ -730,8 +730,8 @@ function formatPath(pathObject, isWin) {
|
|
|
730
730
|
if (dir === pathObject.root) return dir + base;
|
|
731
731
|
return dir + separator + base;
|
|
732
732
|
}
|
|
733
|
-
function normalize(
|
|
734
|
-
return normalizePath(
|
|
733
|
+
function normalize(path) {
|
|
734
|
+
return normalizePath(path, isWindows);
|
|
735
735
|
}
|
|
736
736
|
function join(...paths) {
|
|
737
737
|
return joinPaths(paths, isWindows);
|
|
@@ -739,30 +739,30 @@ function join(...paths) {
|
|
|
739
739
|
function resolve(...paths) {
|
|
740
740
|
return resolvePaths(paths, isWindows);
|
|
741
741
|
}
|
|
742
|
-
function isAbsolute(
|
|
743
|
-
return isWindows ? win32.isAbsolute(
|
|
742
|
+
function isAbsolute(path) {
|
|
743
|
+
return isWindows ? win32.isAbsolute(path) : posix.isAbsolute(path);
|
|
744
744
|
}
|
|
745
745
|
function relative(from, to) {
|
|
746
746
|
return relativePath(from, to, isWindows);
|
|
747
747
|
}
|
|
748
|
-
function dirname(
|
|
749
|
-
return getDirname(
|
|
748
|
+
function dirname(path) {
|
|
749
|
+
return getDirname(path, isWindows);
|
|
750
750
|
}
|
|
751
|
-
function basename(
|
|
752
|
-
return getBasename(
|
|
751
|
+
function basename(path, ext) {
|
|
752
|
+
return getBasename(path, ext, isWindows);
|
|
753
753
|
}
|
|
754
|
-
function extname(
|
|
755
|
-
return getExtname(
|
|
754
|
+
function extname(path) {
|
|
755
|
+
return getExtname(path);
|
|
756
756
|
}
|
|
757
|
-
function parse(
|
|
758
|
-
return parsePath(
|
|
757
|
+
function parse(path) {
|
|
758
|
+
return parsePath(path, isWindows);
|
|
759
759
|
}
|
|
760
760
|
function format(pathObject) {
|
|
761
761
|
return formatPath(pathObject, isWindows);
|
|
762
762
|
}
|
|
763
|
-
function toNamespacedPath(
|
|
764
|
-
if (!isWindows ||
|
|
765
|
-
const resolved = resolve(
|
|
763
|
+
function toNamespacedPath(path) {
|
|
764
|
+
if (!isWindows || path.length === 0) return path;
|
|
765
|
+
const resolved = resolve(path);
|
|
766
766
|
if (resolved.length >= 3) {
|
|
767
767
|
if (resolved[0] === "\\") {
|
|
768
768
|
if (resolved[1] === "\\" && resolved[2] !== "?") {
|
|
@@ -772,7 +772,7 @@ function toNamespacedPath(path2) {
|
|
|
772
772
|
return "\\\\?\\" + resolved;
|
|
773
773
|
}
|
|
774
774
|
}
|
|
775
|
-
return
|
|
775
|
+
return path;
|
|
776
776
|
}
|
|
777
777
|
function getRuntime2() {
|
|
778
778
|
return runtime;
|
|
@@ -1435,7 +1435,7 @@ var require_package = __commonJS({
|
|
|
1435
1435
|
"package.json"(exports2, module2) {
|
|
1436
1436
|
module2.exports = {
|
|
1437
1437
|
name: "elit",
|
|
1438
|
-
version: "3.2.
|
|
1438
|
+
version: "3.2.3",
|
|
1439
1439
|
description: "Optimized lightweight library for creating DOM elements with reactive state",
|
|
1440
1440
|
main: "dist/index.js",
|
|
1441
1441
|
module: "dist/index.mjs",
|
|
@@ -1697,12 +1697,12 @@ async function loadConfigFile(configPath) {
|
|
|
1697
1697
|
return JSON.parse(content);
|
|
1698
1698
|
} else if (ext === "ts") {
|
|
1699
1699
|
try {
|
|
1700
|
-
const { build:
|
|
1700
|
+
const { build: build2 } = await import("esbuild");
|
|
1701
1701
|
const { tmpdir } = await import("os");
|
|
1702
1702
|
const { join: join2, dirname: dirname2 } = await Promise.resolve().then(() => (init_path(), path_exports));
|
|
1703
1703
|
const tempFile = join2(tmpdir(), `elit-config-${Date.now()}.mjs`);
|
|
1704
1704
|
const configDir = dirname2(configPath);
|
|
1705
|
-
await
|
|
1705
|
+
await build2({
|
|
1706
1706
|
entryPoints: [configPath],
|
|
1707
1707
|
bundle: true,
|
|
1708
1708
|
format: "esm",
|
|
@@ -1710,43 +1710,9 @@ async function loadConfigFile(configPath) {
|
|
|
1710
1710
|
outfile: tempFile,
|
|
1711
1711
|
write: true,
|
|
1712
1712
|
target: "es2020",
|
|
1713
|
-
//
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
external: [
|
|
1717
|
-
"fs",
|
|
1718
|
-
"path",
|
|
1719
|
-
"os",
|
|
1720
|
-
"crypto",
|
|
1721
|
-
"http",
|
|
1722
|
-
"https",
|
|
1723
|
-
"stream",
|
|
1724
|
-
"util",
|
|
1725
|
-
"url",
|
|
1726
|
-
"querystring",
|
|
1727
|
-
"events",
|
|
1728
|
-
"buffer",
|
|
1729
|
-
"child_process",
|
|
1730
|
-
"cluster",
|
|
1731
|
-
"dgram",
|
|
1732
|
-
"dns",
|
|
1733
|
-
"net",
|
|
1734
|
-
"tls",
|
|
1735
|
-
"worker_threads",
|
|
1736
|
-
"zlib",
|
|
1737
|
-
"readline",
|
|
1738
|
-
"repl",
|
|
1739
|
-
"vm",
|
|
1740
|
-
"assert",
|
|
1741
|
-
"console",
|
|
1742
|
-
"timers",
|
|
1743
|
-
"async_hooks",
|
|
1744
|
-
"perf_hooks",
|
|
1745
|
-
"module",
|
|
1746
|
-
"process",
|
|
1747
|
-
"v8",
|
|
1748
|
-
"inspector"
|
|
1749
|
-
],
|
|
1713
|
+
// Bundle everything including elit/* so config can use elit modules
|
|
1714
|
+
// Only mark Node.js built-ins as external
|
|
1715
|
+
external: ["node:*"],
|
|
1750
1716
|
// Use the config directory as the working directory for resolution
|
|
1751
1717
|
absWorkingDir: configDir
|
|
1752
1718
|
});
|
|
@@ -2159,32 +2125,32 @@ var WebSocketServer = class extends import_events2.EventEmitter {
|
|
|
2159
2125
|
// src/chokidar.ts
|
|
2160
2126
|
var import_events3 = require("events");
|
|
2161
2127
|
init_runtime();
|
|
2162
|
-
function normalizePath2(
|
|
2163
|
-
return
|
|
2128
|
+
function normalizePath2(path) {
|
|
2129
|
+
return path.replace(/\\/g, "/");
|
|
2164
2130
|
}
|
|
2165
|
-
function emitEvent(watcher, eventType,
|
|
2166
|
-
watcher.emit(eventType,
|
|
2167
|
-
watcher.emit("all", eventType,
|
|
2131
|
+
function emitEvent(watcher, eventType, path) {
|
|
2132
|
+
watcher.emit(eventType, path);
|
|
2133
|
+
watcher.emit("all", eventType, path);
|
|
2168
2134
|
}
|
|
2169
|
-
function matchesAnyPattern(
|
|
2170
|
-
return patterns.some((pattern) => matchesPattern(
|
|
2135
|
+
function matchesAnyPattern(path, patterns) {
|
|
2136
|
+
return patterns.some((pattern) => matchesPattern(path, pattern));
|
|
2171
2137
|
}
|
|
2172
|
-
function handleRenameEvent(watcher, fullPath,
|
|
2138
|
+
function handleRenameEvent(watcher, fullPath, fs2) {
|
|
2173
2139
|
try {
|
|
2174
|
-
|
|
2140
|
+
fs2.statSync(fullPath);
|
|
2175
2141
|
emitEvent(watcher, "add", fullPath);
|
|
2176
2142
|
} catch {
|
|
2177
2143
|
emitEvent(watcher, "unlink", fullPath);
|
|
2178
2144
|
}
|
|
2179
2145
|
}
|
|
2180
|
-
function setupFsWatch(watcher, baseDir, patterns,
|
|
2146
|
+
function setupFsWatch(watcher, baseDir, patterns, fs2) {
|
|
2181
2147
|
try {
|
|
2182
|
-
const nativeWatcher =
|
|
2148
|
+
const nativeWatcher = fs2.watch(baseDir, { recursive: true }, (eventType, filename) => {
|
|
2183
2149
|
if (!filename) return;
|
|
2184
2150
|
const fullPath = normalizePath2(`${baseDir}/${filename}`);
|
|
2185
2151
|
if (!matchesAnyPattern(fullPath, patterns)) return;
|
|
2186
2152
|
if (eventType === "rename") {
|
|
2187
|
-
handleRenameEvent(watcher, fullPath,
|
|
2153
|
+
handleRenameEvent(watcher, fullPath, fs2);
|
|
2188
2154
|
} else if (eventType === "change") {
|
|
2189
2155
|
emitEvent(watcher, "change", fullPath);
|
|
2190
2156
|
}
|
|
@@ -2216,7 +2182,7 @@ var FSWatcher = class extends import_events3.EventEmitter {
|
|
|
2216
2182
|
this._watcher.add(pathArray);
|
|
2217
2183
|
}
|
|
2218
2184
|
} else {
|
|
2219
|
-
pathArray.forEach((
|
|
2185
|
+
pathArray.forEach((path) => this._watched.add(path));
|
|
2220
2186
|
}
|
|
2221
2187
|
return this;
|
|
2222
2188
|
}
|
|
@@ -2233,7 +2199,7 @@ var FSWatcher = class extends import_events3.EventEmitter {
|
|
|
2233
2199
|
this._watcher.unwatch(pathArray);
|
|
2234
2200
|
}
|
|
2235
2201
|
} else {
|
|
2236
|
-
pathArray.forEach((
|
|
2202
|
+
pathArray.forEach((path) => this._watched.delete(path));
|
|
2237
2203
|
}
|
|
2238
2204
|
return this;
|
|
2239
2205
|
}
|
|
@@ -2260,9 +2226,9 @@ var FSWatcher = class extends import_events3.EventEmitter {
|
|
|
2260
2226
|
return this._watcher.getWatched();
|
|
2261
2227
|
}
|
|
2262
2228
|
const result = {};
|
|
2263
|
-
this._watched.forEach((
|
|
2264
|
-
const dir =
|
|
2265
|
-
const file =
|
|
2229
|
+
this._watched.forEach((path) => {
|
|
2230
|
+
const dir = path.substring(0, path.lastIndexOf("/")) || ".";
|
|
2231
|
+
const file = path.substring(path.lastIndexOf("/") + 1);
|
|
2266
2232
|
if (!result[dir]) {
|
|
2267
2233
|
result[dir] = [];
|
|
2268
2234
|
}
|
|
@@ -2299,19 +2265,19 @@ function watch(paths, options) {
|
|
|
2299
2265
|
const watcher = new FSWatcher(options);
|
|
2300
2266
|
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
2301
2267
|
const watchMap = /* @__PURE__ */ new Map();
|
|
2302
|
-
pathArray.forEach((
|
|
2303
|
-
const baseDir = getBaseDirectory(
|
|
2268
|
+
pathArray.forEach((path) => {
|
|
2269
|
+
const baseDir = getBaseDirectory(path);
|
|
2304
2270
|
if (!watchMap.has(baseDir)) {
|
|
2305
2271
|
watchMap.set(baseDir, []);
|
|
2306
2272
|
}
|
|
2307
|
-
watchMap.get(baseDir).push(
|
|
2273
|
+
watchMap.get(baseDir).push(path);
|
|
2308
2274
|
});
|
|
2309
2275
|
if (runtime === "node") {
|
|
2310
|
-
const
|
|
2311
|
-
watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns,
|
|
2276
|
+
const fs2 = require("fs");
|
|
2277
|
+
watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs2));
|
|
2312
2278
|
} else if (runtime === "bun") {
|
|
2313
|
-
const
|
|
2314
|
-
watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns,
|
|
2279
|
+
const fs2 = require("fs");
|
|
2280
|
+
watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs2));
|
|
2315
2281
|
} else if (runtime === "deno") {
|
|
2316
2282
|
const baseDirs = Array.from(watchMap.keys());
|
|
2317
2283
|
const allPatterns = Array.from(watchMap.values()).flat();
|
|
@@ -2320,18 +2286,18 @@ function watch(paths, options) {
|
|
|
2320
2286
|
const denoWatcher = Deno.watchFs(baseDirs);
|
|
2321
2287
|
for await (const event of denoWatcher) {
|
|
2322
2288
|
if (watcher["_closed"]) break;
|
|
2323
|
-
for (const
|
|
2324
|
-
const normalizedPath = normalizePath2(
|
|
2289
|
+
for (const path of event.paths) {
|
|
2290
|
+
const normalizedPath = normalizePath2(path);
|
|
2325
2291
|
if (!matchesAnyPattern(normalizedPath, allPatterns)) continue;
|
|
2326
2292
|
switch (event.kind) {
|
|
2327
2293
|
case "create":
|
|
2328
|
-
emitEvent(watcher, "add",
|
|
2294
|
+
emitEvent(watcher, "add", path);
|
|
2329
2295
|
break;
|
|
2330
2296
|
case "modify":
|
|
2331
|
-
emitEvent(watcher, "change",
|
|
2297
|
+
emitEvent(watcher, "change", path);
|
|
2332
2298
|
break;
|
|
2333
2299
|
case "remove":
|
|
2334
|
-
emitEvent(watcher, "unlink",
|
|
2300
|
+
emitEvent(watcher, "unlink", path);
|
|
2335
2301
|
break;
|
|
2336
2302
|
}
|
|
2337
2303
|
}
|
|
@@ -2342,7 +2308,7 @@ function watch(paths, options) {
|
|
|
2342
2308
|
}
|
|
2343
2309
|
}
|
|
2344
2310
|
})();
|
|
2345
|
-
pathArray.forEach((
|
|
2311
|
+
pathArray.forEach((path) => watcher.add(path));
|
|
2346
2312
|
queueMicrotask(() => watcher.emit("ready"));
|
|
2347
2313
|
}
|
|
2348
2314
|
return watcher;
|
|
@@ -2432,12 +2398,12 @@ for (const ext in MIME_TYPES) {
|
|
|
2432
2398
|
}
|
|
2433
2399
|
TYPE_TO_EXTENSIONS[type].push(ext);
|
|
2434
2400
|
}
|
|
2435
|
-
function getExtension(
|
|
2436
|
-
const match = /\.([^./\\]+)$/.exec(
|
|
2401
|
+
function getExtension(path) {
|
|
2402
|
+
const match = /\.([^./\\]+)$/.exec(path);
|
|
2437
2403
|
return match ? match[1].toLowerCase() : "";
|
|
2438
2404
|
}
|
|
2439
|
-
function lookup(
|
|
2440
|
-
const ext = getExtension(
|
|
2405
|
+
function lookup(path) {
|
|
2406
|
+
const ext = getExtension(path) || path.toLowerCase();
|
|
2441
2407
|
return MIME_TYPES[ext] || false;
|
|
2442
2408
|
}
|
|
2443
2409
|
|
|
@@ -3084,476 +3050,7 @@ var dom = new DomNode();
|
|
|
3084
3050
|
var render = dom.render.bind(dom);
|
|
3085
3051
|
var renderToString = dom.renderToString.bind(dom);
|
|
3086
3052
|
|
|
3087
|
-
// src/database.ts
|
|
3088
|
-
var import_node_vm = __toESM(require("vm"));
|
|
3089
|
-
init_path();
|
|
3090
|
-
var import_node_path = __toESM(require("path"));
|
|
3091
|
-
var import_node_fs = __toESM(require("fs"));
|
|
3092
|
-
var esbuild = __toESM(require("esbuild"));
|
|
3093
|
-
var Database = class {
|
|
3094
|
-
constructor(config) {
|
|
3095
|
-
this._config = {
|
|
3096
|
-
dir: resolve(process.cwd(), "databases")
|
|
3097
|
-
};
|
|
3098
|
-
this._config = { ...this._config, ...config };
|
|
3099
|
-
this._registerModules = config.registerModules || {};
|
|
3100
|
-
this._ctx = import_node_vm.default.createContext(this._registerModules);
|
|
3101
|
-
}
|
|
3102
|
-
set config(config) {
|
|
3103
|
-
this._config = { ...this._config, ...config };
|
|
3104
|
-
}
|
|
3105
|
-
register(context) {
|
|
3106
|
-
this._registerModules = { ...this._registerModules, ...context };
|
|
3107
|
-
this._ctx = import_node_vm.default.createContext(this._registerModules);
|
|
3108
|
-
}
|
|
3109
|
-
plugin(moduleName, moduleContent) {
|
|
3110
|
-
this.register({ [moduleName]: moduleContent });
|
|
3111
|
-
}
|
|
3112
|
-
resolvePath(fileList, query) {
|
|
3113
|
-
const aliases = { "@db": this._config.dir || resolve(process.cwd(), "databases") };
|
|
3114
|
-
let resolvedPath = query;
|
|
3115
|
-
for (const [alias, target] of Object.entries(aliases)) {
|
|
3116
|
-
if (resolvedPath.startsWith(alias + "/")) {
|
|
3117
|
-
resolvedPath = resolvedPath.replace(alias, target);
|
|
3118
|
-
break;
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3121
|
-
resolvedPath = import_node_path.default.normalize(resolvedPath);
|
|
3122
|
-
return fileList.find((file) => {
|
|
3123
|
-
const normalizedFile = import_node_path.default.normalize(file);
|
|
3124
|
-
const fileWithoutExt = normalizedFile.replace(/\.[^/.]+$/, "");
|
|
3125
|
-
return normalizedFile === resolvedPath || fileWithoutExt === resolvedPath || normalizedFile === resolvedPath + ".ts" || normalizedFile === resolvedPath + ".js";
|
|
3126
|
-
});
|
|
3127
|
-
}
|
|
3128
|
-
async moduleLinker(specifier, referencingModule) {
|
|
3129
|
-
const dbFiles = import_node_fs.default.readdirSync(this._config.dir || resolve(process.cwd(), "databases")).filter((f) => f.endsWith(".ts")).map((f) => import_node_path.default.join(this._config.dir || resolve(process.cwd(), "databases"), f));
|
|
3130
|
-
const dbResult = this.resolvePath(dbFiles, specifier);
|
|
3131
|
-
if (dbResult) {
|
|
3132
|
-
try {
|
|
3133
|
-
const actualModule = await import(dbResult);
|
|
3134
|
-
const exportNames = Object.keys(actualModule);
|
|
3135
|
-
return new import_node_vm.default.SyntheticModule(
|
|
3136
|
-
exportNames,
|
|
3137
|
-
function() {
|
|
3138
|
-
exportNames.forEach((key) => {
|
|
3139
|
-
this.setExport(key, actualModule[key]);
|
|
3140
|
-
});
|
|
3141
|
-
},
|
|
3142
|
-
{ identifier: specifier, context: referencingModule.context }
|
|
3143
|
-
);
|
|
3144
|
-
} catch (err) {
|
|
3145
|
-
console.error(`Failed to load database module ${specifier}:`, err);
|
|
3146
|
-
throw err;
|
|
3147
|
-
}
|
|
3148
|
-
}
|
|
3149
|
-
throw new Error(`Module ${specifier} is not allowed or not found.`);
|
|
3150
|
-
}
|
|
3151
|
-
async vmRun(code, _options) {
|
|
3152
|
-
const logs = [];
|
|
3153
|
-
const customConsole = ["log", "error", "warn", "info", "debug", "trace"].reduce((acc, type) => {
|
|
3154
|
-
acc[type] = (...args) => logs.push({ type, args });
|
|
3155
|
-
return acc;
|
|
3156
|
-
}, {});
|
|
3157
|
-
const systemBase = {
|
|
3158
|
-
update,
|
|
3159
|
-
remove,
|
|
3160
|
-
rename: rename2,
|
|
3161
|
-
read,
|
|
3162
|
-
create,
|
|
3163
|
-
save
|
|
3164
|
-
};
|
|
3165
|
-
this.register({
|
|
3166
|
-
dbConsole: { ...customConsole, ...systemBase }
|
|
3167
|
-
});
|
|
3168
|
-
let stringCode;
|
|
3169
|
-
if (typeof code === "function") {
|
|
3170
|
-
const funcStr = code.toString();
|
|
3171
|
-
if (funcStr.includes("=>")) {
|
|
3172
|
-
const arrowIndex = funcStr.indexOf("=>");
|
|
3173
|
-
let start = arrowIndex + 2;
|
|
3174
|
-
while (start < funcStr.length && funcStr[start] === " ") start++;
|
|
3175
|
-
if (funcStr[start] === "{") start++;
|
|
3176
|
-
let end = funcStr.lastIndexOf("}");
|
|
3177
|
-
if (start < end) {
|
|
3178
|
-
stringCode = funcStr.substring(start, end);
|
|
3179
|
-
} else {
|
|
3180
|
-
stringCode = funcStr.substring(start);
|
|
3181
|
-
}
|
|
3182
|
-
} else if (funcStr.includes("function")) {
|
|
3183
|
-
const funcIndex = funcStr.indexOf("function");
|
|
3184
|
-
let start = funcIndex + 8;
|
|
3185
|
-
while (start < funcStr.length && funcStr[start] === " ") start++;
|
|
3186
|
-
if (funcStr[start] === "(") start++;
|
|
3187
|
-
if (start < funcStr.length && funcStr[start] !== "(") {
|
|
3188
|
-
while (start < funcStr.length && funcStr[start] !== " " && funcStr[start] !== "(") start++;
|
|
3189
|
-
}
|
|
3190
|
-
if (funcStr[start] === "(") start++;
|
|
3191
|
-
while (start < funcStr.length && funcStr[start] === " ") start++;
|
|
3192
|
-
if (funcStr[start] === "{") start++;
|
|
3193
|
-
const end = funcStr.lastIndexOf("}");
|
|
3194
|
-
if (start < end) {
|
|
3195
|
-
stringCode = funcStr.substring(start, end);
|
|
3196
|
-
} else {
|
|
3197
|
-
stringCode = funcStr.substring(start);
|
|
3198
|
-
}
|
|
3199
|
-
} else {
|
|
3200
|
-
stringCode = funcStr;
|
|
3201
|
-
}
|
|
3202
|
-
stringCode = stringCode.trim();
|
|
3203
|
-
let importPos = 0;
|
|
3204
|
-
while ((importPos = stringCode.indexOf("import(", importPos)) !== -1) {
|
|
3205
|
-
const fromPos = stringCode.indexOf(".from(", importPos);
|
|
3206
|
-
if (fromPos === -1) break;
|
|
3207
|
-
const quoteStart = stringCode.indexOf("(", fromPos + 7) + 1;
|
|
3208
|
-
if (quoteStart === -1) break;
|
|
3209
|
-
const quoteChar = stringCode[quoteStart];
|
|
3210
|
-
if (quoteChar !== '"' && quoteChar !== "'") break;
|
|
3211
|
-
const quoteEnd = stringCode.indexOf(quoteChar, quoteStart + 1);
|
|
3212
|
-
if (quoteEnd === -1) break;
|
|
3213
|
-
const modulePath = stringCode.substring(quoteStart + 1, quoteEnd);
|
|
3214
|
-
const importArgEnd = fromPos - 1;
|
|
3215
|
-
const importArgStart = importPos + 7;
|
|
3216
|
-
const trimmed = stringCode.substring(importArgStart, importArgEnd).trim();
|
|
3217
|
-
let replacement;
|
|
3218
|
-
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
3219
|
-
const inner = trimmed.slice(1, -1).trim();
|
|
3220
|
-
replacement = `import { ${inner} } from "${modulePath}"`;
|
|
3221
|
-
} else {
|
|
3222
|
-
replacement = `import ${trimmed} from "${modulePath}"`;
|
|
3223
|
-
}
|
|
3224
|
-
const before = stringCode.substring(0, importPos);
|
|
3225
|
-
const after = stringCode.substring(quoteEnd + 2);
|
|
3226
|
-
stringCode = before + replacement + after;
|
|
3227
|
-
}
|
|
3228
|
-
const lines = stringCode.split("\n");
|
|
3229
|
-
const trimmedLines = lines.map((line) => line.trim());
|
|
3230
|
-
stringCode = trimmedLines.join("\n").trim();
|
|
3231
|
-
} else {
|
|
3232
|
-
stringCode = code;
|
|
3233
|
-
}
|
|
3234
|
-
const result = await esbuild.build({
|
|
3235
|
-
stdin: {
|
|
3236
|
-
contents: stringCode,
|
|
3237
|
-
loader: this._config.language || "ts"
|
|
3238
|
-
},
|
|
3239
|
-
format: "esm",
|
|
3240
|
-
target: "es2020",
|
|
3241
|
-
write: false,
|
|
3242
|
-
bundle: false,
|
|
3243
|
-
sourcemap: false
|
|
3244
|
-
});
|
|
3245
|
-
const js = result.outputFiles[0].text;
|
|
3246
|
-
const mod = new import_node_vm.default.SourceTextModule(js, { context: this._ctx, identifier: import_node_path.default.join(this._config.dir || resolve(process.cwd(), "databases"), "virtual-entry.js") });
|
|
3247
|
-
await mod.link(this.moduleLinker.bind(this));
|
|
3248
|
-
await mod.evaluate();
|
|
3249
|
-
return {
|
|
3250
|
-
namespace: mod.namespace,
|
|
3251
|
-
logs
|
|
3252
|
-
};
|
|
3253
|
-
}
|
|
3254
|
-
/**
|
|
3255
|
-
* Execute database code and return results
|
|
3256
|
-
*/
|
|
3257
|
-
async execute(code, options) {
|
|
3258
|
-
return await this.vmRun(code, options);
|
|
3259
|
-
}
|
|
3260
|
-
};
|
|
3261
|
-
function create(dbName, code) {
|
|
3262
|
-
const DIR = "databases";
|
|
3263
|
-
const basePath = process.cwd();
|
|
3264
|
-
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3265
|
-
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3266
|
-
import_node_fs.default.appendFileSync(dbPath, code.toString(), "utf8");
|
|
3267
|
-
}
|
|
3268
|
-
function read(dbName) {
|
|
3269
|
-
const DIR = "databases";
|
|
3270
|
-
const basePath = process.cwd();
|
|
3271
|
-
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3272
|
-
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3273
|
-
if (!import_node_fs.default.existsSync(dbPath)) {
|
|
3274
|
-
throw new Error(`Database '${dbName}' not found`);
|
|
3275
|
-
}
|
|
3276
|
-
return import_node_fs.default.readFileSync(dbPath, "utf8");
|
|
3277
|
-
}
|
|
3278
|
-
function remove(dbName, fnName) {
|
|
3279
|
-
const DIR = "databases";
|
|
3280
|
-
const basePath = process.cwd();
|
|
3281
|
-
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3282
|
-
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3283
|
-
if (!import_node_fs.default.existsSync(dbPath)) return false;
|
|
3284
|
-
if (!fnName) {
|
|
3285
|
-
const bak2 = `${dbPath}.bak`;
|
|
3286
|
-
try {
|
|
3287
|
-
import_node_fs.default.copyFileSync(dbPath, bak2);
|
|
3288
|
-
} catch (e) {
|
|
3289
|
-
}
|
|
3290
|
-
try {
|
|
3291
|
-
import_node_fs.default.unlinkSync(dbPath);
|
|
3292
|
-
return "Removed successfully";
|
|
3293
|
-
} catch (e) {
|
|
3294
|
-
return "Removed failed";
|
|
3295
|
-
}
|
|
3296
|
-
}
|
|
3297
|
-
const bak = `${dbPath}.bak`;
|
|
3298
|
-
try {
|
|
3299
|
-
import_node_fs.default.copyFileSync(dbPath, bak);
|
|
3300
|
-
} catch (e) {
|
|
3301
|
-
}
|
|
3302
|
-
let src = import_node_fs.default.readFileSync(dbPath, "utf8");
|
|
3303
|
-
const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
3304
|
-
const startRe = new RegExp(
|
|
3305
|
-
`function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
|
|
3306
|
-
"m"
|
|
3307
|
-
);
|
|
3308
|
-
const startMatch = src.match(startRe);
|
|
3309
|
-
if (startMatch) {
|
|
3310
|
-
const startIdx = startMatch.index;
|
|
3311
|
-
const len = src.length;
|
|
3312
|
-
const idxCurly = src.indexOf("{", startIdx);
|
|
3313
|
-
const idxBracket = src.indexOf("[", startIdx);
|
|
3314
|
-
let braceOpen = -1;
|
|
3315
|
-
if (idxCurly === -1) braceOpen = idxBracket;
|
|
3316
|
-
else if (idxBracket === -1) braceOpen = idxCurly;
|
|
3317
|
-
else braceOpen = Math.min(idxCurly, idxBracket);
|
|
3318
|
-
if (braceOpen !== -1) {
|
|
3319
|
-
const openingChar = src[braceOpen];
|
|
3320
|
-
const closingChar = openingChar === "[" ? "]" : "}";
|
|
3321
|
-
let i = braceOpen + 1;
|
|
3322
|
-
let depth = 1;
|
|
3323
|
-
while (i < len && depth > 0) {
|
|
3324
|
-
const ch = src[i];
|
|
3325
|
-
if (ch === openingChar) depth++;
|
|
3326
|
-
else if (ch === closingChar) depth--;
|
|
3327
|
-
i++;
|
|
3328
|
-
}
|
|
3329
|
-
let braceClose = i;
|
|
3330
|
-
let endIdx = braceClose;
|
|
3331
|
-
if (src.slice(braceClose, braceClose + 1) === ";")
|
|
3332
|
-
endIdx = braceClose + 1;
|
|
3333
|
-
const before = src.slice(0, startIdx);
|
|
3334
|
-
const after = src.slice(endIdx);
|
|
3335
|
-
src = before + after;
|
|
3336
|
-
} else {
|
|
3337
|
-
const semi = src.indexOf(";", startIdx);
|
|
3338
|
-
let endIdx = semi !== -1 ? semi + 1 : src.indexOf("\n\n", startIdx);
|
|
3339
|
-
if (endIdx === -1) endIdx = len;
|
|
3340
|
-
src = src.slice(0, startIdx) + src.slice(endIdx);
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
|
-
const exportRe = new RegExp(
|
|
3344
|
-
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
3345
|
-
"g"
|
|
3346
|
-
);
|
|
3347
|
-
src = src.replace(exportRe, "");
|
|
3348
|
-
src = src.replace(/\n{3,}/g, "\n\n");
|
|
3349
|
-
import_node_fs.default.writeFileSync(dbPath, src, "utf8");
|
|
3350
|
-
return `Removed ${fnName} from database ${dbName}.`;
|
|
3351
|
-
}
|
|
3352
|
-
function rename2(oldName, newName) {
|
|
3353
|
-
const DIR = "databases";
|
|
3354
|
-
const basePath = process.cwd();
|
|
3355
|
-
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3356
|
-
const oldPath = import_node_path.default.join(baseDir, `${oldName}.ts`);
|
|
3357
|
-
const newPath = import_node_path.default.join(baseDir, `${newName}.ts`);
|
|
3358
|
-
if (!import_node_fs.default.existsSync(oldPath)) {
|
|
3359
|
-
return `Error: File '${oldName}.ts' does not exist in the database`;
|
|
3360
|
-
}
|
|
3361
|
-
if (import_node_fs.default.existsSync(newPath)) {
|
|
3362
|
-
return `Error: File '${newName}.ts' already exists in the database`;
|
|
3363
|
-
}
|
|
3364
|
-
try {
|
|
3365
|
-
import_node_fs.default.renameSync(oldPath, newPath);
|
|
3366
|
-
return `Successfully renamed '${oldName}.ts' to '${newName}.ts'`;
|
|
3367
|
-
} catch (error) {
|
|
3368
|
-
return `Error renaming file: ${error instanceof Error ? error.message : String(error)}`;
|
|
3369
|
-
}
|
|
3370
|
-
}
|
|
3371
|
-
function save(dbName, code) {
|
|
3372
|
-
const DIR = "databases";
|
|
3373
|
-
const basePath = process.cwd();
|
|
3374
|
-
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3375
|
-
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3376
|
-
let fileContent = typeof code === "function" ? code.toString() : code;
|
|
3377
|
-
import_node_fs.default.writeFileSync(dbPath, fileContent, "utf8");
|
|
3378
|
-
}
|
|
3379
|
-
function update(dbName, fnName, code) {
|
|
3380
|
-
const DIR = "databases";
|
|
3381
|
-
const basePath = process.cwd();
|
|
3382
|
-
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3383
|
-
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3384
|
-
let src;
|
|
3385
|
-
if (!import_node_fs.default.existsSync(dbPath)) {
|
|
3386
|
-
try {
|
|
3387
|
-
import_node_fs.default.writeFileSync(dbPath, "", "utf8");
|
|
3388
|
-
return `Created new database file: ${dbPath}`;
|
|
3389
|
-
} catch (e) {
|
|
3390
|
-
return `Failed to create dbPath file: ${dbPath}`;
|
|
3391
|
-
}
|
|
3392
|
-
}
|
|
3393
|
-
src = import_node_fs.default.readFileSync(dbPath, "utf8");
|
|
3394
|
-
const originalSrc = src;
|
|
3395
|
-
const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
3396
|
-
const startRe = new RegExp(
|
|
3397
|
-
`function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
|
|
3398
|
-
"m"
|
|
3399
|
-
);
|
|
3400
|
-
const startMatch = src.match(startRe);
|
|
3401
|
-
let declKind = null;
|
|
3402
|
-
if (startMatch) {
|
|
3403
|
-
let startIdx = startMatch.index;
|
|
3404
|
-
const snippet = src.slice(startIdx, startIdx + 80);
|
|
3405
|
-
if (/^function\b/.test(snippet)) declKind = "functionDecl";
|
|
3406
|
-
else if (/^class\b/.test(snippet)) declKind = "classDecl";
|
|
3407
|
-
else if (/^\b(?:const|let|var)\b/.test(snippet)) declKind = "varAssign";
|
|
3408
|
-
}
|
|
3409
|
-
let newCode;
|
|
3410
|
-
if (typeof code === "function") {
|
|
3411
|
-
const fnStr = code.toString();
|
|
3412
|
-
if (declKind === "functionDecl") {
|
|
3413
|
-
if (/^function\s+\w+/.test(fnStr)) newCode = fnStr;
|
|
3414
|
-
else
|
|
3415
|
-
newCode = `function ${fnName}${fnStr.replace(
|
|
3416
|
-
/^function\s*\(/,
|
|
3417
|
-
"("
|
|
3418
|
-
)}`;
|
|
3419
|
-
} else if (declKind === "classDecl") {
|
|
3420
|
-
if (/^class\s+\w+/.test(fnStr)) newCode = fnStr;
|
|
3421
|
-
else if (/^class\s*\{/.test(fnStr))
|
|
3422
|
-
newCode = fnStr.replace(/^class\s*\{/, `class ${fnName} {`);
|
|
3423
|
-
else newCode = `const ${fnName} = ${fnStr};`;
|
|
3424
|
-
} else {
|
|
3425
|
-
newCode = `const ${fnName} = ${fnStr};`;
|
|
3426
|
-
}
|
|
3427
|
-
} else {
|
|
3428
|
-
newCode = `const ${fnName} = ${valueToCode(code, 0)};`;
|
|
3429
|
-
}
|
|
3430
|
-
if (startMatch) {
|
|
3431
|
-
const startIdx = startMatch.index;
|
|
3432
|
-
const idxCurly = src.indexOf("{", startIdx);
|
|
3433
|
-
const idxBracket = src.indexOf("[", startIdx);
|
|
3434
|
-
let braceOpen = -1;
|
|
3435
|
-
if (idxCurly === -1) braceOpen = idxBracket;
|
|
3436
|
-
else if (idxBracket === -1) braceOpen = idxCurly;
|
|
3437
|
-
else braceOpen = Math.min(idxCurly, idxBracket);
|
|
3438
|
-
if (braceOpen === -1) {
|
|
3439
|
-
const exportRe = new RegExp(
|
|
3440
|
-
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
3441
|
-
"m"
|
|
3442
|
-
);
|
|
3443
|
-
if (exportRe.test(src)) {
|
|
3444
|
-
src = src.replace(
|
|
3445
|
-
exportRe,
|
|
3446
|
-
`${newCode}
|
|
3447
|
-
|
|
3448
|
-
export const ${fnName}: any = ${fnName};`
|
|
3449
|
-
);
|
|
3450
|
-
} else {
|
|
3451
|
-
src = src + `
|
|
3452
|
-
|
|
3453
|
-
${newCode}
|
|
3454
|
-
|
|
3455
|
-
export const ${fnName}: any = ${fnName};`;
|
|
3456
|
-
}
|
|
3457
|
-
} else {
|
|
3458
|
-
const openingChar = src[braceOpen];
|
|
3459
|
-
const closingChar = openingChar === "[" ? "]" : "}";
|
|
3460
|
-
let i = braceOpen + 1;
|
|
3461
|
-
let depth = 1;
|
|
3462
|
-
const len = src.length;
|
|
3463
|
-
while (i < len && depth > 0) {
|
|
3464
|
-
const ch = src[i];
|
|
3465
|
-
if (ch === openingChar) depth++;
|
|
3466
|
-
else if (ch === closingChar) depth--;
|
|
3467
|
-
i++;
|
|
3468
|
-
}
|
|
3469
|
-
let braceClose = i;
|
|
3470
|
-
let endIdx = braceClose;
|
|
3471
|
-
if (src.slice(braceClose, braceClose + 1) === ";")
|
|
3472
|
-
endIdx = braceClose + 1;
|
|
3473
|
-
const before = src.slice(0, startIdx);
|
|
3474
|
-
const after = src.slice(endIdx);
|
|
3475
|
-
src = before + newCode + after;
|
|
3476
|
-
}
|
|
3477
|
-
} else {
|
|
3478
|
-
const exportRe = new RegExp(
|
|
3479
|
-
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
3480
|
-
"m"
|
|
3481
|
-
);
|
|
3482
|
-
if (exportRe.test(src)) {
|
|
3483
|
-
src = src.replace(
|
|
3484
|
-
exportRe,
|
|
3485
|
-
`${newCode}
|
|
3486
|
-
|
|
3487
|
-
export const ${fnName}: any = ${fnName};`
|
|
3488
|
-
);
|
|
3489
|
-
} else {
|
|
3490
|
-
src = src + `
|
|
3491
|
-
|
|
3492
|
-
${newCode}
|
|
3493
|
-
|
|
3494
|
-
export const ${fnName}: any = ${fnName};`;
|
|
3495
|
-
}
|
|
3496
|
-
}
|
|
3497
|
-
import_node_fs.default.writeFileSync(dbPath, src, "utf8");
|
|
3498
|
-
if (src === originalSrc) {
|
|
3499
|
-
return `Saved ${fnName} to database ${dbName}.`;
|
|
3500
|
-
} else {
|
|
3501
|
-
return `Updated ${dbName} with ${fnName}.`;
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
function valueToCode(val, depth = 0) {
|
|
3505
|
-
const indentUnit = " ";
|
|
3506
|
-
const indent = indentUnit.repeat(depth);
|
|
3507
|
-
const indentInner = indentUnit.repeat(depth + 1);
|
|
3508
|
-
if (val === null) return "null";
|
|
3509
|
-
const t = typeof val;
|
|
3510
|
-
if (t === "string") return JSON.stringify(val);
|
|
3511
|
-
if (t === "number" || t === "boolean") return String(val);
|
|
3512
|
-
if (t === "function") return val.toString();
|
|
3513
|
-
if (Array.isArray(val)) {
|
|
3514
|
-
if (val.length === 0) return "[]";
|
|
3515
|
-
const items = val.map((v) => valueToCode(v, depth + 1));
|
|
3516
|
-
return "[\n" + items.map((it) => indentInner + it).join(",\n") + "\n" + indent + "]";
|
|
3517
|
-
}
|
|
3518
|
-
if (t === "object") {
|
|
3519
|
-
const keys = Object.keys(val);
|
|
3520
|
-
if (keys.length === 0) return "{}";
|
|
3521
|
-
const entries = keys.map((k) => {
|
|
3522
|
-
const keyPart = isIdentifier(k) ? k : JSON.stringify(k);
|
|
3523
|
-
const v = valueToCode(val[k], depth + 1);
|
|
3524
|
-
return indentInner + keyPart + ": " + v;
|
|
3525
|
-
});
|
|
3526
|
-
return "{\n" + entries.join(",\n") + "\n" + indent + "}";
|
|
3527
|
-
}
|
|
3528
|
-
return String(val);
|
|
3529
|
-
}
|
|
3530
|
-
function isIdentifier(key) {
|
|
3531
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
|
|
3532
|
-
}
|
|
3533
|
-
var dbConsole = {
|
|
3534
|
-
create,
|
|
3535
|
-
read,
|
|
3536
|
-
remove,
|
|
3537
|
-
rename: rename2,
|
|
3538
|
-
save,
|
|
3539
|
-
update,
|
|
3540
|
-
...console
|
|
3541
|
-
};
|
|
3542
|
-
|
|
3543
3053
|
// src/server.ts
|
|
3544
|
-
var ServerDatabase = class {
|
|
3545
|
-
constructor() {
|
|
3546
|
-
this._db = null;
|
|
3547
|
-
}
|
|
3548
|
-
async initialize(config) {
|
|
3549
|
-
this._db = new Database(config);
|
|
3550
|
-
}
|
|
3551
|
-
database() {
|
|
3552
|
-
return this._db;
|
|
3553
|
-
}
|
|
3554
|
-
};
|
|
3555
|
-
var serverDatabase = new ServerDatabase();
|
|
3556
|
-
var database = serverDatabase.database;
|
|
3557
3054
|
var json = (res, data, status = 200) => (res.writeHead(status, { "Content-Type": "application/json" }), res.end(JSON.stringify(data)));
|
|
3558
3055
|
var sendError = (res, code, msg) => {
|
|
3559
3056
|
res.writeHead(code, { "Content-Type": "text/plain" });
|
|
@@ -3823,21 +3320,21 @@ function resolveExport(exportValue) {
|
|
|
3823
3320
|
}
|
|
3824
3321
|
return null;
|
|
3825
3322
|
}
|
|
3826
|
-
function rewritePath(
|
|
3827
|
-
if (!pathRewrite) return
|
|
3323
|
+
function rewritePath(path, pathRewrite) {
|
|
3324
|
+
if (!pathRewrite) return path;
|
|
3828
3325
|
for (const [from, to] of Object.entries(pathRewrite)) {
|
|
3829
3326
|
const regex = new RegExp(from);
|
|
3830
|
-
if (regex.test(
|
|
3831
|
-
return
|
|
3327
|
+
if (regex.test(path)) {
|
|
3328
|
+
return path.replace(regex, to);
|
|
3832
3329
|
}
|
|
3833
3330
|
}
|
|
3834
|
-
return
|
|
3331
|
+
return path;
|
|
3835
3332
|
}
|
|
3836
3333
|
function createProxyHandler(proxyConfigs) {
|
|
3837
3334
|
return async (req, res) => {
|
|
3838
3335
|
const url = req.url || "/";
|
|
3839
|
-
const
|
|
3840
|
-
const proxy = proxyConfigs.find((p) =>
|
|
3336
|
+
const path = url.split("?")[0];
|
|
3337
|
+
const proxy = proxyConfigs.find((p) => path.startsWith(p.context));
|
|
3841
3338
|
if (!proxy) return false;
|
|
3842
3339
|
const { target, changeOrigin, pathRewrite, headers } = proxy;
|
|
3843
3340
|
try {
|
|
@@ -3889,7 +3386,7 @@ function createProxyHandler(proxyConfigs) {
|
|
|
3889
3386
|
req.on("end", () => proxyReq.end());
|
|
3890
3387
|
return true;
|
|
3891
3388
|
} catch (error) {
|
|
3892
|
-
console.error("[Proxy] Invalid proxy configuration for %s:",
|
|
3389
|
+
console.error("[Proxy] Invalid proxy configuration for %s:", path, error);
|
|
3893
3390
|
return false;
|
|
3894
3391
|
}
|
|
3895
3392
|
};
|
|
@@ -4010,9 +3507,6 @@ function createDevServer(options) {
|
|
|
4010
3507
|
if (config.mode === "dev") {
|
|
4011
3508
|
clearImportMapCache();
|
|
4012
3509
|
}
|
|
4013
|
-
serverDatabase.initialize(config.database ? config.database : {
|
|
4014
|
-
dir: resolve(process.cwd(), "databases")
|
|
4015
|
-
});
|
|
4016
3510
|
const clientsToNormalize = config.clients?.length ? config.clients : config.root ? [{ root: config.root, basePath: config.basePath || "", index: config.index, ssr: config.ssr, api: config.api, proxy: config.proxy, mode: config.mode }] : null;
|
|
4017
3511
|
if (!clientsToNormalize) throw new Error('DevServerOptions must include either "clients" array or "root" directory');
|
|
4018
3512
|
const normalizedClients = clientsToNormalize.map((client) => {
|
|
@@ -4304,8 +3798,8 @@ export default css;
|
|
|
4304
3798
|
});
|
|
4305
3799
|
transpiled = transpiler.transformSync(content.toString());
|
|
4306
3800
|
} else {
|
|
4307
|
-
const { build:
|
|
4308
|
-
const result = await
|
|
3801
|
+
const { build: build2 } = await import("esbuild");
|
|
3802
|
+
const result = await build2({
|
|
4309
3803
|
stdin: {
|
|
4310
3804
|
contents: content.toString(),
|
|
4311
3805
|
loader: ext === ".tsx" ? "tsx" : "ts",
|
|
@@ -4322,19 +3816,19 @@ export default css;
|
|
|
4322
3816
|
}
|
|
4323
3817
|
transpiled = transpiled.replace(
|
|
4324
3818
|
/from\s+["']([^"']+)\.ts(x?)["']/g,
|
|
4325
|
-
(_,
|
|
3819
|
+
(_, path, tsx) => `from "${path}.js${tsx}"`
|
|
4326
3820
|
);
|
|
4327
3821
|
transpiled = transpiled.replace(
|
|
4328
3822
|
/import\s+["']([^"']+)\.ts(x?)["']/g,
|
|
4329
|
-
(_,
|
|
3823
|
+
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
4330
3824
|
);
|
|
4331
3825
|
transpiled = transpiled.replace(
|
|
4332
3826
|
/import\s+["']([^"']+\.css)["']/g,
|
|
4333
|
-
(_,
|
|
3827
|
+
(_, path) => `import "${path}?inline"`
|
|
4334
3828
|
);
|
|
4335
3829
|
transpiled = transpiled.replace(
|
|
4336
3830
|
/from\s+["']([^"']+\.css)["']/g,
|
|
4337
|
-
(_,
|
|
3831
|
+
(_, path) => `from "${path}?inline"`
|
|
4338
3832
|
);
|
|
4339
3833
|
content = Buffer.from(transpiled);
|
|
4340
3834
|
mimeType = "application/javascript";
|
|
@@ -4496,17 +3990,17 @@ ${elitImportMap}` : elitImportMap;
|
|
|
4496
3990
|
(client) => config.watch.map((pattern) => join(client.root, pattern))
|
|
4497
3991
|
);
|
|
4498
3992
|
const watcher = watch(watchPaths, {
|
|
4499
|
-
ignored: (
|
|
3993
|
+
ignored: (path) => config.ignore.some((pattern) => path.includes(pattern.replace("/**", "").replace("**/", ""))),
|
|
4500
3994
|
ignoreInitial: true,
|
|
4501
3995
|
persistent: true
|
|
4502
3996
|
});
|
|
4503
|
-
watcher.on("change", (
|
|
4504
|
-
if (config.logging) console.log(`[HMR] File changed: ${
|
|
4505
|
-
const message = JSON.stringify({ type: "update", path
|
|
3997
|
+
watcher.on("change", (path) => {
|
|
3998
|
+
if (config.logging) console.log(`[HMR] File changed: ${path}`);
|
|
3999
|
+
const message = JSON.stringify({ type: "update", path, timestamp: Date.now() });
|
|
4506
4000
|
wsClients.forEach((client) => client.readyState === 1 /* OPEN */ && client.send(message));
|
|
4507
4001
|
});
|
|
4508
|
-
watcher.on("add", (
|
|
4509
|
-
watcher.on("unlink", (
|
|
4002
|
+
watcher.on("add", (path) => config.logging && console.log(`[HMR] File added: ${path}`));
|
|
4003
|
+
watcher.on("unlink", (path) => config.logging && console.log(`[HMR] File removed: ${path}`));
|
|
4510
4004
|
server.setMaxListeners(20);
|
|
4511
4005
|
server.listen(config.port, config.host, () => {
|
|
4512
4006
|
if (config.logging) {
|
|
@@ -4620,7 +4114,7 @@ var defaultOptions2 = {
|
|
|
4620
4114
|
logging: true,
|
|
4621
4115
|
external: []
|
|
4622
4116
|
};
|
|
4623
|
-
async function
|
|
4117
|
+
async function build(options) {
|
|
4624
4118
|
const config = { ...defaultOptions2, ...options };
|
|
4625
4119
|
const startTime = Date.now();
|
|
4626
4120
|
if (!config.entry) {
|
|
@@ -4641,14 +4135,14 @@ async function build2(options) {
|
|
|
4641
4135
|
}
|
|
4642
4136
|
const browserOnlyPlugin = {
|
|
4643
4137
|
name: "browser-only",
|
|
4644
|
-
setup(
|
|
4645
|
-
|
|
4138
|
+
setup(build2) {
|
|
4139
|
+
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)$/ }, () => {
|
|
4646
4140
|
return { path: "node-builtin", external: true, sideEffects: false };
|
|
4647
4141
|
});
|
|
4648
|
-
|
|
4142
|
+
build2.onResolve({ filter: /^(chokidar|esbuild|mime-types|open|ws|fs\/promises)$/ }, () => {
|
|
4649
4143
|
return { path: "server-dep", external: true, sideEffects: false };
|
|
4650
4144
|
});
|
|
4651
|
-
|
|
4145
|
+
build2.onLoad({ filter: /[\\/](server|config|cli)\.ts$/ }, () => {
|
|
4652
4146
|
return {
|
|
4653
4147
|
contents: "export {}",
|
|
4654
4148
|
loader: "js"
|
|
@@ -4676,7 +4170,7 @@ async function build2(options) {
|
|
|
4676
4170
|
let buildTime;
|
|
4677
4171
|
let size;
|
|
4678
4172
|
if (runtime === "node") {
|
|
4679
|
-
const { build:
|
|
4173
|
+
const { build: esbuild } = await import("esbuild");
|
|
4680
4174
|
const baseOptions = {
|
|
4681
4175
|
entryPoints: [entryPath],
|
|
4682
4176
|
bundle: true,
|
|
@@ -4703,7 +4197,7 @@ async function build2(options) {
|
|
|
4703
4197
|
if (config.resolve?.alias) {
|
|
4704
4198
|
esbuildOptions.resolve = { alias: config.resolve.alias };
|
|
4705
4199
|
}
|
|
4706
|
-
result = await
|
|
4200
|
+
result = await esbuild(esbuildOptions);
|
|
4707
4201
|
({ buildTime, size } = calculateBuildMetrics(startTime, outputPath));
|
|
4708
4202
|
} else if (runtime === "bun") {
|
|
4709
4203
|
result = await Bun.build({
|
|
@@ -4831,7 +4325,7 @@ function setupShutdownHandlers(closeFunc) {
|
|
|
4831
4325
|
}
|
|
4832
4326
|
async function executeBuild(options) {
|
|
4833
4327
|
try {
|
|
4834
|
-
await
|
|
4328
|
+
await build(options);
|
|
4835
4329
|
} catch (error) {
|
|
4836
4330
|
process.exit(1);
|
|
4837
4331
|
}
|
|
@@ -4924,7 +4418,7 @@ async function runBuild(args) {
|
|
|
4924
4418
|
validateEntry(buildConfig.entry, i);
|
|
4925
4419
|
console.log(`[${i + 1}/${builds.length}] Building ${buildConfig.entry}...`);
|
|
4926
4420
|
try {
|
|
4927
|
-
await
|
|
4421
|
+
await build(buildConfig);
|
|
4928
4422
|
} catch (error) {
|
|
4929
4423
|
console.error(`Build #${i + 1} failed`);
|
|
4930
4424
|
process.exit(1);
|