visaljs 0.0.4 → 0.0.6

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 (433) hide show
  1. package/cli.js +469 -53
  2. package/node/include/js_node.h +36 -0
  3. package/node/prelude/async_hooks.js +63 -8
  4. package/node/prelude/buffer.js +0 -0
  5. package/node/prelude/diagnostics_channel.js +322 -0
  6. package/node/prelude/dns.js +3 -2
  7. package/node/prelude/events.js +17 -3
  8. package/node/prelude/fs.js +177 -5
  9. package/node/prelude/fs_promises.js +24 -0
  10. package/node/prelude/http.js +13 -4
  11. package/node/prelude/http2.js +0 -0
  12. package/node/prelude/internal/async_context.js +27 -0
  13. package/node/prelude/internal/crypto/asym.js +0 -0
  14. package/node/prelude/internal/crypto/cipher.js +0 -0
  15. package/node/prelude/internal/crypto/kdf.js +0 -0
  16. package/node/prelude/internal/crypto/keys.js +0 -0
  17. package/node/prelude/internal/crypto/random.js +0 -0
  18. package/node/prelude/internal/crypto/util.js +0 -0
  19. package/node/prelude/internal/errors.js +11 -0
  20. package/node/prelude/internal/process_events.js +14 -0
  21. package/node/prelude/internal/process_signals.js +42 -0
  22. package/node/prelude/internal/querystring.js +0 -0
  23. package/node/prelude/internal/timers.js +233 -0
  24. package/node/prelude/internal/timers_global.js +9 -0
  25. package/node/prelude/internal/zlib_brotli.js +6 -0
  26. package/node/prelude/internal/zlib_engines.js +4 -0
  27. package/node/prelude/internal/zlib_zstd.js +6 -0
  28. package/node/prelude/module.js +22 -6
  29. package/node/prelude/net.js +9 -8
  30. package/node/prelude/os.js +0 -0
  31. package/node/prelude/path.js +1599 -186
  32. package/node/prelude/path_posix.js +9 -0
  33. package/node/prelude/path_win32.js +9 -0
  34. package/node/prelude/process.js +3 -0
  35. package/node/prelude/querystring.js +0 -0
  36. package/node/prelude/stream.js +18 -6
  37. package/node/prelude/stream_promises.js +0 -0
  38. package/node/prelude/stream_web.js +0 -0
  39. package/node/prelude/string_decoder.js +0 -0
  40. package/node/prelude/timers.js +92 -0
  41. package/node/prelude/timers_promises.js +133 -0
  42. package/node/prelude/tty.js +0 -0
  43. package/node/prelude/url.js +0 -0
  44. package/node/prelude/util.js +0 -0
  45. package/node/prelude/zlib.js +912 -72
  46. package/node/src/host_brotli.c +157 -0
  47. package/node/src/host_fs.c +95 -1
  48. package/node/src/host_loop.c +10 -4
  49. package/node/src/host_os.c +0 -0
  50. package/node/src/host_signal.c +70 -0
  51. package/node/src/host_sys.c +50 -0
  52. package/node/src/host_zlib.c +314 -0
  53. package/node/src/host_zstd.c +179 -0
  54. package/node/third_party/brotli/LICENSE +19 -0
  55. package/node/third_party/brotli/common/constants.c +15 -0
  56. package/node/third_party/brotli/common/constants.h +201 -0
  57. package/node/third_party/brotli/common/context.c +156 -0
  58. package/node/third_party/brotli/common/context.h +113 -0
  59. package/node/third_party/brotli/common/dictionary.c +5916 -0
  60. package/node/third_party/brotli/common/dictionary.h +64 -0
  61. package/node/third_party/brotli/common/platform.c +23 -0
  62. package/node/third_party/brotli/common/platform.h +541 -0
  63. package/node/third_party/brotli/common/shared_dictionary.c +521 -0
  64. package/node/third_party/brotli/common/shared_dictionary_internal.h +75 -0
  65. package/node/third_party/brotli/common/transform.c +291 -0
  66. package/node/third_party/brotli/common/transform.h +85 -0
  67. package/node/third_party/brotli/common/version.h +51 -0
  68. package/node/third_party/brotli/dec/bit_reader.c +78 -0
  69. package/node/third_party/brotli/dec/bit_reader.h +423 -0
  70. package/node/third_party/brotli/dec/decode.c +2875 -0
  71. package/node/third_party/brotli/dec/huffman.c +342 -0
  72. package/node/third_party/brotli/dec/huffman.h +122 -0
  73. package/node/third_party/brotli/dec/prefix.h +733 -0
  74. package/node/third_party/brotli/dec/state.c +183 -0
  75. package/node/third_party/brotli/dec/state.h +400 -0
  76. package/node/third_party/brotli/enc/backward_references.c +207 -0
  77. package/node/third_party/brotli/enc/backward_references.h +40 -0
  78. package/node/third_party/brotli/enc/backward_references_hq.c +939 -0
  79. package/node/third_party/brotli/enc/backward_references_hq.h +96 -0
  80. package/node/third_party/brotli/enc/backward_references_inc.h +189 -0
  81. package/node/third_party/brotli/enc/bit_cost.c +36 -0
  82. package/node/third_party/brotli/enc/bit_cost.h +64 -0
  83. package/node/third_party/brotli/enc/bit_cost_inc.h +127 -0
  84. package/node/third_party/brotli/enc/block_encoder_inc.h +34 -0
  85. package/node/third_party/brotli/enc/block_splitter.c +217 -0
  86. package/node/third_party/brotli/enc/block_splitter.h +52 -0
  87. package/node/third_party/brotli/enc/block_splitter_inc.h +481 -0
  88. package/node/third_party/brotli/enc/brotli_bit_stream.c +1336 -0
  89. package/node/third_party/brotli/enc/brotli_bit_stream.h +89 -0
  90. package/node/third_party/brotli/enc/cluster.c +57 -0
  91. package/node/third_party/brotli/enc/cluster.h +49 -0
  92. package/node/third_party/brotli/enc/cluster_inc.h +325 -0
  93. package/node/third_party/brotli/enc/command.c +28 -0
  94. package/node/third_party/brotli/enc/command.h +191 -0
  95. package/node/third_party/brotli/enc/compound_dictionary.c +207 -0
  96. package/node/third_party/brotli/enc/compound_dictionary.h +74 -0
  97. package/node/third_party/brotli/enc/compress_fragment.c +800 -0
  98. package/node/third_party/brotli/enc/compress_fragment.h +86 -0
  99. package/node/third_party/brotli/enc/compress_fragment_two_pass.c +657 -0
  100. package/node/third_party/brotli/enc/compress_fragment_two_pass.h +72 -0
  101. package/node/third_party/brotli/enc/dictionary_hash.c +1848 -0
  102. package/node/third_party/brotli/enc/dictionary_hash.h +25 -0
  103. package/node/third_party/brotli/enc/encode.c +1996 -0
  104. package/node/third_party/brotli/enc/encoder_dict.c +640 -0
  105. package/node/third_party/brotli/enc/encoder_dict.h +157 -0
  106. package/node/third_party/brotli/enc/entropy_encode.c +504 -0
  107. package/node/third_party/brotli/enc/entropy_encode.h +123 -0
  108. package/node/third_party/brotli/enc/entropy_encode_static.h +542 -0
  109. package/node/third_party/brotli/enc/fast_log.c +105 -0
  110. package/node/third_party/brotli/enc/fast_log.h +67 -0
  111. package/node/third_party/brotli/enc/find_match_length.h +72 -0
  112. package/node/third_party/brotli/enc/hash.h +728 -0
  113. package/node/third_party/brotli/enc/hash_composite_inc.h +140 -0
  114. package/node/third_party/brotli/enc/hash_forgetful_chain_inc.h +295 -0
  115. package/node/third_party/brotli/enc/hash_longest_match64_inc.h +262 -0
  116. package/node/third_party/brotli/enc/hash_longest_match_inc.h +258 -0
  117. package/node/third_party/brotli/enc/hash_longest_match_quickly_inc.h +266 -0
  118. package/node/third_party/brotli/enc/hash_rolling_inc.h +212 -0
  119. package/node/third_party/brotli/enc/hash_to_binary_tree_inc.h +330 -0
  120. package/node/third_party/brotli/enc/histogram.c +100 -0
  121. package/node/third_party/brotli/enc/histogram.h +64 -0
  122. package/node/third_party/brotli/enc/histogram_inc.h +51 -0
  123. package/node/third_party/brotli/enc/literal_cost.c +180 -0
  124. package/node/third_party/brotli/enc/literal_cost.h +32 -0
  125. package/node/third_party/brotli/enc/memory.c +194 -0
  126. package/node/third_party/brotli/enc/memory.h +131 -0
  127. package/node/third_party/brotli/enc/metablock.c +677 -0
  128. package/node/third_party/brotli/enc/metablock.h +106 -0
  129. package/node/third_party/brotli/enc/metablock_inc.h +185 -0
  130. package/node/third_party/brotli/enc/params.h +47 -0
  131. package/node/third_party/brotli/enc/prefix.h +54 -0
  132. package/node/third_party/brotli/enc/quality.h +202 -0
  133. package/node/third_party/brotli/enc/ringbuffer.h +168 -0
  134. package/node/third_party/brotli/enc/state.h +104 -0
  135. package/node/third_party/brotli/enc/static_dict.c +542 -0
  136. package/node/third_party/brotli/enc/static_dict.h +41 -0
  137. package/node/third_party/brotli/enc/static_dict_lut.h +5866 -0
  138. package/node/third_party/brotli/enc/utf8_util.c +85 -0
  139. package/node/third_party/brotli/enc/utf8_util.h +33 -0
  140. package/node/third_party/brotli/enc/write_bits.h +88 -0
  141. package/node/third_party/brotli/include/brotli/decode.h +409 -0
  142. package/node/third_party/brotli/include/brotli/encode.h +501 -0
  143. package/node/third_party/brotli/include/brotli/port.h +305 -0
  144. package/node/third_party/brotli/include/brotli/shared_dictionary.h +100 -0
  145. package/node/third_party/brotli/include/brotli/types.h +83 -0
  146. package/node/third_party/libuv/LICENSE +0 -0
  147. package/node/third_party/libuv/include/uv/aix.h +0 -0
  148. package/node/third_party/libuv/include/uv/bsd.h +0 -0
  149. package/node/third_party/libuv/include/uv/darwin.h +0 -0
  150. package/node/third_party/libuv/include/uv/errno.h +0 -0
  151. package/node/third_party/libuv/include/uv/linux.h +0 -0
  152. package/node/third_party/libuv/include/uv/os390.h +0 -0
  153. package/node/third_party/libuv/include/uv/posix.h +0 -0
  154. package/node/third_party/libuv/include/uv/sunos.h +0 -0
  155. package/node/third_party/libuv/include/uv/threadpool.h +0 -0
  156. package/node/third_party/libuv/include/uv/tree.h +0 -0
  157. package/node/third_party/libuv/include/uv/unix.h +0 -0
  158. package/node/third_party/libuv/include/uv/version.h +0 -0
  159. package/node/third_party/libuv/include/uv/win.h +0 -0
  160. package/node/third_party/libuv/include/uv.h +0 -0
  161. package/node/third_party/libuv/src/fs-poll.c +0 -0
  162. package/node/third_party/libuv/src/heap-inl.h +0 -0
  163. package/node/third_party/libuv/src/idna.c +0 -0
  164. package/node/third_party/libuv/src/idna.h +0 -0
  165. package/node/third_party/libuv/src/inet.c +0 -0
  166. package/node/third_party/libuv/src/queue.h +0 -0
  167. package/node/third_party/libuv/src/random.c +0 -0
  168. package/node/third_party/libuv/src/strscpy.c +0 -0
  169. package/node/third_party/libuv/src/strscpy.h +0 -0
  170. package/node/third_party/libuv/src/strtok.c +0 -0
  171. package/node/third_party/libuv/src/strtok.h +0 -0
  172. package/node/third_party/libuv/src/thread-common.c +0 -0
  173. package/node/third_party/libuv/src/threadpool.c +0 -0
  174. package/node/third_party/libuv/src/timer.c +0 -0
  175. package/node/third_party/libuv/src/unix/async.c +0 -0
  176. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
  177. package/node/third_party/libuv/src/unix/core.c +0 -0
  178. package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
  179. package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
  180. package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
  181. package/node/third_party/libuv/src/unix/darwin.c +0 -0
  182. package/node/third_party/libuv/src/unix/dl.c +0 -0
  183. package/node/third_party/libuv/src/unix/fs.c +0 -0
  184. package/node/third_party/libuv/src/unix/fsevents.c +0 -0
  185. package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
  186. package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
  187. package/node/third_party/libuv/src/unix/internal.h +0 -0
  188. package/node/third_party/libuv/src/unix/kqueue.c +0 -0
  189. package/node/third_party/libuv/src/unix/linux.c +0 -0
  190. package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
  191. package/node/third_party/libuv/src/unix/loop.c +0 -0
  192. package/node/third_party/libuv/src/unix/pipe.c +0 -0
  193. package/node/third_party/libuv/src/unix/poll.c +0 -0
  194. package/node/third_party/libuv/src/unix/process.c +0 -0
  195. package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
  196. package/node/third_party/libuv/src/unix/proctitle.c +0 -0
  197. package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
  198. package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
  199. package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
  200. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
  201. package/node/third_party/libuv/src/unix/signal.c +0 -0
  202. package/node/third_party/libuv/src/unix/stream.c +0 -0
  203. package/node/third_party/libuv/src/unix/tcp.c +0 -0
  204. package/node/third_party/libuv/src/unix/thread.c +0 -0
  205. package/node/third_party/libuv/src/unix/tty.c +0 -0
  206. package/node/third_party/libuv/src/unix/udp.c +0 -0
  207. package/node/third_party/libuv/src/uv-common.c +0 -0
  208. package/node/third_party/libuv/src/uv-common.h +0 -0
  209. package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
  210. package/node/third_party/libuv/src/version.c +0 -0
  211. package/node/third_party/llhttp/LICENSE +0 -0
  212. package/node/third_party/llhttp/api.c +0 -0
  213. package/node/third_party/llhttp/http.c +0 -0
  214. package/node/third_party/llhttp/llhttp.c +0 -0
  215. package/node/third_party/llhttp/llhttp.h +0 -0
  216. package/node/third_party/zlib/LICENSE +19 -0
  217. package/node/third_party/zlib/README.chromium +38 -0
  218. package/node/third_party/zlib/adler32.c +197 -0
  219. package/node/third_party/zlib/chromeconf.h +203 -0
  220. package/node/third_party/zlib/contrib/optimizations/insert_string.h +80 -0
  221. package/node/third_party/zlib/cpu_features.c +213 -0
  222. package/node/third_party/zlib/cpu_features.h +22 -0
  223. package/node/third_party/zlib/crc32.c +1192 -0
  224. package/node/third_party/zlib/crc32.h +9446 -0
  225. package/node/third_party/zlib/deflate.c +2289 -0
  226. package/node/third_party/zlib/deflate.h +407 -0
  227. package/node/third_party/zlib/gzguts.h +214 -0
  228. package/node/third_party/zlib/inffast.c +327 -0
  229. package/node/third_party/zlib/inffast.h +26 -0
  230. package/node/third_party/zlib/inffixed.h +94 -0
  231. package/node/third_party/zlib/inflate.c +1528 -0
  232. package/node/third_party/zlib/inflate.h +126 -0
  233. package/node/third_party/zlib/inftrees.c +299 -0
  234. package/node/third_party/zlib/inftrees.h +62 -0
  235. package/node/third_party/zlib/trees.c +1161 -0
  236. package/node/third_party/zlib/trees.h +128 -0
  237. package/node/third_party/zlib/zconf.h +558 -0
  238. package/node/third_party/zlib/zlib.h +1967 -0
  239. package/node/third_party/zlib/zutil.c +299 -0
  240. package/node/third_party/zlib/zutil.h +275 -0
  241. package/node/third_party/zstd/LICENSE +30 -0
  242. package/node/third_party/zstd/common/allocations.h +55 -0
  243. package/node/third_party/zstd/common/bits.h +205 -0
  244. package/node/third_party/zstd/common/bitstream.h +454 -0
  245. package/node/third_party/zstd/common/compiler.h +464 -0
  246. package/node/third_party/zstd/common/cpu.h +249 -0
  247. package/node/third_party/zstd/common/debug.c +30 -0
  248. package/node/third_party/zstd/common/debug.h +107 -0
  249. package/node/third_party/zstd/common/entropy_common.c +340 -0
  250. package/node/third_party/zstd/common/error_private.c +64 -0
  251. package/node/third_party/zstd/common/error_private.h +158 -0
  252. package/node/third_party/zstd/common/fse.h +625 -0
  253. package/node/third_party/zstd/common/fse_decompress.c +315 -0
  254. package/node/third_party/zstd/common/huf.h +277 -0
  255. package/node/third_party/zstd/common/mem.h +422 -0
  256. package/node/third_party/zstd/common/pool.c +371 -0
  257. package/node/third_party/zstd/common/pool.h +81 -0
  258. package/node/third_party/zstd/common/portability_macros.h +171 -0
  259. package/node/third_party/zstd/common/threading.c +182 -0
  260. package/node/third_party/zstd/common/threading.h +142 -0
  261. package/node/third_party/zstd/common/xxhash.c +18 -0
  262. package/node/third_party/zstd/common/xxhash.h +7094 -0
  263. package/node/third_party/zstd/common/zstd_common.c +48 -0
  264. package/node/third_party/zstd/common/zstd_deps.h +123 -0
  265. package/node/third_party/zstd/common/zstd_internal.h +324 -0
  266. package/node/third_party/zstd/common/zstd_trace.h +156 -0
  267. package/node/third_party/zstd/compress/clevels.h +134 -0
  268. package/node/third_party/zstd/compress/fse_compress.c +625 -0
  269. package/node/third_party/zstd/compress/hist.c +191 -0
  270. package/node/third_party/zstd/compress/hist.h +82 -0
  271. package/node/third_party/zstd/compress/huf_compress.c +1464 -0
  272. package/node/third_party/zstd/compress/zstd_compress.c +7843 -0
  273. package/node/third_party/zstd/compress/zstd_compress_internal.h +1636 -0
  274. package/node/third_party/zstd/compress/zstd_compress_literals.c +235 -0
  275. package/node/third_party/zstd/compress/zstd_compress_literals.h +39 -0
  276. package/node/third_party/zstd/compress/zstd_compress_sequences.c +442 -0
  277. package/node/third_party/zstd/compress/zstd_compress_sequences.h +55 -0
  278. package/node/third_party/zstd/compress/zstd_compress_superblock.c +688 -0
  279. package/node/third_party/zstd/compress/zstd_compress_superblock.h +32 -0
  280. package/node/third_party/zstd/compress/zstd_cwksp.h +765 -0
  281. package/node/third_party/zstd/compress/zstd_double_fast.c +778 -0
  282. package/node/third_party/zstd/compress/zstd_double_fast.h +42 -0
  283. package/node/third_party/zstd/compress/zstd_fast.c +985 -0
  284. package/node/third_party/zstd/compress/zstd_fast.h +30 -0
  285. package/node/third_party/zstd/compress/zstd_lazy.c +2199 -0
  286. package/node/third_party/zstd/compress/zstd_lazy.h +193 -0
  287. package/node/third_party/zstd/compress/zstd_ldm.c +745 -0
  288. package/node/third_party/zstd/compress/zstd_ldm.h +109 -0
  289. package/node/third_party/zstd/compress/zstd_ldm_geartab.h +106 -0
  290. package/node/third_party/zstd/compress/zstd_opt.c +1580 -0
  291. package/node/third_party/zstd/compress/zstd_opt.h +72 -0
  292. package/node/third_party/zstd/compress/zstd_preSplit.c +238 -0
  293. package/node/third_party/zstd/compress/zstd_preSplit.h +33 -0
  294. package/node/third_party/zstd/compress/zstdmt_compress.c +1923 -0
  295. package/node/third_party/zstd/compress/zstdmt_compress.h +102 -0
  296. package/node/third_party/zstd/decompress/huf_decompress.c +1944 -0
  297. package/node/third_party/zstd/decompress/zstd_ddict.c +244 -0
  298. package/node/third_party/zstd/decompress/zstd_ddict.h +44 -0
  299. package/node/third_party/zstd/decompress/zstd_decompress.c +2410 -0
  300. package/node/third_party/zstd/decompress/zstd_decompress_block.c +2209 -0
  301. package/node/third_party/zstd/decompress/zstd_decompress_block.h +73 -0
  302. package/node/third_party/zstd/decompress/zstd_decompress_internal.h +240 -0
  303. package/node/third_party/zstd/zdict.h +481 -0
  304. package/node/third_party/zstd/zstd.h +3198 -0
  305. package/node/third_party/zstd/zstd_errors.h +107 -0
  306. package/package.json +1 -1
  307. package/runtime/include/js_atoms.gen.h +0 -0
  308. package/runtime/include/js_atoms.h +0 -0
  309. package/runtime/include/js_bigint.h +0 -0
  310. package/runtime/include/js_buffer.h +0 -0
  311. package/runtime/include/js_builtins.h +0 -0
  312. package/runtime/include/js_console.h +5 -2
  313. package/runtime/include/js_convert.h +0 -0
  314. package/runtime/include/js_core.def +0 -0
  315. package/runtime/include/js_error.h +0 -0
  316. package/runtime/include/js_exception.h +0 -0
  317. package/runtime/include/js_function.h +0 -0
  318. package/runtime/include/js_gc.h +0 -0
  319. package/runtime/include/js_generator.h +0 -0
  320. package/runtime/include/js_host.h +5 -3
  321. package/runtime/include/js_jobs.h +18 -1
  322. package/runtime/include/js_module.h +0 -0
  323. package/runtime/include/js_object.h +0 -0
  324. package/runtime/include/js_ops.h +0 -0
  325. package/runtime/include/js_promise.h +1 -0
  326. package/runtime/include/js_regexp.h +0 -0
  327. package/runtime/include/js_runtime.h +0 -0
  328. package/runtime/include/js_symbol.h +0 -0
  329. package/runtime/include/js_web.h +0 -0
  330. package/runtime/include/jscell.h +0 -0
  331. package/runtime/include/jscontext.h +14 -0
  332. package/runtime/include/jsnum.h +0 -0
  333. package/runtime/include/jsstring.h +0 -0
  334. package/runtime/include/jsvalue.h +0 -0
  335. package/runtime/src/arguments.c +0 -0
  336. package/runtime/src/array.c +0 -0
  337. package/runtime/src/arraybuffer.c +0 -0
  338. package/runtime/src/async_iter.c +0 -0
  339. package/runtime/src/atoms.c +0 -0
  340. package/runtime/src/base64.c +0 -0
  341. package/runtime/src/bigint.c +0 -0
  342. package/runtime/src/blob.c +0 -0
  343. package/runtime/src/buffer.c +20 -16
  344. package/runtime/src/builtin_table.c +0 -0
  345. package/runtime/src/builtins.c +0 -0
  346. package/runtime/src/builtins_util.h +0 -0
  347. package/runtime/src/collections.c +0 -0
  348. package/runtime/src/components.c +0 -0
  349. package/runtime/src/console.c +15 -2
  350. package/runtime/src/convert.c +0 -0
  351. package/runtime/src/core_all.c +0 -0
  352. package/runtime/src/crypto.c +0 -0
  353. package/runtime/src/crypto_host.c +0 -0
  354. package/runtime/src/crypto_kdf.c +0 -0
  355. package/runtime/src/crypto_key.c +0 -0
  356. package/runtime/src/date.c +0 -0
  357. package/runtime/src/domexception.c +0 -0
  358. package/runtime/src/elements.c +0 -0
  359. package/runtime/src/elements.h +0 -0
  360. package/runtime/src/encoding.c +0 -0
  361. package/runtime/src/error.c +0 -0
  362. package/runtime/src/events.c +1 -1
  363. package/runtime/src/exception.c +0 -0
  364. package/runtime/src/fetch.c +0 -0
  365. package/runtime/src/function.c +0 -0
  366. package/runtime/src/gc.c +2 -0
  367. package/runtime/src/generator.c +0 -0
  368. package/runtime/src/global.c +0 -0
  369. package/runtime/src/headers.c +0 -0
  370. package/runtime/src/inspect.c +0 -0
  371. package/runtime/src/internal.h +0 -0
  372. package/runtime/src/iterate.c +0 -0
  373. package/runtime/src/iterator.c +0 -0
  374. package/runtime/src/jobs.c +123 -44
  375. package/runtime/src/jsnum.c +0 -0
  376. package/runtime/src/json.c +0 -0
  377. package/runtime/src/math.c +0 -0
  378. package/runtime/src/module.c +0 -0
  379. package/runtime/src/number.c +0 -0
  380. package/runtime/src/object.c +0 -0
  381. package/runtime/src/ops.c +0 -0
  382. package/runtime/src/os.c +0 -0
  383. package/runtime/src/os.h +0 -0
  384. package/runtime/src/process.c +92 -8
  385. package/runtime/src/promise.c +7 -2
  386. package/runtime/src/proxy.c +0 -0
  387. package/runtime/src/reflect.c +0 -0
  388. package/runtime/src/regexp.c +0 -0
  389. package/runtime/src/regexp_anchor.h +0 -0
  390. package/runtime/src/regexp_message.h +0 -0
  391. package/runtime/src/shape.c +0 -0
  392. package/runtime/src/shape.h +0 -0
  393. package/runtime/src/streams.c +0 -0
  394. package/runtime/src/streams.h +0 -0
  395. package/runtime/src/string.c +0 -0
  396. package/runtime/src/string_builtins.c +0 -0
  397. package/runtime/src/symbol.c +0 -0
  398. package/runtime/src/test_host.c +0 -0
  399. package/runtime/src/typedarray.c +0 -0
  400. package/runtime/src/tznames.gen.h +0 -0
  401. package/runtime/src/uri.c +0 -0
  402. package/runtime/src/url.c +0 -0
  403. package/runtime/src/weak.c +1 -4
  404. package/runtime/src/web.c +0 -0
  405. package/runtime/src/wrapper.c +0 -0
  406. package/runtime/src/writable.c +0 -0
  407. package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
  408. package/runtime/third_party/ada-idna/README.md +0 -0
  409. package/runtime/third_party/ada-idna/convert.mjs +0 -0
  410. package/runtime/third_party/ada-idna/idna.c +0 -0
  411. package/runtime/third_party/ada-idna/idna.h +0 -0
  412. package/runtime/third_party/ada-idna/idna_tables.h +0 -0
  413. package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
  414. package/runtime/third_party/quickjs-dtoa/README.md +0 -0
  415. package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
  416. package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
  417. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
  418. package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
  419. package/runtime/third_party/quickjs-regexp/README.md +0 -0
  420. package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
  421. package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
  422. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
  423. package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
  424. package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
  425. package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
  426. package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
  427. package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
  428. package/runtime/third_party/v8-ieee754/LICENSE +0 -0
  429. package/runtime/third_party/v8-ieee754/README.md +0 -0
  430. package/runtime/third_party/v8-ieee754/convert.py +0 -0
  431. package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
  432. package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
  433. package/runtime/tools/regexp_compile.c +0 -0
