@netlify/plugin-nextjs 5.9.0 → 5.9.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.
Files changed (35) hide show
  1. package/dist/build/content/prerendered.js +2 -2
  2. package/dist/build/content/static.js +2 -2
  3. package/dist/build/functions/edge.js +1 -1
  4. package/dist/esm-chunks/{chunk-BFYMHE3E.js → chunk-HGXG447M.js} +13 -0
  5. package/dist/esm-chunks/chunk-LVXJQ2G2.js +147 -0
  6. package/dist/esm-chunks/{chunk-KBX7SJLC.js → chunk-NEZW7TGG.js} +1 -1
  7. package/dist/esm-chunks/{next-4L47PQSM.js → next-H2VMRX5P.js} +2 -4
  8. package/dist/esm-chunks/{package-LCNINN36.js → package-36IBNZ37.js} +2 -2
  9. package/dist/index.js +4 -4
  10. package/dist/run/handlers/cache.cjs +251 -139
  11. package/dist/run/handlers/request-context.cjs +88 -63
  12. package/dist/run/handlers/server.js +4 -4
  13. package/dist/run/handlers/tracer.cjs +88 -57
  14. package/dist/run/handlers/tracing.js +2 -2
  15. package/dist/run/handlers/wait-until.cjs +88 -57
  16. package/dist/run/next.cjs +88 -59
  17. package/edge-runtime/lib/middleware.ts +1 -1
  18. package/edge-runtime/lib/response.ts +5 -2
  19. package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter.js +1218 -0
  20. package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter_bg.wasm +0 -0
  21. package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/src/index.ts +80 -0
  22. package/edge-runtime/vendor/deno.land/x/{html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts → htmlrewriter@v1.0.0/src/types.d.ts} +8 -25
  23. package/edge-runtime/vendor/import_map.json +0 -2
  24. package/edge-runtime/vendor.ts +1 -1
  25. package/package.json +1 -1
  26. package/dist/esm-chunks/chunk-NDSDIXRD.js +0 -122
  27. package/edge-runtime/vendor/deno.land/std@0.134.0/fmt/colors.ts +0 -536
  28. package/edge-runtime/vendor/deno.land/std@0.134.0/testing/_diff.ts +0 -360
  29. package/edge-runtime/vendor/deno.land/std@0.134.0/testing/asserts.ts +0 -866
  30. package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +0 -133
  31. package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +0 -112
  32. package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +0 -974
  33. package/edge-runtime/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +0 -50
  34. package/dist/esm-chunks/{chunk-BVYZSEV6.js → chunk-J4D25YDX.js} +3 -3
  35. package/dist/esm-chunks/{chunk-HWMLYAVP.js → chunk-NTLBFRPA.js} +3 -3
