@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.
- package/dist/build/content/prerendered.js +2 -2
- package/dist/build/content/static.js +2 -2
- package/dist/build/functions/edge.js +1 -1
- package/dist/esm-chunks/{chunk-BFYMHE3E.js → chunk-HGXG447M.js} +13 -0
- package/dist/esm-chunks/chunk-LVXJQ2G2.js +147 -0
- package/dist/esm-chunks/{chunk-KBX7SJLC.js → chunk-NEZW7TGG.js} +1 -1
- package/dist/esm-chunks/{next-4L47PQSM.js → next-H2VMRX5P.js} +2 -4
- package/dist/esm-chunks/{package-LCNINN36.js → package-36IBNZ37.js} +2 -2
- package/dist/index.js +4 -4
- package/dist/run/handlers/cache.cjs +251 -139
- package/dist/run/handlers/request-context.cjs +88 -63
- package/dist/run/handlers/server.js +4 -4
- package/dist/run/handlers/tracer.cjs +88 -57
- package/dist/run/handlers/tracing.js +2 -2
- package/dist/run/handlers/wait-until.cjs +88 -57
- package/dist/run/next.cjs +88 -59
- package/edge-runtime/lib/middleware.ts +1 -1
- package/edge-runtime/lib/response.ts +5 -2
- package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter.js +1218 -0
- package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter_bg.wasm +0 -0
- package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/src/index.ts +80 -0
- 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
- package/edge-runtime/vendor/import_map.json +0 -2
- package/edge-runtime/vendor.ts +1 -1
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-NDSDIXRD.js +0 -122
- package/edge-runtime/vendor/deno.land/std@0.134.0/fmt/colors.ts +0 -536
- package/edge-runtime/vendor/deno.land/std@0.134.0/testing/_diff.ts +0 -360
- package/edge-runtime/vendor/deno.land/std@0.134.0/testing/asserts.ts +0 -866
- package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +0 -133
- package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +0 -112
- package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +0 -974
- package/edge-runtime/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +0 -50
- package/dist/esm-chunks/{chunk-BVYZSEV6.js → chunk-J4D25YDX.js} +3 -3
- package/dist/esm-chunks/{chunk-HWMLYAVP.js → chunk-NTLBFRPA.js} +3 -3
|
Binary file
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { HTMLRewriter as RawHTMLRewriter } from "../pkg/htmlrewriter.js";
|
|
2
|
+
import type { DocumentHandlers, ElementHandlers } from "./types.d.ts";
|
|
3
|
+
|
|
4
|
+
export type {
|
|
5
|
+
Comment,
|
|
6
|
+
ContentTypeOptions,
|
|
7
|
+
Doctype,
|
|
8
|
+
DocumentEnd,
|
|
9
|
+
DocumentHandlers,
|
|
10
|
+
Element,
|
|
11
|
+
ElementHandlers,
|
|
12
|
+
EndTag,
|
|
13
|
+
TextChunk,
|
|
14
|
+
} from "./types.d.ts";
|
|
15
|
+
|
|
16
|
+
export { default as init } from "../pkg/htmlrewriter.js";
|
|
17
|
+
|
|
18
|
+
export class HTMLRewriter {
|
|
19
|
+
constructor() {}
|
|
20
|
+
|
|
21
|
+
elementHandlers: [selector: string, handlers: ElementHandlers][] = [];
|
|
22
|
+
documentHandlers: DocumentHandlers[] = [];
|
|
23
|
+
|
|
24
|
+
on(selector: string, handlers: ElementHandlers): HTMLRewriter {
|
|
25
|
+
this.elementHandlers.push([selector, handlers]);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
onDocument(handlers: DocumentHandlers): HTMLRewriter {
|
|
29
|
+
this.documentHandlers.push(handlers);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
transform(response: Response): Response {
|
|
34
|
+
const body = response.body as ReadableStream<Uint8Array> | null;
|
|
35
|
+
// HTMLRewriter doesn't run the end handler if the body is null, so it's
|
|
36
|
+
// pointless to setup the transform stream.
|
|
37
|
+
if (body === null) {
|
|
38
|
+
return new Response(body, response);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (response instanceof Response) {
|
|
42
|
+
// Make sure we validate chunks are BufferSources and convert them to
|
|
43
|
+
// Uint8Arrays as required by the Rust glue code.
|
|
44
|
+
response = new Response(response.body, response);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let rewriter: RawHTMLRewriter;
|
|
48
|
+
const transformStream = new TransformStream<Uint8Array, Uint8Array>({
|
|
49
|
+
start: (controller) => {
|
|
50
|
+
// Create a rewriter instance for this transformation that writes its
|
|
51
|
+
// output to the transformed response's stream. Note that each
|
|
52
|
+
// RawHTMLRewriter can only be used once.
|
|
53
|
+
rewriter = new RawHTMLRewriter((chunk: Uint8Array) => {
|
|
54
|
+
// enqueue will throw on empty chunks
|
|
55
|
+
if (chunk.length !== 0) controller.enqueue(chunk);
|
|
56
|
+
});
|
|
57
|
+
// Add all registered handlers
|
|
58
|
+
for (const [selector, handlers] of this.elementHandlers) {
|
|
59
|
+
rewriter.on(selector, handlers);
|
|
60
|
+
}
|
|
61
|
+
for (const handlers of this.documentHandlers) {
|
|
62
|
+
rewriter.onDocument(handlers);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
transform: (chunk) => {
|
|
66
|
+
rewriter.write(chunk);
|
|
67
|
+
},
|
|
68
|
+
flush: () => {
|
|
69
|
+
rewriter.end();
|
|
70
|
+
rewriter.free();
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
// Return a response with the transformed body, copying over headers, etc
|
|
74
|
+
const res = new Response(body.pipeThrough(transformStream), response);
|
|
75
|
+
// If Content-Length is set, it's probably going to be wrong, since we're
|
|
76
|
+
// rewriting content, so remove it
|
|
77
|
+
res.headers.delete("Content-Length");
|
|
78
|
+
return res;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -15,11 +15,10 @@ export class Element {
|
|
|
15
15
|
append(content: string, options?: ContentTypeOptions): this;
|
|
16
16
|
setInnerContent(content: string, options?: ContentTypeOptions): this;
|
|
17
17
|
removeAndKeepContent(): this;
|
|
18
|
-
readonly attributes:
|
|
18
|
+
readonly attributes: [string, string][];
|
|
19
19
|
readonly namespaceURI: string;
|
|
20
20
|
readonly removed: boolean;
|
|
21
21
|
tagName: string;
|
|
22
|
-
onEndTag(handler: (this: this, endTag: EndTag) => void | Promise<void>): void;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
export class EndTag {
|
|
@@ -59,30 +58,14 @@ export class DocumentEnd {
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
export interface ElementHandlers {
|
|
62
|
-
element?(element: Element): void
|
|
63
|
-
comments?(comment: Comment): void
|
|
64
|
-
text?(text: TextChunk): void
|
|
61
|
+
element?(element: Element): void;
|
|
62
|
+
comments?(comment: Comment): void;
|
|
63
|
+
text?(text: TextChunk): void;
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
export interface DocumentHandlers {
|
|
68
|
-
doctype?(doctype: Doctype): void
|
|
69
|
-
comments?(comment: Comment): void
|
|
70
|
-
text?(text: TextChunk): void
|
|
71
|
-
end?(end: DocumentEnd): void
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface HTMLRewriterOptions {
|
|
75
|
-
enableEsiTags?: boolean;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export class HTMLRewriter {
|
|
79
|
-
constructor(
|
|
80
|
-
outputSink: (chunk: Uint8Array) => void,
|
|
81
|
-
options?: HTMLRewriterOptions
|
|
82
|
-
);
|
|
83
|
-
on(selector: string, handlers: ElementHandlers): this;
|
|
84
|
-
onDocument(handlers: DocumentHandlers): this;
|
|
85
|
-
write(chunk: Uint8Array): Promise<void>;
|
|
86
|
-
end(): Promise<void>;
|
|
87
|
-
free(): void;
|
|
67
|
+
doctype?(doctype: Doctype): void;
|
|
68
|
+
comments?(comment: Comment): void;
|
|
69
|
+
text?(text: TextChunk): void;
|
|
70
|
+
end?(end: DocumentEnd): void;
|
|
88
71
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"imports": {
|
|
3
|
-
"https://ghuc.cc/worker-tools/resolvable-promise/index.ts": "./raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts",
|
|
4
3
|
"https://deno.land/": "./deno.land/",
|
|
5
|
-
"https://raw.githubusercontent.com/": "./raw.githubusercontent.com/",
|
|
6
4
|
"https://v1-7-0--edge-utils.netlify.app/": "./v1-7-0--edge-utils.netlify.app/"
|
|
7
5
|
}
|
|
8
6
|
}
|
package/edge-runtime/vendor.ts
CHANGED
|
@@ -12,6 +12,6 @@ import 'https://deno.land/std@0.175.0/node/util.ts'
|
|
|
12
12
|
import 'https://deno.land/std@0.175.0/path/mod.ts'
|
|
13
13
|
|
|
14
14
|
import 'https://deno.land/x/path_to_regexp@v6.2.1/index.ts'
|
|
15
|
-
import 'https://deno.land/x/
|
|
15
|
+
import 'https://deno.land/x/htmlrewriter@v1.0.0/src/index.ts'
|
|
16
16
|
|
|
17
17
|
import 'https://v1-7-0--edge-utils.netlify.app/logger/mod.ts'
|
package/package.json
CHANGED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/run/handlers/request-context.cts
|
|
9
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
-
|
|
11
|
-
// node_modules/@netlify/functions/dist/chunk-HYMERDCV.mjs
|
|
12
|
-
import { env } from "process";
|
|
13
|
-
var systemLogTag = "__nfSystemLog";
|
|
14
|
-
var serializeError = (error) => {
|
|
15
|
-
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
16
|
-
return {
|
|
17
|
-
error: error.message,
|
|
18
|
-
error_cause: cause,
|
|
19
|
-
error_stack: error.stack
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
23
|
-
LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
|
|
24
|
-
LogLevel2[LogLevel2["Log"] = 2] = "Log";
|
|
25
|
-
LogLevel2[LogLevel2["Error"] = 3] = "Error";
|
|
26
|
-
return LogLevel2;
|
|
27
|
-
})(LogLevel || {});
|
|
28
|
-
var SystemLogger = class _SystemLogger {
|
|
29
|
-
fields;
|
|
30
|
-
logLevel;
|
|
31
|
-
constructor(fields = {}, logLevel = 2) {
|
|
32
|
-
this.fields = fields;
|
|
33
|
-
this.logLevel = logLevel;
|
|
34
|
-
}
|
|
35
|
-
doLog(logger, message) {
|
|
36
|
-
if (env.NETLIFY_DEV && !env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
40
|
-
}
|
|
41
|
-
log(message) {
|
|
42
|
-
if (this.logLevel > 2) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
this.doLog(console.log, message);
|
|
46
|
-
}
|
|
47
|
-
debug(message) {
|
|
48
|
-
if (this.logLevel > 1) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this.doLog(console.debug, message);
|
|
52
|
-
}
|
|
53
|
-
error(message) {
|
|
54
|
-
if (this.logLevel > 3) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
this.doLog(console.error, message);
|
|
58
|
-
}
|
|
59
|
-
withLogLevel(level) {
|
|
60
|
-
return new _SystemLogger(this.fields, level);
|
|
61
|
-
}
|
|
62
|
-
withFields(fields) {
|
|
63
|
-
return new _SystemLogger(
|
|
64
|
-
{
|
|
65
|
-
...this.fields,
|
|
66
|
-
...fields
|
|
67
|
-
},
|
|
68
|
-
this.logLevel
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
withError(error) {
|
|
72
|
-
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
73
|
-
return this.withFields(fields);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var systemLogger = new SystemLogger();
|
|
77
|
-
|
|
78
|
-
// src/run/handlers/request-context.cts
|
|
79
|
-
function createRequestContext(request, context) {
|
|
80
|
-
const backgroundWorkPromises = [];
|
|
81
|
-
return {
|
|
82
|
-
captureServerTiming: request?.headers.has("x-next-debug-logging") ?? false,
|
|
83
|
-
trackBackgroundWork: (promise) => {
|
|
84
|
-
if (context?.waitUntil) {
|
|
85
|
-
context.waitUntil(promise);
|
|
86
|
-
} else {
|
|
87
|
-
backgroundWorkPromises.push(promise);
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
get backgroundWorkPromise() {
|
|
91
|
-
return Promise.allSettled(backgroundWorkPromises);
|
|
92
|
-
},
|
|
93
|
-
logger: systemLogger.withLogLevel(
|
|
94
|
-
request?.headers.has("x-nf-debug-logging") || request?.headers.has("x-next-debug-logging") ? LogLevel.Debug : LogLevel.Log
|
|
95
|
-
)
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
99
|
-
var requestContextAsyncLocalStorage;
|
|
100
|
-
function getRequestContextAsyncLocalStorage() {
|
|
101
|
-
if (requestContextAsyncLocalStorage) {
|
|
102
|
-
return requestContextAsyncLocalStorage;
|
|
103
|
-
}
|
|
104
|
-
const extendedGlobalThis = globalThis;
|
|
105
|
-
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
106
|
-
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
107
|
-
}
|
|
108
|
-
const storage = new AsyncLocalStorage();
|
|
109
|
-
requestContextAsyncLocalStorage = storage;
|
|
110
|
-
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
111
|
-
return storage;
|
|
112
|
-
}
|
|
113
|
-
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
114
|
-
function getLogger() {
|
|
115
|
-
return getRequestContext()?.logger ?? systemLogger;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export {
|
|
119
|
-
createRequestContext,
|
|
120
|
-
getRequestContext,
|
|
121
|
-
getLogger
|
|
122
|
-
};
|