@@ -1,37 +1,81 @@
1
- // node:path (ADR 0012, layer 3): POSIX paths, following Node's algorithms so results
2
- // match byte for byte. Only resolve() reaches the host (the working directory).
3
- import { cwd } from "visaljs:host";
4
- import { validateString } from "./internal/errors.js";
1
+ // node:path (ADR 0012, layer 3): Node's lib/path.js (MIT; Node v22), both its win32 and its
2
+ // posix halves, ported: primordials are the methods they stand for, the working directory is the
3
+ // host's, and matchesGlob (minimatch, which visaljs doesn't bundle) is a stub. Results match Node's
4
+ // byte for byte; the default export is win32 on Windows, posix elsewhere, as Node's.
5
+ import { cwd as hostCwd } from "visaljs:host";
6
+ import { invalidArgType, notSupported, validateString } from "./internal/errors.js";
5
7
 
6
- const SLASH = 47, DOT = 46;
8
+ const CHAR_UPPERCASE_A = 65, CHAR_LOWERCASE_A = 97, CHAR_UPPERCASE_Z = 90, CHAR_LOWERCASE_Z = 122;
9
+ const CHAR_DOT = 46, CHAR_FORWARD_SLASH = 47, CHAR_BACKWARD_SLASH = 92, CHAR_COLON = 58, CHAR_QUESTION_MARK = 63;
10
+ const isWindows = process.platform === "win32";
7
11
 
