@moostjs/vite 0.6.9 → 0.6.10
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 +47 -46
- package/dist/index.mjs +29 -44
- package/dist/prod-server.cjs +21 -50
- package/dist/prod-server.mjs +19 -24
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6,12 +7,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
9
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
@@ -21,12 +26,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
26
|
}) : target, mod));
|
|
22
27
|
|
|
23
28
|
//#endregion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
let node_fs = require("node:fs");
|
|
30
|
+
let node_path = require("node:path");
|
|
31
|
+
let vite = require("vite");
|
|
32
|
+
let magic_string = require("magic-string");
|
|
33
|
+
magic_string = __toESM(magic_string);
|
|
34
|
+
let node_module = require("node:module");
|
|
35
|
+
let moost = require("moost");
|
|
30
36
|
|
|
31
37
|
//#region packages/vite/src/utils.ts
|
|
32
38
|
const PLUGIN_NAME = "moost-vite";
|
|
@@ -57,9 +63,8 @@ function escapeRegex(str) {
|
|
|
57
63
|
}
|
|
58
64
|
function getExternals({ node, workspace }) {
|
|
59
65
|
const pkg = JSON.parse((0, node_fs.readFileSync)("package.json", "utf8").toString());
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
if (node) externals.push(...node_module.builtinModules.map((m) => /* @__PURE__ */ new RegExp(`^${escapeRegex(m)}(/|$)`)), ...node_module.builtinModules.map((m) => /* @__PURE__ */ new RegExp(`^node:${escapeRegex(m)}(/|$)`)));
|
|
66
|
+
const externals = (workspace ? Object.keys(pkg.dependencies || {}) : Object.entries(pkg.dependencies || {}).filter(([key, ver]) => !ver.startsWith("workspace:")).map((i) => i[0])).map((name) => new RegExp(`^${escapeRegex(name)}(/|$)`));
|
|
67
|
+
if (node) externals.push(...node_module.builtinModules.map((m) => new RegExp(`^${escapeRegex(m)}(/|$)`)), ...node_module.builtinModules.map((m) => new RegExp(`^node:${escapeRegex(m)}(/|$)`)));
|
|
63
68
|
return externals;
|
|
64
69
|
}
|
|
65
70
|
|
|
@@ -73,17 +78,17 @@ function getExternals({ node, workspace }) {
|
|
|
73
78
|
*/ function createAdapterDetector(adapter, onInit) {
|
|
74
79
|
return {
|
|
75
80
|
detected: false,
|
|
76
|
-
regex:
|
|
81
|
+
regex: new RegExp(`from\\s+["'](@moostjs\\/event-${adapter})["']`),
|
|
77
82
|
constructor: null,
|
|
78
83
|
ssrLoadModule: null,
|
|
79
84
|
async init() {
|
|
80
85
|
this.detected = true;
|
|
81
86
|
const moduleId = `@moostjs/event-${adapter}`;
|
|
82
|
-
const module
|
|
83
|
-
const constructorName
|
|
84
|
-
getLogger().log(`🔍 [2mExtracting Adapter "${constructorName
|
|
85
|
-
this.constructor = module
|
|
86
|
-
if (onInit && this.constructor) onInit(this.constructor, module
|
|
87
|
+
const module = this.ssrLoadModule ? await this.ssrLoadModule(moduleId) : await import(moduleId);
|
|
88
|
+
const constructorName = `Moost${adapter.charAt(0).toUpperCase() + adapter.slice(1)}`;
|
|
89
|
+
getLogger().log(`🔍 [2mExtracting Adapter "${constructorName}"`);
|
|
90
|
+
this.constructor = module[constructorName];
|
|
91
|
+
if (onInit && this.constructor) onInit(this.constructor, module);
|
|
87
92
|
},
|
|
88
93
|
compare(c) {
|
|
89
94
|
if (this.detected && this.constructor) return this.constructor === c || c instanceof this.constructor || c.prototype instanceof this.constructor;
|
|
@@ -118,7 +123,7 @@ function _define_property(obj, key, value) {
|
|
|
118
123
|
* 2. Compare them against previously recorded handlers to detect
|
|
119
124
|
* which are newly added vs. removed.
|
|
120
125
|
* 3. Store the new state as the old map for the next cycle.
|
|
121
|
-
*/ let LogsStorage = class LogsStorage
|
|
126
|
+
*/ let LogsStorage = class LogsStorage {
|
|
122
127
|
/**
|
|
123
128
|
* Called at the start of an init cycle to
|
|
124
129
|
* clear out the list of new items.
|
|
@@ -214,7 +219,7 @@ function _define_property(obj, key, value) {
|
|
|
214
219
|
*
|
|
215
220
|
* @param {Set<string>} [cleanupInstances] A set of module IDs to remove from the registry.
|
|
216
221
|
*/ function moostRestartCleanup(adapters, onEject, cleanupInstances) {
|
|
217
|
-
const logger
|
|
222
|
+
const logger = getLogger();
|
|
218
223
|
const infact = (0, moost.getMoostInfact)();
|
|
219
224
|
const { registry, scopes } = infact;
|
|
220
225
|
const registries = [registry, ...Object.values(scopes)];
|
|
@@ -226,7 +231,7 @@ function _define_property(obj, key, value) {
|
|
|
226
231
|
const instance = reg[key];
|
|
227
232
|
const viteId = mate.read(instance)?.__vite_id;
|
|
228
233
|
if (viteId && cleanupInstances.has(viteId)) {
|
|
229
|
-
logger
|
|
234
|
+
logger.debug(`🔃 Replacing "${constructorName(instance)}"`);
|
|
230
235
|
delete reg[key];
|
|
231
236
|
}
|
|
232
237
|
}
|
|
@@ -235,12 +240,12 @@ function _define_property(obj, key, value) {
|
|
|
235
240
|
scanParams(instance, (type) => {
|
|
236
241
|
if ((type === moost.Moost || type instanceof moost.Moost || type.prototype instanceof moost.Moost) && (!onEject || onEject(instance, type))) {
|
|
237
242
|
delete reg[key];
|
|
238
|
-
logger
|
|
243
|
+
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "Moost")`);
|
|
239
244
|
return true;
|
|
240
245
|
}
|
|
241
246
|
for (const adapter of adapters) if (adapter.compare(type) && (!onEject || onEject(instance, type))) {
|
|
242
247
|
delete reg[key];
|
|
243
|
-
logger
|
|
248
|
+
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "${adapter.constructor.name}")`);
|
|
244
249
|
return true;
|
|
245
250
|
}
|
|
246
251
|
});
|
|
@@ -254,7 +259,7 @@ function _define_property(obj, key, value) {
|
|
|
254
259
|
(0, moost.clearGlobalWooks)();
|
|
255
260
|
}
|
|
256
261
|
function clearDependantRegistry(registry, onEject) {
|
|
257
|
-
const logger
|
|
262
|
+
const logger = getLogger();
|
|
258
263
|
const objSet = /* @__PURE__ */ new Set();
|
|
259
264
|
let somethingIsDeleted = true;
|
|
260
265
|
while (somethingIsDeleted) {
|
|
@@ -265,17 +270,16 @@ function clearDependantRegistry(registry, onEject) {
|
|
|
265
270
|
}
|
|
266
271
|
for (const key of Object.getOwnPropertySymbols(registry)) {
|
|
267
272
|
const instance = registry[key];
|
|
268
|
-
|
|
269
|
-
if (ejected) somethingIsDeleted = true;
|
|
273
|
+
if (checkAndEject(instance, objSet, onEject, registry, key, logger)) somethingIsDeleted = true;
|
|
270
274
|
}
|
|
271
275
|
}
|
|
272
276
|
}
|
|
273
|
-
function checkAndEject(instance, objSet, onEject, registry, key, logger
|
|
277
|
+
function checkAndEject(instance, objSet, onEject, registry, key, logger) {
|
|
274
278
|
let ejected = false;
|
|
275
279
|
scanParams(instance, (type) => {
|
|
276
280
|
if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
|
|
277
281
|
delete registry[key];
|
|
278
|
-
logger
|
|
282
|
+
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
|
|
279
283
|
ejected = true;
|
|
280
284
|
return true;
|
|
281
285
|
}
|
|
@@ -283,8 +287,7 @@ function checkAndEject(instance, objSet, onEject, registry, key, logger$1) {
|
|
|
283
287
|
return ejected;
|
|
284
288
|
}
|
|
285
289
|
function scanParams(instance, cb) {
|
|
286
|
-
const
|
|
287
|
-
const params = mate.read(instance)?.params;
|
|
290
|
+
const params = (0, moost.getMoostMate)().read(instance)?.params;
|
|
288
291
|
if (params?.length) for (const param of params) {
|
|
289
292
|
if (param.type === void 0 || [
|
|
290
293
|
Array,
|
|
@@ -350,7 +353,7 @@ function moostVite(options) {
|
|
|
350
353
|
const adapters = isTest ? [] : [
|
|
351
354
|
createAdapterDetector("http", (MoostHttp, moduleExports) => {
|
|
352
355
|
MoostHttp.prototype.listen = function(...args) {
|
|
353
|
-
logger
|
|
356
|
+
logger.log(`🔌 [2mOvertaking HTTP.listen`);
|
|
354
357
|
if (options.middleware) moostMiddleware = this.getServerCb((req) => {
|
|
355
358
|
pendingNextMap.get(req)?.();
|
|
356
359
|
});
|
|
@@ -358,7 +361,7 @@ function moostVite(options) {
|
|
|
358
361
|
if (options.ssrFetch !== false && moduleExports?.enableLocalFetch) {
|
|
359
362
|
if (localFetchTeardown) localFetchTeardown();
|
|
360
363
|
localFetchTeardown = moduleExports.enableLocalFetch(this);
|
|
361
|
-
logger
|
|
364
|
+
logger.log(`🔀 [2mLocal fetch enabled for SSR`);
|
|
362
365
|
}
|
|
363
366
|
setTimeout(() => {
|
|
364
367
|
args.filter((a) => typeof a === "function").forEach((a) => a());
|
|
@@ -369,7 +372,7 @@ function moostVite(options) {
|
|
|
369
372
|
createAdapterDetector("cli"),
|
|
370
373
|
createAdapterDetector("wf")
|
|
371
374
|
];
|
|
372
|
-
/** A logger instance for plugin debug output. */ const logger
|
|
375
|
+
/** A logger instance for plugin debug output. */ const logger = isTest ? console : getLogger();
|
|
373
376
|
let reloadRequired = false;
|
|
374
377
|
patchMoostHandlerLogging();
|
|
375
378
|
const pluginConfig = {
|
|
@@ -386,8 +389,7 @@ function moostVite(options) {
|
|
|
386
389
|
__MOOST_ENTRY__: JSON.stringify(options.entry),
|
|
387
390
|
__MOOST_PREFIX__: JSON.stringify(prefix || "/api")
|
|
388
391
|
};
|
|
389
|
-
const
|
|
390
|
-
const ssrInput = { server: serverEntry };
|
|
392
|
+
const ssrInput = { server: options.serverEntry || generatedServerEntry(cfg.root) };
|
|
391
393
|
if (options.ssrEntry) {
|
|
392
394
|
const ssrBasename = entryBasename(options.ssrEntry);
|
|
393
395
|
ssrInput[`ssr/${ssrBasename.replace(/\.js$/, "")}`] = options.ssrEntry;
|
|
@@ -510,10 +512,10 @@ function moostVite(options) {
|
|
|
510
512
|
if (reloadRequired) {
|
|
511
513
|
reloadRequired = false;
|
|
512
514
|
console.log();
|
|
513
|
-
logger
|
|
515
|
+
logger.debug("🚀 Reloading Moost App...");
|
|
514
516
|
console.log();
|
|
515
517
|
await ssrImport(options.entry);
|
|
516
|
-
await new Promise((resolve
|
|
518
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
517
519
|
}
|
|
518
520
|
if (options.middleware && prefix) {
|
|
519
521
|
const url = req.url || "";
|
|
@@ -534,7 +536,7 @@ function moostVite(options) {
|
|
|
534
536
|
if (file.endsWith(".ts")) {
|
|
535
537
|
const modules = this.environment.moduleGraph.getModulesByFile(file);
|
|
536
538
|
if (modules) {
|
|
537
|
-
logger
|
|
539
|
+
logger.debug(`🔃 Hot update: ${file}`);
|
|
538
540
|
const cleanupInstances = /* @__PURE__ */ new Set();
|
|
539
541
|
for (const mod of modules) {
|
|
540
542
|
const allImporters = gatherAllImporters(mod);
|
|
@@ -560,7 +562,7 @@ function moostVite(options) {
|
|
|
560
562
|
delete pluginConfig.transform;
|
|
561
563
|
delete pluginConfig.hotUpdate;
|
|
562
564
|
}
|
|
563
|
-
|
|
565
|
+
return [pluginConfig, !isProd && !isTest && options.middleware && options.ssrEntry ? {
|
|
564
566
|
name: `${PLUGIN_NAME}:ssr-fallback`,
|
|
565
567
|
async configureServer(server) {
|
|
566
568
|
const ssrOutlet = options.ssrOutlet || DEFAULT_SSR_OUTLET;
|
|
@@ -577,7 +579,7 @@ function moostVite(options) {
|
|
|
577
579
|
const { html: appHtml, state } = await render(url);
|
|
578
580
|
res.statusCode = 200;
|
|
579
581
|
res.setHeader("Content-Type", "text/html");
|
|
580
|
-
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}
|
|
582
|
+
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}<\/script>` : ""));
|
|
581
583
|
} catch (error) {
|
|
582
584
|
server.ssrFixStacktrace(error);
|
|
583
585
|
console.error(error);
|
|
@@ -587,8 +589,7 @@ function moostVite(options) {
|
|
|
587
589
|
});
|
|
588
590
|
};
|
|
589
591
|
}
|
|
590
|
-
} : null;
|
|
591
|
-
return [pluginConfig, ssrFallbackPlugin];
|
|
592
|
+
} : null];
|
|
592
593
|
}
|
|
593
594
|
|
|
594
595
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -34,9 +34,8 @@ function escapeRegex(str) {
|
|
|
34
34
|
}
|
|
35
35
|
function getExternals({ node, workspace }) {
|
|
36
36
|
const pkg = JSON.parse(readFileSync("package.json", "utf8").toString());
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
if (node) externals.push(...builtinModules.map((m) => /* @__PURE__ */ new RegExp(`^${escapeRegex(m)}(/|$)`)), ...builtinModules.map((m) => /* @__PURE__ */ new RegExp(`^node:${escapeRegex(m)}(/|$)`)));
|
|
37
|
+
const externals = (workspace ? Object.keys(pkg.dependencies || {}) : Object.entries(pkg.dependencies || {}).filter(([key, ver]) => !ver.startsWith("workspace:")).map((i) => i[0])).map((name) => new RegExp(`^${escapeRegex(name)}(/|$)`));
|
|
38
|
+
if (node) externals.push(...builtinModules.map((m) => new RegExp(`^${escapeRegex(m)}(/|$)`)), ...builtinModules.map((m) => new RegExp(`^node:${escapeRegex(m)}(/|$)`)));
|
|
40
39
|
return externals;
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -50,16 +49,16 @@ function getExternals({ node, workspace }) {
|
|
|
50
49
|
*/ function createAdapterDetector(adapter, onInit) {
|
|
51
50
|
return {
|
|
52
51
|
detected: false,
|
|
53
|
-
regex:
|
|
52
|
+
regex: new RegExp(`from\\s+["'](@moostjs\\/event-${adapter})["']`),
|
|
54
53
|
constructor: null,
|
|
55
54
|
ssrLoadModule: null,
|
|
56
55
|
async init() {
|
|
57
56
|
this.detected = true;
|
|
58
57
|
const moduleId = `@moostjs/event-${adapter}`;
|
|
59
58
|
const module = this.ssrLoadModule ? await this.ssrLoadModule(moduleId) : await import(moduleId);
|
|
60
|
-
const constructorName
|
|
61
|
-
getLogger().log(`🔍 [2mExtracting Adapter "${constructorName
|
|
62
|
-
this.constructor = module[constructorName
|
|
59
|
+
const constructorName = `Moost${adapter.charAt(0).toUpperCase() + adapter.slice(1)}`;
|
|
60
|
+
getLogger().log(`🔍 [2mExtracting Adapter "${constructorName}"`);
|
|
61
|
+
this.constructor = module[constructorName];
|
|
63
62
|
if (onInit && this.constructor) onInit(this.constructor, module);
|
|
64
63
|
},
|
|
65
64
|
compare(c) {
|
|
@@ -95,7 +94,7 @@ function _define_property(obj, key, value) {
|
|
|
95
94
|
* 2. Compare them against previously recorded handlers to detect
|
|
96
95
|
* which are newly added vs. removed.
|
|
97
96
|
* 3. Store the new state as the old map for the next cycle.
|
|
98
|
-
*/ let LogsStorage = class LogsStorage
|
|
97
|
+
*/ let LogsStorage = class LogsStorage {
|
|
99
98
|
/**
|
|
100
99
|
* Called at the start of an init cycle to
|
|
101
100
|
* clear out the list of new items.
|
|
@@ -191,7 +190,7 @@ function _define_property(obj, key, value) {
|
|
|
191
190
|
*
|
|
192
191
|
* @param {Set<string>} [cleanupInstances] A set of module IDs to remove from the registry.
|
|
193
192
|
*/ function moostRestartCleanup(adapters, onEject, cleanupInstances) {
|
|
194
|
-
const logger
|
|
193
|
+
const logger = getLogger();
|
|
195
194
|
const infact = getMoostInfact();
|
|
196
195
|
const { registry, scopes } = infact;
|
|
197
196
|
const registries = [registry, ...Object.values(scopes)];
|
|
@@ -203,7 +202,7 @@ function _define_property(obj, key, value) {
|
|
|
203
202
|
const instance = reg[key];
|
|
204
203
|
const viteId = mate.read(instance)?.__vite_id;
|
|
205
204
|
if (viteId && cleanupInstances.has(viteId)) {
|
|
206
|
-
logger
|
|
205
|
+
logger.debug(`🔃 Replacing "${constructorName(instance)}"`);
|
|
207
206
|
delete reg[key];
|
|
208
207
|
}
|
|
209
208
|
}
|
|
@@ -212,12 +211,12 @@ function _define_property(obj, key, value) {
|
|
|
212
211
|
scanParams(instance, (type) => {
|
|
213
212
|
if ((type === Moost || type instanceof Moost || type.prototype instanceof Moost) && (!onEject || onEject(instance, type))) {
|
|
214
213
|
delete reg[key];
|
|
215
|
-
logger
|
|
214
|
+
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "Moost")`);
|
|
216
215
|
return true;
|
|
217
216
|
}
|
|
218
217
|
for (const adapter of adapters) if (adapter.compare(type) && (!onEject || onEject(instance, type))) {
|
|
219
218
|
delete reg[key];
|
|
220
|
-
logger
|
|
219
|
+
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on re-instantiated "${adapter.constructor.name}")`);
|
|
221
220
|
return true;
|
|
222
221
|
}
|
|
223
222
|
});
|
|
@@ -231,7 +230,7 @@ function _define_property(obj, key, value) {
|
|
|
231
230
|
clearGlobalWooks();
|
|
232
231
|
}
|
|
233
232
|
function clearDependantRegistry(registry, onEject) {
|
|
234
|
-
const logger
|
|
233
|
+
const logger = getLogger();
|
|
235
234
|
const objSet = /* @__PURE__ */ new Set();
|
|
236
235
|
let somethingIsDeleted = true;
|
|
237
236
|
while (somethingIsDeleted) {
|
|
@@ -242,17 +241,16 @@ function clearDependantRegistry(registry, onEject) {
|
|
|
242
241
|
}
|
|
243
242
|
for (const key of Object.getOwnPropertySymbols(registry)) {
|
|
244
243
|
const instance = registry[key];
|
|
245
|
-
|
|
246
|
-
if (ejected) somethingIsDeleted = true;
|
|
244
|
+
if (checkAndEject(instance, objSet, onEject, registry, key, logger)) somethingIsDeleted = true;
|
|
247
245
|
}
|
|
248
246
|
}
|
|
249
247
|
}
|
|
250
|
-
function checkAndEject(instance, objSet, onEject, registry, key, logger
|
|
248
|
+
function checkAndEject(instance, objSet, onEject, registry, key, logger) {
|
|
251
249
|
let ejected = false;
|
|
252
250
|
scanParams(instance, (type) => {
|
|
253
251
|
if (!objSet.has(type) && (!onEject || onEject(instance, type))) {
|
|
254
252
|
delete registry[key];
|
|
255
|
-
logger
|
|
253
|
+
logger.debug(`✖️ Ejecting "${constructorName(instance)}" (depends on "${type.name}" which is not in registry)`);
|
|
256
254
|
ejected = true;
|
|
257
255
|
return true;
|
|
258
256
|
}
|
|
@@ -260,8 +258,7 @@ function checkAndEject(instance, objSet, onEject, registry, key, logger$1) {
|
|
|
260
258
|
return ejected;
|
|
261
259
|
}
|
|
262
260
|
function scanParams(instance, cb) {
|
|
263
|
-
const
|
|
264
|
-
const params = mate.read(instance)?.params;
|
|
261
|
+
const params = getMoostMate().read(instance)?.params;
|
|
265
262
|
if (params?.length) for (const param of params) {
|
|
266
263
|
if (param.type === void 0 || [
|
|
267
264
|
Array,
|
|
@@ -311,8 +308,6 @@ function generatedServerEntry(root) {
|
|
|
311
308
|
return entryPath;
|
|
312
309
|
}
|
|
313
310
|
function moostVite(options) {
|
|
314
|
-
const isTest = false;
|
|
315
|
-
const isProd = false;
|
|
316
311
|
const externals = options.externals ?? true;
|
|
317
312
|
let prefix = options.prefix;
|
|
318
313
|
if (prefix) {
|
|
@@ -324,10 +319,10 @@ function moostVite(options) {
|
|
|
324
319
|
let moostMiddleware = null;
|
|
325
320
|
let localFetchTeardown = null;
|
|
326
321
|
/** In middleware mode: maps req → next() for the onNoMatch callback */ const pendingNextMap = /* @__PURE__ */ new WeakMap();
|
|
327
|
-
const adapters =
|
|
322
|
+
const adapters = [
|
|
328
323
|
createAdapterDetector("http", (MoostHttp, moduleExports) => {
|
|
329
324
|
MoostHttp.prototype.listen = function(...args) {
|
|
330
|
-
logger
|
|
325
|
+
logger.log(`🔌 [2mOvertaking HTTP.listen`);
|
|
331
326
|
if (options.middleware) moostMiddleware = this.getServerCb((req) => {
|
|
332
327
|
pendingNextMap.get(req)?.();
|
|
333
328
|
});
|
|
@@ -335,7 +330,7 @@ function moostVite(options) {
|
|
|
335
330
|
if (options.ssrFetch !== false && moduleExports?.enableLocalFetch) {
|
|
336
331
|
if (localFetchTeardown) localFetchTeardown();
|
|
337
332
|
localFetchTeardown = moduleExports.enableLocalFetch(this);
|
|
338
|
-
logger
|
|
333
|
+
logger.log(`🔀 [2mLocal fetch enabled for SSR`);
|
|
339
334
|
}
|
|
340
335
|
setTimeout(() => {
|
|
341
336
|
args.filter((a) => typeof a === "function").forEach((a) => a());
|
|
@@ -346,10 +341,10 @@ function moostVite(options) {
|
|
|
346
341
|
createAdapterDetector("cli"),
|
|
347
342
|
createAdapterDetector("wf")
|
|
348
343
|
];
|
|
349
|
-
/** A logger instance for plugin debug output. */ const logger
|
|
344
|
+
/** A logger instance for plugin debug output. */ const logger = getLogger();
|
|
350
345
|
let reloadRequired = false;
|
|
351
346
|
patchMoostHandlerLogging();
|
|
352
|
-
|
|
347
|
+
return [{
|
|
353
348
|
name: PLUGIN_NAME,
|
|
354
349
|
enforce: "pre",
|
|
355
350
|
config(cfg) {
|
|
@@ -363,8 +358,7 @@ function moostVite(options) {
|
|
|
363
358
|
__MOOST_ENTRY__: JSON.stringify(options.entry),
|
|
364
359
|
__MOOST_PREFIX__: JSON.stringify(prefix || "/api")
|
|
365
360
|
};
|
|
366
|
-
const
|
|
367
|
-
const ssrInput = { server: serverEntry };
|
|
361
|
+
const ssrInput = { server: options.serverEntry || generatedServerEntry(cfg.root) };
|
|
368
362
|
if (options.ssrEntry) {
|
|
369
363
|
const ssrBasename = entryBasename(options.ssrEntry);
|
|
370
364
|
ssrInput[`ssr/${ssrBasename.replace(/\.js$/, "")}`] = options.ssrEntry;
|
|
@@ -423,7 +417,7 @@ function moostVite(options) {
|
|
|
423
417
|
minify: cfg.build?.minify || false,
|
|
424
418
|
sourcemap: !!(options.sourcemap ?? true),
|
|
425
419
|
rollupOptions: {
|
|
426
|
-
external:
|
|
420
|
+
external: cfg.build?.rollupOptions?.external || (externals === false ? [] : getExternals({
|
|
427
421
|
node: Boolean(externals === true || externals?.node),
|
|
428
422
|
workspace: Boolean(externals === true || externals?.workspace)
|
|
429
423
|
})),
|
|
@@ -487,10 +481,10 @@ function moostVite(options) {
|
|
|
487
481
|
if (reloadRequired) {
|
|
488
482
|
reloadRequired = false;
|
|
489
483
|
console.log();
|
|
490
|
-
logger
|
|
484
|
+
logger.debug("🚀 Reloading Moost App...");
|
|
491
485
|
console.log();
|
|
492
486
|
await ssrImport(options.entry);
|
|
493
|
-
await new Promise((resolve
|
|
487
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
494
488
|
}
|
|
495
489
|
if (options.middleware && prefix) {
|
|
496
490
|
const url = req.url || "";
|
|
@@ -511,7 +505,7 @@ function moostVite(options) {
|
|
|
511
505
|
if (file.endsWith(".ts")) {
|
|
512
506
|
const modules = this.environment.moduleGraph.getModulesByFile(file);
|
|
513
507
|
if (modules) {
|
|
514
|
-
logger
|
|
508
|
+
logger.debug(`🔃 Hot update: ${file}`);
|
|
515
509
|
const cleanupInstances = /* @__PURE__ */ new Set();
|
|
516
510
|
for (const mod of modules) {
|
|
517
511
|
const allImporters = gatherAllImporters(mod);
|
|
@@ -529,15 +523,7 @@ function moostVite(options) {
|
|
|
529
523
|
return [];
|
|
530
524
|
}
|
|
531
525
|
}
|
|
532
|
-
}
|
|
533
|
-
if (isProd || isTest) {
|
|
534
|
-
delete pluginConfig.configureServer;
|
|
535
|
-
delete pluginConfig.resolveId;
|
|
536
|
-
delete pluginConfig.load;
|
|
537
|
-
delete pluginConfig.transform;
|
|
538
|
-
delete pluginConfig.hotUpdate;
|
|
539
|
-
}
|
|
540
|
-
const ssrFallbackPlugin = !isProd && !isTest && options.middleware && options.ssrEntry ? {
|
|
526
|
+
}, options.middleware && options.ssrEntry ? {
|
|
541
527
|
name: `${PLUGIN_NAME}:ssr-fallback`,
|
|
542
528
|
async configureServer(server) {
|
|
543
529
|
const ssrOutlet = options.ssrOutlet || DEFAULT_SSR_OUTLET;
|
|
@@ -554,7 +540,7 @@ function moostVite(options) {
|
|
|
554
540
|
const { html: appHtml, state } = await render(url);
|
|
555
541
|
res.statusCode = 200;
|
|
556
542
|
res.setHeader("Content-Type", "text/html");
|
|
557
|
-
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}
|
|
543
|
+
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}<\/script>` : ""));
|
|
558
544
|
} catch (error) {
|
|
559
545
|
server.ssrFixStacktrace(error);
|
|
560
546
|
console.error(error);
|
|
@@ -564,8 +550,7 @@ function moostVite(options) {
|
|
|
564
550
|
});
|
|
565
551
|
};
|
|
566
552
|
}
|
|
567
|
-
} : null;
|
|
568
|
-
return [pluginConfig, ssrFallbackPlugin];
|
|
553
|
+
} : null];
|
|
569
554
|
}
|
|
570
555
|
|
|
571
556
|
//#endregion
|
package/dist/prod-server.cjs
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
require("node:fs");
|
|
25
|
-
require("node:module");
|
|
26
|
-
const moost = __toESM(require("moost"));
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let moost = require("moost");
|
|
27
3
|
|
|
28
4
|
//#region packages/vite/src/utils.ts
|
|
29
5
|
const PLUGIN_NAME = "moost-vite";
|
|
@@ -39,33 +15,31 @@ function stripUndefined(obj) {
|
|
|
39
15
|
async function createSSRServer(options) {
|
|
40
16
|
const userMiddlewares = [];
|
|
41
17
|
const opts = options ? stripUndefined(options) : {};
|
|
42
|
-
|
|
43
|
-
if (!isProd) {
|
|
18
|
+
if (!(process.env.MOOST_DEFERRED_ENV === "production")) {
|
|
44
19
|
const { createServer: createViteServer } = await import("vite");
|
|
45
20
|
const vite = await createViteServer();
|
|
46
|
-
const pluginOpts = vite.config.__moostViteOptions || {};
|
|
47
21
|
const config = {
|
|
48
|
-
...
|
|
22
|
+
...vite.config.__moostViteOptions || {},
|
|
49
23
|
...opts
|
|
50
24
|
};
|
|
51
25
|
const ssrEntry = config.ssrEntry;
|
|
52
|
-
const ssrOutlet
|
|
53
|
-
const ssrState
|
|
26
|
+
const ssrOutlet = config.ssrOutlet || DEFAULT_SSR_OUTLET;
|
|
27
|
+
const ssrState = config.ssrState || DEFAULT_SSR_STATE;
|
|
54
28
|
let ssrFallback = null;
|
|
55
29
|
if (ssrEntry) {
|
|
56
|
-
const fs
|
|
57
|
-
const path
|
|
30
|
+
const fs = await import("node:fs/promises");
|
|
31
|
+
const path = await import("node:path");
|
|
58
32
|
ssrFallback = async (req, res, next) => {
|
|
59
33
|
if (req.method !== "GET") return next();
|
|
60
34
|
const url = req.originalUrl || req.url || "/";
|
|
61
35
|
try {
|
|
62
|
-
let template
|
|
63
|
-
template
|
|
64
|
-
const { render
|
|
65
|
-
const { html: appHtml, state } = await render
|
|
36
|
+
let template = await fs.readFile(path.resolve(process.cwd(), "index.html"), "utf8");
|
|
37
|
+
template = await vite.transformIndexHtml(url, template);
|
|
38
|
+
const { render } = await vite.ssrLoadModule(ssrEntry);
|
|
39
|
+
const { html: appHtml, state } = await render(url);
|
|
66
40
|
res.statusCode = 200;
|
|
67
41
|
res.setHeader("Content-Type", "text/html");
|
|
68
|
-
res.end(template
|
|
42
|
+
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}<\/script>` : ""));
|
|
69
43
|
} catch (error) {
|
|
70
44
|
vite.ssrFixStacktrace(error);
|
|
71
45
|
console.error(error);
|
|
@@ -99,13 +73,10 @@ async function createSSRServer(options) {
|
|
|
99
73
|
const defaultPort = opts.port || Number(process.env.PORT) || 3e3;
|
|
100
74
|
const template = await fs.readFile(path.resolve(clientDir, "index.html"), "utf8");
|
|
101
75
|
let render = null;
|
|
102
|
-
|
|
103
|
-
if (hasSsr) {
|
|
104
|
-
const ssrModule = await import(
|
|
76
|
+
if (__MOOST_SSR_ENTRY__ !== void 0 && !!__MOOST_SSR_ENTRY__) render = (await import(
|
|
105
77
|
/* @vite-ignore */
|
|
106
|
-
__MOOST_SSR_ENTRY__
|
|
107
|
-
|
|
108
|
-
}
|
|
78
|
+
__MOOST_SSR_ENTRY__
|
|
79
|
+
)).render;
|
|
109
80
|
const { MoostHttp, enableLocalFetch } = await import("@moostjs/event-http");
|
|
110
81
|
let moostHandler = null;
|
|
111
82
|
const moostHttpRef = { instance: null };
|
|
@@ -118,13 +89,13 @@ async function createSSRServer(options) {
|
|
|
118
89
|
};
|
|
119
90
|
if (typeof opts.entry === "function") await opts.entry();
|
|
120
91
|
else if (typeof opts.entry === "string") await import(
|
|
121
|
-
|
|
122
|
-
|
|
92
|
+
/* @vite-ignore */
|
|
93
|
+
opts.entry
|
|
94
|
+
);
|
|
123
95
|
else await import(__MOOST_ENTRY__);
|
|
124
96
|
MoostHttp.prototype.listen = origListen;
|
|
125
97
|
if (enableLocalFetch && moostHttpRef.instance) enableLocalFetch(moostHttpRef.instance);
|
|
126
|
-
const
|
|
127
|
-
const sirv = sirvModule.default;
|
|
98
|
+
const sirv = (await import("sirv")).default;
|
|
128
99
|
const serve = sirv(path.resolve(clientDir), { extensions: [] });
|
|
129
100
|
return {
|
|
130
101
|
use(mw) {
|
|
@@ -155,7 +126,7 @@ async function createSSRServer(options) {
|
|
|
155
126
|
const { html: appHtml, state } = await render(url);
|
|
156
127
|
res.statusCode = 200;
|
|
157
128
|
res.setHeader("Content-Type", "text/html");
|
|
158
|
-
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}
|
|
129
|
+
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}<\/script>` : ""));
|
|
159
130
|
} else {
|
|
160
131
|
res.statusCode = 200;
|
|
161
132
|
res.setHeader("Content-Type", "text/html");
|
package/dist/prod-server.mjs
CHANGED
|
@@ -16,33 +16,31 @@ function stripUndefined(obj) {
|
|
|
16
16
|
async function createSSRServer(options) {
|
|
17
17
|
const userMiddlewares = [];
|
|
18
18
|
const opts = options ? stripUndefined(options) : {};
|
|
19
|
-
|
|
20
|
-
if (!isProd) {
|
|
19
|
+
if (!(process.env.MOOST_DEFERRED_ENV === "production")) {
|
|
21
20
|
const { createServer: createViteServer } = await import("vite");
|
|
22
21
|
const vite = await createViteServer();
|
|
23
|
-
const pluginOpts = vite.config.__moostViteOptions || {};
|
|
24
22
|
const config = {
|
|
25
|
-
...
|
|
23
|
+
...vite.config.__moostViteOptions || {},
|
|
26
24
|
...opts
|
|
27
25
|
};
|
|
28
26
|
const ssrEntry = config.ssrEntry;
|
|
29
|
-
const ssrOutlet
|
|
30
|
-
const ssrState
|
|
27
|
+
const ssrOutlet = config.ssrOutlet || DEFAULT_SSR_OUTLET;
|
|
28
|
+
const ssrState = config.ssrState || DEFAULT_SSR_STATE;
|
|
31
29
|
let ssrFallback = null;
|
|
32
30
|
if (ssrEntry) {
|
|
33
|
-
const fs
|
|
34
|
-
const path
|
|
31
|
+
const fs = await import("node:fs/promises");
|
|
32
|
+
const path = await import("node:path");
|
|
35
33
|
ssrFallback = async (req, res, next) => {
|
|
36
34
|
if (req.method !== "GET") return next();
|
|
37
35
|
const url = req.originalUrl || req.url || "/";
|
|
38
36
|
try {
|
|
39
|
-
let template
|
|
40
|
-
template
|
|
41
|
-
const { render
|
|
42
|
-
const { html: appHtml, state } = await render
|
|
37
|
+
let template = await fs.readFile(path.resolve(process.cwd(), "index.html"), "utf8");
|
|
38
|
+
template = await vite.transformIndexHtml(url, template);
|
|
39
|
+
const { render } = await vite.ssrLoadModule(ssrEntry);
|
|
40
|
+
const { html: appHtml, state } = await render(url);
|
|
43
41
|
res.statusCode = 200;
|
|
44
42
|
res.setHeader("Content-Type", "text/html");
|
|
45
|
-
res.end(template
|
|
43
|
+
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}<\/script>` : ""));
|
|
46
44
|
} catch (error) {
|
|
47
45
|
vite.ssrFixStacktrace(error);
|
|
48
46
|
console.error(error);
|
|
@@ -76,13 +74,10 @@ async function createSSRServer(options) {
|
|
|
76
74
|
const defaultPort = opts.port || Number(process.env.PORT) || 3e3;
|
|
77
75
|
const template = await fs.readFile(path.resolve(clientDir, "index.html"), "utf8");
|
|
78
76
|
let render = null;
|
|
79
|
-
|
|
80
|
-
if (hasSsr) {
|
|
81
|
-
const ssrModule = await import(
|
|
77
|
+
if (__MOOST_SSR_ENTRY__ !== void 0 && !!__MOOST_SSR_ENTRY__) render = (await import(
|
|
82
78
|
/* @vite-ignore */
|
|
83
|
-
__MOOST_SSR_ENTRY__
|
|
84
|
-
|
|
85
|
-
}
|
|
79
|
+
__MOOST_SSR_ENTRY__
|
|
80
|
+
)).render;
|
|
86
81
|
const { MoostHttp, enableLocalFetch } = await import("@moostjs/event-http");
|
|
87
82
|
let moostHandler = null;
|
|
88
83
|
const moostHttpRef = { instance: null };
|
|
@@ -95,13 +90,13 @@ async function createSSRServer(options) {
|
|
|
95
90
|
};
|
|
96
91
|
if (typeof opts.entry === "function") await opts.entry();
|
|
97
92
|
else if (typeof opts.entry === "string") await import(
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
/* @vite-ignore */
|
|
94
|
+
opts.entry
|
|
95
|
+
);
|
|
100
96
|
else await import(__MOOST_ENTRY__);
|
|
101
97
|
MoostHttp.prototype.listen = origListen;
|
|
102
98
|
if (enableLocalFetch && moostHttpRef.instance) enableLocalFetch(moostHttpRef.instance);
|
|
103
|
-
const
|
|
104
|
-
const sirv = sirvModule.default;
|
|
99
|
+
const sirv = (await import("sirv")).default;
|
|
105
100
|
const serve = sirv(path.resolve(clientDir), { extensions: [] });
|
|
106
101
|
return {
|
|
107
102
|
use(mw) {
|
|
@@ -132,7 +127,7 @@ async function createSSRServer(options) {
|
|
|
132
127
|
const { html: appHtml, state } = await render(url);
|
|
133
128
|
res.statusCode = 200;
|
|
134
129
|
res.setHeader("Content-Type", "text/html");
|
|
135
|
-
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}
|
|
130
|
+
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}<\/script>` : ""));
|
|
136
131
|
} else {
|
|
137
132
|
res.statusCode = 200;
|
|
138
133
|
res.setHeader("Content-Type", "text/html");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/vite",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
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.10",
|
|
62
|
+
"moost": "^0.6.10"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"sirv": {
|