@netlify/plugin-nextjs 4.40.1 → 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 (161) hide show
  1. package/lib/helpers/edge.js +1 -0
  2. package/lib/templates/vendor.js +20 -0
  3. package/package.json +7 -4
  4. package/src/templates/edge/next-dev.js +3 -3
  5. package/src/templates/edge/shims.js +6 -6
  6. package/src/templates/edge-shared/next-utils.ts +3 -3
  7. package/src/templates/edge-shared/utils.ts +1 -1
  8. package/src/templates/vendor/deno.land/std@0.134.0/fmt/colors.ts +536 -0
  9. package/src/templates/vendor/deno.land/std@0.134.0/testing/_diff.ts +360 -0
  10. package/src/templates/vendor/deno.land/std@0.134.0/testing/asserts.ts +866 -0
  11. package/src/templates/vendor/deno.land/std@0.175.0/_util/asserts.ts +25 -0
  12. package/src/templates/vendor/deno.land/std@0.175.0/_util/os.ts +23 -0
  13. package/src/templates/vendor/deno.land/std@0.175.0/async/abortable.ts +149 -0
  14. package/src/templates/vendor/deno.land/std@0.175.0/async/deadline.ts +30 -0
  15. package/src/templates/vendor/deno.land/std@0.175.0/async/debounce.ts +79 -0
  16. package/src/templates/vendor/deno.land/std@0.175.0/async/deferred.ts +48 -0
  17. package/src/templates/vendor/deno.land/std@0.175.0/async/delay.ts +67 -0
  18. package/src/templates/vendor/deno.land/std@0.175.0/async/mod.ts +18 -0
  19. package/src/templates/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +97 -0
  20. package/src/templates/vendor/deno.land/std@0.175.0/async/pool.ts +95 -0
  21. package/src/templates/vendor/deno.land/std@0.175.0/async/retry.ts +81 -0
  22. package/src/templates/vendor/deno.land/std@0.175.0/async/tee.ts +100 -0
  23. package/src/templates/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +49 -0
  24. package/src/templates/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +29 -0
  25. package/src/templates/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +45 -0
  26. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64.ts +144 -0
  27. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64url.ts +70 -0
  28. package/src/templates/vendor/deno.land/std@0.175.0/flags/mod.ts +785 -0
  29. package/src/templates/vendor/deno.land/std@0.175.0/fmt/colors.ts +569 -0
  30. package/src/templates/vendor/deno.land/std@0.175.0/fmt/printf.ts +939 -0
  31. package/src/templates/vendor/deno.land/std@0.175.0/http/cookie.ts +403 -0
  32. package/src/templates/vendor/deno.land/std@0.175.0/node/_core.ts +77 -0
  33. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.d.ts +848 -0
  34. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.mjs +1033 -0
  35. package/src/templates/vendor/deno.land/std@0.175.0/node/_global.d.ts +66 -0
  36. package/src/templates/vendor/deno.land/std@0.175.0/node/_next_tick.ts +173 -0
  37. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +4 -0
  38. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/process.ts +131 -0
  39. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +7 -0
  40. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +146 -0
  41. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.d.ts +1488 -0
  42. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.mjs +746 -0
  43. package/src/templates/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +129 -0
  44. package/src/templates/vendor/deno.land/std@0.175.0/node/_utils.ts +206 -0
  45. package/src/templates/vendor/deno.land/std@0.175.0/node/assert.ts +940 -0
  46. package/src/templates/vendor/deno.land/std@0.175.0/node/assertion_error.ts +579 -0
  47. package/src/templates/vendor/deno.land/std@0.175.0/node/async_hooks.ts +331 -0
  48. package/src/templates/vendor/deno.land/std@0.175.0/node/buffer.ts +13 -0
  49. package/src/templates/vendor/deno.land/std@0.175.0/node/events.ts +14 -0
  50. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +2074 -0
  51. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +2607 -0
  52. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +16 -0
  53. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +5 -0
  54. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +7 -0
  55. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/errors.ts +2867 -0
  56. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +123 -0
  57. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +16 -0
  58. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/net.ts +95 -0
  59. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +72 -0
  60. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/options.ts +45 -0
  61. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +30 -0
  62. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +272 -0
  63. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +137 -0
  64. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +580 -0
  65. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +320 -0
  66. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +229 -0
  67. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +242 -0
  68. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +669 -0
  69. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +118 -0
  70. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +2237 -0
  71. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +113 -0
  72. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util.mjs +143 -0
  73. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +317 -0
  74. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +229 -0
  75. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +16 -0
  76. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +18 -0
  77. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +12 -0
  78. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +86 -0
  79. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +16873 -0
  80. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +66 -0
  81. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +152 -0
  82. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +130 -0
  83. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +541 -0
  84. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +3 -0
  85. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +80 -0
  86. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +900 -0
  87. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +3 -0
  88. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +3 -0
  89. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +14 -0
  90. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +3 -0
  91. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +3 -0
  92. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +3 -0
  93. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +3 -0
  94. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +50 -0
  95. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +3 -0
  96. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +3 -0
  97. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +3 -0
  98. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +3 -0
  99. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +3 -0
  100. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +3 -0
  101. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +108 -0
  102. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +3 -0
  103. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +3 -0
  104. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +3 -0
  105. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +84 -0
  106. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +39 -0
  107. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +3 -0
  108. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +3 -0
  109. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +3 -0
  110. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +392 -0
  111. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +3 -0
  112. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +3 -0
  113. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +3 -0
  114. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +3 -0
  115. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +3 -0
  116. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +354 -0
  117. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +15 -0
  118. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +27 -0
  119. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +3 -0
  120. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +488 -0
  121. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +3 -0
  122. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +3 -0
  123. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +3 -0
  124. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +3 -0
  125. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +186 -0
  126. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +496 -0
  127. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +3 -0
  128. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +126 -0
  129. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +437 -0
  130. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +3 -0
  131. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +3 -0
  132. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +3 -0
  133. package/src/templates/vendor/deno.land/std@0.175.0/node/process.ts +705 -0
  134. package/src/templates/vendor/deno.land/std@0.175.0/node/stream.ts +37 -0
  135. package/src/templates/vendor/deno.land/std@0.175.0/node/string_decoder.ts +337 -0
  136. package/src/templates/vendor/deno.land/std@0.175.0/node/util/types.ts +4 -0
  137. package/src/templates/vendor/deno.land/std@0.175.0/node/util.ts +289 -0
  138. package/src/templates/vendor/deno.land/std@0.175.0/path/_constants.ts +49 -0
  139. package/src/templates/vendor/deno.land/std@0.175.0/path/_interface.ts +30 -0
  140. package/src/templates/vendor/deno.land/std@0.175.0/path/_util.ts +194 -0
  141. package/src/templates/vendor/deno.land/std@0.175.0/path/common.ts +40 -0
  142. package/src/templates/vendor/deno.land/std@0.175.0/path/glob.ts +418 -0
  143. package/src/templates/vendor/deno.land/std@0.175.0/path/mod.ts +53 -0
  144. package/src/templates/vendor/deno.land/std@0.175.0/path/posix.ts +487 -0
  145. package/src/templates/vendor/deno.land/std@0.175.0/path/separator.ts +7 -0
  146. package/src/templates/vendor/deno.land/std@0.175.0/path/win32.ts +962 -0
  147. package/src/templates/vendor/deno.land/std@0.175.0/streams/write_all.ts +64 -0
  148. package/src/templates/vendor/deno.land/std@0.175.0/testing/_diff.ts +440 -0
  149. package/src/templates/vendor/deno.land/std@0.175.0/testing/_format.ts +23 -0
  150. package/src/templates/vendor/deno.land/std@0.175.0/testing/asserts.ts +906 -0
  151. package/src/templates/vendor/deno.land/std@0.175.0/types.d.ts +89 -0
  152. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +133 -0
  153. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +112 -0
  154. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +88 -0
  155. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +974 -0
  156. package/src/templates/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +621 -0
  157. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +13 -0
  158. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +12 -0
  159. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +5 -0
  160. package/src/templates/vendor/import_map.json +13 -0
  161. package/src/templates/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +50 -0