8
- /** Resolves `.` and `..` segments; `..` past the start is kept only when allowAboveRoot. */
9
- function normalizeString(path, allowAboveRoot) {
10
- let res = "";
12
+ function validateObject(value, name) {
13
+ if (value === null || typeof value !== "object" || Array.isArray(value)) throw invalidArgType(name, "of type object", value);
14
+ }
15
+
16
+ function isPathSeparator(code) {
17
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
18
+ }
19
+
20
+ function isPosixPathSeparator(code) {
21
+ return code === CHAR_FORWARD_SLASH;
22
+ }
23
+
24
+ const WINDOWS_RESERVED_NAMES = [
25
+ 'CON', 'PRN', 'AUX', 'NUL',
26
+ 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9',
27
+ 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9',
28
+ 'COM\xb9', 'COM\xb2', 'COM\xb3',
29
+ 'LPT\xb9', 'LPT\xb2', 'LPT\xb3',
30
+ ];
31
+
32
+ function isWindowsReservedName(path, colonIndex) {
33
+ const devicePart = path.slice(0, colonIndex).toUpperCase();
34
+ return WINDOWS_RESERVED_NAMES.includes(devicePart);
35
+ }
36
+
37
+ function isWindowsDeviceRoot(code) {
38
+ return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
39
+ (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
40
+ }
41
+
42
+ // Resolves . and .. elements in a path with directory names
43
+ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
44
+ let res = '';
11
45
  let lastSegmentLength = 0;
12
46
  let lastSlash = -1;
13
47
  let dots = 0;
14
- for (let i = 0; i <= path.length; i++) {
15
- const code = i < path.length ? path.charCodeAt(i) : SLASH;
16
- if (code === SLASH) {
48
+ let code = 0;
49
+ for (let i = 0; i <= path.length; ++i) {
50
+ if (i < path.length)
51
+ code = path.charCodeAt(i);
52
+ else if (isPathSeparator(code))
53
+ break;
54
+ else
55
+ code = CHAR_FORWARD_SLASH;
56
+
57
+ if (isPathSeparator(code)) {
17
58
  if (lastSlash === i - 1 || dots === 1) {
18
- /* empty or `.` segment */
59
+ // NOOP
19
60
  } else if (dots === 2) {
20
- if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== DOT || res.charCodeAt(res.length - 2) !== DOT) {
61
+ if (res.length < 2 || lastSegmentLength !== 2 ||
62
+ res.charCodeAt(res.length - 1) !== CHAR_DOT ||
63
+ res.charCodeAt(res.length - 2) !== CHAR_DOT) {
21
64
  if (res.length > 2) {
22
- const idx = lastIndexOfSlash(res);
23
- if (idx === -1) {
24
- res = "";
65
+ const lastSlashIndex = res.length - lastSegmentLength - 1;
66
+ if (lastSlashIndex === -1) {
67
+ res = '';
25
68
  lastSegmentLength = 0;
26
69
  } else {
27
- res = res.slice(0, idx);
28
- lastSegmentLength = res.length - 1 - lastIndexOfSlash(res);
70
+ res = res.slice(0, lastSlashIndex);
71
+ lastSegmentLength =
72
+ res.length - 1 - res.lastIndexOf(separator);
29
73
  }
30
74
  lastSlash = i;
31
75
  dots = 0;
32
76
  continue;
33
77
  } else if (res.length !== 0) {
34
- res = "";
78
+ res = '';
35
79
  lastSegmentLength = 0;
36
80
  lastSlash = i;
37
81
  dots = 0;
@@ -39,17 +83,19 @@ function normalizeString(path, allowAboveRoot) {
39
83
  }
40
84
  }
41
85
  if (allowAboveRoot) {
42
- res += res.length > 0 ? "/.." : "..";
86
+ res += res.length > 0 ? `${separator}..` : '..';
43
87
  lastSegmentLength = 2;
44
88
  }
45
89
  } else {
46
- if (res.length > 0) res += "/" + path.slice(lastSlash + 1, i);
47
- else res = path.slice(lastSlash + 1, i);
90
+ if (res.length > 0)
91
+ res += `${separator}${path.slice(lastSlash + 1, i)}`;
92
+ else
93
+ res = path.slice(lastSlash + 1, i);
48
94
  lastSegmentLength = i - lastSlash - 1;
49
95
  }
50
96
  lastSlash = i;
51
97
  dots = 0;
52
- } else if (code === DOT && dots !== -1) {
98
+ } else if (code === CHAR_DOT && dots !== -1) {
53
99
  ++dots;
54
100
  } else {
55
101
  dots = -1;
@@ -58,200 +104,1567 @@ function normalizeString(path, allowAboveRoot) {
58
104
  return res;
59
105
  }
60
106
 
61
- function lastIndexOfSlash(s) {
62
- for (let i = s.length - 1; i >= 0; i--) if (s.charCodeAt(i) === SLASH) return i;
63
- return -1;
107
+ function formatExt(ext) {
108
+ return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';
64
109
  }
65
110
 
66
- export const sep = "/";
67
- export const delimiter = ":";
68
-
69
- export function resolve(...args) {
70
- let resolvedPath = "";
71
- let resolvedAbsolute = false;
72
- for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
73
- const path = i >= 0 ? args[i] : cwd();
74
- validateString(path, "paths[" + i + "]");
75
- if (path.length === 0) continue;
76
- resolvedPath = path + "/" + resolvedPath;
77
- resolvedAbsolute = path.charCodeAt(0) === SLASH;
111
+ /**
112
+ * @param {string} sep
113
+ * @param {{
114
+ * dir?: string;
115
+ * root?: string;
116
+ * base?: string;
117
+ * name?: string;
118
+ * ext?: string;
119
+ * }} pathObject
120
+ * @returns {string}
121
+ */
122
+ function _format(sep, pathObject) {
123
+ validateObject(pathObject, 'pathObject');
124
+ const dir = pathObject.dir || pathObject.root;
125
+ const base = pathObject.base ||
126
+ `${pathObject.name || ''}${formatExt(pathObject.ext)}`;
127
+ if (!dir) {
128
+ return base;
78
129
  }
79
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
80
- if (resolvedAbsolute) return "/" + resolvedPath;
81
- return resolvedPath.length > 0 ? resolvedPath : ".";
130
+ return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`;
82
131
  }
83
132
 
84
- export function normalize(path) {
85
- validateString(path, "path");
86
- if (path.length === 0) return ".";
87
- const isAbs = path.charCodeAt(0) === SLASH;
88
- const trailingSeparator = path.charCodeAt(path.length - 1) === SLASH;
89
- path = normalizeString(path, !isAbs);
90
- if (path.length === 0) {
91
- if (isAbs) return "/";
92
- return trailingSeparator ? "./" : ".";
93
- }
94
- if (trailingSeparator) path += "/";
95
- return isAbs ? "/" + path : path;
96
- }
133
+ const forwardSlashRegExp = /\//g;
97
134
 
98
- export function isAbsolute(path) {
99
- validateString(path, "path");
100
- return path.length > 0 && path.charCodeAt(0) === SLASH;
101
- }
135
+ const win32 = {
136
+ /**
137
+ * path.resolve([from ...], to)
138
+ * @param {...string} args
139
+ * @returns {string}
140
+ */
141
+ resolve(...args) {
142
+ let resolvedDevice = '';
143
+ let resolvedTail = '';
144
+ let resolvedAbsolute = false;
102
145
 
103
- export function join(...args) {
104
- if (args.length === 0) return ".";
105
- let joined;
106
- for (const arg of args) {
107
- validateString(arg, "path");
108
- if (arg.length > 0) joined = joined === undefined ? arg : joined + "/" + arg;
109
- }
110
- return joined === undefined ? "." : normalize(joined);
111
- }
146
+ for (let i = args.length - 1; i >= -1; i--) {
147
+ let path;
148
+ if (i >= 0) {
149
+ path = args[i];
150
+ validateString(path, `paths[${i}]`);
112
151
 
113
- export function relative(from, to) {
114
- validateString(from, "from");
115
- validateString(to, "to");
116
- if (from === to) return "";
117
- from = resolve(from);
118
- to = resolve(to);
119
- if (from === to) return "";
120
- const fromStart = 1;
121
- const fromEnd = from.length;
122
- const fromLen = fromEnd - fromStart;
123
- const toStart = 1;
124
- const toLen = to.length - toStart;
125
- const length = fromLen < toLen ? fromLen : toLen;
126
- let lastCommonSep = -1;
127
- let i = 0;
128
- for (; i < length; i++) {
129
- const fromCode = from.charCodeAt(fromStart + i);
130
- if (fromCode !== to.charCodeAt(toStart + i)) break;
131
- else if (fromCode === SLASH) lastCommonSep = i;
132
- }
133
- if (i === length) {
134
- if (toLen > length) {
135
- if (to.charCodeAt(toStart + i) === SLASH) return to.slice(toStart + i + 1);
136
- if (i === 0) return to.slice(toStart + i);
137
- } else if (fromLen > length) {
138
- if (from.charCodeAt(fromStart + i) === SLASH) lastCommonSep = i;
139
- else if (i === 0) lastCommonSep = 0;
152
+ // Skip empty entries
153
+ if (path.length === 0) {
154
+ continue;
155
+ }
156
+ } else if (resolvedDevice.length === 0) {
157
+ path = hostCwd();
158
+ // Fast path for current directory
159
+ if (args.length === 0 || ((args.length === 1 && (args[0] === '' || args[0] === '.')) &&
160
+ isPathSeparator(path.charCodeAt(0)))) {
161
+ if (!isWindows) {
162
+ path = path.replace(forwardSlashRegExp, '\\');
163
+ }
164
+ return path;
165
+ }
166
+ } else {
167
+ // Windows has the concept of drive-specific current working
168
+ // directories. If we've resolved a drive letter but not yet an
169
+ // absolute path, get cwd for that drive, or the process cwd if
170
+ // the drive cwd is not available. We're sure the device is not
171
+ // a UNC path at this points, because UNC paths are always absolute.
172
+ path = process.env[`=${resolvedDevice}`] || hostCwd();
173
+
174
+ // Verify that a cwd was found and that it actually points
175
+ // to our drive. If not, default to the drive's root.
176
+ if (path === undefined ||
177
+ (path.slice(0, 2).toLowerCase() !==
178
+ resolvedDevice.toLowerCase() &&
179
+ path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) {
180
+ path = `${resolvedDevice}\\`;
181
+ }
182
+ }
183
+
184
+ const len = path.length;
185
+ let rootEnd = 0;
186
+ let device = '';
187
+ let isAbsolute = false;
188
+ const code = path.charCodeAt(0);
189
+
190
+ // Try to match a root
191
+ if (len === 1) {
192
+ if (isPathSeparator(code)) {
193
+ // `path` contains just a path separator
194
+ rootEnd = 1;
195
+ isAbsolute = true;
196
+ }
197
+ } else if (isPathSeparator(code)) {
198
+ // Possible UNC root
199
+
200
+ // If we started with a separator, we know we at least have an
201
+ // absolute path of some kind (UNC or otherwise)
202
+ isAbsolute = true;
203
+
204
+ if (isPathSeparator(path.charCodeAt(1))) {
205
+ // Matched double path separator at beginning
206
+ let j = 2;
207
+ let last = j;
208
+ // Match 1 or more non-path separators
209
+ while (j < len &&
210
+ !isPathSeparator(path.charCodeAt(j))) {
211
+ j++;
212
+ }
213
+ if (j < len && j !== last) {
214
+ const firstPart = path.slice(last, j);
215
+ // Matched!
216
+ last = j;
217
+ // Match 1 or more path separators
218
+ while (j < len &&
219
+ isPathSeparator(path.charCodeAt(j))) {
220
+ j++;
221
+ }
222
+ if (j < len && j !== last) {
223
+ // Matched!
224
+ last = j;
225
+ // Match 1 or more non-path separators
226
+ while (j < len &&
227
+ !isPathSeparator(path.charCodeAt(j))) {
228
+ j++;
229
+ }
230
+ if (j === len || j !== last) {
231
+ if (firstPart !== '.' && firstPart !== '?') {
232
+ // We matched a UNC root
233
+ device =
234
+ `\\\\${firstPart}\\${path.slice(last, j)}`;
235
+ rootEnd = j;
236
+ } else {
237
+ // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
238
+ device = `\\\\${firstPart}`;
239
+ rootEnd = 4;
240
+ }
241
+ }
242
+ }
243
+ }
244
+ } else {
245
+ rootEnd = 1;
246
+ }
247
+ } else if (isWindowsDeviceRoot(code) &&
248
+ path.charCodeAt(1) === CHAR_COLON) {
249
+ // Possible device root
250
+ device = path.slice(0, 2);
251
+ rootEnd = 2;
252
+ if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
253
+ // Treat separator following drive name as an absolute path
254
+ // indicator
255
+ isAbsolute = true;
256
+ rootEnd = 3;
257
+ }
258
+ }
259
+
260
+ if (device.length > 0) {
261
+ if (resolvedDevice.length > 0) {
262
+ if (device.toLowerCase() !==
263
+ resolvedDevice.toLowerCase())
264
+ // This path points to another device so it is not applicable
265
+ continue;
266
+ } else {
267
+ resolvedDevice = device;
268
+ }
269
+ }
270
+
271
+ if (resolvedAbsolute) {
272
+ if (resolvedDevice.length > 0)
273
+ break;
274
+ } else {
275
+ resolvedTail =
276
+ `${path.slice(rootEnd)}\\${resolvedTail}`;
277
+ resolvedAbsolute = isAbsolute;
278
+ if (isAbsolute && resolvedDevice.length > 0) {
279
+ break;
280
+ }
281
+ }
140
282
  }
141
- }
142
- let out = "";
143
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
144
- if (i === fromEnd || from.charCodeAt(i) === SLASH) out += out.length === 0 ? ".." : "/..";
145
- }
146
- return out + to.slice(toStart + lastCommonSep);
147
- }
148
283
 
149
- export function dirname(path) {
150
- validateString(path, "path");
151
- if (path.length === 0) return ".";
152
- const hasRoot = path.charCodeAt(0) === SLASH;
153
- let end = -1;
154
- let matchedSlash = true;
155
- for (let i = path.length - 1; i >= 1; --i) {
156
- if (path.charCodeAt(i) === SLASH) {
157
- if (!matchedSlash) {
158
- end = i;
159
- break;
284
+ // At this point the path should be resolved to a full absolute path,
285
+ // but handle relative paths to be safe (might happen when process.cwd()
286
+ // fails)
287
+
288
+ // Normalize the tail path
289
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\',
290
+ isPathSeparator);
291
+
292
+ return resolvedAbsolute ?
293
+ `${resolvedDevice}\\${resolvedTail}` :
294
+ `${resolvedDevice}${resolvedTail}` || '.';
295
+ },
296
+
297
+ /**
298
+ * @param {string} path
299
+ * @returns {string}
300
+ */
301
+ normalize(path) {
302
+ validateString(path, 'path');
303
+ const len = path.length;
304
+ if (len === 0)
305
+ return '.';
306
+ let rootEnd = 0;
307
+ let device;
308
+ let isAbsolute = false;
309
+ const code = path.charCodeAt(0);
310
+
311
+ // Try to match a root
312
+ if (len === 1) {
313
+ // `path` contains just a single char, exit early to avoid
314
+ // unnecessary work
315
+ return isPosixPathSeparator(code) ? '\\' : path;
316
+ }
317
+ if (isPathSeparator(code)) {
318
+ // Possible UNC root
319
+
320
+ // If we started with a separator, we know we at least have an absolute
321
+ // path of some kind (UNC or otherwise)
322
+ isAbsolute = true;
323
+
324
+ if (isPathSeparator(path.charCodeAt(1))) {
325
+ // Matched double path separator at beginning
326
+ let j = 2;
327
+ let last = j;
328
+ // Match 1 or more non-path separators
329
+ while (j < len &&
330
+ !isPathSeparator(path.charCodeAt(j))) {
331
+ j++;
332
+ }
333
+ if (j < len && j !== last) {
334
+ const firstPart = path.slice(last, j);
335
+ // Matched!
336
+ last = j;
337
+ // Match 1 or more path separators
338
+ while (j < len &&
339
+ isPathSeparator(path.charCodeAt(j))) {
340
+ j++;
341
+ }
342
+ if (j < len && j !== last) {
343
+ // Matched!
344
+ last = j;
345
+ // Match 1 or more non-path separators
346
+ while (j < len &&
347
+ !isPathSeparator(path.charCodeAt(j))) {
348
+ j++;
349
+ }
350
+ if (j === len || j !== last) {
351
+ if (firstPart === '.' || firstPart === '?') {
352
+ // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
353
+ device = `\\\\${firstPart}`;
354
+ rootEnd = 4;
355
+ const colonIndex = path.indexOf(':');
356
+ // Special case: handle \\?\COM1: or similar reserved device paths
357
+ const possibleDevice = path.slice(4, colonIndex + 1);
358
+ if (isWindowsReservedName(possibleDevice, possibleDevice.length - 1)) {
359
+ device = `\\\\?\\${possibleDevice}`;
360
+ rootEnd = 4 + possibleDevice.length;
361
+ }
362
+ } else if (j === len) {
363
+ // We matched a UNC root only
364
+ // Return the normalized version of the UNC root since there
365
+ // is nothing left to process
366
+ return `\\\\${firstPart}\\${path.slice(last)}\\`;
367
+ } else {
368
+ // We matched a UNC root with leftovers
369
+ device =
370
+ `\\\\${firstPart}\\${path.slice(last, j)}`;
371
+ rootEnd = j;
372
+ }
373
+ }
374
+ }
375
+ }
376
+ } else {
377
+ rootEnd = 1;
160
378
  }
161
379
  } else {
162
- matchedSlash = false;
380
+ const colonIndex = path.indexOf(':');
381
+ if (colonIndex > 0) {
382
+ if (isWindowsDeviceRoot(code) && colonIndex === 1) {
383
+ device = path.slice(0, 2);
384
+ rootEnd = 2;
385
+ if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
386
+ isAbsolute = true;
387
+ rootEnd = 3;
388
+ }
389
+ } else if (isWindowsReservedName(path, colonIndex)) {
390
+ device = path.slice(0, colonIndex + 1);
391
+ rootEnd = colonIndex + 1;
392
+
393
+ }
394
+ }
163
395
  }
164
- }
165
- if (end === -1) return hasRoot ? "/" : ".";
166
- if (hasRoot && end === 1) return "//";
167
- return path.slice(0, end);
168
- }
169
396
 
170
- export function basename(path, suffix) {
171
- if (suffix !== undefined) validateString(suffix, "suffix");
172
- validateString(path, "path");
173
- let start = 0;
174
- let end = -1;
175
- let matchedSlash = true;
176
- if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
177
- if (suffix === path) return "";
178
- let extIdx = suffix.length - 1;
179
- let firstNonSlashEnd = -1;
180
- for (let i = path.length - 1; i >= 0; --i) {
181
- const code = path.charCodeAt(i);
182
- if (code === SLASH) {
397
+ let tail = rootEnd < len ?
398
+ normalizeString(path.slice(rootEnd),
399
+ !isAbsolute, '\\', isPathSeparator) :
400
+ '';
401
+ if (tail.length === 0 && !isAbsolute)
402
+ tail = '.';
403
+ if (tail.length > 0 &&
404
+ isPathSeparator(path.charCodeAt(len - 1)))
405
+ tail += '\\';
406
+ if (!isAbsolute && device === undefined && path.includes(':')) {
407
+ // If the original path was not absolute and if we have not been able to
408
+ // resolve it relative to a particular device, we need to ensure that the
409
+ // `tail` has not become something that Windows might interpret as an
410
+ // absolute path. See CVE-2024-36139.
411
+ if (tail.length >= 2 &&
412
+ isWindowsDeviceRoot(tail.charCodeAt(0)) &&
413
+ tail.charCodeAt(1) === CHAR_COLON) {
414
+ return `.\\${tail}`;
415
+ }
416
+ let index = path.indexOf(':');
417
+
418
+ do {
419
+ if (index === len - 1 || isPathSeparator(path.charCodeAt(index + 1))) {
420
+ return `.\\${tail}`;
421
+ }
422
+ } while ((index = path.indexOf(':', index + 1)) !== -1);
423
+ }
424
+ const colonIndex = path.indexOf(':');
425
+ if (isWindowsReservedName(path, colonIndex)) {
426
+ return `.\\${device ?? ''}${tail}`;
427
+ }
428
+ if (device === undefined) {
429
+ return isAbsolute ? `\\${tail}` : tail;
430
+ }
431
+ return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
432
+ },
433
+
434
+ /**
435
+ * @param {string} path
436
+ * @returns {boolean}
437
+ */
438
+ isAbsolute(path) {
439
+ validateString(path, 'path');
440
+ const len = path.length;
441
+ if (len === 0)
442
+ return false;
443
+
444
+ const code = path.charCodeAt(0);
445
+ return isPathSeparator(code) ||
446
+ // Possible device root
447
+ (len > 2 &&
448
+ isWindowsDeviceRoot(code) &&
449
+ path.charCodeAt(1) === CHAR_COLON &&
450
+ isPathSeparator(path.charCodeAt(2)));
451
+ },
452
+
453
+ /**
454
+ * @param {...string} args
455
+ * @returns {string}
456
+ */
457
+ join(...args) {
458
+ if (args.length === 0)
459
+ return '.';
460
+
461
+ const path = [];
462
+ for (let i = 0; i < args.length; ++i) {
463
+ const arg = args[i];
464
+ validateString(arg, 'path');
465
+ if (arg.length > 0) {
466
+ path.push(arg);
467
+ }
468
+ }
469
+
470
+ if (path.length === 0)
471
+ return '.';
472
+
473
+ const firstPart = path[0];
474
+ let joined = path.join('\\');
475
+
476
+ // Make sure that the joined path doesn't start with two slashes, because
477
+ // normalize() will mistake it for a UNC path then.
478
+ //
479
+ // This step is skipped when it is very clear that the user actually
480
+ // intended to point at a UNC path. This is assumed when the first
481
+ // non-empty string arguments starts with exactly two slashes followed by
482
+ // at least one more non-slash character.
483
+ //
484
+ // Note that for normalize() to treat a path as a UNC path it needs to
485
+ // have at least 2 components, so we don't filter for that here.
486
+ // This means that the user can use join to construct UNC paths from
487
+ // a server name and a share name; for example:
488
+ // path.join('//server', 'share') -> '\\\\server\\share\\')
489
+ let needsReplace = true;
490
+ let slashCount = 0;
491
+ if (isPathSeparator(firstPart.charCodeAt(0))) {
492
+ ++slashCount;
493
+ const firstLen = firstPart.length;
494
+ if (firstLen > 1 &&
495
+ isPathSeparator(firstPart.charCodeAt(1))) {
496
+ ++slashCount;
497
+ if (firstLen > 2) {
498
+ if (isPathSeparator(firstPart.charCodeAt(2)))
499
+ ++slashCount;
500
+ else {
501
+ // We matched a UNC path in the first part
502
+ needsReplace = false;
503
+ }
504
+ }
505
+ }
506
+ }
507
+ if (needsReplace) {
508
+ // Find any more consecutive slashes we need to replace
509
+ while (slashCount < joined.length &&
510
+ isPathSeparator(joined.charCodeAt(slashCount))) {
511
+ slashCount++;
512
+ }
513
+
514
+ // Replace the slashes if needed
515
+ if (slashCount >= 2)
516
+ joined = `\\${joined.slice(slashCount)}`;
517
+ }
518
+
519
+ // Skip normalization when reserved device names are present
520
+ const parts = [];
521
+ let part = '';
522
+
523
+ for (let i = 0; i < joined.length; i++) {
524
+ if (joined[i] === '\\') {
525
+ if (part) parts.push(part);
526
+ part = '';
527
+ // Skip consecutive backslashes
528
+ while (i + 1 < joined.length && joined[i + 1] === '\\') i++;
529
+ } else {
530
+ part += joined[i];
531
+ }
532
+ }
533
+ // Add the final part if any
534
+ if (part) parts.push(part);
535
+
536
+ // Check if any part has a Windows reserved name
537
+ if (parts.some((p) => {
538
+ const colonIndex = p.indexOf(':');
539
+ return colonIndex !== -1 && isWindowsReservedName(p, colonIndex);
540
+ })) {
541
+ // Replace forward slashes with backslashes
542
+ let result = '';
543
+ for (let i = 0; i < joined.length; i++) {
544
+ result += joined[i] === '/' ? '\\' : joined[i];
545
+ }
546
+ return result;
547
+ }
548
+
549
+ return win32.normalize(joined);
550
+ },
551
+
552
+ /**
553
+ * It will solve the relative path from `from` to `to`, for instance
554
+ * from = 'C:\\orandea\\test\\aaa'
555
+ * to = 'C:\\orandea\\impl\\bbb'
556
+ * The output of the function should be: '..\\..\\impl\\bbb'
557
+ * @param {string} from
558
+ * @param {string} to
559
+ * @returns {string}
560
+ */
561
+ relative(from, to) {
562
+ validateString(from, 'from');
563
+ validateString(to, 'to');
564
+
565
+ if (from === to)
566
+ return '';
567
+
568
+ const fromOrig = win32.resolve(from);
569
+ const toOrig = win32.resolve(to);
570
+
571
+ if (fromOrig === toOrig)
572
+ return '';
573
+
574
+ from = fromOrig.toLowerCase();
575
+ to = toOrig.toLowerCase();
576
+
577
+ if (from === to)
578
+ return '';
579
+
580
+ if (fromOrig.length !== from.length || toOrig.length !== to.length) {
581
+ const fromSplit = fromOrig.split('\\');
582
+ const toSplit = toOrig.split('\\');
583
+ if (fromSplit[fromSplit.length - 1] === '') {
584
+ fromSplit.pop();
585
+ }
586
+ if (toSplit[toSplit.length - 1] === '') {
587
+ toSplit.pop();
588
+ }
589
+
590
+ const fromLen = fromSplit.length;
591
+ const toLen = toSplit.length;
592
+ const length = fromLen < toLen ? fromLen : toLen;
593
+
594
+ let i;
595
+ for (i = 0; i < length; i++) {
596
+ if (fromSplit[i].toLowerCase() !== toSplit[i].toLowerCase()) {
597
+ break;
598
+ }
599
+ }
600
+
601
+ if (i === 0) {
602
+ return toOrig;
603
+ } else if (i === length) {
604
+ if (toLen > length) {
605
+ return toSplit.slice(i).join('\\');
606
+ }
607
+ if (fromLen > length) {
608
+ return ('..\\').repeat(fromLen - 1 - i) + '..';
609
+ }
610
+ return '';
611
+ }
612
+
613
+ return ('..\\').repeat(fromLen - i) + toSplit.slice(i).join('\\');
614
+ }
615
+
616
+ // Trim any leading backslashes
617
+ let fromStart = 0;
618
+ while (fromStart < from.length &&
619
+ from.charCodeAt(fromStart) === CHAR_BACKWARD_SLASH) {
620
+ fromStart++;
621
+ }
622
+ // Trim trailing backslashes (applicable to UNC paths only)
623
+ let fromEnd = from.length;
624
+ while (
625
+ fromEnd - 1 > fromStart &&
626
+ from.charCodeAt(fromEnd - 1) === CHAR_BACKWARD_SLASH
627
+ ) {
628
+ fromEnd--;
629
+ }
630
+ const fromLen = fromEnd - fromStart;
631
+
632
+ // Trim any leading backslashes
633
+ let toStart = 0;
634
+ while (toStart < to.length &&
635
+ to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
636
+ toStart++;
637
+ }
638
+ // Trim trailing backslashes (applicable to UNC paths only)
639
+ let toEnd = to.length;
640
+ while (toEnd - 1 > toStart &&
641
+ to.charCodeAt(toEnd - 1) === CHAR_BACKWARD_SLASH) {
642
+ toEnd--;
643
+ }
644
+ const toLen = toEnd - toStart;
645
+
646
+ // Compare paths to find the longest common path from root
647
+ const length = fromLen < toLen ? fromLen : toLen;
648
+ let lastCommonSep = -1;
649
+ let i = 0;
650
+ for (; i < length; i++) {
651
+ const fromCode = from.charCodeAt(fromStart + i);
652
+ if (fromCode !== to.charCodeAt(toStart + i))
653
+ break;
654
+ else if (fromCode === CHAR_BACKWARD_SLASH)
655
+ lastCommonSep = i;
656
+ }
657
+
658
+ // We found a mismatch before the first common path separator was seen, so
659
+ // return the original `to`.
660
+ if (i !== length) {
661
+ if (lastCommonSep === -1)
662
+ return toOrig;
663
+ } else {
664
+ if (toLen > length) {
665
+ if (to.charCodeAt(toStart + i) ===
666
+ CHAR_BACKWARD_SLASH) {
667
+ // We get here if `from` is the exact base path for `to`.
668
+ // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
669
+ return toOrig.slice(toStart + i + 1);
670
+ }
671
+ if (i === 2) {
672
+ // We get here if `from` is the device root.
673
+ // For example: from='C:\\'; to='C:\\foo'
674
+ return toOrig.slice(toStart + i);
675
+ }
676
+ }
677
+ if (fromLen > length) {
678
+ if (from.charCodeAt(fromStart + i) ===
679
+ CHAR_BACKWARD_SLASH) {
680
+ // We get here if `to` is the exact base path for `from`.
681
+ // For example: from='C:\\foo\\bar'; to='C:\\foo'
682
+ lastCommonSep = i;
683
+ } else if (i === 2) {
684
+ // We get here if `to` is the device root.
685
+ // For example: from='C:\\foo\\bar'; to='C:\\'
686
+ lastCommonSep = 3;
687
+ }
688
+ }
689
+ if (lastCommonSep === -1)
690
+ lastCommonSep = 0;
691
+ }
692
+
693
+ let out = '';
694
+ // Generate the relative path based on the path difference between `to` and
695
+ // `from`
696
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
697
+ if (i === fromEnd ||
698
+ from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
699
+ out += out.length === 0 ? '..' : '\\..';
700
+ }
701
+ }
702
+
703
+ toStart += lastCommonSep;
704
+
705
+ // Lastly, append the rest of the destination (`to`) path that comes after
706
+ // the common path parts
707
+ if (out.length > 0)
708
+ return `${out}${toOrig.slice(toStart, toEnd)}`;
709
+
710
+ if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH)
711
+ ++toStart;
712
+ return toOrig.slice(toStart, toEnd);
713
+ },
714
+
715
+ /**
716
+ * @param {string} path
717
+ * @returns {string}
718
+ */
719
+ toNamespacedPath(path) {
720
+ // Note: this will *probably* throw somewhere.
721
+ if (typeof path !== 'string' || path.length === 0)
722
+ return path;
723
+
724
+ const resolvedPath = win32.resolve(path);
725
+
726
+ if (resolvedPath.length <= 2)
727
+ return path;
728
+
729
+ if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
730
+ // Possible UNC root
731
+ if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
732
+ const code = resolvedPath.charCodeAt(2);
733
+ if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
734
+ // Matched non-long UNC root, convert the path to a long UNC path
735
+ return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
736
+ }
737
+ }
738
+ } else if (
739
+ isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) &&
740
+ resolvedPath.charCodeAt(1) === CHAR_COLON &&
741
+ resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH
742
+ ) {
743
+ // Matched device root, convert the path to a long UNC path
744
+ return `\\\\?\\${resolvedPath}`;
745
+ }
746
+
747
+ return resolvedPath;
748
+ },
749
+
750
+ /**
751
+ * @param {string} path
752
+ * @returns {string}
753
+ */
754
+ dirname(path) {
755
+ validateString(path, 'path');
756
+ const len = path.length;
757
+ if (len === 0)
758
+ return '.';
759
+ let rootEnd = -1;
760
+ let offset = 0;
761
+ const code = path.charCodeAt(0);
762
+
763
+ if (len === 1) {
764
+ // `path` contains just a path separator, exit early to avoid
765
+ // unnecessary work or a dot.
766
+ return isPathSeparator(code) ? path : '.';
767
+ }
768
+
769
+ // Try to match a root
770
+ if (isPathSeparator(code)) {
771
+ // Possible UNC root
772
+
773
+ rootEnd = offset = 1;
774
+
775
+ if (isPathSeparator(path.charCodeAt(1))) {
776
+ // Matched double path separator at beginning
777
+ let j = 2;
778
+ let last = j;
779
+ // Match 1 or more non-path separators
780
+ while (j < len &&
781
+ !isPathSeparator(path.charCodeAt(j))) {
782
+ j++;
783
+ }
784
+ if (j < len && j !== last) {
785
+ // Matched!
786
+ last = j;
787
+ // Match 1 or more path separators
788
+ while (j < len &&
789
+ isPathSeparator(path.charCodeAt(j))) {
790
+ j++;
791
+ }
792
+ if (j < len && j !== last) {
793
+ // Matched!
794
+ last = j;
795
+ // Match 1 or more non-path separators
796
+ while (j < len &&
797
+ !isPathSeparator(path.charCodeAt(j))) {
798
+ j++;
799
+ }
800
+ if (j === len) {
801
+ // We matched a UNC root only
802
+ return path;
803
+ }
804
+ if (j !== last) {
805
+ // We matched a UNC root with leftovers
806
+
807
+ // Offset by 1 to include the separator after the UNC root to
808
+ // treat it as a "normal root" on top of a (UNC) root
809
+ rootEnd = offset = j + 1;
810
+ }
811
+ }
812
+ }
813
+ }
814
+ // Possible device root
815
+ } else if (isWindowsDeviceRoot(code) &&
816
+ path.charCodeAt(1) === CHAR_COLON) {
817
+ rootEnd =
818
+ len > 2 && isPathSeparator(path.charCodeAt(2)) ? 3 : 2;
819
+ offset = rootEnd;
820
+ }
821
+
822
+ let end = -1;
823
+ let matchedSlash = true;
824
+ for (let i = len - 1; i >= offset; --i) {
825
+ if (isPathSeparator(path.charCodeAt(i))) {
183
826
  if (!matchedSlash) {
184
- start = i + 1;
827
+ end = i;
185
828
  break;
186
829
  }
187
830
  } else {
188
- if (firstNonSlashEnd === -1) {
189
- matchedSlash = false;
190
- firstNonSlashEnd = i + 1;
191
- }
192
- if (extIdx >= 0) {
193
- if (code === suffix.charCodeAt(extIdx)) {
194
- if (--extIdx === -1) end = i;
195
- } else {
196
- extIdx = -1;
197
- end = firstNonSlashEnd;
831
+ // We saw the first non-path separator
832
+ matchedSlash = false;
833
+ }
834
+ }
835
+
836
+ if (end === -1) {
837
+ if (rootEnd === -1)
838
+ return '.';
839
+
840
+ end = rootEnd;
841
+ }
842
+ return path.slice(0, end);
843
+ },
844
+
845
+ /**
846
+ * @param {string} path
847
+ * @param {string} [suffix]
848
+ * @returns {string}
849
+ */
850
+ basename(path, suffix) {
851
+ if (suffix !== undefined)
852
+ validateString(suffix, 'suffix');
853
+ validateString(path, 'path');
854
+ let start = 0;
855
+ let end = -1;
856
+ let matchedSlash = true;
857
+
858
+ // Check for a drive letter prefix so as not to mistake the following
859
+ // path separator as an extra separator at the end of the path that can be
860
+ // disregarded
861
+ if (path.length >= 2 &&
862
+ isWindowsDeviceRoot(path.charCodeAt(0)) &&
863
+ path.charCodeAt(1) === CHAR_COLON) {
864
+ start = 2;
865
+ }
866
+
867
+ if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
868
+ if (suffix === path)
869
+ return '';
870
+ let extIdx = suffix.length - 1;
871
+ let firstNonSlashEnd = -1;
872
+ for (let i = path.length - 1; i >= start; --i) {
873
+ const code = path.charCodeAt(i);
874
+ if (isPathSeparator(code)) {
875
+ // If we reached a path separator that was not part of a set of path
876
+ // separators at the end of the string, stop now
877
+ if (!matchedSlash) {
878
+ start = i + 1;
879
+ break;
880
+ }
881
+ } else {
882
+ if (firstNonSlashEnd === -1) {
883
+ // We saw the first non-path separator, remember this index in case
884
+ // we need it if the extension ends up not matching
885
+ matchedSlash = false;
886
+ firstNonSlashEnd = i + 1;
887
+ }
888
+ if (extIdx >= 0) {
889
+ // Try to match the explicit extension
890
+ if (code === suffix.charCodeAt(extIdx)) {
891
+ if (--extIdx === -1) {
892
+ // We matched the extension, so mark this as the end of our path
893
+ // component
894
+ end = i;
895
+ }
896
+ } else {
897
+ // Extension does not match, so our result is the entire path
898
+ // component
899
+ extIdx = -1;
900
+ end = firstNonSlashEnd;
901
+ }
198
902
  }
199
903
  }
200
904
  }
905
+
906
+ if (start === end)
907
+ end = firstNonSlashEnd;
908
+ else if (end === -1)
909
+ end = path.length;
910
+ return path.slice(start, end);
201
911
  }
202
- if (start === end) end = firstNonSlashEnd;
203
- else if (end === -1) end = path.length;
912
+ for (let i = path.length - 1; i >= start; --i) {
913
+ if (isPathSeparator(path.charCodeAt(i))) {
914
+ // If we reached a path separator that was not part of a set of path
915
+ // separators at the end of the string, stop now
916
+ if (!matchedSlash) {
917
+ start = i + 1;
918
+ break;
919
+ }
920
+ } else if (end === -1) {
921
+ // We saw the first non-path separator, mark this as the end of our
922
+ // path component
923
+ matchedSlash = false;
924
+ end = i + 1;
925
+ }
926
+ }
927
+
928
+ if (end === -1)
929
+ return '';
204
930
  return path.slice(start, end);
205
- }
206
- for (let i = path.length - 1; i >= 0; --i) {
207
- if (path.charCodeAt(i) === SLASH) {
208
- if (!matchedSlash) {
209
- start = i + 1;
210
- break;
931
+ },
932
+
933
+ /**
934
+ * @param {string} path
935
+ * @returns {string}
936
+ */
937
+ extname(path) {
938
+ validateString(path, 'path');
939
+ let start = 0;
940
+ let startDot = -1;
941
+ let startPart = 0;
942
+ let end = -1;
943
+ let matchedSlash = true;
944
+ // Track the state of characters (if any) we see before our first dot and
945
+ // after any path separator we find
946
+ let preDotState = 0;
947
+
948
+ // Check for a drive letter prefix so as not to mistake the following
949
+ // path separator as an extra separator at the end of the path that can be
950
+ // disregarded
951
+
952
+ if (path.length >= 2 &&
953
+ path.charCodeAt(1) === CHAR_COLON &&
954
+ isWindowsDeviceRoot(path.charCodeAt(0))) {
955
+ start = startPart = 2;
956
+ }
957
+
958
+ for (let i = path.length - 1; i >= start; --i) {
959
+ const code = path.charCodeAt(i);
960
+ if (isPathSeparator(code)) {
961
+ // If we reached a path separator that was not part of a set of path
962
+ // separators at the end of the string, stop now
963
+ if (!matchedSlash) {
964
+ startPart = i + 1;
965
+ break;
966
+ }
967
+ continue;
968
+ }
969
+ if (end === -1) {
970
+ // We saw the first non-path separator, mark this as the end of our
971
+ // extension
972
+ matchedSlash = false;
973
+ end = i + 1;
974
+ }
975
+ if (code === CHAR_DOT) {
976
+ // If this is our first dot, mark it as the start of our extension
977
+ if (startDot === -1)
978
+ startDot = i;
979
+ else if (preDotState !== 1)
980
+ preDotState = 1;
981
+ } else if (startDot !== -1) {
982
+ // We saw a non-dot and non-path separator before our dot, so we should
983
+ // have a good chance at having a non-empty extension
984
+ preDotState = -1;
985
+ }
986
+ }
987
+
988
+ if (startDot === -1 ||
989
+ end === -1 ||
990
+ // We saw a non-dot character immediately before the dot
991
+ preDotState === 0 ||
992
+ // The (right-most) trimmed path component is exactly '..'
993
+ (preDotState === 1 &&
994
+ startDot === end - 1 &&
995
+ startDot === startPart + 1)) {
996
+ return '';
997
+ }
998
+ return path.slice(startDot, end);
999
+ },
1000
+
1001
+ format: _format.bind(null, '\\'),
1002
+
1003
+ /**
1004
+ * @param {string} path
1005
+ * @returns {{
1006
+ * dir: string;
1007
+ * root: string;
1008
+ * base: string;
1009
+ * name: string;
1010
+ * ext: string;
1011
+ * }}
1012
+ */
1013
+ parse(path) {
1014
+ validateString(path, 'path');
1015
+
1016
+ const ret = { root: '', dir: '', base: '', ext: '', name: '' };
1017
+ if (path.length === 0)
1018
+ return ret;
1019
+
1020
+ const len = path.length;
1021
+ let rootEnd = 0;
1022
+ let code = path.charCodeAt(0);
1023
+
1024
+ if (len === 1) {
1025
+ if (isPathSeparator(code)) {
1026
+ // `path` contains just a path separator, exit early to avoid
1027
+ // unnecessary work
1028
+ ret.root = ret.dir = path;
1029
+ return ret;
1030
+ }
1031
+ ret.base = ret.name = path;
1032
+ return ret;
1033
+ }
1034
+ // Try to match a root
1035
+ if (isPathSeparator(code)) {
1036
+ // Possible UNC root
1037
+
1038
+ rootEnd = 1;
1039
+ if (isPathSeparator(path.charCodeAt(1))) {
1040
+ // Matched double path separator at beginning
1041
+ let j = 2;
1042
+ let last = j;
1043
+ // Match 1 or more non-path separators
1044
+ while (j < len &&
1045
+ !isPathSeparator(path.charCodeAt(j))) {
1046
+ j++;
1047
+ }
1048
+ if (j < len && j !== last) {
1049
+ // Matched!
1050
+ last = j;
1051
+ // Match 1 or more path separators
1052
+ while (j < len &&
1053
+ isPathSeparator(path.charCodeAt(j))) {
1054
+ j++;
1055
+ }
1056
+ if (j < len && j !== last) {
1057
+ // Matched!
1058
+ last = j;
1059
+ // Match 1 or more non-path separators
1060
+ while (j < len &&
1061
+ !isPathSeparator(path.charCodeAt(j))) {
1062
+ j++;
1063
+ }
1064
+ if (j === len) {
1065
+ // We matched a UNC root only
1066
+ rootEnd = j;
1067
+ } else if (j !== last) {
1068
+ // We matched a UNC root with leftovers
1069
+ rootEnd = j + 1;
1070
+ }
1071
+ }
1072
+ }
1073
+ }
1074
+ } else if (isWindowsDeviceRoot(code) &&
1075
+ path.charCodeAt(1) === CHAR_COLON) {
1076
+ // Possible device root
1077
+ if (len <= 2) {
1078
+ // `path` contains just a drive root, exit early to avoid
1079
+ // unnecessary work
1080
+ ret.root = ret.dir = path;
1081
+ return ret;
1082
+ }
1083
+ rootEnd = 2;
1084
+ if (isPathSeparator(path.charCodeAt(2))) {
1085
+ if (len === 3) {
1086
+ // `path` contains just a drive root, exit early to avoid
1087
+ // unnecessary work
1088
+ ret.root = ret.dir = path;
1089
+ return ret;
1090
+ }
1091
+ rootEnd = 3;
211
1092
  }
212
- } else if (end === -1) {
213
- matchedSlash = false;
214
- end = i + 1;
215
1093
  }
1094
+ if (rootEnd > 0)
1095
+ ret.root = path.slice(0, rootEnd);
1096
+
1097
+ let startDot = -1;
1098
+ let startPart = rootEnd;
1099
+ let end = -1;
1100
+ let matchedSlash = true;
1101
+ let i = path.length - 1;
1102
+
1103
+ // Track the state of characters (if any) we see before our first dot and
1104
+ // after any path separator we find
1105
+ let preDotState = 0;
1106
+
1107
+ // Get non-dir info
1108
+ for (; i >= rootEnd; --i) {
1109
+ code = path.charCodeAt(i);
1110
+ if (isPathSeparator(code)) {
1111
+ // If we reached a path separator that was not part of a set of path
1112
+ // separators at the end of the string, stop now
1113
+ if (!matchedSlash) {
1114
+ startPart = i + 1;
1115
+ break;
1116
+ }
1117
+ continue;
1118
+ }
1119
+ if (end === -1) {
1120
+ // We saw the first non-path separator, mark this as the end of our
1121
+ // extension
1122
+ matchedSlash = false;
1123
+ end = i + 1;
1124
+ }
1125
+ if (code === CHAR_DOT) {
1126
+ // If this is our first dot, mark it as the start of our extension
1127
+ if (startDot === -1)
1128
+ startDot = i;
1129
+ else if (preDotState !== 1)
1130
+ preDotState = 1;
1131
+ } else if (startDot !== -1) {
1132
+ // We saw a non-dot and non-path separator before our dot, so we should
1133
+ // have a good chance at having a non-empty extension
1134
+ preDotState = -1;
1135
+ }
1136
+ }
1137
+
1138
+ if (end !== -1) {
1139
+ if (startDot === -1 ||
1140
+ // We saw a non-dot character immediately before the dot
1141
+ preDotState === 0 ||
1142
+ // The (right-most) trimmed path component is exactly '..'
1143
+ (preDotState === 1 &&
1144
+ startDot === end - 1 &&
1145
+ startDot === startPart + 1)) {
1146
+ ret.base = ret.name = path.slice(startPart, end);
1147
+ } else {
1148
+ ret.name = path.slice(startPart, startDot);
1149
+ ret.base = path.slice(startPart, end);
1150
+ ret.ext = path.slice(startDot, end);
1151
+ }
1152
+ }
1153
+
1154
+ // If the directory is the root, use the entire root as the `dir` including
1155
+ // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
1156
+ // trailing slash (`C:\abc\def` -> `C:\abc`).
1157
+ if (startPart > 0 && startPart !== rootEnd)
1158
+ ret.dir = path.slice(0, startPart - 1);
1159
+ else
1160
+ ret.dir = ret.root;
1161
+
1162
+ return ret;
1163
+ },
1164
+
1165
+ matchesGlob(_path, _pattern) {
1166
+ throw notSupported('path.matchesGlob');
1167
+ },
1168
+
1169
+ sep: '\\',
1170
+ delimiter: ';',
1171
+ win32: null,
1172
+ posix: null,
1173
+ };
1174
+
1175
+ const posixCwd = (() => {
1176
+ if (isWindows) {
1177
+ // Converts Windows' backslash path separators to POSIX forward slashes
1178
+ // and truncates any drive indicator
1179
+ const regexp = /\\/g;
1180
+ return () => {
1181
+ const cwd = hostCwd().replace(regexp, '/');
1182
+ return cwd.slice(cwd.indexOf('/'));
1183
+ };
216
1184
  }
217
- return end === -1 ? "" : path.slice(start, end);
218
- }
219
1185
 
220
- export function extname(path) {
221
- validateString(path, "path");
222
- let startDot = -1;
223
- let startPart = 0;
224
- let end = -1;
225
- let matchedSlash = true;
226
- let preDotState = 0;
227
- for (let i = path.length - 1; i >= 0; --i) {
228
- const code = path.charCodeAt(i);
229
- if (code === SLASH) {
230
- if (!matchedSlash) {
231
- startPart = i + 1;
1186
+ // We're already on POSIX, no need for any transformations
1187
+ return () => hostCwd();
1188
+ })();
1189
+
1190
+ const posix = {
1191
+ /**
1192
+ * path.resolve([from ...], to)
1193
+ * @param {...string} args
1194
+ * @returns {string}
1195
+ */
1196
+ resolve(...args) {
1197
+ if (args.length === 0 || (args.length === 1 && (args[0] === '' || args[0] === '.'))) {
1198
+ const cwd = posixCwd();
1199
+ if (cwd.charCodeAt(0) === CHAR_FORWARD_SLASH) {
1200
+ return cwd;
1201
+ }
1202
+ }
1203
+ let resolvedPath = '';
1204
+ let resolvedAbsolute = false;
1205
+
1206
+ for (let i = args.length - 1; i >= 0 && !resolvedAbsolute; i--) {
1207
+ const path = args[i];
1208
+ validateString(path, `paths[${i}]`);
1209
+
1210
+ // Skip empty entries
1211
+ if (path.length === 0) {
1212
+ continue;
1213
+ }
1214
+
1215
+ resolvedPath = `${path}/${resolvedPath}`;
1216
+ resolvedAbsolute =
1217
+ path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1218
+ }
1219
+
1220
+ if (!resolvedAbsolute) {
1221
+ const cwd = posixCwd();
1222
+ resolvedPath = `${cwd}/${resolvedPath}`;
1223
+ resolvedAbsolute =
1224
+ cwd.charCodeAt(0) === CHAR_FORWARD_SLASH;
1225
+ }
1226
+
1227
+ // At this point the path should be resolved to a full absolute path, but
1228
+ // handle relative paths to be safe (might happen when process.cwd() fails)
1229
+
1230
+ // Normalize the path
1231
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/',
1232
+ isPosixPathSeparator);
1233
+
1234
+ if (resolvedAbsolute) {
1235
+ return `/${resolvedPath}`;
1236
+ }
1237
+ return resolvedPath.length > 0 ? resolvedPath : '.';
1238
+ },
1239
+
1240
+ /**
1241
+ * @param {string} path
1242
+ * @returns {string}
1243
+ */
1244
+ normalize(path) {
1245
+ validateString(path, 'path');
1246
+
1247
+ if (path.length === 0)
1248
+ return '.';
1249
+
1250
+ const isAbsolute =
1251
+ path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1252
+ const trailingSeparator =
1253
+ path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
1254
+
1255
+ // Normalize the path
1256
+ path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);
1257
+
1258
+ if (path.length === 0) {
1259
+ if (isAbsolute)
1260
+ return '/';
1261
+ return trailingSeparator ? './' : '.';
1262
+ }
1263
+ if (trailingSeparator)
1264
+ path += '/';
1265
+
1266
+ return isAbsolute ? `/${path}` : path;
1267
+ },
1268
+
1269
+ /**
1270
+ * @param {string} path
1271
+ * @returns {boolean}
1272
+ */
1273
+ isAbsolute(path) {
1274
+ validateString(path, 'path');
1275
+ return path.length > 0 &&
1276
+ path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1277
+ },
1278
+
1279
+ /**
1280
+ * @param {...string} args
1281
+ * @returns {string}
1282
+ */
1283
+ join(...args) {
1284
+ if (args.length === 0)
1285
+ return '.';
1286
+
1287
+ const path = [];
1288
+ for (let i = 0; i < args.length; ++i) {
1289
+ const arg = args[i];
1290
+ validateString(arg, 'path');
1291
+ if (arg.length > 0) {
1292
+ path.push(arg);
1293
+ }
1294
+ }
1295
+
1296
+ if (path.length === 0)
1297
+ return '.';
1298
+
1299
+ return posix.normalize(path.join('/'));
1300
+ },
1301
+
1302
+ /**
1303
+ * @param {string} from
1304
+ * @param {string} to
1305
+ * @returns {string}
1306
+ */
1307
+ relative(from, to) {
1308
+ validateString(from, 'from');
1309
+ validateString(to, 'to');
1310
+
1311
+ if (from === to)
1312
+ return '';
1313
+
1314
+ // Trim leading forward slashes.
1315
+ from = posix.resolve(from);
1316
+ to = posix.resolve(to);
1317
+
1318
+ if (from === to)
1319
+ return '';
1320
+
1321
+ const fromStart = 1;
1322
+ const fromEnd = from.length;
1323
+ const fromLen = fromEnd - fromStart;
1324
+ const toStart = 1;
1325
+ const toLen = to.length - toStart;
1326
+
1327
+ // Compare paths to find the longest common path from root
1328
+ const length = (fromLen < toLen ? fromLen : toLen);
1329
+ let lastCommonSep = -1;
1330
+ let i = 0;
1331
+ for (; i < length; i++) {
1332
+ const fromCode = from.charCodeAt(fromStart + i);
1333
+ if (fromCode !== to.charCodeAt(toStart + i))
232
1334
  break;
1335
+ else if (fromCode === CHAR_FORWARD_SLASH)
1336
+ lastCommonSep = i;
1337
+ }
1338
+ if (i === length) {
1339
+ if (toLen > length) {
1340
+ if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
1341
+ // We get here if `from` is the exact base path for `to`.
1342
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
1343
+ return to.slice(toStart + i + 1);
1344
+ }
1345
+ if (i === 0) {
1346
+ // We get here if `from` is the root
1347
+ // For example: from='/'; to='/foo'
1348
+ return to.slice(toStart + i);
1349
+ }
1350
+ } else if (fromLen > length) {
1351
+ if (from.charCodeAt(fromStart + i) ===
1352
+ CHAR_FORWARD_SLASH) {
1353
+ // We get here if `to` is the exact base path for `from`.
1354
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
1355
+ lastCommonSep = i;
1356
+ } else if (i === 0) {
1357
+ // We get here if `to` is the root.
1358
+ // For example: from='/foo/bar'; to='/'
1359
+ lastCommonSep = 0;
1360
+ }
233
1361
  }
234
- continue;
235
1362
  }
236
- if (end === -1) {
237
- matchedSlash = false;
238
- end = i + 1;
1363
+
1364
+ let out = '';
1365
+ // Generate the relative path based on the path difference between `to`
1366
+ // and `from`.
1367
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1368
+ if (i === fromEnd ||
1369
+ from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1370
+ out += out.length === 0 ? '..' : '/..';
1371
+ }
239
1372
  }
240
- if (code === DOT) {
241
- if (startDot === -1) startDot = i;
242
- else if (preDotState !== 1) preDotState = 1;
243
- } else if (startDot !== -1) {
244
- preDotState = -1;
1373
+
1374
+ // Lastly, append the rest of the destination (`to`) path that comes after
1375
+ // the common path parts.
1376
+ return `${out}${to.slice(toStart + lastCommonSep)}`;
1377
+ },
1378
+
1379
+ /**
1380
+ * @param {string} path
1381
+ * @returns {string}
1382
+ */
1383
+ toNamespacedPath(path) {
1384
+ // Non-op on posix systems
1385
+ return path;
1386
+ },
1387
+
1388
+ /**
1389
+ * @param {string} path
1390
+ * @returns {string}
1391
+ */
1392
+ dirname(path) {
1393
+ validateString(path, 'path');
1394
+ if (path.length === 0)
1395
+ return '.';
1396
+ const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1397
+ let end = -1;
1398
+ let matchedSlash = true;
1399
+ for (let i = path.length - 1; i >= 1; --i) {
1400
+ if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1401
+ if (!matchedSlash) {
1402
+ end = i;
1403
+ break;
1404
+ }
1405
+ } else {
1406
+ // We saw the first non-path separator
1407
+ matchedSlash = false;
1408
+ }
245
1409
  }
246
- }
247
- if (startDot === -1 || end === -1 || preDotState === 0 ||
248
- (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
249
- return "";
250
- }
251
- return path.slice(startDot, end);
252
- }
253
1410
 
254
- const path = { sep, delimiter, resolve, normalize, isAbsolute, join, relative, dirname, basename, extname };
255
- path.posix = path;
256
- export const posix = path;
1411
+ if (end === -1)
1412
+ return hasRoot ? '/' : '.';
1413
+ if (hasRoot && end === 1)
1414
+ return '//';
1415
+ return path.slice(0, end);
1416
+ },
1417
+
1418
+ /**
1419
+ * @param {string} path
1420
+ * @param {string} [suffix]
1421
+ * @returns {string}
1422
+ */
1423
+ basename(path, suffix) {
1424
+ if (suffix !== undefined)
1425
+ validateString(suffix, 'suffix');
1426
+ validateString(path, 'path');
1427
+
1428
+ let start = 0;
1429
+ let end = -1;
1430
+ let matchedSlash = true;
1431
+
1432
+ if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
1433
+ if (suffix === path)
1434
+ return '';
1435
+ let extIdx = suffix.length - 1;
1436
+ let firstNonSlashEnd = -1;
1437
+ for (let i = path.length - 1; i >= 0; --i) {
1438
+ const code = path.charCodeAt(i);
1439
+ if (code === CHAR_FORWARD_SLASH) {
1440
+ // If we reached a path separator that was not part of a set of path
1441
+ // separators at the end of the string, stop now
1442
+ if (!matchedSlash) {
1443
+ start = i + 1;
1444
+ break;
1445
+ }
1446
+ } else {
1447
+ if (firstNonSlashEnd === -1) {
1448
+ // We saw the first non-path separator, remember this index in case
1449
+ // we need it if the extension ends up not matching
1450
+ matchedSlash = false;
1451
+ firstNonSlashEnd = i + 1;
1452
+ }
1453
+ if (extIdx >= 0) {
1454
+ // Try to match the explicit extension
1455
+ if (code === suffix.charCodeAt(extIdx)) {
1456
+ if (--extIdx === -1) {
1457
+ // We matched the extension, so mark this as the end of our path
1458
+ // component
1459
+ end = i;
1460
+ }
1461
+ } else {
1462
+ // Extension does not match, so our result is the entire path
1463
+ // component
1464
+ extIdx = -1;
1465
+ end = firstNonSlashEnd;
1466
+ }
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+ if (start === end)
1472
+ end = firstNonSlashEnd;
1473
+ else if (end === -1)
1474
+ end = path.length;
1475
+ return path.slice(start, end);
1476
+ }
1477
+ for (let i = path.length - 1; i >= 0; --i) {
1478
+ if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1479
+ // If we reached a path separator that was not part of a set of path
1480
+ // separators at the end of the string, stop now
1481
+ if (!matchedSlash) {
1482
+ start = i + 1;
1483
+ break;
1484
+ }
1485
+ } else if (end === -1) {
1486
+ // We saw the first non-path separator, mark this as the end of our
1487
+ // path component
1488
+ matchedSlash = false;
1489
+ end = i + 1;
1490
+ }
1491
+ }
1492
+
1493
+ if (end === -1)
1494
+ return '';
1495
+ return path.slice(start, end);
1496
+ },
1497
+
1498
+ /**
1499
+ * @param {string} path
1500
+ * @returns {string}
1501
+ */
1502
+ extname(path) {
1503
+ validateString(path, 'path');
1504
+ let startDot = -1;
1505
+ let startPart = 0;
1506
+ let end = -1;
1507
+ let matchedSlash = true;
1508
+ // Track the state of characters (if any) we see before our first dot and
1509
+ // after any path separator we find
1510
+ let preDotState = 0;
1511
+ for (let i = path.length - 1; i >= 0; --i) {
1512
+ const char = path[i];
1513
+ if (char === '/') {
1514
+ // If we reached a path separator that was not part of a set of path
1515
+ // separators at the end of the string, stop now
1516
+ if (!matchedSlash) {
1517
+ startPart = i + 1;
1518
+ break;
1519
+ }
1520
+ continue;
1521
+ }
1522
+ if (end === -1) {
1523
+ // We saw the first non-path separator, mark this as the end of our
1524
+ // extension
1525
+ matchedSlash = false;
1526
+ end = i + 1;
1527
+ }
1528
+ if (char === '.') {
1529
+ // If this is our first dot, mark it as the start of our extension
1530
+ if (startDot === -1)
1531
+ startDot = i;
1532
+ else if (preDotState !== 1)
1533
+ preDotState = 1;
1534
+ } else if (startDot !== -1) {
1535
+ // We saw a non-dot and non-path separator before our dot, so we should
1536
+ // have a good chance at having a non-empty extension
1537
+ preDotState = -1;
1538
+ }
1539
+ }
1540
+
1541
+ if (startDot === -1 ||
1542
+ end === -1 ||
1543
+ // We saw a non-dot character immediately before the dot
1544
+ preDotState === 0 ||
1545
+ // The (right-most) trimmed path component is exactly '..'
1546
+ (preDotState === 1 &&
1547
+ startDot === end - 1 &&
1548
+ startDot === startPart + 1)) {
1549
+ return '';
1550
+ }
1551
+ return path.slice(startDot, end);
1552
+ },
1553
+
1554
+ format: _format.bind(null, '/'),
1555
+
1556
+ /**
1557
+ * @param {string} path
1558
+ * @returns {{
1559
+ * dir: string;
1560
+ * root: string;
1561
+ * base: string;
1562
+ * name: string;
1563
+ * ext: string;
1564
+ * }}
1565
+ */
1566
+ parse(path) {
1567
+ validateString(path, 'path');
1568
+
1569
+ const ret = { root: '', dir: '', base: '', ext: '', name: '' };
1570
+ if (path.length === 0)
1571
+ return ret;
1572
+ const isAbsolute =
1573
+ path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1574
+ let start;
1575
+ if (isAbsolute) {
1576
+ ret.root = '/';
1577
+ start = 1;
1578
+ } else {
1579
+ start = 0;
1580
+ }
1581
+ let startDot = -1;
1582
+ let startPart = 0;
1583
+ let end = -1;
1584
+ let matchedSlash = true;
1585
+ let i = path.length - 1;
1586
+
1587
+ // Track the state of characters (if any) we see before our first dot and
1588
+ // after any path separator we find
1589
+ let preDotState = 0;
1590
+
1591
+ // Get non-dir info
1592
+ for (; i >= start; --i) {
1593
+ const code = path.charCodeAt(i);
1594
+ if (code === CHAR_FORWARD_SLASH) {
1595
+ // If we reached a path separator that was not part of a set of path
1596
+ // separators at the end of the string, stop now
1597
+ if (!matchedSlash) {
1598
+ startPart = i + 1;
1599
+ break;
1600
+ }
1601
+ continue;
1602
+ }
1603
+ if (end === -1) {
1604
+ // We saw the first non-path separator, mark this as the end of our
1605
+ // extension
1606
+ matchedSlash = false;
1607
+ end = i + 1;
1608
+ }
1609
+ if (code === CHAR_DOT) {
1610
+ // If this is our first dot, mark it as the start of our extension
1611
+ if (startDot === -1)
1612
+ startDot = i;
1613
+ else if (preDotState !== 1)
1614
+ preDotState = 1;
1615
+ } else if (startDot !== -1) {
1616
+ // We saw a non-dot and non-path separator before our dot, so we should
1617
+ // have a good chance at having a non-empty extension
1618
+ preDotState = -1;
1619
+ }
1620
+ }
1621
+
1622
+ if (end !== -1) {
1623
+ const start = startPart === 0 && isAbsolute ? 1 : startPart;
1624
+ if (startDot === -1 ||
1625
+ // We saw a non-dot character immediately before the dot
1626
+ preDotState === 0 ||
1627
+ // The (right-most) trimmed path component is exactly '..'
1628
+ (preDotState === 1 &&
1629
+ startDot === end - 1 &&
1630
+ startDot === startPart + 1)) {
1631
+ ret.base = ret.name = path.slice(start, end);
1632
+ } else {
1633
+ ret.name = path.slice(start, startDot);
1634
+ ret.base = path.slice(start, end);
1635
+ ret.ext = path.slice(startDot, end);
1636
+ }
1637
+ }
1638
+
1639
+ if (startPart > 0)
1640
+ ret.dir = path.slice(0, startPart - 1);
1641
+ else if (isAbsolute)
1642
+ ret.dir = '/';
1643
+
1644
+ return ret;
1645
+ },
1646
+
1647
+ matchesGlob(_path, _pattern) {
1648
+ throw notSupported('path.matchesGlob');
1649
+ },
1650
+
1651
+ sep: '/',
1652
+ delimiter: ':',
1653
+ win32: null,
1654
+ posix: null,
1655
+ };
1656
+
1657
+ posix.win32 = win32.win32 = win32;
1658
+ posix.posix = win32.posix = posix;
1659
+
1660
+ // Legacy internal API, docs-only deprecated: DEP0080
1661
+ win32._makeLong = win32.toNamespacedPath;
1662
+ posix._makeLong = posix.toNamespacedPath;
1663
+
1664
+ const path = isWindows ? win32 : posix;
1665
+ export const {
1666
+ resolve, normalize, isAbsolute, join, relative, toNamespacedPath, dirname, basename, extname, format, parse,
1667
+ matchesGlob, sep, delimiter,
1668
+ } = path;
1669
+ export { posix, win32 };
257
1670
  export default path;