cf-workers-native 0.0.0-stage → 0.1.2-beta.local.sha2f5e4e6956f4

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 (629) hide show
  1. package/LICENSE +21 -0
  2. package/Package.swift +25 -0
  3. package/README.md +92 -2
  4. package/dist/android.d.ts +2 -0
  5. package/dist/android.js +1 -0
  6. package/dist/browser/abort/index.d.ts +13 -0
  7. package/dist/browser/abort/index.js +66 -0
  8. package/dist/browser/body/index.d.ts +24 -0
  9. package/dist/browser/body/index.js +116 -0
  10. package/dist/browser/body/stream-body.d.ts +13 -0
  11. package/dist/browser/body/stream-body.js +84 -0
  12. package/dist/browser/documents/body.d.ts +3 -0
  13. package/dist/browser/documents/body.js +48 -0
  14. package/dist/browser/documents/form-body.d.ts +1 -0
  15. package/dist/browser/documents/form-body.js +54 -0
  16. package/dist/browser/documents/host.d.ts +11 -0
  17. package/dist/browser/documents/host.js +256 -0
  18. package/dist/browser/documents/links-source.d.ts +1 -0
  19. package/dist/browser/documents/links-source.js +1 -0
  20. package/dist/browser/documents/links.d.ts +1 -0
  21. package/dist/browser/documents/links.js +33 -0
  22. package/dist/browser/documents/page-config.d.ts +5 -0
  23. package/dist/browser/documents/page-config.js +5 -0
  24. package/dist/browser/documents/page-source.d.ts +1 -0
  25. package/dist/browser/documents/page-source.js +1 -0
  26. package/dist/browser/documents/page.d.ts +2 -0
  27. package/dist/browser/documents/page.js +153 -0
  28. package/dist/browser/documents/registration.d.ts +5 -0
  29. package/dist/browser/documents/registration.js +75 -0
  30. package/dist/browser/documents/runtime.d.ts +7 -0
  31. package/dist/browser/documents/runtime.js +161 -0
  32. package/dist/browser/documents/service-worker.js +285 -0
  33. package/dist/browser/encoding/index.d.ts +7 -0
  34. package/dist/browser/encoding/index.js +3 -0
  35. package/dist/browser/fetch/LICENSE-3RD-PARTY.md +9 -0
  36. package/dist/browser/fetch/LICENSE-APACHE +177 -0
  37. package/dist/browser/fetch/host-call.d.ts +3 -0
  38. package/dist/browser/fetch/host-call.js +67 -0
  39. package/dist/browser/fetch/index.d.ts +5 -0
  40. package/dist/browser/fetch/index.js +96 -0
  41. package/dist/browser/fetch/interop.d.ts +6 -0
  42. package/dist/browser/fetch/interop.js +48 -0
  43. package/dist/browser/fetch/native-network.d.ts +20 -0
  44. package/dist/browser/fetch/native-network.js +233 -0
  45. package/dist/browser/fetch/outbound.d.ts +2 -0
  46. package/dist/browser/fetch/outbound.js +11 -0
  47. package/dist/browser/fetch/relay.d.ts +7 -0
  48. package/dist/browser/fetch/relay.js +100 -0
  49. package/dist/browser/fetch/scope.d.ts +8 -0
  50. package/dist/browser/fetch/scope.js +108 -0
  51. package/dist/browser/fetch/transport.d.ts +39 -0
  52. package/dist/browser/fetch/transport.js +136 -0
  53. package/dist/browser/headers/LICENSE-3RD-PARTY.md +9 -0
  54. package/dist/browser/headers/LICENSE-APACHE +177 -0
  55. package/dist/browser/headers/index.d.ts +20 -0
  56. package/dist/browser/headers/index.js +194 -0
  57. package/dist/browser/isolated/bridge.d.ts +8 -0
  58. package/dist/browser/isolated/bridge.js +267 -0
  59. package/dist/browser/isolated/protocol.d.ts +40 -0
  60. package/dist/browser/isolated/protocol.js +1 -0
  61. package/dist/browser/isolated/transport.d.ts +2 -0
  62. package/dist/browser/isolated/transport.js +157 -0
  63. package/dist/browser/request/LICENSE-3RD-PARTY.md +10 -0
  64. package/dist/browser/request/LICENSE-APACHE +177 -0
  65. package/dist/browser/request/index.d.ts +48 -0
  66. package/dist/browser/request/index.js +182 -0
  67. package/dist/browser/response/LICENSE-3RD-PARTY.md +10 -0
  68. package/dist/browser/response/LICENSE-APACHE +177 -0
  69. package/dist/browser/response/index.d.ts +43 -0
  70. package/dist/browser/response/index.js +192 -0
  71. package/dist/browser/response/status.d.ts +1 -0
  72. package/dist/browser/response/status.js +75 -0
  73. package/dist/browser/structured-clone/index.d.ts +1 -0
  74. package/dist/browser/structured-clone/index.js +479 -0
  75. package/dist/cloudflare/apis/cloudflare-node/index.d.ts +18 -0
  76. package/dist/cloudflare/apis/cloudflare-node/index.js +150 -0
  77. package/dist/cloudflare/apis/cloudflare-workers/index.d.ts +8 -0
  78. package/dist/cloudflare/apis/cloudflare-workers/index.js +37 -0
  79. package/dist/cloudflare/apis/types.d.ts +7 -0
  80. package/dist/cloudflare/apis/types.js +1 -0
  81. package/dist/cloudflare/bindings/config.d.ts +42 -0
  82. package/dist/cloudflare/bindings/config.js +280 -0
  83. package/dist/cloudflare/bindings/kv/contract.d.ts +6 -0
  84. package/dist/cloudflare/bindings/kv/contract.js +181 -0
  85. package/dist/cloudflare/bindings/kv/index.d.ts +18 -0
  86. package/dist/cloudflare/bindings/kv/index.js +61 -0
  87. package/dist/cloudflare/bindings/kv/storage.d.ts +25 -0
  88. package/dist/cloudflare/bindings/kv/storage.js +320 -0
  89. package/dist/cloudflare/bindings/kv/types.d.ts +50 -0
  90. package/dist/cloudflare/bindings/kv/types.js +1 -0
  91. package/dist/cloudflare/bindings/remote.d.ts +8 -0
  92. package/dist/cloudflare/bindings/remote.js +261 -0
  93. package/dist/cloudflare/workers/contract.d.ts +8 -0
  94. package/dist/cloudflare/workers/contract.js +65 -0
  95. package/dist/cloudflare/workers/feature.d.ts +10 -0
  96. package/dist/cloudflare/workers/feature.js +28 -0
  97. package/dist/cloudflare/workers/runtime.d.ts +23 -0
  98. package/dist/cloudflare/workers/runtime.js +121 -0
  99. package/dist/cloudflare/workers/types.d.ts +49 -0
  100. package/dist/cloudflare/workers/types.js +1 -0
  101. package/dist/cloudflare/workers/worker-runtime.d.ts +44 -0
  102. package/dist/cloudflare/workers/worker-runtime.js +267 -0
  103. package/dist/compat/assert/LICENSE-3RD-PARTY.md +5 -0
  104. package/dist/compat/assert/LICENSE-APACHE +177 -0
  105. package/dist/compat/assert/assertion-error.d.ts +26 -0
  106. package/dist/compat/assert/assertion-error.js +468 -0
  107. package/dist/compat/assert/diff.d.ts +26 -0
  108. package/dist/compat/assert/diff.js +329 -0
  109. package/dist/compat/assert/errors.d.ts +11 -0
  110. package/dist/compat/assert/errors.js +55 -0
  111. package/dist/compat/assert/index.cjs +24 -0
  112. package/dist/compat/assert/index.d.cts +43 -0
  113. package/dist/compat/assert/index.d.ts +50 -0
  114. package/dist/compat/assert/index.js +858 -0
  115. package/dist/compat/async-hooks/LICENSE-APACHE +177 -0
  116. package/dist/compat/async-hooks/NOTICE.md +8 -0
  117. package/dist/compat/async-hooks/callbacks.d.ts +7 -0
  118. package/dist/compat/async-hooks/callbacks.js +18 -0
  119. package/dist/compat/async-hooks/hooks.d.ts +10 -0
  120. package/dist/compat/async-hooks/hooks.js +111 -0
  121. package/dist/compat/async-hooks/index.d.ts +41 -0
  122. package/dist/compat/async-hooks/index.js +298 -0
  123. package/dist/compat/buffer/LICENSE-3RD-PARTY.md +15 -0
  124. package/dist/compat/buffer/LICENSE-APACHE +177 -0
  125. package/dist/compat/buffer/blob.d.ts +22 -0
  126. package/dist/compat/buffer/blob.js +210 -0
  127. package/dist/compat/buffer/bytes.d.ts +34 -0
  128. package/dist/compat/buffer/bytes.js +228 -0
  129. package/dist/compat/buffer/errors.d.ts +41 -0
  130. package/dist/compat/buffer/errors.js +265 -0
  131. package/dist/compat/buffer/index.d.ts +25 -0
  132. package/dist/compat/buffer/index.js +24 -0
  133. package/dist/compat/buffer/internal-buffer.d.ts +148 -0
  134. package/dist/compat/buffer/internal-buffer.js +1809 -0
  135. package/dist/compat/buffer/support.d.ts +13 -0
  136. package/dist/compat/buffer/support.js +65 -0
  137. package/dist/compat/child-process/LICENSE-3RD-PARTY.md +8 -0
  138. package/dist/compat/child-process/LICENSE-APACHE +177 -0
  139. package/dist/compat/child-process/errors.d.ts +4 -0
  140. package/dist/compat/child-process/errors.js +6 -0
  141. package/dist/compat/child-process/index.d.ts +49 -0
  142. package/dist/compat/child-process/index.js +96 -0
  143. package/dist/compat/cluster/LICENSE-3RD-PARTY.md +40 -0
  144. package/dist/compat/cluster/LICENSE-APACHE +177 -0
  145. package/dist/compat/cluster/errors.d.ts +4 -0
  146. package/dist/compat/cluster/errors.js +6 -0
  147. package/dist/compat/cluster/index.d.ts +47 -0
  148. package/dist/compat/cluster/index.js +88 -0
  149. package/dist/compat/constants/LICENSE-3RD-PARTY.md +6 -0
  150. package/dist/compat/constants/LICENSE-APACHE +177 -0
  151. package/dist/compat/constants/index.d.ts +481 -0
  152. package/dist/compat/constants/index.js +488 -0
  153. package/dist/compat/dgram/LICENSE-3RD-PARTY.md +8 -0
  154. package/dist/compat/dgram/LICENSE-APACHE +177 -0
  155. package/dist/compat/dgram/index.d.ts +10 -0
  156. package/dist/compat/dgram/index.js +132 -0
  157. package/dist/compat/diagnostics-channel/LICENSE-3RD-PARTY.md +13 -0
  158. package/dist/compat/diagnostics-channel/LICENSE-APACHE +177 -0
  159. package/dist/compat/diagnostics-channel/index.d.ts +73 -0
  160. package/dist/compat/diagnostics-channel/index.js +261 -0
  161. package/dist/compat/diagnostics-channel/native.d.ts +26 -0
  162. package/dist/compat/diagnostics-channel/native.js +154 -0
  163. package/dist/compat/dns/LICENSE-3RD-PARTY.md +5 -0
  164. package/dist/compat/dns/LICENSE-APACHE +177 -0
  165. package/dist/compat/dns/client.d.ts +72 -0
  166. package/dist/compat/dns/client.js +161 -0
  167. package/dist/compat/dns/constants.d.ts +27 -0
  168. package/dist/compat/dns/constants.js +31 -0
  169. package/dist/compat/dns/errors.d.ts +8 -0
  170. package/dist/compat/dns/errors.js +12 -0
  171. package/dist/compat/dns/index.d.ts +97 -0
  172. package/dist/compat/dns/index.js +127 -0
  173. package/dist/compat/dns/parser.d.ts +18 -0
  174. package/dist/compat/dns/parser.js +144 -0
  175. package/dist/compat/dns/promise-resolver.d.ts +82 -0
  176. package/dist/compat/dns/promise-resolver.js +113 -0
  177. package/dist/compat/dns/promises.d.ts +50 -0
  178. package/dist/compat/dns/promises.js +53 -0
  179. package/dist/compat/dns/resolver.d.ts +34 -0
  180. package/dist/compat/dns/resolver.js +415 -0
  181. package/dist/compat/domain/LICENSE-3RD-PARTY.md +5 -0
  182. package/dist/compat/domain/LICENSE-APACHE +177 -0
  183. package/dist/compat/domain/index.d.ts +22 -0
  184. package/dist/compat/domain/index.js +79 -0
  185. package/dist/compat/fs/index.d.ts +85 -0
  186. package/dist/compat/fs/index.js +255 -0
  187. package/dist/compat/fs/promises/index.d.ts +3 -0
  188. package/dist/compat/fs/promises/index.js +3 -0
  189. package/dist/compat/http/index.d.ts +322 -0
  190. package/dist/compat/http/index.js +1356 -0
  191. package/dist/compat/http/registry.d.ts +19 -0
  192. package/dist/compat/http/registry.js +13 -0
  193. package/dist/compat/http-agent/LICENSE-3RD-PARTY.md +5 -0
  194. package/dist/compat/http-agent/LICENSE-APACHE +177 -0
  195. package/dist/compat/http-agent/index.d.ts +7 -0
  196. package/dist/compat/http-agent/index.js +10 -0
  197. package/dist/compat/http-client/LICENSE-3RD-PARTY.md +5 -0
  198. package/dist/compat/http-client/LICENSE-APACHE +177 -0
  199. package/dist/compat/http-client/index.d.ts +6 -0
  200. package/dist/compat/http-client/index.js +7 -0
  201. package/dist/compat/http-incoming/LICENSE-3RD-PARTY.md +5 -0
  202. package/dist/compat/http-incoming/LICENSE-APACHE +177 -0
  203. package/dist/compat/http-incoming/index.d.ts +6 -0
  204. package/dist/compat/http-incoming/index.js +9 -0
  205. package/dist/compat/http2/LICENSE-3RD-PARTY.md +29 -0
  206. package/dist/compat/http2/LICENSE-APACHE +177 -0
  207. package/dist/compat/http2/constants.d.ts +255 -0
  208. package/dist/compat/http2/constants.js +515 -0
  209. package/dist/compat/http2/errors.d.ts +4 -0
  210. package/dist/compat/http2/errors.js +6 -0
  211. package/dist/compat/http2/index.d.ts +283 -0
  212. package/dist/compat/http2/index.js +68 -0
  213. package/dist/compat/https/LICENSE-3RD-PARTY.md +5 -0
  214. package/dist/compat/https/LICENSE-APACHE +177 -0
  215. package/dist/compat/https/agent.d.ts +10 -0
  216. package/dist/compat/https/agent.js +99 -0
  217. package/dist/compat/https/errors.d.ts +4 -0
  218. package/dist/compat/https/errors.js +6 -0
  219. package/dist/compat/https/index.d.ts +20 -0
  220. package/dist/compat/https/index.js +50 -0
  221. package/dist/compat/https/server.d.ts +8 -0
  222. package/dist/compat/https/server.js +27 -0
  223. package/dist/compat/immediate/index.d.ts +11 -0
  224. package/dist/compat/immediate/index.js +58 -0
  225. package/dist/compat/inspector/LICENSE-3RD-PARTY.md +34 -0
  226. package/dist/compat/inspector/LICENSE-APACHE +177 -0
  227. package/dist/compat/inspector/errors.d.ts +4 -0
  228. package/dist/compat/inspector/errors.js +6 -0
  229. package/dist/compat/inspector/index.d.ts +18 -0
  230. package/dist/compat/inspector/index.js +117 -0
  231. package/dist/compat/inspector/promises.d.ts +18 -0
  232. package/dist/compat/inspector/promises.js +114 -0
  233. package/dist/compat/module/index.cjs +2 -0
  234. package/dist/compat/module/index.d.cts +2 -0
  235. package/dist/compat/module/index.d.ts +11 -0
  236. package/dist/compat/module/index.js +44 -0
  237. package/dist/compat/module/resolve-unavailable.d.ts +1 -0
  238. package/dist/compat/module/resolve-unavailable.js +3 -0
  239. package/dist/compat/net/LICENSE-3RD-PARTY.md +15 -0
  240. package/dist/compat/net/LICENSE-APACHE +177 -0
  241. package/dist/compat/net/error-base.d.ts +14 -0
  242. package/dist/compat/net/error-base.js +62 -0
  243. package/dist/compat/net/errors.d.ts +76 -0
  244. package/dist/compat/net/errors.js +333 -0
  245. package/dist/compat/net/index.d.ts +23 -0
  246. package/dist/compat/net/index.js +46 -0
  247. package/dist/compat/net/internal-net.d.ts +236 -0
  248. package/dist/compat/net/internal-net.js +2292 -0
  249. package/dist/compat/net/ports.d.ts +32 -0
  250. package/dist/compat/net/ports.js +149 -0
  251. package/dist/compat/net/reader.d.ts +8 -0
  252. package/dist/compat/net/reader.js +36 -0
  253. package/dist/compat/net/sockets.d.ts +20 -0
  254. package/dist/compat/net/sockets.js +195 -0
  255. package/dist/compat/net/validators.d.ts +18 -0
  256. package/dist/compat/net/validators.js +154 -0
  257. package/dist/compat/os/LICENSE-3RD-PARTY.md +8 -0
  258. package/dist/compat/os/LICENSE-APACHE +177 -0
  259. package/dist/compat/os/index.d.ts +329 -0
  260. package/dist/compat/os/index.js +278 -0
  261. package/dist/compat/path/LICENSE-3RD-PARTY.md +35 -0
  262. package/dist/compat/path/LICENSE-APACHE +177 -0
  263. package/dist/compat/path/index.d.ts +4 -0
  264. package/dist/compat/path/index.js +11 -0
  265. package/dist/compat/path/internal-path.d.ts +95 -0
  266. package/dist/compat/path/internal-path.js +1542 -0
  267. package/dist/compat/path/posix/index.d.ts +4 -0
  268. package/dist/compat/path/posix/index.js +5 -0
  269. package/dist/compat/path/win32/index.d.ts +4 -0
  270. package/dist/compat/path/win32/index.js +5 -0
  271. package/dist/compat/perf-hooks/LICENSE-3RD-PARTY.md +5 -0
  272. package/dist/compat/perf-hooks/LICENSE-APACHE +177 -0
  273. package/dist/compat/perf-hooks/index.d.ts +85 -0
  274. package/dist/compat/perf-hooks/index.js +79 -0
  275. package/dist/compat/perf-hooks/performance.d.ts +96 -0
  276. package/dist/compat/perf-hooks/performance.js +445 -0
  277. package/dist/compat/punycode/LICENSE-3RD-PARTY.md +7 -0
  278. package/dist/compat/punycode/LICENSE-APACHE +177 -0
  279. package/dist/compat/punycode/index.d.ts +93 -0
  280. package/dist/compat/punycode/index.js +410 -0
  281. package/dist/compat/querystring/LICENSE-3RD-PARTY.md +35 -0
  282. package/dist/compat/querystring/LICENSE-APACHE +177 -0
  283. package/dist/compat/querystring/index.d.ts +14 -0
  284. package/dist/compat/querystring/index.js +18 -0
  285. package/dist/compat/querystring/internal-querystring.d.ts +22 -0
  286. package/dist/compat/querystring/internal-querystring.js +498 -0
  287. package/dist/compat/readline/LICENSE-3RD-PARTY.md +37 -0
  288. package/dist/compat/readline/LICENSE-APACHE +177 -0
  289. package/dist/compat/readline/index.d.ts +21 -0
  290. package/dist/compat/readline/index.js +56 -0
  291. package/dist/compat/readline/interface.d.ts +22 -0
  292. package/dist/compat/readline/interface.js +85 -0
  293. package/dist/compat/readline/internal-promises.d.ts +32 -0
  294. package/dist/compat/readline/internal-promises.js +104 -0
  295. package/dist/compat/readline/promises.d.ts +8 -0
  296. package/dist/compat/readline/promises.js +32 -0
  297. package/dist/compat/repl/LICENSE-3RD-PARTY.md +5 -0
  298. package/dist/compat/repl/LICENSE-APACHE +177 -0
  299. package/dist/compat/repl/builtin-modules.d.ts +1 -0
  300. package/dist/compat/repl/builtin-modules.js +101 -0
  301. package/dist/compat/repl/errors.d.ts +4 -0
  302. package/dist/compat/repl/errors.js +6 -0
  303. package/dist/compat/repl/index.d.ts +53 -0
  304. package/dist/compat/repl/index.js +106 -0
  305. package/dist/compat/sqlite/LICENSE-3RD-PARTY.md +6 -0
  306. package/dist/compat/sqlite/LICENSE-APACHE +177 -0
  307. package/dist/compat/sqlite/index.d.ts +12 -0
  308. package/dist/compat/sqlite/index.js +101 -0
  309. package/dist/compat/sqlite/native.d.ts +16 -0
  310. package/dist/compat/sqlite/native.js +33 -0
  311. package/dist/compat/stream/LICENSE-3RD-PARTY.md +13 -0
  312. package/dist/compat/stream/LICENSE-APACHE +177 -0
  313. package/dist/compat/stream/add-abort-signal.d.ts +4 -0
  314. package/dist/compat/stream/add-abort-signal.js +73 -0
  315. package/dist/compat/stream/compose.d.ts +1 -0
  316. package/dist/compat/stream/compose.js +313 -0
  317. package/dist/compat/stream/destroy.d.ts +5 -0
  318. package/dist/compat/stream/destroy.js +315 -0
  319. package/dist/compat/stream/duplex.d.ts +48 -0
  320. package/dist/compat/stream/duplex.js +789 -0
  321. package/dist/compat/stream/end-of-stream.d.ts +16 -0
  322. package/dist/compat/stream/end-of-stream.js +269 -0
  323. package/dist/compat/stream/errors.d.ts +40 -0
  324. package/dist/compat/stream/errors.js +86 -0
  325. package/dist/compat/stream/events.d.ts +6 -0
  326. package/dist/compat/stream/events.js +28 -0
  327. package/dist/compat/stream/index.cjs +27 -0
  328. package/dist/compat/stream/index.d.cts +25 -0
  329. package/dist/compat/stream/index.d.ts +20 -0
  330. package/dist/compat/stream/index.js +55 -0
  331. package/dist/compat/stream/legacy.d.ts +8 -0
  332. package/dist/compat/stream/legacy.js +105 -0
  333. package/dist/compat/stream/once.d.ts +7 -0
  334. package/dist/compat/stream/once.js +13 -0
  335. package/dist/compat/stream/pipeline.d.ts +5 -0
  336. package/dist/compat/stream/pipeline.js +567 -0
  337. package/dist/compat/stream/process.d.ts +1 -0
  338. package/dist/compat/stream/process.js +4 -0
  339. package/dist/compat/stream/promises.d.ts +7 -0
  340. package/dist/compat/stream/promises.js +60 -0
  341. package/dist/compat/stream/readable.d.ts +29 -0
  342. package/dist/compat/stream/readable.js +2267 -0
  343. package/dist/compat/stream/state.d.ts +8 -0
  344. package/dist/compat/stream/state.js +63 -0
  345. package/dist/compat/stream/transform.d.ts +2 -0
  346. package/dist/compat/stream/transform.js +202 -0
  347. package/dist/compat/stream/util.d.ts +55 -0
  348. package/dist/compat/stream/util.js +345 -0
  349. package/dist/compat/stream/validators.d.ts +2 -0
  350. package/dist/compat/stream/validators.js +14 -0
  351. package/dist/compat/stream/writable.d.ts +21 -0
  352. package/dist/compat/stream/writable.js +1325 -0
  353. package/dist/compat/stream-consumers/LICENSE-3RD-PARTY.md +5 -0
  354. package/dist/compat/stream-consumers/LICENSE-APACHE +177 -0
  355. package/dist/compat/stream-consumers/index.d.ts +14 -0
  356. package/dist/compat/stream-consumers/index.js +62 -0
  357. package/dist/compat/stream-consumers/iterable.d.ts +1 -0
  358. package/dist/compat/stream-consumers/iterable.js +34 -0
  359. package/dist/compat/stream-duplex/LICENSE-3RD-PARTY.md +13 -0
  360. package/dist/compat/stream-duplex/LICENSE-APACHE +177 -0
  361. package/dist/compat/stream-duplex/index.cjs +3 -0
  362. package/dist/compat/stream-duplex/index.d.cts +2 -0
  363. package/dist/compat/stream-duplex/index.d.ts +3 -0
  364. package/dist/compat/stream-duplex/index.js +8 -0
  365. package/dist/compat/stream-passthrough/LICENSE-3RD-PARTY.md +13 -0
  366. package/dist/compat/stream-passthrough/LICENSE-APACHE +177 -0
  367. package/dist/compat/stream-passthrough/index.cjs +3 -0
  368. package/dist/compat/stream-passthrough/index.d.cts +2 -0
  369. package/dist/compat/stream-passthrough/index.d.ts +3 -0
  370. package/dist/compat/stream-passthrough/index.js +8 -0
  371. package/dist/compat/stream-promises/LICENSE-3RD-PARTY.md +13 -0
  372. package/dist/compat/stream-promises/LICENSE-APACHE +177 -0
  373. package/dist/compat/stream-promises/index.d.ts +1 -0
  374. package/dist/compat/stream-promises/index.js +1 -0
  375. package/dist/compat/stream-readable/LICENSE-3RD-PARTY.md +13 -0
  376. package/dist/compat/stream-readable/LICENSE-APACHE +177 -0
  377. package/dist/compat/stream-readable/index.cjs +3 -0
  378. package/dist/compat/stream-readable/index.d.cts +2 -0
  379. package/dist/compat/stream-readable/index.d.ts +3 -0
  380. package/dist/compat/stream-readable/index.js +8 -0
  381. package/dist/compat/stream-transform/LICENSE-3RD-PARTY.md +13 -0
  382. package/dist/compat/stream-transform/LICENSE-APACHE +177 -0
  383. package/dist/compat/stream-transform/index.cjs +3 -0
  384. package/dist/compat/stream-transform/index.d.cts +2 -0
  385. package/dist/compat/stream-transform/index.d.ts +3 -0
  386. package/dist/compat/stream-transform/index.js +8 -0
  387. package/dist/compat/stream-web/LICENSE-MIT +22 -0
  388. package/dist/compat/stream-web/NOTICE.md +3 -0
  389. package/dist/compat/stream-web/context.d.ts +2 -0
  390. package/dist/compat/stream-web/context.js +35 -0
  391. package/dist/compat/stream-web/index.d.ts +80 -0
  392. package/dist/compat/stream-web/index.js +129 -0
  393. package/dist/compat/stream-web/interop.d.ts +6 -0
  394. package/dist/compat/stream-web/interop.js +72 -0
  395. package/dist/compat/stream-web/ponyfill.d.ts +1 -0
  396. package/dist/compat/stream-web/ponyfill.js +2093 -0
  397. package/dist/compat/stream-web/runtime.d.ts +16 -0
  398. package/dist/compat/stream-web/runtime.js +51 -0
  399. package/dist/compat/stream-writable/LICENSE-3RD-PARTY.md +13 -0
  400. package/dist/compat/stream-writable/LICENSE-APACHE +177 -0
  401. package/dist/compat/stream-writable/index.cjs +3 -0
  402. package/dist/compat/stream-writable/index.d.cts +2 -0
  403. package/dist/compat/stream-writable/index.d.ts +3 -0
  404. package/dist/compat/stream-writable/index.js +8 -0
  405. package/dist/compat/string-decoder/LICENSE-3RD-PARTY.md +38 -0
  406. package/dist/compat/string-decoder/LICENSE-APACHE +177 -0
  407. package/dist/compat/string-decoder/index.d.ts +33 -0
  408. package/dist/compat/string-decoder/index.js +518 -0
  409. package/dist/compat/test/LICENSE-3RD-PARTY.md +37 -0
  410. package/dist/compat/test/LICENSE-APACHE +177 -0
  411. package/dist/compat/test/index.d.ts +9 -0
  412. package/dist/compat/test/index.js +11 -0
  413. package/dist/compat/test/mock.d.ts +103 -0
  414. package/dist/compat/test/mock.js +397 -0
  415. package/dist/compat/test/validators.d.ts +2 -0
  416. package/dist/compat/test/validators.js +14 -0
  417. package/dist/compat/timers/LICENSE-3RD-PARTY.md +7 -0
  418. package/dist/compat/timers/LICENSE-APACHE +177 -0
  419. package/dist/compat/timers/errors.d.ts +28 -0
  420. package/dist/compat/timers/errors.js +206 -0
  421. package/dist/compat/timers/host.d.ts +11 -0
  422. package/dist/compat/timers/host.js +60 -0
  423. package/dist/compat/timers/index.cjs +3 -0
  424. package/dist/compat/timers/index.d.cts +23 -0
  425. package/dist/compat/timers/index.d.ts +36 -0
  426. package/dist/compat/timers/index.js +20 -0
  427. package/dist/compat/timers/installation.d.ts +4 -0
  428. package/dist/compat/timers/installation.js +61 -0
  429. package/dist/compat/timers/internal-promises.d.ts +19 -0
  430. package/dist/compat/timers/internal-promises.js +173 -0
  431. package/dist/compat/timers/promises.cjs +2 -0
  432. package/dist/compat/timers/promises.d.cts +12 -0
  433. package/dist/compat/timers/promises.d.ts +14 -0
  434. package/dist/compat/timers/promises.js +3 -0
  435. package/dist/compat/timers/timers.d.ts +32 -0
  436. package/dist/compat/timers/timers.js +147 -0
  437. package/dist/compat/timers/validation.d.ts +5 -0
  438. package/dist/compat/timers/validation.js +22 -0
  439. package/dist/compat/timers/wait.d.ts +4 -0
  440. package/dist/compat/timers/wait.js +91 -0
  441. package/dist/compat/tls-common/LICENSE-3RD-PARTY.md +11 -0
  442. package/dist/compat/tls-common/LICENSE-APACHE +177 -0
  443. package/dist/compat/tls-common/index.d.ts +14 -0
  444. package/dist/compat/tls-common/index.js +88 -0
  445. package/dist/compat/trace-events/LICENSE-3RD-PARTY.md +5 -0
  446. package/dist/compat/trace-events/LICENSE-APACHE +177 -0
  447. package/dist/compat/trace-events/index.d.ts +18 -0
  448. package/dist/compat/trace-events/index.js +88 -0
  449. package/dist/compat/tty/LICENSE-3RD-PARTY.md +8 -0
  450. package/dist/compat/tty/LICENSE-APACHE +177 -0
  451. package/dist/compat/tty/index.d.ts +17 -0
  452. package/dist/compat/tty/index.js +101 -0
  453. package/dist/compat/url/LICENSE-3RD-PARTY.md +63 -0
  454. package/dist/compat/url/LICENSE-ADA +18 -0
  455. package/dist/compat/url/LICENSE-APACHE +177 -0
  456. package/dist/compat/url/LICENSE-UNICODE +39 -0
  457. package/dist/compat/url/LICENSE-WHATWG-URL +21 -0
  458. package/dist/compat/url/brand.d.ts +4 -0
  459. package/dist/compat/url/brand.js +10 -0
  460. package/dist/compat/url/constants.d.ts +27 -0
  461. package/dist/compat/url/constants.js +28 -0
  462. package/dist/compat/url/errors.d.ts +44 -0
  463. package/dist/compat/url/errors.js +248 -0
  464. package/dist/compat/url/idna-data.d.ts +3958 -0
  465. package/dist/compat/url/idna-data.js +22 -0
  466. package/dist/compat/url/idna.d.ts +9 -0
  467. package/dist/compat/url/idna.js +47 -0
  468. package/dist/compat/url/index.d.ts +48 -0
  469. package/dist/compat/url/index.js +39 -0
  470. package/dist/compat/url/installation.d.ts +4 -0
  471. package/dist/compat/url/installation.js +61 -0
  472. package/dist/compat/url/internal-url.d.ts +34 -0
  473. package/dist/compat/url/internal-url.js +264 -0
  474. package/dist/compat/url/legacy-url.d.ts +28 -0
  475. package/dist/compat/url/legacy-url.js +870 -0
  476. package/dist/compat/url/parser-platform.d.ts +3 -0
  477. package/dist/compat/url/parser-platform.js +26 -0
  478. package/dist/compat/url/standard-url.d.ts +2 -0
  479. package/dist/compat/url/standard-url.js +3189 -0
  480. package/dist/compat/url/unicode.d.ts +2 -0
  481. package/dist/compat/url/unicode.js +119 -0
  482. package/dist/compat/url/validation.d.ts +2 -0
  483. package/dist/compat/url/validation.js +9 -0
  484. package/dist/compat/url/web-url.d.ts +27 -0
  485. package/dist/compat/url/web-url.js +119 -0
  486. package/dist/compat/util/LICENSE-3RD-PARTY.md +5 -0
  487. package/dist/compat/util/LICENSE-APACHE +177 -0
  488. package/dist/compat/util/additional.d.ts +11 -0
  489. package/dist/compat/util/additional.js +121 -0
  490. package/dist/compat/util/comparison-types.d.ts +16 -0
  491. package/dist/compat/util/comparison-types.js +50 -0
  492. package/dist/compat/util/comparisons.d.ts +1 -0
  493. package/dist/compat/util/comparisons.js +527 -0
  494. package/dist/compat/util/core.d.ts +18 -0
  495. package/dist/compat/util/core.js +265 -0
  496. package/dist/compat/util/debuglog.d.ts +1 -0
  497. package/dist/compat/util/debuglog.js +78 -0
  498. package/dist/compat/util/index.d.ts +35 -0
  499. package/dist/compat/util/index.js +77 -0
  500. package/dist/compat/util/inspect-binding.d.ts +13 -0
  501. package/dist/compat/util/inspect-binding.js +39 -0
  502. package/dist/compat/util/inspect-types.d.ts +13 -0
  503. package/dist/compat/util/inspect-types.js +30 -0
  504. package/dist/compat/util/inspect.d.ts +152 -0
  505. package/dist/compat/util/inspect.js +2503 -0
  506. package/dist/compat/util/mime.d.ts +24 -0
  507. package/dist/compat/util/mime.js +284 -0
  508. package/dist/compat/util/properties.d.ts +9 -0
  509. package/dist/compat/util/properties.js +76 -0
  510. package/dist/compat/v8/LICENSE-3RD-PARTY.md +6 -0
  511. package/dist/compat/v8/LICENSE-APACHE +177 -0
  512. package/dist/compat/v8/errors.d.ts +5 -0
  513. package/dist/compat/v8/errors.js +7 -0
  514. package/dist/compat/v8/index.d.ts +106 -0
  515. package/dist/compat/v8/index.js +280 -0
  516. package/dist/compat/vm/LICENSE-3RD-PARTY.md +39 -0
  517. package/dist/compat/vm/LICENSE-APACHE +177 -0
  518. package/dist/compat/vm/errors.d.ts +5 -0
  519. package/dist/compat/vm/errors.js +7 -0
  520. package/dist/compat/vm/index.d.ts +47 -0
  521. package/dist/compat/vm/index.js +231 -0
  522. package/dist/compat/vm/validation.d.ts +3 -0
  523. package/dist/compat/vm/validation.js +14 -0
  524. package/dist/compat/wasi/LICENSE-3RD-PARTY.md +8 -0
  525. package/dist/compat/wasi/LICENSE-APACHE +177 -0
  526. package/dist/compat/wasi/errors.d.ts +4 -0
  527. package/dist/compat/wasi/errors.js +6 -0
  528. package/dist/compat/wasi/index.d.ts +15 -0
  529. package/dist/compat/wasi/index.js +44 -0
  530. package/dist/compat/worker-threads/LICENSE-3RD-PARTY.md +5 -0
  531. package/dist/compat/worker-threads/LICENSE-APACHE +177 -0
  532. package/dist/compat/worker-threads/errors.d.ts +4 -0
  533. package/dist/compat/worker-threads/errors.js +6 -0
  534. package/dist/compat/worker-threads/index.d.ts +71 -0
  535. package/dist/compat/worker-threads/index.js +138 -0
  536. package/dist/compat/worker-threads/message-channel.d.ts +18 -0
  537. package/dist/compat/worker-threads/message-channel.js +157 -0
  538. package/dist/configured.d.ts +3 -0
  539. package/dist/configured.js +4 -0
  540. package/dist/environment.d.ts +4 -0
  541. package/dist/environment.js +18 -0
  542. package/dist/index.d.ts +11 -0
  543. package/dist/index.js +107 -0
  544. package/dist/ios.d.ts +2 -0
  545. package/dist/ios.js +1 -0
  546. package/dist/native-entry.d.ts +8 -0
  547. package/dist/native-entry.js +67 -0
  548. package/dist/shared/brotli/LICENSE-APACHE +201 -0
  549. package/dist/shared/brotli/LICENSE-MIT +9 -0
  550. package/dist/shared/brotli/NOTICE +3 -0
  551. package/dist/shared/brotli/index.d.ts +2 -0
  552. package/dist/shared/brotli/index.js +288 -0
  553. package/dist/shared/contracts/index.d.ts +42 -0
  554. package/dist/shared/contracts/index.js +88 -0
  555. package/dist/shared/contracts/testing.d.ts +22 -0
  556. package/dist/shared/contracts/testing.js +57 -0
  557. package/dist/shared/globals/index.d.ts +3 -0
  558. package/dist/shared/globals/index.js +87 -0
  559. package/dist/shared/globals/inject.d.ts +2 -0
  560. package/dist/shared/globals/inject.js +3 -0
  561. package/dist/shared/globals/install.d.ts +1 -0
  562. package/dist/shared/globals/install.js +15 -0
  563. package/dist/shared/globals/node-install.d.ts +1 -0
  564. package/dist/shared/globals/node-install.js +4 -0
  565. package/dist/shared/globals/platform.d.ts +104 -0
  566. package/dist/shared/globals/platform.js +37 -0
  567. package/dist/shared/globals/runtime.d.ts +6 -0
  568. package/dist/shared/globals/runtime.js +8 -0
  569. package/dist/shared/globals/symbols.d.ts +4 -0
  570. package/dist/shared/globals/symbols.js +35 -0
  571. package/dist/shared/globals/web.d.ts +4 -0
  572. package/dist/shared/globals/web.js +108 -0
  573. package/dist/shared/http-wire/LICENSE.llhttp +22 -0
  574. package/dist/shared/http-wire/LICENSE.undici +21 -0
  575. package/dist/shared/http-wire/NOTICE.md +14 -0
  576. package/dist/shared/http-wire/index.d.ts +27 -0
  577. package/dist/shared/http-wire/index.js +132 -0
  578. package/dist/shared/http-wire/wasm.d.ts +2 -0
  579. package/dist/shared/http-wire/wasm.js +2 -0
  580. package/dist/tooling/async.d.ts +7 -0
  581. package/dist/tooling/async.js +99 -0
  582. package/dist/tooling/build-isolation.d.ts +4 -0
  583. package/dist/tooling/build-isolation.js +34 -0
  584. package/dist/tooling/documents.d.ts +7 -0
  585. package/dist/tooling/documents.js +26 -0
  586. package/dist/tooling/esbuild.d.ts +15 -0
  587. package/dist/tooling/esbuild.js +193 -0
  588. package/dist/tooling/files.d.ts +2 -0
  589. package/dist/tooling/files.js +18 -0
  590. package/dist/tooling/opennext/build.d.ts +1 -0
  591. package/dist/tooling/opennext/build.js +121 -0
  592. package/dist/tooling/opennext/index.d.ts +3 -0
  593. package/dist/tooling/opennext/index.js +213 -0
  594. package/dist/tooling/opennext/plan.d.ts +9 -0
  595. package/dist/tooling/opennext/plan.js +36 -0
  596. package/dist/tooling/opennext/safety.d.ts +4 -0
  597. package/dist/tooling/opennext/safety.js +36 -0
  598. package/dist/tooling/route-permissions.d.ts +3 -0
  599. package/dist/tooling/route-permissions.js +15 -0
  600. package/dist/tooling/server-modules.d.ts +30 -0
  601. package/dist/tooling/server-modules.js +98 -0
  602. package/dist/tooling/server-only-html.d.ts +1 -0
  603. package/dist/tooling/server-only-html.js +66 -0
  604. package/dist/tooling/server-only.d.ts +6 -0
  605. package/dist/tooling/server-only.js +53 -0
  606. package/dist/tooling/server.d.ts +25 -0
  607. package/dist/tooling/server.js +981 -0
  608. package/dist/tooling/shared.d.ts +13 -0
  609. package/dist/tooling/shared.js +130 -0
  610. package/dist/tooling/vite.d.ts +18 -0
  611. package/dist/tooling/vite.js +448 -0
  612. package/dist/tooling/void/index.d.ts +3 -0
  613. package/dist/tooling/void/index.js +205 -0
  614. package/dist/tooling/void/plan.d.ts +17 -0
  615. package/dist/tooling/void/plan.js +288 -0
  616. package/native/android/build.gradle +68 -0
  617. package/native/android/consumer-rules.pro +2 -0
  618. package/native/android/src/main/AndroidManifest.xml +6 -0
  619. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkerSockets.java +202 -0
  620. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersCapacitorPlugin.java +256 -0
  621. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNative.java +22 -0
  622. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeActivity.java +178 -0
  623. package/native/android/src/main/java/jp/rdlabo/workerscapacitor/WorkersNativeBridge.java +45 -0
  624. package/native/ios/DocumentBridge.swift +330 -0
  625. package/native/ios/NetworkBridge.swift +51 -0
  626. package/native/ios/SocketBridge.swift +180 -0
  627. package/native/ios/WorkersCapacitorPlugin.swift +152 -0
  628. package/native/ios-host/WorkersView.swift +194 -0
  629. package/package.json +154 -4
