@moostjs/vite 0.6.4 → 0.6.5
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 +7 -7
- package/dist/index.mjs +7 -7
- package/dist/prod-server.cjs +19 -18
- package/dist/prod-server.mjs +19 -18
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -342,8 +342,8 @@ function moostVite(options) {
|
|
|
342
342
|
if (!prefix.startsWith("/")) prefix = `/${prefix}`;
|
|
343
343
|
if (prefix.endsWith("/")) prefix = prefix.slice(0, -1);
|
|
344
344
|
}
|
|
345
|
-
const prefixSlash = prefix ? prefix
|
|
346
|
-
const prefixQuery = prefix ? prefix
|
|
345
|
+
const prefixSlash = prefix ? `${prefix}/` : void 0;
|
|
346
|
+
const prefixQuery = prefix ? `${prefix}?` : void 0;
|
|
347
347
|
let moostMiddleware = null;
|
|
348
348
|
let localFetchTeardown = null;
|
|
349
349
|
/** In middleware mode: maps req → next() for the onNoMatch callback */ const pendingNextMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -571,18 +571,18 @@ function moostVite(options) {
|
|
|
571
571
|
if (req.method !== "GET") return next();
|
|
572
572
|
const url = req.originalUrl || req.url || "/";
|
|
573
573
|
try {
|
|
574
|
-
let template = await fs.readFile((0, node_path.resolve)(process.cwd(), "index.html"), "
|
|
574
|
+
let template = await fs.readFile((0, node_path.resolve)(process.cwd(), "index.html"), "utf8");
|
|
575
575
|
template = await server.transformIndexHtml(url, template);
|
|
576
576
|
const { render } = await server.ssrLoadModule(options.ssrEntry);
|
|
577
577
|
const { html: appHtml, state } = await render(url);
|
|
578
578
|
res.statusCode = 200;
|
|
579
579
|
res.setHeader("Content-Type", "text/html");
|
|
580
580
|
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}</script>` : ""));
|
|
581
|
-
} catch (
|
|
582
|
-
server.ssrFixStacktrace(
|
|
583
|
-
console.error(
|
|
581
|
+
} catch (error) {
|
|
582
|
+
server.ssrFixStacktrace(error);
|
|
583
|
+
console.error(error);
|
|
584
584
|
res.statusCode = 500;
|
|
585
|
-
res.end(
|
|
585
|
+
res.end(error.message);
|
|
586
586
|
}
|
|
587
587
|
});
|
|
588
588
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -319,8 +319,8 @@ function moostVite(options) {
|
|
|
319
319
|
if (!prefix.startsWith("/")) prefix = `/${prefix}`;
|
|
320
320
|
if (prefix.endsWith("/")) prefix = prefix.slice(0, -1);
|
|
321
321
|
}
|
|
322
|
-
const prefixSlash = prefix ? prefix
|
|
323
|
-
const prefixQuery = prefix ? prefix
|
|
322
|
+
const prefixSlash = prefix ? `${prefix}/` : void 0;
|
|
323
|
+
const prefixQuery = prefix ? `${prefix}?` : void 0;
|
|
324
324
|
let moostMiddleware = null;
|
|
325
325
|
let localFetchTeardown = null;
|
|
326
326
|
/** In middleware mode: maps req → next() for the onNoMatch callback */ const pendingNextMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -548,18 +548,18 @@ function moostVite(options) {
|
|
|
548
548
|
if (req.method !== "GET") return next();
|
|
549
549
|
const url = req.originalUrl || req.url || "/";
|
|
550
550
|
try {
|
|
551
|
-
let template = await fs.readFile(resolve(process.cwd(), "index.html"), "
|
|
551
|
+
let template = await fs.readFile(resolve(process.cwd(), "index.html"), "utf8");
|
|
552
552
|
template = await server.transformIndexHtml(url, template);
|
|
553
553
|
const { render } = await server.ssrLoadModule(options.ssrEntry);
|
|
554
554
|
const { html: appHtml, state } = await render(url);
|
|
555
555
|
res.statusCode = 200;
|
|
556
556
|
res.setHeader("Content-Type", "text/html");
|
|
557
557
|
res.end(template.replace(ssrOutlet, appHtml).replace(ssrState, state ? `<script>window.__SSR_STATE__=${state}</script>` : ""));
|
|
558
|
-
} catch (
|
|
559
|
-
server.ssrFixStacktrace(
|
|
560
|
-
console.error(
|
|
558
|
+
} catch (error) {
|
|
559
|
+
server.ssrFixStacktrace(error);
|
|
560
|
+
console.error(error);
|
|
561
561
|
res.statusCode = 500;
|
|
562
|
-
res.end(
|
|
562
|
+
res.end(error.message);
|
|
563
563
|
}
|
|
564
564
|
});
|
|
565
565
|
};
|
package/dist/prod-server.cjs
CHANGED
|
@@ -59,18 +59,18 @@ async function createSSRServer(options) {
|
|
|
59
59
|
if (req.method !== "GET") return next();
|
|
60
60
|
const url = req.originalUrl || req.url || "/";
|
|
61
61
|
try {
|
|
62
|
-
let template$1 = await fs$1.readFile(path$1.resolve(process.cwd(), "index.html"), "
|
|
62
|
+
let template$1 = await fs$1.readFile(path$1.resolve(process.cwd(), "index.html"), "utf8");
|
|
63
63
|
template$1 = await vite.transformIndexHtml(url, template$1);
|
|
64
64
|
const { render: render$1 } = await vite.ssrLoadModule(ssrEntry);
|
|
65
65
|
const { html: appHtml, state } = await render$1(url);
|
|
66
66
|
res.statusCode = 200;
|
|
67
67
|
res.setHeader("Content-Type", "text/html");
|
|
68
68
|
res.end(template$1.replace(ssrOutlet$1, appHtml).replace(ssrState$1, state ? `<script>window.__SSR_STATE__=${state}</script>` : ""));
|
|
69
|
-
} catch (
|
|
70
|
-
vite.ssrFixStacktrace(
|
|
71
|
-
console.error(
|
|
69
|
+
} catch (error) {
|
|
70
|
+
vite.ssrFixStacktrace(error);
|
|
71
|
+
console.error(error);
|
|
72
72
|
res.statusCode = 500;
|
|
73
|
-
res.end(
|
|
73
|
+
res.end(error.message);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
}
|
|
@@ -90,16 +90,16 @@ async function createSSRServer(options) {
|
|
|
90
90
|
const path = await import("node:path");
|
|
91
91
|
const { createServer: createHttpServer } = await import("node:http");
|
|
92
92
|
const clientDir = opts.clientDir || path.resolve(__dirname, "../client");
|
|
93
|
-
const ssrOutlet = opts.ssrOutlet || (
|
|
94
|
-
const ssrState = opts.ssrState || (
|
|
93
|
+
const ssrOutlet = opts.ssrOutlet || (__MOOST_SSR_OUTLET__ !== void 0 ? __MOOST_SSR_OUTLET__ : "<!--ssr-outlet-->");
|
|
94
|
+
const ssrState = opts.ssrState || (__MOOST_SSR_STATE__ !== void 0 ? __MOOST_SSR_STATE__ : "<!--ssr-state-->");
|
|
95
95
|
let prefix = opts.prefix || __MOOST_PREFIX__;
|
|
96
96
|
if (!prefix.startsWith("/")) prefix = `/${prefix}`;
|
|
97
97
|
if (prefix.endsWith("/")) prefix = prefix.slice(0, -1);
|
|
98
|
-
const prefixSlash = prefix
|
|
98
|
+
const prefixSlash = `${prefix}/`;
|
|
99
99
|
const defaultPort = opts.port || Number(process.env.PORT) || 3e3;
|
|
100
|
-
const template = await fs.readFile(path.resolve(clientDir, "index.html"), "
|
|
100
|
+
const template = await fs.readFile(path.resolve(clientDir, "index.html"), "utf8");
|
|
101
101
|
let render = null;
|
|
102
|
-
const hasSsr =
|
|
102
|
+
const hasSsr = __MOOST_SSR_ENTRY__ !== void 0 && !!__MOOST_SSR_ENTRY__;
|
|
103
103
|
if (hasSsr) {
|
|
104
104
|
const ssrModule = await import(
|
|
105
105
|
/* @vite-ignore */
|
|
@@ -108,11 +108,11 @@ async function createSSRServer(options) {
|
|
|
108
108
|
}
|
|
109
109
|
const { MoostHttp, enableLocalFetch } = await import("@moostjs/event-http");
|
|
110
110
|
let moostHandler = null;
|
|
111
|
-
|
|
111
|
+
const moostHttpRef = { instance: null };
|
|
112
112
|
const origListen = MoostHttp.prototype.listen;
|
|
113
113
|
MoostHttp.prototype.listen = function(...args) {
|
|
114
114
|
moostHandler = this.getServerCb();
|
|
115
|
-
|
|
115
|
+
moostHttpRef.instance = this;
|
|
116
116
|
setTimeout(() => args.filter((a) => typeof a === "function").forEach((a) => a()), 1);
|
|
117
117
|
return Promise.resolve();
|
|
118
118
|
};
|
|
@@ -122,8 +122,9 @@ async function createSSRServer(options) {
|
|
|
122
122
|
opts.entry);
|
|
123
123
|
else await import(__MOOST_ENTRY__);
|
|
124
124
|
MoostHttp.prototype.listen = origListen;
|
|
125
|
-
if (enableLocalFetch &&
|
|
126
|
-
const
|
|
125
|
+
if (enableLocalFetch && moostHttpRef.instance) enableLocalFetch(moostHttpRef.instance);
|
|
126
|
+
const sirvModule = await import("sirv");
|
|
127
|
+
const sirv = sirvModule.default;
|
|
127
128
|
const serve = sirv(path.resolve(clientDir), { extensions: [] });
|
|
128
129
|
return {
|
|
129
130
|
use(mw) {
|
|
@@ -139,7 +140,7 @@ async function createSSRServer(options) {
|
|
|
139
140
|
userMiddlewares[i++](req, res, runNext);
|
|
140
141
|
return;
|
|
141
142
|
}
|
|
142
|
-
if (moostHandler && (url.startsWith(prefixSlash) || url === prefix || url.startsWith(prefix
|
|
143
|
+
if (moostHandler && (url.startsWith(prefixSlash) || url === prefix || url.startsWith(`${prefix}?`))) {
|
|
143
144
|
moostHandler(req, res);
|
|
144
145
|
return;
|
|
145
146
|
}
|
|
@@ -160,10 +161,10 @@ async function createSSRServer(options) {
|
|
|
160
161
|
res.setHeader("Content-Type", "text/html");
|
|
161
162
|
res.end(template);
|
|
162
163
|
}
|
|
163
|
-
} catch (
|
|
164
|
-
console.error(
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error(error);
|
|
165
166
|
res.statusCode = 500;
|
|
166
|
-
res.end(
|
|
167
|
+
res.end(error.message);
|
|
167
168
|
}
|
|
168
169
|
});
|
|
169
170
|
};
|
package/dist/prod-server.mjs
CHANGED
|
@@ -36,18 +36,18 @@ async function createSSRServer(options) {
|
|
|
36
36
|
if (req.method !== "GET") return next();
|
|
37
37
|
const url = req.originalUrl || req.url || "/";
|
|
38
38
|
try {
|
|
39
|
-
let template$1 = await fs$1.readFile(path$1.resolve(process.cwd(), "index.html"), "
|
|
39
|
+
let template$1 = await fs$1.readFile(path$1.resolve(process.cwd(), "index.html"), "utf8");
|
|
40
40
|
template$1 = await vite.transformIndexHtml(url, template$1);
|
|
41
41
|
const { render: render$1 } = await vite.ssrLoadModule(ssrEntry);
|
|
42
42
|
const { html: appHtml, state } = await render$1(url);
|
|
43
43
|
res.statusCode = 200;
|
|
44
44
|
res.setHeader("Content-Type", "text/html");
|
|
45
45
|
res.end(template$1.replace(ssrOutlet$1, appHtml).replace(ssrState$1, state ? `<script>window.__SSR_STATE__=${state}</script>` : ""));
|
|
46
|
-
} catch (
|
|
47
|
-
vite.ssrFixStacktrace(
|
|
48
|
-
console.error(
|
|
46
|
+
} catch (error) {
|
|
47
|
+
vite.ssrFixStacktrace(error);
|
|
48
|
+
console.error(error);
|
|
49
49
|
res.statusCode = 500;
|
|
50
|
-
res.end(
|
|
50
|
+
res.end(error.message);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
}
|
|
@@ -67,16 +67,16 @@ async function createSSRServer(options) {
|
|
|
67
67
|
const path = await import("node:path");
|
|
68
68
|
const { createServer: createHttpServer } = await import("node:http");
|
|
69
69
|
const clientDir = opts.clientDir || path.resolve(import.meta.dirname, "../client");
|
|
70
|
-
const ssrOutlet = opts.ssrOutlet || (
|
|
71
|
-
const ssrState = opts.ssrState || (
|
|
70
|
+
const ssrOutlet = opts.ssrOutlet || (__MOOST_SSR_OUTLET__ !== void 0 ? __MOOST_SSR_OUTLET__ : "<!--ssr-outlet-->");
|
|
71
|
+
const ssrState = opts.ssrState || (__MOOST_SSR_STATE__ !== void 0 ? __MOOST_SSR_STATE__ : "<!--ssr-state-->");
|
|
72
72
|
let prefix = opts.prefix || __MOOST_PREFIX__;
|
|
73
73
|
if (!prefix.startsWith("/")) prefix = `/${prefix}`;
|
|
74
74
|
if (prefix.endsWith("/")) prefix = prefix.slice(0, -1);
|
|
75
|
-
const prefixSlash = prefix
|
|
75
|
+
const prefixSlash = `${prefix}/`;
|
|
76
76
|
const defaultPort = opts.port || Number(process.env.PORT) || 3e3;
|
|
77
|
-
const template = await fs.readFile(path.resolve(clientDir, "index.html"), "
|
|
77
|
+
const template = await fs.readFile(path.resolve(clientDir, "index.html"), "utf8");
|
|
78
78
|
let render = null;
|
|
79
|
-
const hasSsr =
|
|
79
|
+
const hasSsr = __MOOST_SSR_ENTRY__ !== void 0 && !!__MOOST_SSR_ENTRY__;
|
|
80
80
|
if (hasSsr) {
|
|
81
81
|
const ssrModule = await import(
|
|
82
82
|
/* @vite-ignore */
|
|
@@ -85,11 +85,11 @@ async function createSSRServer(options) {
|
|
|
85
85
|
}
|
|
86
86
|
const { MoostHttp, enableLocalFetch } = await import("@moostjs/event-http");
|
|
87
87
|
let moostHandler = null;
|
|
88
|
-
|
|
88
|
+
const moostHttpRef = { instance: null };
|
|
89
89
|
const origListen = MoostHttp.prototype.listen;
|
|
90
90
|
MoostHttp.prototype.listen = function(...args) {
|
|
91
91
|
moostHandler = this.getServerCb();
|
|
92
|
-
|
|
92
|
+
moostHttpRef.instance = this;
|
|
93
93
|
setTimeout(() => args.filter((a) => typeof a === "function").forEach((a) => a()), 1);
|
|
94
94
|
return Promise.resolve();
|
|
95
95
|
};
|
|
@@ -99,8 +99,9 @@ async function createSSRServer(options) {
|
|
|
99
99
|
opts.entry);
|
|
100
100
|
else await import(__MOOST_ENTRY__);
|
|
101
101
|
MoostHttp.prototype.listen = origListen;
|
|
102
|
-
if (enableLocalFetch &&
|
|
103
|
-
const
|
|
102
|
+
if (enableLocalFetch && moostHttpRef.instance) enableLocalFetch(moostHttpRef.instance);
|
|
103
|
+
const sirvModule = await import("sirv");
|
|
104
|
+
const sirv = sirvModule.default;
|
|
104
105
|
const serve = sirv(path.resolve(clientDir), { extensions: [] });
|
|
105
106
|
return {
|
|
106
107
|
use(mw) {
|
|
@@ -116,7 +117,7 @@ async function createSSRServer(options) {
|
|
|
116
117
|
userMiddlewares[i++](req, res, runNext);
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
|
-
if (moostHandler && (url.startsWith(prefixSlash) || url === prefix || url.startsWith(prefix
|
|
120
|
+
if (moostHandler && (url.startsWith(prefixSlash) || url === prefix || url.startsWith(`${prefix}?`))) {
|
|
120
121
|
moostHandler(req, res);
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
@@ -137,10 +138,10 @@ async function createSSRServer(options) {
|
|
|
137
138
|
res.setHeader("Content-Type", "text/html");
|
|
138
139
|
res.end(template);
|
|
139
140
|
}
|
|
140
|
-
} catch (
|
|
141
|
-
console.error(
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error(error);
|
|
142
143
|
res.statusCode = 500;
|
|
143
|
-
res.end(
|
|
144
|
+
res.end(error.message);
|
|
144
145
|
}
|
|
145
146
|
});
|
|
146
147
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/vite",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
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.5",
|
|
62
|
+
"moost": "^0.6.5"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"sirv": {
|