@netlify/plugin-nextjs 4.41.3 → 5.0.0-beta.1

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 (241) hide show
  1. package/README.md +61 -17
  2. package/dist/build/cache.js +15 -0
  3. package/dist/build/content/prerendered.js +16 -0
  4. package/dist/build/content/server.js +18 -0
  5. package/dist/build/content/static.js +20 -0
  6. package/dist/build/functions/edge.js +14 -0
  7. package/dist/build/functions/server.js +16 -0
  8. package/dist/build/plugin-context.js +17 -0
  9. package/dist/esm-chunks/chunk-4AJYXTWN.js +17 -0
  10. package/dist/esm-chunks/chunk-5N2CWXSJ.js +564 -0
  11. package/dist/esm-chunks/chunk-A22224GM.js +113 -0
  12. package/dist/esm-chunks/chunk-AVWFCGVE.js +5536 -0
  13. package/dist/esm-chunks/chunk-B6QMRLBH.js +255 -0
  14. package/dist/esm-chunks/chunk-G3GM7JNF.js +92 -0
  15. package/dist/esm-chunks/chunk-GGHAQM5D.js +28 -0
  16. package/dist/esm-chunks/chunk-NOX2JUQZ.js +89 -0
  17. package/dist/esm-chunks/chunk-R4NHZWGU.js +32 -0
  18. package/dist/esm-chunks/chunk-RSKIKBZH.js +44 -0
  19. package/dist/esm-chunks/chunk-UXLNY5XK.js +86 -0
  20. package/dist/esm-chunks/chunk-VP3PT3VV.js +119 -0
  21. package/dist/esm-chunks/chunk-YZXA5QBC.js +60 -0
  22. package/dist/esm-chunks/chunk-Z7ZMLVTM.js +78 -0
  23. package/dist/index.js +66 -0
  24. package/dist/run/config.js +18 -0
  25. package/dist/run/constants.js +15 -0
  26. package/dist/run/handlers/cache.cjs +852 -0
  27. package/dist/run/handlers/server.js +3297 -0
  28. package/dist/run/headers.js +19 -0
  29. package/dist/run/next.cjs +1058 -0
  30. package/dist/run/revalidate.js +13 -0
  31. package/dist/run/systemlog.js +15 -0
  32. package/edge-runtime/README.md +29 -0
  33. package/edge-runtime/lib/headers.ts +26 -0
  34. package/edge-runtime/lib/middleware.ts +60 -0
  35. package/edge-runtime/lib/next-request.ts +59 -0
  36. package/edge-runtime/lib/response.ts +145 -0
  37. package/{src/templates/edge-shared/next-utils.ts → edge-runtime/lib/routing.ts} +64 -20
  38. package/edge-runtime/lib/util.ts +26 -0
  39. package/edge-runtime/middleware.ts +53 -0
  40. package/edge-runtime/shim/index.js +11 -0
  41. package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +1 -1
  42. package/edge-runtime/vendor/import_map.json +13 -0
  43. package/edge-runtime/vendor.ts +18 -0
  44. package/manifest.yml +1 -1
  45. package/package.json +23 -60
  46. package/index.js +0 -1
  47. package/lib/constants.js +0 -56
  48. package/lib/helpers/analysis.js +0 -115
  49. package/lib/helpers/cache.js +0 -46
  50. package/lib/helpers/compiler.js +0 -119
  51. package/lib/helpers/config.js +0 -192
  52. package/lib/helpers/dev.js +0 -20
  53. package/lib/helpers/edge.js +0 -328
  54. package/lib/helpers/files.js +0 -335
  55. package/lib/helpers/flags.js +0 -46
  56. package/lib/helpers/functions.js +0 -437
  57. package/lib/helpers/functionsMetaData.js +0 -46
  58. package/lib/helpers/matchers.js +0 -41
  59. package/lib/helpers/middlewareWatcher.js +0 -12
  60. package/lib/helpers/pack.js +0 -41
  61. package/lib/helpers/redirects.js +0 -246
  62. package/lib/helpers/types.js +0 -2
  63. package/lib/helpers/utils.js +0 -226
  64. package/lib/helpers/verification.js +0 -182
  65. package/lib/index.js +0 -194
  66. package/lib/templates/blobStorage.js +0 -30
  67. package/lib/templates/getApiHandler.js +0 -120
  68. package/lib/templates/getHandler.js +0 -201
  69. package/lib/templates/getPageResolver.js +0 -54
  70. package/lib/templates/handlerUtils.js +0 -268
  71. package/lib/templates/ipx.js +0 -13
  72. package/lib/templates/requireHooks.js +0 -105
  73. package/lib/templates/server.js +0 -159
  74. package/lib/templates/vendor.js +0 -20
  75. package/src/templates/edge/bundle.js +0 -8
  76. package/src/templates/edge/function-runtime.ts +0 -24
  77. package/src/templates/edge/imageconfig.json +0 -3
  78. package/src/templates/edge/ipx.ts +0 -5
  79. package/src/templates/edge/middleware-runtime.ts +0 -62
  80. package/src/templates/edge/next-dev.js +0 -104
  81. package/src/templates/edge/rsc-data.ts +0 -5
  82. package/src/templates/edge/shims.js +0 -77
  83. package/src/templates/edge-shared/nextConfig.json +0 -3
  84. package/src/templates/edge-shared/prerender-manifest.json +0 -7
  85. package/src/templates/edge-shared/rsc-data.ts +0 -78
  86. package/src/templates/edge-shared/utils.test.ts +0 -114
  87. package/src/templates/edge-shared/utils.ts +0 -315
  88. package/src/templates/vendor/import_map.json +0 -13
  89. /package/{src/templates/edge → edge-runtime}/matchers.json +0 -0
  90. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/fmt/colors.ts +0 -0
  91. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/testing/_diff.ts +0 -0
  92. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.134.0/testing/asserts.ts +0 -0
  93. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/_util/asserts.ts +0 -0
  94. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/_util/os.ts +0 -0
  95. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/abortable.ts +0 -0
  96. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/deadline.ts +0 -0
  97. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/debounce.ts +0 -0
  98. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/deferred.ts +0 -0
  99. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/delay.ts +0 -0
  100. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/mod.ts +0 -0
  101. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +0 -0
  102. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/pool.ts +0 -0
  103. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/retry.ts +0 -0
  104. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/async/tee.ts +0 -0
  105. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +0 -0
  106. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +0 -0
  107. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +0 -0
  108. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/encoding/base64.ts +0 -0
  109. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/encoding/base64url.ts +0 -0
  110. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/flags/mod.ts +0 -0
  111. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/fmt/colors.ts +0 -0
  112. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/fmt/printf.ts +0 -0
  113. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/http/cookie.ts +0 -0
  114. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_core.ts +0 -0
  115. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_events.d.ts +0 -0
  116. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_events.mjs +0 -0
  117. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_global.d.ts +0 -0
  118. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_next_tick.ts +0 -0
  119. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +0 -0
  120. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/process.ts +0 -0
  121. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +0 -0
  122. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +0 -0
  123. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_stream.d.ts +0 -0
  124. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_stream.mjs +0 -0
  125. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +0 -0
  126. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/_utils.ts +0 -0
  127. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/assert.ts +0 -0
  128. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/assertion_error.ts +0 -0
  129. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/async_hooks.ts +0 -0
  130. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/buffer.ts +0 -0
  131. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/events.ts +0 -0
  132. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +0 -0
  133. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +0 -0
  134. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +0 -0
  135. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +0 -0
  136. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +0 -0
  137. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/errors.ts +0 -0
  138. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +0 -0
  139. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +0 -0
  140. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/net.ts +0 -0
  141. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +0 -0
  142. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/options.ts +0 -0
  143. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +0 -0
  144. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +0 -0
  145. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +0 -0
  146. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +0 -0
  147. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +0 -0
  148. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +0 -0
  149. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +0 -0
  150. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +0 -0
  151. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +0 -0
  152. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +0 -0
  153. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +0 -0
  154. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/util.mjs +0 -0
  155. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +0 -0
  156. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +0 -0
  157. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +0 -0
  158. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +0 -0
  159. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +0 -0
  160. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +0 -0
  161. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +0 -0
  162. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +0 -0
  163. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +0 -0
  164. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +0 -0
  165. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +0 -0
  166. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +0 -0
  167. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +0 -0
  168. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +0 -0
  169. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +0 -0
  170. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +0 -0
  171. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +0 -0
  172. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +0 -0
  173. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +0 -0
  174. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +0 -0
  175. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +0 -0
  176. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +0 -0
  177. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +0 -0
  178. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +0 -0
  179. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +0 -0
  180. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +0 -0
  181. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +0 -0
  182. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +0 -0
  183. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +0 -0
  184. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +0 -0
  185. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +0 -0
  186. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +0 -0
  187. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +0 -0
  188. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +0 -0
  189. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +0 -0
  190. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +0 -0
  191. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +0 -0
  192. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +0 -0
  193. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +0 -0
  194. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +0 -0
  195. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +0 -0
  196. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +0 -0
  197. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +0 -0
  198. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +0 -0
  199. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +0 -0
  200. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +0 -0
  201. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +0 -0
  202. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +0 -0
  203. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +0 -0
  204. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +0 -0
  205. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +0 -0
  206. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +0 -0
  207. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +0 -0
  208. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +0 -0
  209. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +0 -0
  210. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +0 -0
  211. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +0 -0
  212. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +0 -0
  213. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +0 -0
  214. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +0 -0
  215. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/process.ts +0 -0
  216. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/stream.ts +0 -0
  217. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/string_decoder.ts +0 -0
  218. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/util/types.ts +0 -0
  219. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/node/util.ts +0 -0
  220. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_constants.ts +0 -0
  221. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_interface.ts +0 -0
  222. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/_util.ts +0 -0
  223. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/common.ts +0 -0
  224. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/glob.ts +0 -0
  225. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/mod.ts +0 -0
  226. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/posix.ts +0 -0
  227. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/separator.ts +0 -0
  228. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/path/win32.ts +0 -0
  229. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/streams/write_all.ts +0 -0
  230. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/_diff.ts +0 -0
  231. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/_format.ts +0 -0
  232. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/testing/asserts.ts +0 -0
  233. /package/{src/templates → edge-runtime}/vendor/deno.land/std@0.175.0/types.d.ts +0 -0
  234. /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +0 -0
  235. /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +0 -0
  236. /package/{src/templates → edge-runtime}/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +0 -0
  237. /package/{src/templates → edge-runtime}/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +0 -0
  238. /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +0 -0
  239. /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +0 -0
  240. /package/{src/templates → edge-runtime}/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +0 -0
  241. /package/{src/templates → edge-runtime}/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +0 -0
