@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.
Files changed (164) hide show
  1. package/lib/helpers/edge.js +4 -2
  2. package/lib/templates/getHandler.js +1 -2
  3. package/lib/templates/handlerUtils.js +14 -1
  4. package/lib/templates/server.js +9 -8
  5. package/lib/templates/vendor.js +20 -0
  6. package/package.json +7 -4
  7. package/src/templates/edge/next-dev.js +3 -3
  8. package/src/templates/edge/shims.js +6 -6
  9. package/src/templates/edge-shared/next-utils.ts +3 -3
  10. package/src/templates/edge-shared/utils.ts +1 -1
  11. package/src/templates/vendor/deno.land/std@0.134.0/fmt/colors.ts +536 -0
  12. package/src/templates/vendor/deno.land/std@0.134.0/testing/_diff.ts +360 -0
  13. package/src/templates/vendor/deno.land/std@0.134.0/testing/asserts.ts +866 -0
  14. package/src/templates/vendor/deno.land/std@0.175.0/_util/asserts.ts +25 -0
  15. package/src/templates/vendor/deno.land/std@0.175.0/_util/os.ts +23 -0
  16. package/src/templates/vendor/deno.land/std@0.175.0/async/abortable.ts +149 -0
  17. package/src/templates/vendor/deno.land/std@0.175.0/async/deadline.ts +30 -0
  18. package/src/templates/vendor/deno.land/std@0.175.0/async/debounce.ts +79 -0
  19. package/src/templates/vendor/deno.land/std@0.175.0/async/deferred.ts +48 -0
  20. package/src/templates/vendor/deno.land/std@0.175.0/async/delay.ts +67 -0
  21. package/src/templates/vendor/deno.land/std@0.175.0/async/mod.ts +18 -0
  22. package/src/templates/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +97 -0
  23. package/src/templates/vendor/deno.land/std@0.175.0/async/pool.ts +95 -0
  24. package/src/templates/vendor/deno.land/std@0.175.0/async/retry.ts +81 -0
  25. package/src/templates/vendor/deno.land/std@0.175.0/async/tee.ts +100 -0
  26. package/src/templates/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +49 -0
  27. package/src/templates/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +29 -0
  28. package/src/templates/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +45 -0
  29. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64.ts +144 -0
  30. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64url.ts +70 -0
  31. package/src/templates/vendor/deno.land/std@0.175.0/flags/mod.ts +785 -0
  32. package/src/templates/vendor/deno.land/std@0.175.0/fmt/colors.ts +569 -0
  33. package/src/templates/vendor/deno.land/std@0.175.0/fmt/printf.ts +939 -0
  34. package/src/templates/vendor/deno.land/std@0.175.0/http/cookie.ts +403 -0
  35. package/src/templates/vendor/deno.land/std@0.175.0/node/_core.ts +77 -0
  36. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.d.ts +848 -0
  37. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.mjs +1033 -0
  38. package/src/templates/vendor/deno.land/std@0.175.0/node/_global.d.ts +66 -0
  39. package/src/templates/vendor/deno.land/std@0.175.0/node/_next_tick.ts +173 -0
  40. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +4 -0
  41. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/process.ts +131 -0
  42. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +7 -0
  43. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +146 -0
  44. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.d.ts +1488 -0
  45. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.mjs +746 -0
  46. package/src/templates/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +129 -0
  47. package/src/templates/vendor/deno.land/std@0.175.0/node/_utils.ts +206 -0
  48. package/src/templates/vendor/deno.land/std@0.175.0/node/assert.ts +940 -0
  49. package/src/templates/vendor/deno.land/std@0.175.0/node/assertion_error.ts +579 -0
  50. package/src/templates/vendor/deno.land/std@0.175.0/node/async_hooks.ts +331 -0
  51. package/src/templates/vendor/deno.land/std@0.175.0/node/buffer.ts +13 -0
  52. package/src/templates/vendor/deno.land/std@0.175.0/node/events.ts +14 -0
  53. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +2074 -0
  54. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +2607 -0
  55. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +16 -0
  56. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +5 -0
  57. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +7 -0
  58. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/errors.ts +2867 -0
  59. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +123 -0
  60. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +16 -0
  61. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/net.ts +95 -0
  62. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +72 -0
  63. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/options.ts +45 -0
  64. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +30 -0
  65. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +272 -0
  66. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +137 -0
  67. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +580 -0
  68. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +320 -0
  69. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +229 -0
  70. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +242 -0
  71. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +669 -0
  72. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +118 -0
  73. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +2237 -0
  74. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +113 -0
  75. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util.mjs +143 -0
  76. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +317 -0
  77. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +229 -0
  78. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +16 -0
  79. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +18 -0
  80. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +12 -0
  81. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +86 -0
  82. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +16873 -0
  83. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +66 -0
  84. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +152 -0
  85. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +130 -0
  86. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +541 -0
  87. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +3 -0
  88. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +80 -0
  89. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +900 -0
  90. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +3 -0
  91. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +3 -0
  92. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +14 -0
  93. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +3 -0
  94. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +3 -0
  95. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +3 -0
  96. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +3 -0
  97. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +50 -0
  98. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +3 -0
  99. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +3 -0
  100. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +3 -0
  101. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +3 -0
  102. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +3 -0
  103. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +3 -0
  104. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +108 -0
  105. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +3 -0
  106. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +3 -0
  107. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +3 -0
  108. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +84 -0
  109. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +39 -0
  110. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +3 -0
  111. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +3 -0
  112. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +3 -0
  113. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +392 -0
  114. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +3 -0
  115. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +3 -0
  116. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +3 -0
  117. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +3 -0
  118. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +3 -0
  119. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +354 -0
  120. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +15 -0
  121. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +27 -0
  122. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +3 -0
  123. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +488 -0
  124. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +3 -0
  125. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +3 -0
  126. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +3 -0
  127. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +3 -0
  128. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +186 -0
  129. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +496 -0
  130. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +3 -0
  131. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +126 -0
  132. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +437 -0
  133. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +3 -0
  134. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +3 -0
  135. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +3 -0
  136. package/src/templates/vendor/deno.land/std@0.175.0/node/process.ts +705 -0
  137. package/src/templates/vendor/deno.land/std@0.175.0/node/stream.ts +37 -0
  138. package/src/templates/vendor/deno.land/std@0.175.0/node/string_decoder.ts +337 -0
  139. package/src/templates/vendor/deno.land/std@0.175.0/node/util/types.ts +4 -0
  140. package/src/templates/vendor/deno.land/std@0.175.0/node/util.ts +289 -0
  141. package/src/templates/vendor/deno.land/std@0.175.0/path/_constants.ts +49 -0
  142. package/src/templates/vendor/deno.land/std@0.175.0/path/_interface.ts +30 -0
  143. package/src/templates/vendor/deno.land/std@0.175.0/path/_util.ts +194 -0
  144. package/src/templates/vendor/deno.land/std@0.175.0/path/common.ts +40 -0
  145. package/src/templates/vendor/deno.land/std@0.175.0/path/glob.ts +418 -0
  146. package/src/templates/vendor/deno.land/std@0.175.0/path/mod.ts +53 -0
  147. package/src/templates/vendor/deno.land/std@0.175.0/path/posix.ts +487 -0
  148. package/src/templates/vendor/deno.land/std@0.175.0/path/separator.ts +7 -0
  149. package/src/templates/vendor/deno.land/std@0.175.0/path/win32.ts +962 -0
  150. package/src/templates/vendor/deno.land/std@0.175.0/streams/write_all.ts +64 -0
  151. package/src/templates/vendor/deno.land/std@0.175.0/testing/_diff.ts +440 -0
  152. package/src/templates/vendor/deno.land/std@0.175.0/testing/_format.ts +23 -0
  153. package/src/templates/vendor/deno.land/std@0.175.0/testing/asserts.ts +906 -0
  154. package/src/templates/vendor/deno.land/std@0.175.0/types.d.ts +89 -0
  155. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +133 -0
  156. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +112 -0
  157. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +88 -0
  158. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +974 -0
  159. package/src/templates/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +621 -0
  160. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +13 -0
  161. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +12 -0
  162. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +5 -0
  163. package/src/templates/vendor/import_map.json +13 -0
  164. package/src/templates/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +50 -0
