toiljs 0.0.4 → 0.0.5

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 (359) hide show
  1. package/.idea/prettier.xml +1 -0
  2. package/as-pect.config.js +1 -1
  3. package/build/backend/.tsbuildinfo +1 -1
  4. package/build/backend/index.js +1 -2
  5. package/build/cli/.tsbuildinfo +1 -1
  6. package/build/cli/configure.d.ts +15 -0
  7. package/build/cli/configure.js +201 -0
  8. package/build/cli/create.d.ts +4 -0
  9. package/build/cli/create.js +168 -57
  10. package/build/cli/features.d.ts +23 -0
  11. package/build/cli/features.js +85 -0
  12. package/build/cli/index.js +42 -2
  13. package/build/cli/proc.d.ts +1 -0
  14. package/build/cli/proc.js +11 -0
  15. package/build/cli/ui.js +1 -2
  16. package/build/cli/validate.d.ts +4 -0
  17. package/build/cli/validate.js +19 -0
  18. package/build/client/.tsbuildinfo +1 -1
  19. package/build/client/Link.d.ts +8 -0
  20. package/build/client/Link.js +44 -0
  21. package/build/client/NavLink.d.ts +14 -0
  22. package/build/client/NavLink.js +37 -0
  23. package/build/client/Router.d.ts +7 -0
  24. package/build/client/Router.js +55 -0
  25. package/build/client/error-boundary.d.ts +16 -0
  26. package/build/client/error-boundary.js +19 -0
  27. package/build/client/head.d.ts +26 -0
  28. package/build/client/head.js +87 -0
  29. package/build/client/hooks.d.ts +17 -0
  30. package/build/client/hooks.js +48 -0
  31. package/build/client/index.d.ts +14 -2
  32. package/build/client/index.js +8 -1
  33. package/build/client/lazy.d.ts +16 -0
  34. package/build/client/lazy.js +53 -0
  35. package/build/client/match.js +7 -0
  36. package/build/client/mount.d.ts +2 -0
  37. package/build/client/mount.js +13 -0
  38. package/build/client/navigation.d.ts +13 -0
  39. package/build/client/navigation.js +97 -0
  40. package/build/client/params-context.d.ts +2 -0
  41. package/build/client/params-context.js +2 -0
  42. package/build/client/prefetch.d.ts +11 -0
  43. package/build/client/prefetch.js +100 -0
  44. package/build/client/scroll.d.ts +8 -0
  45. package/build/client/scroll.js +36 -0
  46. package/build/client/types.d.ts +27 -0
  47. package/build/client/types.js +1 -0
  48. package/build/compiler/.tsbuildinfo +1 -1
  49. package/build/compiler/config.d.ts +2 -0
  50. package/build/compiler/config.js +4 -1
  51. package/build/compiler/docs.d.ts +10 -0
  52. package/build/compiler/docs.js +59 -0
  53. package/build/compiler/generate.js +134 -16
  54. package/build/compiler/index.d.ts +4 -2
  55. package/build/compiler/index.js +4 -3
  56. package/build/compiler/plugin.js +2 -1
  57. package/build/compiler/routes.js +5 -1
  58. package/build/compiler/vite.d.ts +1 -1
  59. package/build/compiler/vite.js +17 -1
  60. package/build/io/.tsbuildinfo +1 -1
  61. package/build/io/BinaryWriter.js +2 -2
  62. package/eslint.config.js +1 -1
  63. package/examples/basic/.toil/docs/cli.md +3 -0
  64. package/examples/basic/.toil/docs/client.md +3 -0
  65. package/examples/basic/.toil/docs/index.md +3 -0
  66. package/examples/basic/.toil/docs/routing.md +3 -0
  67. package/examples/basic/.toil/docs/server.md +3 -0
  68. package/examples/basic/.toil/docs/styling.md +3 -0
  69. package/examples/basic/.toil/entry.tsx +3 -8
  70. package/examples/basic/.toil/globals.ts +6 -0
  71. package/examples/basic/.toil/index.html +16 -12
  72. package/examples/basic/.toil/public/images/.gitkeep +1 -0
  73. package/examples/basic/.toil/public/images/logo.svg +37 -0
  74. package/examples/basic/.toil/public/robots.txt +2 -0
  75. package/examples/basic/.toil/routes.ts +9 -7
  76. package/examples/basic/build/client/assets/404-Bq0jNTUo.js +1 -0
  77. package/examples/basic/build/client/assets/_...slug_-CXKf6qnB.js +1 -0
  78. package/examples/basic/build/client/assets/_id_-BadAyQnb.js +1 -0
  79. package/examples/basic/build/client/assets/about-BOhoEcEO.js +1 -0
  80. package/examples/basic/build/client/assets/get-started-BIXpcjkT.js +9 -0
  81. package/examples/basic/build/client/assets/index-BmqcTaBB.js +1 -0
  82. package/examples/basic/build/client/assets/io-DEVjjaJj.js +1 -0
  83. package/examples/basic/build/client/assets/layout-DJegirdz.js +1 -0
  84. package/examples/basic/build/client/assets/react-DEQrz1q7.js +9 -0
  85. package/examples/basic/build/client/assets/rolldown-runtime-KL5VtC6j.js +1 -0
  86. package/examples/basic/build/client/assets/routes-BYWn6TxK.js +1 -0
  87. package/examples/basic/build/client/css/style.css +2 -0
  88. package/examples/basic/build/client/images/.gitkeep +1 -0
  89. package/examples/basic/build/client/images/logo.svg +37 -0
  90. package/examples/basic/build/client/index.html +17 -0
  91. package/examples/basic/build/client/robots.txt +2 -0
  92. package/examples/basic/client/404.tsx +2 -5
  93. package/examples/basic/client/components/.gitkeep +1 -0
  94. package/examples/basic/client/components/Footer.tsx +8 -0
  95. package/examples/basic/client/layout.tsx +39 -26
  96. package/examples/basic/client/public/images/.gitkeep +1 -0
  97. package/examples/basic/client/public/images/logo.svg +37 -0
  98. package/examples/basic/client/public/index.html +15 -0
  99. package/examples/basic/client/public/robots.txt +2 -0
  100. package/examples/basic/client/routes/about.tsx +1 -3
  101. package/examples/basic/client/routes/blog/[id].tsx +2 -4
  102. package/examples/basic/client/routes/docs/[...slug].tsx +3 -6
  103. package/examples/basic/client/routes/get-started.tsx +84 -0
  104. package/examples/basic/client/routes/index.tsx +74 -7
  105. package/examples/basic/client/routes/io.tsx +3 -7
  106. package/examples/basic/client/styles/main.css +461 -0
  107. package/examples/basic/client/toil.tsx +7 -0
  108. package/examples/basic/node_modules/.bin/toilinit +16 -0
  109. package/examples/basic/node_modules/.bin/toilinit.cmd +17 -0
  110. package/examples/basic/node_modules/.bin/toilinit.ps1 +28 -0
  111. package/examples/basic/node_modules/.bin/toilscript +16 -0
  112. package/examples/basic/node_modules/.bin/toilscript.cmd +17 -0
  113. package/examples/basic/node_modules/.bin/toilscript.ps1 +28 -0
  114. package/examples/basic/node_modules/.bin/wasm-as +16 -0
  115. package/examples/basic/node_modules/.bin/wasm-as.cmd +17 -0
  116. package/examples/basic/node_modules/.bin/wasm-as.ps1 +28 -0
  117. package/examples/basic/node_modules/.bin/wasm-ctor-eval +16 -0
  118. package/examples/basic/node_modules/.bin/wasm-ctor-eval.cmd +17 -0
  119. package/examples/basic/node_modules/.bin/wasm-ctor-eval.ps1 +28 -0
  120. package/examples/basic/node_modules/.bin/wasm-dis +16 -0
  121. package/examples/basic/node_modules/.bin/wasm-dis.cmd +17 -0
  122. package/examples/basic/node_modules/.bin/wasm-dis.ps1 +28 -0
  123. package/examples/basic/node_modules/.bin/wasm-merge +16 -0
  124. package/examples/basic/node_modules/.bin/wasm-merge.cmd +17 -0
  125. package/examples/basic/node_modules/.bin/wasm-merge.ps1 +28 -0
  126. package/examples/basic/node_modules/.bin/wasm-metadce +16 -0
  127. package/examples/basic/node_modules/.bin/wasm-metadce.cmd +17 -0
  128. package/examples/basic/node_modules/.bin/wasm-metadce.ps1 +28 -0
  129. package/examples/basic/node_modules/.bin/wasm-opt +16 -0
  130. package/examples/basic/node_modules/.bin/wasm-opt.cmd +17 -0
  131. package/examples/basic/node_modules/.bin/wasm-opt.ps1 +28 -0
  132. package/examples/basic/node_modules/.bin/wasm-reduce +16 -0
  133. package/examples/basic/node_modules/.bin/wasm-reduce.cmd +17 -0
  134. package/examples/basic/node_modules/.bin/wasm-reduce.ps1 +28 -0
  135. package/examples/basic/node_modules/.bin/wasm-shell +16 -0
  136. package/examples/basic/node_modules/.bin/wasm-shell.cmd +17 -0
  137. package/examples/basic/node_modules/.bin/wasm-shell.ps1 +28 -0
  138. package/examples/basic/node_modules/.bin/wasm2js +16 -0
  139. package/examples/basic/node_modules/.bin/wasm2js.cmd +17 -0
  140. package/examples/basic/node_modules/.bin/wasm2js.ps1 +28 -0
  141. package/examples/basic/node_modules/.package-lock.json +49 -1
  142. package/examples/basic/node_modules/.vite/deps/_metadata.json +9 -9
  143. package/examples/basic/node_modules/binaryen/LICENSE +201 -0
  144. package/examples/basic/node_modules/binaryen/README.md +1362 -0
  145. package/examples/basic/node_modules/binaryen/bin/package.json +3 -0
  146. package/examples/basic/node_modules/binaryen/bin/wasm-as +0 -0
  147. package/examples/basic/node_modules/binaryen/bin/wasm-ctor-eval +0 -0
  148. package/examples/basic/node_modules/binaryen/bin/wasm-dis +0 -0
  149. package/examples/basic/node_modules/binaryen/bin/wasm-merge +0 -0
  150. package/examples/basic/node_modules/binaryen/bin/wasm-metadce +0 -0
  151. package/examples/basic/node_modules/binaryen/bin/wasm-opt +0 -0
  152. package/examples/basic/node_modules/binaryen/bin/wasm-reduce +0 -0
  153. package/examples/basic/node_modules/binaryen/bin/wasm-shell +0 -0
  154. package/examples/basic/node_modules/binaryen/bin/wasm2js +0 -0
  155. package/examples/basic/node_modules/binaryen/index.d.ts +2371 -0
  156. package/examples/basic/node_modules/binaryen/index.js +30552 -0
  157. package/examples/basic/node_modules/binaryen/package.json +50 -0
  158. package/examples/basic/node_modules/long/LICENSE +202 -0
  159. package/examples/basic/node_modules/long/README.md +286 -0
  160. package/examples/basic/node_modules/long/index.d.ts +2 -0
  161. package/examples/basic/node_modules/long/index.js +1581 -0
  162. package/examples/basic/node_modules/long/package.json +58 -0
  163. package/examples/basic/node_modules/long/types.d.ts +474 -0
  164. package/examples/basic/node_modules/long/umd/index.d.ts +3 -0
  165. package/examples/basic/node_modules/long/umd/index.js +1622 -0
  166. package/examples/basic/node_modules/long/umd/package.json +3 -0
  167. package/examples/basic/node_modules/long/umd/types.d.ts +474 -0
  168. package/examples/basic/node_modules/toilscript/LICENSE +201 -0
  169. package/examples/basic/node_modules/toilscript/NOTICE +94 -0
  170. package/examples/basic/node_modules/toilscript/README.md +66 -0
  171. package/examples/basic/node_modules/toilscript/bin/toilinit.js +468 -0
  172. package/examples/basic/node_modules/toilscript/bin/toilscript.js +35 -0
  173. package/examples/basic/node_modules/toilscript/dist/cli.d.ts +4 -0
  174. package/examples/basic/node_modules/toilscript/dist/cli.generated.d.ts +10027 -0
  175. package/examples/basic/node_modules/toilscript/dist/cli.js +24474 -0
  176. package/examples/basic/node_modules/toilscript/dist/cli.js.map +7 -0
  177. package/examples/basic/node_modules/toilscript/dist/importmap.json +9 -0
  178. package/examples/basic/node_modules/toilscript/dist/toilscript.d.ts +4 -0
  179. package/examples/basic/node_modules/toilscript/dist/toilscript.generated.d.ts +11242 -0
  180. package/examples/basic/node_modules/toilscript/dist/toilscript.js +337 -0
  181. package/examples/basic/node_modules/toilscript/dist/toilscript.js.map +7 -0
  182. package/examples/basic/node_modules/toilscript/dist/transform.cjs +1 -0
  183. package/examples/basic/node_modules/toilscript/dist/transform.d.ts +1 -0
  184. package/examples/basic/node_modules/toilscript/dist/transform.js +1 -0
  185. package/examples/basic/node_modules/toilscript/dist/web.js +22 -0
  186. package/examples/basic/node_modules/toilscript/lib/binaryen.d.ts +2 -0
  187. package/examples/basic/node_modules/toilscript/lib/binaryen.js +2 -0
  188. package/examples/basic/node_modules/toilscript/package.json +115 -0
  189. package/examples/basic/node_modules/toilscript/std/README.md +6 -0
  190. package/examples/basic/node_modules/toilscript/std/assembly/array.ts +550 -0
  191. package/examples/basic/node_modules/toilscript/std/assembly/arraybuffer.ts +77 -0
  192. package/examples/basic/node_modules/toilscript/std/assembly/atomics.ts +127 -0
  193. package/examples/basic/node_modules/toilscript/std/assembly/bindings/asyncify.ts +16 -0
  194. package/examples/basic/node_modules/toilscript/std/assembly/bindings/dom.ts +291 -0
  195. package/examples/basic/node_modules/toilscript/std/assembly/bindings/node.ts +6 -0
  196. package/examples/basic/node_modules/toilscript/std/assembly/bitflags.ts +53 -0
  197. package/examples/basic/node_modules/toilscript/std/assembly/builtins.ts +2650 -0
  198. package/examples/basic/node_modules/toilscript/std/assembly/byteslice.ts +177 -0
  199. package/examples/basic/node_modules/toilscript/std/assembly/compat.ts +2 -0
  200. package/examples/basic/node_modules/toilscript/std/assembly/console.ts +42 -0
  201. package/examples/basic/node_modules/toilscript/std/assembly/crypto.ts +9 -0
  202. package/examples/basic/node_modules/toilscript/std/assembly/dataview.ts +181 -0
  203. package/examples/basic/node_modules/toilscript/std/assembly/date.ts +375 -0
  204. package/examples/basic/node_modules/toilscript/std/assembly/diagnostics.ts +11 -0
  205. package/examples/basic/node_modules/toilscript/std/assembly/encoding.ts +151 -0
  206. package/examples/basic/node_modules/toilscript/std/assembly/endian.ts +45 -0
  207. package/examples/basic/node_modules/toilscript/std/assembly/error.ts +44 -0
  208. package/examples/basic/node_modules/toilscript/std/assembly/fixedarray.ts +173 -0
  209. package/examples/basic/node_modules/toilscript/std/assembly/fixedmap.ts +326 -0
  210. package/examples/basic/node_modules/toilscript/std/assembly/fixedset.ts +275 -0
  211. package/examples/basic/node_modules/toilscript/std/assembly/function.ts +42 -0
  212. package/examples/basic/node_modules/toilscript/std/assembly/index.d.ts +2892 -0
  213. package/examples/basic/node_modules/toilscript/std/assembly/iterator.ts +35 -0
  214. package/examples/basic/node_modules/toilscript/std/assembly/map.ts +269 -0
  215. package/examples/basic/node_modules/toilscript/std/assembly/math.ts +3289 -0
  216. package/examples/basic/node_modules/toilscript/std/assembly/memory.ts +123 -0
  217. package/examples/basic/node_modules/toilscript/std/assembly/number.ts +388 -0
  218. package/examples/basic/node_modules/toilscript/std/assembly/object.ts +36 -0
  219. package/examples/basic/node_modules/toilscript/std/assembly/performance.ts +9 -0
  220. package/examples/basic/node_modules/toilscript/std/assembly/pointer.ts +80 -0
  221. package/examples/basic/node_modules/toilscript/std/assembly/polyfills.ts +27 -0
  222. package/examples/basic/node_modules/toilscript/std/assembly/process.ts +50 -0
  223. package/examples/basic/node_modules/toilscript/std/assembly/reference.ts +48 -0
  224. package/examples/basic/node_modules/toilscript/std/assembly/regexp.ts +12 -0
  225. package/examples/basic/node_modules/toilscript/std/assembly/rt/README.md +83 -0
  226. package/examples/basic/node_modules/toilscript/std/assembly/rt/common.ts +81 -0
  227. package/examples/basic/node_modules/toilscript/std/assembly/rt/index-incremental.ts +2 -0
  228. package/examples/basic/node_modules/toilscript/std/assembly/rt/index-memory.ts +1 -0
  229. package/examples/basic/node_modules/toilscript/std/assembly/rt/index-minimal.ts +2 -0
  230. package/examples/basic/node_modules/toilscript/std/assembly/rt/index-stub.ts +1 -0
  231. package/examples/basic/node_modules/toilscript/std/assembly/rt/index.d.ts +37 -0
  232. package/examples/basic/node_modules/toilscript/std/assembly/rt/itcms.ts +419 -0
  233. package/examples/basic/node_modules/toilscript/std/assembly/rt/memory-runtime.ts +94 -0
  234. package/examples/basic/node_modules/toilscript/std/assembly/rt/rtrace.ts +15 -0
  235. package/examples/basic/node_modules/toilscript/std/assembly/rt/stub.ts +133 -0
  236. package/examples/basic/node_modules/toilscript/std/assembly/rt/tcms.ts +254 -0
  237. package/examples/basic/node_modules/toilscript/std/assembly/rt/tlsf.ts +592 -0
  238. package/examples/basic/node_modules/toilscript/std/assembly/rt.ts +90 -0
  239. package/examples/basic/node_modules/toilscript/std/assembly/set.ts +225 -0
  240. package/examples/basic/node_modules/toilscript/std/assembly/shared/feature.ts +68 -0
  241. package/examples/basic/node_modules/toilscript/std/assembly/shared/runtime.ts +13 -0
  242. package/examples/basic/node_modules/toilscript/std/assembly/shared/target.ts +11 -0
  243. package/examples/basic/node_modules/toilscript/std/assembly/shared/tsconfig.json +11 -0
  244. package/examples/basic/node_modules/toilscript/std/assembly/shared/typeinfo.ts +72 -0
  245. package/examples/basic/node_modules/toilscript/std/assembly/staticarray.ts +423 -0
  246. package/examples/basic/node_modules/toilscript/std/assembly/string.ts +850 -0
  247. package/examples/basic/node_modules/toilscript/std/assembly/symbol.ts +114 -0
  248. package/examples/basic/node_modules/toilscript/std/assembly/table.ts +16 -0
  249. package/examples/basic/node_modules/toilscript/std/assembly/toilscript.ts +16 -0
  250. package/examples/basic/node_modules/toilscript/std/assembly/tsconfig.json +6 -0
  251. package/examples/basic/node_modules/toilscript/std/assembly/typedarray.ts +1954 -0
  252. package/examples/basic/node_modules/toilscript/std/assembly/uri.ts +17 -0
  253. package/examples/basic/node_modules/toilscript/std/assembly/util/bytes.ts +107 -0
  254. package/examples/basic/node_modules/toilscript/std/assembly/util/casemap.ts +497 -0
  255. package/examples/basic/node_modules/toilscript/std/assembly/util/error.ts +58 -0
  256. package/examples/basic/node_modules/toilscript/std/assembly/util/hash.ts +117 -0
  257. package/examples/basic/node_modules/toilscript/std/assembly/util/math.ts +1922 -0
  258. package/examples/basic/node_modules/toilscript/std/assembly/util/memory.ts +290 -0
  259. package/examples/basic/node_modules/toilscript/std/assembly/util/number.ts +873 -0
  260. package/examples/basic/node_modules/toilscript/std/assembly/util/sort.ts +313 -0
  261. package/examples/basic/node_modules/toilscript/std/assembly/util/string.ts +1202 -0
  262. package/examples/basic/node_modules/toilscript/std/assembly/util/uri.ts +275 -0
  263. package/examples/basic/node_modules/toilscript/std/assembly/vector.ts +4 -0
  264. package/examples/basic/node_modules/toilscript/std/assembly.json +16 -0
  265. package/examples/basic/node_modules/toilscript/std/portable/index.d.ts +461 -0
  266. package/examples/basic/node_modules/toilscript/std/portable/index.js +416 -0
  267. package/examples/basic/node_modules/toilscript/std/portable.json +11 -0
  268. package/examples/basic/node_modules/toilscript/std/types/assembly/index.d.ts +1 -0
  269. package/examples/basic/node_modules/toilscript/std/types/assembly/package.json +3 -0
  270. package/examples/basic/node_modules/toilscript/std/types/portable/index.d.ts +1 -0
  271. package/examples/basic/node_modules/toilscript/std/types/portable/package.json +3 -0
  272. package/examples/basic/node_modules/toilscript/tsconfig-base.json +13 -0
  273. package/examples/basic/node_modules/toilscript/util/README.md +23 -0
  274. package/examples/basic/node_modules/toilscript/util/browser/fs.js +1 -0
  275. package/examples/basic/node_modules/toilscript/util/browser/module.js +5 -0
  276. package/examples/basic/node_modules/toilscript/util/browser/path.js +520 -0
  277. package/examples/basic/node_modules/toilscript/util/browser/process.js +59 -0
  278. package/examples/basic/node_modules/toilscript/util/browser/url.js +23 -0
  279. package/examples/basic/node_modules/toilscript/util/cpu.d.ts +9 -0
  280. package/examples/basic/node_modules/toilscript/util/cpu.js +42 -0
  281. package/examples/basic/node_modules/toilscript/util/find.d.ts +6 -0
  282. package/examples/basic/node_modules/toilscript/util/find.js +20 -0
  283. package/examples/basic/node_modules/toilscript/util/node.d.ts +21 -0
  284. package/examples/basic/node_modules/toilscript/util/node.js +34 -0
  285. package/examples/basic/node_modules/toilscript/util/options.d.ts +70 -0
  286. package/examples/basic/node_modules/toilscript/util/options.js +262 -0
  287. package/examples/basic/node_modules/toilscript/util/terminal.d.ts +52 -0
  288. package/examples/basic/node_modules/toilscript/util/terminal.js +35 -0
  289. package/examples/basic/node_modules/toilscript/util/text.d.ts +26 -0
  290. package/examples/basic/node_modules/toilscript/util/text.js +114 -0
  291. package/examples/basic/node_modules/toilscript/util/tsconfig.json +9 -0
  292. package/examples/basic/node_modules/toilscript/util/web.d.ts +11 -0
  293. package/examples/basic/node_modules/toilscript/util/web.js +33 -0
  294. package/examples/basic/package-lock.json +50 -1
  295. package/examples/basic/package.json +5 -2
  296. package/examples/basic/server/index.ts +3 -0
  297. package/examples/basic/server/main.ts +6 -0
  298. package/examples/basic/server/tsconfig.json +7 -0
  299. package/examples/basic/toil-env.d.ts +20 -1
  300. package/examples/basic/toil.config.ts +2 -5
  301. package/examples/basic/toilconfig.json +30 -0
  302. package/package.json +1 -1
  303. package/presets/eslint.js +2 -7
  304. package/presets/no-uint8array-tostring.js +4 -5
  305. package/presets/prettier.json +8 -1
  306. package/src/backend/index.ts +11 -18
  307. package/src/cli/configure.ts +272 -0
  308. package/src/cli/create.ts +227 -69
  309. package/src/cli/features.ts +128 -0
  310. package/src/cli/index.ts +44 -3
  311. package/src/cli/proc.ts +20 -0
  312. package/src/cli/ui.ts +4 -6
  313. package/src/cli/validate.ts +31 -0
  314. package/src/client/Link.tsx +99 -0
  315. package/src/client/NavLink.tsx +86 -0
  316. package/src/client/Router.tsx +95 -0
  317. package/src/client/error-boundary.tsx +43 -0
  318. package/src/client/head.ts +140 -0
  319. package/src/client/hooks.ts +115 -0
  320. package/src/client/index.ts +35 -5
  321. package/src/client/lazy.ts +93 -0
  322. package/src/client/match.ts +11 -3
  323. package/src/client/mount.tsx +28 -0
  324. package/src/client/navigation.ts +142 -0
  325. package/src/client/params-context.ts +10 -0
  326. package/src/client/prefetch.ts +130 -0
  327. package/src/client/scroll.ts +53 -0
  328. package/src/client/types.ts +36 -0
  329. package/src/compiler/config.ts +15 -8
  330. package/src/compiler/docs.ts +87 -0
  331. package/src/compiler/generate.ts +164 -23
  332. package/src/compiler/index.ts +6 -4
  333. package/src/compiler/plugin.ts +3 -1
  334. package/src/compiler/routes.ts +13 -7
  335. package/src/compiler/vite.ts +28 -5
  336. package/src/io/BinaryReader.ts +1 -5
  337. package/src/io/BinaryWriter.ts +3 -3
  338. package/src/server/index.ts +3 -4
  339. package/src/server/tsconfig.json +4 -0
  340. package/test/configure.test.ts +90 -0
  341. package/test/features.test.ts +111 -0
  342. package/test/head.test.ts +35 -0
  343. package/test/io.test.ts +8 -0
  344. package/test/navlink.test.ts +28 -0
  345. package/test/routes.test.ts +15 -0
  346. package/test/validate.test.ts +42 -0
  347. package/vitest.config.ts +1 -1
  348. package/examples/basic/dist/assets/404-D1bS2aH_.js +0 -1
  349. package/examples/basic/dist/assets/_...slug_-wR3shlWn.js +0 -1
  350. package/examples/basic/dist/assets/_id_-EWYvHfi2.js +0 -1
  351. package/examples/basic/dist/assets/about-Ddvj1tjF.js +0 -1
  352. package/examples/basic/dist/assets/index-CdG0me90.js +0 -1
  353. package/examples/basic/dist/assets/io-CODNJU57.js +0 -1
  354. package/examples/basic/dist/assets/layout-C15ZTPYI.js +0 -1
  355. package/examples/basic/dist/assets/react-JbAfoxYe.js +0 -9
  356. package/examples/basic/dist/assets/rolldown-runtime-1VNLd2iN.js +0 -1
  357. package/examples/basic/dist/assets/routes-GoydenoY.js +0 -1
  358. package/examples/basic/dist/index.html +0 -12
  359. package/src/client/runtime.tsx +0 -190
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @fileoverview Node.js polyfills.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ export const isNode = Object.prototype.toString.call(typeof globalThis.process !== 'undefined' ? globalThis.process : 0) === '[object process]';
7
+
8
+ var fs;
9
+ var module;
10
+ var path;
11
+ var process;
12
+ var url;
13
+
14
+ if (isNode) {
15
+ fs = await import("fs");
16
+ module = await import("module");
17
+ path = await import("path");
18
+ process = globalThis.process;
19
+ url = await import("url");
20
+ } else {
21
+ fs = await import("./browser/fs.js");
22
+ module = await import("./browser/module.js");
23
+ path = await import("./browser/path.js");
24
+ process = await import("./browser/process.js");
25
+ url = await import("./browser/url.js");
26
+ }
27
+
28
+ export {
29
+ fs,
30
+ module,
31
+ path,
32
+ process,
33
+ url
34
+ };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @fileoverview Command line options utility definitions.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ /** A set of options. */
7
+ export interface OptionSet {
8
+ [key: string]: number | string
9
+ }
10
+
11
+ /** Command line option description. */
12
+ export interface OptionDescription {
13
+ /** Textual description. */
14
+ description?: string | string[],
15
+ /** Data type. One of (b)oolean [default], (i)nteger, (f)loat or (s)tring. Uppercase means multiple values. */
16
+ type?: "b" | "i" | "f" | "s" | "I" | "F" | "S",
17
+ /** Substituted options, if any. */
18
+ value?: OptionSet,
19
+ /** Short alias, if any. */
20
+ alias?: string
21
+ /** The default value, if any. */
22
+ default?: string | number | boolean | string[] | number[];
23
+ /** The category this option belongs in. */
24
+ category?: string;
25
+ }
26
+
27
+ /** Configuration object. */
28
+ export interface Config {
29
+ [key: string]: OptionDescription;
30
+ }
31
+
32
+ /** Parsing result. */
33
+ export interface Result {
34
+ /** Parsed options. */
35
+ options: OptionSet,
36
+ /** Unknown options. */
37
+ unknown: string[],
38
+ /** Normal arguments. */
39
+ arguments: string[],
40
+ /** Trailing arguments. */
41
+ trailing: string[]
42
+ }
43
+
44
+ /** Parses the specified command line arguments according to the given configuration. */
45
+ export function parse(argv: string[], config: Config, propagateDefaults?: boolean): Result;
46
+
47
+ /** Help formatting options. */
48
+ export interface HelpOptions {
49
+ /** Leading indent. Defaults to 2. */
50
+ indent?: number,
51
+ /** Table padding. Defaults to 24. */
52
+ padding?: number,
53
+ /** End of line character. Defaults to "\n". */
54
+ eol?: string
55
+ }
56
+
57
+ /** Generates the help text for the specified configuration. */
58
+ export function help(config: Config, options?: HelpOptions): string;
59
+
60
+ /** Merges two sets of options into one, preferring the current over the parent set. */
61
+ export function merge(config: Config, currentOptions: OptionSet, parentOptions: OptionSet, parentBaseDir: string): OptionSet;
62
+
63
+ /** Normalizes a path. */
64
+ export function normalizePath(path: string): string;
65
+
66
+ /** Resolves a single relative path. Keeps absolute paths, otherwise prepends baseDir. */
67
+ export function resolvePath(path: string, baseDir: string, useNodeResolution?: boolean): string;
68
+
69
+ /** Populates default values on a parsed options result. */
70
+ export function addDefaults(config: Config, options: OptionSet): void;
@@ -0,0 +1,262 @@
1
+ /**
2
+ * @fileoverview Command line options utility.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ import { path, module } from "./node.js";
7
+ import { stdoutColors } from "./terminal.js";
8
+
9
+ const require = module.createRequire(import.meta.url);
10
+
11
+ // type | meaning
12
+ // -----|---------------
13
+ // b | boolean
14
+ // i | integer
15
+ // f | float
16
+ // s | string
17
+ // I | integer array
18
+ // F | float array
19
+ // S | string array
20
+
21
+ /** Parses the specified command line arguments according to the given configuration. */
22
+ export function parse(argv, config, propagateDefaults = true) {
23
+ var options = {};
24
+ var unknown = [];
25
+ var args = [];
26
+ var trailing = [];
27
+
28
+ // make an alias map and initialize defaults
29
+ var aliases = {};
30
+ Object.keys(config).forEach(key => {
31
+ if (key.startsWith(" ")) return;
32
+ var option = config[key];
33
+ if (option.alias != null) {
34
+ if (typeof option.alias === "string") aliases[option.alias] = key;
35
+ else if (Array.isArray(option.alias)) option.alias.forEach(alias => aliases[alias] = key);
36
+ }
37
+ if (propagateDefaults && option.default != null) options[key] = option.default;
38
+ });
39
+
40
+ // iterate over argv
41
+ for (var i = 0, k = (argv = argv.slice()).length; i < k; ++i) {
42
+ let arg = argv[i];
43
+ if (arg == "--") { ++i; break; }
44
+ let match = /^(?:(-\w)(?:=(.*))?|(--\w{2,})(?:=(.*))?)$/.exec(arg), option, key;
45
+ if (match) {
46
+ if (config[arg]) option = config[key = arg]; // exact
47
+ else if (match[1] != null) { // alias
48
+ option = config[key = aliases[match[1].substring(1)]];
49
+ if (option && match[2] != null) argv[i--] = match[2];
50
+ } else if (match[3] != null) { // full
51
+ option = config[key = match[3].substring(2)];
52
+ if (option && match[4] != null) argv[i--] = match[4];
53
+ }
54
+ } else {
55
+ if (arg.charCodeAt(0) == 45) option = config[key = arg]; // exact
56
+ else { args.push(arg); continue; } // argument
57
+ }
58
+ if (option) {
59
+ if (option.value) {
60
+ // alias setting fixed values
61
+ Object.keys(option.value).forEach(k => options[k] = option.value[k]);
62
+ } else if (option.type == null || option.type === "b") {
63
+ // boolean flag not taking a value
64
+ options[key] = true;
65
+ } else {
66
+ if (i + 1 < argv.length && argv[i + 1].charCodeAt(0) != 45) {
67
+ // non-boolean with given value
68
+ switch (option.type) {
69
+ case "i": options[key] = parseInt(argv[++i], 10); break;
70
+ case "I": options[key] = (options[key] || []).concat(parseInt(argv[++i], 10)); break;
71
+ case "f": options[key] = parseFloat(argv[++i]); break;
72
+ case "F": options[key] = (options[key] || []).concat(parseFloat(argv[++i])); break;
73
+ case "s": options[key] = String(argv[++i]); break;
74
+ case "S": options[key] = (options[key] || []).concat(argv[++i].split(",")); break;
75
+ default: unknown.push(arg); --i;
76
+ }
77
+ } else {
78
+ // non-boolean with omitted value
79
+ switch (option.type) {
80
+ case "i":
81
+ case "f": options[key] = option.default || 0; break;
82
+ case "s": options[key] = option.default || ""; break;
83
+ case "I":
84
+ case "F":
85
+ case "S": options[key] = option.default || []; break;
86
+ default: unknown.push(arg);
87
+ }
88
+ }
89
+ }
90
+ } else unknown.push(arg);
91
+ }
92
+ while (i < k) trailing.push(argv[i++]); // trailing
93
+ if (propagateDefaults) addDefaults(config, options);
94
+
95
+ return { options, unknown, arguments: args, trailing };
96
+ }
97
+
98
+ /** Generates the help text for the specified configuration. */
99
+ export function help(config, options) {
100
+ if (!options) options = {};
101
+ var indent = options.indent || 2;
102
+ var padding = options.padding || 24;
103
+ var eol = options.eol || "\n";
104
+ var sbCategories = {};
105
+ var sbOther = [];
106
+ Object.keys(config).forEach(key => {
107
+ var option = config[key];
108
+ if (option.description == null) return;
109
+ var text = "";
110
+ while (text.length < indent) text += " ";
111
+ text += "--" + key;
112
+ if (option.alias) text += ", -" + option.alias;
113
+ while (text.length < padding) text += " ";
114
+ var sb;
115
+ if (!options.noCategories && option.category) {
116
+ if (!(sb = sbCategories[option.category])) {
117
+ sbCategories[option.category] = sb = [];
118
+ }
119
+ } else {
120
+ sb = sbOther;
121
+ }
122
+ if (Array.isArray(option.description)) {
123
+ sb.push(text + option.description[0] + option.description.slice(1).map(line => {
124
+ for (let i = 0; i < padding; ++i) line = " " + line;
125
+ return eol + line;
126
+ }).join(""));
127
+ } else sb.push(text + option.description);
128
+ });
129
+ var sb = [];
130
+ var hasCategories = false;
131
+ Object.keys(sbCategories).forEach(category => {
132
+ hasCategories = true;
133
+ sb.push(eol + " " + stdoutColors.gray(category) + eol);
134
+ sb.push(sbCategories[category].join(eol));
135
+ });
136
+ if (hasCategories && sbOther.length) {
137
+ sb.push(eol + " " + stdoutColors.gray("Other") + eol);
138
+ }
139
+ sb.push(sbOther.join(eol));
140
+ return sb.join(eol);
141
+ }
142
+
143
+ /** Sanitizes an option value to be a valid value of the option's type. */
144
+ function sanitizeValue(value, type) {
145
+ if (value != null) {
146
+ switch (type) {
147
+ case undefined:
148
+ case "b": return Boolean(value);
149
+ case "i": return Math.trunc(value) || 0;
150
+ case "f": return Number(value) || 0;
151
+ case "s": {
152
+ if (value === true) return "";
153
+ if (value === false) return null;
154
+ return String(value);
155
+ }
156
+ case "I": {
157
+ if (!Array.isArray(value)) value = [ value ];
158
+ return value.map(v => Math.trunc(v) || 0);
159
+ }
160
+ case "F": {
161
+ if (!Array.isArray(value)) value = [ value ];
162
+ return value.map(v => Number(v) || 0);
163
+ }
164
+ case "S": {
165
+ if (!Array.isArray(value)) value = [ value ];
166
+ return value.map(String);
167
+ }
168
+ }
169
+ }
170
+ return undefined;
171
+ }
172
+
173
+ /** Merges two sets of options into one, preferring the current over the parent set. */
174
+ export function merge(config, currentOptions, parentOptions, parentBaseDir) {
175
+ const mergedOptions = {};
176
+ for (const [key, { type, mutuallyExclusive, isPath, useNodeResolution, cliOnly }] of Object.entries(config)) {
177
+ let currentValue = sanitizeValue(currentOptions[key], type);
178
+ let parentValue = sanitizeValue(parentOptions[key], type);
179
+ if (currentValue == null) {
180
+ if (parentValue != null) {
181
+ // only parent value present
182
+ if (cliOnly) continue;
183
+ if (Array.isArray(parentValue)) {
184
+ let exclude;
185
+ if (isPath) {
186
+ parentValue = parentValue.map(value => resolvePath(value, parentBaseDir, useNodeResolution));
187
+ }
188
+ if (mutuallyExclusive != null && (exclude = currentOptions[mutuallyExclusive])) {
189
+ mergedOptions[key] = parentValue.filter(value => !exclude.includes(value));
190
+ } else {
191
+ mergedOptions[key] = parentValue.slice();
192
+ }
193
+ } else {
194
+ if (isPath) {
195
+ parentValue = resolvePath(parentValue, parentBaseDir, useNodeResolution);
196
+ }
197
+ mergedOptions[key] = parentValue;
198
+ }
199
+ }
200
+ } else if (parentValue == null) {
201
+ // only current value present
202
+ if (Array.isArray(currentValue)) {
203
+ mergedOptions[key] = currentValue.slice();
204
+ } else {
205
+ mergedOptions[key] = currentValue;
206
+ }
207
+ } else {
208
+ // both current and parent values present
209
+ if (Array.isArray(currentValue)) {
210
+ if (cliOnly) {
211
+ mergedOptions[key] = currentValue.slice();
212
+ continue;
213
+ }
214
+ let exclude;
215
+ if (isPath) {
216
+ parentValue = parentValue.map(value => resolvePath(value, parentBaseDir, useNodeResolution));
217
+ }
218
+ if (mutuallyExclusive != null && (exclude = currentOptions[mutuallyExclusive])) {
219
+ mergedOptions[key] = [
220
+ ...currentValue,
221
+ ...parentValue.filter(value => !currentValue.includes(value) && !exclude.includes(value))
222
+ ];
223
+ } else {
224
+ mergedOptions[key] = [
225
+ ...currentValue,
226
+ ...parentValue.filter(value => !currentValue.includes(value)) // dedup
227
+ ];
228
+ }
229
+ } else {
230
+ mergedOptions[key] = currentValue;
231
+ }
232
+ }
233
+ }
234
+ return mergedOptions;
235
+ }
236
+
237
+ /** Normalizes a path. */
238
+ export function normalizePath(p) {
239
+ const parsed = path.parse(p);
240
+ if (!parsed.root) {
241
+ parsed.root = "./";
242
+ }
243
+ return path.format(parsed);
244
+ }
245
+
246
+ /** Resolves a single possibly relative path. Keeps absolute paths, otherwise prepends baseDir. */
247
+ export function resolvePath(p, baseDir, useNodeResolution = false) {
248
+ if (path.isAbsolute(p)) return p;
249
+ if (useNodeResolution && !p.startsWith(".") && require.resolve) {
250
+ return require.resolve(p, { paths: [ baseDir ] });
251
+ }
252
+ return normalizePath(path.join(baseDir, p));
253
+ }
254
+
255
+ /** Populates default values on a parsed options result. */
256
+ export function addDefaults(config, options) {
257
+ for (const [key, { default: defaultValue }] of Object.entries(config)) {
258
+ if (options[key] == null && defaultValue != null) {
259
+ options[key] = defaultValue;
260
+ }
261
+ }
262
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @fileoverview Terminal colors utility definitions.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ /** Color code for gray. */
7
+ export const GRAY: string;
8
+ /** Color code for red. */
9
+ export const RED: string;
10
+ /** Color code for green. */
11
+ export const GREEN: string;
12
+ /** Color code for yellow. */
13
+ export const YELLOW: string;
14
+ /** Color code for blue. */
15
+ export const BLUE: string;
16
+ /** Color code for magenta. */
17
+ export const MAGENTA: string;
18
+ /** Color code for cyan. */
19
+ export const CYAN: string;
20
+ /** Color code for white. */
21
+ export const WHITE: string;
22
+ /** Code to reset any colors. */
23
+ export const RESET: string;
24
+
25
+ /** Color utility class. */
26
+ export class Colors {
27
+ /** Constructs a new instance for the given stream. */
28
+ constructor(stream: { isTTY: boolean });
29
+ /** Whether terminal colors are enabled. */
30
+ enabled: boolean;
31
+ /** Colors a string in gray if {@link enabled}. */
32
+ gray(text: string): string;
33
+ /** Colors a string in red if {@link enabled}. */
34
+ red(text: string): string;
35
+ /** Colors a string in green if {@link enabled}. */
36
+ green(text: string): string;
37
+ /** Colors a string in yellow if {@link enabled}. */
38
+ yellow(text: string): string;
39
+ /** Colors a string in blue if {@link enabled}. */
40
+ blue(text: string): string;
41
+ /** Colors a string in magenta if {@link enabled}. */
42
+ magenta(text: string): string;
43
+ /** Colors a string in cyan if {@link enabled}. */
44
+ cyan(text: string): string;
45
+ /** Colors a string in white if {@link enabled}. */
46
+ white(text: string): string;
47
+ }
48
+
49
+ /** Color utility for stdout. */
50
+ export const stdoutColors: Colors;
51
+ /** Color utility for stderr. */
52
+ export const stderrColors: Colors;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @fileoverview Terminal utility.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ var proc = typeof process !== "undefined" && process || {};
7
+ var isCI = proc.env && "CI" in proc.env;
8
+
9
+ export const GRAY = "\u001b[90m";
10
+ export const RED = "\u001b[91m";
11
+ export const GREEN = "\u001b[92m";
12
+ export const YELLOW = "\u001b[93m";
13
+ export const BLUE = "\u001b[94m";
14
+ export const MAGENTA = "\u001b[95m";
15
+ export const CYAN = "\u001b[96m";
16
+ export const WHITE = "\u001b[97m";
17
+ export const RESET = "\u001b[0m";
18
+
19
+ export class Colors {
20
+ constructor(stream) {
21
+ this.stream = stream;
22
+ this.enabled = Boolean((this.stream && this.stream.isTTY) || isCI);
23
+ }
24
+ gray(text) { return this.enabled ? GRAY + text + RESET : text; }
25
+ red(text) { return this.enabled ? RED + text + RESET : text; }
26
+ green(text) { return this.enabled ? GREEN + text + RESET : text; }
27
+ yellow(text) { return this.enabled ? YELLOW + text + RESET : text; }
28
+ blue(text) { return this.enabled ? BLUE + text + RESET : text; }
29
+ magenta(text) { return this.enabled ? MAGENTA + text + RESET : text; }
30
+ cyan(text) { return this.enabled ? CYAN + text + RESET : text; }
31
+ white(text) { return this.enabled ? WHITE + text + RESET : text; }
32
+ }
33
+
34
+ export const stdoutColors = new Colors(proc.stdout);
35
+ export const stderrColors = new Colors(proc.stderr);
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @fileoverview Text utility definitions.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ /** Calculates the UTF-8 byte length of a string. */
7
+ export function utf8Length(string: string): number;
8
+
9
+ /** Reads UTF-8 bytes as a string. */
10
+ export function utf8Read(buffer: Uint8Array, start: number, end: number): string;
11
+
12
+ /** Writes a string as UTF-8 bytes. */
13
+ export function utf8Write(string: string, buffer: Uint8Array, offset: number): number;
14
+
15
+ /** UTF-8 utility. */
16
+ export const utf8: {
17
+ /** Calculates the UTF8 byte length of a string. */
18
+ length: typeof utf8Length;
19
+ /** Reads UTF8 bytes as a string. */
20
+ read: typeof utf8Read;
21
+ /** Writes a string as UTF8 bytes. */
22
+ write: typeof utf8Write;
23
+ };
24
+
25
+ /** Computes the difference between an expected and its actual text. */
26
+ export function diff(filename: string, expected: string, actual: string): string;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @fileoverview Text utility.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ import * as Diff from "diff";
7
+ import { stdoutColors } from "./terminal.js";
8
+
9
+ export function utf8Length(string) {
10
+ var len = 0;
11
+ for (var i = 0, k = string.length; i < k; ++i) {
12
+ let c = string.charCodeAt(i);
13
+ if (c < 128) {
14
+ len += 1;
15
+ } else if (c < 2048) {
16
+ len += 2;
17
+ } else if ((c & 0xFC00) === 0xD800 && i + 1 < k && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
18
+ ++i;
19
+ len += 4;
20
+ } else {
21
+ len += 3;
22
+ }
23
+ }
24
+ return len;
25
+ }
26
+
27
+ export function utf8Read(buffer, start, end) {
28
+ var len = end - start;
29
+ if (len < 1) return "";
30
+ var parts = null,
31
+ chunk = [],
32
+ i = 0, // char offset
33
+ t; // temporary
34
+ while (start < end) {
35
+ t = buffer[start++];
36
+ if (t < 128) {
37
+ chunk[i++] = t;
38
+ } else if (t > 191 && t < 224) {
39
+ chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
40
+ } else if (t > 239 && t < 365) {
41
+ t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
42
+ chunk[i++] = 0xD800 + (t >> 10);
43
+ chunk[i++] = 0xDC00 + (t & 1023);
44
+ } else {
45
+ chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
46
+ }
47
+ if (i >= 8192) {
48
+ (parts || (parts = [])).push(String.fromCharCode(...chunk));
49
+ i = 0;
50
+ }
51
+ }
52
+ if (parts) {
53
+ if (i) parts.push(String.fromCharCode(...chunk.slice(0, i)));
54
+ return parts.join("");
55
+ }
56
+ return String.fromCharCode(...chunk.slice(0, i));
57
+ }
58
+
59
+ export function utf8Write(string, buffer, offset) {
60
+ var start = offset;
61
+ for (var i = 0, k = string.length; i < k; ++i) {
62
+ let c1 = string.charCodeAt(i), c2;
63
+ if (c1 < 128) {
64
+ buffer[offset++] = c1;
65
+ } else if (c1 < 2048) {
66
+ buffer[offset++] = c1 >> 6 | 192;
67
+ buffer[offset++] = c1 & 63 | 128;
68
+ } else if ((c1 & 0xFC00) === 0xD800 && i + 1 < k && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
69
+ c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
70
+ ++i;
71
+ buffer[offset++] = c1 >> 18 | 240;
72
+ buffer[offset++] = c1 >> 12 & 63 | 128;
73
+ buffer[offset++] = c1 >> 6 & 63 | 128;
74
+ buffer[offset++] = c1 & 63 | 128;
75
+ } else {
76
+ buffer[offset++] = c1 >> 12 | 224;
77
+ buffer[offset++] = c1 >> 6 & 63 | 128;
78
+ buffer[offset++] = c1 & 63 | 128;
79
+ }
80
+ }
81
+ return offset - start;
82
+ }
83
+
84
+ export const utf8 = {
85
+ length: utf8Length,
86
+ read: utf8Read,
87
+ write: utf8Write
88
+ };
89
+
90
+ export function diff(filename, expected, actual) {
91
+ const diff = Diff.structuredPatch(filename, filename, expected, actual, "expected", "actual", { context: 5 });
92
+ if (!diff.hunks.length) return null;
93
+
94
+ const out = [
95
+ '--- ' + diff.oldHeader,
96
+ '+++ ' + diff.newHeader
97
+ ];
98
+ for (const hunk of diff.hunks) {
99
+ out.push(
100
+ '@@ -' + hunk.oldStart + ',' + hunk.oldLines
101
+ + ' +' + hunk.newStart + ',' + hunk.newLines
102
+ + ' @@'
103
+ );
104
+ out.push(...hunk.lines.map(line =>
105
+ line.charAt(0) === "+"
106
+ ? stdoutColors.green(line)
107
+ : line.charAt(0) === "-"
108
+ ? stdoutColors.red(line)
109
+ : line
110
+ ));
111
+ }
112
+
113
+ return out.join('\n') + '\n';
114
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "esModuleInterop": true
5
+ },
6
+ "include": [
7
+ "./**/*.ts"
8
+ ]
9
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @fileoverview Web polyfill definitions.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ /** Fetches a file. */
7
+ export function fetch(url: string): Promise<{
8
+ arrayBuffer(): Promise<ArrayBuffer>;
9
+ text(): Promise<string>;
10
+ json(): Promise<any>;
11
+ }>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @fileoverview Web polyfills.
3
+ * @license Apache-2.0
4
+ */
5
+
6
+ import { fs } from "./node.js";
7
+
8
+ var _fetch = typeof fetch === "function" ? fetch :
9
+ url => new Promise((resolve, reject) => {
10
+ fs.readFile(url, (err, data) => {
11
+ if (err) reject(err);
12
+ resolve({
13
+ arrayBuffer() {
14
+ let offset = data.byteOffset;
15
+ return Promise.resolve(data.buffer.slice(offset, offset + data.byteLength));
16
+ },
17
+ text() {
18
+ return Promise.resolve(data.toString());
19
+ },
20
+ json() {
21
+ try {
22
+ return Promise.resolve(JSON.parse(data.toString()));
23
+ } catch (err) {
24
+ return Promise.reject(err);
25
+ }
26
+ }
27
+ });
28
+ });
29
+ });
30
+
31
+ export {
32
+ _fetch as fetch
33
+ };