@volter/tabnode 0.2.14-volter.88

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 (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,1418 @@
1
+ 'use strict';
2
+
3
+ const {
4
+ ArrayFrom,
5
+ ArrayPrototypeFilter,
6
+ ArrayPrototypeIndexOf,
7
+ ArrayPrototypeJoin,
8
+ ArrayPrototypeMap,
9
+ ArrayPrototypePop,
10
+ ArrayPrototypePush,
11
+ ArrayPrototypeReverse,
12
+ ArrayPrototypeShift,
13
+ ArrayPrototypeSplice,
14
+ ArrayPrototypeUnshift,
15
+ DateNow,
16
+ FunctionPrototypeCall,
17
+ MathCeil,
18
+ MathFloor,
19
+ MathMax,
20
+ MathMaxApply,
21
+ NumberIsFinite,
22
+ ObjectSetPrototypeOf,
23
+ RegExpPrototypeExec,
24
+ SafeStringIterator,
25
+ StringPrototypeCodePointAt,
26
+ StringPrototypeEndsWith,
27
+ StringPrototypeRepeat,
28
+ StringPrototypeSlice,
29
+ StringPrototypeStartsWith,
30
+ StringPrototypeTrim,
31
+ Symbol,
32
+ SymbolAsyncIterator,
33
+ } = primordials;
34
+
35
+ const {
36
+ AbortError,
37
+ codes: {
38
+ ERR_INVALID_ARG_VALUE,
39
+ ERR_USE_AFTER_CLOSE,
40
+ },
41
+ } = require('internal/errors');
42
+
43
+ const {
44
+ validateAbortSignal,
45
+ validateArray,
46
+ validateNumber,
47
+ validateString,
48
+ validateUint32,
49
+ } = require('internal/validators');
50
+ const {
51
+ assignFunctionName,
52
+ kEmptyObject,
53
+ SymbolDispose,
54
+ } = require('internal/util');
55
+ const {
56
+ inspect,
57
+ getStringWidth,
58
+ stripVTControlCharacters,
59
+ } = require('internal/util/inspect');
60
+ const EventEmitter = require('events');
61
+ const { addAbortListener } = require('internal/events/abort_listener');
62
+ const {
63
+ charLengthAt,
64
+ charLengthLeft,
65
+ commonPrefix,
66
+ kSubstringSearch,
67
+ } = require('internal/readline/utils');
68
+ let emitKeypressEvents;
69
+ let kFirstEventParam;
70
+ const {
71
+ clearScreenDown,
72
+ cursorTo,
73
+ moveCursor,
74
+ } = require('internal/readline/callbacks');
75
+
76
+ const { StringDecoder } = require('string_decoder');
77
+
78
+ const kHistorySize = 30;
79
+ const kMaxUndoRedoStackSize = 2048;
80
+ const kMincrlfDelay = 100;
81
+ // \r\n, \n, or \r followed by something other than \n
82
+ const lineEnding = /\r?\n|\r(?!\n)/g;
83
+
84
+ const kLineObjectStream = Symbol('line object stream');
85
+ const kQuestionCancel = Symbol('kQuestionCancel');
86
+ const kQuestion = Symbol('kQuestion');
87
+
88
+ // GNU readline library - keyseq-timeout is 500ms (default)
89
+ const ESCAPE_CODE_TIMEOUT = 500;
90
+
91
+ // Max length of the kill ring
92
+ const kMaxLengthOfKillRing = 32;
93
+
94
+ const kAddHistory = Symbol('_addHistory');
95
+ const kBeforeEdit = Symbol('_beforeEdit');
96
+ const kDecoder = Symbol('_decoder');
97
+ const kDeleteLeft = Symbol('_deleteLeft');
98
+ const kDeleteLineLeft = Symbol('_deleteLineLeft');
99
+ const kDeleteLineRight = Symbol('_deleteLineRight');
100
+ const kDeleteRight = Symbol('_deleteRight');
101
+ const kDeleteWordLeft = Symbol('_deleteWordLeft');
102
+ const kDeleteWordRight = Symbol('_deleteWordRight');
103
+ const kGetDisplayPos = Symbol('_getDisplayPos');
104
+ const kHistoryNext = Symbol('_historyNext');
105
+ const kHistoryPrev = Symbol('_historyPrev');
106
+ const kInsertString = Symbol('_insertString');
107
+ const kLine = Symbol('_line');
108
+ const kLine_buffer = Symbol('_line_buffer');
109
+ const kKillRing = Symbol('_killRing');
110
+ const kKillRingCursor = Symbol('_killRingCursor');
111
+ const kMoveCursor = Symbol('_moveCursor');
112
+ const kNormalWrite = Symbol('_normalWrite');
113
+ const kOldPrompt = Symbol('_oldPrompt');
114
+ const kOnLine = Symbol('_onLine');
115
+ const kPreviousKey = Symbol('_previousKey');
116
+ const kPrompt = Symbol('_prompt');
117
+ const kPushToKillRing = Symbol('_pushToKillRing');
118
+ const kPushToUndoStack = Symbol('_pushToUndoStack');
119
+ const kQuestionCallback = Symbol('_questionCallback');
120
+ const kQuestionReject = Symbol('_questionReject');
121
+ const kRedo = Symbol('_redo');
122
+ const kRedoStack = Symbol('_redoStack');
123
+ const kRefreshLine = Symbol('_refreshLine');
124
+ const kSawKeyPress = Symbol('_sawKeyPress');
125
+ const kSawReturnAt = Symbol('_sawReturnAt');
126
+ const kSetRawMode = Symbol('_setRawMode');
127
+ const kTabComplete = Symbol('_tabComplete');
128
+ const kTabCompleter = Symbol('_tabCompleter');
129
+ const kTtyWrite = Symbol('_ttyWrite');
130
+ const kUndo = Symbol('_undo');
131
+ const kUndoStack = Symbol('_undoStack');
132
+ const kWordLeft = Symbol('_wordLeft');
133
+ const kWordRight = Symbol('_wordRight');
134
+ const kWriteToOutput = Symbol('_writeToOutput');
135
+ const kYank = Symbol('_yank');
136
+ const kYanking = Symbol('_yanking');
137
+ const kYankPop = Symbol('_yankPop');
138
+
139
+ function InterfaceConstructor(input, output, completer, terminal) {
140
+ this[kSawReturnAt] = 0;
141
+ // TODO(BridgeAR): Document this property. The name is not ideal, so we
142
+ // might want to expose an alias and document that instead.
143
+ this.isCompletionEnabled = true;
144
+ this[kSawKeyPress] = false;
145
+ this[kPreviousKey] = null;
146
+ this.escapeCodeTimeout = ESCAPE_CODE_TIMEOUT;
147
+ this.tabSize = 8;
148
+
149
+ FunctionPrototypeCall(EventEmitter, this);
150
+
151
+ let history;
152
+ let historySize;
153
+ let removeHistoryDuplicates = false;
154
+ let crlfDelay;
155
+ let prompt = '> ';
156
+ let signal;
157
+
158
+ if (input?.input) {
159
+ // An options object was given
160
+ output = input.output;
161
+ completer = input.completer;
162
+ terminal = input.terminal;
163
+ history = input.history;
164
+ historySize = input.historySize;
165
+ signal = input.signal;
166
+ if (input.tabSize !== undefined) {
167
+ validateUint32(input.tabSize, 'tabSize', true);
168
+ this.tabSize = input.tabSize;
169
+ }
170
+ removeHistoryDuplicates = input.removeHistoryDuplicates;
171
+ if (input.prompt !== undefined) {
172
+ prompt = input.prompt;
173
+ }
174
+ if (input.escapeCodeTimeout !== undefined) {
175
+ if (NumberIsFinite(input.escapeCodeTimeout)) {
176
+ this.escapeCodeTimeout = input.escapeCodeTimeout;
177
+ } else {
178
+ throw new ERR_INVALID_ARG_VALUE(
179
+ 'input.escapeCodeTimeout',
180
+ this.escapeCodeTimeout,
181
+ );
182
+ }
183
+ }
184
+
185
+ if (signal) {
186
+ validateAbortSignal(signal, 'options.signal');
187
+ }
188
+
189
+ crlfDelay = input.crlfDelay;
190
+ input = input.input;
191
+ }
192
+
193
+ if (completer !== undefined && typeof completer !== 'function') {
194
+ throw new ERR_INVALID_ARG_VALUE('completer', completer);
195
+ }
196
+
197
+ if (history === undefined) {
198
+ history = [];
199
+ } else {
200
+ validateArray(history, 'history');
201
+ }
202
+
203
+ if (historySize === undefined) {
204
+ historySize = kHistorySize;
205
+ }
206
+
207
+ validateNumber(historySize, 'historySize', 0);
208
+
209
+ // Backwards compat; check the isTTY prop of the output stream
210
+ // when `terminal` was not specified
211
+ if (terminal === undefined && !(output === null || output === undefined)) {
212
+ terminal = !!output.isTTY;
213
+ }
214
+
215
+ const self = this;
216
+
217
+ this.line = '';
218
+ this[kSubstringSearch] = null;
219
+ this.output = output;
220
+ this.input = input;
221
+ this[kUndoStack] = [];
222
+ this[kRedoStack] = [];
223
+ this.history = history;
224
+ this.historySize = historySize;
225
+
226
+ // The kill ring is a global list of blocks of text that were previously
227
+ // killed (deleted). If its size exceeds kMaxLengthOfKillRing, the oldest
228
+ // element will be removed to make room for the latest deletion. With kill
229
+ // ring, users are able to recall (yank) or cycle (yank pop) among previously
230
+ // killed texts, quite similar to the behavior of Emacs.
231
+ this[kKillRing] = [];
232
+ this[kKillRingCursor] = 0;
233
+
234
+ this.removeHistoryDuplicates = !!removeHistoryDuplicates;
235
+ this.crlfDelay = crlfDelay ?
236
+ MathMax(kMincrlfDelay, crlfDelay) :
237
+ kMincrlfDelay;
238
+ this.completer = completer;
239
+
240
+ this.setPrompt(prompt);
241
+
242
+ this.terminal = !!terminal;
243
+
244
+
245
+ function onerror(err) {
246
+ self.emit('error', err);
247
+ }
248
+
249
+ function ondata(data) {
250
+ self[kNormalWrite](data);
251
+ }
252
+
253
+ function onend() {
254
+ if (
255
+ typeof self[kLine_buffer] === 'string' &&
256
+ self[kLine_buffer].length > 0
257
+ ) {
258
+ self.emit('line', self[kLine_buffer]);
259
+ }
260
+ self.close();
261
+ }
262
+
263
+ function ontermend() {
264
+ if (typeof self.line === 'string' && self.line.length > 0) {
265
+ self.emit('line', self.line);
266
+ }
267
+ self.close();
268
+ }
269
+
270
+ function onkeypress(s, key) {
271
+ self[kTtyWrite](s, key);
272
+ if (key?.sequence) {
273
+ // If the key.sequence is half of a surrogate pair
274
+ // (>= 0xd800 and <= 0xdfff), refresh the line so
275
+ // the character is displayed appropriately.
276
+ const ch = StringPrototypeCodePointAt(key.sequence, 0);
277
+ if (ch >= 0xd800 && ch <= 0xdfff) self[kRefreshLine]();
278
+ }
279
+ }
280
+
281
+ function onresize() {
282
+ self[kRefreshLine]();
283
+ }
284
+
285
+ this[kLineObjectStream] = undefined;
286
+
287
+ input.on('error', onerror);
288
+
289
+ if (!this.terminal) {
290
+ function onSelfCloseWithoutTerminal() {
291
+ input.removeListener('data', ondata);
292
+ input.removeListener('error', onerror);
293
+ input.removeListener('end', onend);
294
+ }
295
+
296
+ input.on('data', ondata);
297
+ input.on('end', onend);
298
+ self.once('close', onSelfCloseWithoutTerminal);
299
+ this[kDecoder] = new StringDecoder('utf8');
300
+ } else {
301
+ function onSelfCloseWithTerminal() {
302
+ input.removeListener('keypress', onkeypress);
303
+ input.removeListener('error', onerror);
304
+ input.removeListener('end', ontermend);
305
+ if (output !== null && output !== undefined) {
306
+ output.removeListener('resize', onresize);
307
+ }
308
+ }
309
+
310
+ emitKeypressEvents ??= require('internal/readline/emitKeypressEvents');
311
+ emitKeypressEvents(input, this);
312
+
313
+ // `input` usually refers to stdin
314
+ input.on('keypress', onkeypress);
315
+ input.on('end', ontermend);
316
+
317
+ this[kSetRawMode](true);
318
+ this.terminal = true;
319
+
320
+ // Cursor position on the line.
321
+ this.cursor = 0;
322
+
323
+ this.historyIndex = -1;
324
+
325
+ if (output !== null && output !== undefined)
326
+ output.on('resize', onresize);
327
+
328
+ self.once('close', onSelfCloseWithTerminal);
329
+ }
330
+
331
+ if (signal) {
332
+ const onAborted = () => self.close();
333
+ if (signal.aborted) {
334
+ process.nextTick(onAborted);
335
+ } else {
336
+ const disposable = addAbortListener(signal, onAborted);
337
+ self.once('close', disposable[SymbolDispose]);
338
+ }
339
+ }
340
+
341
+ // Current line
342
+ this.line = '';
343
+
344
+ input.resume();
345
+ }
346
+
347
+ ObjectSetPrototypeOf(InterfaceConstructor.prototype, EventEmitter.prototype);
348
+ ObjectSetPrototypeOf(InterfaceConstructor, EventEmitter);
349
+
350
+ class Interface extends InterfaceConstructor {
351
+ // eslint-disable-next-line no-useless-constructor
352
+ constructor(input, output, completer, terminal) {
353
+ super(input, output, completer, terminal);
354
+ }
355
+ get columns() {
356
+ if (this.output?.columns) return this.output.columns;
357
+ return Infinity;
358
+ }
359
+
360
+ /**
361
+ * Sets the prompt written to the output.
362
+ * @param {string} prompt
363
+ * @returns {void}
364
+ */
365
+ setPrompt(prompt) {
366
+ this[kPrompt] = prompt;
367
+ }
368
+
369
+ /**
370
+ * Returns the current prompt used by `rl.prompt()`.
371
+ * @returns {string}
372
+ */
373
+ getPrompt() {
374
+ return this[kPrompt];
375
+ }
376
+
377
+ [kSetRawMode](mode) {
378
+ const wasInRawMode = this.input.isRaw;
379
+
380
+ if (typeof this.input.setRawMode === 'function') {
381
+ this.input.setRawMode(mode);
382
+ }
383
+
384
+ return wasInRawMode;
385
+ }
386
+
387
+ /**
388
+ * Writes the configured `prompt` to a new line in `output`.
389
+ * @param {boolean} [preserveCursor]
390
+ * @returns {void}
391
+ */
392
+ prompt(preserveCursor) {
393
+ if (this.paused) this.resume();
394
+ if (this.terminal && process.env.TERM !== 'dumb') {
395
+ if (!preserveCursor) this.cursor = 0;
396
+ this[kRefreshLine]();
397
+ } else {
398
+ this[kWriteToOutput](this[kPrompt]);
399
+ }
400
+ }
401
+
402
+ [kQuestion](query, cb) {
403
+ if (this.closed) {
404
+ throw new ERR_USE_AFTER_CLOSE('readline');
405
+ }
406
+ if (this[kQuestionCallback]) {
407
+ this.prompt();
408
+ } else {
409
+ this[kOldPrompt] = this[kPrompt];
410
+ this.setPrompt(query);
411
+ this[kQuestionCallback] = cb;
412
+ this.prompt();
413
+ }
414
+ }
415
+
416
+ [kOnLine](line) {
417
+ if (this[kQuestionCallback]) {
418
+ const cb = this[kQuestionCallback];
419
+ this[kQuestionCallback] = null;
420
+ this.setPrompt(this[kOldPrompt]);
421
+ cb(line);
422
+ } else {
423
+ this.emit('line', line);
424
+ }
425
+ }
426
+
427
+ [kBeforeEdit](oldText, oldCursor) {
428
+ this[kPushToUndoStack](oldText, oldCursor);
429
+ }
430
+
431
+ [kQuestionCancel]() {
432
+ if (this[kQuestionCallback]) {
433
+ this[kQuestionCallback] = null;
434
+ this.setPrompt(this[kOldPrompt]);
435
+ this.clearLine();
436
+ }
437
+ }
438
+
439
+ [kWriteToOutput](stringToWrite) {
440
+ validateString(stringToWrite, 'stringToWrite');
441
+
442
+ if (this.output !== null && this.output !== undefined) {
443
+ this.output.write(stringToWrite);
444
+ }
445
+ }
446
+
447
+ [kAddHistory]() {
448
+ if (this.line.length === 0) return '';
449
+
450
+ // If the history is disabled then return the line
451
+ if (this.historySize === 0) return this.line;
452
+
453
+ // If the trimmed line is empty then return the line
454
+ if (StringPrototypeTrim(this.line).length === 0) return this.line;
455
+
456
+ if (this.history.length === 0 || this.history[0] !== this.line) {
457
+ if (this.removeHistoryDuplicates) {
458
+ // Remove older history line if identical to new one
459
+ const dupIndex = ArrayPrototypeIndexOf(this.history, this.line);
460
+ if (dupIndex !== -1) ArrayPrototypeSplice(this.history, dupIndex, 1);
461
+ }
462
+
463
+ ArrayPrototypeUnshift(this.history, this.line);
464
+
465
+ // Only store so many
466
+ if (this.history.length > this.historySize)
467
+ ArrayPrototypePop(this.history);
468
+ }
469
+
470
+ this.historyIndex = -1;
471
+
472
+ // The listener could change the history object, possibly
473
+ // to remove the last added entry if it is sensitive and should
474
+ // not be persisted in the history, like a password
475
+ const line = this.history[0];
476
+
477
+ // Emit history event to notify listeners of update
478
+ this.emit('history', this.history);
479
+
480
+ return line;
481
+ }
482
+
483
+ [kRefreshLine]() {
484
+ // line length
485
+ const line = this[kPrompt] + this.line;
486
+ const dispPos = this[kGetDisplayPos](line);
487
+ const lineCols = dispPos.cols;
488
+ const lineRows = dispPos.rows;
489
+
490
+ // cursor position
491
+ const cursorPos = this.getCursorPos();
492
+
493
+ // First move to the bottom of the current line, based on cursor pos
494
+ const prevRows = this.prevRows || 0;
495
+ if (prevRows > 0) {
496
+ moveCursor(this.output, 0, -prevRows);
497
+ }
498
+
499
+ // Cursor to left edge.
500
+ cursorTo(this.output, 0);
501
+ // erase data
502
+ clearScreenDown(this.output);
503
+
504
+ // Write the prompt and the current buffer content.
505
+ this[kWriteToOutput](line);
506
+
507
+ // Force terminal to allocate a new line
508
+ if (lineCols === 0) {
509
+ this[kWriteToOutput](' ');
510
+ }
511
+
512
+ // Move cursor to original position.
513
+ cursorTo(this.output, cursorPos.cols);
514
+
515
+ const diff = lineRows - cursorPos.rows;
516
+ if (diff > 0) {
517
+ moveCursor(this.output, 0, -diff);
518
+ }
519
+
520
+ this.prevRows = cursorPos.rows;
521
+ }
522
+
523
+ /**
524
+ * Closes the `readline.Interface` instance.
525
+ * @returns {void}
526
+ */
527
+ close() {
528
+ if (this.closed) return;
529
+ this.pause();
530
+ if (this.terminal) {
531
+ this[kSetRawMode](false);
532
+ }
533
+ this.closed = true;
534
+ this.emit('close');
535
+ }
536
+
537
+ /**
538
+ * Pauses the `input` stream.
539
+ * @returns {void | Interface}
540
+ */
541
+ pause() {
542
+ if (this.paused) return;
543
+ this.input.pause();
544
+ this.paused = true;
545
+ this.emit('pause');
546
+ return this;
547
+ }
548
+
549
+ /**
550
+ * Resumes the `input` stream if paused.
551
+ * @returns {void | Interface}
552
+ */
553
+ resume() {
554
+ if (!this.paused) return;
555
+ this.input.resume();
556
+ this.paused = false;
557
+ this.emit('resume');
558
+ return this;
559
+ }
560
+
561
+ /**
562
+ * Writes either `data` or a `key` sequence identified by
563
+ * `key` to the `output`.
564
+ * @param {string} d
565
+ * @param {{
566
+ * ctrl?: boolean;
567
+ * meta?: boolean;
568
+ * shift?: boolean;
569
+ * name?: string;
570
+ * }} [key]
571
+ * @returns {void}
572
+ */
573
+ write(d, key) {
574
+ if (this.paused) this.resume();
575
+ if (this.terminal) {
576
+ this[kTtyWrite](d, key);
577
+ } else {
578
+ this[kNormalWrite](d);
579
+ }
580
+ }
581
+
582
+ [kNormalWrite](b) {
583
+ if (b === undefined) {
584
+ return;
585
+ }
586
+ let string = this[kDecoder].write(b);
587
+ if (
588
+ this[kSawReturnAt] &&
589
+ DateNow() - this[kSawReturnAt] <= this.crlfDelay
590
+ ) {
591
+ if (StringPrototypeCodePointAt(string) === 10) string = StringPrototypeSlice(string, 1);
592
+ this[kSawReturnAt] = 0;
593
+ }
594
+
595
+ // Run test() on the new string chunk, not on the entire line buffer.
596
+ let newPartContainsEnding = RegExpPrototypeExec(lineEnding, string);
597
+ if (newPartContainsEnding !== null) {
598
+ if (this[kLine_buffer]) {
599
+ string = this[kLine_buffer] + string;
600
+ this[kLine_buffer] = null;
601
+ lineEnding.lastIndex = 0; // Start the search from the beginning of the string.
602
+ newPartContainsEnding = RegExpPrototypeExec(lineEnding, string);
603
+ }
604
+ this[kSawReturnAt] = StringPrototypeEndsWith(string, '\r') ?
605
+ DateNow() :
606
+ 0;
607
+
608
+ const indexes = [0, newPartContainsEnding.index, lineEnding.lastIndex];
609
+ let nextMatch;
610
+ while ((nextMatch = RegExpPrototypeExec(lineEnding, string)) !== null) {
611
+ ArrayPrototypePush(indexes, nextMatch.index, lineEnding.lastIndex);
612
+ }
613
+ const lastIndex = indexes.length - 1;
614
+ // Either '' or (conceivably) the unfinished portion of the next line
615
+ this[kLine_buffer] = StringPrototypeSlice(string, indexes[lastIndex]);
616
+ for (let i = 1; i < lastIndex; i += 2) {
617
+ this[kOnLine](StringPrototypeSlice(string, indexes[i - 1], indexes[i]));
618
+ }
619
+ } else if (string) {
620
+ // No newlines this time, save what we have for next time
621
+ if (this[kLine_buffer]) {
622
+ this[kLine_buffer] += string;
623
+ } else {
624
+ this[kLine_buffer] = string;
625
+ }
626
+ }
627
+ }
628
+
629
+ [kInsertString](c) {
630
+ this[kBeforeEdit](this.line, this.cursor);
631
+ if (this.cursor < this.line.length) {
632
+ const beg = StringPrototypeSlice(this.line, 0, this.cursor);
633
+ const end = StringPrototypeSlice(
634
+ this.line,
635
+ this.cursor,
636
+ this.line.length,
637
+ );
638
+ this.line = beg + c + end;
639
+ this.cursor += c.length;
640
+ this[kRefreshLine]();
641
+ } else {
642
+ const oldPos = this.getCursorPos();
643
+ this.line += c;
644
+ this.cursor += c.length;
645
+ const newPos = this.getCursorPos();
646
+
647
+ if (oldPos.rows < newPos.rows) {
648
+ this[kRefreshLine]();
649
+ } else {
650
+ this[kWriteToOutput](c);
651
+ }
652
+ }
653
+ }
654
+
655
+ async [kTabComplete](lastKeypressWasTab) {
656
+ this.pause();
657
+ const string = StringPrototypeSlice(this.line, 0, this.cursor);
658
+ let value;
659
+ try {
660
+ value = await this.completer(string);
661
+ } catch (err) {
662
+ this[kWriteToOutput](`Tab completion error: ${inspect(err)}`);
663
+ return;
664
+ } finally {
665
+ this.resume();
666
+ }
667
+ this[kTabCompleter](lastKeypressWasTab, value);
668
+ }
669
+
670
+ [kTabCompleter](lastKeypressWasTab, { 0: completions, 1: completeOn }) {
671
+ // Result and the text that was completed.
672
+
673
+ if (!completions || completions.length === 0) {
674
+ return;
675
+ }
676
+
677
+ // If there is a common prefix to all matches, then apply that portion.
678
+ const prefix = commonPrefix(
679
+ ArrayPrototypeFilter(completions, (e) => e !== ''),
680
+ );
681
+ if (StringPrototypeStartsWith(prefix, completeOn) &&
682
+ prefix.length > completeOn.length) {
683
+ this[kInsertString](StringPrototypeSlice(prefix, completeOn.length));
684
+ return;
685
+ } else if (!StringPrototypeStartsWith(completeOn, prefix)) {
686
+ this.line = StringPrototypeSlice(this.line,
687
+ 0,
688
+ this.cursor - completeOn.length) +
689
+ prefix +
690
+ StringPrototypeSlice(this.line,
691
+ this.cursor,
692
+ this.line.length);
693
+ this.cursor = this.cursor - completeOn.length + prefix.length;
694
+ this[kRefreshLine]();
695
+ return;
696
+ }
697
+
698
+ if (!lastKeypressWasTab) {
699
+ return;
700
+ }
701
+
702
+ this[kBeforeEdit](this.line, this.cursor);
703
+
704
+ // Apply/show completions.
705
+ const completionsWidth = ArrayPrototypeMap(completions, (e) =>
706
+ getStringWidth(e),
707
+ );
708
+ const width = MathMaxApply(completionsWidth) + 2; // 2 space padding
709
+ let maxColumns = MathFloor(this.columns / width) || 1;
710
+ if (maxColumns === Infinity) {
711
+ maxColumns = 1;
712
+ }
713
+ let output = '\r\n';
714
+ let lineIndex = 0;
715
+ let whitespace = 0;
716
+ for (let i = 0; i < completions.length; i++) {
717
+ const completion = completions[i];
718
+ if (completion === '' || lineIndex === maxColumns) {
719
+ output += '\r\n';
720
+ lineIndex = 0;
721
+ whitespace = 0;
722
+ } else {
723
+ output += StringPrototypeRepeat(' ', whitespace);
724
+ }
725
+ if (completion !== '') {
726
+ output += completion;
727
+ whitespace = width - completionsWidth[i];
728
+ lineIndex++;
729
+ } else {
730
+ output += '\r\n';
731
+ }
732
+ }
733
+ if (lineIndex !== 0) {
734
+ output += '\r\n\r\n';
735
+ }
736
+ this[kWriteToOutput](output);
737
+ this[kRefreshLine]();
738
+ }
739
+
740
+ [kWordLeft]() {
741
+ if (this.cursor > 0) {
742
+ // Reverse the string and match a word near beginning
743
+ // to avoid quadratic time complexity
744
+ const leading = StringPrototypeSlice(this.line, 0, this.cursor);
745
+ const reversed = ArrayPrototypeJoin(
746
+ ArrayPrototypeReverse(ArrayFrom(leading)),
747
+ '',
748
+ );
749
+ const match = RegExpPrototypeExec(/^\s*(?:[^\w\s]+|\w+)?/, reversed);
750
+ this[kMoveCursor](-match[0].length);
751
+ }
752
+ }
753
+
754
+ [kWordRight]() {
755
+ if (this.cursor < this.line.length) {
756
+ const trailing = StringPrototypeSlice(this.line, this.cursor);
757
+ const match = RegExpPrototypeExec(/^(?:\s+|[^\w\s]+|\w+)\s*/, trailing);
758
+ this[kMoveCursor](match[0].length);
759
+ }
760
+ }
761
+
762
+ [kDeleteLeft]() {
763
+ if (this.cursor > 0 && this.line.length > 0) {
764
+ this[kBeforeEdit](this.line, this.cursor);
765
+ // The number of UTF-16 units comprising the character to the left
766
+ const charSize = charLengthLeft(this.line, this.cursor);
767
+ this.line =
768
+ StringPrototypeSlice(this.line, 0, this.cursor - charSize) +
769
+ StringPrototypeSlice(this.line, this.cursor, this.line.length);
770
+
771
+ this.cursor -= charSize;
772
+ this[kRefreshLine]();
773
+ }
774
+ }
775
+
776
+ [kDeleteRight]() {
777
+ if (this.cursor < this.line.length) {
778
+ this[kBeforeEdit](this.line, this.cursor);
779
+ // The number of UTF-16 units comprising the character to the left
780
+ const charSize = charLengthAt(this.line, this.cursor);
781
+ this.line =
782
+ StringPrototypeSlice(this.line, 0, this.cursor) +
783
+ StringPrototypeSlice(
784
+ this.line,
785
+ this.cursor + charSize,
786
+ this.line.length,
787
+ );
788
+ this[kRefreshLine]();
789
+ }
790
+ }
791
+
792
+ [kDeleteWordLeft]() {
793
+ if (this.cursor > 0) {
794
+ this[kBeforeEdit](this.line, this.cursor);
795
+ // Reverse the string and match a word near beginning
796
+ // to avoid quadratic time complexity
797
+ let leading = StringPrototypeSlice(this.line, 0, this.cursor);
798
+ const reversed = ArrayPrototypeJoin(
799
+ ArrayPrototypeReverse(ArrayFrom(leading)),
800
+ '',
801
+ );
802
+ const match = RegExpPrototypeExec(/^\s*(?:[^\w\s]+|\w+)?/, reversed);
803
+ leading = StringPrototypeSlice(
804
+ leading,
805
+ 0,
806
+ leading.length - match[0].length,
807
+ );
808
+ this.line =
809
+ leading +
810
+ StringPrototypeSlice(this.line, this.cursor, this.line.length);
811
+ this.cursor = leading.length;
812
+ this[kRefreshLine]();
813
+ }
814
+ }
815
+
816
+ [kDeleteWordRight]() {
817
+ if (this.cursor < this.line.length) {
818
+ this[kBeforeEdit](this.line, this.cursor);
819
+ const trailing = StringPrototypeSlice(this.line, this.cursor);
820
+ const match = RegExpPrototypeExec(/^(?:\s+|\W+|\w+)\s*/, trailing);
821
+ this.line =
822
+ StringPrototypeSlice(this.line, 0, this.cursor) +
823
+ StringPrototypeSlice(trailing, match[0].length);
824
+ this[kRefreshLine]();
825
+ }
826
+ }
827
+
828
+ [kDeleteLineLeft]() {
829
+ this[kBeforeEdit](this.line, this.cursor);
830
+ const del = StringPrototypeSlice(this.line, 0, this.cursor);
831
+ this.line = StringPrototypeSlice(this.line, this.cursor);
832
+ this.cursor = 0;
833
+ this[kPushToKillRing](del);
834
+ this[kRefreshLine]();
835
+ }
836
+
837
+ [kDeleteLineRight]() {
838
+ this[kBeforeEdit](this.line, this.cursor);
839
+ const del = StringPrototypeSlice(this.line, this.cursor);
840
+ this.line = StringPrototypeSlice(this.line, 0, this.cursor);
841
+ this[kPushToKillRing](del);
842
+ this[kRefreshLine]();
843
+ }
844
+
845
+ [kPushToKillRing](del) {
846
+ if (!del || del === this[kKillRing][0]) return;
847
+ ArrayPrototypeUnshift(this[kKillRing], del);
848
+ this[kKillRingCursor] = 0;
849
+ while (this[kKillRing].length > kMaxLengthOfKillRing)
850
+ ArrayPrototypePop(this[kKillRing]);
851
+ }
852
+
853
+ [kYank]() {
854
+ if (this[kKillRing].length > 0) {
855
+ this[kYanking] = true;
856
+ this[kInsertString](this[kKillRing][this[kKillRingCursor]]);
857
+ }
858
+ }
859
+
860
+ [kYankPop]() {
861
+ if (!this[kYanking]) {
862
+ return;
863
+ }
864
+ if (this[kKillRing].length > 1) {
865
+ const lastYank = this[kKillRing][this[kKillRingCursor]];
866
+ this[kKillRingCursor]++;
867
+ if (this[kKillRingCursor] >= this[kKillRing].length) {
868
+ this[kKillRingCursor] = 0;
869
+ }
870
+ const currentYank = this[kKillRing][this[kKillRingCursor]];
871
+ const head =
872
+ StringPrototypeSlice(this.line, 0, this.cursor - lastYank.length);
873
+ const tail =
874
+ StringPrototypeSlice(this.line, this.cursor);
875
+ this.line = head + currentYank + tail;
876
+ this.cursor = head.length + currentYank.length;
877
+ this[kRefreshLine]();
878
+ }
879
+ }
880
+
881
+ clearLine() {
882
+ this[kMoveCursor](+Infinity);
883
+ this[kWriteToOutput]('\r\n');
884
+ this.line = '';
885
+ this.cursor = 0;
886
+ this.prevRows = 0;
887
+ }
888
+
889
+ [kLine]() {
890
+ const line = this[kAddHistory]();
891
+ this[kUndoStack] = [];
892
+ this[kRedoStack] = [];
893
+ this.clearLine();
894
+ this[kOnLine](line);
895
+ }
896
+
897
+ [kPushToUndoStack](text, cursor) {
898
+ if (ArrayPrototypePush(this[kUndoStack], { text, cursor }) >
899
+ kMaxUndoRedoStackSize) {
900
+ ArrayPrototypeShift(this[kUndoStack]);
901
+ }
902
+ }
903
+
904
+ [kUndo]() {
905
+ if (this[kUndoStack].length <= 0) return;
906
+
907
+ ArrayPrototypePush(
908
+ this[kRedoStack],
909
+ { text: this.line, cursor: this.cursor },
910
+ );
911
+
912
+ const entry = ArrayPrototypePop(this[kUndoStack]);
913
+ this.line = entry.text;
914
+ this.cursor = entry.cursor;
915
+
916
+ this[kRefreshLine]();
917
+ }
918
+
919
+ [kRedo]() {
920
+ if (this[kRedoStack].length <= 0) return;
921
+
922
+ ArrayPrototypePush(
923
+ this[kUndoStack],
924
+ { text: this.line, cursor: this.cursor },
925
+ );
926
+
927
+ const entry = ArrayPrototypePop(this[kRedoStack]);
928
+ this.line = entry.text;
929
+ this.cursor = entry.cursor;
930
+
931
+ this[kRefreshLine]();
932
+ }
933
+
934
+ // TODO(BridgeAR): Add underscores to the search part and a red background in
935
+ // case no match is found. This should only be the visual part and not the
936
+ // actual line content!
937
+ // TODO(BridgeAR): In case the substring based search is active and the end is
938
+ // reached, show a comment how to search the history as before. E.g., using
939
+ // <ctrl> + N. Only show this after two/three UPs or DOWNs, not on the first
940
+ // one.
941
+ [kHistoryNext]() {
942
+ if (this.historyIndex >= 0) {
943
+ this[kBeforeEdit](this.line, this.cursor);
944
+ const search = this[kSubstringSearch] || '';
945
+ let index = this.historyIndex - 1;
946
+ while (
947
+ index >= 0 &&
948
+ (!StringPrototypeStartsWith(this.history[index], search) ||
949
+ this.line === this.history[index])
950
+ ) {
951
+ index--;
952
+ }
953
+ if (index === -1) {
954
+ this.line = search;
955
+ } else {
956
+ this.line = this.history[index];
957
+ }
958
+ this.historyIndex = index;
959
+ this.cursor = this.line.length; // Set cursor to end of line.
960
+ this[kRefreshLine]();
961
+ }
962
+ }
963
+
964
+ [kHistoryPrev]() {
965
+ if (this.historyIndex < this.history.length && this.history.length) {
966
+ this[kBeforeEdit](this.line, this.cursor);
967
+ const search = this[kSubstringSearch] || '';
968
+ let index = this.historyIndex + 1;
969
+ while (
970
+ index < this.history.length &&
971
+ (!StringPrototypeStartsWith(this.history[index], search) ||
972
+ this.line === this.history[index])
973
+ ) {
974
+ index++;
975
+ }
976
+ if (index === this.history.length) {
977
+ this.line = search;
978
+ } else {
979
+ this.line = this.history[index];
980
+ }
981
+ this.historyIndex = index;
982
+ this.cursor = this.line.length; // Set cursor to end of line.
983
+ this[kRefreshLine]();
984
+ }
985
+ }
986
+
987
+ // Returns the last character's display position of the given string
988
+ [kGetDisplayPos](str) {
989
+ let offset = 0;
990
+ const col = this.columns;
991
+ let rows = 0;
992
+ str = stripVTControlCharacters(str);
993
+ for (const char of new SafeStringIterator(str)) {
994
+ if (char === '\n') {
995
+ // Rows must be incremented by 1 even if offset = 0 or col = +Infinity.
996
+ rows += MathCeil(offset / col) || 1;
997
+ offset = 0;
998
+ continue;
999
+ }
1000
+ // Tabs must be aligned by an offset of the tab size.
1001
+ if (char === '\t') {
1002
+ offset += this.tabSize - (offset % this.tabSize);
1003
+ continue;
1004
+ }
1005
+ const width = getStringWidth(char, false /* stripVTControlCharacters */);
1006
+ if (width === 0 || width === 1) {
1007
+ offset += width;
1008
+ } else {
1009
+ // width === 2
1010
+ if ((offset + 1) % col === 0) {
1011
+ offset++;
1012
+ }
1013
+ offset += 2;
1014
+ }
1015
+ }
1016
+ const cols = offset % col;
1017
+ rows += (offset - cols) / col;
1018
+ return { cols, rows };
1019
+ }
1020
+
1021
+ /**
1022
+ * Returns the real position of the cursor in relation
1023
+ * to the input prompt + string.
1024
+ * @returns {{
1025
+ * rows: number;
1026
+ * cols: number;
1027
+ * }}
1028
+ */
1029
+ getCursorPos() {
1030
+ const strBeforeCursor =
1031
+ this[kPrompt] + StringPrototypeSlice(this.line, 0, this.cursor);
1032
+ return this[kGetDisplayPos](strBeforeCursor);
1033
+ }
1034
+
1035
+ // This function moves cursor dx places to the right
1036
+ // (-dx for left) and refreshes the line if it is needed.
1037
+ [kMoveCursor](dx) {
1038
+ if (dx === 0) {
1039
+ return;
1040
+ }
1041
+ const oldPos = this.getCursorPos();
1042
+ this.cursor += dx;
1043
+
1044
+ // Bounds check
1045
+ if (this.cursor < 0) {
1046
+ this.cursor = 0;
1047
+ } else if (this.cursor > this.line.length) {
1048
+ this.cursor = this.line.length;
1049
+ }
1050
+
1051
+ const newPos = this.getCursorPos();
1052
+
1053
+ // Check if cursor stayed on the line.
1054
+ if (oldPos.rows === newPos.rows) {
1055
+ const diffWidth = newPos.cols - oldPos.cols;
1056
+ moveCursor(this.output, diffWidth, 0);
1057
+ } else {
1058
+ this[kRefreshLine]();
1059
+ }
1060
+ }
1061
+
1062
+ // Handle a write from the tty
1063
+ [kTtyWrite](s, key) {
1064
+ const previousKey = this[kPreviousKey];
1065
+ key ||= kEmptyObject;
1066
+ this[kPreviousKey] = key;
1067
+
1068
+ if (!key.meta || key.name !== 'y') {
1069
+ // Reset yanking state unless we are doing yank pop.
1070
+ this[kYanking] = false;
1071
+ }
1072
+
1073
+ // Activate or deactivate substring search.
1074
+ if (
1075
+ (key.name === 'up' || key.name === 'down') &&
1076
+ !key.ctrl &&
1077
+ !key.meta &&
1078
+ !key.shift
1079
+ ) {
1080
+ if (this[kSubstringSearch] === null) {
1081
+ this[kSubstringSearch] = StringPrototypeSlice(
1082
+ this.line,
1083
+ 0,
1084
+ this.cursor,
1085
+ );
1086
+ }
1087
+ } else if (this[kSubstringSearch] !== null) {
1088
+ this[kSubstringSearch] = null;
1089
+ // Reset the index in case there's no match.
1090
+ if (this.history.length === this.historyIndex) {
1091
+ this.historyIndex = -1;
1092
+ }
1093
+ }
1094
+
1095
+ // Undo & Redo
1096
+ if (typeof key.sequence === 'string') {
1097
+ switch (StringPrototypeCodePointAt(key.sequence, 0)) {
1098
+ case 0x1f:
1099
+ this[kUndo]();
1100
+ return;
1101
+ case 0x1e:
1102
+ this[kRedo]();
1103
+ return;
1104
+ default:
1105
+ break;
1106
+ }
1107
+ }
1108
+
1109
+ // Ignore escape key, fixes
1110
+ // https://github.com/nodejs/node-v0.x-archive/issues/2876.
1111
+ if (key.name === 'escape') return;
1112
+
1113
+ if (key.ctrl && key.shift) {
1114
+ /* Control and shift pressed */
1115
+ switch (key.name) {
1116
+ // TODO(BridgeAR): The transmitted escape sequence is `\b` and that is
1117
+ // identical to <ctrl>-h. It should have a unique escape sequence.
1118
+ case 'backspace':
1119
+ this[kDeleteLineLeft]();
1120
+ break;
1121
+
1122
+ case 'delete':
1123
+ this[kDeleteLineRight]();
1124
+ break;
1125
+ }
1126
+ } else if (key.ctrl) {
1127
+ /* Control key pressed */
1128
+
1129
+ switch (key.name) {
1130
+ case 'c':
1131
+ if (this.listenerCount('SIGINT') > 0) {
1132
+ this.emit('SIGINT');
1133
+ } else {
1134
+ // This readline instance is finished
1135
+ this.close();
1136
+ this[kQuestionReject]?.(new AbortError('Aborted with Ctrl+C'));
1137
+ }
1138
+ break;
1139
+
1140
+ case 'h': // delete left
1141
+ this[kDeleteLeft]();
1142
+ break;
1143
+
1144
+ case 'd': // delete right or EOF
1145
+ if (this.cursor === 0 && this.line.length === 0) {
1146
+ // This readline instance is finished
1147
+ this.close();
1148
+ this[kQuestionReject]?.(new AbortError('Aborted with Ctrl+D'));
1149
+ } else if (this.cursor < this.line.length) {
1150
+ this[kDeleteRight]();
1151
+ }
1152
+ break;
1153
+
1154
+ case 'u': // Delete from current to start of line
1155
+ this[kDeleteLineLeft]();
1156
+ break;
1157
+
1158
+ case 'k': // Delete from current to end of line
1159
+ this[kDeleteLineRight]();
1160
+ break;
1161
+
1162
+ case 'a': // Go to the start of the line
1163
+ this[kMoveCursor](-Infinity);
1164
+ break;
1165
+
1166
+ case 'e': // Go to the end of the line
1167
+ this[kMoveCursor](+Infinity);
1168
+ break;
1169
+
1170
+ case 'b': // back one character
1171
+ this[kMoveCursor](-charLengthLeft(this.line, this.cursor));
1172
+ break;
1173
+
1174
+ case 'f': // Forward one character
1175
+ this[kMoveCursor](+charLengthAt(this.line, this.cursor));
1176
+ break;
1177
+
1178
+ case 'l': // Clear the whole screen
1179
+ cursorTo(this.output, 0, 0);
1180
+ clearScreenDown(this.output);
1181
+ this[kRefreshLine]();
1182
+ break;
1183
+
1184
+ case 'n': // next history item
1185
+ this[kHistoryNext]();
1186
+ break;
1187
+
1188
+ case 'p': // Previous history item
1189
+ this[kHistoryPrev]();
1190
+ break;
1191
+
1192
+ case 'y': // Yank killed string
1193
+ this[kYank]();
1194
+ break;
1195
+
1196
+ case 'z':
1197
+ if (process.platform === 'win32') break;
1198
+ if (this.listenerCount('SIGTSTP') > 0) {
1199
+ this.emit('SIGTSTP');
1200
+ } else {
1201
+ process.once('SIGCONT', () => {
1202
+ // Don't raise events if stream has already been abandoned.
1203
+ if (!this.paused) {
1204
+ // Stream must be paused and resumed after SIGCONT to catch
1205
+ // SIGINT, SIGTSTP, and EOF.
1206
+ this.pause();
1207
+ this.emit('SIGCONT');
1208
+ }
1209
+ // Explicitly re-enable "raw mode" and move the cursor to
1210
+ // the correct position.
1211
+ // See https://github.com/joyent/node/issues/3295.
1212
+ this[kSetRawMode](true);
1213
+ this[kRefreshLine]();
1214
+ });
1215
+ this[kSetRawMode](false);
1216
+ process.kill(process.pid, 'SIGTSTP');
1217
+ }
1218
+ break;
1219
+
1220
+ case 'w': // Delete backwards to a word boundary
1221
+ // TODO(BridgeAR): The transmitted escape sequence is `\b` and that is
1222
+ // identical to <ctrl>-h. It should have a unique escape sequence.
1223
+ // Falls through
1224
+ case 'backspace':
1225
+ this[kDeleteWordLeft]();
1226
+ break;
1227
+
1228
+ case 'delete': // Delete forward to a word boundary
1229
+ this[kDeleteWordRight]();
1230
+ break;
1231
+
1232
+ case 'left':
1233
+ this[kWordLeft]();
1234
+ break;
1235
+
1236
+ case 'right':
1237
+ this[kWordRight]();
1238
+ break;
1239
+ }
1240
+ } else if (key.meta) {
1241
+ /* Meta key pressed */
1242
+
1243
+ switch (key.name) {
1244
+ case 'b': // backward word
1245
+ this[kWordLeft]();
1246
+ break;
1247
+
1248
+ case 'f': // forward word
1249
+ this[kWordRight]();
1250
+ break;
1251
+
1252
+ case 'd': // delete forward word
1253
+ case 'delete':
1254
+ this[kDeleteWordRight]();
1255
+ break;
1256
+
1257
+ case 'backspace': // Delete backwards to a word boundary
1258
+ this[kDeleteWordLeft]();
1259
+ break;
1260
+
1261
+ case 'y': // Doing yank pop
1262
+ this[kYankPop]();
1263
+ break;
1264
+ }
1265
+ } else {
1266
+ /* No modifier keys used */
1267
+
1268
+ // \r bookkeeping is only relevant if a \n comes right after.
1269
+ if (this[kSawReturnAt] && key.name !== 'enter') this[kSawReturnAt] = 0;
1270
+
1271
+ switch (key.name) {
1272
+ case 'return': // Carriage return, i.e. \r
1273
+ this[kSawReturnAt] = DateNow();
1274
+ this[kLine]();
1275
+ break;
1276
+
1277
+ case 'enter':
1278
+ // When key interval > crlfDelay
1279
+ if (
1280
+ this[kSawReturnAt] === 0 ||
1281
+ DateNow() - this[kSawReturnAt] > this.crlfDelay
1282
+ ) {
1283
+ this[kLine]();
1284
+ }
1285
+ this[kSawReturnAt] = 0;
1286
+ break;
1287
+
1288
+ case 'backspace':
1289
+ this[kDeleteLeft]();
1290
+ break;
1291
+
1292
+ case 'delete':
1293
+ this[kDeleteRight]();
1294
+ break;
1295
+
1296
+ case 'left':
1297
+ // Obtain the code point to the left
1298
+ this[kMoveCursor](-charLengthLeft(this.line, this.cursor));
1299
+ break;
1300
+
1301
+ case 'right':
1302
+ this[kMoveCursor](+charLengthAt(this.line, this.cursor));
1303
+ break;
1304
+
1305
+ case 'home':
1306
+ this[kMoveCursor](-Infinity);
1307
+ break;
1308
+
1309
+ case 'end':
1310
+ this[kMoveCursor](+Infinity);
1311
+ break;
1312
+
1313
+ case 'up':
1314
+ this[kHistoryPrev]();
1315
+ break;
1316
+
1317
+ case 'down':
1318
+ this[kHistoryNext]();
1319
+ break;
1320
+
1321
+ case 'tab':
1322
+ // If tab completion enabled, do that...
1323
+ if (
1324
+ typeof this.completer === 'function' &&
1325
+ this.isCompletionEnabled
1326
+ ) {
1327
+ const lastKeypressWasTab =
1328
+ previousKey && previousKey.name === 'tab';
1329
+ this[kTabComplete](lastKeypressWasTab);
1330
+ break;
1331
+ }
1332
+ // falls through
1333
+ default:
1334
+ if (typeof s === 'string' && s) {
1335
+ // Erase state of previous searches.
1336
+ lineEnding.lastIndex = 0;
1337
+ let nextMatch;
1338
+ // Keep track of the end of the last match.
1339
+ let lastIndex = 0;
1340
+ while ((nextMatch = RegExpPrototypeExec(lineEnding, s)) !== null) {
1341
+ this[kInsertString](StringPrototypeSlice(s, lastIndex, nextMatch.index));
1342
+ ({ lastIndex } = lineEnding);
1343
+ this[kLine]();
1344
+ // Restore lastIndex as the call to kLine could have mutated it.
1345
+ lineEnding.lastIndex = lastIndex;
1346
+ }
1347
+ // This ensures that the last line is written if it doesn't end in a newline.
1348
+ // Note that the last line may be the first line, in which case this still works.
1349
+ this[kInsertString](StringPrototypeSlice(s, lastIndex));
1350
+ }
1351
+ }
1352
+ }
1353
+ }
1354
+
1355
+ /**
1356
+ * Creates an `AsyncIterator` object that iterates through
1357
+ * each line in the input stream as a string.
1358
+ * @typedef {{
1359
+ * [Symbol.asyncIterator]: () => InterfaceAsyncIterator,
1360
+ * next: () => Promise<string>
1361
+ * }} InterfaceAsyncIterator
1362
+ * @returns {InterfaceAsyncIterator}
1363
+ */
1364
+ [SymbolAsyncIterator]() {
1365
+ if (this[kLineObjectStream] === undefined) {
1366
+ kFirstEventParam ??= require('internal/events/symbols').kFirstEventParam;
1367
+ this[kLineObjectStream] = EventEmitter.on(
1368
+ this, 'line', {
1369
+ close: ['close'],
1370
+ highWaterMark: 1024,
1371
+ [kFirstEventParam]: true,
1372
+ });
1373
+ }
1374
+ return this[kLineObjectStream];
1375
+ }
1376
+ }
1377
+ Interface.prototype[SymbolDispose] = assignFunctionName(SymbolDispose, function() {
1378
+ this.close();
1379
+ });
1380
+
1381
+ module.exports = {
1382
+ Interface,
1383
+ InterfaceConstructor,
1384
+ kAddHistory,
1385
+ kDecoder,
1386
+ kDeleteLeft,
1387
+ kDeleteLineLeft,
1388
+ kDeleteLineRight,
1389
+ kDeleteRight,
1390
+ kDeleteWordLeft,
1391
+ kDeleteWordRight,
1392
+ kGetDisplayPos,
1393
+ kHistoryNext,
1394
+ kHistoryPrev,
1395
+ kInsertString,
1396
+ kLine,
1397
+ kLine_buffer,
1398
+ kMoveCursor,
1399
+ kNormalWrite,
1400
+ kOldPrompt,
1401
+ kOnLine,
1402
+ kPreviousKey,
1403
+ kPrompt,
1404
+ kQuestion,
1405
+ kQuestionCallback,
1406
+ kQuestionCancel,
1407
+ kQuestionReject,
1408
+ kRefreshLine,
1409
+ kSawKeyPress,
1410
+ kSawReturnAt,
1411
+ kSetRawMode,
1412
+ kTabComplete,
1413
+ kTabCompleter,
1414
+ kTtyWrite,
1415
+ kWordLeft,
1416
+ kWordRight,
1417
+ kWriteToOutput,
1418
+ };