@@ -1,133 +0,0 @@
1
- // FIXME: replace multiple 1 import from skypack!?
2
- import type {
3
- HTMLRewriter as BaseHTMLRewriter,
4
- ContentTypeOptions,
5
- Element,
6
- EndTag,
7
- Comment,
8
- TextChunk,
9
- Doctype,
10
- DocumentEnd,
11
- ElementHandlers,
12
- DocumentHandlers,
13
- } from "./vendor/html_rewriter.d.ts";
14
- import * as _base from './vendor/html_rewriter.js'
15
- const { default: initWASM } = _base;
16
- const base: typeof import("./vendor/html_rewriter.d.ts") = _base;
17
-
18
- export type {
19
- ContentTypeOptions,
20
- Element,
21
- EndTag,
22
- Comment,
23
- TextChunk,
24
- Doctype,
25
- DocumentEnd,
26
- ElementHandlers,
27
- DocumentHandlers,
28
- }
29
-
30
- import { ResolvablePromise } from 'https://ghuc.cc/worker-tools/resolvable-promise/index.ts'
31
-
32
- type SelectorElementHandlers = [selector: string, handlers: ElementHandlers];
33
-
34
- const kEnableEsiTags = Symbol("kEnableEsiTags");
35
-
36
- // In case a server doesn't return the proper mime type (e.g. githubusercontent.com)..
37
- const toWASMResponse = (response: Response) => {
38
- if (response.headers.get('content-type')?.startsWith('application/wasm')) return response;
39
- const { body, headers: hs, ...props } = response
40
- const headers = new Headers(hs)
41
- headers.set('content-type', 'application/wasm')
42
- return new Response(body, { ...props, headers })
43
- }
44
-
45
- const initialized = new ResolvablePromise<void>();
46
- let executing = false;
47
-
48
- export class HTMLRewriter {
49
- readonly #elementHandlers: SelectorElementHandlers[] = [];
50
- readonly #documentHandlers: DocumentHandlers[] = [];
51
- [kEnableEsiTags] = false;
52
-
53
- constructor() {
54
- if (!initialized.settled && !executing) {
55
- executing = true;
56
- fetch(new URL("./vendor/html_rewriter_bg.wasm", import.meta.url).href)
57
- .then(r => r.ok ? r : (() => { throw Error('WASM response not ok') })())
58
- .then(toWASMResponse)
59
- .then(initWASM)
60
- .then(() => initialized.resolve())
61
- .catch(err => {
62
- executing = false;
63
- console.error(err);
64
- })
65
- }
66
- }
67
-
68
- on(selector: string, handlers: ElementHandlers): this {
69
- this.#elementHandlers.push([selector, handlers]);
70
- return this;
71
- }
72
-
73
- onDocument(handlers: DocumentHandlers): this {
74
- this.#documentHandlers.push(handlers);
75
- return this;
76
- }
77
-
78
- transform(response: Response): Response {
79
- const body = response.body as ReadableStream<Uint8Array> | null;
80
- // HTMLRewriter doesn't run the end handler if the body is null, so it's
81
- // pointless to setup the transform stream.
82
- if (body === null) return new Response(body, response);
83
-
84
- if (response instanceof Response) {
85
- // Make sure we validate chunks are BufferSources and convert them to
86
- // Uint8Arrays as required by the Rust glue code.
87
- response = new Response(response.body, response);
88
- }
89
-
90
- let rewriter: BaseHTMLRewriter;
91
- const transformStream = new TransformStream<Uint8Array, Uint8Array>({
92
- start: async (controller) => {
93
- // Create a rewriter instance for this transformation that writes its
94
- // output to the transformed response's stream. Note that each
95
- // BaseHTMLRewriter can only be used once.
96
- await initialized;
97
- rewriter = new base.HTMLRewriter(
98
- (output) => {
99
- // enqueue will throw on empty chunks
100
- if (output.length !== 0) controller.enqueue(output);
101
- },
102
- { enableEsiTags: this[kEnableEsiTags] }
103
- );
104
- // Add all registered handlers
105
- for (const [selector, handlers] of this.#elementHandlers) {
106
- rewriter.on(selector, handlers);
107
- }
108
- for (const handlers of this.#documentHandlers) {
109
- rewriter.onDocument(handlers);
110
- }
111
- },
112
- // The finally() below will ensure the rewriter is always freed.
113
- // chunk is guaranteed to be a Uint8Array as we're using the
114
- // @miniflare/core Response class, which transforms to a byte stream.
115
- transform: (chunk) => rewriter.write(chunk),
116
- flush: () => rewriter.end(),
117
- });
118
- const promise = body.pipeTo(transformStream.writable);
119
- promise.catch(() => {}).finally(() => rewriter?.free());
120
-
121
- // Return a response with the transformed body, copying over headers, etc
122
- const res = new Response(transformStream.readable, response);
123
- // If Content-Length is set, it's probably going to be wrong, since we're
124
- // rewriting content, so remove it
125
- res.headers.delete("Content-Length");
126
- return res;
127
- }
128
- }
129
-
130
- export function withEnableEsiTags(rewriter: HTMLRewriter): HTMLRewriter {
131
- rewriter[kEnableEsiTags] = true;
132
- return rewriter;
133
- }
@@ -1,112 +0,0 @@
1
- import { assert, assertEquals } from "https://deno.land/std@0.134.0/testing/asserts.ts";
2
-
3
- /**
4
- * @typedef {object} WasmExports
5
- * @property {WebAssembly.Memory} memory
6
- * @property {function} asyncify_get_state
7
- * @property {function} asyncify_start_unwind
8
- * @property {function} asyncify_stop_unwind
9
- * @property {function} asyncify_start_rewind
10
- * @property {function} asyncify_stop_rewind
11
- */
12
-
13
- /**
14
- * @type {WasmExports}
15
- */
16
- let wasm;
17
-
18
- /**
19
- * @param {WasmExports} wasmExports
20
- */
21
- function setWasmExports(wasmExports) {
22
- wasm = wasmExports;
23
- }
24
-
25
- /**
26
- * @type {Int32Array}
27
- */
28
- let cachedInt32Memory = null;
29
-
30
- /**
31
- * @returns {Int32Array}
32
- */
33
- function getInt32Memory() {
34
- if (
35
- cachedInt32Memory === null ||
36
- cachedInt32Memory.buffer !== wasm.memory.buffer
37
- ) {
38
- cachedInt32Memory = new Int32Array(wasm.memory.buffer);
39
- }
40
- return cachedInt32Memory;
41
- }
42
-
43
- // https://github.com/WebAssembly/binaryen/blob/fb9de9d391a7272548dcc41cd8229076189d7398/src/passes/Asyncify.cpp#L99
44
- const State = {
45
- NONE: 0,
46
- UNWINDING: 1,
47
- REWINDING: 2,
48
- };
49
-
50
- function assertNoneState() {
51
- assertEquals(wasm.asyncify_get_state(), State.NONE);
52
- }
53
-
54
- /**
55
- * Maps `HTMLRewriter`s (their `asyncifyStackPtr`s) to `Promise`s.
56
- * `asyncifyStackPtr` acts as unique reference to `HTMLRewriter`.
57
- * Each rewriter MUST have AT MOST ONE pending promise at any time.
58
- * @type {Map<number, Promise>}
59
- */
60
- const promises = new Map();
61
-
62
- /**
63
- * @param {number} stackPtr
64
- * @param {Promise} promise
65
- */
66
- function awaitPromise(stackPtr, promise) {
67
- if (wasm.asyncify_get_state() === State.REWINDING) {
68
- wasm.asyncify_stop_rewind();
69
- return;
70
- }
71
-
72
- assertNoneState();
73
-
74
- // https://github.com/WebAssembly/binaryen/blob/fb9de9d391a7272548dcc41cd8229076189d7398/src/passes/Asyncify.cpp#L106
75
- assertEquals(stackPtr % 4, 0);
76
- getInt32Memory().set([stackPtr + 8, stackPtr + 1024], stackPtr / 4);
77
-
78
- wasm.asyncify_start_unwind(stackPtr);
79
-
80
- assert(!promises.has(stackPtr));
81
- promises.set(stackPtr, promise);
82
- }
83
-
84
- /**
85
- * @param {HTMLRewriter} rewriter
86
- * @param {Function} fn
87
- * @param args
88
- */
89
- async function wrap(rewriter, fn, ...args) {
90
- const stackPtr = rewriter.asyncifyStackPtr;
91
-
92
- assertNoneState();
93
- let result = fn(...args);
94
-
95
- while (wasm.asyncify_get_state() === State.UNWINDING) {
96
- wasm.asyncify_stop_unwind();
97
-
98
- assertNoneState();
99
- assert(promises.has(stackPtr));
100
- await promises.get(stackPtr);
101
- promises.delete(stackPtr);
102
-
103
- assertNoneState();
104
- wasm.asyncify_start_rewind(stackPtr);
105
- result = fn();
106
- }
107
-
108
- assertNoneState();
109
- return result;
110
- }
111
-
112
- export { awaitPromise, setWasmExports, wrap };