@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,64 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
|
|
3
|
+
import type { Writer, WriterSync } from "../types.d.ts";
|
|
4
|
+
|
|
5
|
+
/** Write all the content of the array buffer (`arr`) to the writer (`w`).
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { Buffer } from "https://deno.land/std@$STD_VERSION/io/buffer.ts";
|
|
9
|
+
* import { writeAll } from "https://deno.land/std@$STD_VERSION/streams/write_all.ts";
|
|
10
|
+
|
|
11
|
+
* // Example writing to stdout
|
|
12
|
+
* let contentBytes = new TextEncoder().encode("Hello World");
|
|
13
|
+
* await writeAll(Deno.stdout, contentBytes);
|
|
14
|
+
*
|
|
15
|
+
* // Example writing to file
|
|
16
|
+
* contentBytes = new TextEncoder().encode("Hello World");
|
|
17
|
+
* const file = await Deno.open('test.file', {write: true});
|
|
18
|
+
* await writeAll(file, contentBytes);
|
|
19
|
+
* file.close();
|
|
20
|
+
*
|
|
21
|
+
* // Example writing to buffer
|
|
22
|
+
* contentBytes = new TextEncoder().encode("Hello World");
|
|
23
|
+
* const writer = new Buffer();
|
|
24
|
+
* await writeAll(writer, contentBytes);
|
|
25
|
+
* console.log(writer.bytes().length); // 11
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export async function writeAll(w: Writer, arr: Uint8Array) {
|
|
29
|
+
let nwritten = 0;
|
|
30
|
+
while (nwritten < arr.length) {
|
|
31
|
+
nwritten += await w.write(arr.subarray(nwritten));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Synchronously write all the content of the array buffer (`arr`) to the
|
|
36
|
+
* writer (`w`).
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { Buffer } from "https://deno.land/std@$STD_VERSION/io/buffer.ts";
|
|
40
|
+
* import { writeAllSync } from "https://deno.land/std@$STD_VERSION/streams/write_all.ts";
|
|
41
|
+
*
|
|
42
|
+
* // Example writing to stdout
|
|
43
|
+
* let contentBytes = new TextEncoder().encode("Hello World");
|
|
44
|
+
* writeAllSync(Deno.stdout, contentBytes);
|
|
45
|
+
*
|
|
46
|
+
* // Example writing to file
|
|
47
|
+
* contentBytes = new TextEncoder().encode("Hello World");
|
|
48
|
+
* const file = Deno.openSync('test.file', {write: true});
|
|
49
|
+
* writeAllSync(file, contentBytes);
|
|
50
|
+
* file.close();
|
|
51
|
+
*
|
|
52
|
+
* // Example writing to buffer
|
|
53
|
+
* contentBytes = new TextEncoder().encode("Hello World");
|
|
54
|
+
* const writer = new Buffer();
|
|
55
|
+
* writeAllSync(writer, contentBytes);
|
|
56
|
+
* console.log(writer.bytes().length); // 11
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function writeAllSync(w: WriterSync, arr: Uint8Array) {
|
|
60
|
+
let nwritten = 0;
|
|
61
|
+
while (nwritten < arr.length) {
|
|
62
|
+
nwritten += w.writeSync(arr.subarray(nwritten));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
bgGreen,
|
|
6
|
+
bgRed,
|
|
7
|
+
bold,
|
|
8
|
+
gray,
|
|
9
|
+
green,
|
|
10
|
+
red,
|
|
11
|
+
white,
|
|
12
|
+
} from "../fmt/colors.ts";
|
|
13
|
+
|
|
14
|
+
interface FarthestPoint {
|
|
15
|
+
y: number;
|
|
16
|
+
id: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export enum DiffType {
|
|
20
|
+
removed = "removed",
|
|
21
|
+
common = "common",
|
|
22
|
+
added = "added",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DiffResult<T> {
|
|
26
|
+
type: DiffType;
|
|
27
|
+
value: T;
|
|
28
|
+
details?: Array<DiffResult<T>>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const REMOVED = 1;
|
|
32
|
+
const COMMON = 2;
|
|
33
|
+
const ADDED = 3;
|
|
34
|
+
|
|
35
|
+
function createCommon<T>(A: T[], B: T[], reverse?: boolean): T[] {
|
|
36
|
+
const common = [];
|
|
37
|
+
if (A.length === 0 || B.length === 0) return [];
|
|
38
|
+
for (let i = 0; i < Math.min(A.length, B.length); i += 1) {
|
|
39
|
+
if (
|
|
40
|
+
A[reverse ? A.length - i - 1 : i] === B[reverse ? B.length - i - 1 : i]
|
|
41
|
+
) {
|
|
42
|
+
common.push(A[reverse ? A.length - i - 1 : i]);
|
|
43
|
+
} else {
|
|
44
|
+
return common;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return common;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Renders the differences between the actual and expected values
|
|
52
|
+
* @param A Actual value
|
|
53
|
+
* @param B Expected value
|
|
54
|
+
*/
|
|
55
|
+
export function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> {
|
|
56
|
+
const prefixCommon = createCommon(A, B);
|
|
57
|
+
const suffixCommon = createCommon(
|
|
58
|
+
A.slice(prefixCommon.length),
|
|
59
|
+
B.slice(prefixCommon.length),
|
|
60
|
+
true,
|
|
61
|
+
).reverse();
|
|
62
|
+
A = suffixCommon.length
|
|
63
|
+
? A.slice(prefixCommon.length, -suffixCommon.length)
|
|
64
|
+
: A.slice(prefixCommon.length);
|
|
65
|
+
B = suffixCommon.length
|
|
66
|
+
? B.slice(prefixCommon.length, -suffixCommon.length)
|
|
67
|
+
: B.slice(prefixCommon.length);
|
|
68
|
+
const swapped = B.length > A.length;
|
|
69
|
+
[A, B] = swapped ? [B, A] : [A, B];
|
|
70
|
+
const M = A.length;
|
|
71
|
+
const N = B.length;
|
|
72
|
+
if (!M && !N && !suffixCommon.length && !prefixCommon.length) return [];
|
|
73
|
+
if (!N) {
|
|
74
|
+
return [
|
|
75
|
+
...prefixCommon.map(
|
|
76
|
+
(c): DiffResult<typeof c> => ({ type: DiffType.common, value: c }),
|
|
77
|
+
),
|
|
78
|
+
...A.map(
|
|
79
|
+
(a): DiffResult<typeof a> => ({
|
|
80
|
+
type: swapped ? DiffType.added : DiffType.removed,
|
|
81
|
+
value: a,
|
|
82
|
+
}),
|
|
83
|
+
),
|
|
84
|
+
...suffixCommon.map(
|
|
85
|
+
(c): DiffResult<typeof c> => ({ type: DiffType.common, value: c }),
|
|
86
|
+
),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
const offset = N;
|
|
90
|
+
const delta = M - N;
|
|
91
|
+
const size = M + N + 1;
|
|
92
|
+
const fp: FarthestPoint[] = Array.from(
|
|
93
|
+
{ length: size },
|
|
94
|
+
() => ({ y: -1, id: -1 }),
|
|
95
|
+
);
|
|
96
|
+
/**
|
|
97
|
+
* INFO:
|
|
98
|
+
* This buffer is used to save memory and improve performance.
|
|
99
|
+
* The first half is used to save route and last half is used to save diff
|
|
100
|
+
* type.
|
|
101
|
+
* This is because, when I kept new uint8array area to save type,performance
|
|
102
|
+
* worsened.
|
|
103
|
+
*/
|
|
104
|
+
const routes = new Uint32Array((M * N + size + 1) * 2);
|
|
105
|
+
const diffTypesPtrOffset = routes.length / 2;
|
|
106
|
+
let ptr = 0;
|
|
107
|
+
let p = -1;
|
|
108
|
+
|
|
109
|
+
function backTrace<T>(
|
|
110
|
+
A: T[],
|
|
111
|
+
B: T[],
|
|
112
|
+
current: FarthestPoint,
|
|
113
|
+
swapped: boolean,
|
|
114
|
+
): Array<{
|
|
115
|
+
type: DiffType;
|
|
116
|
+
value: T;
|
|
117
|
+
}> {
|
|
118
|
+
const M = A.length;
|
|
119
|
+
const N = B.length;
|
|
120
|
+
const result = [];
|
|
121
|
+
let a = M - 1;
|
|
122
|
+
let b = N - 1;
|
|
123
|
+
let j = routes[current.id];
|
|
124
|
+
let type = routes[current.id + diffTypesPtrOffset];
|
|
125
|
+
while (true) {
|
|
126
|
+
if (!j && !type) break;
|
|
127
|
+
const prev = j;
|
|
128
|
+
if (type === REMOVED) {
|
|
129
|
+
result.unshift({
|
|
130
|
+
type: swapped ? DiffType.removed : DiffType.added,
|
|
131
|
+
value: B[b],
|
|
132
|
+
});
|
|
133
|
+
b -= 1;
|
|
134
|
+
} else if (type === ADDED) {
|
|
135
|
+
result.unshift({
|
|
136
|
+
type: swapped ? DiffType.added : DiffType.removed,
|
|
137
|
+
value: A[a],
|
|
138
|
+
});
|
|
139
|
+
a -= 1;
|
|
140
|
+
} else {
|
|
141
|
+
result.unshift({ type: DiffType.common, value: A[a] });
|
|
142
|
+
a -= 1;
|
|
143
|
+
b -= 1;
|
|
144
|
+
}
|
|
145
|
+
j = routes[prev];
|
|
146
|
+
type = routes[prev + diffTypesPtrOffset];
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function createFP(
|
|
152
|
+
slide: FarthestPoint,
|
|
153
|
+
down: FarthestPoint,
|
|
154
|
+
k: number,
|
|
155
|
+
M: number,
|
|
156
|
+
): FarthestPoint {
|
|
157
|
+
if (slide && slide.y === -1 && down && down.y === -1) {
|
|
158
|
+
return { y: 0, id: 0 };
|
|
159
|
+
}
|
|
160
|
+
if (
|
|
161
|
+
(down && down.y === -1) ||
|
|
162
|
+
k === M ||
|
|
163
|
+
(slide && slide.y) > (down && down.y) + 1
|
|
164
|
+
) {
|
|
165
|
+
const prev = slide.id;
|
|
166
|
+
ptr++;
|
|
167
|
+
routes[ptr] = prev;
|
|
168
|
+
routes[ptr + diffTypesPtrOffset] = ADDED;
|
|
169
|
+
return { y: slide.y, id: ptr };
|
|
170
|
+
} else {
|
|
171
|
+
const prev = down.id;
|
|
172
|
+
ptr++;
|
|
173
|
+
routes[ptr] = prev;
|
|
174
|
+
routes[ptr + diffTypesPtrOffset] = REMOVED;
|
|
175
|
+
return { y: down.y + 1, id: ptr };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function snake<T>(
|
|
180
|
+
k: number,
|
|
181
|
+
slide: FarthestPoint,
|
|
182
|
+
down: FarthestPoint,
|
|
183
|
+
_offset: number,
|
|
184
|
+
A: T[],
|
|
185
|
+
B: T[],
|
|
186
|
+
): FarthestPoint {
|
|
187
|
+
const M = A.length;
|
|
188
|
+
const N = B.length;
|
|
189
|
+
if (k < -N || M < k) return { y: -1, id: -1 };
|
|
190
|
+
const fp = createFP(slide, down, k, M);
|
|
191
|
+
while (fp.y + k < M && fp.y < N && A[fp.y + k] === B[fp.y]) {
|
|
192
|
+
const prev = fp.id;
|
|
193
|
+
ptr++;
|
|
194
|
+
fp.id = ptr;
|
|
195
|
+
fp.y += 1;
|
|
196
|
+
routes[ptr] = prev;
|
|
197
|
+
routes[ptr + diffTypesPtrOffset] = COMMON;
|
|
198
|
+
}
|
|
199
|
+
return fp;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
while (fp[delta + offset].y < N) {
|
|
203
|
+
p = p + 1;
|
|
204
|
+
for (let k = -p; k < delta; ++k) {
|
|
205
|
+
fp[k + offset] = snake(
|
|
206
|
+
k,
|
|
207
|
+
fp[k - 1 + offset],
|
|
208
|
+
fp[k + 1 + offset],
|
|
209
|
+
offset,
|
|
210
|
+
A,
|
|
211
|
+
B,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
for (let k = delta + p; k > delta; --k) {
|
|
215
|
+
fp[k + offset] = snake(
|
|
216
|
+
k,
|
|
217
|
+
fp[k - 1 + offset],
|
|
218
|
+
fp[k + 1 + offset],
|
|
219
|
+
offset,
|
|
220
|
+
A,
|
|
221
|
+
B,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
fp[delta + offset] = snake(
|
|
225
|
+
delta,
|
|
226
|
+
fp[delta - 1 + offset],
|
|
227
|
+
fp[delta + 1 + offset],
|
|
228
|
+
offset,
|
|
229
|
+
A,
|
|
230
|
+
B,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
return [
|
|
234
|
+
...prefixCommon.map(
|
|
235
|
+
(c): DiffResult<typeof c> => ({ type: DiffType.common, value: c }),
|
|
236
|
+
),
|
|
237
|
+
...backTrace(A, B, fp[delta + offset], swapped),
|
|
238
|
+
...suffixCommon.map(
|
|
239
|
+
(c): DiffResult<typeof c> => ({ type: DiffType.common, value: c }),
|
|
240
|
+
),
|
|
241
|
+
];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Renders the differences between the actual and expected strings
|
|
246
|
+
* Partially inspired from https://github.com/kpdecker/jsdiff
|
|
247
|
+
* @param A Actual string
|
|
248
|
+
* @param B Expected string
|
|
249
|
+
*/
|
|
250
|
+
export function diffstr(A: string, B: string) {
|
|
251
|
+
function unescape(string: string): string {
|
|
252
|
+
// unescape invisible characters.
|
|
253
|
+
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#escape_sequences
|
|
254
|
+
return string
|
|
255
|
+
.replaceAll("\b", "\\b")
|
|
256
|
+
.replaceAll("\f", "\\f")
|
|
257
|
+
.replaceAll("\t", "\\t")
|
|
258
|
+
.replaceAll("\v", "\\v")
|
|
259
|
+
.replaceAll( // does not remove line breaks
|
|
260
|
+
/\r\n|\r|\n/g,
|
|
261
|
+
(str) => str === "\r" ? "\\r" : str === "\n" ? "\\n\n" : "\\r\\n\r\n",
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function tokenize(string: string, { wordDiff = false } = {}): string[] {
|
|
266
|
+
if (wordDiff) {
|
|
267
|
+
// Split string on whitespace symbols
|
|
268
|
+
const tokens = string.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/);
|
|
269
|
+
// Extended Latin character set
|
|
270
|
+
const words =
|
|
271
|
+
/^[a-zA-Z\u{C0}-\u{FF}\u{D8}-\u{F6}\u{F8}-\u{2C6}\u{2C8}-\u{2D7}\u{2DE}-\u{2FF}\u{1E00}-\u{1EFF}]+$/u;
|
|
272
|
+
|
|
273
|
+
// Join boundary splits that we do not consider to be boundaries and merge empty strings surrounded by word chars
|
|
274
|
+
for (let i = 0; i < tokens.length - 1; i++) {
|
|
275
|
+
if (
|
|
276
|
+
!tokens[i + 1] && tokens[i + 2] && words.test(tokens[i]) &&
|
|
277
|
+
words.test(tokens[i + 2])
|
|
278
|
+
) {
|
|
279
|
+
tokens[i] += tokens[i + 2];
|
|
280
|
+
tokens.splice(i + 1, 2);
|
|
281
|
+
i--;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return tokens.filter((token) => token);
|
|
285
|
+
} else {
|
|
286
|
+
// Split string on new lines symbols
|
|
287
|
+
const tokens = [], lines = string.split(/(\n|\r\n)/);
|
|
288
|
+
|
|
289
|
+
// Ignore final empty token when text ends with a newline
|
|
290
|
+
if (!lines[lines.length - 1]) {
|
|
291
|
+
lines.pop();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Merge the content and line separators into single tokens
|
|
295
|
+
for (let i = 0; i < lines.length; i++) {
|
|
296
|
+
if (i % 2) {
|
|
297
|
+
tokens[tokens.length - 1] += lines[i];
|
|
298
|
+
} else {
|
|
299
|
+
tokens.push(lines[i]);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return tokens;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Create details by filtering relevant word-diff for current line
|
|
307
|
+
// and merge "space-diff" if surrounded by word-diff for cleaner displays
|
|
308
|
+
function createDetails(
|
|
309
|
+
line: DiffResult<string>,
|
|
310
|
+
tokens: Array<DiffResult<string>>,
|
|
311
|
+
) {
|
|
312
|
+
return tokens.filter(({ type }) =>
|
|
313
|
+
type === line.type || type === DiffType.common
|
|
314
|
+
).map((result, i, t) => {
|
|
315
|
+
if (
|
|
316
|
+
(result.type === DiffType.common) && (t[i - 1]) &&
|
|
317
|
+
(t[i - 1]?.type === t[i + 1]?.type) && /\s+/.test(result.value)
|
|
318
|
+
) {
|
|
319
|
+
return {
|
|
320
|
+
...result,
|
|
321
|
+
type: t[i - 1].type,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
return result;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Compute multi-line diff
|
|
329
|
+
const diffResult = diff(
|
|
330
|
+
tokenize(`${unescape(A)}\n`),
|
|
331
|
+
tokenize(`${unescape(B)}\n`),
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
const added = [], removed = [];
|
|
335
|
+
for (const result of diffResult) {
|
|
336
|
+
if (result.type === DiffType.added) {
|
|
337
|
+
added.push(result);
|
|
338
|
+
}
|
|
339
|
+
if (result.type === DiffType.removed) {
|
|
340
|
+
removed.push(result);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Compute word-diff
|
|
345
|
+
const aLines = added.length < removed.length ? added : removed;
|
|
346
|
+
const bLines = aLines === removed ? added : removed;
|
|
347
|
+
for (const a of aLines) {
|
|
348
|
+
let tokens = [] as Array<DiffResult<string>>,
|
|
349
|
+
b: undefined | DiffResult<string>;
|
|
350
|
+
// Search another diff line with at least one common token
|
|
351
|
+
while (bLines.length) {
|
|
352
|
+
b = bLines.shift();
|
|
353
|
+
tokens = diff(
|
|
354
|
+
tokenize(a.value, { wordDiff: true }),
|
|
355
|
+
tokenize(b?.value ?? "", { wordDiff: true }),
|
|
356
|
+
);
|
|
357
|
+
if (
|
|
358
|
+
tokens.some(({ type, value }) =>
|
|
359
|
+
type === DiffType.common && value.trim().length
|
|
360
|
+
)
|
|
361
|
+
) {
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
// Register word-diff details
|
|
366
|
+
a.details = createDetails(a, tokens);
|
|
367
|
+
if (b) {
|
|
368
|
+
b.details = createDetails(b, tokens);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return diffResult;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Colors the output of assertion diffs
|
|
377
|
+
* @param diffType Difference type, either added or removed
|
|
378
|
+
*/
|
|
379
|
+
function createColor(
|
|
380
|
+
diffType: DiffType,
|
|
381
|
+
{ background = false } = {},
|
|
382
|
+
): (s: string) => string {
|
|
383
|
+
// TODO(@littledivy): Remove this when we can detect
|
|
384
|
+
// true color terminals.
|
|
385
|
+
// https://github.com/denoland/deno_std/issues/2575
|
|
386
|
+
background = false;
|
|
387
|
+
switch (diffType) {
|
|
388
|
+
case DiffType.added:
|
|
389
|
+
return (s: string): string =>
|
|
390
|
+
background ? bgGreen(white(s)) : green(bold(s));
|
|
391
|
+
case DiffType.removed:
|
|
392
|
+
return (s: string): string => background ? bgRed(white(s)) : red(bold(s));
|
|
393
|
+
default:
|
|
394
|
+
return white;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Prefixes `+` or `-` in diff output
|
|
400
|
+
* @param diffType Difference type, either added or removed
|
|
401
|
+
*/
|
|
402
|
+
function createSign(diffType: DiffType): string {
|
|
403
|
+
switch (diffType) {
|
|
404
|
+
case DiffType.added:
|
|
405
|
+
return "+ ";
|
|
406
|
+
case DiffType.removed:
|
|
407
|
+
return "- ";
|
|
408
|
+
default:
|
|
409
|
+
return " ";
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export function buildMessage(
|
|
414
|
+
diffResult: ReadonlyArray<DiffResult<string>>,
|
|
415
|
+
{ stringDiff = false } = {},
|
|
416
|
+
): string[] {
|
|
417
|
+
const messages: string[] = [], diffMessages: string[] = [];
|
|
418
|
+
messages.push("");
|
|
419
|
+
messages.push("");
|
|
420
|
+
messages.push(
|
|
421
|
+
` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${
|
|
422
|
+
green(bold("Expected"))
|
|
423
|
+
}`,
|
|
424
|
+
);
|
|
425
|
+
messages.push("");
|
|
426
|
+
messages.push("");
|
|
427
|
+
diffResult.forEach((result: DiffResult<string>) => {
|
|
428
|
+
const c = createColor(result.type);
|
|
429
|
+
const line = result.details?.map((detail) =>
|
|
430
|
+
detail.type !== DiffType.common
|
|
431
|
+
? createColor(detail.type, { background: true })(detail.value)
|
|
432
|
+
: detail.value
|
|
433
|
+
).join("") ?? result.value;
|
|
434
|
+
diffMessages.push(c(`${createSign(result.type)}${line}`));
|
|
435
|
+
});
|
|
436
|
+
messages.push(...(stringDiff ? [diffMessages.join("")] : diffMessages));
|
|
437
|
+
messages.push("");
|
|
438
|
+
|
|
439
|
+
return messages;
|
|
440
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts the input into a string. Objects, Sets and Maps are sorted so as to
|
|
6
|
+
* make tests less flaky
|
|
7
|
+
* @param v Value to be formatted
|
|
8
|
+
*/
|
|
9
|
+
export function format(v: unknown): string {
|
|
10
|
+
// deno-lint-ignore no-explicit-any
|
|
11
|
+
const { Deno } = globalThis as any;
|
|
12
|
+
return typeof Deno?.inspect === "function"
|
|
13
|
+
? Deno.inspect(v, {
|
|
14
|
+
depth: Infinity,
|
|
15
|
+
sorted: true,
|
|
16
|
+
trailingComma: true,
|
|
17
|
+
compact: false,
|
|
18
|
+
iterableLimit: Infinity,
|
|
19
|
+
// getters should be true in assertEquals.
|
|
20
|
+
getters: true,
|
|
21
|
+
})
|
|
22
|
+
: `"${String(v).replace(/(?=["\\])/g, "\\")}"`;
|
|
23
|
+
}
|