@@ -0,0 +1,392 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright Joyent, Inc. and other Node contributors.
3
+ //
4
+ // Permission is hereby granted, free of charge, to any person obtaining a
5
+ // copy of this software and associated documentation files (the
6
+ // "Software"), to deal in the Software without restriction, including
7
+ // without limitation the rights to use, copy, modify, merge, publish,
8
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
9
+ // persons to whom the Software is furnished to do so, subject to the
10
+ // following conditions:
11
+ //
12
+ // The above copyright notice and this permission notice shall be included
13
+ // in all copies or substantial portions of the Software.
14
+ //
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ // This module ports:
24
+ // - https://github.com/nodejs/node/blob/master/src/pipe_wrap.cc
25
+ // - https://github.com/nodejs/node/blob/master/src/pipe_wrap.h
26
+
27
+ import { notImplemented } from "../_utils.ts";
28
+ import { unreachable } from "../../_util/asserts.ts";
29
+ import { ConnectionWrap } from "./connection_wrap.ts";
30
+ import { AsyncWrap, providerType } from "./async_wrap.ts";
31
+ import { LibuvStreamWrap } from "./stream_wrap.ts";
32
+ import { codeMap } from "./uv.ts";
33
+ import { delay } from "../../async/mod.ts";
34
+ import { kStreamBaseField } from "./stream_wrap.ts";
35
+ import {
36
+ ceilPowOf2,
37
+ INITIAL_ACCEPT_BACKOFF_DELAY,
38
+ MAX_ACCEPT_BACKOFF_DELAY,
39
+ } from "./_listen.ts";
40
+ import { isWindows } from "../../_util/os.ts";
41
+ import { fs } from "./constants.ts";
42
+
43
+ export enum socketType {
44
+ SOCKET,
45
+ SERVER,
46
+ IPC,
47
+ }
48
+
49
+ export class Pipe extends ConnectionWrap {
50
+ override reading = false;
51
+ ipc: boolean;
52
+
53
+ // REF: https://github.com/nodejs/node/blob/master/deps/uv/src/win/pipe.c#L48
54
+ #pendingInstances = 4;
55
+
56
+ #address?: string;
57
+
58
+ #backlog?: number;
59
+ #listener!: Deno.Listener;
60
+ #connections = 0;
61
+
62
+ #closed = false;
63
+ #acceptBackoffDelay?: number;
64
+
65
+ constructor(type: number, conn?: Deno.UnixConn) {
66
+ let provider: providerType;
67
+ let ipc: boolean;
68
+
69
+ switch (type) {
70
+ case socketType.SOCKET: {
71
+ provider = providerType.PIPEWRAP;
72
+ ipc = false;
73
+
74
+ break;
75
+ }
76
+ case socketType.SERVER: {
77
+ provider = providerType.PIPESERVERWRAP;
78
+ ipc = false;
79
+
80
+ break;
81
+ }
82
+ case socketType.IPC: {
83
+ provider = providerType.PIPEWRAP;
84
+ ipc = true;
85
+
86
+ break;
87
+ }
88
+ default: {
89
+ unreachable();
90
+ }
91
+ }
92
+
93
+ super(provider, conn);
94
+
95
+ this.ipc = ipc;
96
+
97
+ if (conn && provider === providerType.PIPEWRAP) {
98
+ const localAddr = conn.localAddr as Deno.UnixAddr;
99
+ this.#address = localAddr.path;
100
+ }
101
+ }
102
+
103
+ open(_fd: number): number {
104
+ // REF: https://github.com/denoland/deno/issues/6529
105
+ notImplemented("Pipe.prototype.open");
106
+ }
107
+
108
+ /**
109
+ * Bind to a Unix domain or Windows named pipe.
110
+ * @param name Unix domain or Windows named pipe the server should listen to.
111
+ * @return An error status code.
112
+ */
113
+ bind(name: string) {
114
+ // Deno doesn't currently separate bind from connect. For now we noop under
115
+ // the assumption we will connect shortly.
116
+ // REF: https://doc.deno.land/deno/unstable/~/Deno.connect
117
+
118
+ this.#address = name;
119
+
120
+ return 0;
121
+ }
122
+
123
+ /**
124
+ * Connect to a Unix domain or Windows named pipe.
125
+ * @param req A PipeConnectWrap instance.
126
+ * @param address Unix domain or Windows named pipe the server should connect to.
127
+ * @return An error status code.
128
+ */
129
+ connect(req: PipeConnectWrap, address: string) {
130
+ if (isWindows) {
131
+ // REF: https://github.com/denoland/deno/issues/10244
132
+ notImplemented("Pipe.prototype.connect - Windows");
133
+ }
134
+
135
+ const connectOptions: Deno.UnixConnectOptions = {
136
+ path: address,
137
+ transport: "unix",
138
+ };
139
+
140
+ Deno.connect(connectOptions).then(
141
+ (conn: Deno.UnixConn) => {
142
+ const localAddr = conn.localAddr as Deno.UnixAddr;
143
+
144
+ this.#address = req.address = localAddr.path;
145
+ this[kStreamBaseField] = conn;
146
+
147
+ try {
148
+ this.afterConnect(req, 0);
149
+ } catch {
150
+ // swallow callback errors.
151
+ }
152
+ },
153
+ (e) => {
154
+ // TODO(cmorten): correct mapping of connection error to status code.
155
+ let code: number;
156
+
157
+ if (e instanceof Deno.errors.NotFound) {
158
+ code = codeMap.get("ENOENT")!;
159
+ } else if (e instanceof Deno.errors.PermissionDenied) {
160
+ code = codeMap.get("EACCES")!;
161
+ } else {
162
+ code = codeMap.get("ECONNREFUSED")!;
163
+ }
164
+
165
+ try {
166
+ this.afterConnect(req, code);
167
+ } catch {
168
+ // swallow callback errors.
169
+ }
170
+ },
171
+ );
172
+
173
+ return 0;
174
+ }
175
+
176
+ /**
177
+ * Listen for new connections.
178
+ * @param backlog The maximum length of the queue of pending connections.
179
+ * @return An error status code.
180
+ */
181
+ listen(backlog: number): number {
182
+ if (isWindows) {
183
+ // REF: https://github.com/denoland/deno/issues/10244
184
+ notImplemented("Pipe.prototype.listen - Windows");
185
+ }
186
+
187
+ this.#backlog = isWindows
188
+ ? this.#pendingInstances
189
+ : ceilPowOf2(backlog + 1);
190
+
191
+ const listenOptions = {
192
+ path: this.#address!,
193
+ transport: "unix" as const,
194
+ };
195
+
196
+ let listener;
197
+
198
+ try {
199
+ listener = Deno.listen(listenOptions);
200
+ } catch (e) {
201
+ if (e instanceof Deno.errors.AddrInUse) {
202
+ return codeMap.get("EADDRINUSE")!;
203
+ } else if (e instanceof Deno.errors.AddrNotAvailable) {
204
+ return codeMap.get("EADDRNOTAVAIL")!;
205
+ }
206
+
207
+ // TODO(cmorten): map errors to appropriate error codes.
208
+ return codeMap.get("UNKNOWN")!;
209
+ }
210
+
211
+ const address = listener.addr as Deno.UnixAddr;
212
+ this.#address = address.path;
213
+
214
+ this.#listener = listener;
215
+ this.#accept();
216
+
217
+ return 0;
218
+ }
219
+
220
+ override ref() {
221
+ if (this.#listener) {
222
+ this.#listener.ref();
223
+ }
224
+ }
225
+
226
+ override unref() {
227
+ if (this.#listener) {
228
+ this.#listener.unref();
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Set the number of pending pipe instance handles when the pipe server is
234
+ * waiting for connections. This setting applies to Windows only.
235
+ * @param instances Number of pending pipe instances.
236
+ */
237
+ setPendingInstances(instances: number) {
238
+ this.#pendingInstances = instances;
239
+ }
240
+
241
+ /**
242
+ * Alters pipe permissions, allowing it to be accessed from processes run by
243
+ * different users. Makes the pipe writable or readable by all users. Mode
244
+ * can be `UV_WRITABLE`, `UV_READABLE` or `UV_WRITABLE | UV_READABLE`. This
245
+ * function is blocking.
246
+ * @param mode Pipe permissions mode.
247
+ * @return An error status code.
248
+ */
249
+ fchmod(mode: number) {
250
+ if (
251
+ mode != constants.UV_READABLE &&
252
+ mode != constants.UV_WRITABLE &&
253
+ mode != (constants.UV_WRITABLE | constants.UV_READABLE)
254
+ ) {
255
+ return codeMap.get("EINVAL");
256
+ }
257
+
258
+ let desired_mode = 0;
259
+
260
+ if (mode & constants.UV_READABLE) {
261
+ desired_mode |= fs.S_IRUSR | fs.S_IRGRP | fs.S_IROTH;
262
+ }
263
+ if (mode & constants.UV_WRITABLE) {
264
+ desired_mode |= fs.S_IWUSR | fs.S_IWGRP | fs.S_IWOTH;
265
+ }
266
+
267
+ // TODO(cmorten): this will incorrectly throw on Windows
268
+ // REF: https://github.com/denoland/deno/issues/4357
269
+ try {
270
+ Deno.chmodSync(this.#address!, desired_mode);
271
+ } catch {
272
+ // TODO(cmorten): map errors to appropriate error codes.
273
+ return codeMap.get("UNKNOWN")!;
274
+ }
275
+
276
+ return 0;
277
+ }
278
+
279
+ /** Handle backoff delays following an unsuccessful accept. */
280
+ async #acceptBackoff() {
281
+ // Backoff after transient errors to allow time for the system to
282
+ // recover, and avoid blocking up the event loop with a continuously
283
+ // running loop.
284
+ if (!this.#acceptBackoffDelay) {
285
+ this.#acceptBackoffDelay = INITIAL_ACCEPT_BACKOFF_DELAY;
286
+ } else {
287
+ this.#acceptBackoffDelay *= 2;
288
+ }
289
+
290
+ if (this.#acceptBackoffDelay >= MAX_ACCEPT_BACKOFF_DELAY) {
291
+ this.#acceptBackoffDelay = MAX_ACCEPT_BACKOFF_DELAY;
292
+ }
293
+
294
+ await delay(this.#acceptBackoffDelay);
295
+
296
+ this.#accept();
297
+ }
298
+
299
+ /** Accept new connections. */
300
+ async #accept(): Promise<void> {
301
+ if (this.#closed) {
302
+ return;
303
+ }
304
+
305
+ if (this.#connections > this.#backlog!) {
306
+ this.#acceptBackoff();
307
+
308
+ return;
309
+ }
310
+
311
+ let connection: Deno.Conn;
312
+
313
+ try {
314
+ connection = await this.#listener.accept();
315
+ } catch (e) {
316
+ if (e instanceof Deno.errors.BadResource && this.#closed) {
317
+ // Listener and server has closed.
318
+ return;
319
+ }
320
+
321
+ try {
322
+ // TODO(cmorten): map errors to appropriate error codes.
323
+ this.onconnection!(codeMap.get("UNKNOWN")!, undefined);
324
+ } catch {
325
+ // swallow callback errors.
326
+ }
327
+
328
+ this.#acceptBackoff();
329
+
330
+ return;
331
+ }
332
+
333
+ // Reset the backoff delay upon successful accept.
334
+ this.#acceptBackoffDelay = undefined;
335
+
336
+ const connectionHandle = new Pipe(socketType.SOCKET, connection);
337
+ this.#connections++;
338
+
339
+ try {
340
+ this.onconnection!(0, connectionHandle);
341
+ } catch {
342
+ // swallow callback errors.
343
+ }
344
+
345
+ return this.#accept();
346
+ }
347
+
348
+ /** Handle server closure. */
349
+ override _onClose(): number {
350
+ this.#closed = true;
351
+ this.reading = false;
352
+
353
+ this.#address = undefined;
354
+
355
+ this.#backlog = undefined;
356
+ this.#connections = 0;
357
+ this.#acceptBackoffDelay = undefined;
358
+
359
+ if (this.provider === providerType.PIPESERVERWRAP) {
360
+ try {
361
+ this.#listener.close();
362
+ } catch {
363
+ // listener already closed
364
+ }
365
+ }
366
+
367
+ return LibuvStreamWrap.prototype._onClose.call(this);
368
+ }
369
+ }
370
+
371
+ export class PipeConnectWrap extends AsyncWrap {
372
+ oncomplete!: (
373
+ status: number,
374
+ handle: ConnectionWrap,
375
+ req: PipeConnectWrap,
376
+ readable: boolean,
377
+ writeable: boolean,
378
+ ) => void;
379
+ address!: string;
380
+
381
+ constructor() {
382
+ super(providerType.PIPECONNECTWRAP);
383
+ }
384
+ }
385
+
386
+ export enum constants {
387
+ SOCKET = socketType.SOCKET,
388
+ SERVER = socketType.SERVER,
389
+ IPC = socketType.IPC,
390
+ UV_READABLE = 1,
391
+ UV_WRITABLE = 2,
392
+ }
@@ -0,0 +1,3 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+
3
+ export {};
@@ -0,0 +1,3 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+
3
+ export {};
@@ -0,0 +1,3 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+
3
+ export {};
@@ -0,0 +1,3 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+
3
+ export {};
@@ -0,0 +1,3 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+
3
+ export {};