vike-lite 1.16.0 → 1.16.2
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.
|
@@ -6,8 +6,8 @@ import fs from 'node:fs'
|
|
|
6
6
|
import fsPromises from 'node:fs/promises'
|
|
7
7
|
import path from 'node:path'
|
|
8
8
|
import { fileURLToPath } from 'node:url'
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const clientDir = path.resolve(import.meta.dirname, '../client')
|
|
10
|
+
const assetsDir = path.join(clientDir, 'assets')
|
|
11
11
|
const MIME_TYPES = {
|
|
12
12
|
'.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8',
|
|
13
13
|
'.mjs': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8',
|
|
@@ -29,7 +29,8 @@ const server = createServer(async (req, res) => {
|
|
|
29
29
|
const { BASE_URL } = import.meta.env
|
|
30
30
|
if (BASE_URL !== '/' && pathname.startsWith(BASE_URL)) fileUrl = '/' + pathname.slice(BASE_URL.length)
|
|
31
31
|
if (fileUrl !== '/') {
|
|
32
|
-
const
|
|
32
|
+
const normalizedUrl = path.normalize(fileUrl)
|
|
33
|
+
const filePath = path.resolve(clientDir, '.' + normalizedUrl)
|
|
33
34
|
if (!filePath.startsWith(clientDir)) {
|
|
34
35
|
res.statusCode = 403
|
|
35
36
|
res.end('Forbidden')
|
|
@@ -41,10 +42,7 @@ const server = createServer(async (req, res) => {
|
|
|
41
42
|
const ext = path.extname(filePath).toLowerCase()
|
|
42
43
|
const mimeType = MIME_TYPES[ext] || 'application/octet-stream'
|
|
43
44
|
res.setHeader('Content-Type', mimeType)
|
|
44
|
-
res.setHeader(
|
|
45
|
-
'Cache-Control',
|
|
46
|
-
fileUrl.startsWith('/assets/') ? 'public, max-age=31536000, immutable' : 'public, max-age=0, must-revalidate'
|
|
47
|
-
)
|
|
45
|
+
res.setHeader('Cache-Control', filePath.startsWith(assetsDir) ? 'public, max-age=31536000, immutable' : 'public, max-age=0, must-revalidate')
|
|
48
46
|
fs.createReadStream(filePath).pipe(res)
|
|
49
47
|
return
|
|
50
48
|
}
|
|
@@ -27,19 +27,17 @@ declare function createDepsConfigPlugin({ packageName, optimizeDepsInclude }: {
|
|
|
27
27
|
*
|
|
28
28
|
* This centralizes logic that is otherwise identical across every `vike-lite-*` package.
|
|
29
29
|
*/
|
|
30
|
-
declare function createFrameworkAdapterPlugin({ packageName, hydration,
|
|
30
|
+
declare function createFrameworkAdapterPlugin({ packageName, hydration, streaming }: {
|
|
31
31
|
/** The framework adapter's package name, e.g. 'vike-lite-react'. */
|
|
32
32
|
packageName: string;
|
|
33
33
|
/** @default true */
|
|
34
34
|
hydration?: boolean;
|
|
35
|
-
/** @default true */
|
|
36
|
-
wrapServerHydration?: boolean;
|
|
37
35
|
/**
|
|
38
36
|
* Stream the server-rendered app markup via the framework's Web Streams-based
|
|
39
37
|
* SSR API instead of buffering it into a single string. Threaded through to
|
|
40
38
|
* `onRenderHtml` the same way `hydration` is. Ignored by adapters whose
|
|
41
39
|
* `onRenderHtml` doesn't accept a `streaming` option.
|
|
42
|
-
* @default
|
|
40
|
+
* @default true
|
|
43
41
|
*/
|
|
44
42
|
streaming?: boolean;
|
|
45
43
|
}): Plugin;
|
package/dist/__internal/vite.mjs
CHANGED
|
@@ -35,7 +35,7 @@ function createDepsConfigPlugin({ packageName, optimizeDepsInclude }) {
|
|
|
35
35
|
*
|
|
36
36
|
* This centralizes logic that is otherwise identical across every `vike-lite-*` package.
|
|
37
37
|
*/
|
|
38
|
-
function createFrameworkAdapterPlugin({ packageName, hydration = true,
|
|
38
|
+
function createFrameworkAdapterPlugin({ packageName, hydration = true, streaming = true }) {
|
|
39
39
|
const virtualClientId = "virtual:vike-lite/client";
|
|
40
40
|
const virtualServerId = "virtual:vike-lite/server";
|
|
41
41
|
const resolvedVirtualClientId = "\0virtual:vike-lite/client";
|
|
@@ -49,7 +49,7 @@ function createFrameworkAdapterPlugin({ packageName, hydration = true, wrapServe
|
|
|
49
49
|
},
|
|
50
50
|
load(id) {
|
|
51
51
|
if (id === resolvedVirtualClientId) return `export const onRenderClient=async(options)=>(await import("${packageName}/__internal/client/onRenderClient")).onRenderClient({...options,hydration:${hydration}});`;
|
|
52
|
-
if (id === resolvedVirtualServerId) return `import
|
|
52
|
+
if (id === resolvedVirtualServerId) return `import{onRenderHtml as _onRenderHtml}from'${packageName}/__internal/server/onRenderHtml';export const onRenderHtml=(ctx)=>_onRenderHtml({...ctx,hydration:${hydration},streaming:${streaming}});`;
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
}
|
package/dist/vite.mjs
CHANGED
|
@@ -389,15 +389,21 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
389
389
|
for (const [key, value] of response.headers) if (key.toLowerCase() !== "set-cookie") res.setHeader(key, value);
|
|
390
390
|
const cookies = response.headers.getSetCookie();
|
|
391
391
|
if (cookies.length > 0) res.setHeader("Set-Cookie", cookies);
|
|
392
|
+
async function safeCancelBody(body) {
|
|
393
|
+
if (!body || body.locked) return;
|
|
394
|
+
try {
|
|
395
|
+
await body.cancel();
|
|
396
|
+
} catch {}
|
|
397
|
+
}
|
|
392
398
|
if (response.headers.get("content-type")?.includes("text/html")) {
|
|
393
399
|
res.removeHeader("content-length");
|
|
394
400
|
server.config.logger.info(`📄 Page: ${req.url}`, { timestamp: true });
|
|
395
401
|
if (req.method === "HEAD" || !response.body) {
|
|
396
|
-
await response.body
|
|
402
|
+
await safeCancelBody(response.body);
|
|
397
403
|
return res.end();
|
|
398
404
|
}
|
|
399
405
|
if (res.destroyed || res.closed) {
|
|
400
|
-
await response.body
|
|
406
|
+
await safeCancelBody(response.body);
|
|
401
407
|
return;
|
|
402
408
|
}
|
|
403
409
|
let headBuffered = "";
|
|
@@ -435,12 +441,12 @@ function vikeLite({ pagesDir = "pages", apiPrefix = "/api", prerender = false, s
|
|
|
435
441
|
return;
|
|
436
442
|
}
|
|
437
443
|
if (req.method === "HEAD" || !response.body) {
|
|
438
|
-
await response.body
|
|
444
|
+
await safeCancelBody(response.body);
|
|
439
445
|
if (!res.destroyed && !res.closed) res.end();
|
|
440
446
|
return;
|
|
441
447
|
}
|
|
442
448
|
if (res.destroyed || res.closed) {
|
|
443
|
-
await response.body
|
|
449
|
+
await safeCancelBody(response.body);
|
|
444
450
|
return;
|
|
445
451
|
}
|
|
446
452
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike-lite",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@types/node": "^26.1.1",
|
|
85
|
-
"tsdown": "^0.22.
|
|
85
|
+
"tsdown": "^0.22.14",
|
|
86
86
|
"vite": "^8.1.5",
|
|
87
87
|
"vitest": "^4.1.10"
|
|
88
88
|
},
|