@timber-js/app 0.1.43 → 0.1.45
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/adapters/compress-module.d.ts.map +1 -1
- package/dist/adapters/nitro.js +8 -30
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/client/index.js +20 -11
- package/dist/client/index.js.map +1 -1
- package/dist/client/navigation-context.d.ts.map +1 -1
- package/dist/index.js +13 -38
- package/dist/index.js.map +1 -1
- package/dist/server/compress.d.ts +11 -6
- package/dist/server/compress.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/compress-module.ts +11 -31
- package/src/client/navigation-context.ts +20 -8
- package/src/server/compress.ts +18 -62
package/dist/index.js
CHANGED
|
@@ -5,10 +5,9 @@ import { dirname, extname, join, resolve } from "node:path";
|
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import react from "@vitejs/plugin-react";
|
|
8
|
-
import { constants, createBrotliCompress, gzipSync } from "node:zlib";
|
|
9
|
-
import { Readable } from "node:stream";
|
|
10
8
|
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
11
9
|
import { createHash } from "node:crypto";
|
|
10
|
+
import { gzipSync } from "node:zlib";
|
|
12
11
|
import { performance as performance$1 } from "node:perf_hooks";
|
|
13
12
|
//#region \0rolldown/runtime.js
|
|
14
13
|
var __create = Object.create;
|
|
@@ -11547,18 +11546,21 @@ var COMPRESSIBLE_TYPES = new Set([
|
|
|
11547
11546
|
var NO_COMPRESS_STATUSES = new Set([204, 304]);
|
|
11548
11547
|
/**
|
|
11549
11548
|
* Parse Accept-Encoding and return the best supported encoding.
|
|
11550
|
-
*
|
|
11549
|
+
* Returns 'gzip' if the client accepts it, null otherwise.
|
|
11551
11550
|
*
|
|
11552
|
-
*
|
|
11553
|
-
*
|
|
11554
|
-
*
|
|
11555
|
-
*
|
|
11551
|
+
* Brotli (br) is intentionally not handled at the application level.
|
|
11552
|
+
* At the streaming-friendly quality levels (0–4), brotli's compression
|
|
11553
|
+
* ratio advantage over gzip is marginal, and node:zlib's brotli transform
|
|
11554
|
+
* buffers output internally — turning smooth streaming responses into
|
|
11555
|
+
* large infrequent bursts. Brotli's real wins come from offline/static
|
|
11556
|
+
* compression at higher quality levels (5–11), which CDNs and reverse
|
|
11557
|
+
* proxies (Cloudflare, nginx, Caddy) apply on cached responses.
|
|
11558
|
+
*
|
|
11559
|
+
* See design/25-production-deployments.md.
|
|
11556
11560
|
*/
|
|
11557
11561
|
function negotiateEncoding(acceptEncoding) {
|
|
11558
11562
|
if (!acceptEncoding) return null;
|
|
11559
|
-
|
|
11560
|
-
if (tokens.includes("br")) return "br";
|
|
11561
|
-
if (tokens.includes("gzip")) return "gzip";
|
|
11563
|
+
if (acceptEncoding.split(",").map((s) => s.split(";")[0].trim().toLowerCase()).includes("gzip")) return "gzip";
|
|
11562
11564
|
return null;
|
|
11563
11565
|
}
|
|
11564
11566
|
/**
|
|
@@ -11593,7 +11595,7 @@ function compressResponse(request, response) {
|
|
|
11593
11595
|
if (!shouldCompress(response)) return response;
|
|
11594
11596
|
const encoding = negotiateEncoding(request.headers.get("Accept-Encoding") ?? "");
|
|
11595
11597
|
if (!encoding) return response;
|
|
11596
|
-
const compressedBody =
|
|
11598
|
+
const compressedBody = compressWithGzip(response.body);
|
|
11597
11599
|
const headers = new Headers(response.headers);
|
|
11598
11600
|
headers.set("Content-Encoding", encoding);
|
|
11599
11601
|
headers.delete("Content-Length");
|
|
@@ -11615,33 +11617,6 @@ function compressWithGzip(body) {
|
|
|
11615
11617
|
const compressionStream = new CompressionStream("gzip");
|
|
11616
11618
|
return body.pipeThrough(compressionStream);
|
|
11617
11619
|
}
|
|
11618
|
-
/**
|
|
11619
|
-
* Compress a ReadableStream with brotli using node:zlib.
|
|
11620
|
-
*
|
|
11621
|
-
* CompressionStream doesn't support brotli — it only handles gzip and deflate.
|
|
11622
|
-
* We use node:zlib's createBrotliCompress() and bridge between Web streams
|
|
11623
|
-
* and Node streams.
|
|
11624
|
-
*/
|
|
11625
|
-
function compressWithBrotli(body) {
|
|
11626
|
-
const brotli = createBrotliCompress({ params: { [constants.BROTLI_PARAM_QUALITY]: 4 } });
|
|
11627
|
-
const reader = body.getReader();
|
|
11628
|
-
const pump = async () => {
|
|
11629
|
-
try {
|
|
11630
|
-
while (true) {
|
|
11631
|
-
const { done, value } = await reader.read();
|
|
11632
|
-
if (done) {
|
|
11633
|
-
brotli.end();
|
|
11634
|
-
return;
|
|
11635
|
-
}
|
|
11636
|
-
if (!brotli.write(value)) await new Promise((resolve) => brotli.once("drain", resolve));
|
|
11637
|
-
}
|
|
11638
|
-
} catch (err) {
|
|
11639
|
-
brotli.destroy(err instanceof Error ? err : new Error(String(err)));
|
|
11640
|
-
}
|
|
11641
|
-
};
|
|
11642
|
-
pump();
|
|
11643
|
-
return Readable.toWeb(brotli);
|
|
11644
|
-
}
|
|
11645
11620
|
//#endregion
|
|
11646
11621
|
//#region src/plugins/dev-server.ts
|
|
11647
11622
|
var RSC_ENTRY_ID = "virtual:timber-rsc-entry";
|