@netlify/plugin-nextjs 4.40.0 → 4.40.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/lib/helpers/edge.js +4 -2
- package/lib/templates/getHandler.js +1 -2
- package/lib/templates/handlerUtils.js +14 -1
- package/lib/templates/server.js +9 -8
- package/lib/templates/vendor.js +20 -0
- package/package.json +7 -4
- package/src/templates/edge/next-dev.js +3 -3
- package/src/templates/edge/shims.js +6 -6
- package/src/templates/edge-shared/next-utils.ts +3 -3
- package/src/templates/edge-shared/utils.ts +1 -1
- package/src/templates/vendor/deno.land/std@0.134.0/fmt/colors.ts +536 -0
- package/src/templates/vendor/deno.land/std@0.134.0/testing/_diff.ts +360 -0
- package/src/templates/vendor/deno.land/std@0.134.0/testing/asserts.ts +866 -0
- package/src/templates/vendor/deno.land/std@0.175.0/_util/asserts.ts +25 -0
- package/src/templates/vendor/deno.land/std@0.175.0/_util/os.ts +23 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/abortable.ts +149 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/deadline.ts +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/debounce.ts +79 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/deferred.ts +48 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/delay.ts +67 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/mod.ts +18 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +97 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/pool.ts +95 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/retry.ts +81 -0
- package/src/templates/vendor/deno.land/std@0.175.0/async/tee.ts +100 -0
- package/src/templates/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +49 -0
- package/src/templates/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +29 -0
- package/src/templates/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +45 -0
- package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64.ts +144 -0
- package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64url.ts +70 -0
- package/src/templates/vendor/deno.land/std@0.175.0/flags/mod.ts +785 -0
- package/src/templates/vendor/deno.land/std@0.175.0/fmt/colors.ts +569 -0
- package/src/templates/vendor/deno.land/std@0.175.0/fmt/printf.ts +939 -0
- package/src/templates/vendor/deno.land/std@0.175.0/http/cookie.ts +403 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_core.ts +77 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_events.d.ts +848 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_events.mjs +1033 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_global.d.ts +66 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_next_tick.ts +173 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +4 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/process.ts +131 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +146 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.d.ts +1488 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.mjs +746 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +129 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/_utils.ts +206 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/assert.ts +940 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/assertion_error.ts +579 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/async_hooks.ts +331 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/buffer.ts +13 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/events.ts +14 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +2074 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +2607 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +5 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/errors.ts +2867 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +123 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/net.ts +95 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +72 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/options.ts +45 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +272 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +137 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +580 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +320 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +229 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +242 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +669 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +118 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +2237 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +113 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util.mjs +143 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +317 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +229 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +16 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +18 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +12 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +86 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +16873 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +66 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +152 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +130 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +541 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +80 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +900 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +14 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +50 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +108 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +84 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +39 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +392 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +354 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +15 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +27 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +488 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +186 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +496 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +126 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +437 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +3 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/process.ts +705 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/stream.ts +37 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/string_decoder.ts +337 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/util/types.ts +4 -0
- package/src/templates/vendor/deno.land/std@0.175.0/node/util.ts +289 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_constants.ts +49 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_interface.ts +30 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/_util.ts +194 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/common.ts +40 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/glob.ts +418 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/mod.ts +53 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/posix.ts +487 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/separator.ts +7 -0
- package/src/templates/vendor/deno.land/std@0.175.0/path/win32.ts +962 -0
- package/src/templates/vendor/deno.land/std@0.175.0/streams/write_all.ts +64 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/_diff.ts +440 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/_format.ts +23 -0
- package/src/templates/vendor/deno.land/std@0.175.0/testing/asserts.ts +906 -0
- package/src/templates/vendor/deno.land/std@0.175.0/types.d.ts +89 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +133 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +112 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +88 -0
- package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +974 -0
- package/src/templates/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +621 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +13 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +12 -0
- package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +5 -0
- package/src/templates/vendor/import_map.json +13 -0
- package/src/templates/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +50 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
/** See the Contributing > Types section in the README for an explanation of this file. */
|
|
4
|
+
|
|
5
|
+
/** An abstract interface which when implemented provides an interface to read bytes into an array buffer asynchronously. */
|
|
6
|
+
export interface Reader {
|
|
7
|
+
/** Reads up to `p.byteLength` bytes into `p`. It resolves to the number of
|
|
8
|
+
* bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
|
|
9
|
+
* encountered. Even if `read()` resolves to `n` < `p.byteLength`, it may
|
|
10
|
+
* use all of `p` as scratch space during the call. If some data is
|
|
11
|
+
* available but not `p.byteLength` bytes, `read()` conventionally resolves
|
|
12
|
+
* to what is available instead of waiting for more.
|
|
13
|
+
*
|
|
14
|
+
* When `read()` encounters end-of-file condition, it resolves to EOF
|
|
15
|
+
* (`null`).
|
|
16
|
+
*
|
|
17
|
+
* When `read()` encounters an error, it rejects with an error.
|
|
18
|
+
*
|
|
19
|
+
* Callers should always process the `n` > `0` bytes returned before
|
|
20
|
+
* considering the EOF (`null`). Doing so correctly handles I/O errors that
|
|
21
|
+
* happen after reading some bytes and also both of the allowed EOF
|
|
22
|
+
* behaviors.
|
|
23
|
+
*
|
|
24
|
+
* Implementations should not retain a reference to `p`.
|
|
25
|
+
*
|
|
26
|
+
* Use iterateReader() from https://deno.land/std@$STD_VERSION/streams/iterate_reader.ts to turn a Reader into an
|
|
27
|
+
* AsyncIterator.
|
|
28
|
+
*/
|
|
29
|
+
read(p: Uint8Array): Promise<number | null>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** An abstract interface which when implemented provides an interface to read bytes into an array buffer synchronously. */
|
|
33
|
+
export interface ReaderSync {
|
|
34
|
+
/** Reads up to `p.byteLength` bytes into `p`. It resolves to the number
|
|
35
|
+
* of bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
|
|
36
|
+
* encountered. Even if `read()` returns `n` < `p.byteLength`, it may use
|
|
37
|
+
* all of `p` as scratch space during the call. If some data is available
|
|
38
|
+
* but not `p.byteLength` bytes, `read()` conventionally returns what is
|
|
39
|
+
* available instead of waiting for more.
|
|
40
|
+
*
|
|
41
|
+
* When `readSync()` encounters end-of-file condition, it returns EOF
|
|
42
|
+
* (`null`).
|
|
43
|
+
*
|
|
44
|
+
* When `readSync()` encounters an error, it throws with an error.
|
|
45
|
+
*
|
|
46
|
+
* Callers should always process the `n` > `0` bytes returned before
|
|
47
|
+
* considering the EOF (`null`). Doing so correctly handles I/O errors that happen
|
|
48
|
+
* after reading some bytes and also both of the allowed EOF behaviors.
|
|
49
|
+
*
|
|
50
|
+
* Implementations should not retain a reference to `p`.
|
|
51
|
+
*
|
|
52
|
+
* Use iterateReaderSync() from https://deno.land/std@$STD_VERSION/streams/iterate_reader.ts to turn a ReaderSync
|
|
53
|
+
* into an Iterator.
|
|
54
|
+
*/
|
|
55
|
+
readSync(p: Uint8Array): number | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource asynchronously. */
|
|
59
|
+
export interface Writer {
|
|
60
|
+
/** Writes `p.byteLength` bytes from `p` to the underlying data stream. It
|
|
61
|
+
* resolves to the number of bytes written from `p` (`0` <= `n` <=
|
|
62
|
+
* `p.byteLength`) or reject with the error encountered that caused the
|
|
63
|
+
* write to stop early. `write()` must reject with a non-null error if
|
|
64
|
+
* would resolve to `n` < `p.byteLength`. `write()` must not modify the
|
|
65
|
+
* slice data, even temporarily.
|
|
66
|
+
*
|
|
67
|
+
* Implementations should not retain a reference to `p`.
|
|
68
|
+
*/
|
|
69
|
+
write(p: Uint8Array): Promise<number>;
|
|
70
|
+
}
|
|
71
|
+
/** An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource synchronously. */
|
|
72
|
+
export interface WriterSync {
|
|
73
|
+
/** Writes `p.byteLength` bytes from `p` to the underlying data
|
|
74
|
+
* stream. It returns the number of bytes written from `p` (`0` <= `n`
|
|
75
|
+
* <= `p.byteLength`) and any error encountered that caused the write to
|
|
76
|
+
* stop early. `writeSync()` must throw a non-null error if it returns `n` <
|
|
77
|
+
* `p.byteLength`. `writeSync()` must not modify the slice data, even
|
|
78
|
+
* temporarily.
|
|
79
|
+
*
|
|
80
|
+
* Implementations should not retain a reference to `p`.
|
|
81
|
+
*/
|
|
82
|
+
writeSync(p: Uint8Array): number;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** An abstract interface which when implemented provides an interface to close files/resources that were previously opened. */
|
|
86
|
+
export interface Closer {
|
|
87
|
+
/** Closes the resource, "freeing" the backing file/resource. */
|
|
88
|
+
close(): void;
|
|
89
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
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("https://deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter_bg.wasm")
|
|
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
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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 };
|
package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export interface ContentTypeOptions {
|
|
2
|
+
html?: boolean;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export class Element {
|
|
6
|
+
before(content: string, options?: ContentTypeOptions): this;
|
|
7
|
+
after(content: string, options?: ContentTypeOptions): this;
|
|
8
|
+
replace(content: string, options?: ContentTypeOptions): this;
|
|
9
|
+
remove(): this;
|
|
10
|
+
getAttribute(name: string): string | null;
|
|
11
|
+
hasAttribute(name: string): boolean;
|
|
12
|
+
setAttribute(name: string, value: string): this;
|
|
13
|
+
removeAttribute(name: string): this;
|
|
14
|
+
prepend(content: string, options?: ContentTypeOptions): this;
|
|
15
|
+
append(content: string, options?: ContentTypeOptions): this;
|
|
16
|
+
setInnerContent(content: string, options?: ContentTypeOptions): this;
|
|
17
|
+
removeAndKeepContent(): this;
|
|
18
|
+
readonly attributes: IterableIterator<[string, string]>;
|
|
19
|
+
readonly namespaceURI: string;
|
|
20
|
+
readonly removed: boolean;
|
|
21
|
+
tagName: string;
|
|
22
|
+
onEndTag(handler: (this: this, endTag: EndTag) => void | Promise<void>): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class EndTag {
|
|
26
|
+
before(content: string, options?: ContentTypeOptions): this;
|
|
27
|
+
after(content: string, options?: ContentTypeOptions): this;
|
|
28
|
+
remove(): this;
|
|
29
|
+
name: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class Comment {
|
|
33
|
+
before(content: string, options?: ContentTypeOptions): this;
|
|
34
|
+
after(content: string, options?: ContentTypeOptions): this;
|
|
35
|
+
replace(content: string, options?: ContentTypeOptions): this;
|
|
36
|
+
remove(): this;
|
|
37
|
+
readonly removed: boolean;
|
|
38
|
+
text: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class TextChunk {
|
|
42
|
+
before(content: string, options?: ContentTypeOptions): this;
|
|
43
|
+
after(content: string, options?: ContentTypeOptions): this;
|
|
44
|
+
replace(content: string, options?: ContentTypeOptions): this;
|
|
45
|
+
remove(): this;
|
|
46
|
+
readonly lastInTextNode: boolean;
|
|
47
|
+
readonly removed: boolean;
|
|
48
|
+
readonly text: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class Doctype {
|
|
52
|
+
readonly name: string | null;
|
|
53
|
+
readonly publicId: string | null;
|
|
54
|
+
readonly systemId: string | null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class DocumentEnd {
|
|
58
|
+
append(content: string, options?: ContentTypeOptions): this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface ElementHandlers {
|
|
62
|
+
element?(element: Element): void | Promise<void>;
|
|
63
|
+
comments?(comment: Comment): void | Promise<void>;
|
|
64
|
+
text?(text: TextChunk): void | Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface DocumentHandlers {
|
|
68
|
+
doctype?(doctype: Doctype): void | Promise<void>;
|
|
69
|
+
comments?(comment: Comment): void | Promise<void>;
|
|
70
|
+
text?(text: TextChunk): void | Promise<void>;
|
|
71
|
+
end?(end: DocumentEnd): void | Promise<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;
|
|
88
|
+
}
|