@@ -0,0 +1,13 @@
1
+ export declare const configuredPath: string;
2
+ export declare const transportPath: string;
3
+ export declare const globalsPath: string;
4
+ export declare const networkRelayPath: string;
5
+ export declare const globalsInstallPath: string;
6
+ export declare const nodeGlobalsInstallPath: string;
7
+ export declare const nodeCompatPath: (name: string) => string;
8
+ export declare function compatibilityAliases(): Record<string, string>;
9
+ export declare function commonJSCompatibilityAliases(): Record<string, string>;
10
+ export declare function compatibilityDependencies(): string[];
11
+ export declare function workerEntry(entry: string, virtualFiles?: string): string;
12
+ export declare function workerSource(entry: string, factoryImport: string, selector?: string): string;
13
+ export declare const globalsInjectPath: string;
@@ -0,0 +1,130 @@
1
+ import stdlib from "node-stdlib-browser";
2
+ import { fileURLToPath } from "node:url";
3
+ export const configuredPath = fileURLToPath(new URL("../configured.js", import.meta.url));
4
+ export const transportPath = fileURLToPath(new URL("../browser/isolated/transport.js", import.meta.url));
5
+ export const globalsPath = fileURLToPath(new URL("../shared/globals/index.js", import.meta.url));
6
+ export const networkRelayPath = fileURLToPath(new URL("../browser/fetch/relay.js", import.meta.url));
7
+ export const globalsInstallPath = fileURLToPath(new URL("../shared/globals/install.js", import.meta.url));
8
+ export const nodeGlobalsInstallPath = fileURLToPath(new URL("../shared/globals/node-install.js", import.meta.url));
9
+ export const nodeCompatPath = (name) => fileURLToPath(new URL(`../compat/${name}/index.js`, import.meta.url));
10
+ const workersModulePath = (name) => fileURLToPath(new URL(`../cloudflare/apis/${name}/index.js`, import.meta.url));
11
+ // A compat module reusing a CommonJS polyfill imports the concrete package
12
+ // file; the bare name is the alias target, so only the deep specifier can
13
+ // reach the real implementation without recursing.
14
+ const polyfill = (specifier) => fileURLToPath(import.meta.resolve(specifier));
15
+ // One entry per builtin; subpaths precede parent aliases when expanded.
16
+ // The optional third path is the CommonJS constructor entry.
17
+ const builtins = [
18
+ ["punycode", "punycode/index.js"],
19
+ ["child_process", "child-process/index.js"],
20
+ ["cluster", "cluster/index.js"],
21
+ ["dgram", "dgram/index.js"],
22
+ ["inspector/promises", "inspector/promises.js"],
23
+ ["inspector", "inspector/index.js"],
24
+ ["readline/promises", "readline/promises.js"],
25
+ ["readline", "readline/index.js"],
26
+ ["domain", "domain/index.js"],
27
+ ["stream/promises", "stream-promises/index.js"],
28
+ ["stream/consumers", "stream-consumers/index.js"],
29
+ ["dns/promises", "dns/promises.js"],
30
+ ["dns", "dns/index.js"],
31
+ ["assert/strict", "assert/index.cjs"],
32
+ ["assert", "assert/index.cjs"],
33
+ ["perf_hooks", "perf-hooks/index.js"],
34
+ ["trace_events", "trace-events/index.js"],
35
+ ["https", "https/index.js"],
36
+ ["worker_threads", "worker-threads/index.js"],
37
+ ["node:test", "test/index.js"],
38
+ ["node:sqlite", "sqlite/index.js"],
39
+ ["repl", "repl/index.js"],
40
+ ["vm", "vm/index.js"],
41
+ ["http2", "http2/index.js"],
42
+ ["constants", "constants/index.js"],
43
+ ["v8", "v8/index.js"],
44
+ ["wasi", "wasi/index.js"],
45
+ ["os", "os/index.js"],
46
+ ["tty", "tty/index.js"],
47
+ ["url", "url/index.js"],
48
+ ["diagnostics_channel", "diagnostics-channel/index.js"],
49
+ ["_tls_common", "tls-common/index.js"],
50
+ ["async_hooks", "async-hooks/index.js"],
51
+ ["timers/promises", "timers/promises.js", "timers/promises.cjs"],
52
+ ["timers", "timers/index.js", "timers/index.cjs"],
53
+ ["fs/promises", "fs/promises/index.js"],
54
+ ["fs", "fs/index.js"],
55
+ ["module", "module/index.js", "module/index.cjs"],
56
+ ["_stream_readable", "stream-readable/index.js", "stream-readable/index.cjs"],
57
+ ["_stream_writable", "stream-writable/index.js", "stream-writable/index.cjs"],
58
+ ["_stream_duplex", "stream-duplex/index.js", "stream-duplex/index.cjs"],
59
+ [
60
+ "_stream_transform",
61
+ "stream-transform/index.js",
62
+ "stream-transform/index.cjs",
63
+ ],
64
+ [
65
+ "_stream_passthrough",
66
+ "stream-passthrough/index.js",
67
+ "stream-passthrough/index.cjs",
68
+ ],
69
+ ["stream/web", "stream-web/index.js"],
70
+ ["util", "util/index.js"],
71
+ ["buffer", "buffer/index.js"],
72
+ ["_http_agent", "http-agent/index.js"],
73
+ ["_http_client", "http-client/index.js"],
74
+ ["_http_incoming", "http-incoming/index.js"],
75
+ ["http", "http/index.js"],
76
+ ["net", "net/index.js"],
77
+ ["stream", "stream/index.js", "stream/index.cjs"],
78
+ ["path/win32", "path/win32/index.js"],
79
+ ["path/posix", "path/posix/index.js"],
80
+ ["path", "path/index.js"],
81
+ ["querystring", "querystring/index.js"],
82
+ ["string_decoder", "string-decoder/index.js"],
83
+ ];
84
+ function builtinAliases(commonJS = false) {
85
+ const result = {};
86
+ for (const [name, esm, cjs] of builtins) {
87
+ if (commonJS && !cjs)
88
+ continue;
89
+ const path = fileURLToPath(new URL(`../compat/${commonJS ? cjs : esm}`, import.meta.url));
90
+ result[name] = path;
91
+ if (!name.startsWith("node:"))
92
+ result[`node:${name}`] = path;
93
+ }
94
+ return Object.fromEntries(Object.entries(result).sort(([a], [b]) => b.length - a.length));
95
+ }
96
+ export function compatibilityAliases() {
97
+ return {
98
+ "process/": stdlib.process,
99
+ "cloudflare:node": workersModulePath("cloudflare-node"),
100
+ "cloudflare:workers": workersModulePath("cloudflare-workers"),
101
+ "punycode/": polyfill("punycode/punycode.js"),
102
+ "util/util.js": polyfill("util/util.js"),
103
+ "string_decoder/lib/string_decoder.js": polyfill("string_decoder/lib/string_decoder.js"),
104
+ ...builtinAliases(),
105
+ };
106
+ }
107
+ export function commonJSCompatibilityAliases() {
108
+ return builtinAliases(true);
109
+ }
110
+ export function compatibilityDependencies() {
111
+ return [
112
+ "cloudflare:node",
113
+ "cloudflare:workers",
114
+ ...Object.keys(builtinAliases()),
115
+ ];
116
+ }
117
+ export function workerEntry(entry, virtualFiles) {
118
+ // WebKit can evaluate a Worker entry twice when a dynamic child imports its
119
+ // exports. Keep the bootstrap free of exports and all shared code in children.
120
+ // Older WebKit does not deliver rejected module evaluation to Worker.onerror;
121
+ // explicitly report startup failure before the parent waits indefinitely.
122
+ const files = virtualFiles
123
+ ? `const { registerVirtualFiles } = await import(${JSON.stringify(nodeCompatPath("fs"))});\nregisterVirtualFiles(${virtualFiles});\n`
124
+ : "";
125
+ return `try {\nconst { initializeWorkerNetwork } = await import(${JSON.stringify(networkRelayPath)});\nawait initializeWorkerNetwork();\nawait import(${JSON.stringify(globalsInstallPath)});\n${files}const { default: worker } = await import(${JSON.stringify(entry)});\nconst { serve } = await import(${JSON.stringify(transportPath)});\nserve(worker);\n} catch (error) {\nself.postMessage({ type: "startup-error", name: error instanceof Error ? error.name : "Error", message: error instanceof Error ? error.message : String(error) });\n}`;
126
+ }
127
+ export function workerSource(entry, factoryImport, selector) {
128
+ return `import createWorker from ${JSON.stringify(factoryImport)};\n${selector ? `import { needsRemote, requiresRemote } from ${JSON.stringify(selector)};` : ""}\nimport { installNodeGlobals } from ${JSON.stringify(globalsPath)};\nexport default { createWorker, ${selector ? "needsRemote, requiresRemote," : ""} async loadDirect() {\n const dispose = installNodeGlobals();\n try {\n return { handler: (await import(${JSON.stringify(entry)})).default, dispose };\n } catch (error) {\n dispose();\n throw error;\n }\n} };`;
129
+ }
130
+ export const globalsInjectPath = fileURLToPath(new URL("../shared/globals/inject.js", import.meta.url));
@@ -0,0 +1,18 @@
1
+ export type { WorkerExecution, WorkerExecutionMode, LocalRoute, } from "./server.js";
2
+ import type { ServerBuildOptions } from "./server.js";
3
+ import type { PluginOption } from "vite";
4
+ /** Add only to the Capacitor/browser build, never the Cloudflare build. */
5
+ export interface WorkersCapacitorPluginOptions extends ServerBuildOptions {
6
+ /** Workers application entry, relative to Vite root or an absolute path. */
7
+ worker?: string;
8
+ /**
9
+ * Additional files embedded into the worker's read-only virtual filesystem.
10
+ * Only explicitly selected public files are included; server build metadata
11
+ * is never discovered recursively.
12
+ * Paths resolve relative to the Vite root; the
13
+ * normalized absolute path is the lookup key, with suffix matching so
14
+ * bundled runtimes find entries regardless of their cwd assumptions.
15
+ */
16
+ workerFiles?: string[];
17
+ }
18
+ export declare function workersCapacitorPlugin(options?: WorkersCapacitorPluginOptions): PluginOption[];
@@ -0,0 +1,448 @@
1
+ import { guardHtmlAssets } from "./server-only-html.js";
2
+ import { assertSeparateOutput, assertNoOutputLinks, } from "./build-isolation.js";
3
+ import { serverOnlyFiles } from "./server-only.js";
4
+ import { readWorkerFiles } from "./files.js";
5
+ import { lowerAsync, asyncContextPlugin } from "./async.js";
6
+ import { documentAssets, listAssets } from "./documents.js";
7
+ import { serverModules } from "./server-modules.js";
8
+ import { resolve, dirname, isAbsolute } from "node:path";
9
+ import { existsSync } from "node:fs";
10
+ import { configuredPath, compatibilityAliases, compatibilityDependencies, commonJSCompatibilityAliases, globalsInstallPath, nodeGlobalsInstallPath, globalsPath, globalsInjectPath, workerEntry, } from "./shared.js";
11
+ import { nodePolyfills } from "vite-plugin-node-polyfills";
12
+ import inject from "@rollup/plugin-inject";
13
+ import { normalizePath } from "vite";
14
+ /** Add only to the Capacitor/browser build, never the Cloudflare build. */
15
+ function compatibilityPlugins(installGlobals = false) {
16
+ // Overrides take bare module names only; both bare and "node:" imports of
17
+ // the same module resolve to the shared compat profile.
18
+ const globalsRuntimePath = globalsInjectPath.replace(/inject\.js$/, "runtime.js");
19
+ const aliases = compatibilityAliases();
20
+ const commonJS = commonJSCompatibilityAliases();
21
+ const commonJSPaths = new Map(Object.entries(commonJS).map(([specifier, path]) => [
22
+ normalizePath(aliases[specifier]),
23
+ path,
24
+ ]));
25
+ const overrides = Object.fromEntries(Object.entries(aliases).filter(([specifier]) => !specifier.includes(":")));
26
+ return [
27
+ {
28
+ name: "workers-capacitor-async-context",
29
+ enforce: "post",
30
+ transform(code, id) {
31
+ if (/\.[cm]?[jt]sx?(?:\?|$)/.test(id))
32
+ return lowerAsync(code, id);
33
+ },
34
+ renderChunk(code, chunk) {
35
+ return lowerAsync(code, chunk.fileName);
36
+ },
37
+ },
38
+ ...(installGlobals
39
+ ? [
40
+ {
41
+ name: "workers-capacitor-global-install",
42
+ enforce: "pre",
43
+ transform(code, id) {
44
+ // CommonJS proxy modules are already generated ESM. Injecting a
45
+ // require into their virtual .cjs IDs leaves it unbundled.
46
+ if (id.startsWith("\0"))
47
+ return;
48
+ const path = normalizePath(id.split("?")[0]);
49
+ if (!/\.[cm]?[jt]sx?$/.test(path) ||
50
+ path.includes("/node_modules/") ||
51
+ path.startsWith(normalizePath(resolve(globalsPath, "../../../"))))
52
+ return;
53
+ const installation = JSON.stringify(installGlobals === "worker"
54
+ ? globalsInstallPath
55
+ : nodeGlobalsInstallPath);
56
+ return /\.c[jt]s$/.test(path)
57
+ ? `require(${installation});\n${code}`
58
+ : `import ${installation};\n${code}`;
59
+ },
60
+ },
61
+ ]
62
+ : []),
63
+ {
64
+ name: "workers-capacitor",
65
+ enforce: "pre",
66
+ async resolveId(source, importer, options) {
67
+ if (options.custom?.["node-resolve"]?.isRequire)
68
+ return commonJS[source] ?? commonJSPaths.get(normalizePath(source));
69
+ if (!importer || !source.startsWith("."))
70
+ return;
71
+ const root = normalizePath(resolve(globalsPath, "../../.."));
72
+ const owner = normalizePath(importer.split("?")[0]);
73
+ if (!owner.startsWith(`${root}/`))
74
+ return;
75
+ const target = normalizePath(resolve(dirname(owner), source));
76
+ // Runtime-relative imports and public builtins must resolve to the same
77
+ // optimized module. Keep internal buffer/performance imports untouched.
78
+ let specifier;
79
+ if (target === `${root}/compat/stream-web/index.js`)
80
+ specifier = "node:stream/web";
81
+ else if (owner === `${root}/browser/body/stream-body.js` ||
82
+ owner === `${root}/shared/globals/web.js`) {
83
+ if (target === `${root}/compat/buffer/blob.js`)
84
+ specifier = "node:buffer";
85
+ if (target === `${root}/compat/perf-hooks/performance.js`)
86
+ specifier = "node:perf_hooks";
87
+ }
88
+ if (specifier)
89
+ return this.resolve(specifier, importer, { skipSelf: true });
90
+ },
91
+ config: () => ({
92
+ // Generated Workers (including OpenNext) can mix ESM exports with
93
+ // require() calls in .mjs files outside node_modules.
94
+ build: {
95
+ commonjsOptions: {
96
+ include: [/node_modules/, /\.[cm]?js$/],
97
+ extensions: [".js", ".cjs", ".mjs"],
98
+ transformMixedEsModules: true,
99
+ },
100
+ },
101
+ // App globals and dependencies must share Buffer identity and the HTTP registry.
102
+ optimizeDeps: {
103
+ esbuildOptions: {
104
+ plugins: [
105
+ asyncContextPlugin(),
106
+ {
107
+ name: "workers-capacitor-commonjs-builtins",
108
+ setup(build) {
109
+ build.onResolve({
110
+ filter: /^(?:node:)?[\w/]+$/,
111
+ }, ({ path, kind }) => kind === "require-call" && commonJS[path]
112
+ ? { path: commonJS[path] }
113
+ : undefined);
114
+ },
115
+ },
116
+ ],
117
+ },
118
+ include: compatibilityDependencies(),
119
+ },
120
+ resolve: {
121
+ alias: aliases,
122
+ },
123
+ }),
124
+ },
125
+ ...nodePolyfills({
126
+ overrides,
127
+ globals: { Buffer: false, global: false, process: false },
128
+ }),
129
+ {
130
+ ...inject({
131
+ Buffer: [globalsInjectPath, "Buffer"],
132
+ // util reads process during Buffer initialization. Keep this import
133
+ // independent of the injector that also imports Buffer.
134
+ process: [aliases["process/"], "default"],
135
+ global: [globalsRuntimePath, "global"],
136
+ setImmediate: [globalsRuntimePath, "setImmediate"],
137
+ clearImmediate: [globalsRuntimePath, "clearImmediate"],
138
+ // Static requires were bundled above; remaining resolve references
139
+ // must fail explicitly when called rather than during module setup.
140
+ "require.resolve": [
141
+ resolve(dirname(aliases["module"]), "resolve-unavailable.js"),
142
+ "default",
143
+ ],
144
+ exclude: [
145
+ normalizePath(globalsPath),
146
+ normalizePath(globalsInjectPath),
147
+ normalizePath(globalsRuntimePath),
148
+ normalizePath(globalsInstallPath),
149
+ ],
150
+ }),
151
+ enforce: "post",
152
+ },
153
+ ];
154
+ }
155
+ // A real-looking absolute ID survives Vite's worker query stripping without
156
+ // writing generated entry files into the consumer's project.
157
+ const entrySuffix = ".workers-capacitor-worker.js";
158
+ function virtualId(source, root, owns) {
159
+ const [path, ...query] = source.split("?");
160
+ const candidates = [path];
161
+ if (path.startsWith("/@fs/"))
162
+ candidates.push(/^[a-z]:/i.test(path.slice(5)) ? path.slice(5) : "/" + path.slice(5));
163
+ if (root && path.startsWith("/"))
164
+ candidates.push(normalizePath(resolve(root, "." + path)));
165
+ const match = candidates.find(owns);
166
+ return match
167
+ ? match + (query.length ? "?" + query.join("?") : "")
168
+ : undefined;
169
+ }
170
+ function workerEntryPlugin(entries, root, virtualFiles) {
171
+ return {
172
+ name: "workers-capacitor-entry",
173
+ enforce: "pre",
174
+ resolveId(source) {
175
+ return virtualId(source, root(), (path) => entries.has(path));
176
+ },
177
+ load(id) {
178
+ const [path, query = ""] = id.split("?");
179
+ if (entries.has(path) && !new URLSearchParams(query).has("worker")) {
180
+ const original = entries.get(path);
181
+ if (!virtualFiles)
182
+ return workerEntry(original);
183
+ return virtualFiles().then((files) => workerEntry(original, files));
184
+ }
185
+ },
186
+ };
187
+ }
188
+ export function workersCapacitorPlugin(options = {}) {
189
+ const entries = new Map();
190
+ const virtualFiles = () => readWorkerFiles(root, options.workerFiles, options.serverOnly);
191
+ let root;
192
+ let publicDir;
193
+ let htmlEnv;
194
+ let denied;
195
+ let server;
196
+ let outputDirectory;
197
+ const serverPlugin = () => ({
198
+ name: "workers-capacitor-server",
199
+ enforce: "pre",
200
+ resolveId(id) {
201
+ if (this.environment.config.consumer === "server")
202
+ this.error("workersCapacitorPlugin cannot build a server environment");
203
+ return virtualId(id, root, (path) => server?.owns(path) ?? false);
204
+ },
205
+ transform(_code, id) {
206
+ denied.assertPublic(id);
207
+ },
208
+ async load(id) {
209
+ denied.assertPublic(id);
210
+ if (outputDirectory && isAbsolute(id))
211
+ assertSeparateOutput(outputDirectory, [id.split("?")[0]]);
212
+ if (!server)
213
+ return;
214
+ const path = id.split("?")[0];
215
+ const generated = await server.load(path);
216
+ if (generated) {
217
+ // Declared file contents are replaced before analysis and cannot affect
218
+ // the mobile output. Keep them out of client-asset provenance below.
219
+ for (const input of generated.inputs)
220
+ if (!denied.matches(input))
221
+ this.addWatchFile(input);
222
+ return { code: generated.code, map: null };
223
+ }
224
+ await server.guard(path);
225
+ },
226
+ generateBundle() {
227
+ // Vite's CSS and new URL assets can be inlined without loading a module.
228
+ // Their tracked source files still identify what entered the client build.
229
+ for (const path of this.getWatchFiles())
230
+ denied.assertPublic(path);
231
+ },
232
+ buildEnd() {
233
+ if (outputDirectory)
234
+ assertSeparateOutput(outputDirectory, this.getWatchFiles());
235
+ },
236
+ async handleHotUpdate(ctx) {
237
+ const previous = await server?.get();
238
+ if (previous?.inputs.includes(ctx.file)) {
239
+ server?.reset();
240
+ ctx.server.moduleGraph.invalidateAll();
241
+ ctx.server.ws.send({ type: "full-reload" });
242
+ return [];
243
+ }
244
+ },
245
+ });
246
+ const assetGuard = () => ({
247
+ name: "workers-capacitor-server-only-urls",
248
+ async transform(code, id) {
249
+ if (!options.serverOnly?.length ||
250
+ !code.includes("import.meta.url") ||
251
+ !code.includes("URL"))
252
+ return;
253
+ const paths = [];
254
+ const visit = (node) => {
255
+ if (node.type === "NewExpression" &&
256
+ node.callee.type === "Identifier" &&
257
+ node.callee.name === "URL") {
258
+ const [value, base] = node.arguments;
259
+ if (base?.type === "MemberExpression" &&
260
+ base.object.type === "MetaProperty" &&
261
+ base.object.meta.name === "import" &&
262
+ base.property.type === "Identifier" &&
263
+ base.property.name === "url") {
264
+ const path = value?.type === "Literal" && typeof value.value === "string"
265
+ ? value.value
266
+ : value?.type === "TemplateLiteral" && !value.expressions.length
267
+ ? value.quasis[0].value.cooked
268
+ : undefined;
269
+ if (path)
270
+ paths.push(path);
271
+ }
272
+ }
273
+ for (const value of Object.values(node))
274
+ for (const child of Array.isArray(value) ? value : [value])
275
+ if (child &&
276
+ typeof child === "object" &&
277
+ typeof child.type === "string")
278
+ visit(child);
279
+ };
280
+ visit(this.parse(code));
281
+ for (const path of paths) {
282
+ // Vite does not track new URL files with query suffixes as watch inputs.
283
+ // Resolve aliases as well as relative paths before built-in inlining.
284
+ const resolved = await this.resolve(path, id, { skipSelf: true });
285
+ denied.assertPublic(resolved?.id ?? resolve(dirname(id), path));
286
+ }
287
+ },
288
+ });
289
+ return [
290
+ serverPlugin(),
291
+ assetGuard(),
292
+ {
293
+ name: "workers-capacitor-source",
294
+ enforce: "pre",
295
+ config: () => ({
296
+ optimizeDeps: { exclude: ["cf-workers-native"] },
297
+ worker: { format: "es" },
298
+ }),
299
+ transformIndexHtml: {
300
+ order: "pre",
301
+ handler(html, context) {
302
+ if (options.serverOnly?.length)
303
+ guardHtmlAssets(html.replace(/%(\S+?)%/g, (match, key) => htmlEnv[key] ?? match), context.filename, root, denied.assertPublic);
304
+ },
305
+ },
306
+ configResolved(config) {
307
+ if (config.build.ssr ||
308
+ Object.entries(config.environments).some(([name, environment]) => environment.consumer === "server" &&
309
+ // Vite adds an unused default SSR environment to every dev server.
310
+ // Its actual use is rejected by the server-environment hooks.
311
+ (config.command === "build" || name !== "ssr")) ||
312
+ config.plugins.some((plugin) => /^vite-plugin-cloudflare(?::|$)/.test(plugin.name)))
313
+ throw new Error("workersCapacitorPlugin is only for a separate Capacitor/browser build; do not add it to the Cloudflare or SSR build.");
314
+ root = config.root;
315
+ outputDirectory = config.build.write
316
+ ? resolve(root, config.build.outDir)
317
+ : undefined;
318
+ if (outputDirectory && options.worker)
319
+ assertSeparateOutput(outputDirectory, [
320
+ resolve(root, options.worker),
321
+ ]);
322
+ if (outputDirectory)
323
+ assertNoOutputLinks(outputDirectory);
324
+ htmlEnv = { ...config.env };
325
+ // Match Vite HTML substitution, including define overrides of env.
326
+ for (const [key, value] of Object.entries(config.define ?? {})) {
327
+ if (!key.startsWith("import.meta.env."))
328
+ continue;
329
+ let replacement = typeof value === "string" ? value : JSON.stringify(value);
330
+ if (typeof value === "string") {
331
+ try {
332
+ const parsed = JSON.parse(value);
333
+ if (typeof parsed === "string")
334
+ replacement = parsed;
335
+ }
336
+ catch {
337
+ /* Vite retains non-JSON strings. */
338
+ }
339
+ }
340
+ htmlEnv[key.slice(16)] = replacement;
341
+ }
342
+ denied = serverOnlyFiles(root, options.serverOnly);
343
+ publicDir = config.publicDir;
344
+ if (options.worker)
345
+ server = serverModules(resolve(root, options.worker), root, options);
346
+ },
347
+ async buildStart() {
348
+ if (outputDirectory)
349
+ assertNoOutputLinks(outputDirectory);
350
+ if (this.environment.config.consumer === "server")
351
+ this.error("workersCapacitorPlugin cannot build a server environment");
352
+ if (outputDirectory && server)
353
+ assertSeparateOutput(outputDirectory, (await server.get()).inputs);
354
+ denied = serverOnlyFiles(root, options.serverOnly);
355
+ if (publicDir && existsSync(publicDir))
356
+ denied.assertDirectory(publicDir);
357
+ for (const file of options.workerFiles ?? [])
358
+ denied.assertPublic(resolve(root, file));
359
+ },
360
+ generateBundle: {
361
+ order: "post",
362
+ async handler(_options, bundle) {
363
+ for (const asset of Object.values(bundle)) {
364
+ if (asset.type === "asset")
365
+ for (const path of asset.originalFileNames)
366
+ denied.assertPublic(resolve(root, path));
367
+ }
368
+ const files = [
369
+ ...Object.keys(bundle),
370
+ ...(publicDir ? await listAssets(publicDir) : []),
371
+ ];
372
+ const compilation = await server?.get();
373
+ if (compilation) {
374
+ const fileName = compilation.reportFile;
375
+ if (files.includes(fileName))
376
+ this.error("Server report asset collision: " + fileName);
377
+ const { mode, reason, routes } = compilation;
378
+ this.emitFile({
379
+ type: "asset",
380
+ fileName,
381
+ source: JSON.stringify({ mode, reason, routes }, null, 2),
382
+ });
383
+ files.push(fileName);
384
+ }
385
+ const assets = await documentAssets(files);
386
+ for (const [fileName, source] of Object.entries(assets)) {
387
+ if (files.includes(fileName))
388
+ this.error("Document asset collision: " + fileName);
389
+ this.emitFile({ type: "asset", fileName, source });
390
+ }
391
+ },
392
+ },
393
+ async load(id) {
394
+ if (id.split("?")[0] !== normalizePath(configuredPath) ||
395
+ !options.worker)
396
+ return;
397
+ const path = resolve(root, options.worker);
398
+ const compilation = await server?.get();
399
+ // Resolve only the selected graph: CommonJS resolution may eagerly load
400
+ // its target, and server source must never enter the client graph.
401
+ const resolved = await this.resolve(compilation ? server.localEntry : path, undefined, {
402
+ skipSelf: true,
403
+ });
404
+ if (!resolved || resolved.external)
405
+ this.error("Cannot resolve Worker entry: " + path);
406
+ if (compilation)
407
+ this.warn(compilation.message);
408
+ const entry = resolved.id;
409
+ const generated = entry + entrySuffix;
410
+ if (existsSync(generated))
411
+ this.error("Generated Worker entry conflicts with an existing file: " +
412
+ generated);
413
+ entries.set(generated, entry);
414
+ return `import Constructor from ${JSON.stringify(generated + "?worker")};
415
+ ${compilation ? `import { needsRemote, requiresRemote } from ${JSON.stringify(server.selectorEntry)};` : ""}
416
+ import { installNodeGlobals } from ${JSON.stringify(globalsPath)};
417
+ export default { createWorker: () => new Constructor(), ${compilation ? "needsRemote, requiresRemote," : ""} async loadDirect() {
418
+ const dispose = installNodeGlobals();
419
+ try {
420
+ return { handler: (await import(${JSON.stringify(entry)})).default, dispose };
421
+ } catch (error) {
422
+ dispose();
423
+ throw error;
424
+ }
425
+ } };`;
426
+ },
427
+ },
428
+ workerEntryPlugin(entries, () => root, virtualFiles),
429
+ {
430
+ name: "workers-capacitor-worker-build",
431
+ config(config) {
432
+ const previous = config.worker?.plugins;
433
+ return {
434
+ worker: {
435
+ plugins: () => [
436
+ ...(previous?.() ?? []),
437
+ serverPlugin(),
438
+ assetGuard(),
439
+ workerEntryPlugin(entries, () => root, virtualFiles),
440
+ ...compatibilityPlugins("worker"),
441
+ ],
442
+ },
443
+ };
444
+ },
445
+ },
446
+ ...compatibilityPlugins(options.worker ? false : "node"),
447
+ ];
448
+ }
@@ -0,0 +1,3 @@
1
+ import { type LocalRoute, type ServerCompilation } from "../server.js";
2
+ /** Generated Void Pages builds only. Unknown generators keep the Worker boundary. */
3
+ export declare function compileVoid(entry: string, permissions: readonly LocalRoute[], bindings: string[]): Promise<ServerCompilation | undefined>;