@@ -0,0 +1,13 @@
1
+
2
+ const require = await (async () => {
3
+ const { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import {
8
+ nextResponseProxy
9
+ } from "../esm-chunks/chunk-B6QMRLBH.js";
10
+ import "../esm-chunks/chunk-RSKIKBZH.js";
11
+ export {
12
+ nextResponseProxy
13
+ };
@@ -0,0 +1,15 @@
1
+
2
+ const require = await (async () => {
3
+ const { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import {
8
+ StructuredLogger,
9
+ logger
10
+ } from "../esm-chunks/chunk-YZXA5QBC.js";
11
+ import "../esm-chunks/chunk-RSKIKBZH.js";
12
+ export {
13
+ StructuredLogger,
14
+ logger
15
+ };
@@ -0,0 +1,29 @@
1
+ # Edge runtime
2
+
3
+ This directory contains the logic required to create Netlify Edge Functions to support a Next.js
4
+ site.
5
+
6
+ It stands out from the rest of the project because it contains files that run in Deno, not Node.js.
7
+ Therefore any files within `edge-runtime/` should not be imported from anywhere outside this
8
+ directory.
9
+
10
+ There are a few sub-directories you should know about.
11
+
12
+ ## `lib/`
13
+
14
+ Files that are imported by the generated edge functions.
15
+
16
+ ## `shim/`
17
+
18
+ Files that are inlined in the generated edge functions. This means that _you must not import these
19
+ files_ from anywhere in the application, because they contain just fragments of a valid program.
20
+
21
+ ## `vendor/`
22
+
23
+ Third-party dependencies used in the generated edge functions and pulled in ahead of time to avoid a
24
+ build time dependency on any package registry.
25
+
26
+ This directory is automatically managed by the build script and can be re-generated by running
27
+ `npm run build`.
28
+
29
+ You should not commit this directory to version control.
@@ -0,0 +1,26 @@
1
+ // Next 13 supports request header mutations and has the side effect of prepending header values with 'x-middleware-request'
2
+ // as part of invoking NextResponse.next() in the middleware. We need to remove that before sending the response the user
3
+ // as the code that removes it in Next isn't run based on how we handle the middleware
4
+ //
5
+ // Related Next.js code:
6
+ // * https://github.com/vercel/next.js/blob/68d06fe015b28d8f81da52ca107a5f4bd72ab37c/packages/next/server/next-server.ts#L1918-L1928
7
+ // * https://github.com/vercel/next.js/blob/43c9d8940dc42337dd2f7d66aa90e6abf952278e/packages/next/server/web/spec-extension/response.ts#L10-L27
8
+ export function updateModifiedHeaders(requestHeaders: Headers, responseHeaders: Headers) {
9
+ const overriddenHeaders = responseHeaders.get('x-middleware-override-headers')
10
+
11
+ if (!overriddenHeaders) {
12
+ return
13
+ }
14
+
15
+ const headersToUpdate = overriddenHeaders.split(',').map((header) => header.trim())
16
+
17
+ for (const header of headersToUpdate) {
18
+ const oldHeaderKey = 'x-middleware-request-' + header
19
+ const headerValue = responseHeaders.get(oldHeaderKey) || ''
20
+
21
+ requestHeaders.set(header, headerValue)
22
+ responseHeaders.delete(oldHeaderKey)
23
+ }
24
+
25
+ responseHeaders.delete('x-middleware-override-headers')
26
+ }
@@ -0,0 +1,60 @@
1
+ import type { Context } from '@netlify/edge-functions'
2
+
3
+ import { ElementHandlers } from '../vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts'
4
+
5
+ type NextDataTransform = <T>(data: T) => T
6
+
7
+ interface ResponseCookies {
8
+ // This is non-standard that Next.js adds.
9
+ // https://github.com/vercel/next.js/blob/de08f8b3d31ef45131dad97a7d0e95fa01001167/packages/next/src/compiled/@edge-runtime/cookies/index.js#L158
10
+ readonly _headers: Headers
11
+ }
12
+
13
+ interface MiddlewareResponse extends Response {
14
+ originResponse: Response
15
+ dataTransforms: NextDataTransform[]
16
+ elementHandlers: Array<[selector: string, handlers: ElementHandlers]>
17
+ get cookies(): ResponseCookies
18
+ }
19
+
20
+ interface MiddlewareRequest {
21
+ request: Request
22
+ context: Context
23
+ originalRequest: Request
24
+ next(): Promise<MiddlewareResponse>
25
+ rewrite(destination: string | URL, init?: ResponseInit): Response
26
+ }
27
+
28
+ export function isMiddlewareRequest(
29
+ response: Response | MiddlewareRequest,
30
+ ): response is MiddlewareRequest {
31
+ return 'originalRequest' in response
32
+ }
33
+
34
+ export function isMiddlewareResponse(
35
+ response: Response | MiddlewareResponse,
36
+ ): response is MiddlewareResponse {
37
+ return 'dataTransforms' in response
38
+ }
39
+
40
+ export const addMiddlewareHeaders = async (
41
+ originResponse: Promise<Response> | Response,
42
+ middlewareResponse: Response,
43
+ ) => {
44
+ // If there are extra headers, we need to add them to the response.
45
+ if ([...middlewareResponse.headers.keys()].length === 0) {
46
+ return originResponse
47
+ }
48
+
49
+ // We need to await the response to get the origin headers, then we can add the ones from middleware.
50
+ const res = await originResponse
51
+ const response = new Response(res.body, res)
52
+ middlewareResponse.headers.forEach((value, key) => {
53
+ if (key === 'set-cookie') {
54
+ response.headers.append(key, value)
55
+ } else {
56
+ response.headers.set(key, value)
57
+ }
58
+ })
59
+ return response
60
+ }
@@ -0,0 +1,59 @@
1
+ import type { Context } from '@netlify/edge-functions'
2
+
3
+ interface I18NConfig {
4
+ defaultLocale: string
5
+ localeDetection?: false
6
+ locales: string[]
7
+ }
8
+
9
+ export interface RequestData {
10
+ geo?: {
11
+ city?: string
12
+ country?: string
13
+ region?: string
14
+ latitude?: string
15
+ longitude?: string
16
+ timezone?: string
17
+ }
18
+ headers: Record<string, string>
19
+ ip?: string
20
+ method: string
21
+ nextConfig?: {
22
+ basePath?: string
23
+ i18n?: I18NConfig | null
24
+ trailingSlash?: boolean
25
+ }
26
+ page?: {
27
+ name?: string
28
+ params?: { [key: string]: string }
29
+ }
30
+ url: string
31
+ body?: ReadableStream<Uint8Array>
32
+ }
33
+
34
+ export const buildNextRequest = (
35
+ request: Request,
36
+ context: Context,
37
+ nextConfig?: RequestData['nextConfig'],
38
+ ): RequestData => {
39
+ const { url, method, body, headers } = request
40
+ const { country, subdivision, city, latitude, longitude, timezone } = context.geo
41
+ const geo: RequestData['geo'] = {
42
+ country: country?.code,
43
+ region: subdivision?.code,
44
+ city,
45
+ latitude: latitude?.toString(),
46
+ longitude: longitude?.toString(),
47
+ timezone,
48
+ }
49
+
50
+ return {
51
+ headers: Object.fromEntries(headers.entries()),
52
+ geo,
53
+ url,
54
+ method,
55
+ ip: context.ip,
56
+ body: body ?? undefined,
57
+ nextConfig,
58
+ }
59
+ }
@@ -0,0 +1,145 @@
1
+ import type { Context } from '@netlify/edge-functions'
2
+ import { HTMLRewriter } from '../vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts'
3
+
4
+ import { updateModifiedHeaders } from './headers.ts'
5
+ import { normalizeDataUrl, relativizeURL } from './util.ts'
6
+ import { addMiddlewareHeaders, isMiddlewareRequest, isMiddlewareResponse } from './middleware.ts'
7
+
8
+ export interface FetchEventResult {
9
+ response: Response
10
+ waitUntil: Promise<any>
11
+ }
12
+
13
+ export const buildResponse = async ({
14
+ result,
15
+ request,
16
+ context,
17
+ }: {
18
+ result: FetchEventResult
19
+ request: Request
20
+ context: Context
21
+ }) => {
22
+ updateModifiedHeaders(request.headers, result.response.headers)
23
+
24
+ // They've returned the MiddlewareRequest directly, so we'll call `next()` for them.
25
+ if (isMiddlewareRequest(result.response)) {
26
+ result.response = await result.response.next()
27
+ }
28
+
29
+ if (isMiddlewareResponse(result.response)) {
30
+ const { response } = result
31
+ if (request.method === 'HEAD' || request.method === 'OPTIONS') {
32
+ return response.originResponse
33
+ }
34
+
35
+ // NextResponse doesn't set cookies onto the originResponse, so we need to copy them over
36
+ // In some cases, it's possible there are no headers set. See https://github.com/netlify/pod-ecosystem-frameworks/issues/475
37
+ if (response.cookies._headers?.has('set-cookie')) {
38
+ response.originResponse.headers.set(
39
+ 'set-cookie',
40
+ response.cookies._headers.get('set-cookie')!,
41
+ )
42
+ }
43
+
44
+ // If it's JSON we don't need to use the rewriter, we can just parse it
45
+ if (response.originResponse.headers.get('content-type')?.includes('application/json')) {
46
+ const props = await response.originResponse.json()
47
+ const transformed = response.dataTransforms.reduce((prev, transform) => {
48
+ return transform(prev)
49
+ }, props)
50
+ const body = JSON.stringify(transformed)
51
+ const headers = new Headers(response.headers)
52
+ headers.set('content-length', String(body.length))
53
+
54
+ return Response.json(transformed, { ...response, headers })
55
+ }
56
+
57
+ // This var will hold the contents of the script tag
58
+ let buffer = ''
59
+ // Create an HTMLRewriter that matches the Next data script tag
60
+ const rewriter = new HTMLRewriter()
61
+
62
+ if (response.dataTransforms.length > 0) {
63
+ rewriter.on('script[id="__NEXT_DATA__"]', {
64
+ text(textChunk) {
65
+ // Grab all the chunks in the Next data script tag
66
+ buffer += textChunk.text
67
+ if (textChunk.lastInTextNode) {
68
+ try {
69
+ // When we have all the data, try to parse it as JSON
70
+ const data = JSON.parse(buffer.trim())
71
+ // Apply all of the transforms to the props
72
+ const props = response.dataTransforms.reduce(
73
+ (prev, transform) => transform(prev),
74
+ data.props,
75
+ )
76
+ // Replace the data with the transformed props
77
+ // With `html: true` the input is treated as raw HTML
78
+ // @see https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/#global-types
79
+ textChunk.replace(JSON.stringify({ ...data, props }), { html: true })
80
+ } catch (err) {
81
+ console.log('Could not parse', err)
82
+ }
83
+ } else {
84
+ // Remove the chunk after we've appended it to the buffer
85
+ textChunk.remove()
86
+ }
87
+ },
88
+ })
89
+ }
90
+
91
+ if (response.elementHandlers.length > 0) {
92
+ response.elementHandlers.forEach(([selector, handlers]) => rewriter.on(selector, handlers))
93
+ }
94
+ return rewriter.transform(response.originResponse)
95
+ }
96
+ const res = new Response(result.response.body, result.response)
97
+ request.headers.set('x-nf-next-middleware', 'skip')
98
+
99
+ const rewrite = res.headers.get('x-middleware-rewrite')
100
+
101
+ // Data requests (i.e. requests for /_next/data ) need special handling
102
+ const isDataReq = request.headers.get('x-nextjs-data')
103
+
104
+ if (rewrite) {
105
+ const rewriteUrl = new URL(rewrite, request.url)
106
+ const baseUrl = new URL(request.url)
107
+ const relativeUrl = relativizeURL(rewrite, request.url)
108
+
109
+ // Data requests might be rewritten to an external URL
110
+ // This header tells the client router the redirect target, and if it's external then it will do a full navigation
111
+ if (isDataReq) {
112
+ res.headers.set('x-nextjs-rewrite', relativeUrl)
113
+ }
114
+ if (rewriteUrl.origin !== baseUrl.origin) {
115
+ // Netlify Edge Functions don't support proxying to external domains, but Next middleware does
116
+ const proxied = fetch(new Request(rewriteUrl.toString(), request))
117
+ return addMiddlewareHeaders(proxied, res)
118
+ }
119
+ res.headers.set('x-middleware-rewrite', relativeUrl)
120
+
121
+ request.headers.set('x-original-path', new URL(request.url, `http://n`).pathname)
122
+ request.headers.set('x-middleware-rewrite', rewrite)
123
+
124
+ return addMiddlewareHeaders(context.rewrite(rewrite), res)
125
+ }
126
+
127
+ const redirect = res.headers.get('Location')
128
+
129
+ // Data requests shouldn't automatically redirect in the browser (they might be HTML pages): they're handled by the router
130
+ if (redirect && isDataReq) {
131
+ res.headers.delete('location')
132
+ res.headers.set('x-nextjs-redirect', relativizeURL(redirect, request.url))
133
+ }
134
+
135
+ const nextRedirect = res.headers.get('x-nextjs-redirect')
136
+
137
+ if (nextRedirect && isDataReq) {
138
+ res.headers.set('x-nextjs-redirect', normalizeDataUrl(nextRedirect))
139
+ }
140
+
141
+ if (res.headers.get('x-middleware-next') === '1') {
142
+ return addMiddlewareHeaders(context.next(), res)
143
+ }
144
+ return res
145
+ }
@@ -1,26 +1,25 @@
1
1
  /**
2
2
  * Various router utils ported to Deno from Next.js source
3
- * https://github.com/vercel/next.js/blob/7280c3ced186bb9a7ae3d7012613ef93f20b0fa9/packages/next/shared/lib/router/utils/
4
3
  * Licence: https://github.com/vercel/next.js/blob/7280c3ced186bb9a7ae3d7012613ef93f20b0fa9/license.md
5
4
  *
6
5
  * Some types have been re-implemented to be more compatible with Deno or avoid chains of dependent files
7
6
  */
8
7
 
9
- // Deno imports
10
8
  import type { Key } from '../vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts'
11
9
 
12
10
  import { compile, pathToRegexp } from '../vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts'
13
11
  import { getCookies } from '../vendor/deno.land/std@0.175.0/http/cookie.ts'
14
12
 
15
- // Inlined/re-implemented types
16
-
13
+ /*
14
+ ┌─────────────────────────────────────────────────────────────────────────┐
15
+ │ Inlined/re-implemented types │
16
+ └─────────────────────────────────────────────────────────────────────────┘
17
+ */
17
18
  export interface ParsedUrlQuery {
18
19
  [key: string]: string | string[]
19
20
  }
20
21
 
21
22
  export interface Params {
22
- // Yeah, best we get
23
- // deno-lint-ignore no-explicit-any
24
23
  [param: string]: any
25
24
  }
26
25
 
@@ -55,6 +54,7 @@ export type Header = {
55
54
  missing?: RouteHas[]
56
55
  regex: string
57
56
  }
57
+
58
58
  export type Redirect = {
59
59
  source: string
60
60
  destination: string
@@ -85,7 +85,12 @@ export type RoutesManifest = {
85
85
  }
86
86
  dynamicRoutes: DynamicRoute[]
87
87
  }
88
- // escape-regexp.ts
88
+
89
+ /*
90
+ ┌─────────────────────────────────────────────────────────────────────────┐
91
+ │ packages/next/src/shared/lib/escape-regexp.ts │
92
+ └─────────────────────────────────────────────────────────────────────────┘
93
+ */
89
94
  // regexp is based on https://github.com/sindresorhus/escape-string-regexp
90
95
  const reHasRegExp = /[|\\{}()[\]^$+*?.-]/
91
96
  const reReplaceRegExp = /[|\\{}()[\]^$+*?.-]/g
@@ -95,12 +100,18 @@ export function escapeStringRegexp(str: string) {
95
100
  if (reHasRegExp.test(str)) {
96
101
  return str.replace(reReplaceRegExp, '\\$&')
97
102
  }
103
+
98
104
  return str
99
105
  }
100
106
 
101
- // querystring.ts
107
+ /*
108
+ ┌─────────────────────────────────────────────────────────────────────────┐
109
+ │ packages/next/src/shared/lib/router/utils/querystring.ts │
110
+ └─────────────────────────────────────────────────────────────────────────┘
111
+ */
102
112
  export function searchParamsToUrlQuery(searchParams: URLSearchParams): ParsedUrlQuery {
103
113
  const query: ParsedUrlQuery = {}
114
+
104
115
  searchParams.forEach((value, key) => {
105
116
  if (typeof query[key] === 'undefined') {
106
117
  query[key] = value
@@ -110,10 +121,15 @@ export function searchParamsToUrlQuery(searchParams: URLSearchParams): ParsedUrl
110
121
  query[key] = [query[key] as string, value]
111
122
  }
112
123
  })
124
+
113
125
  return query
114
126
  }
115
127
 
116
- // parse-url.ts
128
+ /*
129
+ ┌─────────────────────────────────────────────────────────────────────────┐
130
+ │ packages/next/src/shared/lib/router/utils/parse-url.ts │
131
+ └─────────────────────────────────────────────────────────────────────────┘
132
+ */
117
133
  interface ParsedUrl {
118
134
  hash: string
119
135
  hostname?: string | null
@@ -127,6 +143,7 @@ interface ParsedUrl {
127
143
 
128
144
  export function parseUrl(url: string): ParsedUrl {
129
145
  const parsedURL = url.startsWith('/') ? new URL(url, 'http://n') : new URL(url)
146
+
130
147
  return {
131
148
  hash: parsedURL.hash,
132
149
  hostname: parsedURL.hostname,
@@ -139,8 +156,13 @@ export function parseUrl(url: string): ParsedUrl {
139
156
  }
140
157
  }
141
158
 
142
- // prepare-destination.ts
143
- // Changed to use WHATWG Fetch Request instead of IncomingMessage
159
+ /*
160
+ ┌─────────────────────────────────────────────────────────────────────────┐
161
+ │ packages/next/src/shared/lib/router/utils/prepare-destination.ts │
162
+ │ — Changed to use WHATWG Fetch `Request` instead of │
163
+ │ `http.IncomingMessage`. │
164
+ └─────────────────────────────────────────────────────────────────────────┘
165
+ */
144
166
  export function matchHas(
145
167
  req: Pick<Request, 'headers' | 'url'>,
146
168
  query: Params,
@@ -178,10 +200,13 @@ export function matchHas(
178
200
  }
179
201
  if (!hasItem.value && value && key) {
180
202
  params[getSafeParamName(key)] = value
203
+
181
204
  return true
182
205
  } else if (value) {
183
206
  const matcher = new RegExp(`^${hasItem.value}$`)
184
- const matches = Array.isArray(value) ? value.slice(-1)[0].match(matcher) : value.match(matcher)
207
+ const matches = Array.isArray(value)
208
+ ? value.slice(-1)[0].match(matcher)
209
+ : value.match(matcher)
185
210
 
186
211
  if (matches) {
187
212
  if (Array.isArray(matches)) {
@@ -281,7 +306,9 @@ export function prepareDestination(args: {
281
306
  // the value needs to start with a forward-slash to be compiled
282
307
  // correctly
283
308
  if (Array.isArray(strOrArray)) {
284
- destQuery[key] = strOrArray.map((value) => compileNonPath(unescapeSegments(value), args.params))
309
+ destQuery[key] = strOrArray.map((value) =>
310
+ compileNonPath(unescapeSegments(value), args.params),
311
+ )
285
312
  } else {
286
313
  destQuery[key] = compileNonPath(unescapeSegments(strOrArray), args.params)
287
314
  }
@@ -355,14 +382,21 @@ function getSafeParamName(paramName: string) {
355
382
  }
356
383
 
357
384
  function escapeSegment(str: string, segmentName: string) {
358
- return str.replace(new RegExp(`:${escapeStringRegexp(segmentName)}`, 'g'), `__ESC_COLON_${segmentName}`)
385
+ return str.replace(
386
+ new RegExp(`:${escapeStringRegexp(segmentName)}`, 'g'),
387
+ `__ESC_COLON_${segmentName}`,
388
+ )
359
389
  }
360
390
 
361
391
  function unescapeSegments(str: string) {
362
392
  return str.replace(/__ESC_COLON_/gi, ':')
363
393
  }
364
394
 
365
- // is-dynamic.ts
395
+ /*
396
+ ┌─────────────────────────────────────────────────────────────────────────┐
397
+ │ packages/next/src/shared/lib/router/utils/is-dynamic.ts │
398
+ └─────────────────────────────────────────────────────────────────────────┘
399
+ */
366
400
  // Identify /[param]/ in route string
367
401
  const TEST_ROUTE = /\/\[[^/]+?\](?=\/|$)/
368
402
 
@@ -370,11 +404,17 @@ export function isDynamicRoute(route: string): boolean {
370
404
  return TEST_ROUTE.test(route)
371
405
  }
372
406
 
373
- // packages/next/shared/lib/router/utils/middleware-route-matcher.ts
374
- // 12.3 middleware route matcher
375
-
407
+ /*
408
+ ┌─────────────────────────────────────────────────────────────────────────┐
409
+ │ packages/next/shared/lib/router/utils/middleware-route-matcher.ts │
410
+ └─────────────────────────────────────────────────────────────────────────┘
411
+ */
376
412
  export interface MiddlewareRouteMatch {
377
- (pathname: string | null | undefined, request: Pick<Request, 'headers' | 'url'>, query: Params): boolean
413
+ (
414
+ pathname: string | null | undefined,
415
+ request: Pick<Request, 'headers' | 'url'>,
416
+ query: Params,
417
+ ): boolean
378
418
  }
379
419
 
380
420
  export interface MiddlewareMatcher {
@@ -385,7 +425,11 @@ export interface MiddlewareMatcher {
385
425
  }
386
426
 
387
427
  export function getMiddlewareRouteMatcher(matchers: MiddlewareMatcher[]): MiddlewareRouteMatch {
388
- return (pathname: string | null | undefined, req: Pick<Request, 'headers' | 'url'>, query: Params) => {
428
+ return (
429
+ pathname: string | null | undefined,
430
+ req: Pick<Request, 'headers' | 'url'>,
431
+ query: Params,
432
+ ) => {
389
433
  for (const matcher of matchers) {
390
434
  const routeMatch = new RegExp(matcher.regexp).exec(pathname!)
391
435
  if (!routeMatch) {
@@ -0,0 +1,26 @@
1
+ // If the redirect is a data URL, we need to normalize it.
2
+ // https://github.com/vercel/next.js/blob/25e0988e7c9033cb1503cbe0c62ba5de2e97849c/packages/next/src/shared/lib/router/utils/get-next-pathname-info.ts#L69-L76
3
+ export function normalizeDataUrl(redirect: string) {
4
+ if (redirect.startsWith('/_next/data/') && redirect.includes('.json')) {
5
+ const paths = redirect
6
+ .replace(/^\/_next\/data\//, '')
7
+ .replace(/\.json/, '')
8
+ .split('/')
9
+
10
+ redirect = paths[1] !== 'index' ? `/${paths.slice(1).join('/')}` : '/'
11
+ }
12
+
13
+ return redirect
14
+ }
15
+
16
+ /**
17
+ * This is how Next handles rewritten URLs.
18
+ */
19
+ export function relativizeURL(url: string | string, base: string | URL) {
20
+ const baseURL = typeof base === 'string' ? new URL(base) : base
21
+ const relative = new URL(url, base)
22
+ const origin = `${baseURL.protocol}//${baseURL.host}`
23
+ return `${relative.protocol}//${relative.host}` === origin
24
+ ? relative.toString().replace(origin, '')
25
+ : relative.toString()
26
+ }
@@ -0,0 +1,53 @@
1
+ import type { Context } from '@netlify/edge-functions'
2
+
3
+ import matchers from './matchers.json' assert { type: 'json' }
4
+
5
+ import { buildNextRequest, RequestData } from './lib/next-request.ts'
6
+ import { buildResponse } from './lib/response.ts'
7
+ import { FetchEventResult } from './lib/response.ts'
8
+ import {
9
+ type MiddlewareRouteMatch,
10
+ getMiddlewareRouteMatcher,
11
+ searchParamsToUrlQuery,
12
+ } from './lib/routing.ts'
13
+
14
+ type NextHandler = (params: { request: RequestData }) => Promise<FetchEventResult>
15
+
16
+ const matchesMiddleware: MiddlewareRouteMatch = getMiddlewareRouteMatcher(matchers || [])
17
+
18
+ /**
19
+ * Runs a Next.js middleware as a Netlify Edge Function. It translates a web
20
+ * platform Request into a NextRequest instance on the way in, and translates
21
+ * a NextResponse into a web platform Response on the way out.
22
+ *
23
+ * @param request Incoming request
24
+ * @param context Netlify-specific context object
25
+ * @param nextHandler Next.js middleware handler
26
+ */
27
+ export async function handleMiddleware(
28
+ request: Request,
29
+ context: Context,
30
+ nextHandler: NextHandler,
31
+ ) {
32
+ const nextRequest = buildNextRequest(request, context)
33
+ const url = new URL(request.url)
34
+
35
+ // While we have already checked the path when mapping to the edge function,
36
+ // Next.js supports extra rules that we need to check here too, because we
37
+ // might be running an edge function for a path we should not. If we find
38
+ // that's the case, short-circuit the execution.
39
+ if (!matchesMiddleware(url.pathname, request, searchParamsToUrlQuery(url.searchParams))) {
40
+ return
41
+ }
42
+
43
+ try {
44
+ const result = await nextHandler({ request: nextRequest })
45
+ const response = await buildResponse({ result, request: request, context })
46
+
47
+ return response
48
+ } catch (error) {
49
+ console.error(error)
50
+
51
+ return new Response(error.message, { status: 500 })
52
+ }
53
+ }
@@ -0,0 +1,11 @@
1
+ // NOTE: This is a fragment of a JavaScript program that will be inlined with
2
+ // a Webpack bundle. You should not import this file from anywhere in the
3
+ // application.
4
+ import { AsyncLocalStorage } from 'node:async_hooks'
5
+ import process from 'node:process'
6
+
7
+ globalThis.process = process
8
+
9
+ globalThis.AsyncLocalStorage = AsyncLocalStorage
10
+
11
+ var _ENTRIES = {}
@@ -53,7 +53,7 @@ export class HTMLRewriter {
53
53
  constructor() {
54
54
  if (!initialized.settled && !executing) {
55
55
  executing = true;
56
- fetch("https://deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter_bg.wasm")
56
+ fetch(new URL("./vendor/html_rewriter_bg.wasm", import.meta.url).href)
57
57
  .then(r => r.ok ? r : (() => { throw Error('WASM response not ok') })())
58
58
  .then(toWASMResponse)
59
59
  .then(initWASM)
@@ -0,0 +1,13 @@
1
+ {
2
+ "imports": {
3
+ "https://ghuc.cc/worker-tools/resolvable-promise/index.ts": "./raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts",
4
+ "https://deno.land/": "./deno.land/",
5
+ "https://esm.sh/": "./esm.sh/",
6
+ "https://raw.githubusercontent.com/": "./raw.githubusercontent.com/"
7
+ },
8
+ "scopes": {
9
+ "./esm.sh/": {
10
+ "/v91/next@12.2.5/deno/dist/compiled/cookie.js": "./esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js"
11
+ }
12
+ }
13
+ }