@moostjs/vite 0.6.10 → 0.6.12
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 +10 -9
- package/dist/index.d.ts +25 -0
- package/dist/index.mjs +10 -9
- package/dist/prod-server.cjs +7 -0
- package/dist/prod-server.mjs +7 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -378,12 +378,8 @@ function moostVite(options) {
|
|
|
378
378
|
const pluginConfig = {
|
|
379
379
|
name: PLUGIN_NAME,
|
|
380
380
|
enforce: "pre",
|
|
381
|
-
config(cfg) {
|
|
381
|
+
config(cfg, env) {
|
|
382
382
|
if (options.middleware) {
|
|
383
|
-
const defaultExternals = getExternals({
|
|
384
|
-
node: true,
|
|
385
|
-
workspace: true
|
|
386
|
-
});
|
|
387
383
|
const serverDefines = {
|
|
388
384
|
"process.env.MOOST_DEFERRED_ENV": "\"production\"",
|
|
389
385
|
__MOOST_ENTRY__: JSON.stringify(options.entry),
|
|
@@ -398,8 +394,17 @@ function moostVite(options) {
|
|
|
398
394
|
serverDefines.__MOOST_SSR_STATE__ = JSON.stringify(options.ssrState || DEFAULT_SSR_STATE);
|
|
399
395
|
}
|
|
400
396
|
const outDir = cfg.build?.outDir || "dist";
|
|
397
|
+
const isBuild = env.command === "build";
|
|
398
|
+
const userNoExternal = cfg.ssr?.noExternal;
|
|
399
|
+
const ssrNoExternal = isBuild ? true : Array.from(new Set([...Array.isArray(userNoExternal) ? userNoExternal : userNoExternal && typeof userNoExternal !== "boolean" ? [userNoExternal] : [], /^@moostjs\/vite($|\/)/]));
|
|
400
|
+
const userExternal = cfg.ssr?.external;
|
|
401
|
+
const ssrExternal = isBuild ? [...Array.isArray(userExternal) ? userExternal : [], ...options.ssrExternal ?? []] : void 0;
|
|
401
402
|
return {
|
|
402
403
|
...options.ssrEntry && { appType: "custom" },
|
|
404
|
+
ssr: {
|
|
405
|
+
noExternal: ssrNoExternal,
|
|
406
|
+
...ssrExternal && ssrExternal.length > 0 ? { external: ssrExternal } : {}
|
|
407
|
+
},
|
|
403
408
|
builder: { async buildApp(builder) {
|
|
404
409
|
(0, node_fs.rmSync)((0, node_path.resolve)(cfg.root || process.cwd(), outDir), {
|
|
405
410
|
recursive: true,
|
|
@@ -421,10 +426,6 @@ function moostVite(options) {
|
|
|
421
426
|
sourcemap: !!(options.sourcemap ?? true),
|
|
422
427
|
rollupOptions: {
|
|
423
428
|
input: ssrInput,
|
|
424
|
-
external: (id) => {
|
|
425
|
-
if (id === "@moostjs/vite/server") return false;
|
|
426
|
-
return defaultExternals.some((ext) => ext.test(id));
|
|
427
|
-
},
|
|
428
429
|
output: { format: "esm" }
|
|
429
430
|
}
|
|
430
431
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -120,6 +120,31 @@ interface TMoostViteDevOptions {
|
|
|
120
120
|
* production server that serves static files + Moost API (+ SSR if configured).
|
|
121
121
|
*/
|
|
122
122
|
serverEntry?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Packages to keep external in the production SSR bundle.
|
|
125
|
+
*
|
|
126
|
+
* In middleware mode during `vite build`, the plugin defaults to
|
|
127
|
+
* `ssr.noExternal: true` — every dependency is bundled into the SSR
|
|
128
|
+
* output. This avoids two common failure modes:
|
|
129
|
+
* - duplicate module instances of packages like `@wooksjs/event-http`
|
|
130
|
+
* whose Symbol-identity slot keys do not match across instances;
|
|
131
|
+
* - pnpm strict-resolution failures where externalized transitive deps
|
|
132
|
+
* are not hoist-accessible from the consumer's `node_modules`.
|
|
133
|
+
*
|
|
134
|
+
* Use `ssrExternal` to opt specific packages OUT of bundling for cases
|
|
135
|
+
* where bundling is impossible or undesirable — native bindings such as
|
|
136
|
+
* `mongodb`, `ioredis`, or anything that loads `.node` modules.
|
|
137
|
+
*
|
|
138
|
+
* Only applied in `middleware: true` mode during `vite build`. Dev
|
|
139
|
+
* (`vite serve`) is unaffected: Vite's default externalizer continues
|
|
140
|
+
* to handle node_modules, which is required so CJS-only packages like
|
|
141
|
+
* `@vue/server-renderer` can be loaded by Node's ESM/CJS interop
|
|
142
|
+
* instead of evaluated by Vite's ESM-only SSR module runner.
|
|
143
|
+
*
|
|
144
|
+
* Concatenated with any `cfg.ssr.external` the consumer sets directly
|
|
145
|
+
* in `vite.config.ts`.
|
|
146
|
+
*/
|
|
147
|
+
ssrExternal?: string[];
|
|
123
148
|
}
|
|
124
149
|
declare function moostVite(options: TMoostViteDevOptions): PluginOption;
|
|
125
150
|
|
package/dist/index.mjs
CHANGED
|
@@ -347,12 +347,8 @@ function moostVite(options) {
|
|
|
347
347
|
return [{
|
|
348
348
|
name: PLUGIN_NAME,
|
|
349
349
|
enforce: "pre",
|
|
350
|
-
config(cfg) {
|
|
350
|
+
config(cfg, env) {
|
|
351
351
|
if (options.middleware) {
|
|
352
|
-
const defaultExternals = getExternals({
|
|
353
|
-
node: true,
|
|
354
|
-
workspace: true
|
|
355
|
-
});
|
|
356
352
|
const serverDefines = {
|
|
357
353
|
"process.env.MOOST_DEFERRED_ENV": "\"production\"",
|
|
358
354
|
__MOOST_ENTRY__: JSON.stringify(options.entry),
|
|
@@ -367,8 +363,17 @@ function moostVite(options) {
|
|
|
367
363
|
serverDefines.__MOOST_SSR_STATE__ = JSON.stringify(options.ssrState || DEFAULT_SSR_STATE);
|
|
368
364
|
}
|
|
369
365
|
const outDir = cfg.build?.outDir || "dist";
|
|
366
|
+
const isBuild = env.command === "build";
|
|
367
|
+
const userNoExternal = cfg.ssr?.noExternal;
|
|
368
|
+
const ssrNoExternal = isBuild ? true : Array.from(new Set([...Array.isArray(userNoExternal) ? userNoExternal : userNoExternal && typeof userNoExternal !== "boolean" ? [userNoExternal] : [], /^@moostjs\/vite($|\/)/]));
|
|
369
|
+
const userExternal = cfg.ssr?.external;
|
|
370
|
+
const ssrExternal = isBuild ? [...Array.isArray(userExternal) ? userExternal : [], ...options.ssrExternal ?? []] : void 0;
|
|
370
371
|
return {
|
|
371
372
|
...options.ssrEntry && { appType: "custom" },
|
|
373
|
+
ssr: {
|
|
374
|
+
noExternal: ssrNoExternal,
|
|
375
|
+
...ssrExternal && ssrExternal.length > 0 ? { external: ssrExternal } : {}
|
|
376
|
+
},
|
|
372
377
|
builder: { async buildApp(builder) {
|
|
373
378
|
rmSync(resolve(cfg.root || process.cwd(), outDir), {
|
|
374
379
|
recursive: true,
|
|
@@ -390,10 +395,6 @@ function moostVite(options) {
|
|
|
390
395
|
sourcemap: !!(options.sourcemap ?? true),
|
|
391
396
|
rollupOptions: {
|
|
392
397
|
input: ssrInput,
|
|
393
|
-
external: (id) => {
|
|
394
|
-
if (id === "@moostjs/vite/server") return false;
|
|
395
|
-
return defaultExternals.some((ext) => ext.test(id));
|
|
396
|
-
},
|
|
397
398
|
output: { format: "esm" }
|
|
398
399
|
}
|
|
399
400
|
},
|
package/dist/prod-server.cjs
CHANGED
|
@@ -80,10 +80,12 @@ async function createSSRServer(options) {
|
|
|
80
80
|
const { MoostHttp, enableLocalFetch } = await import("@moostjs/event-http");
|
|
81
81
|
let moostHandler = null;
|
|
82
82
|
const moostHttpRef = { instance: null };
|
|
83
|
+
let captured = false;
|
|
83
84
|
const origListen = MoostHttp.prototype.listen;
|
|
84
85
|
MoostHttp.prototype.listen = function(...args) {
|
|
85
86
|
moostHandler = this.getServerCb();
|
|
86
87
|
moostHttpRef.instance = this;
|
|
88
|
+
captured = true;
|
|
87
89
|
setTimeout(() => args.filter((a) => typeof a === "function").forEach((a) => a()), 1);
|
|
88
90
|
return Promise.resolve();
|
|
89
91
|
};
|
|
@@ -93,6 +95,11 @@ async function createSSRServer(options) {
|
|
|
93
95
|
opts.entry
|
|
94
96
|
);
|
|
95
97
|
else await import(__MOOST_ENTRY__);
|
|
98
|
+
if (!captured) {
|
|
99
|
+
const deadline = Date.now() + 3e4;
|
|
100
|
+
while (!captured && Date.now() < deadline) await new Promise((resolve) => setTimeout(resolve, 10));
|
|
101
|
+
if (!captured) console.warn("[moost-vite] MoostHttp.listen was not called within 30s after entry import. The Moost HTTP handler will not be active. Ensure your entry uses top-level await for async setup.");
|
|
102
|
+
}
|
|
96
103
|
MoostHttp.prototype.listen = origListen;
|
|
97
104
|
if (enableLocalFetch && moostHttpRef.instance) enableLocalFetch(moostHttpRef.instance);
|
|
98
105
|
const sirv = (await import("sirv")).default;
|
package/dist/prod-server.mjs
CHANGED
|
@@ -81,10 +81,12 @@ async function createSSRServer(options) {
|
|
|
81
81
|
const { MoostHttp, enableLocalFetch } = await import("@moostjs/event-http");
|
|
82
82
|
let moostHandler = null;
|
|
83
83
|
const moostHttpRef = { instance: null };
|
|
84
|
+
let captured = false;
|
|
84
85
|
const origListen = MoostHttp.prototype.listen;
|
|
85
86
|
MoostHttp.prototype.listen = function(...args) {
|
|
86
87
|
moostHandler = this.getServerCb();
|
|
87
88
|
moostHttpRef.instance = this;
|
|
89
|
+
captured = true;
|
|
88
90
|
setTimeout(() => args.filter((a) => typeof a === "function").forEach((a) => a()), 1);
|
|
89
91
|
return Promise.resolve();
|
|
90
92
|
};
|
|
@@ -94,6 +96,11 @@ async function createSSRServer(options) {
|
|
|
94
96
|
opts.entry
|
|
95
97
|
);
|
|
96
98
|
else await import(__MOOST_ENTRY__);
|
|
99
|
+
if (!captured) {
|
|
100
|
+
const deadline = Date.now() + 3e4;
|
|
101
|
+
while (!captured && Date.now() < deadline) await new Promise((resolve) => setTimeout(resolve, 10));
|
|
102
|
+
if (!captured) console.warn("[moost-vite] MoostHttp.listen was not called within 30s after entry import. The Moost HTTP handler will not be active. Ensure your entry uses top-level await for async setup.");
|
|
103
|
+
}
|
|
97
104
|
MoostHttp.prototype.listen = origListen;
|
|
98
105
|
if (enableLocalFetch && moostHttpRef.instance) enableLocalFetch(moostHttpRef.instance);
|
|
99
106
|
const sirv = (await import("sirv")).default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/vite",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12",
|
|
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.12",
|
|
62
|
+
"moost": "^0.6.12"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"sirv": {
|