@moostjs/vite 0.6.37 → 0.6.38
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 -44
- package/dist/index.mjs +25 -44
- 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
|
}
|
|
@@ -977,7 +958,7 @@ function moostVite(options) {
|
|
|
977
958
|
beginBoot();
|
|
978
959
|
const cleanupInstances = pendingCleanup ?? void 0;
|
|
979
960
|
pendingCleanup = null;
|
|
980
|
-
await moostRestartCleanup(
|
|
961
|
+
await moostRestartCleanup(options.onEject, cleanupInstances);
|
|
981
962
|
for (const adapter of adapters) if (adapter.detected) await adapter.init();
|
|
982
963
|
const entryModule = await getEntryModule(server.environments.ssr.moduleGraph);
|
|
983
964
|
if (entryModule?.transformResult) server.environments.ssr.moduleGraph.invalidateModule(entryModule);
|
|
@@ -999,7 +980,7 @@ function moostVite(options) {
|
|
|
999
980
|
}
|
|
1000
981
|
};
|
|
1001
982
|
for (const adapter of adapters) adapter.ssrLoadModule = ssrImport;
|
|
1002
|
-
await moostRestartCleanup(
|
|
983
|
+
await moostRestartCleanup(options.onEject);
|
|
1003
984
|
await ssrImport(options.entry);
|
|
1004
985
|
await settleBootInit();
|
|
1005
986
|
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
|
}
|
|
@@ -946,7 +927,7 @@ function moostVite(options) {
|
|
|
946
927
|
beginBoot();
|
|
947
928
|
const cleanupInstances = pendingCleanup ?? void 0;
|
|
948
929
|
pendingCleanup = null;
|
|
949
|
-
await moostRestartCleanup(
|
|
930
|
+
await moostRestartCleanup(options.onEject, cleanupInstances);
|
|
950
931
|
for (const adapter of adapters) if (adapter.detected) await adapter.init();
|
|
951
932
|
const entryModule = await getEntryModule(server.environments.ssr.moduleGraph);
|
|
952
933
|
if (entryModule?.transformResult) server.environments.ssr.moduleGraph.invalidateModule(entryModule);
|
|
@@ -968,7 +949,7 @@ function moostVite(options) {
|
|
|
968
949
|
}
|
|
969
950
|
};
|
|
970
951
|
for (const adapter of adapters) adapter.ssrLoadModule = ssrImport;
|
|
971
|
-
await moostRestartCleanup(
|
|
952
|
+
await moostRestartCleanup(options.onEject);
|
|
972
953
|
await ssrImport(options.entry);
|
|
973
954
|
await settleBootInit();
|
|
974
955
|
server.middlewares.use(async (req, res, next) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/vite",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.38",
|
|
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.38",
|
|
62
|
+
"moost": "^0.6.38"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"sirv": {
|