@@ -0,0 +1,579 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+
3
+ // Adapted from Node.js. Copyright Joyent, Inc. and other Node contributors.
4
+
5
+ // Permission is hereby granted, free of charge, to any person obtaining a
6
+ // copy of this software and associated documentation files (the
7
+ // "Software"), to deal in the Software without restriction, including
8
+ // without limitation the rights to use, copy, modify, merge, publish,
9
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
10
+ // persons to whom the Software is furnished to do so, subject to the
11
+ // following conditions:
12
+
13
+ // The above copyright notice and this permission notice shall be included
14
+ // in all copies or substantial portions of the Software.
15
+
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ import { inspect } from "./util.ts";
25
+ import { stripColor as removeColors } from "../fmt/colors.ts";
26
+
27
+ function getConsoleWidth(): number {
28
+ try {
29
+ return Deno.consoleSize().columns;
30
+ } catch {
31
+ return 80;
32
+ }
33
+ }
34
+
35
+ // TODO(schwarzkopfb): we should implement Node's concept of "primordials"
36
+ // Ref: https://github.com/denoland/deno/issues/6040#issuecomment-637305828
37
+ const MathMax = Math.max;
38
+ const { Error } = globalThis;
39
+ const {
40
+ create: ObjectCreate,
41
+ defineProperty: ObjectDefineProperty,
42
+ getPrototypeOf: ObjectGetPrototypeOf,
43
+ getOwnPropertyDescriptor: ObjectGetOwnPropertyDescriptor,
44
+ keys: ObjectKeys,
45
+ } = Object;
46
+
47
+ import { ERR_INVALID_ARG_TYPE } from "./internal/errors.ts";
48
+
49
+ let blue = "";
50
+ let green = "";
51
+ let red = "";
52
+ let defaultColor = "";
53
+
54
+ const kReadableOperator: { [key: string]: string } = {
55
+ deepStrictEqual: "Expected values to be strictly deep-equal:",
56
+ strictEqual: "Expected values to be strictly equal:",
57
+ strictEqualObject: 'Expected "actual" to be reference-equal to "expected":',
58
+ deepEqual: "Expected values to be loosely deep-equal:",
59
+ notDeepStrictEqual: 'Expected "actual" not to be strictly deep-equal to:',
60
+ notStrictEqual: 'Expected "actual" to be strictly unequal to:',
61
+ notStrictEqualObject:
62
+ 'Expected "actual" not to be reference-equal to "expected":',
63
+ notDeepEqual: 'Expected "actual" not to be loosely deep-equal to:',
64
+ notIdentical: "Values have same structure but are not reference-equal:",
65
+ notDeepEqualUnequal: "Expected values not to be loosely deep-equal:",
66
+ };
67
+
68
+ // Comparing short primitives should just show === / !== instead of using the
69
+ // diff.
70
+ const kMaxShortLength = 12;
71
+
72
+ export function copyError(source: Error): Error {
73
+ const keys = ObjectKeys(source);
74
+ const target = ObjectCreate(ObjectGetPrototypeOf(source));
75
+ for (const key of keys) {
76
+ const desc = ObjectGetOwnPropertyDescriptor(source, key);
77
+
78
+ if (desc !== undefined) {
79
+ ObjectDefineProperty(target, key, desc);
80
+ }
81
+ }
82
+ ObjectDefineProperty(target, "message", { value: source.message });
83
+ return target;
84
+ }
85
+
86
+ export function inspectValue(val: unknown): string {
87
+ // The util.inspect default values could be changed. This makes sure the
88
+ // error messages contain the necessary information nevertheless.
89
+ return inspect(
90
+ val,
91
+ {
92
+ compact: true,
93
+ customInspect: false,
94
+ depth: 1000,
95
+ maxArrayLength: Infinity,
96
+ // Assert compares only enumerable properties (with a few exceptions).
97
+ showHidden: false,
98
+ // Assert does not detect proxies currently.
99
+ showProxy: false,
100
+ sorted: true,
101
+ // Inspect getters as we also check them when comparing entries.
102
+ getters: true,
103
+ },
104
+ );
105
+ }
106
+
107
+ export function createErrDiff(
108
+ actual: unknown,
109
+ expected: unknown,
110
+ operator: string,
111
+ ): string {
112
+ let other = "";
113
+ let res = "";
114
+ let end = "";
115
+ let skipped = false;
116
+ const actualInspected = inspectValue(actual);
117
+ const actualLines = actualInspected.split("\n");
118
+ const expectedLines = inspectValue(expected).split("\n");
119
+
120
+ let i = 0;
121
+ let indicator = "";
122
+
123
+ // In case both values are objects or functions explicitly mark them as not
124
+ // reference equal for the `strictEqual` operator.
125
+ if (
126
+ operator === "strictEqual" &&
127
+ ((typeof actual === "object" && actual !== null &&
128
+ typeof expected === "object" && expected !== null) ||
129
+ (typeof actual === "function" && typeof expected === "function"))
130
+ ) {
131
+ operator = "strictEqualObject";
132
+ }
133
+
134
+ // If "actual" and "expected" fit on a single line and they are not strictly
135
+ // equal, check further special handling.
136
+ if (
137
+ actualLines.length === 1 && expectedLines.length === 1 &&
138
+ actualLines[0] !== expectedLines[0]
139
+ ) {
140
+ // Check for the visible length using the `removeColors()` function, if
141
+ // appropriate.
142
+ const c = inspect.defaultOptions.colors;
143
+ const actualRaw = c ? removeColors(actualLines[0]) : actualLines[0];
144
+ const expectedRaw = c ? removeColors(expectedLines[0]) : expectedLines[0];
145
+ const inputLength = actualRaw.length + expectedRaw.length;
146
+ // If the character length of "actual" and "expected" together is less than
147
+ // kMaxShortLength and if neither is an object and at least one of them is
148
+ // not `zero`, use the strict equal comparison to visualize the output.
149
+ if (inputLength <= kMaxShortLength) {
150
+ if (
151
+ (typeof actual !== "object" || actual === null) &&
152
+ (typeof expected !== "object" || expected === null) &&
153
+ (actual !== 0 || expected !== 0)
154
+ ) { // -0 === +0
155
+ return `${kReadableOperator[operator]}\n\n` +
156
+ `${actualLines[0]} !== ${expectedLines[0]}\n`;
157
+ }
158
+ } else if (operator !== "strictEqualObject") {
159
+ // If the stderr is a tty and the input length is lower than the current
160
+ // columns per line, add a mismatch indicator below the output. If it is
161
+ // not a tty, use a default value of 80 characters.
162
+ const maxLength = Deno.isatty(Deno.stderr.rid) ? getConsoleWidth() : 80;
163
+ if (inputLength < maxLength) {
164
+ while (actualRaw[i] === expectedRaw[i]) {
165
+ i++;
166
+ }
167
+ // Ignore the first characters.
168
+ if (i > 2) {
169
+ // Add position indicator for the first mismatch in case it is a
170
+ // single line and the input length is less than the column length.
171
+ indicator = `\n ${" ".repeat(i)}^`;
172
+ i = 0;
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ // Remove all ending lines that match (this optimizes the output for
179
+ // readability by reducing the number of total changed lines).
180
+ let a = actualLines[actualLines.length - 1];
181
+ let b = expectedLines[expectedLines.length - 1];
182
+ while (a === b) {
183
+ if (i++ < 3) {
184
+ end = `\n ${a}${end}`;
185
+ } else {
186
+ other = a;
187
+ }
188
+ actualLines.pop();
189
+ expectedLines.pop();
190
+ if (actualLines.length === 0 || expectedLines.length === 0) {
191
+ break;
192
+ }
193
+ a = actualLines[actualLines.length - 1];
194
+ b = expectedLines[expectedLines.length - 1];
195
+ }
196
+
197
+ const maxLines = MathMax(actualLines.length, expectedLines.length);
198
+ // Strict equal with identical objects that are not identical by reference.
199
+ // E.g., assert.deepStrictEqual({ a: Symbol() }, { a: Symbol() })
200
+ if (maxLines === 0) {
201
+ // We have to get the result again. The lines were all removed before.
202
+ const actualLines = actualInspected.split("\n");
203
+
204
+ // Only remove lines in case it makes sense to collapse those.
205
+ if (actualLines.length > 50) {
206
+ actualLines[46] = `${blue}...${defaultColor}`;
207
+ while (actualLines.length > 47) {
208
+ actualLines.pop();
209
+ }
210
+ }
211
+
212
+ return `${kReadableOperator.notIdentical}\n\n${actualLines.join("\n")}\n`;
213
+ }
214
+
215
+ // There were at least five identical lines at the end. Mark a couple of
216
+ // skipped.
217
+ if (i >= 5) {
218
+ end = `\n${blue}...${defaultColor}${end}`;
219
+ skipped = true;
220
+ }
221
+ if (other !== "") {
222
+ end = `\n ${other}${end}`;
223
+ other = "";
224
+ }
225
+
226
+ let printedLines = 0;
227
+ let identical = 0;
228
+ const msg = kReadableOperator[operator] +
229
+ `\n${green}+ actual${defaultColor} ${red}- expected${defaultColor}`;
230
+ const skippedMsg = ` ${blue}...${defaultColor} Lines skipped`;
231
+
232
+ let lines = actualLines;
233
+ let plusMinus = `${green}+${defaultColor}`;
234
+ let maxLength = expectedLines.length;
235
+ if (actualLines.length < maxLines) {
236
+ lines = expectedLines;
237
+ plusMinus = `${red}-${defaultColor}`;
238
+ maxLength = actualLines.length;
239
+ }
240
+
241
+ for (i = 0; i < maxLines; i++) {
242
+ if (maxLength < i + 1) {
243
+ // If more than two former lines are identical, print them. Collapse them
244
+ // in case more than five lines were identical.
245
+ if (identical > 2) {
246
+ if (identical > 3) {
247
+ if (identical > 4) {
248
+ if (identical === 5) {
249
+ res += `\n ${lines[i - 3]}`;
250
+ printedLines++;
251
+ } else {
252
+ res += `\n${blue}...${defaultColor}`;
253
+ skipped = true;
254
+ }
255
+ }
256
+ res += `\n ${lines[i - 2]}`;
257
+ printedLines++;
258
+ }
259
+ res += `\n ${lines[i - 1]}`;
260
+ printedLines++;
261
+ }
262
+ // No identical lines before.
263
+ identical = 0;
264
+ // Add the expected line to the cache.
265
+ if (lines === actualLines) {
266
+ res += `\n${plusMinus} ${lines[i]}`;
267
+ } else {
268
+ other += `\n${plusMinus} ${lines[i]}`;
269
+ }
270
+ printedLines++;
271
+ // Only extra actual lines exist
272
+ // Lines diverge
273
+ } else {
274
+ const expectedLine = expectedLines[i];
275
+ let actualLine = actualLines[i];
276
+ // If the lines diverge, specifically check for lines that only diverge by
277
+ // a trailing comma. In that case it is actually identical and we should
278
+ // mark it as such.
279
+ let divergingLines = actualLine !== expectedLine &&
280
+ (!actualLine.endsWith(",") ||
281
+ actualLine.slice(0, -1) !== expectedLine);
282
+ // If the expected line has a trailing comma but is otherwise identical,
283
+ // add a comma at the end of the actual line. Otherwise the output could
284
+ // look weird as in:
285
+ //
286
+ // [
287
+ // 1 // No comma at the end!
288
+ // + 2
289
+ // ]
290
+ //
291
+ if (
292
+ divergingLines &&
293
+ expectedLine.endsWith(",") &&
294
+ expectedLine.slice(0, -1) === actualLine
295
+ ) {
296
+ divergingLines = false;
297
+ actualLine += ",";
298
+ }
299
+ if (divergingLines) {
300
+ // If more than two former lines are identical, print them. Collapse
301
+ // them in case more than five lines were identical.
302
+ if (identical > 2) {
303
+ if (identical > 3) {
304
+ if (identical > 4) {
305
+ if (identical === 5) {
306
+ res += `\n ${actualLines[i - 3]}`;
307
+ printedLines++;
308
+ } else {
309
+ res += `\n${blue}...${defaultColor}`;
310
+ skipped = true;
311
+ }
312
+ }
313
+ res += `\n ${actualLines[i - 2]}`;
314
+ printedLines++;
315
+ }
316
+ res += `\n ${actualLines[i - 1]}`;
317
+ printedLines++;
318
+ }
319
+ // No identical lines before.
320
+ identical = 0;
321
+ // Add the actual line to the result and cache the expected diverging
322
+ // line so consecutive diverging lines show up as +++--- and not +-+-+-.
323
+ res += `\n${green}+${defaultColor} ${actualLine}`;
324
+ other += `\n${red}-${defaultColor} ${expectedLine}`;
325
+ printedLines += 2;
326
+ // Lines are identical
327
+ } else {
328
+ // Add all cached information to the result before adding other things
329
+ // and reset the cache.
330
+ res += other;
331
+ other = "";
332
+ identical++;
333
+ // The very first identical line since the last diverging line is be
334
+ // added to the result.
335
+ if (identical <= 2) {
336
+ res += `\n ${actualLine}`;
337
+ printedLines++;
338
+ }
339
+ }
340
+ }
341
+ // Inspected object to big (Show ~50 rows max)
342
+ if (printedLines > 50 && i < maxLines - 2) {
343
+ return `${msg}${skippedMsg}\n${res}\n${blue}...${defaultColor}${other}\n` +
344
+ `${blue}...${defaultColor}`;
345
+ }
346
+ }
347
+
348
+ return `${msg}${skipped ? skippedMsg : ""}\n${res}${other}${end}${indicator}`;
349
+ }
350
+
351
+ export interface AssertionErrorDetailsDescriptor {
352
+ message: string;
353
+ actual: unknown;
354
+ expected: unknown;
355
+ operator: string;
356
+ stack: Error;
357
+ }
358
+
359
+ export interface AssertionErrorConstructorOptions {
360
+ message?: string;
361
+ actual?: unknown;
362
+ expected?: unknown;
363
+ operator?: string;
364
+ details?: AssertionErrorDetailsDescriptor[];
365
+ // deno-lint-ignore ban-types
366
+ stackStartFn?: Function;
367
+ // Compatibility with older versions.
368
+ // deno-lint-ignore ban-types
369
+ stackStartFunction?: Function;
370
+ }
371
+
372
+ interface ErrorWithStackTraceLimit extends ErrorConstructor {
373
+ stackTraceLimit: number;
374
+ }
375
+
376
+ export class AssertionError extends Error {
377
+ [key: string]: unknown;
378
+
379
+ // deno-lint-ignore constructor-super
380
+ constructor(options: AssertionErrorConstructorOptions) {
381
+ if (typeof options !== "object" || options === null) {
382
+ throw new ERR_INVALID_ARG_TYPE("options", "Object", options);
383
+ }
384
+ const {
385
+ message,
386
+ operator,
387
+ stackStartFn,
388
+ details,
389
+ // Compatibility with older versions.
390
+ stackStartFunction,
391
+ } = options;
392
+ let {
393
+ actual,
394
+ expected,
395
+ } = options;
396
+
397
+ // TODO(schwarzkopfb): `stackTraceLimit` should be added to `ErrorConstructor` in
398
+ // cli/dts/lib.deno.shared_globals.d.ts
399
+ const limit = (Error as ErrorWithStackTraceLimit).stackTraceLimit;
400
+ (Error as ErrorWithStackTraceLimit).stackTraceLimit = 0;
401
+
402
+ if (message != null) {
403
+ super(String(message));
404
+ } else {
405
+ if (Deno.isatty(Deno.stderr.rid)) {
406
+ // Reset on each call to make sure we handle dynamically set environment
407
+ // variables correct.
408
+ if (Deno.noColor) {
409
+ blue = "";
410
+ green = "";
411
+ defaultColor = "";
412
+ red = "";
413
+ } else {
414
+ blue = "\u001b[34m";
415
+ green = "\u001b[32m";
416
+ defaultColor = "\u001b[39m";
417
+ red = "\u001b[31m";
418
+ }
419
+ }
420
+ // Prevent the error stack from being visible by duplicating the error
421
+ // in a very close way to the original in case both sides are actually
422
+ // instances of Error.
423
+ if (
424
+ typeof actual === "object" && actual !== null &&
425
+ typeof expected === "object" && expected !== null &&
426
+ "stack" in actual && actual instanceof Error &&
427
+ "stack" in expected && expected instanceof Error
428
+ ) {
429
+ actual = copyError(actual);
430
+ expected = copyError(expected);
431
+ }
432
+
433
+ if (operator === "deepStrictEqual" || operator === "strictEqual") {
434
+ super(createErrDiff(actual, expected, operator));
435
+ } else if (
436
+ operator === "notDeepStrictEqual" ||
437
+ operator === "notStrictEqual"
438
+ ) {
439
+ // In case the objects are equal but the operator requires unequal, show
440
+ // the first object and say A equals B
441
+ let base = kReadableOperator[operator];
442
+ const res = inspectValue(actual).split("\n");
443
+
444
+ // In case "actual" is an object or a function, it should not be
445
+ // reference equal.
446
+ if (
447
+ operator === "notStrictEqual" &&
448
+ ((typeof actual === "object" && actual !== null) ||
449
+ typeof actual === "function")
450
+ ) {
451
+ base = kReadableOperator.notStrictEqualObject;
452
+ }
453
+
454
+ // Only remove lines in case it makes sense to collapse those.
455
+ if (res.length > 50) {
456
+ res[46] = `${blue}...${defaultColor}`;
457
+ while (res.length > 47) {
458
+ res.pop();
459
+ }
460
+ }
461
+
462
+ // Only print a single input.
463
+ if (res.length === 1) {
464
+ super(`${base}${res[0].length > 5 ? "\n\n" : " "}${res[0]}`);
465
+ } else {
466
+ super(`${base}\n\n${res.join("\n")}\n`);
467
+ }
468
+ } else {
469
+ let res = inspectValue(actual);
470
+ let other = inspectValue(expected);
471
+ const knownOperator = kReadableOperator[operator ?? ""];
472
+ if (operator === "notDeepEqual" && res === other) {
473
+ res = `${knownOperator}\n\n${res}`;
474
+ if (res.length > 1024) {
475
+ res = `${res.slice(0, 1021)}...`;
476
+ }
477
+ super(res);
478
+ } else {
479
+ if (res.length > 512) {
480
+ res = `${res.slice(0, 509)}...`;
481
+ }
482
+ if (other.length > 512) {
483
+ other = `${other.slice(0, 509)}...`;
484
+ }
485
+ if (operator === "deepEqual") {
486
+ res = `${knownOperator}\n\n${res}\n\nshould loosely deep-equal\n\n`;
487
+ } else {
488
+ const newOp = kReadableOperator[`${operator}Unequal`];
489
+ if (newOp) {
490
+ res = `${newOp}\n\n${res}\n\nshould not loosely deep-equal\n\n`;
491
+ } else {
492
+ other = ` ${operator} ${other}`;
493
+ }
494
+ }
495
+ super(`${res}${other}`);
496
+ }
497
+ }
498
+ }
499
+
500
+ (Error as ErrorWithStackTraceLimit).stackTraceLimit = limit;
501
+
502
+ this.generatedMessage = !message;
503
+ ObjectDefineProperty(this, "name", {
504
+ __proto__: null,
505
+ value: "AssertionError [ERR_ASSERTION]",
506
+ enumerable: false,
507
+ writable: true,
508
+ configurable: true,
509
+ // deno-lint-ignore no-explicit-any
510
+ } as any);
511
+ this.code = "ERR_ASSERTION";
512
+
513
+ if (details) {
514
+ this.actual = undefined;
515
+ this.expected = undefined;
516
+ this.operator = undefined;
517
+
518
+ for (let i = 0; i < details.length; i++) {
519
+ this["message " + i] = details[i].message;
520
+ this["actual " + i] = details[i].actual;
521
+ this["expected " + i] = details[i].expected;
522
+ this["operator " + i] = details[i].operator;
523
+ this["stack trace " + i] = details[i].stack;
524
+ }
525
+ } else {
526
+ this.actual = actual;
527
+ this.expected = expected;
528
+ this.operator = operator;
529
+ }
530
+
531
+ // @ts-ignore this function is not available in lib.dom.d.ts
532
+ Error.captureStackTrace(this, stackStartFn || stackStartFunction);
533
+ // Create error message including the error code in the name.
534
+ this.stack;
535
+ // Reset the name.
536
+ this.name = "AssertionError";
537
+ }
538
+
539
+ override toString() {
540
+ return `${this.name} [${this.code}]: ${this.message}`;
541
+ }
542
+
543
+ [inspect.custom](_recurseTimes: number, ctx: Record<string, unknown>) {
544
+ // Long strings should not be fully inspected.
545
+ const tmpActual = this.actual;
546
+ const tmpExpected = this.expected;
547
+
548
+ for (const name of ["actual", "expected"]) {
549
+ if (typeof this[name] === "string") {
550
+ const value = this[name] as string;
551
+ const lines = value.split("\n");
552
+ if (lines.length > 10) {
553
+ lines.length = 10;
554
+ this[name] = `${lines.join("\n")}\n...`;
555
+ } else if (value.length > 512) {
556
+ this[name] = `${value.slice(512)}...`;
557
+ }
558
+ }
559
+ }
560
+
561
+ // This limits the `actual` and `expected` property default inspection to
562
+ // the minimum depth. Otherwise those values would be too verbose compared
563
+ // to the actual error message which contains a combined view of these two
564
+ // input values.
565
+ const result = inspect(this, {
566
+ ...ctx,
567
+ customInspect: false,
568
+ depth: 0,
569
+ });
570
+
571
+ // Reset the properties after inspection.
572
+ this.actual = tmpActual;
573
+ this.expected = tmpExpected;
574
+
575
+ return result;
576
+ }
577
+ }
578
+
579
+ export default AssertionError;