@wular/pnext 0.1.6 → 0.1.8
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.
- package/bin/pnext +9 -2
- package/dist/server/_chunks/aliases-pycbtjt1.js +46 -0
- package/dist/server/_chunks/analyze-4d9e00g9.js +449 -0
- package/dist/server/_chunks/boot-bhemypxz.js +38 -0
- package/dist/server/_chunks/build-c991dv65.js +86 -0
- package/dist/server/_chunks/build-kh5e3x48.js +3341 -0
- package/dist/server/_chunks/build-tier-0a96kmx3.js +2456 -0
- package/dist/server/_chunks/compile-040r79gj.js +22 -0
- package/dist/server/_chunks/config-0tvz03a6.js +24 -0
- package/dist/server/_chunks/config-27rj7830.js +36 -0
- package/dist/server/_chunks/create-9rvwshsp.js +135 -0
- package/dist/server/_chunks/dev-ex9exynt.js +220 -0
- package/dist/server/_chunks/esbuild-yyktfrtt.js +15 -0
- package/dist/server/_chunks/generate-myw9hef7.js +22 -0
- package/dist/server/_chunks/index-0r5eqfc7.js +279 -0
- package/dist/server/_chunks/index-0yjv5v47.js +105 -0
- package/dist/server/_chunks/index-11xpbfej.js +17 -0
- package/dist/server/_chunks/index-141vcwk6.js +109 -0
- package/dist/server/_chunks/index-1pzm1hdy.js +4130 -0
- package/dist/server/_chunks/index-29pq0kax.js +590 -0
- package/dist/server/_chunks/index-2vz0wzdn.js +59 -0
- package/dist/server/_chunks/index-2wfv4kvx.js +182 -0
- package/dist/server/_chunks/index-38xpdxwd.js +194 -0
- package/dist/server/_chunks/index-3e075kny.js +128 -0
- package/dist/server/_chunks/index-3ycf5ckv.js +472 -0
- package/dist/server/_chunks/index-4399bvd2.js +18 -0
- package/dist/server/_chunks/index-4da76t62.js +297 -0
- package/dist/server/_chunks/index-4t92hdxd.js +172 -0
- package/dist/server/_chunks/index-4zzebszd.js +10 -0
- package/dist/server/_chunks/index-52k54ykj.js +95 -0
- package/dist/server/_chunks/index-5hr4062s.js +70 -0
- package/dist/server/_chunks/index-68m3mwbd.js +84 -0
- package/dist/server/_chunks/index-6b009mt0.js +56 -0
- package/dist/server/_chunks/index-6gex3pfa.js +15 -0
- package/dist/server/_chunks/index-6kp9r0d9.js +11 -0
- package/dist/server/_chunks/index-6q7zvrap.js +134 -0
- package/dist/server/_chunks/index-71885zaq.js +284 -0
- package/dist/server/_chunks/index-73z4esab.js +38 -0
- package/dist/server/_chunks/index-79ngvam8.js +60 -0
- package/dist/server/_chunks/index-7wc9n8be.js +25 -0
- package/dist/server/_chunks/index-8ct7rqy3.js +198 -0
- package/dist/server/_chunks/index-8kcxdfya.js +206 -0
- package/dist/server/_chunks/index-9ch50vtq.js +18 -0
- package/dist/server/_chunks/index-9f49w76j.js +213 -0
- package/dist/server/_chunks/index-9hz3s0m8.js +851 -0
- package/dist/server/_chunks/index-akkrvjn6.js +535 -0
- package/dist/server/_chunks/index-b6wtkdp4.js +24 -0
- package/dist/server/_chunks/index-b7j671dj.js +207 -0
- package/dist/server/_chunks/index-bcws5eh2.js +35 -0
- package/dist/server/_chunks/index-bzd2ef7t.js +10 -0
- package/dist/server/_chunks/index-cjgqs13g.js +65 -0
- package/dist/server/_chunks/index-ckkdpht5.js +41 -0
- package/dist/server/_chunks/index-cn86z041.js +296 -0
- package/dist/server/_chunks/index-cvr4z22m.js +92 -0
- package/dist/server/_chunks/index-cyfednwb.js +87 -0
- package/dist/server/_chunks/index-d158y67j.js +152 -0
- package/dist/server/_chunks/index-d1jsmhhk.js +955 -0
- package/dist/server/_chunks/index-dg0f05zs.js +199 -0
- package/dist/server/_chunks/index-dgr390q7.js +9438 -0
- package/dist/server/_chunks/index-drwv61cc.js +185 -0
- package/dist/server/_chunks/index-e3a6yx84.js +18 -0
- package/dist/server/_chunks/index-e88tyv35.js +45 -0
- package/dist/server/_chunks/index-en7n9f7m.js +22 -0
- package/dist/server/_chunks/index-entm8bmz.js +28 -0
- package/dist/server/_chunks/index-evhd413j.js +57 -0
- package/dist/server/_chunks/index-ezgj0tr1.js +88 -0
- package/dist/server/_chunks/index-fjv96re1.js +5295 -0
- package/dist/server/_chunks/index-fn1chkkd.js +214 -0
- package/dist/server/_chunks/index-fp8r0sqs.js +64 -0
- package/dist/server/_chunks/index-gcmj16xy.js +92 -0
- package/dist/server/_chunks/index-gkndxkxf.js +736 -0
- package/dist/server/_chunks/index-grta8ap3.js +238 -0
- package/dist/server/_chunks/index-h2a70tg4.js +7 -0
- package/dist/server/_chunks/index-h4xy648y.js +51 -0
- package/dist/server/_chunks/index-hdbwtdv2.js +352 -0
- package/dist/server/_chunks/index-he6n2bvp.js +1270 -0
- package/dist/server/_chunks/index-j0m1jxqa.js +1253 -0
- package/dist/server/_chunks/index-j2zrcp1k.js +66 -0
- package/dist/server/_chunks/index-j681c48a.js +2530 -0
- package/dist/server/_chunks/index-jbj7ehef.js +50 -0
- package/dist/server/_chunks/index-jcsjq3d1.js +20 -0
- package/dist/server/_chunks/index-jks0x0a1.js +14 -0
- package/dist/server/_chunks/index-jn9rbhrx.js +1599 -0
- package/dist/server/_chunks/index-jt8e1pje.js +12 -0
- package/dist/server/_chunks/index-kdhxpwyq.js +483 -0
- package/dist/server/_chunks/index-knp0s912.js +7 -0
- package/dist/server/_chunks/index-kqyy1d4f.js +50 -0
- package/dist/server/_chunks/index-kresp2n8.js +445 -0
- package/dist/server/_chunks/index-m63czgq5.js +590 -0
- package/dist/server/_chunks/index-ms9v9tnx.js +31 -0
- package/dist/server/_chunks/index-n4hxpng2.js +11 -0
- package/dist/server/_chunks/index-n629dy38.js +1071 -0
- package/dist/server/_chunks/index-nf3df4jy.js +266 -0
- package/dist/server/_chunks/index-nqh3xhdc.js +57 -0
- package/dist/server/_chunks/index-pym1cezq.js +39 -0
- package/dist/server/_chunks/index-q3r9z8mq.js +213 -0
- package/dist/server/_chunks/index-q738kkhj.js +100 -0
- package/dist/server/_chunks/index-qcrvt6er.js +112 -0
- package/dist/server/_chunks/index-qjj6gddn.js +54 -0
- package/dist/server/_chunks/index-qpwsgt3a.js +158 -0
- package/dist/server/_chunks/index-r97ptz1q.js +97 -0
- package/dist/server/_chunks/index-ras0sdab.js +26 -0
- package/dist/server/_chunks/index-rcs322t1.js +19 -0
- package/dist/server/_chunks/index-rgj5mx84.js +101 -0
- package/dist/server/_chunks/index-rjegyfx4.js +1435 -0
- package/dist/server/_chunks/index-rt9qq1va.js +4 -0
- package/dist/server/_chunks/index-rthrsed5.js +356 -0
- package/dist/server/_chunks/index-sq3kvz3g.js +200 -0
- package/dist/server/_chunks/index-stbk3jhn.js +31 -0
- package/dist/server/_chunks/index-tf4j19ge.js +130 -0
- package/dist/server/_chunks/index-tgcakdxc.js +125 -0
- package/dist/server/_chunks/index-tgsfjmep.js +74 -0
- package/dist/server/_chunks/index-tq1f96v7.js +51 -0
- package/dist/server/_chunks/index-tq3b39a5.js +107 -0
- package/dist/server/_chunks/index-typcbcsv.js +819 -0
- package/dist/server/_chunks/index-v1ags1na.js +132 -0
- package/dist/server/_chunks/index-vmr35jjw.js +170 -0
- package/dist/server/_chunks/index-vvq7rqtn.js +329 -0
- package/dist/server/_chunks/index-vz0km5qk.js +33 -0
- package/dist/server/_chunks/index-w6h8m6vp.js +138 -0
- package/dist/server/_chunks/index-web361b8.js +138 -0
- package/dist/server/_chunks/index-wm36rj4v.js +311 -0
- package/dist/server/_chunks/index-x0y005nh.js +283 -0
- package/dist/server/_chunks/index-x2m17v9c.js +6166 -0
- package/dist/server/_chunks/index-x3yn4ywm.js +22 -0
- package/dist/server/_chunks/index-x9c55pzy.js +871 -0
- package/dist/server/_chunks/index-xh1nbk46.js +1299 -0
- package/dist/server/_chunks/index-xvj80c3a.js +30 -0
- package/dist/server/_chunks/index-xywjg2vc.js +100 -0
- package/dist/server/_chunks/index-y4d02znn.js +66 -0
- package/dist/server/_chunks/index-y7mzvq2q.js +110 -0
- package/dist/server/_chunks/index-ye9hmsvf.js +47 -0
- package/dist/server/_chunks/index-yhxkxghe.js +56 -0
- package/dist/server/_chunks/index-yrjkqtfj.js +86 -0
- package/dist/server/_chunks/index-z88qv16t.js +11 -0
- package/dist/server/_chunks/index-zfrwq472.js +154 -0
- package/dist/server/_chunks/index-zqpqyg8p.js +666 -0
- package/dist/server/_chunks/loader-5en7wpt5.js +80 -0
- package/dist/server/_chunks/modules-t92favpj.js +76 -0
- package/dist/server/_chunks/pipeline-4t9q43ht.js +836 -0
- package/dist/server/_chunks/production-385bw8df.js +55 -0
- package/dist/server/_chunks/proxy-config-60gprphe.js +23 -0
- package/dist/server/_chunks/proxy-gfhmktbk.js +35 -0
- package/dist/server/_chunks/router-xnrva921.js +501 -0
- package/dist/server/_chunks/routes-ht868pdc.js +66 -0
- package/dist/server/_chunks/run-d40d63ag.js +697 -0
- package/dist/server/_chunks/server-2p8fgqq2.js +1839 -0
- package/dist/server/_chunks/tsconfig-defaults-bcn34eqb.js +21 -0
- package/dist/server/_chunks/typegen-dvtcjtaw.js +37 -0
- package/dist/server/api/client-cache.js +14 -0
- package/dist/server/cli/index.js +375 -0
- package/dist/server/cli/start.js +158 -0
- package/dist/server/client/reference.js +16 -0
- package/dist/server/compat/next/cache.js +56 -0
- package/dist/server/compat/next/canonical-url.js +13 -0
- package/dist/server/compat/next/client-cache.js +57 -0
- package/dist/server/compat/next/client-navigation.js +232 -0
- package/dist/server/compat/next/client-only.js +1 -0
- package/dist/server/compat/next/client-script.js +178 -0
- package/dist/server/compat/next/client-server.js +34 -0
- package/dist/server/compat/next/config-headers.js +34 -0
- package/dist/server/compat/next/config-loader.js +25 -0
- package/dist/server/compat/next/config.js +10 -0
- package/dist/server/compat/next/constants.js +18 -0
- package/dist/server/compat/next/custom-server.js +10 -0
- package/dist/server/compat/next/dist/client/components/app-router-headers.js +48 -0
- package/dist/server/compat/next/dist/server/web/spec-extension/revalidate.js +27 -0
- package/dist/server/compat/next/dist/server/web/spec-extension/unstable-cache.js +25 -0
- package/dist/server/compat/next/dist/server/web/spec-extension/unstable-no-store.js +25 -0
- package/dist/server/compat/next/dynamic.js +21 -0
- package/dist/server/compat/next/error.js +112 -0
- package/dist/server/compat/next/font/cache.js +16 -0
- package/dist/server/compat/next/font/google.js +3 -0
- package/dist/server/compat/next/font/index.js +1 -0
- package/dist/server/compat/next/font/local.js +24 -0
- package/dist/server/compat/next/font/runtime-client.js +33 -0
- package/dist/server/compat/next/font/runtime.js +43 -0
- package/dist/server/compat/next/font/shared.js +22 -0
- package/dist/server/compat/next/form.js +129 -0
- package/dist/server/compat/next/head.js +10 -0
- package/dist/server/compat/next/headers.js +30 -0
- package/dist/server/compat/next/image/client.js +11 -0
- package/dist/server/compat/next/image/config.js +18 -0
- package/dist/server/compat/next/image/optimizer.js +25 -0
- package/dist/server/compat/next/image/patterns.js +12 -0
- package/dist/server/compat/next/image/props.js +16 -0
- package/dist/server/compat/next/image/shared.js +86 -0
- package/dist/server/compat/next/image/static-metadata.js +32 -0
- package/dist/server/compat/next/image/validate.js +8 -0
- package/dist/server/compat/next/image.js +59 -0
- package/dist/server/compat/next/index.js +1 -0
- package/dist/server/compat/next/legacy-image.js +78 -0
- package/dist/server/compat/next/legacy-request-apis.js +24 -0
- package/dist/server/compat/next/link-transform.js +15 -0
- package/dist/server/compat/next/link.js +14 -0
- package/dist/server/compat/next/navigation.js +191 -0
- package/dist/server/compat/next/offline.js +45 -0
- package/dist/server/compat/next/og.js +8 -0
- package/dist/server/compat/next/preferred-region.js +8 -0
- package/dist/server/compat/next/redirects.js +32 -0
- package/dist/server/compat/next/resource-hints.js +30 -0
- package/dist/server/compat/next/rewrites.js +43 -0
- package/dist/server/compat/next/root-params.js +121 -0
- package/dist/server/compat/next/route-state.js +23 -0
- package/dist/server/compat/next/router.js +103 -0
- package/dist/server/compat/next/script.js +37 -0
- package/dist/server/compat/next/server-only.js +1 -0
- package/dist/server/compat/next/server.js +131 -0
- package/dist/server/compat/next/svgr.js +14 -0
- package/dist/server/compat/next/telemetry.js +10 -0
- package/dist/server/compat/next/usage.js +13 -0
- package/dist/server/compat/next/user-agent.js +12 -0
- package/dist/server/compat/next/web-vitals.js +35 -0
- package/dist/server/compat/react/action-state.js +11 -0
- package/dist/server/compat/react/client-lite.js +83 -0
- package/dist/server/compat/react/client.js +131 -0
- package/dist/server/compat/react/compiler-runtime.js +42 -0
- package/dist/server/compat/react/dom-client.js +106 -0
- package/dist/server/compat/react/dom-react-server.js +37 -0
- package/dist/server/compat/react/dom-server.js +40 -0
- package/dist/server/compat/react/dom.js +52 -0
- package/dist/server/compat/react/hooks-extra.js +12 -0
- package/dist/server/compat/react/internals.js +14 -0
- package/dist/server/compat/react/parity.js +11 -0
- package/dist/server/compat/react/preact.js +113 -0
- package/dist/server/compat/react/react-server.js +133 -0
- package/dist/server/compat/react/router-shim.js +8 -0
- package/dist/server/compat/react/server-component-use.js +14 -0
- package/dist/server/compat/react/server-inserted-html.js +14 -0
- package/dist/server/compat/react/server.js +194 -0
- package/dist/server/compat/react/style-values.js +10 -0
- package/dist/server/compat/react/use.js +10 -0
- package/dist/server/compat/react/view-transition.js +12 -0
- package/dist/server/generation.json +1 -0
- package/package.json +4 -1
- package/reference/compat.md +1 -1
- package/reference/config.md +2 -2
- package/reference/dev.md +1 -1
- package/reference/getting-started.md +1 -1
- package/reference/rendering.md +4 -4
- package/src/api/dynamic.tsx +86 -4
- package/src/api/server.ts +24 -6
- package/src/cli/adapters/vercel-warm.ts +327 -62
- package/src/cli/adapters/vercel.ts +164 -1054
- package/src/cli/analyze.ts +3 -2
- package/src/cli/build/cache.ts +6 -6
- package/src/cli/build.ts +78 -45
- package/src/cli/index.ts +21 -3
- package/src/cli/serve/immutable.ts +31 -0
- package/src/cli/serve/pipeline.ts +97 -93
- package/src/cli/serve/standalone-worker.ts +8 -0
- package/src/cli/serve/standalone.ts +703 -0
- package/src/cli/start.ts +31 -8
- package/src/client/build.ts +1 -1
- package/src/client/chunk-fold.ts +19 -6
- package/src/client/react-tier.ts +3 -2
- package/src/client/reference-stub.ts +23 -36
- package/src/compat/actions/client-plugin.ts +4 -2
- package/src/compat/actions/config.ts +6 -5
- package/src/compat/actions/extensions.ts +5 -5
- package/src/compat/aliases.ts +8 -1
- package/src/compat/bundler/config.ts +88 -0
- package/src/compat/bundler/optimize-package-imports.ts +86 -26
- package/src/compat/bundler/relay-transform.ts +15 -3
- package/src/compat/bundler/require-context.ts +2 -1
- package/src/compat/bundler/webpack-loaders.ts +3 -2
- package/src/compat/bundler/worker.ts +2 -2
- package/src/compat/cache-control.ts +16 -8
- package/src/compat/css/inline-css.ts +1 -1
- package/src/compat/css/modules.ts +18 -5
- package/src/compat/export/build-complete.ts +1 -1
- package/src/compat/export/emit.ts +4 -4
- package/src/compat/export/standalone.ts +30 -65
- package/src/compat/image-optimizer/optimize.ts +1 -1
- package/src/compat/lifecycle/error-funnel.ts +1 -1
- package/src/compat/lifecycle/instrumentation-client.ts +4 -3
- package/src/compat/lifecycle/instrumentation.ts +117 -24
- package/src/compat/lifecycle/testmode.ts +3 -2
- package/src/compat/metadata-artifacts.ts +1 -1
- package/src/compat/next/config-loader.ts +140 -13
- package/src/compat/next/dynamic.tsx +10 -23
- package/src/compat/next/font/cache.ts +2 -1
- package/src/compat/next/font/runtime.ts +23 -3
- package/src/compat/next/og.ts +3 -3
- package/src/compat/next/usage.ts +3 -2
- package/src/compat/pages/api.ts +83 -14
- package/src/compat/pages/router.ts +30 -14
- package/src/compat/register/bundler.ts +3 -1
- package/src/compat/register/image.ts +1 -1
- package/src/compat/register/middleware.ts +1 -1
- package/src/compat/register/otel.ts +5 -9
- package/src/compat/register/render.ts +3 -1
- package/src/compat/register/use-cache.ts +3 -1
- package/src/compat/release.ts +46 -0
- package/src/compat/segment/serve.ts +1 -1
- package/src/compat/typecheck/check.ts +6 -4
- package/src/compat/validation/validate.ts +10 -7
- package/src/config.ts +76 -9
- package/src/css/assets.ts +213 -0
- package/src/css/build.ts +190 -247
- package/src/dev/client-chunk-store.ts +2 -1
- package/src/dev/restart/client-key.ts +2 -1
- package/src/dev/restart/global-css.ts +2 -1
- package/src/dev/restart/route-bundle-key.ts +2 -1
- package/src/dev/restart/route-facts.ts +2 -1
- package/src/dev/server.ts +34 -14
- package/src/extensions.ts +4 -0
- package/src/out-paths.ts +10 -0
- package/src/render/hooks.ts +13 -0
- package/src/render/renderer.ts +53 -33
- package/src/request/context.ts +9 -0
- package/src/resolve/dynamic.ts +7 -1
- package/src/resolve/engine.ts +2 -12
- package/src/resolve/imports.ts +12 -52
- package/src/resolve/package-json.ts +56 -0
- package/src/resolve/scan-facts.ts +250 -1
- package/src/routing/href.ts +10 -3
- package/src/routing/match.ts +287 -0
- package/src/routing/metadata-files.ts +20 -6
- package/src/routing/proxy-config.ts +137 -0
- package/src/routing/proxy.ts +35 -134
- package/src/routing/routes.ts +22 -281
- package/src/runtime/fingerprint.ts +23 -8
- package/src/runtime/load.ts +170 -0
- package/src/runtime/loader.ts +218 -44
- package/src/runtime/module-cache.ts +15 -1
- package/src/runtime/modules.ts +405 -82
- package/src/runtime/prebundle.ts +101 -0
- package/src/runtime/production.ts +456 -0
- package/src/runtime/release-graph.ts +342 -0
- package/src/runtime/vendor-build.ts +750 -17
- package/src/runtime/vendor.ts +16 -3
- package/src/types.ts +4 -3
- package/src/utils/directive.ts +40 -0
- package/src/utils/fs.ts +95 -4
- package/src/utils/resource-query.ts +12 -0
- package/src/cli/serve/entry.ts +0 -45
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
activateTestProxy
|
|
4
|
+
} from "./index-2wfv4kvx.js";
|
|
5
|
+
import {
|
|
6
|
+
nextCompatEnabled
|
|
7
|
+
} from "./index-kdhxpwyq.js";
|
|
8
|
+
import {
|
|
9
|
+
findProxyFiles,
|
|
10
|
+
setProxyRewriteObserver
|
|
11
|
+
} from "./index-3ycf5ckv.js";
|
|
12
|
+
import {
|
|
13
|
+
getNextConfig
|
|
14
|
+
} from "./index-m63czgq5.js";
|
|
15
|
+
import {
|
|
16
|
+
readText,
|
|
17
|
+
toPosixPath
|
|
18
|
+
} from "./index-4da76t62.js";
|
|
19
|
+
import {
|
|
20
|
+
recordCanonicalUrl
|
|
21
|
+
} from "./index-en7n9f7m.js";
|
|
22
|
+
import {
|
|
23
|
+
getWorkUnit,
|
|
24
|
+
legacyRequestAPIs
|
|
25
|
+
} from "./index-grta8ap3.js";
|
|
26
|
+
import {
|
|
27
|
+
moduleExportNames
|
|
28
|
+
} from "./index-x9c55pzy.js";
|
|
29
|
+
import {
|
|
30
|
+
setProxyExtensions,
|
|
31
|
+
setProxyResponseProtocol
|
|
32
|
+
} from "./index-zqpqyg8p.js";
|
|
33
|
+
|
|
34
|
+
// src/compat/register/proxy.ts
|
|
35
|
+
import path from "path";
|
|
36
|
+
|
|
37
|
+
// src/compat/protocol.ts
|
|
38
|
+
var ROUTER_VARY = [
|
|
39
|
+
"rsc",
|
|
40
|
+
"next-router-state-tree",
|
|
41
|
+
"next-router-prefetch",
|
|
42
|
+
"next-router-segment-prefetch"
|
|
43
|
+
];
|
|
44
|
+
var rewrites = new WeakMap;
|
|
45
|
+
function recordRewrite(from, to) {
|
|
46
|
+
const unit = getWorkUnit();
|
|
47
|
+
if (!unit)
|
|
48
|
+
return;
|
|
49
|
+
if (from.pathname === to.pathname && from.search === to.search)
|
|
50
|
+
return;
|
|
51
|
+
const query = to.search.replace(/^\?/, "");
|
|
52
|
+
rewrites.set(unit, {
|
|
53
|
+
...to.pathname !== from.pathname ? { path: to.pathname } : {},
|
|
54
|
+
...query ? { query } : {}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
var CACHE_BUSTING_REDIRECT_HEADER = "x-pnext-cache-bust";
|
|
58
|
+
var APP_ROUTE_KINDS = new Set([
|
|
59
|
+
"html",
|
|
60
|
+
"data",
|
|
61
|
+
"route-handler"
|
|
62
|
+
]);
|
|
63
|
+
var protocolFinalizer = (ctx) => {
|
|
64
|
+
if (!APP_ROUTE_KINDS.has(ctx.routeKind))
|
|
65
|
+
return;
|
|
66
|
+
if (!isPlainRedirect(ctx))
|
|
67
|
+
mergeVary(ctx.headers, ROUTER_VARY);
|
|
68
|
+
normalizeRscRedirectStatus(ctx);
|
|
69
|
+
applyRewrittenHeaders(ctx);
|
|
70
|
+
applyEdgeRuntimeHeader(ctx);
|
|
71
|
+
};
|
|
72
|
+
function isPlainRedirect(ctx) {
|
|
73
|
+
if (ctx.status < 300 || ctx.status >= 400 || !ctx.headers.has("location"))
|
|
74
|
+
return false;
|
|
75
|
+
return ctx.request.headers.get("rsc") !== "1" && !ctx.request.headers.has("next-router-prefetch") && !ctx.request.headers.has("next-router-segment-prefetch");
|
|
76
|
+
}
|
|
77
|
+
function applyEdgeRuntimeHeader(ctx) {
|
|
78
|
+
const runtime = ctx.hints?.runtime;
|
|
79
|
+
if (runtime === "edge" || runtime === "experimental-edge") {
|
|
80
|
+
ctx.headers.set("x-edge-runtime", "1");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function mergeVary(headers, values) {
|
|
84
|
+
const existing = headers.get("vary");
|
|
85
|
+
const present = new Set((existing ?? "").split(",").map((token) => token.trim().toLowerCase()).filter(Boolean));
|
|
86
|
+
const merged = existing ? existing.split(",").map((token) => token.trim()).filter(Boolean) : [];
|
|
87
|
+
for (const value of values) {
|
|
88
|
+
if (present.has(value.toLowerCase()))
|
|
89
|
+
continue;
|
|
90
|
+
present.add(value.toLowerCase());
|
|
91
|
+
merged.push(value);
|
|
92
|
+
}
|
|
93
|
+
if (merged.length > 0)
|
|
94
|
+
headers.set("vary", merged.join(", "));
|
|
95
|
+
}
|
|
96
|
+
function applyRewrittenHeaders(ctx) {
|
|
97
|
+
if (ctx.request.headers.get("rsc") !== "1")
|
|
98
|
+
return;
|
|
99
|
+
const unit = getWorkUnit();
|
|
100
|
+
if (!unit)
|
|
101
|
+
return;
|
|
102
|
+
const info = rewrites.get(unit);
|
|
103
|
+
if (!info)
|
|
104
|
+
return;
|
|
105
|
+
if (info.path !== undefined)
|
|
106
|
+
ctx.headers.set("x-nextjs-rewritten-path", info.path);
|
|
107
|
+
if (info.query !== undefined)
|
|
108
|
+
ctx.headers.set("x-nextjs-rewritten-query", info.query);
|
|
109
|
+
}
|
|
110
|
+
function normalizeRscRedirectStatus(ctx) {
|
|
111
|
+
if (ctx.headers.has(CACHE_BUSTING_REDIRECT_HEADER)) {
|
|
112
|
+
ctx.headers.delete(CACHE_BUSTING_REDIRECT_HEADER);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (ctx.routeKind !== "html")
|
|
116
|
+
return;
|
|
117
|
+
if (ctx.request.headers.get("rsc") !== "1")
|
|
118
|
+
return;
|
|
119
|
+
if (ctx.request.headers.has("x-pnext-soft-nav"))
|
|
120
|
+
return;
|
|
121
|
+
if (!ctx.headers.has("location"))
|
|
122
|
+
return;
|
|
123
|
+
if (ctx.status !== 307 && ctx.status !== 308)
|
|
124
|
+
return;
|
|
125
|
+
ctx.status = 200;
|
|
126
|
+
}
|
|
127
|
+
function isValidFlightRouterState(value) {
|
|
128
|
+
if (!Array.isArray(value))
|
|
129
|
+
return false;
|
|
130
|
+
const [segment, parallelRoutes] = value;
|
|
131
|
+
if (typeof segment !== "string" && !Array.isArray(segment))
|
|
132
|
+
return false;
|
|
133
|
+
if (typeof parallelRoutes !== "object" || parallelRoutes === null)
|
|
134
|
+
return false;
|
|
135
|
+
if (Array.isArray(parallelRoutes))
|
|
136
|
+
return false;
|
|
137
|
+
return Object.values(parallelRoutes).every(isValidFlightRouterState);
|
|
138
|
+
}
|
|
139
|
+
var routerStateTreeInterceptor = (request) => Promise.resolve(validateRouterStateTree(request));
|
|
140
|
+
function validateRouterStateTree(request) {
|
|
141
|
+
if (request.headers.get("rsc") !== "1")
|
|
142
|
+
return;
|
|
143
|
+
if (request.headers.has("x-pnext-soft-nav"))
|
|
144
|
+
return;
|
|
145
|
+
const header = request.headers.get("next-router-state-tree");
|
|
146
|
+
if (header === null)
|
|
147
|
+
return;
|
|
148
|
+
let tree;
|
|
149
|
+
try {
|
|
150
|
+
tree = JSON.parse(decodeURIComponent(header));
|
|
151
|
+
} catch {
|
|
152
|
+
try {
|
|
153
|
+
tree = JSON.parse(header);
|
|
154
|
+
} catch {
|
|
155
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return isValidFlightRouterState(tree) ? undefined : new Response("Internal Server Error", { status: 500 });
|
|
159
|
+
}
|
|
160
|
+
function protocolInterceptors(config) {
|
|
161
|
+
if (!nextCompatEnabled(config))
|
|
162
|
+
return [];
|
|
163
|
+
return [routerStateTreeInterceptor];
|
|
164
|
+
}
|
|
165
|
+
function protocolFinalizers(config) {
|
|
166
|
+
if (!nextCompatEnabled(config))
|
|
167
|
+
return [];
|
|
168
|
+
return [protocolFinalizer];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/compat/register/proxy.ts
|
|
172
|
+
function registerProxyExtensions(_config) {
|
|
173
|
+
setProxyResponseProtocol({
|
|
174
|
+
nextHeader: "x-middleware-next",
|
|
175
|
+
rewriteHeader: "x-middleware-rewrite"
|
|
176
|
+
});
|
|
177
|
+
setProxyExtensions({
|
|
178
|
+
names: ["proxy", "middleware"],
|
|
179
|
+
validateFiles: validateNextProxyFiles,
|
|
180
|
+
handlerExport: (module) => module.proxy ?? module.default ?? module.middleware,
|
|
181
|
+
skipUrlNormalize: () => getNextConfig().skipProxyUrlNormalize === true,
|
|
182
|
+
locale: proxyLocale,
|
|
183
|
+
onExternalRewrite: (request) => activateTestProxy(request.headers),
|
|
184
|
+
clientMaxBodySize: proxyClientMaxBodySize
|
|
185
|
+
});
|
|
186
|
+
setProxyRewriteObserver((from, to) => {
|
|
187
|
+
recordCanonicalUrl(from);
|
|
188
|
+
recordRewrite(from, to);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
var DEFAULT_PROXY_CLIENT_MAX_BODY_SIZE = 10 * 1024 * 1024;
|
|
192
|
+
function proxyClientMaxBodySize() {
|
|
193
|
+
const experimental = getNextConfig().experimental ?? {};
|
|
194
|
+
const raw = experimental.proxyClientMaxBodySize ?? experimental.middlewareClientMaxBodySize;
|
|
195
|
+
if (typeof raw === "number" && raw > 0)
|
|
196
|
+
return raw;
|
|
197
|
+
if (typeof raw === "string") {
|
|
198
|
+
const match = /^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?$/i.exec(raw.trim());
|
|
199
|
+
if (match?.[1]) {
|
|
200
|
+
const unit = (match[2] ?? "b").toLowerCase();
|
|
201
|
+
const multiplier = unit === "gb" ? 1024 ** 3 : unit === "mb" ? 1024 ** 2 : unit === "kb" ? 1024 : 1;
|
|
202
|
+
const bytes = Math.floor(Number(match[1]) * multiplier);
|
|
203
|
+
if (bytes > 0)
|
|
204
|
+
return bytes;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return DEFAULT_PROXY_CLIENT_MAX_BODY_SIZE;
|
|
208
|
+
}
|
|
209
|
+
function proxyLocale(url) {
|
|
210
|
+
const i18n = getNextConfig().i18n;
|
|
211
|
+
if (!Array.isArray(i18n?.locales))
|
|
212
|
+
return "";
|
|
213
|
+
const locales = i18n.locales.filter((locale) => typeof locale === "string");
|
|
214
|
+
const dataLocale = /^\/_next\/data\/[^/]+\/([^/]+)(?:\/|$)/.exec(url.pathname)?.[1];
|
|
215
|
+
const candidate = dataLocale ?? url.pathname.split("/")[1];
|
|
216
|
+
return locales.find((locale) => locale.toLowerCase() === candidate?.toLowerCase()) ?? "";
|
|
217
|
+
}
|
|
218
|
+
async function validateNextProxyFiles(config) {
|
|
219
|
+
const files = findProxyFiles(config, ["proxy", "middleware"]);
|
|
220
|
+
const middleware = files.find((file) => path.basename(file).startsWith("middleware."));
|
|
221
|
+
const proxy = files.find((file) => path.basename(file).startsWith("proxy."));
|
|
222
|
+
if (middleware && proxy) {
|
|
223
|
+
throw new Error(`Both middleware file "${relativeProxyPath(config, middleware)}" and proxy file "${relativeProxyPath(config, proxy)}" are detected. Please use "${relativeProxyPath(config, proxy)}" only.`);
|
|
224
|
+
}
|
|
225
|
+
if (middleware && !proxy && !legacyRequestAPIs()) {
|
|
226
|
+
console.warn('The "middleware" file convention is deprecated. Please use "proxy" instead.');
|
|
227
|
+
}
|
|
228
|
+
await Promise.all(files.map((file) => validateNextProxyFile(config, file)));
|
|
229
|
+
}
|
|
230
|
+
async function validateNextProxyFile(config, file) {
|
|
231
|
+
const source = await readText(file);
|
|
232
|
+
const name = path.basename(file).split(".")[0];
|
|
233
|
+
const exports = moduleExportNames(source, file);
|
|
234
|
+
const validExport = exports.includes("default") || (name === "proxy" ? exports.includes("proxy") : exports.includes("middleware"));
|
|
235
|
+
if (!validExport) {
|
|
236
|
+
throw new Error(proxyMissingExportError(config, file));
|
|
237
|
+
}
|
|
238
|
+
if (name === "proxy" && hasRuntimeConfig(source)) {
|
|
239
|
+
throw new Error(`Route segment config is not allowed in Proxy file at "${relativeProxyPath(config, file)}". Proxy always runs on Node.js runtime. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function proxyMissingExportError(config, file) {
|
|
243
|
+
const name = path.basename(file).split(".")[0] === "middleware" ? "middleware" : "proxy";
|
|
244
|
+
const migrationReason = name === "proxy" ? "- You are migrating from `middleware` to `proxy`, but haven't updated the exported function.\n" : "";
|
|
245
|
+
const target = name === "proxy" ? "proxy (previously called middleware)" : "middleware";
|
|
246
|
+
return `The file "${relativeProxyPath(config, file)}" must export a function, either as a default export or as a named "${name}" export.
|
|
247
|
+
This function is what Next.js runs for every request handled by this ${target}.
|
|
248
|
+
|
|
249
|
+
Why this happens:
|
|
250
|
+
${migrationReason}- The file exists but doesn't export a function.
|
|
251
|
+
- The export is not a function (e.g., an object or constant).
|
|
252
|
+
- There's a syntax error preventing the export from being recognized.
|
|
253
|
+
|
|
254
|
+
To fix it:
|
|
255
|
+
- Ensure this file has either a default or "${name}" function export.
|
|
256
|
+
|
|
257
|
+
Learn more: https://nextjs.org/docs/messages/middleware-to-proxy`;
|
|
258
|
+
}
|
|
259
|
+
function hasRuntimeConfig(source) {
|
|
260
|
+
return /\bexport\s+const\s+config\s*=/.test(source) && /\bruntime\s*:/.test(source);
|
|
261
|
+
}
|
|
262
|
+
function relativeProxyPath(config, file) {
|
|
263
|
+
return `./${toPosixPath(path.relative(config.root, file))}`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export { recordRewrite, CACHE_BUSTING_REDIRECT_HEADER, protocolInterceptors, protocolFinalizers, registerProxyExtensions };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/compat/react/server-inserted-html.ts
|
|
3
|
+
import { h, Fragment } from "preact";
|
|
4
|
+
import renderToString from "preact-render-to-string";
|
|
5
|
+
var collectorKey = Symbol.for("pnext.serverInsertedHTML");
|
|
6
|
+
var SCOPE_GETTER_KEY = Symbol.for("pnext.serverInsertedHTMLScope");
|
|
7
|
+
function setServerInsertedHTMLScope(getter) {
|
|
8
|
+
globalThis[SCOPE_GETTER_KEY] = getter;
|
|
9
|
+
}
|
|
10
|
+
function requestScope() {
|
|
11
|
+
const getter = globalThis[SCOPE_GETTER_KEY];
|
|
12
|
+
return getter?.();
|
|
13
|
+
}
|
|
14
|
+
function collector() {
|
|
15
|
+
const scope = requestScope();
|
|
16
|
+
if (scope) {
|
|
17
|
+
return {
|
|
18
|
+
callbacks: scope[collectorKey] ??= [],
|
|
19
|
+
scoped: true
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const holder = globalThis;
|
|
23
|
+
holder.__PNEXT_SERVER_INSERTED_HTML__ ??= [];
|
|
24
|
+
return { callbacks: holder.__PNEXT_SERVER_INSERTED_HTML__, scoped: false };
|
|
25
|
+
}
|
|
26
|
+
var isServer = typeof document === "undefined";
|
|
27
|
+
function useServerInsertedHTML(callback) {
|
|
28
|
+
if (!isServer)
|
|
29
|
+
return;
|
|
30
|
+
collector().callbacks.push(callback);
|
|
31
|
+
}
|
|
32
|
+
function renderServerInsertedHTML() {
|
|
33
|
+
const { callbacks, scoped } = collector();
|
|
34
|
+
if (!scoped)
|
|
35
|
+
globalThis.__PNEXT_SERVER_INSERTED_HTML__ = [];
|
|
36
|
+
if (callbacks.length === 0)
|
|
37
|
+
return "";
|
|
38
|
+
const parts = [];
|
|
39
|
+
for (const callback of callbacks) {
|
|
40
|
+
try {
|
|
41
|
+
const node = callback();
|
|
42
|
+
if (node == null || node === false)
|
|
43
|
+
continue;
|
|
44
|
+
parts.push(renderToString(h(Fragment, null, node)));
|
|
45
|
+
} catch {}
|
|
46
|
+
}
|
|
47
|
+
return parts.join("");
|
|
48
|
+
}
|
|
49
|
+
function clearServerInsertedHTML() {
|
|
50
|
+
const scope = requestScope();
|
|
51
|
+
if (scope)
|
|
52
|
+
scope[collectorKey] = [];
|
|
53
|
+
else
|
|
54
|
+
globalThis.__PNEXT_SERVER_INSERTED_HTML__ = [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { setServerInsertedHTMLScope, useServerInsertedHTML, renderServerInsertedHTML, clearServerInsertedHTML };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/resolve/package-json.ts
|
|
3
|
+
import { existsSync, readFileSync } from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
var packageJsonCache = new Map;
|
|
6
|
+
var workspaceRootCache = new Map;
|
|
7
|
+
function readPackageJson(root) {
|
|
8
|
+
const existing = packageJsonCache.get(root);
|
|
9
|
+
if (existing)
|
|
10
|
+
return existing;
|
|
11
|
+
const config = readJson(path.join(root, "package.json")) ?? {};
|
|
12
|
+
packageJsonCache.set(root, config);
|
|
13
|
+
return config;
|
|
14
|
+
}
|
|
15
|
+
function findWorkspaceRoot(root) {
|
|
16
|
+
const key = path.resolve(root);
|
|
17
|
+
if (workspaceRootCache.has(key))
|
|
18
|
+
return workspaceRootCache.get(key);
|
|
19
|
+
let dir = key;
|
|
20
|
+
while (true) {
|
|
21
|
+
if (readPackageJson(dir).workspaces || existsSync(path.join(dir, "pnpm-workspace.yaml"))) {
|
|
22
|
+
workspaceRootCache.set(key, dir);
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
25
|
+
const parent = path.dirname(dir);
|
|
26
|
+
if (parent === dir) {
|
|
27
|
+
workspaceRootCache.set(key, undefined);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
dir = parent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function readJson(file) {
|
|
34
|
+
if (!existsSync(file))
|
|
35
|
+
return;
|
|
36
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { readPackageJson, findWorkspaceRoot };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
generateBlurDataURL
|
|
4
|
+
} from "./index-typcbcsv.js";
|
|
5
|
+
import {
|
|
6
|
+
isSvgAsComponentEnabled,
|
|
7
|
+
svgComponentModule
|
|
8
|
+
} from "./index-ckkdpht5.js";
|
|
9
|
+
|
|
10
|
+
// src/compat/next/image/static-metadata.ts
|
|
11
|
+
import { createHash } from "crypto";
|
|
12
|
+
import path from "path";
|
|
13
|
+
var STATIC_IMAGE_EXTENSIONS = new Set([
|
|
14
|
+
".png",
|
|
15
|
+
".jpg",
|
|
16
|
+
".jpeg",
|
|
17
|
+
".gif",
|
|
18
|
+
".webp",
|
|
19
|
+
".avif",
|
|
20
|
+
".svg",
|
|
21
|
+
".ico",
|
|
22
|
+
".bmp"
|
|
23
|
+
]);
|
|
24
|
+
async function staticImageModule(context) {
|
|
25
|
+
const ext = path.extname(context.sourcePath).toLowerCase();
|
|
26
|
+
if (ext === ".svg" && isSvgAsComponentEnabled())
|
|
27
|
+
return svgComponentModule(context.bytes);
|
|
28
|
+
if (!STATIC_IMAGE_EXTENSIONS.has(ext))
|
|
29
|
+
return;
|
|
30
|
+
const src = context.emit(staticMediaRelative(context.sourcePath, context.bytes), context.bytes);
|
|
31
|
+
const data = await staticImageData(src, context.sourcePath, context.bytes);
|
|
32
|
+
return staticImageModuleText(data);
|
|
33
|
+
}
|
|
34
|
+
function staticMediaRelative(sourcePath, bytes) {
|
|
35
|
+
const ext = path.extname(sourcePath).toLowerCase() || ".bin";
|
|
36
|
+
const hash = createHash("sha256").update(bytes).digest("hex").slice(0, 8);
|
|
37
|
+
const base = path.basename(sourcePath, path.extname(sourcePath)).replace(/[^A-Za-z0-9_-]+/g, "-");
|
|
38
|
+
return path.posix.join("_next", "static", "media", `${base}.${hash}${ext}`);
|
|
39
|
+
}
|
|
40
|
+
async function staticImageData(src, sourcePath, bytes) {
|
|
41
|
+
const ext = path.extname(sourcePath).toLowerCase() || ".bin";
|
|
42
|
+
const dimensions = imageDimensions(bytes, ext);
|
|
43
|
+
const { blurWidth, blurHeight } = blurDimensions(dimensions);
|
|
44
|
+
const blurDataURL = await generateBlurDataURL(Buffer.from(bytes), ext.slice(1), blurWidth, blurHeight) ?? "";
|
|
45
|
+
return {
|
|
46
|
+
src,
|
|
47
|
+
width: dimensions?.width ?? 0,
|
|
48
|
+
height: dimensions?.height ?? 0,
|
|
49
|
+
blurDataURL,
|
|
50
|
+
blurWidth: blurDataURL ? blurWidth : 0,
|
|
51
|
+
blurHeight: blurDataURL ? blurHeight : 0
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function staticImageModuleText(image) {
|
|
55
|
+
return `const image = ${JSON.stringify(image)};
|
|
56
|
+
export default image;
|
|
57
|
+
export const src = image.src;
|
|
58
|
+
export const width = image.width;
|
|
59
|
+
export const height = image.height;
|
|
60
|
+
export const blurDataURL = image.blurDataURL;
|
|
61
|
+
export const blurWidth = image.blurWidth;
|
|
62
|
+
export const blurHeight = image.blurHeight;
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
var textDecoder = new TextDecoder;
|
|
66
|
+
function imageDimensions(bytes, ext) {
|
|
67
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
68
|
+
switch (ext) {
|
|
69
|
+
case ".png":
|
|
70
|
+
return pngDimensions(view);
|
|
71
|
+
case ".jpg":
|
|
72
|
+
case ".jpeg":
|
|
73
|
+
return jpegDimensions(view);
|
|
74
|
+
case ".gif":
|
|
75
|
+
return gifDimensions(view);
|
|
76
|
+
case ".webp":
|
|
77
|
+
return webpDimensions(view, bytes);
|
|
78
|
+
case ".bmp":
|
|
79
|
+
return bmpDimensions(view);
|
|
80
|
+
case ".avif":
|
|
81
|
+
return avifDimensions(bytes);
|
|
82
|
+
case ".svg":
|
|
83
|
+
return svgDimensions(bytes);
|
|
84
|
+
case ".ico":
|
|
85
|
+
return icoDimensions(view);
|
|
86
|
+
default:
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function pngDimensions(view) {
|
|
91
|
+
if (view.byteLength < 24)
|
|
92
|
+
return;
|
|
93
|
+
if (view.getUint32(0) !== 2303741511)
|
|
94
|
+
return;
|
|
95
|
+
return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
96
|
+
}
|
|
97
|
+
function jpegDimensions(view) {
|
|
98
|
+
if (view.byteLength < 4 || view.getUint16(0) !== 65496)
|
|
99
|
+
return;
|
|
100
|
+
let offset = 2;
|
|
101
|
+
while (offset + 9 < view.byteLength) {
|
|
102
|
+
if (view.getUint8(offset) !== 255) {
|
|
103
|
+
offset += 1;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const marker = view.getUint8(offset + 1);
|
|
107
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
108
|
+
return { height: view.getUint16(offset + 5), width: view.getUint16(offset + 7) };
|
|
109
|
+
}
|
|
110
|
+
const segmentLength = view.getUint16(offset + 2);
|
|
111
|
+
if (segmentLength < 2)
|
|
112
|
+
return;
|
|
113
|
+
offset += 2 + segmentLength;
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
function gifDimensions(view) {
|
|
118
|
+
if (view.byteLength < 10)
|
|
119
|
+
return;
|
|
120
|
+
if (view.getUint32(0) !== 1195984440)
|
|
121
|
+
return;
|
|
122
|
+
return { width: view.getUint16(6, true), height: view.getUint16(8, true) };
|
|
123
|
+
}
|
|
124
|
+
function webpDimensions(view, bytes) {
|
|
125
|
+
if (view.byteLength < 30)
|
|
126
|
+
return;
|
|
127
|
+
if (view.getUint32(0) !== 1380533830 || view.getUint32(8) !== 1464156752)
|
|
128
|
+
return;
|
|
129
|
+
const format = textDecoder.decode(bytes.subarray(12, 16));
|
|
130
|
+
if (format === "VP8 ") {
|
|
131
|
+
return {
|
|
132
|
+
width: view.getUint16(26, true) & 16383,
|
|
133
|
+
height: view.getUint16(28, true) & 16383
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (format === "VP8L") {
|
|
137
|
+
const bits = view.getUint32(21, true);
|
|
138
|
+
return {
|
|
139
|
+
width: (bits & 16383) + 1,
|
|
140
|
+
height: (bits >> 14 & 16383) + 1
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (format === "VP8X") {
|
|
144
|
+
const width = (bytes[24] | bytes[25] << 8 | bytes[26] << 16) + 1;
|
|
145
|
+
const height = (bytes[27] | bytes[28] << 8 | bytes[29] << 16) + 1;
|
|
146
|
+
return { width, height };
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
function bmpDimensions(view) {
|
|
151
|
+
if (view.byteLength < 26 || view.getUint16(0) !== 16973)
|
|
152
|
+
return;
|
|
153
|
+
return { width: view.getInt32(18, true), height: Math.abs(view.getInt32(22, true)) };
|
|
154
|
+
}
|
|
155
|
+
function icoDimensions(view) {
|
|
156
|
+
if (view.byteLength < 8 || view.getUint16(0, true) !== 0 || view.getUint16(2, true) !== 1) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const width = view.getUint8(6) || 256;
|
|
160
|
+
const height = view.getUint8(7) || 256;
|
|
161
|
+
return { width, height };
|
|
162
|
+
}
|
|
163
|
+
function avifDimensions(bytes) {
|
|
164
|
+
const marker = [105, 115, 112, 101];
|
|
165
|
+
for (let i = 0;i + 12 <= bytes.length; i += 1) {
|
|
166
|
+
if (bytes[i] === marker[0] && bytes[i + 1] === marker[1] && bytes[i + 2] === marker[2] && bytes[i + 3] === marker[3]) {
|
|
167
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
168
|
+
return { width: view.getUint32(i + 8), height: view.getUint32(i + 12) };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
function svgDimensions(bytes) {
|
|
174
|
+
const head = textDecoder.decode(bytes.subarray(0, Math.min(bytes.length, 4096)));
|
|
175
|
+
const svgTag = /<svg[^>]*>/i.exec(head)?.[0];
|
|
176
|
+
if (!svgTag)
|
|
177
|
+
return;
|
|
178
|
+
const width = svgLength(svgTag, "width");
|
|
179
|
+
const height = svgLength(svgTag, "height");
|
|
180
|
+
if (width && height)
|
|
181
|
+
return { width, height };
|
|
182
|
+
const viewBox = /viewBox\s*=\s*["']?\s*[\d.]+[ ,]+[\d.]+[ ,]+([\d.]+)[ ,]+([\d.]+)/i.exec(svgTag);
|
|
183
|
+
if (viewBox?.[1] && viewBox[2]) {
|
|
184
|
+
return { width: Math.round(Number(viewBox[1])), height: Math.round(Number(viewBox[2])) };
|
|
185
|
+
}
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
function svgLength(tag, attr) {
|
|
189
|
+
const match = new RegExp(`${attr}\\s*=\\s*["']?\\s*([\\d.]+)`, "i").exec(tag);
|
|
190
|
+
if (!match?.[1])
|
|
191
|
+
return;
|
|
192
|
+
const value = Number(match[1]);
|
|
193
|
+
return Number.isFinite(value) && value > 0 ? Math.round(value) : undefined;
|
|
194
|
+
}
|
|
195
|
+
var BLUR_IMG_SIZE = 8;
|
|
196
|
+
function blurDimensions(dimensions) {
|
|
197
|
+
if (!dimensions || dimensions.width <= 0 || dimensions.height <= 0) {
|
|
198
|
+
return { blurWidth: BLUR_IMG_SIZE, blurHeight: BLUR_IMG_SIZE };
|
|
199
|
+
}
|
|
200
|
+
const { width, height } = dimensions;
|
|
201
|
+
if (width >= height) {
|
|
202
|
+
return {
|
|
203
|
+
blurWidth: BLUR_IMG_SIZE,
|
|
204
|
+
blurHeight: Math.max(Math.round(height / width * BLUR_IMG_SIZE), 1)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
blurWidth: Math.max(Math.round(width / height * BLUR_IMG_SIZE), 1),
|
|
209
|
+
blurHeight: BLUR_IMG_SIZE
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { staticImageModule, staticMediaRelative, staticImageData, staticImageModuleText, imageDimensions, blurDimensions };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
bold,
|
|
4
|
+
cyan,
|
|
5
|
+
dim,
|
|
6
|
+
green
|
|
7
|
+
} from "./index-6kp9r0d9.js";
|
|
8
|
+
|
|
9
|
+
// src/cli/serve/ui.ts
|
|
10
|
+
import { networkInterfaces } from "os";
|
|
11
|
+
function browserHost(hostname) {
|
|
12
|
+
if (hostname === "::" || hostname === "::1")
|
|
13
|
+
return "[::1]";
|
|
14
|
+
if (["0.0.0.0", "127.0.0.1"].includes(hostname))
|
|
15
|
+
return "localhost";
|
|
16
|
+
return hostname;
|
|
17
|
+
}
|
|
18
|
+
function printServerReady({ mode, hostname, port, elapsedMs }) {
|
|
19
|
+
const rows = [["Local:", cyan(`http://${browserHost(hostname)}:${port}`)]];
|
|
20
|
+
const lan = hostname === "::" ? "[::]" : wildcard(hostname) ? lanAddress() : undefined;
|
|
21
|
+
if (lan)
|
|
22
|
+
rows.push(["Network:", cyan(`http://${lan}:${port}`)]);
|
|
23
|
+
const ready = elapsedMs === undefined ? `${green("\u2713")} ${bold("Ready")}` : `${green("\u2713")} ${bold("Ready")} ${dim(`in ${Math.round(elapsedMs)}ms`)}`;
|
|
24
|
+
const pad = Math.max(...rows.map(([label]) => label.length));
|
|
25
|
+
console.log("");
|
|
26
|
+
console.log(`\u26A1 ${bold("pnext")} ${dim(mode)}`);
|
|
27
|
+
for (const [label, value] of rows) {
|
|
28
|
+
console.log(` ${dim("-")} ${dim(label.padEnd(pad))} ${value}`);
|
|
29
|
+
}
|
|
30
|
+
console.log("");
|
|
31
|
+
console.log(ready);
|
|
32
|
+
console.log("");
|
|
33
|
+
}
|
|
34
|
+
function wildcard(hostname) {
|
|
35
|
+
return hostname === "0.0.0.0" || hostname === "::";
|
|
36
|
+
}
|
|
37
|
+
async function ensurePortFree(port, hostname, options = {}) {
|
|
38
|
+
const attempts = options.attempts ?? 1;
|
|
39
|
+
const delayMs = options.delayMs ?? 300;
|
|
40
|
+
const candidates = wildcard(hostname) || hostname === "localhost" ? ["127.0.0.1", "::1"] : [hostname];
|
|
41
|
+
for (const candidate of candidates) {
|
|
42
|
+
let inUse = await portInUse(candidate, port);
|
|
43
|
+
for (let attempt = 1;inUse && attempt < attempts; attempt += 1) {
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
45
|
+
inUse = await portInUse(candidate, port);
|
|
46
|
+
}
|
|
47
|
+
if (inUse) {
|
|
48
|
+
throw new Error(`Port ${port} is already in use on ${candidate} (another pnext dev/start or process). ` + `Stop it or pass --port. To find it:` + ` lsof -nP -iTCP:${port} -sTCP:LISTEN`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function portInUse(hostname, port) {
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
const timer = setTimeout(() => resolve(false), 300);
|
|
55
|
+
Bun.connect({
|
|
56
|
+
hostname,
|
|
57
|
+
port,
|
|
58
|
+
socket: {
|
|
59
|
+
open(socket) {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
socket.end();
|
|
62
|
+
resolve(true);
|
|
63
|
+
},
|
|
64
|
+
data() {},
|
|
65
|
+
connectError() {
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
resolve(false);
|
|
68
|
+
},
|
|
69
|
+
error() {
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
resolve(false);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}).catch(() => {
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
resolve(false);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function lanAddress() {
|
|
81
|
+
for (const addresses of Object.values(networkInterfaces())) {
|
|
82
|
+
for (const address of addresses ?? []) {
|
|
83
|
+
if (address.family === "IPv4" && !address.internal)
|
|
84
|
+
return address.address;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
function openBrowser(url) {
|
|
90
|
+
const browser = process.env.BROWSER;
|
|
91
|
+
if (browser === "none" || process.env.CI || false)
|
|
92
|
+
return;
|
|
93
|
+
const browserArgs = process.env.BROWSER_ARGS?.split(/\s+/).filter(Boolean) ?? [];
|
|
94
|
+
const command = browser ? process.platform === "darwin" ? ["open", "-a", browser, ...browserArgs, url] : [browser, ...browserArgs, url] : process.platform === "darwin" ? ["open", url] : process.platform === "win32" ? ["cmd", "/c", "start", "", url] : ["xdg-open", url];
|
|
95
|
+
try {
|
|
96
|
+
Bun.spawn(command, { stdout: "ignore", stderr: "ignore", stdin: "ignore" }).unref();
|
|
97
|
+
} catch {}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { browserHost, printServerReady, ensurePortFree, openBrowser };
|