@moostjs/vite 0.6.37 → 0.6.39
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/index.cjs +25 -45
- package/dist/index.mjs +25 -45
- package/dist/prod-server.cjs +16 -6
- package/dist/prod-server.d.ts +10 -2
- package/dist/prod-server.mjs +16 -6
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -340,7 +340,7 @@ function _define_property(obj, key, value) {
|
|
|
340
340
|
/**
|
|
341
341
|
* Clean up Moost’s global containers and optionally remove specific instances from the registry.
|
|
342
342
|
*
|
|
343
|
-
* Every instance actually removed from
|
|
343
|
+
* Every instance actually removed from the registry is **disposed** before the
|
|
344
344
|
* caches are dropped: its `@MoostDispose` hooks (or `Symbol.asyncDispose` /
|
|
345
345
|
* `Symbol.dispose`) are awaited, so a singleton owning a connection, consumer,
|
|
346
346
|
* timer or file handle releases it instead of leaking one copy per reload. An
|
|
@@ -349,46 +349,25 @@ function _define_property(obj, key, value) {
|
|
|
349
349
|
*
|
|
350
350
|
* @param {Set<string>} [cleanupInstances] A set of module IDs to remove from the registry.
|
|
351
351
|
* @returns the instances that were ejected (and therefore disposed)
|
|
352
|
-
*/ async function moostRestartCleanup(
|
|
352
|
+
*/ async function moostRestartCleanup(onEject, cleanupInstances) {
|
|
353
353
|
const logger = getLogger();
|
|
354
354
|
const infact = (0, moost.getMoostInfact)();
|
|
355
|
-
const { registry
|
|
356
|
-
const registries = [registry, ...Object.values(scopes)];
|
|
355
|
+
const { registry } = infact;
|
|
357
356
|
infact._cleanup();
|
|
358
357
|
const mate = (0, moost.getMoostMate)();
|
|
359
|
-
/** Instances removed from
|
|
358
|
+
/** Instances removed from the registry by this run — disposed below, before the caches drop. */ const ejected = [];
|
|
360
359
|
if (cleanupInstances) {
|
|
361
|
-
for (const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
ejected.push(instance);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
for (const key of Object.getOwnPropertySymbols(reg)) {
|
|
372
|
-
const instance = reg[key];
|
|
373
|
-
scanParams(instance, (type) => {
|
|
374
|
-
if ((type === moost.Moost || type instanceof moost.Moost || type.prototype instanceof moost.Moost) && (!onEject || onEject(instance, type))) {
|
|
375
|
-
delete reg[key];
|
|
376
|
-
ejected.push(instance);
|
|
377
|
-
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "Moost")`);
|
|
378
|
-
return true;
|
|
379
|
-
}
|
|
380
|
-
for (const adapter of adapters) if (adapter.compare(type) && (!onEject || onEject(instance, type))) {
|
|
381
|
-
delete reg[key];
|
|
382
|
-
ejected.push(instance);
|
|
383
|
-
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "${adapter.constructor.name}")`);
|
|
384
|
-
return true;
|
|
385
|
-
}
|
|
386
|
-
});
|
|
360
|
+
for (const key of Object.getOwnPropertySymbols(registry)) {
|
|
361
|
+
const instance = registry[key];
|
|
362
|
+
const viteId = mate.read(instance)?.__vite_id;
|
|
363
|
+
if (viteId && cleanupInstances.has(viteId)) {
|
|
364
|
+
logger.debug(`🔃 Replacing "${constructorName(instance)}"`);
|
|
365
|
+
delete registry[key];
|
|
366
|
+
ejected.push(instance);
|
|
387
367
|
}
|
|
388
|
-
clearDependantRegistry(reg, onEject, ejected);
|
|
389
368
|
}
|
|
369
|
+
clearDependantRegistry(registry, onEject, ejected);
|
|
390
370
|
infact.registry = registry;
|
|
391
|
-
infact.scopes = scopes;
|
|
392
371
|
}
|
|
393
372
|
await disposeEjected(ejected);
|
|
394
373
|
(0, moost.getMoostMate)()._cleanup();
|
|
@@ -405,19 +384,21 @@ function _define_property(obj, key, value) {
|
|
|
405
384
|
for (const instance of disposed) logger.debug(`♻️ Disposed "${constructorName(instance)}"`);
|
|
406
385
|
for (const e of errors) logger.warn(`⚠️ Dispose hook "${constructorName(e.instance)}.${String(e.method)}" failed — the reload continues`);
|
|
407
386
|
}
|
|
408
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Ejects, to a fixed point, every instance whose constructor dependency is not
|
|
389
|
+
* in the registry: an instance ejected in one pass ejects its consumers in the
|
|
390
|
+
* next (Moost → Database → Repository → Worker loses the whole chain). An
|
|
391
|
+
* `onEject` veto keeps the instance present, and with it its consumers.
|
|
392
|
+
*/ function clearDependantRegistry(registry, onEject, ejected) {
|
|
409
393
|
const logger = getLogger();
|
|
410
|
-
const objSet = /* @__PURE__ */ new Set();
|
|
411
394
|
let somethingIsDeleted = true;
|
|
412
395
|
while (somethingIsDeleted) {
|
|
413
396
|
somethingIsDeleted = false;
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
for (const key of Object.getOwnPropertySymbols(registry)) {
|
|
397
|
+
const keys = Object.getOwnPropertySymbols(registry);
|
|
398
|
+
const present = new Set(keys.map((key) => registry[key].constructor));
|
|
399
|
+
for (const key of keys) {
|
|
419
400
|
const instance = registry[key];
|
|
420
|
-
if (checkAndEject(instance,
|
|
401
|
+
if (checkAndEject(instance, present, onEject, registry, key, logger)) {
|
|
421
402
|
ejected.push(instance);
|
|
422
403
|
somethingIsDeleted = true;
|
|
423
404
|
}
|
|
@@ -429,7 +410,7 @@ function checkAndEject(instance, objSet, onEject, registry, key, logger) {
|
|
|
429
410
|
scanParams(instance, (type) => {
|
|
430
411
|
if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
|
|
431
412
|
delete registry[key];
|
|
432
|
-
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}"
|
|
413
|
+
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}", rebuilt by this reload)`);
|
|
433
414
|
ejected = true;
|
|
434
415
|
return true;
|
|
435
416
|
}
|
|
@@ -909,7 +890,6 @@ function moostVite(options) {
|
|
|
909
890
|
ssrEntry: options.ssrEntry,
|
|
910
891
|
serverEntry: options.serverEntry,
|
|
911
892
|
prefix: prefixes,
|
|
912
|
-
port: options.port,
|
|
913
893
|
ssrOutlet: options.ssrOutlet,
|
|
914
894
|
ssrState: options.ssrState,
|
|
915
895
|
ssrHead: options.ssrHead,
|
|
@@ -977,7 +957,7 @@ function moostVite(options) {
|
|
|
977
957
|
beginBoot();
|
|
978
958
|
const cleanupInstances = pendingCleanup ?? void 0;
|
|
979
959
|
pendingCleanup = null;
|
|
980
|
-
await moostRestartCleanup(
|
|
960
|
+
await moostRestartCleanup(options.onEject, cleanupInstances);
|
|
981
961
|
for (const adapter of adapters) if (adapter.detected) await adapter.init();
|
|
982
962
|
const entryModule = await getEntryModule(server.environments.ssr.moduleGraph);
|
|
983
963
|
if (entryModule?.transformResult) server.environments.ssr.moduleGraph.invalidateModule(entryModule);
|
|
@@ -999,7 +979,7 @@ function moostVite(options) {
|
|
|
999
979
|
}
|
|
1000
980
|
};
|
|
1001
981
|
for (const adapter of adapters) adapter.ssrLoadModule = ssrImport;
|
|
1002
|
-
await moostRestartCleanup(
|
|
982
|
+
await moostRestartCleanup(options.onEject);
|
|
1003
983
|
await ssrImport(options.entry);
|
|
1004
984
|
await settleBootInit();
|
|
1005
985
|
server.middlewares.use(async (req, res, next) => {
|
package/dist/index.mjs
CHANGED
|
@@ -311,7 +311,7 @@ function _define_property(obj, key, value) {
|
|
|
311
311
|
/**
|
|
312
312
|
* Clean up Moost’s global containers and optionally remove specific instances from the registry.
|
|
313
313
|
*
|
|
314
|
-
* Every instance actually removed from
|
|
314
|
+
* Every instance actually removed from the registry is **disposed** before the
|
|
315
315
|
* caches are dropped: its `@MoostDispose` hooks (or `Symbol.asyncDispose` /
|
|
316
316
|
* `Symbol.dispose`) are awaited, so a singleton owning a connection, consumer,
|
|
317
317
|
* timer or file handle releases it instead of leaking one copy per reload. An
|
|
@@ -320,46 +320,25 @@ function _define_property(obj, key, value) {
|
|
|
320
320
|
*
|
|
321
321
|
* @param {Set<string>} [cleanupInstances] A set of module IDs to remove from the registry.
|
|
322
322
|
* @returns the instances that were ejected (and therefore disposed)
|
|
323
|
-
*/ async function moostRestartCleanup(
|
|
323
|
+
*/ async function moostRestartCleanup(onEject, cleanupInstances) {
|
|
324
324
|
const logger = getLogger();
|
|
325
325
|
const infact = getMoostInfact();
|
|
326
|
-
const { registry
|
|
327
|
-
const registries = [registry, ...Object.values(scopes)];
|
|
326
|
+
const { registry } = infact;
|
|
328
327
|
infact._cleanup();
|
|
329
328
|
const mate = getMoostMate();
|
|
330
|
-
/** Instances removed from
|
|
329
|
+
/** Instances removed from the registry by this run — disposed below, before the caches drop. */ const ejected = [];
|
|
331
330
|
if (cleanupInstances) {
|
|
332
|
-
for (const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
ejected.push(instance);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
for (const key of Object.getOwnPropertySymbols(reg)) {
|
|
343
|
-
const instance = reg[key];
|
|
344
|
-
scanParams(instance, (type) => {
|
|
345
|
-
if ((type === Moost || type instanceof Moost || type.prototype instanceof Moost) && (!onEject || onEject(instance, type))) {
|
|
346
|
-
delete reg[key];
|
|
347
|
-
ejected.push(instance);
|
|
348
|
-
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "Moost")`);
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
for (const adapter of adapters) if (adapter.compare(type) && (!onEject || onEject(instance, type))) {
|
|
352
|
-
delete reg[key];
|
|
353
|
-
ejected.push(instance);
|
|
354
|
-
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "${adapter.constructor.name}")`);
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
});
|
|
331
|
+
for (const key of Object.getOwnPropertySymbols(registry)) {
|
|
332
|
+
const instance = registry[key];
|
|
333
|
+
const viteId = mate.read(instance)?.__vite_id;
|
|
334
|
+
if (viteId && cleanupInstances.has(viteId)) {
|
|
335
|
+
logger.debug(`🔃 Replacing "${constructorName(instance)}"`);
|
|
336
|
+
delete registry[key];
|
|
337
|
+
ejected.push(instance);
|
|
358
338
|
}
|
|
359
|
-
clearDependantRegistry(reg, onEject, ejected);
|
|
360
339
|
}
|
|
340
|
+
clearDependantRegistry(registry, onEject, ejected);
|
|
361
341
|
infact.registry = registry;
|
|
362
|
-
infact.scopes = scopes;
|
|
363
342
|
}
|
|
364
343
|
await disposeEjected(ejected);
|
|
365
344
|
getMoostMate()._cleanup();
|
|
@@ -376,19 +355,21 @@ function _define_property(obj, key, value) {
|
|
|
376
355
|
for (const instance of disposed) logger.debug(`♻️ Disposed "${constructorName(instance)}"`);
|
|
377
356
|
for (const e of errors) logger.warn(`⚠️ Dispose hook "${constructorName(e.instance)}.${String(e.method)}" failed — the reload continues`);
|
|
378
357
|
}
|
|
379
|
-
|
|
358
|
+
/**
|
|
359
|
+
* Ejects, to a fixed point, every instance whose constructor dependency is not
|
|
360
|
+
* in the registry: an instance ejected in one pass ejects its consumers in the
|
|
361
|
+
* next (Moost → Database → Repository → Worker loses the whole chain). An
|
|
362
|
+
* `onEject` veto keeps the instance present, and with it its consumers.
|
|
363
|
+
*/ function clearDependantRegistry(registry, onEject, ejected) {
|
|
380
364
|
const logger = getLogger();
|
|
381
|
-
const objSet = /* @__PURE__ */ new Set();
|
|
382
365
|
let somethingIsDeleted = true;
|
|
383
366
|
while (somethingIsDeleted) {
|
|
384
367
|
somethingIsDeleted = false;
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
for (const key of Object.getOwnPropertySymbols(registry)) {
|
|
368
|
+
const keys = Object.getOwnPropertySymbols(registry);
|
|
369
|
+
const present = new Set(keys.map((key) => registry[key].constructor));
|
|
370
|
+
for (const key of keys) {
|
|
390
371
|
const instance = registry[key];
|
|
391
|
-
if (checkAndEject(instance,
|
|
372
|
+
if (checkAndEject(instance, present, onEject, registry, key, logger)) {
|
|
392
373
|
ejected.push(instance);
|
|
393
374
|
somethingIsDeleted = true;
|
|
394
375
|
}
|
|
@@ -400,7 +381,7 @@ function checkAndEject(instance, objSet, onEject, registry, key, logger) {
|
|
|
400
381
|
scanParams(instance, (type) => {
|
|
401
382
|
if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
|
|
402
383
|
delete registry[key];
|
|
403
|
-
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}"
|
|
384
|
+
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}", rebuilt by this reload)`);
|
|
404
385
|
ejected = true;
|
|
405
386
|
return true;
|
|
406
387
|
}
|
|
@@ -878,7 +859,6 @@ function moostVite(options) {
|
|
|
878
859
|
ssrEntry: options.ssrEntry,
|
|
879
860
|
serverEntry: options.serverEntry,
|
|
880
861
|
prefix: prefixes,
|
|
881
|
-
port: options.port,
|
|
882
862
|
ssrOutlet: options.ssrOutlet,
|
|
883
863
|
ssrState: options.ssrState,
|
|
884
864
|
ssrHead: options.ssrHead,
|
|
@@ -946,7 +926,7 @@ function moostVite(options) {
|
|
|
946
926
|
beginBoot();
|
|
947
927
|
const cleanupInstances = pendingCleanup ?? void 0;
|
|
948
928
|
pendingCleanup = null;
|
|
949
|
-
await moostRestartCleanup(
|
|
929
|
+
await moostRestartCleanup(options.onEject, cleanupInstances);
|
|
950
930
|
for (const adapter of adapters) if (adapter.detected) await adapter.init();
|
|
951
931
|
const entryModule = await getEntryModule(server.environments.ssr.moduleGraph);
|
|
952
932
|
if (entryModule?.transformResult) server.environments.ssr.moduleGraph.invalidateModule(entryModule);
|
|
@@ -968,7 +948,7 @@ function moostVite(options) {
|
|
|
968
948
|
}
|
|
969
949
|
};
|
|
970
950
|
for (const adapter of adapters) adapter.ssrLoadModule = ssrImport;
|
|
971
|
-
await moostRestartCleanup(
|
|
951
|
+
await moostRestartCleanup(options.onEject);
|
|
972
952
|
await ssrImport(options.entry);
|
|
973
953
|
await settleBootInit();
|
|
974
954
|
server.middlewares.use(async (req, res, next) => {
|
package/dist/prod-server.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let node_events = require("node:events");
|
|
2
3
|
let moost = require("moost");
|
|
3
4
|
|
|
4
5
|
//#region packages/vite/src/utils.ts
|
|
@@ -81,6 +82,11 @@ const logger = (0, moost.createLogger)({ level: 99 }).createTopic("\x1B[2m\x1B[3
|
|
|
81
82
|
|
|
82
83
|
//#endregion
|
|
83
84
|
//#region packages/vite/src/prod-server.ts
|
|
85
|
+
/** URL of the address the server actually bound (wildcard binds print as localhost). */ function serverUrl(server) {
|
|
86
|
+
const addr = server.address();
|
|
87
|
+
if (!addr || typeof addr === "string") return String(addr);
|
|
88
|
+
return `http://${addr.address === "::" || addr.address === "0.0.0.0" ? "localhost" : addr.family === "IPv6" ? `[${addr.address}]` : addr.address}:${addr.port}`;
|
|
89
|
+
}
|
|
84
90
|
function stripUndefined(obj) {
|
|
85
91
|
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
|
|
86
92
|
}
|
|
@@ -135,11 +141,13 @@ async function createSSRServer(options) {
|
|
|
135
141
|
use(mw) {
|
|
136
142
|
userMiddlewares.push(mw);
|
|
137
143
|
},
|
|
138
|
-
async listen(
|
|
144
|
+
async listen(port, host) {
|
|
145
|
+
if ((port ?? host ?? opts.port ?? opts.host) !== void 0) console.warn("[moost-vite] port/host passed to createSSRServer() or listen() are ignored in dev — set server.port / server.host in vite.config instead.");
|
|
139
146
|
for (const mw of userMiddlewares) vite.middlewares.use(mw);
|
|
140
147
|
if (ssrFallback) vite.middlewares.use(ssrFallback);
|
|
141
148
|
await vite.listen();
|
|
142
149
|
vite.printUrls();
|
|
150
|
+
return vite.httpServer;
|
|
143
151
|
}
|
|
144
152
|
};
|
|
145
153
|
}
|
|
@@ -153,6 +161,7 @@ async function createSSRServer(options) {
|
|
|
153
161
|
const prefixes = normalizePrefixes(opts.prefix ?? __MOOST_PREFIX__);
|
|
154
162
|
const ssrForwarding = opts.ssrFetchForwarding ?? __MOOST_SSR_FORWARDING__ ?? true;
|
|
155
163
|
const defaultPort = opts.port || Number(process.env.PORT) || 3e3;
|
|
164
|
+
const defaultHost = opts.host ?? process.env.HOST;
|
|
156
165
|
const template = await fs.readFile(path.resolve(clientDir, "index.html"), "utf8");
|
|
157
166
|
let render = null;
|
|
158
167
|
if (__MOOST_SSR_ENTRY__ !== void 0 && !!__MOOST_SSR_ENTRY__) render = (await import(
|
|
@@ -228,9 +237,8 @@ async function createSSRServer(options) {
|
|
|
228
237
|
use(mw) {
|
|
229
238
|
userMiddlewares.push(mw);
|
|
230
239
|
},
|
|
231
|
-
async listen(port) {
|
|
232
|
-
const
|
|
233
|
-
createHttpServer((req, res) => {
|
|
240
|
+
async listen(port, host) {
|
|
241
|
+
const server = createHttpServer((req, res) => {
|
|
234
242
|
const url = req.url || "/";
|
|
235
243
|
let i = 0;
|
|
236
244
|
const runNext = () => {
|
|
@@ -245,9 +253,11 @@ async function createSSRServer(options) {
|
|
|
245
253
|
serveStatic(req, res);
|
|
246
254
|
};
|
|
247
255
|
runNext();
|
|
248
|
-
}).listen(p, () => {
|
|
249
|
-
console.log(`Server running at http://localhost:${p}`);
|
|
250
256
|
});
|
|
257
|
+
server.listen(port || defaultPort, host || defaultHost);
|
|
258
|
+
await (0, node_events.once)(server, "listening");
|
|
259
|
+
console.log(`Server running at ${serverUrl(server)}`);
|
|
260
|
+
return server;
|
|
251
261
|
}
|
|
252
262
|
};
|
|
253
263
|
}
|
package/dist/prod-server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { Server } from 'node:net';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The value an SSR `render(url)` function may return. Only `html` is required;
|
|
@@ -54,6 +55,8 @@ interface TSSRServerOptions {
|
|
|
54
55
|
prefix?: string | string[];
|
|
55
56
|
/** Override: port number (default: process.env.PORT || 3000) */
|
|
56
57
|
port?: number;
|
|
58
|
+
/** Override: bind address, e.g. '127.0.0.1' (default: process.env.HOST, else all interfaces) */
|
|
59
|
+
host?: string;
|
|
57
60
|
/** Override: client build directory (default: 'dist/client') */
|
|
58
61
|
clientDir?: string;
|
|
59
62
|
/** Override: HTML placeholder for SSR content */
|
|
@@ -75,8 +78,13 @@ interface TSSRServerOptions {
|
|
|
75
78
|
interface TSSRServer {
|
|
76
79
|
/** Add Connect-compatible middleware (runs in both dev and prod) */
|
|
77
80
|
use(middleware: TMiddleware): void;
|
|
78
|
-
/**
|
|
79
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Start the server; resolves with the bound server (for `address()` / `close()`)
|
|
83
|
+
* and rejects on a bind error (`EADDRINUSE`, `EACCES`, bad host).
|
|
84
|
+
* `port`/`host` and the matching options apply in production only — in dev,
|
|
85
|
+
* Vite's `server.port`/`server.host` do.
|
|
86
|
+
*/
|
|
87
|
+
listen(port?: number, host?: string): Promise<Server>;
|
|
80
88
|
}
|
|
81
89
|
declare function createSSRServer(options?: TSSRServerOptions): Promise<TSSRServer>;
|
|
82
90
|
|
package/dist/prod-server.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { once } from "node:events";
|
|
1
2
|
import "node:fs";
|
|
2
3
|
import "node:module";
|
|
3
4
|
import { createLogger } from "moost";
|
|
@@ -82,6 +83,11 @@ const logger = createLogger({ level: 99 }).createTopic("\x1B[2m\x1B[36m" + PLUGI
|
|
|
82
83
|
|
|
83
84
|
//#endregion
|
|
84
85
|
//#region packages/vite/src/prod-server.ts
|
|
86
|
+
/** URL of the address the server actually bound (wildcard binds print as localhost). */ function serverUrl(server) {
|
|
87
|
+
const addr = server.address();
|
|
88
|
+
if (!addr || typeof addr === "string") return String(addr);
|
|
89
|
+
return `http://${addr.address === "::" || addr.address === "0.0.0.0" ? "localhost" : addr.family === "IPv6" ? `[${addr.address}]` : addr.address}:${addr.port}`;
|
|
90
|
+
}
|
|
85
91
|
function stripUndefined(obj) {
|
|
86
92
|
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
|
|
87
93
|
}
|
|
@@ -136,11 +142,13 @@ async function createSSRServer(options) {
|
|
|
136
142
|
use(mw) {
|
|
137
143
|
userMiddlewares.push(mw);
|
|
138
144
|
},
|
|
139
|
-
async listen(
|
|
145
|
+
async listen(port, host) {
|
|
146
|
+
if ((port ?? host ?? opts.port ?? opts.host) !== void 0) console.warn("[moost-vite] port/host passed to createSSRServer() or listen() are ignored in dev — set server.port / server.host in vite.config instead.");
|
|
140
147
|
for (const mw of userMiddlewares) vite.middlewares.use(mw);
|
|
141
148
|
if (ssrFallback) vite.middlewares.use(ssrFallback);
|
|
142
149
|
await vite.listen();
|
|
143
150
|
vite.printUrls();
|
|
151
|
+
return vite.httpServer;
|
|
144
152
|
}
|
|
145
153
|
};
|
|
146
154
|
}
|
|
@@ -154,6 +162,7 @@ async function createSSRServer(options) {
|
|
|
154
162
|
const prefixes = normalizePrefixes(opts.prefix ?? __MOOST_PREFIX__);
|
|
155
163
|
const ssrForwarding = opts.ssrFetchForwarding ?? __MOOST_SSR_FORWARDING__ ?? true;
|
|
156
164
|
const defaultPort = opts.port || Number(process.env.PORT) || 3e3;
|
|
165
|
+
const defaultHost = opts.host ?? process.env.HOST;
|
|
157
166
|
const template = await fs.readFile(path.resolve(clientDir, "index.html"), "utf8");
|
|
158
167
|
let render = null;
|
|
159
168
|
if (__MOOST_SSR_ENTRY__ !== void 0 && !!__MOOST_SSR_ENTRY__) render = (await import(
|
|
@@ -229,9 +238,8 @@ async function createSSRServer(options) {
|
|
|
229
238
|
use(mw) {
|
|
230
239
|
userMiddlewares.push(mw);
|
|
231
240
|
},
|
|
232
|
-
async listen(port) {
|
|
233
|
-
const
|
|
234
|
-
createHttpServer((req, res) => {
|
|
241
|
+
async listen(port, host) {
|
|
242
|
+
const server = createHttpServer((req, res) => {
|
|
235
243
|
const url = req.url || "/";
|
|
236
244
|
let i = 0;
|
|
237
245
|
const runNext = () => {
|
|
@@ -246,9 +254,11 @@ async function createSSRServer(options) {
|
|
|
246
254
|
serveStatic(req, res);
|
|
247
255
|
};
|
|
248
256
|
runNext();
|
|
249
|
-
}).listen(p, () => {
|
|
250
|
-
console.log(`Server running at http://localhost:${p}`);
|
|
251
257
|
});
|
|
258
|
+
server.listen(port || defaultPort, host || defaultHost);
|
|
259
|
+
await once(server, "listening");
|
|
260
|
+
console.log(`Server running at ${serverUrl(server)}`);
|
|
261
|
+
return server;
|
|
252
262
|
}
|
|
253
263
|
};
|
|
254
264
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/vite",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.39",
|
|
4
4
|
"description": "Vite Dev plugin for moostjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"composables",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"sirv": "^3.0.0",
|
|
60
60
|
"vite": "^8.0.0",
|
|
61
|
-
"@moostjs/event-http": "^0.6.
|
|
62
|
-
"moost": "^0.6.
|
|
61
|
+
"@moostjs/event-http": "^0.6.39",
|
|
62
|
+
"moost": "^0.6.39"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"sirv": {
|