@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,1694 @@
1
+ // VENDORED, UNMODIFIED: Node.js lib/path.js
2
+ //
3
+ // version: v22.18.0
4
+ // commit: d1b18258ce0d85253e4e44cede152e31363ef5db
5
+ // source: https://raw.githubusercontent.com/nodejs/node/v22.18.0/lib/path.js
6
+ // sha256: 3448e7d5a3a27f4ddc34e3d5278f39f1a0c560fd4cbbf55d07803113b720cda1
7
+ //
8
+ // Everything below this header is Node's own text, byte for byte; the sha256
9
+ // above is of that text alone, so the vendoring is checkable with
10
+ // tail -n +17 src/node-lib/path.js | shasum -a 256
11
+ // Nothing here is edited. The free names the file expects of the Node runtime
12
+ // -- `primordials`, `require` of `internal/constants`, `internal/validators`,
13
+ // `internal/util` and `internal/deps/minimatch/index`, `module` and `process`
14
+ // -- are supplied by the binding in src/shims/path.ts, which evaluates this
15
+ // text. To move to a newer Node, replace this file and the header, and run
16
+ // Node's own test/parallel/test-path-*.js against the build.
17
+ // Copyright Joyent, Inc. and other Node contributors.
18
+ //
19
+ // Permission is hereby granted, free of charge, to any person obtaining a
20
+ // copy of this software and associated documentation files (the
21
+ // "Software"), to deal in the Software without restriction, including
22
+ // without limitation the rights to use, copy, modify, merge, publish,
23
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
24
+ // persons to whom the Software is furnished to do so, subject to the
25
+ // following conditions:
26
+ //
27
+ // The above copyright notice and this permission notice shall be included
28
+ // in all copies or substantial portions of the Software.
29
+ //
30
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
33
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
35
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
36
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
37
+
38
+ 'use strict';
39
+
40
+ const {
41
+ ArrayPrototypeIncludes,
42
+ ArrayPrototypeJoin,
43
+ ArrayPrototypeSlice,
44
+ FunctionPrototypeBind,
45
+ StringPrototypeCharCodeAt,
46
+ StringPrototypeIncludes,
47
+ StringPrototypeIndexOf,
48
+ StringPrototypeLastIndexOf,
49
+ StringPrototypeRepeat,
50
+ StringPrototypeReplace,
51
+ StringPrototypeSlice,
52
+ StringPrototypeSplit,
53
+ StringPrototypeToLowerCase,
54
+ StringPrototypeToUpperCase,
55
+ } = primordials;
56
+
57
+ const {
58
+ CHAR_UPPERCASE_A,
59
+ CHAR_LOWERCASE_A,
60
+ CHAR_UPPERCASE_Z,
61
+ CHAR_LOWERCASE_Z,
62
+ CHAR_DOT,
63
+ CHAR_FORWARD_SLASH,
64
+ CHAR_BACKWARD_SLASH,
65
+ CHAR_COLON,
66
+ CHAR_QUESTION_MARK,
67
+ } = require('internal/constants');
68
+ const {
69
+ validateObject,
70
+ validateString,
71
+ } = require('internal/validators');
72
+
73
+ const {
74
+ getLazy,
75
+ isWindows,
76
+ isMacOS,
77
+ } = require('internal/util');
78
+
79
+ const lazyMinimatch = getLazy(() => require('internal/deps/minimatch/index'));
80
+
81
+ function isPathSeparator(code) {
82
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
83
+ }
84
+
85
+ function isPosixPathSeparator(code) {
86
+ return code === CHAR_FORWARD_SLASH;
87
+ }
88
+
89
+ const WINDOWS_RESERVED_NAMES = [
90
+ 'CON', 'PRN', 'AUX', 'NUL',
91
+ 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9',
92
+ 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9',
93
+ ];
94
+
95
+ function isWindowsReservedName(path, colonIndex) {
96
+ const devicePart = StringPrototypeToUpperCase(StringPrototypeSlice(path, 0, colonIndex));
97
+ return ArrayPrototypeIncludes(WINDOWS_RESERVED_NAMES, devicePart);
98
+ }
99
+
100
+ function isWindowsDeviceRoot(code) {
101
+ return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
102
+ (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
103
+ }
104
+
105
+ // Resolves . and .. elements in a path with directory names
106
+ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
107
+ let res = '';
108
+ let lastSegmentLength = 0;
109
+ let lastSlash = -1;
110
+ let dots = 0;
111
+ let code = 0;
112
+ for (let i = 0; i <= path.length; ++i) {
113
+ if (i < path.length)
114
+ code = StringPrototypeCharCodeAt(path, i);
115
+ else if (isPathSeparator(code))
116
+ break;
117
+ else
118
+ code = CHAR_FORWARD_SLASH;
119
+
120
+ if (isPathSeparator(code)) {
121
+ if (lastSlash === i - 1 || dots === 1) {
122
+ // NOOP
123
+ } else if (dots === 2) {
124
+ if (res.length < 2 || lastSegmentLength !== 2 ||
125
+ StringPrototypeCharCodeAt(res, res.length - 1) !== CHAR_DOT ||
126
+ StringPrototypeCharCodeAt(res, res.length - 2) !== CHAR_DOT) {
127
+ if (res.length > 2) {
128
+ const lastSlashIndex = res.length - lastSegmentLength - 1;
129
+ if (lastSlashIndex === -1) {
130
+ res = '';
131
+ lastSegmentLength = 0;
132
+ } else {
133
+ res = StringPrototypeSlice(res, 0, lastSlashIndex);
134
+ lastSegmentLength =
135
+ res.length - 1 - StringPrototypeLastIndexOf(res, separator);
136
+ }
137
+ lastSlash = i;
138
+ dots = 0;
139
+ continue;
140
+ } else if (res.length !== 0) {
141
+ res = '';
142
+ lastSegmentLength = 0;
143
+ lastSlash = i;
144
+ dots = 0;
145
+ continue;
146
+ }
147
+ }
148
+ if (allowAboveRoot) {
149
+ res += res.length > 0 ? `${separator}..` : '..';
150
+ lastSegmentLength = 2;
151
+ }
152
+ } else {
153
+ if (res.length > 0)
154
+ res += `${separator}${StringPrototypeSlice(path, lastSlash + 1, i)}`;
155
+ else
156
+ res = StringPrototypeSlice(path, lastSlash + 1, i);
157
+ lastSegmentLength = i - lastSlash - 1;
158
+ }
159
+ lastSlash = i;
160
+ dots = 0;
161
+ } else if (code === CHAR_DOT && dots !== -1) {
162
+ ++dots;
163
+ } else {
164
+ dots = -1;
165
+ }
166
+ }
167
+ return res;
168
+ }
169
+
170
+ function formatExt(ext) {
171
+ return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';
172
+ }
173
+
174
+ /**
175
+ * @param {string} sep
176
+ * @param {{
177
+ * dir?: string;
178
+ * root?: string;
179
+ * base?: string;
180
+ * name?: string;
181
+ * ext?: string;
182
+ * }} pathObject
183
+ * @returns {string}
184
+ */
185
+ function _format(sep, pathObject) {
186
+ validateObject(pathObject, 'pathObject');
187
+ const dir = pathObject.dir || pathObject.root;
188
+ const base = pathObject.base ||
189
+ `${pathObject.name || ''}${formatExt(pathObject.ext)}`;
190
+ if (!dir) {
191
+ return base;
192
+ }
193
+ return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`;
194
+ }
195
+
196
+ function glob(path, pattern, windows) {
197
+ validateString(path, 'path');
198
+ validateString(pattern, 'pattern');
199
+ return lazyMinimatch().minimatch(path, pattern, {
200
+ __proto__: null,
201
+ nocase: isMacOS || isWindows,
202
+ windowsPathsNoEscape: true,
203
+ nonegate: true,
204
+ nocomment: true,
205
+ optimizationLevel: 2,
206
+ platform: windows ? 'win32' : 'posix',
207
+ nocaseMagicOnly: true,
208
+ });
209
+ }
210
+ const forwardSlashRegExp = /\//g;
211
+
212
+ const win32 = {
213
+ /**
214
+ * path.resolve([from ...], to)
215
+ * @param {...string} args
216
+ * @returns {string}
217
+ */
218
+ resolve(...args) {
219
+ let resolvedDevice = '';
220
+ let resolvedTail = '';
221
+ let resolvedAbsolute = false;
222
+
223
+ for (let i = args.length - 1; i >= -1; i--) {
224
+ let path;
225
+ if (i >= 0) {
226
+ path = args[i];
227
+ validateString(path, `paths[${i}]`);
228
+
229
+ // Skip empty entries
230
+ if (path.length === 0) {
231
+ continue;
232
+ }
233
+ } else if (resolvedDevice.length === 0) {
234
+ path = process.cwd();
235
+ // Fast path for current directory
236
+ if (args.length === 0 || ((args.length === 1 && (args[0] === '' || args[0] === '.')) &&
237
+ isPathSeparator(StringPrototypeCharCodeAt(path, 0)))) {
238
+ if (!isWindows) {
239
+ path = StringPrototypeReplace(path, forwardSlashRegExp, '\\');
240
+ }
241
+ return path;
242
+ }
243
+ } else {
244
+ // Windows has the concept of drive-specific current working
245
+ // directories. If we've resolved a drive letter but not yet an
246
+ // absolute path, get cwd for that drive, or the process cwd if
247
+ // the drive cwd is not available. We're sure the device is not
248
+ // a UNC path at this points, because UNC paths are always absolute.
249
+ path = process.env[`=${resolvedDevice}`] || process.cwd();
250
+
251
+ // Verify that a cwd was found and that it actually points
252
+ // to our drive. If not, default to the drive's root.
253
+ if (path === undefined ||
254
+ (StringPrototypeToLowerCase(StringPrototypeSlice(path, 0, 2)) !==
255
+ StringPrototypeToLowerCase(resolvedDevice) &&
256
+ StringPrototypeCharCodeAt(path, 2) === CHAR_BACKWARD_SLASH)) {
257
+ path = `${resolvedDevice}\\`;
258
+ }
259
+ }
260
+
261
+ const len = path.length;
262
+ let rootEnd = 0;
263
+ let device = '';
264
+ let isAbsolute = false;
265
+ const code = StringPrototypeCharCodeAt(path, 0);
266
+
267
+ // Try to match a root
268
+ if (len === 1) {
269
+ if (isPathSeparator(code)) {
270
+ // `path` contains just a path separator
271
+ rootEnd = 1;
272
+ isAbsolute = true;
273
+ }
274
+ } else if (isPathSeparator(code)) {
275
+ // Possible UNC root
276
+
277
+ // If we started with a separator, we know we at least have an
278
+ // absolute path of some kind (UNC or otherwise)
279
+ isAbsolute = true;
280
+
281
+ if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {
282
+ // Matched double path separator at beginning
283
+ let j = 2;
284
+ let last = j;
285
+ // Match 1 or more non-path separators
286
+ while (j < len &&
287
+ !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
288
+ j++;
289
+ }
290
+ if (j < len && j !== last) {
291
+ const firstPart = StringPrototypeSlice(path, last, j);
292
+ // Matched!
293
+ last = j;
294
+ // Match 1 or more path separators
295
+ while (j < len &&
296
+ isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
297
+ j++;
298
+ }
299
+ if (j < len && j !== last) {
300
+ // Matched!
301
+ last = j;
302
+ // Match 1 or more non-path separators
303
+ while (j < len &&
304
+ !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
305
+ j++;
306
+ }
307
+ if (j === len || j !== last) {
308
+ // We matched a UNC root
309
+ device =
310
+ `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`;
311
+ rootEnd = j;
312
+ }
313
+ }
314
+ }
315
+ } else {
316
+ rootEnd = 1;
317
+ }
318
+ } else if (isWindowsDeviceRoot(code) &&
319
+ StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
320
+ // Possible device root
321
+ device = StringPrototypeSlice(path, 0, 2);
322
+ rootEnd = 2;
323
+ if (len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {
324
+ // Treat separator following drive name as an absolute path
325
+ // indicator
326
+ isAbsolute = true;
327
+ rootEnd = 3;
328
+ }
329
+ }
330
+
331
+ if (device.length > 0) {
332
+ if (resolvedDevice.length > 0) {
333
+ if (StringPrototypeToLowerCase(device) !==
334
+ StringPrototypeToLowerCase(resolvedDevice))
335
+ // This path points to another device so it is not applicable
336
+ continue;
337
+ } else {
338
+ resolvedDevice = device;
339
+ }
340
+ }
341
+
342
+ if (resolvedAbsolute) {
343
+ if (resolvedDevice.length > 0)
344
+ break;
345
+ } else {
346
+ resolvedTail =
347
+ `${StringPrototypeSlice(path, rootEnd)}\\${resolvedTail}`;
348
+ resolvedAbsolute = isAbsolute;
349
+ if (isAbsolute && resolvedDevice.length > 0) {
350
+ break;
351
+ }
352
+ }
353
+ }
354
+
355
+ // At this point the path should be resolved to a full absolute path,
356
+ // but handle relative paths to be safe (might happen when process.cwd()
357
+ // fails)
358
+
359
+ // Normalize the tail path
360
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\',
361
+ isPathSeparator);
362
+
363
+ return resolvedAbsolute ?
364
+ `${resolvedDevice}\\${resolvedTail}` :
365
+ `${resolvedDevice}${resolvedTail}` || '.';
366
+ },
367
+
368
+ /**
369
+ * @param {string} path
370
+ * @returns {string}
371
+ */
372
+ normalize(path) {
373
+ validateString(path, 'path');
374
+ const len = path.length;
375
+ if (len === 0)
376
+ return '.';
377
+ let rootEnd = 0;
378
+ let device;
379
+ let isAbsolute = false;
380
+ const code = StringPrototypeCharCodeAt(path, 0);
381
+
382
+ // Try to match a root
383
+ if (len === 1) {
384
+ // `path` contains just a single char, exit early to avoid
385
+ // unnecessary work
386
+ return isPosixPathSeparator(code) ? '\\' : path;
387
+ }
388
+ if (isPathSeparator(code)) {
389
+ // Possible UNC root
390
+
391
+ // If we started with a separator, we know we at least have an absolute
392
+ // path of some kind (UNC or otherwise)
393
+ isAbsolute = true;
394
+
395
+ if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {
396
+ // Matched double path separator at beginning
397
+ let j = 2;
398
+ let last = j;
399
+ // Match 1 or more non-path separators
400
+ while (j < len &&
401
+ !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
402
+ j++;
403
+ }
404
+ if (j < len && j !== last) {
405
+ const firstPart = StringPrototypeSlice(path, last, j);
406
+ // Matched!
407
+ last = j;
408
+ // Match 1 or more path separators
409
+ while (j < len &&
410
+ isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
411
+ j++;
412
+ }
413
+ if (j < len && j !== last) {
414
+ // Matched!
415
+ last = j;
416
+ // Match 1 or more non-path separators
417
+ while (j < len &&
418
+ !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
419
+ j++;
420
+ }
421
+ if (j === len) {
422
+ // We matched a UNC root only
423
+ // Return the normalized version of the UNC root since there
424
+ // is nothing left to process
425
+ return `\\\\${firstPart}\\${StringPrototypeSlice(path, last)}\\`;
426
+ }
427
+ if (j !== last) {
428
+ // We matched a UNC root with leftovers
429
+ device =
430
+ `\\\\${firstPart}\\${StringPrototypeSlice(path, last, j)}`;
431
+ rootEnd = j;
432
+ }
433
+ }
434
+ }
435
+ } else {
436
+ rootEnd = 1;
437
+ }
438
+ } else {
439
+ const colonIndex = StringPrototypeIndexOf(path, ':');
440
+ if (colonIndex > 0) {
441
+ if (isWindowsDeviceRoot(code) && colonIndex === 1) {
442
+ device = StringPrototypeSlice(path, 0, 2);
443
+ rootEnd = 2;
444
+ if (len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {
445
+ isAbsolute = true;
446
+ rootEnd = 3;
447
+ }
448
+ } else if (isWindowsReservedName(path, colonIndex)) {
449
+ device = StringPrototypeSlice(path, 0, colonIndex + 1);
450
+ rootEnd = colonIndex + 1;
451
+
452
+ }
453
+ }
454
+ }
455
+
456
+ let tail = rootEnd < len ?
457
+ normalizeString(StringPrototypeSlice(path, rootEnd),
458
+ !isAbsolute, '\\', isPathSeparator) :
459
+ '';
460
+ if (tail.length === 0 && !isAbsolute)
461
+ tail = '.';
462
+ if (tail.length > 0 &&
463
+ isPathSeparator(StringPrototypeCharCodeAt(path, len - 1)))
464
+ tail += '\\';
465
+ if (!isAbsolute && device === undefined && StringPrototypeIncludes(path, ':')) {
466
+ // If the original path was not absolute and if we have not been able to
467
+ // resolve it relative to a particular device, we need to ensure that the
468
+ // `tail` has not become something that Windows might interpret as an
469
+ // absolute path. See CVE-2024-36139.
470
+ if (tail.length >= 2 &&
471
+ isWindowsDeviceRoot(StringPrototypeCharCodeAt(tail, 0)) &&
472
+ StringPrototypeCharCodeAt(tail, 1) === CHAR_COLON) {
473
+ return `.\\${tail}`;
474
+ }
475
+ let index = StringPrototypeIndexOf(path, ':');
476
+
477
+ do {
478
+ if (index === len - 1 || isPathSeparator(StringPrototypeCharCodeAt(path, index + 1))) {
479
+ return `.\\${tail}`;
480
+ }
481
+ } while ((index = StringPrototypeIndexOf(path, ':', index + 1)) !== -1);
482
+ }
483
+ const colonIndex = StringPrototypeIndexOf(path, ':');
484
+ if (isWindowsReservedName(path, colonIndex)) {
485
+ return `.\\${device ?? ''}${tail}`;
486
+ }
487
+ if (device === undefined) {
488
+ return isAbsolute ? `\\${tail}` : tail;
489
+ }
490
+ return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
491
+ },
492
+
493
+ /**
494
+ * @param {string} path
495
+ * @returns {boolean}
496
+ */
497
+ isAbsolute(path) {
498
+ validateString(path, 'path');
499
+ const len = path.length;
500
+ if (len === 0)
501
+ return false;
502
+
503
+ const code = StringPrototypeCharCodeAt(path, 0);
504
+ return isPathSeparator(code) ||
505
+ // Possible device root
506
+ (len > 2 &&
507
+ isWindowsDeviceRoot(code) &&
508
+ StringPrototypeCharCodeAt(path, 1) === CHAR_COLON &&
509
+ isPathSeparator(StringPrototypeCharCodeAt(path, 2)));
510
+ },
511
+
512
+ /**
513
+ * @param {...string} args
514
+ * @returns {string}
515
+ */
516
+ join(...args) {
517
+ if (args.length === 0)
518
+ return '.';
519
+
520
+ let joined;
521
+ let firstPart;
522
+ for (let i = 0; i < args.length; ++i) {
523
+ const arg = args[i];
524
+ validateString(arg, 'path');
525
+ if (arg.length > 0) {
526
+ if (joined === undefined)
527
+ joined = firstPart = arg;
528
+ else
529
+ joined += `\\${arg}`;
530
+ }
531
+ }
532
+
533
+ if (joined === undefined)
534
+ return '.';
535
+
536
+ // Make sure that the joined path doesn't start with two slashes, because
537
+ // normalize() will mistake it for a UNC path then.
538
+ //
539
+ // This step is skipped when it is very clear that the user actually
540
+ // intended to point at a UNC path. This is assumed when the first
541
+ // non-empty string arguments starts with exactly two slashes followed by
542
+ // at least one more non-slash character.
543
+ //
544
+ // Note that for normalize() to treat a path as a UNC path it needs to
545
+ // have at least 2 components, so we don't filter for that here.
546
+ // This means that the user can use join to construct UNC paths from
547
+ // a server name and a share name; for example:
548
+ // path.join('//server', 'share') -> '\\\\server\\share\\')
549
+ let needsReplace = true;
550
+ let slashCount = 0;
551
+ if (isPathSeparator(StringPrototypeCharCodeAt(firstPart, 0))) {
552
+ ++slashCount;
553
+ const firstLen = firstPart.length;
554
+ if (firstLen > 1 &&
555
+ isPathSeparator(StringPrototypeCharCodeAt(firstPart, 1))) {
556
+ ++slashCount;
557
+ if (firstLen > 2) {
558
+ if (isPathSeparator(StringPrototypeCharCodeAt(firstPart, 2)))
559
+ ++slashCount;
560
+ else {
561
+ // We matched a UNC path in the first part
562
+ needsReplace = false;
563
+ }
564
+ }
565
+ }
566
+ }
567
+ if (needsReplace) {
568
+ // Find any more consecutive slashes we need to replace
569
+ while (slashCount < joined.length &&
570
+ isPathSeparator(StringPrototypeCharCodeAt(joined, slashCount))) {
571
+ slashCount++;
572
+ }
573
+
574
+ // Replace the slashes if needed
575
+ if (slashCount >= 2)
576
+ joined = `\\${StringPrototypeSlice(joined, slashCount)}`;
577
+ }
578
+
579
+ return win32.normalize(joined);
580
+ },
581
+
582
+ /**
583
+ * It will solve the relative path from `from` to `to`, for instance
584
+ * from = 'C:\\orandea\\test\\aaa'
585
+ * to = 'C:\\orandea\\impl\\bbb'
586
+ * The output of the function should be: '..\\..\\impl\\bbb'
587
+ * @param {string} from
588
+ * @param {string} to
589
+ * @returns {string}
590
+ */
591
+ relative(from, to) {
592
+ validateString(from, 'from');
593
+ validateString(to, 'to');
594
+
595
+ if (from === to)
596
+ return '';
597
+
598
+ const fromOrig = win32.resolve(from);
599
+ const toOrig = win32.resolve(to);
600
+
601
+ if (fromOrig === toOrig)
602
+ return '';
603
+
604
+ from = StringPrototypeToLowerCase(fromOrig);
605
+ to = StringPrototypeToLowerCase(toOrig);
606
+
607
+ if (from === to)
608
+ return '';
609
+
610
+ if (fromOrig.length !== from.length || toOrig.length !== to.length) {
611
+ const fromSplit = StringPrototypeSplit(fromOrig, '\\');
612
+ const toSplit = StringPrototypeSplit(toOrig, '\\');
613
+ if (fromSplit[fromSplit.length - 1] === '') {
614
+ fromSplit.pop();
615
+ }
616
+ if (toSplit[toSplit.length - 1] === '') {
617
+ toSplit.pop();
618
+ }
619
+
620
+ const fromLen = fromSplit.length;
621
+ const toLen = toSplit.length;
622
+ const length = fromLen < toLen ? fromLen : toLen;
623
+
624
+ let i;
625
+ for (i = 0; i < length; i++) {
626
+ if (StringPrototypeToLowerCase(fromSplit[i]) !== StringPrototypeToLowerCase(toSplit[i])) {
627
+ break;
628
+ }
629
+ }
630
+
631
+ if (i === 0) {
632
+ return toOrig;
633
+ } else if (i === length) {
634
+ if (toLen > length) {
635
+ return ArrayPrototypeJoin(ArrayPrototypeSlice(toSplit, i), '\\');
636
+ }
637
+ if (fromLen > length) {
638
+ return StringPrototypeRepeat('..\\', fromLen - 1 - i) + '..';
639
+ }
640
+ return '';
641
+ }
642
+
643
+ return StringPrototypeRepeat('..\\', fromLen - i) + ArrayPrototypeJoin(ArrayPrototypeSlice(toSplit, i), '\\');
644
+ }
645
+
646
+ // Trim any leading backslashes
647
+ let fromStart = 0;
648
+ while (fromStart < from.length &&
649
+ StringPrototypeCharCodeAt(from, fromStart) === CHAR_BACKWARD_SLASH) {
650
+ fromStart++;
651
+ }
652
+ // Trim trailing backslashes (applicable to UNC paths only)
653
+ let fromEnd = from.length;
654
+ while (
655
+ fromEnd - 1 > fromStart &&
656
+ StringPrototypeCharCodeAt(from, fromEnd - 1) === CHAR_BACKWARD_SLASH
657
+ ) {
658
+ fromEnd--;
659
+ }
660
+ const fromLen = fromEnd - fromStart;
661
+
662
+ // Trim any leading backslashes
663
+ let toStart = 0;
664
+ while (toStart < to.length &&
665
+ StringPrototypeCharCodeAt(to, toStart) === CHAR_BACKWARD_SLASH) {
666
+ toStart++;
667
+ }
668
+ // Trim trailing backslashes (applicable to UNC paths only)
669
+ let toEnd = to.length;
670
+ while (toEnd - 1 > toStart &&
671
+ StringPrototypeCharCodeAt(to, toEnd - 1) === CHAR_BACKWARD_SLASH) {
672
+ toEnd--;
673
+ }
674
+ const toLen = toEnd - toStart;
675
+
676
+ // Compare paths to find the longest common path from root
677
+ const length = fromLen < toLen ? fromLen : toLen;
678
+ let lastCommonSep = -1;
679
+ let i = 0;
680
+ for (; i < length; i++) {
681
+ const fromCode = StringPrototypeCharCodeAt(from, fromStart + i);
682
+ if (fromCode !== StringPrototypeCharCodeAt(to, toStart + i))
683
+ break;
684
+ else if (fromCode === CHAR_BACKWARD_SLASH)
685
+ lastCommonSep = i;
686
+ }
687
+
688
+ // We found a mismatch before the first common path separator was seen, so
689
+ // return the original `to`.
690
+ if (i !== length) {
691
+ if (lastCommonSep === -1)
692
+ return toOrig;
693
+ } else {
694
+ if (toLen > length) {
695
+ if (StringPrototypeCharCodeAt(to, toStart + i) ===
696
+ CHAR_BACKWARD_SLASH) {
697
+ // We get here if `from` is the exact base path for `to`.
698
+ // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
699
+ return StringPrototypeSlice(toOrig, toStart + i + 1);
700
+ }
701
+ if (i === 2) {
702
+ // We get here if `from` is the device root.
703
+ // For example: from='C:\\'; to='C:\\foo'
704
+ return StringPrototypeSlice(toOrig, toStart + i);
705
+ }
706
+ }
707
+ if (fromLen > length) {
708
+ if (StringPrototypeCharCodeAt(from, fromStart + i) ===
709
+ CHAR_BACKWARD_SLASH) {
710
+ // We get here if `to` is the exact base path for `from`.
711
+ // For example: from='C:\\foo\\bar'; to='C:\\foo'
712
+ lastCommonSep = i;
713
+ } else if (i === 2) {
714
+ // We get here if `to` is the device root.
715
+ // For example: from='C:\\foo\\bar'; to='C:\\'
716
+ lastCommonSep = 3;
717
+ }
718
+ }
719
+ if (lastCommonSep === -1)
720
+ lastCommonSep = 0;
721
+ }
722
+
723
+ let out = '';
724
+ // Generate the relative path based on the path difference between `to` and
725
+ // `from`
726
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
727
+ if (i === fromEnd ||
728
+ StringPrototypeCharCodeAt(from, i) === CHAR_BACKWARD_SLASH) {
729
+ out += out.length === 0 ? '..' : '\\..';
730
+ }
731
+ }
732
+
733
+ toStart += lastCommonSep;
734
+
735
+ // Lastly, append the rest of the destination (`to`) path that comes after
736
+ // the common path parts
737
+ if (out.length > 0)
738
+ return `${out}${StringPrototypeSlice(toOrig, toStart, toEnd)}`;
739
+
740
+ if (StringPrototypeCharCodeAt(toOrig, toStart) === CHAR_BACKWARD_SLASH)
741
+ ++toStart;
742
+ return StringPrototypeSlice(toOrig, toStart, toEnd);
743
+ },
744
+
745
+ /**
746
+ * @param {string} path
747
+ * @returns {string}
748
+ */
749
+ toNamespacedPath(path) {
750
+ // Note: this will *probably* throw somewhere.
751
+ if (typeof path !== 'string' || path.length === 0)
752
+ return path;
753
+
754
+ const resolvedPath = win32.resolve(path);
755
+
756
+ if (resolvedPath.length <= 2)
757
+ return path;
758
+
759
+ if (StringPrototypeCharCodeAt(resolvedPath, 0) === CHAR_BACKWARD_SLASH) {
760
+ // Possible UNC root
761
+ if (StringPrototypeCharCodeAt(resolvedPath, 1) === CHAR_BACKWARD_SLASH) {
762
+ const code = StringPrototypeCharCodeAt(resolvedPath, 2);
763
+ if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
764
+ // Matched non-long UNC root, convert the path to a long UNC path
765
+ return `\\\\?\\UNC\\${StringPrototypeSlice(resolvedPath, 2)}`;
766
+ }
767
+ }
768
+ } else if (
769
+ isWindowsDeviceRoot(StringPrototypeCharCodeAt(resolvedPath, 0)) &&
770
+ StringPrototypeCharCodeAt(resolvedPath, 1) === CHAR_COLON &&
771
+ StringPrototypeCharCodeAt(resolvedPath, 2) === CHAR_BACKWARD_SLASH
772
+ ) {
773
+ // Matched device root, convert the path to a long UNC path
774
+ return `\\\\?\\${resolvedPath}`;
775
+ }
776
+
777
+ return resolvedPath;
778
+ },
779
+
780
+ /**
781
+ * @param {string} path
782
+ * @returns {string}
783
+ */
784
+ dirname(path) {
785
+ validateString(path, 'path');
786
+ const len = path.length;
787
+ if (len === 0)
788
+ return '.';
789
+ let rootEnd = -1;
790
+ let offset = 0;
791
+ const code = StringPrototypeCharCodeAt(path, 0);
792
+
793
+ if (len === 1) {
794
+ // `path` contains just a path separator, exit early to avoid
795
+ // unnecessary work or a dot.
796
+ return isPathSeparator(code) ? path : '.';
797
+ }
798
+
799
+ // Try to match a root
800
+ if (isPathSeparator(code)) {
801
+ // Possible UNC root
802
+
803
+ rootEnd = offset = 1;
804
+
805
+ if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {
806
+ // Matched double path separator at beginning
807
+ let j = 2;
808
+ let last = j;
809
+ // Match 1 or more non-path separators
810
+ while (j < len &&
811
+ !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
812
+ j++;
813
+ }
814
+ if (j < len && j !== last) {
815
+ // Matched!
816
+ last = j;
817
+ // Match 1 or more path separators
818
+ while (j < len &&
819
+ isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
820
+ j++;
821
+ }
822
+ if (j < len && j !== last) {
823
+ // Matched!
824
+ last = j;
825
+ // Match 1 or more non-path separators
826
+ while (j < len &&
827
+ !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
828
+ j++;
829
+ }
830
+ if (j === len) {
831
+ // We matched a UNC root only
832
+ return path;
833
+ }
834
+ if (j !== last) {
835
+ // We matched a UNC root with leftovers
836
+
837
+ // Offset by 1 to include the separator after the UNC root to
838
+ // treat it as a "normal root" on top of a (UNC) root
839
+ rootEnd = offset = j + 1;
840
+ }
841
+ }
842
+ }
843
+ }
844
+ // Possible device root
845
+ } else if (isWindowsDeviceRoot(code) &&
846
+ StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
847
+ rootEnd =
848
+ len > 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 2)) ? 3 : 2;
849
+ offset = rootEnd;
850
+ }
851
+
852
+ let end = -1;
853
+ let matchedSlash = true;
854
+ for (let i = len - 1; i >= offset; --i) {
855
+ if (isPathSeparator(StringPrototypeCharCodeAt(path, i))) {
856
+ if (!matchedSlash) {
857
+ end = i;
858
+ break;
859
+ }
860
+ } else {
861
+ // We saw the first non-path separator
862
+ matchedSlash = false;
863
+ }
864
+ }
865
+
866
+ if (end === -1) {
867
+ if (rootEnd === -1)
868
+ return '.';
869
+
870
+ end = rootEnd;
871
+ }
872
+ return StringPrototypeSlice(path, 0, end);
873
+ },
874
+
875
+ /**
876
+ * @param {string} path
877
+ * @param {string} [suffix]
878
+ * @returns {string}
879
+ */
880
+ basename(path, suffix) {
881
+ if (suffix !== undefined)
882
+ validateString(suffix, 'suffix');
883
+ validateString(path, 'path');
884
+ let start = 0;
885
+ let end = -1;
886
+ let matchedSlash = true;
887
+
888
+ // Check for a drive letter prefix so as not to mistake the following
889
+ // path separator as an extra separator at the end of the path that can be
890
+ // disregarded
891
+ if (path.length >= 2 &&
892
+ isWindowsDeviceRoot(StringPrototypeCharCodeAt(path, 0)) &&
893
+ StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
894
+ start = 2;
895
+ }
896
+
897
+ if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
898
+ if (suffix === path)
899
+ return '';
900
+ let extIdx = suffix.length - 1;
901
+ let firstNonSlashEnd = -1;
902
+ for (let i = path.length - 1; i >= start; --i) {
903
+ const code = StringPrototypeCharCodeAt(path, i);
904
+ if (isPathSeparator(code)) {
905
+ // If we reached a path separator that was not part of a set of path
906
+ // separators at the end of the string, stop now
907
+ if (!matchedSlash) {
908
+ start = i + 1;
909
+ break;
910
+ }
911
+ } else {
912
+ if (firstNonSlashEnd === -1) {
913
+ // We saw the first non-path separator, remember this index in case
914
+ // we need it if the extension ends up not matching
915
+ matchedSlash = false;
916
+ firstNonSlashEnd = i + 1;
917
+ }
918
+ if (extIdx >= 0) {
919
+ // Try to match the explicit extension
920
+ if (code === StringPrototypeCharCodeAt(suffix, extIdx)) {
921
+ if (--extIdx === -1) {
922
+ // We matched the extension, so mark this as the end of our path
923
+ // component
924
+ end = i;
925
+ }
926
+ } else {
927
+ // Extension does not match, so our result is the entire path
928
+ // component
929
+ extIdx = -1;
930
+ end = firstNonSlashEnd;
931
+ }
932
+ }
933
+ }
934
+ }
935
+
936
+ if (start === end)
937
+ end = firstNonSlashEnd;
938
+ else if (end === -1)
939
+ end = path.length;
940
+ return StringPrototypeSlice(path, start, end);
941
+ }
942
+ for (let i = path.length - 1; i >= start; --i) {
943
+ if (isPathSeparator(StringPrototypeCharCodeAt(path, i))) {
944
+ // If we reached a path separator that was not part of a set of path
945
+ // separators at the end of the string, stop now
946
+ if (!matchedSlash) {
947
+ start = i + 1;
948
+ break;
949
+ }
950
+ } else if (end === -1) {
951
+ // We saw the first non-path separator, mark this as the end of our
952
+ // path component
953
+ matchedSlash = false;
954
+ end = i + 1;
955
+ }
956
+ }
957
+
958
+ if (end === -1)
959
+ return '';
960
+ return StringPrototypeSlice(path, start, end);
961
+ },
962
+
963
+ /**
964
+ * @param {string} path
965
+ * @returns {string}
966
+ */
967
+ extname(path) {
968
+ validateString(path, 'path');
969
+ let start = 0;
970
+ let startDot = -1;
971
+ let startPart = 0;
972
+ let end = -1;
973
+ let matchedSlash = true;
974
+ // Track the state of characters (if any) we see before our first dot and
975
+ // after any path separator we find
976
+ let preDotState = 0;
977
+
978
+ // Check for a drive letter prefix so as not to mistake the following
979
+ // path separator as an extra separator at the end of the path that can be
980
+ // disregarded
981
+
982
+ if (path.length >= 2 &&
983
+ StringPrototypeCharCodeAt(path, 1) === CHAR_COLON &&
984
+ isWindowsDeviceRoot(StringPrototypeCharCodeAt(path, 0))) {
985
+ start = startPart = 2;
986
+ }
987
+
988
+ for (let i = path.length - 1; i >= start; --i) {
989
+ const code = StringPrototypeCharCodeAt(path, i);
990
+ if (isPathSeparator(code)) {
991
+ // If we reached a path separator that was not part of a set of path
992
+ // separators at the end of the string, stop now
993
+ if (!matchedSlash) {
994
+ startPart = i + 1;
995
+ break;
996
+ }
997
+ continue;
998
+ }
999
+ if (end === -1) {
1000
+ // We saw the first non-path separator, mark this as the end of our
1001
+ // extension
1002
+ matchedSlash = false;
1003
+ end = i + 1;
1004
+ }
1005
+ if (code === CHAR_DOT) {
1006
+ // If this is our first dot, mark it as the start of our extension
1007
+ if (startDot === -1)
1008
+ startDot = i;
1009
+ else if (preDotState !== 1)
1010
+ preDotState = 1;
1011
+ } else if (startDot !== -1) {
1012
+ // We saw a non-dot and non-path separator before our dot, so we should
1013
+ // have a good chance at having a non-empty extension
1014
+ preDotState = -1;
1015
+ }
1016
+ }
1017
+
1018
+ if (startDot === -1 ||
1019
+ end === -1 ||
1020
+ // We saw a non-dot character immediately before the dot
1021
+ preDotState === 0 ||
1022
+ // The (right-most) trimmed path component is exactly '..'
1023
+ (preDotState === 1 &&
1024
+ startDot === end - 1 &&
1025
+ startDot === startPart + 1)) {
1026
+ return '';
1027
+ }
1028
+ return StringPrototypeSlice(path, startDot, end);
1029
+ },
1030
+
1031
+ format: FunctionPrototypeBind(_format, null, '\\'),
1032
+
1033
+ /**
1034
+ * @param {string} path
1035
+ * @returns {{
1036
+ * dir: string;
1037
+ * root: string;
1038
+ * base: string;
1039
+ * name: string;
1040
+ * ext: string;
1041
+ * }}
1042
+ */
1043
+ parse(path) {
1044
+ validateString(path, 'path');
1045
+
1046
+ const ret = { root: '', dir: '', base: '', ext: '', name: '' };
1047
+ if (path.length === 0)
1048
+ return ret;
1049
+
1050
+ const len = path.length;
1051
+ let rootEnd = 0;
1052
+ let code = StringPrototypeCharCodeAt(path, 0);
1053
+
1054
+ if (len === 1) {
1055
+ if (isPathSeparator(code)) {
1056
+ // `path` contains just a path separator, exit early to avoid
1057
+ // unnecessary work
1058
+ ret.root = ret.dir = path;
1059
+ return ret;
1060
+ }
1061
+ ret.base = ret.name = path;
1062
+ return ret;
1063
+ }
1064
+ // Try to match a root
1065
+ if (isPathSeparator(code)) {
1066
+ // Possible UNC root
1067
+
1068
+ rootEnd = 1;
1069
+ if (isPathSeparator(StringPrototypeCharCodeAt(path, 1))) {
1070
+ // Matched double path separator at beginning
1071
+ let j = 2;
1072
+ let last = j;
1073
+ // Match 1 or more non-path separators
1074
+ while (j < len &&
1075
+ !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
1076
+ j++;
1077
+ }
1078
+ if (j < len && j !== last) {
1079
+ // Matched!
1080
+ last = j;
1081
+ // Match 1 or more path separators
1082
+ while (j < len &&
1083
+ isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
1084
+ j++;
1085
+ }
1086
+ if (j < len && j !== last) {
1087
+ // Matched!
1088
+ last = j;
1089
+ // Match 1 or more non-path separators
1090
+ while (j < len &&
1091
+ !isPathSeparator(StringPrototypeCharCodeAt(path, j))) {
1092
+ j++;
1093
+ }
1094
+ if (j === len) {
1095
+ // We matched a UNC root only
1096
+ rootEnd = j;
1097
+ } else if (j !== last) {
1098
+ // We matched a UNC root with leftovers
1099
+ rootEnd = j + 1;
1100
+ }
1101
+ }
1102
+ }
1103
+ }
1104
+ } else if (isWindowsDeviceRoot(code) &&
1105
+ StringPrototypeCharCodeAt(path, 1) === CHAR_COLON) {
1106
+ // Possible device root
1107
+ if (len <= 2) {
1108
+ // `path` contains just a drive root, exit early to avoid
1109
+ // unnecessary work
1110
+ ret.root = ret.dir = path;
1111
+ return ret;
1112
+ }
1113
+ rootEnd = 2;
1114
+ if (isPathSeparator(StringPrototypeCharCodeAt(path, 2))) {
1115
+ if (len === 3) {
1116
+ // `path` contains just a drive root, exit early to avoid
1117
+ // unnecessary work
1118
+ ret.root = ret.dir = path;
1119
+ return ret;
1120
+ }
1121
+ rootEnd = 3;
1122
+ }
1123
+ }
1124
+ if (rootEnd > 0)
1125
+ ret.root = StringPrototypeSlice(path, 0, rootEnd);
1126
+
1127
+ let startDot = -1;
1128
+ let startPart = rootEnd;
1129
+ let end = -1;
1130
+ let matchedSlash = true;
1131
+ let i = path.length - 1;
1132
+
1133
+ // Track the state of characters (if any) we see before our first dot and
1134
+ // after any path separator we find
1135
+ let preDotState = 0;
1136
+
1137
+ // Get non-dir info
1138
+ for (; i >= rootEnd; --i) {
1139
+ code = StringPrototypeCharCodeAt(path, i);
1140
+ if (isPathSeparator(code)) {
1141
+ // If we reached a path separator that was not part of a set of path
1142
+ // separators at the end of the string, stop now
1143
+ if (!matchedSlash) {
1144
+ startPart = i + 1;
1145
+ break;
1146
+ }
1147
+ continue;
1148
+ }
1149
+ if (end === -1) {
1150
+ // We saw the first non-path separator, mark this as the end of our
1151
+ // extension
1152
+ matchedSlash = false;
1153
+ end = i + 1;
1154
+ }
1155
+ if (code === CHAR_DOT) {
1156
+ // If this is our first dot, mark it as the start of our extension
1157
+ if (startDot === -1)
1158
+ startDot = i;
1159
+ else if (preDotState !== 1)
1160
+ preDotState = 1;
1161
+ } else if (startDot !== -1) {
1162
+ // We saw a non-dot and non-path separator before our dot, so we should
1163
+ // have a good chance at having a non-empty extension
1164
+ preDotState = -1;
1165
+ }
1166
+ }
1167
+
1168
+ if (end !== -1) {
1169
+ if (startDot === -1 ||
1170
+ // We saw a non-dot character immediately before the dot
1171
+ preDotState === 0 ||
1172
+ // The (right-most) trimmed path component is exactly '..'
1173
+ (preDotState === 1 &&
1174
+ startDot === end - 1 &&
1175
+ startDot === startPart + 1)) {
1176
+ ret.base = ret.name = StringPrototypeSlice(path, startPart, end);
1177
+ } else {
1178
+ ret.name = StringPrototypeSlice(path, startPart, startDot);
1179
+ ret.base = StringPrototypeSlice(path, startPart, end);
1180
+ ret.ext = StringPrototypeSlice(path, startDot, end);
1181
+ }
1182
+ }
1183
+
1184
+ // If the directory is the root, use the entire root as the `dir` including
1185
+ // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
1186
+ // trailing slash (`C:\abc\def` -> `C:\abc`).
1187
+ if (startPart > 0 && startPart !== rootEnd)
1188
+ ret.dir = StringPrototypeSlice(path, 0, startPart - 1);
1189
+ else
1190
+ ret.dir = ret.root;
1191
+
1192
+ return ret;
1193
+ },
1194
+
1195
+ matchesGlob(path, pattern) {
1196
+ return glob(path, pattern, true);
1197
+ },
1198
+
1199
+ sep: '\\',
1200
+ delimiter: ';',
1201
+ win32: null,
1202
+ posix: null,
1203
+ };
1204
+
1205
+ const posixCwd = (() => {
1206
+ if (isWindows) {
1207
+ // Converts Windows' backslash path separators to POSIX forward slashes
1208
+ // and truncates any drive indicator
1209
+ const regexp = /\\/g;
1210
+ return () => {
1211
+ const cwd = StringPrototypeReplace(process.cwd(), regexp, '/');
1212
+ return StringPrototypeSlice(cwd, StringPrototypeIndexOf(cwd, '/'));
1213
+ };
1214
+ }
1215
+
1216
+ // We're already on POSIX, no need for any transformations
1217
+ return () => process.cwd();
1218
+ })();
1219
+
1220
+ const posix = {
1221
+ /**
1222
+ * path.resolve([from ...], to)
1223
+ * @param {...string} args
1224
+ * @returns {string}
1225
+ */
1226
+ resolve(...args) {
1227
+ if (args.length === 0 || (args.length === 1 && (args[0] === '' || args[0] === '.'))) {
1228
+ const cwd = posixCwd();
1229
+ if (StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH) {
1230
+ return cwd;
1231
+ }
1232
+ }
1233
+ let resolvedPath = '';
1234
+ let resolvedAbsolute = false;
1235
+
1236
+ for (let i = args.length - 1; i >= 0 && !resolvedAbsolute; i--) {
1237
+ const path = args[i];
1238
+ validateString(path, `paths[${i}]`);
1239
+
1240
+ // Skip empty entries
1241
+ if (path.length === 0) {
1242
+ continue;
1243
+ }
1244
+
1245
+ resolvedPath = `${path}/${resolvedPath}`;
1246
+ resolvedAbsolute =
1247
+ StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1248
+ }
1249
+
1250
+ if (!resolvedAbsolute) {
1251
+ const cwd = posixCwd();
1252
+ resolvedPath = `${cwd}/${resolvedPath}`;
1253
+ resolvedAbsolute =
1254
+ StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH;
1255
+ }
1256
+
1257
+ // At this point the path should be resolved to a full absolute path, but
1258
+ // handle relative paths to be safe (might happen when process.cwd() fails)
1259
+
1260
+ // Normalize the path
1261
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/',
1262
+ isPosixPathSeparator);
1263
+
1264
+ if (resolvedAbsolute) {
1265
+ return `/${resolvedPath}`;
1266
+ }
1267
+ return resolvedPath.length > 0 ? resolvedPath : '.';
1268
+ },
1269
+
1270
+ /**
1271
+ * @param {string} path
1272
+ * @returns {string}
1273
+ */
1274
+ normalize(path) {
1275
+ validateString(path, 'path');
1276
+
1277
+ if (path.length === 0)
1278
+ return '.';
1279
+
1280
+ const isAbsolute =
1281
+ StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1282
+ const trailingSeparator =
1283
+ StringPrototypeCharCodeAt(path, path.length - 1) === CHAR_FORWARD_SLASH;
1284
+
1285
+ // Normalize the path
1286
+ path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);
1287
+
1288
+ if (path.length === 0) {
1289
+ if (isAbsolute)
1290
+ return '/';
1291
+ return trailingSeparator ? './' : '.';
1292
+ }
1293
+ if (trailingSeparator)
1294
+ path += '/';
1295
+
1296
+ return isAbsolute ? `/${path}` : path;
1297
+ },
1298
+
1299
+ /**
1300
+ * @param {string} path
1301
+ * @returns {boolean}
1302
+ */
1303
+ isAbsolute(path) {
1304
+ validateString(path, 'path');
1305
+ return path.length > 0 &&
1306
+ StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1307
+ },
1308
+
1309
+ /**
1310
+ * @param {...string} args
1311
+ * @returns {string}
1312
+ */
1313
+ join(...args) {
1314
+ if (args.length === 0)
1315
+ return '.';
1316
+
1317
+ const path = [];
1318
+ for (let i = 0; i < args.length; ++i) {
1319
+ const arg = args[i];
1320
+ validateString(arg, 'path');
1321
+ if (arg.length > 0) {
1322
+ path.push(arg);
1323
+ }
1324
+ }
1325
+
1326
+ if (path.length === 0)
1327
+ return '.';
1328
+
1329
+ return posix.normalize(ArrayPrototypeJoin(path, '/'));
1330
+ },
1331
+
1332
+ /**
1333
+ * @param {string} from
1334
+ * @param {string} to
1335
+ * @returns {string}
1336
+ */
1337
+ relative(from, to) {
1338
+ validateString(from, 'from');
1339
+ validateString(to, 'to');
1340
+
1341
+ if (from === to)
1342
+ return '';
1343
+
1344
+ // Trim leading forward slashes.
1345
+ from = posix.resolve(from);
1346
+ to = posix.resolve(to);
1347
+
1348
+ if (from === to)
1349
+ return '';
1350
+
1351
+ const fromStart = 1;
1352
+ const fromEnd = from.length;
1353
+ const fromLen = fromEnd - fromStart;
1354
+ const toStart = 1;
1355
+ const toLen = to.length - toStart;
1356
+
1357
+ // Compare paths to find the longest common path from root
1358
+ const length = (fromLen < toLen ? fromLen : toLen);
1359
+ let lastCommonSep = -1;
1360
+ let i = 0;
1361
+ for (; i < length; i++) {
1362
+ const fromCode = StringPrototypeCharCodeAt(from, fromStart + i);
1363
+ if (fromCode !== StringPrototypeCharCodeAt(to, toStart + i))
1364
+ break;
1365
+ else if (fromCode === CHAR_FORWARD_SLASH)
1366
+ lastCommonSep = i;
1367
+ }
1368
+ if (i === length) {
1369
+ if (toLen > length) {
1370
+ if (StringPrototypeCharCodeAt(to, toStart + i) === CHAR_FORWARD_SLASH) {
1371
+ // We get here if `from` is the exact base path for `to`.
1372
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
1373
+ return StringPrototypeSlice(to, toStart + i + 1);
1374
+ }
1375
+ if (i === 0) {
1376
+ // We get here if `from` is the root
1377
+ // For example: from='/'; to='/foo'
1378
+ return StringPrototypeSlice(to, toStart + i);
1379
+ }
1380
+ } else if (fromLen > length) {
1381
+ if (StringPrototypeCharCodeAt(from, fromStart + i) ===
1382
+ CHAR_FORWARD_SLASH) {
1383
+ // We get here if `to` is the exact base path for `from`.
1384
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
1385
+ lastCommonSep = i;
1386
+ } else if (i === 0) {
1387
+ // We get here if `to` is the root.
1388
+ // For example: from='/foo/bar'; to='/'
1389
+ lastCommonSep = 0;
1390
+ }
1391
+ }
1392
+ }
1393
+
1394
+ let out = '';
1395
+ // Generate the relative path based on the path difference between `to`
1396
+ // and `from`.
1397
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1398
+ if (i === fromEnd ||
1399
+ StringPrototypeCharCodeAt(from, i) === CHAR_FORWARD_SLASH) {
1400
+ out += out.length === 0 ? '..' : '/..';
1401
+ }
1402
+ }
1403
+
1404
+ // Lastly, append the rest of the destination (`to`) path that comes after
1405
+ // the common path parts.
1406
+ return `${out}${StringPrototypeSlice(to, toStart + lastCommonSep)}`;
1407
+ },
1408
+
1409
+ /**
1410
+ * @param {string} path
1411
+ * @returns {string}
1412
+ */
1413
+ toNamespacedPath(path) {
1414
+ // Non-op on posix systems
1415
+ return path;
1416
+ },
1417
+
1418
+ /**
1419
+ * @param {string} path
1420
+ * @returns {string}
1421
+ */
1422
+ dirname(path) {
1423
+ validateString(path, 'path');
1424
+ if (path.length === 0)
1425
+ return '.';
1426
+ const hasRoot = StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1427
+ let end = -1;
1428
+ let matchedSlash = true;
1429
+ for (let i = path.length - 1; i >= 1; --i) {
1430
+ if (StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH) {
1431
+ if (!matchedSlash) {
1432
+ end = i;
1433
+ break;
1434
+ }
1435
+ } else {
1436
+ // We saw the first non-path separator
1437
+ matchedSlash = false;
1438
+ }
1439
+ }
1440
+
1441
+ if (end === -1)
1442
+ return hasRoot ? '/' : '.';
1443
+ if (hasRoot && end === 1)
1444
+ return '//';
1445
+ return StringPrototypeSlice(path, 0, end);
1446
+ },
1447
+
1448
+ /**
1449
+ * @param {string} path
1450
+ * @param {string} [suffix]
1451
+ * @returns {string}
1452
+ */
1453
+ basename(path, suffix) {
1454
+ if (suffix !== undefined)
1455
+ validateString(suffix, 'suffix');
1456
+ validateString(path, 'path');
1457
+
1458
+ let start = 0;
1459
+ let end = -1;
1460
+ let matchedSlash = true;
1461
+
1462
+ if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
1463
+ if (suffix === path)
1464
+ return '';
1465
+ let extIdx = suffix.length - 1;
1466
+ let firstNonSlashEnd = -1;
1467
+ for (let i = path.length - 1; i >= 0; --i) {
1468
+ const code = StringPrototypeCharCodeAt(path, i);
1469
+ if (code === CHAR_FORWARD_SLASH) {
1470
+ // If we reached a path separator that was not part of a set of path
1471
+ // separators at the end of the string, stop now
1472
+ if (!matchedSlash) {
1473
+ start = i + 1;
1474
+ break;
1475
+ }
1476
+ } else {
1477
+ if (firstNonSlashEnd === -1) {
1478
+ // We saw the first non-path separator, remember this index in case
1479
+ // we need it if the extension ends up not matching
1480
+ matchedSlash = false;
1481
+ firstNonSlashEnd = i + 1;
1482
+ }
1483
+ if (extIdx >= 0) {
1484
+ // Try to match the explicit extension
1485
+ if (code === StringPrototypeCharCodeAt(suffix, extIdx)) {
1486
+ if (--extIdx === -1) {
1487
+ // We matched the extension, so mark this as the end of our path
1488
+ // component
1489
+ end = i;
1490
+ }
1491
+ } else {
1492
+ // Extension does not match, so our result is the entire path
1493
+ // component
1494
+ extIdx = -1;
1495
+ end = firstNonSlashEnd;
1496
+ }
1497
+ }
1498
+ }
1499
+ }
1500
+
1501
+ if (start === end)
1502
+ end = firstNonSlashEnd;
1503
+ else if (end === -1)
1504
+ end = path.length;
1505
+ return StringPrototypeSlice(path, start, end);
1506
+ }
1507
+ for (let i = path.length - 1; i >= 0; --i) {
1508
+ if (StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH) {
1509
+ // If we reached a path separator that was not part of a set of path
1510
+ // separators at the end of the string, stop now
1511
+ if (!matchedSlash) {
1512
+ start = i + 1;
1513
+ break;
1514
+ }
1515
+ } else if (end === -1) {
1516
+ // We saw the first non-path separator, mark this as the end of our
1517
+ // path component
1518
+ matchedSlash = false;
1519
+ end = i + 1;
1520
+ }
1521
+ }
1522
+
1523
+ if (end === -1)
1524
+ return '';
1525
+ return StringPrototypeSlice(path, start, end);
1526
+ },
1527
+
1528
+ /**
1529
+ * @param {string} path
1530
+ * @returns {string}
1531
+ */
1532
+ extname(path) {
1533
+ validateString(path, 'path');
1534
+ let startDot = -1;
1535
+ let startPart = 0;
1536
+ let end = -1;
1537
+ let matchedSlash = true;
1538
+ // Track the state of characters (if any) we see before our first dot and
1539
+ // after any path separator we find
1540
+ let preDotState = 0;
1541
+ for (let i = path.length - 1; i >= 0; --i) {
1542
+ const char = path[i];
1543
+ if (char === '/') {
1544
+ // If we reached a path separator that was not part of a set of path
1545
+ // separators at the end of the string, stop now
1546
+ if (!matchedSlash) {
1547
+ startPart = i + 1;
1548
+ break;
1549
+ }
1550
+ continue;
1551
+ }
1552
+ if (end === -1) {
1553
+ // We saw the first non-path separator, mark this as the end of our
1554
+ // extension
1555
+ matchedSlash = false;
1556
+ end = i + 1;
1557
+ }
1558
+ if (char === '.') {
1559
+ // If this is our first dot, mark it as the start of our extension
1560
+ if (startDot === -1)
1561
+ startDot = i;
1562
+ else if (preDotState !== 1)
1563
+ preDotState = 1;
1564
+ } else if (startDot !== -1) {
1565
+ // We saw a non-dot and non-path separator before our dot, so we should
1566
+ // have a good chance at having a non-empty extension
1567
+ preDotState = -1;
1568
+ }
1569
+ }
1570
+
1571
+ if (startDot === -1 ||
1572
+ end === -1 ||
1573
+ // We saw a non-dot character immediately before the dot
1574
+ preDotState === 0 ||
1575
+ // The (right-most) trimmed path component is exactly '..'
1576
+ (preDotState === 1 &&
1577
+ startDot === end - 1 &&
1578
+ startDot === startPart + 1)) {
1579
+ return '';
1580
+ }
1581
+ return StringPrototypeSlice(path, startDot, end);
1582
+ },
1583
+
1584
+ format: FunctionPrototypeBind(_format, null, '/'),
1585
+
1586
+ /**
1587
+ * @param {string} path
1588
+ * @returns {{
1589
+ * dir: string;
1590
+ * root: string;
1591
+ * base: string;
1592
+ * name: string;
1593
+ * ext: string;
1594
+ * }}
1595
+ */
1596
+ parse(path) {
1597
+ validateString(path, 'path');
1598
+
1599
+ const ret = { root: '', dir: '', base: '', ext: '', name: '' };
1600
+ if (path.length === 0)
1601
+ return ret;
1602
+ const isAbsolute =
1603
+ StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
1604
+ let start;
1605
+ if (isAbsolute) {
1606
+ ret.root = '/';
1607
+ start = 1;
1608
+ } else {
1609
+ start = 0;
1610
+ }
1611
+ let startDot = -1;
1612
+ let startPart = 0;
1613
+ let end = -1;
1614
+ let matchedSlash = true;
1615
+ let i = path.length - 1;
1616
+
1617
+ // Track the state of characters (if any) we see before our first dot and
1618
+ // after any path separator we find
1619
+ let preDotState = 0;
1620
+
1621
+ // Get non-dir info
1622
+ for (; i >= start; --i) {
1623
+ const code = StringPrototypeCharCodeAt(path, i);
1624
+ if (code === CHAR_FORWARD_SLASH) {
1625
+ // If we reached a path separator that was not part of a set of path
1626
+ // separators at the end of the string, stop now
1627
+ if (!matchedSlash) {
1628
+ startPart = i + 1;
1629
+ break;
1630
+ }
1631
+ continue;
1632
+ }
1633
+ if (end === -1) {
1634
+ // We saw the first non-path separator, mark this as the end of our
1635
+ // extension
1636
+ matchedSlash = false;
1637
+ end = i + 1;
1638
+ }
1639
+ if (code === CHAR_DOT) {
1640
+ // If this is our first dot, mark it as the start of our extension
1641
+ if (startDot === -1)
1642
+ startDot = i;
1643
+ else if (preDotState !== 1)
1644
+ preDotState = 1;
1645
+ } else if (startDot !== -1) {
1646
+ // We saw a non-dot and non-path separator before our dot, so we should
1647
+ // have a good chance at having a non-empty extension
1648
+ preDotState = -1;
1649
+ }
1650
+ }
1651
+
1652
+ if (end !== -1) {
1653
+ const start = startPart === 0 && isAbsolute ? 1 : startPart;
1654
+ if (startDot === -1 ||
1655
+ // We saw a non-dot character immediately before the dot
1656
+ preDotState === 0 ||
1657
+ // The (right-most) trimmed path component is exactly '..'
1658
+ (preDotState === 1 &&
1659
+ startDot === end - 1 &&
1660
+ startDot === startPart + 1)) {
1661
+ ret.base = ret.name = StringPrototypeSlice(path, start, end);
1662
+ } else {
1663
+ ret.name = StringPrototypeSlice(path, start, startDot);
1664
+ ret.base = StringPrototypeSlice(path, start, end);
1665
+ ret.ext = StringPrototypeSlice(path, startDot, end);
1666
+ }
1667
+ }
1668
+
1669
+ if (startPart > 0)
1670
+ ret.dir = StringPrototypeSlice(path, 0, startPart - 1);
1671
+ else if (isAbsolute)
1672
+ ret.dir = '/';
1673
+
1674
+ return ret;
1675
+ },
1676
+
1677
+ matchesGlob(path, pattern) {
1678
+ return glob(path, pattern, false);
1679
+ },
1680
+
1681
+ sep: '/',
1682
+ delimiter: ':',
1683
+ win32: null,
1684
+ posix: null,
1685
+ };
1686
+
1687
+ posix.win32 = win32.win32 = win32;
1688
+ posix.posix = win32.posix = posix;
1689
+
1690
+ // Legacy internal API, docs-only deprecated: DEP0080
1691
+ win32._makeLong = win32.toNamespacedPath;
1692
+ posix._makeLong = posix.toNamespacedPath;
1693
+
1694
+ module.exports = isWindows ? win32 : posix;