@wular/pnext 0.0.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.
- package/README.md +153 -0
- package/bin/pnext +67 -0
- package/config/lint/base.js +48 -0
- package/config/ts/base.json +26 -0
- package/config/ts/react.json +13 -0
- package/package.json +70 -0
- package/reference/compat.md +63 -0
- package/reference/config.md +120 -0
- package/reference/css.md +58 -0
- package/reference/dev.md +69 -0
- package/reference/env.md +40 -0
- package/reference/metadata.md +86 -0
- package/reference/navigation.md +149 -0
- package/reference/overview.md +35 -0
- package/reference/performance.md +97 -0
- package/reference/rendering.md +127 -0
- package/reference/routing.md +167 -0
- package/reference/typegen.md +64 -0
- package/src/api/cache.ts +80 -0
- package/src/api/client-cache.ts +9 -0
- package/src/api/client-navigation.ts +279 -0
- package/src/api/dynamic.tsx +102 -0
- package/src/api/link.tsx +119 -0
- package/src/api/navigation.ts +198 -0
- package/src/api/router/events.ts +53 -0
- package/src/api/router/history.ts +70 -0
- package/src/api/router/hub.ts +194 -0
- package/src/api/router/policies.ts +107 -0
- package/src/api/router/runtime.ts +5238 -0
- package/src/api/router/types.ts +299 -0
- package/src/api/router.ts +167 -0
- package/src/api/server.ts +323 -0
- package/src/api/suspense.ts +16 -0
- package/src/cache/context.ts +61 -0
- package/src/cli/adapters/vercel-warm.ts +375 -0
- package/src/cli/adapters/vercel.ts +1310 -0
- package/src/cli/analyze-print.ts +181 -0
- package/src/cli/analyze.ts +328 -0
- package/src/cli/boot-trace.ts +29 -0
- package/src/cli/build.ts +3114 -0
- package/src/cli/dev.ts +276 -0
- package/src/cli/index.ts +196 -0
- package/src/cli/named-bin.ts +119 -0
- package/src/cli/serve-ui.ts +160 -0
- package/src/cli/start.ts +1425 -0
- package/src/client/build.ts +2136 -0
- package/src/client/chunk-fold.ts +526 -0
- package/src/client/entry.ts +1525 -0
- package/src/client/paths.ts +22 -0
- package/src/client/prebuilt.ts +621 -0
- package/src/client/profile.ts +75 -0
- package/src/client/react-compiler.ts +94 -0
- package/src/client/reference-stub.ts +145 -0
- package/src/client/reference.ts +47 -0
- package/src/compat/actions/action-client.ts +531 -0
- package/src/compat/actions/action-dispatch.ts +676 -0
- package/src/compat/actions/action-router.ts +40 -0
- package/src/compat/actions/action-shared.ts +95 -0
- package/src/compat/actions/client-plugin.ts +135 -0
- package/src/compat/actions/client-stub.ts +65 -0
- package/src/compat/actions/config.ts +164 -0
- package/src/compat/actions/detect.ts +208 -0
- package/src/compat/actions/discovery.ts +244 -0
- package/src/compat/actions/early-submit.ts +40 -0
- package/src/compat/actions/endpoint.ts +602 -0
- package/src/compat/actions/flight.ts +52 -0
- package/src/compat/actions/form-state.ts +73 -0
- package/src/compat/actions/hoist.ts +485 -0
- package/src/compat/actions/ids.ts +39 -0
- package/src/compat/actions/index.ts +41 -0
- package/src/compat/actions/instances.ts +144 -0
- package/src/compat/actions/origin.ts +109 -0
- package/src/compat/actions/protocol.ts +125 -0
- package/src/compat/actions/registry.ts +74 -0
- package/src/compat/actions/rewrite.ts +282 -0
- package/src/compat/actions/serve.ts +414 -0
- package/src/compat/actions/server-tag.ts +21 -0
- package/src/compat/actions/unrecognized-error.ts +30 -0
- package/src/compat/adapter/build-complete.ts +257 -0
- package/src/compat/bundler/bun-externals.ts +53 -0
- package/src/compat/bundler/cjs-exports.ts +542 -0
- package/src/compat/bundler/config.ts +363 -0
- package/src/compat/bundler/externals.ts +34 -0
- package/src/compat/bundler/import-meta-url.ts +60 -0
- package/src/compat/bundler/modularize-imports.ts +119 -0
- package/src/compat/bundler/new-url-asset.ts +87 -0
- package/src/compat/bundler/optimize-package-imports.ts +273 -0
- package/src/compat/bundler/polyfill.ts +88 -0
- package/src/compat/bundler/react-compiler.ts +61 -0
- package/src/compat/bundler/react-profiler.tsx +25 -0
- package/src/compat/bundler/relay-transform.ts +116 -0
- package/src/compat/bundler/require-context.ts +281 -0
- package/src/compat/bundler/resolve-extensions.ts +75 -0
- package/src/compat/bundler/source-cache.ts +61 -0
- package/src/compat/bundler/static-imports.ts +25 -0
- package/src/compat/bundler/symlink-imports.ts +119 -0
- package/src/compat/bundler/tsconfig-paths.ts +50 -0
- package/src/compat/bundler/wasm.ts +153 -0
- package/src/compat/bundler/webpack-loaders.ts +685 -0
- package/src/compat/bundler/worker.ts +278 -0
- package/src/compat/cache/build-flags.ts +81 -0
- package/src/compat/cache/build-prerender-errors.ts +163 -0
- package/src/compat/cache/custom-handler.ts +159 -0
- package/src/compat/cache/fetch-patch.ts +745 -0
- package/src/compat/cache/handler.ts +100 -0
- package/src/compat/cache/modern-handler.ts +275 -0
- package/src/compat/cache/resume-data-cache.ts +143 -0
- package/src/compat/cache/revalidate.ts +759 -0
- package/src/compat/cache/runtime-error.ts +124 -0
- package/src/compat/cache/use-cache-transform.ts +961 -0
- package/src/compat/cache/use-cache.ts +1695 -0
- package/src/compat/cache-control.ts +269 -0
- package/src/compat/client/base-path.ts +64 -0
- package/src/compat/client/css-order.ts +36 -0
- package/src/compat/client/errors/control-flow.ts +92 -0
- package/src/compat/client/errors/error-boundary.ts +222 -0
- package/src/compat/client/errors/global-error.ts +238 -0
- package/src/compat/client/errors/install.ts +217 -0
- package/src/compat/client/errors/lazy.ts +53 -0
- package/src/compat/client/errors/primitive-throw.ts +126 -0
- package/src/compat/client/errors/soft-refresh.ts +14 -0
- package/src/compat/client/link-status.ts +86 -0
- package/src/compat/client/nav-compat-runtime.ts +57 -0
- package/src/compat/client/nav-compat.ts +42 -0
- package/src/compat/client/navigation-scroll.ts +154 -0
- package/src/compat/client/optimistic-routing.ts +206 -0
- package/src/compat/client/prefetch-cache.ts +111 -0
- package/src/compat/client/route-announcer.ts +72 -0
- package/src/compat/client/segment-cache-policy.ts +159 -0
- package/src/compat/client/segment-cache.ts +1077 -0
- package/src/compat/client/segment-prefetch.ts +375 -0
- package/src/compat/client/trailing-slash.ts +24 -0
- package/src/compat/css/chunking.ts +254 -0
- package/src/compat/css/inline-css.ts +73 -0
- package/src/compat/css/lightningcss.ts +90 -0
- package/src/compat/css/modules.ts +373 -0
- package/src/compat/css/nonce.ts +30 -0
- package/src/compat/css/sass-plugin.ts +65 -0
- package/src/compat/css/sass.ts +392 -0
- package/src/compat/css/styled-jsx-runtime.ts +80 -0
- package/src/compat/css/styled-jsx.ts +49 -0
- package/src/compat/edge-runtime.ts +71 -0
- package/src/compat/export/client.ts +112 -0
- package/src/compat/export/index.ts +272 -0
- package/src/compat/export/standalone.ts +207 -0
- package/src/compat/image-optimizer/cache.ts +119 -0
- package/src/compat/image-optimizer/detect.ts +143 -0
- package/src/compat/image-optimizer/index.ts +601 -0
- package/src/compat/image-optimizer/source.ts +243 -0
- package/src/compat/index.ts +458 -0
- package/src/compat/lifecycle/after-scope.ts +86 -0
- package/src/compat/lifecycle/after.ts +173 -0
- package/src/compat/lifecycle/error-funnel.ts +306 -0
- package/src/compat/lifecycle/error-serialize.ts +87 -0
- package/src/compat/lifecycle/error-ui.ts +167 -0
- package/src/compat/lifecycle/instrumentation-client.ts +138 -0
- package/src/compat/lifecycle/instrumentation.ts +277 -0
- package/src/compat/lifecycle/node-console.ts +19 -0
- package/src/compat/lifecycle/testmode.ts +263 -0
- package/src/compat/mdx/compile.ts +219 -0
- package/src/compat/mdx/next-mdx-stub.ts +46 -0
- package/src/compat/mdx/plugin.ts +37 -0
- package/src/compat/metadata-route-artifacts.ts +458 -0
- package/src/compat/metadata.ts +295 -0
- package/src/compat/middleware/manifest.ts +210 -0
- package/src/compat/misc/action-return.ts +173 -0
- package/src/compat/next/cache.ts +211 -0
- package/src/compat/next/canonical-url.ts +35 -0
- package/src/compat/next/client-cache.ts +57 -0
- package/src/compat/next/client-navigation.ts +313 -0
- package/src/compat/next/client-only.ts +3 -0
- package/src/compat/next/client-script.tsx +215 -0
- package/src/compat/next/client-server.ts +39 -0
- package/src/compat/next/config-loader.ts +569 -0
- package/src/compat/next/config.ts +29 -0
- package/src/compat/next/constants.cjs +6 -0
- package/src/compat/next/constants.ts +6 -0
- package/src/compat/next/custom-server.ts +236 -0
- package/src/compat/next/dist/client/components/app-router-headers.ts +32 -0
- package/src/compat/next/dist/server/app-render/work-unit-async-storage.external.cjs +38 -0
- package/src/compat/next/dist/server/web/spec-extension/revalidate.ts +1 -0
- package/src/compat/next/dist/server/web/spec-extension/unstable-cache.ts +1 -0
- package/src/compat/next/dist/server/web/spec-extension/unstable-no-store.ts +1 -0
- package/src/compat/next/dynamic.tsx +46 -0
- package/src/compat/next/error.tsx +148 -0
- package/src/compat/next/font/cache.ts +171 -0
- package/src/compat/next/font/google.ts +2 -0
- package/src/compat/next/font/index.ts +8 -0
- package/src/compat/next/font/local.ts +5 -0
- package/src/compat/next/font/runtime-client.ts +71 -0
- package/src/compat/next/font/runtime.ts +974 -0
- package/src/compat/next/font/shared.ts +281 -0
- package/src/compat/next/form.tsx +156 -0
- package/src/compat/next/head.tsx +10 -0
- package/src/compat/next/headers.ts +247 -0
- package/src/compat/next/image/config.ts +196 -0
- package/src/compat/next/image/optimizer.ts +96 -0
- package/src/compat/next/image/patterns.ts +103 -0
- package/src/compat/next/image/shared.ts +141 -0
- package/src/compat/next/image/static-metadata.ts +283 -0
- package/src/compat/next/image/validate.ts +269 -0
- package/src/compat/next/image-client.tsx +215 -0
- package/src/compat/next/image-props.ts +575 -0
- package/src/compat/next/image-usage.ts +102 -0
- package/src/compat/next/image.tsx +56 -0
- package/src/compat/next/index.ts +1 -0
- package/src/compat/next/legacy-image.tsx +97 -0
- package/src/compat/next/link-usage.ts +29 -0
- package/src/compat/next/link-validation-transform.ts +200 -0
- package/src/compat/next/link.tsx +466 -0
- package/src/compat/next/navigation.cjs +21 -0
- package/src/compat/next/navigation.ts +188 -0
- package/src/compat/next/offline.ts +51 -0
- package/src/compat/next/og.ts +324 -0
- package/src/compat/next/optimistic-route-state.ts +188 -0
- package/src/compat/next/preferred-region.ts +39 -0
- package/src/compat/next/redirects.ts +131 -0
- package/src/compat/next/resource-hints.ts +136 -0
- package/src/compat/next/rewrites.ts +350 -0
- package/src/compat/next/root-params.ts +142 -0
- package/src/compat/next/router.cjs +49 -0
- package/src/compat/next/router.ts +143 -0
- package/src/compat/next/script.tsx +355 -0
- package/src/compat/next/server-only.ts +3 -0
- package/src/compat/next/server.ts +28 -0
- package/src/compat/next/svgr.ts +58 -0
- package/src/compat/next/telemetry.ts +77 -0
- package/src/compat/next/user-agent.ts +100 -0
- package/src/compat/next/web-vitals.ts +56 -0
- package/src/compat/otel/api.ts +95 -0
- package/src/compat/otel/client-trace-metadata.ts +71 -0
- package/src/compat/otel/fetch-span.ts +77 -0
- package/src/compat/otel/tracer.ts +944 -0
- package/src/compat/pages/client-plugin.ts +108 -0
- package/src/compat/pages/index.ts +527 -0
- package/src/compat/pages/router-state.ts +94 -0
- package/src/compat/ppr/io.ts +38 -0
- package/src/compat/ppr/missing-root-params.ts +105 -0
- package/src/compat/ppr/root-params-scan.ts +164 -0
- package/src/compat/ppr/root-params-transform.ts +75 -0
- package/src/compat/ppr/root-params.ts +129 -0
- package/src/compat/ppr/segment-config-incompat.ts +34 -0
- package/src/compat/protocol.ts +202 -0
- package/src/compat/react/client.ts +59 -0
- package/src/compat/react/compiler-runtime.ts +60 -0
- package/src/compat/react/dom-client.ts +115 -0
- package/src/compat/react/dom-react-server.ts +20 -0
- package/src/compat/react/dom-server.ts +40 -0
- package/src/compat/react/dom.ts +154 -0
- package/src/compat/react/preact.ts +522 -0
- package/src/compat/react/react-server.ts +84 -0
- package/src/compat/react/router-shim.ts +26 -0
- package/src/compat/react/server-component-use.ts +48 -0
- package/src/compat/react/server-inserted-html.ts +87 -0
- package/src/compat/react/server.ts +156 -0
- package/src/compat/react/view-transition.ts +60 -0
- package/src/compat/register/actions.ts +875 -0
- package/src/compat/register/boot.ts +141 -0
- package/src/compat/register/build-tier.ts +11 -0
- package/src/compat/register/build.ts +182 -0
- package/src/compat/register/bundler.ts +587 -0
- package/src/compat/register/cache.ts +85 -0
- package/src/compat/register/client-errors.ts +18 -0
- package/src/compat/register/config.ts +17 -0
- package/src/compat/register/css-extras.ts +120 -0
- package/src/compat/register/edge-runtime.ts +6 -0
- package/src/compat/register/errors.ts +46 -0
- package/src/compat/register/export.ts +23 -0
- package/src/compat/register/font.ts +36 -0
- package/src/compat/register/hooks.ts +34 -0
- package/src/compat/register/image.ts +133 -0
- package/src/compat/register/index.ts +111 -0
- package/src/compat/register/instrumentation-client.ts +35 -0
- package/src/compat/register/lifecycle.ts +86 -0
- package/src/compat/register/mdx.ts +48 -0
- package/src/compat/register/middleware.ts +36 -0
- package/src/compat/register/misc.ts +44 -0
- package/src/compat/register/otel.ts +288 -0
- package/src/compat/register/pages-api.ts +473 -0
- package/src/compat/register/ppr.ts +56 -0
- package/src/compat/register/protocol.ts +57 -0
- package/src/compat/register/proxy.ts +127 -0
- package/src/compat/register/render.ts +268 -0
- package/src/compat/register/routing.ts +410 -0
- package/src/compat/register/segment.ts +1903 -0
- package/src/compat/register/static-image.ts +21 -0
- package/src/compat/register/typed-routes.ts +35 -0
- package/src/compat/register/usecache.ts +131 -0
- package/src/compat/register/validation.ts +56 -0
- package/src/compat/segment/loading-boundary.ts +113 -0
- package/src/compat/segment/page-slot.ts +200 -0
- package/src/compat/segment/tree.ts +481 -0
- package/src/compat/segment/vary-key.ts +102 -0
- package/src/compat/segment/vary-params.ts +551 -0
- package/src/compat/static-params.ts +33 -0
- package/src/compat/tsconfig-defaults.ts +301 -0
- package/src/compat/typecheck/index.ts +1481 -0
- package/src/compat/typecheck/worker.ts +26 -0
- package/src/compat/typed-routes/index.ts +92 -0
- package/src/compat/typed-routes/manifest.ts +356 -0
- package/src/compat/typed-routes/typegen.ts +566 -0
- package/src/compat/validation/errors.ts +159 -0
- package/src/compat/validation/index.ts +1770 -0
- package/src/compat/validation/prerender-diagnostics.ts +1508 -0
- package/src/compat-bootstrap.ts +67 -0
- package/src/config.ts +218 -0
- package/src/css/build.ts +697 -0
- package/src/css/index.ts +2 -0
- package/src/css/postcss.ts +236 -0
- package/src/css/worker.ts +34 -0
- package/src/dev/client-actions.ts +35 -0
- package/src/dev/client-chunk-store.ts +92 -0
- package/src/dev/client-key-cache.ts +178 -0
- package/src/dev/global-css-cache.ts +212 -0
- package/src/dev/imports.ts +2430 -0
- package/src/dev/module-cache.ts +721 -0
- package/src/dev/module-generations.ts +38 -0
- package/src/dev/module-transform.ts +188 -0
- package/src/dev/node-module-bundle-cache.ts +63 -0
- package/src/dev/restart-cache.ts +10 -0
- package/src/dev/route-bundle-key-cache.ts +154 -0
- package/src/dev/route-facts-cache.ts +223 -0
- package/src/dev/server.ts +1710 -0
- package/src/dynamic/source.ts +307 -0
- package/src/dynamic/tree-shake.ts +262 -0
- package/src/env.ts +92 -0
- package/src/extensions.ts +1898 -0
- package/src/index.ts +34 -0
- package/src/internal.ts +43 -0
- package/src/islands/boundary-error.ts +8 -0
- package/src/islands/static-children.ts +37 -0
- package/src/islands/static-slots.ts +106 -0
- package/src/ppr-postpone.ts +24 -0
- package/src/ppr.ts +784 -0
- package/src/proxy.ts +752 -0
- package/src/render/hooks.ts +384 -0
- package/src/render/index.ts +1 -0
- package/src/render/island-context.ts +47 -0
- package/src/render/metadata.ts +857 -0
- package/src/render/renderer.ts +7391 -0
- package/src/render/resource-hints.ts +44 -0
- package/src/render/slots.tsx +679 -0
- package/src/request/context.ts +396 -0
- package/src/resolve/engine.ts +219 -0
- package/src/resolve/imports.ts +1104 -0
- package/src/resolve/scan-facts.ts +474 -0
- package/src/resolve/source-text.ts +86 -0
- package/src/routing/forwarded.ts +41 -0
- package/src/routing/handler.ts +271 -0
- package/src/routing/href.ts +203 -0
- package/src/routing/metadata.ts +1018 -0
- package/src/routing/request-runtime.ts +43 -0
- package/src/routing/routes.ts +2560 -0
- package/src/routing/slots.ts +432 -0
- package/src/runtime/server.ts +3453 -0
- package/src/runtime/vendor.ts +1160 -0
- package/src/style-modules.d.ts +9 -0
- package/src/typegen.ts +151 -0
- package/src/types.ts +725 -0
- package/src/utils/ansi.ts +9 -0
- package/src/utils/content-type.ts +31 -0
- package/src/utils/decode.ts +7 -0
- package/src/utils/dev-profile.ts +31 -0
- package/src/utils/error-log.ts +29 -0
- package/src/utils/fs-cache.ts +31 -0
- package/src/utils/fs.ts +119 -0
- package/src/utils/html.ts +46 -0
- package/src/utils/serialize.ts +378 -0
- package/src/utils/source.ts +35 -0
- package/src/utils/verbose.ts +39 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Client error runtime registration (COMPAT, client half).
|
|
2
|
+
//
|
|
3
|
+
// The client error runtime (src/compat/client/errors/*) is a BROWSER module bundled into each compat
|
|
4
|
+
// client entry - like nav-compat and action-router it is imported and installed by the generated entry,
|
|
5
|
+
// not wired into a server render registry. There is therefore no server-side extension to assign here:
|
|
6
|
+
// this registrar exists as the single server-bootstrap wiring point and documents the entry-append
|
|
7
|
+
// contract. The compat entry already imports the route's nearest error.js and installs the action-error
|
|
8
|
+
// overlay; to activate the general client error pipeline it additionally calls installClientErrors.
|
|
9
|
+
|
|
10
|
+
import type { ResolvedConfig } from '../../config';
|
|
11
|
+
import { nextCompatEnabled } from '../../compat';
|
|
12
|
+
|
|
13
|
+
export function registerClientErrorExtensions(config: ResolvedConfig): void {
|
|
14
|
+
if (!nextCompatEnabled(config)) return;
|
|
15
|
+
// No server-side render/routing extension: the client runtime installs in the
|
|
16
|
+
// browser from the generated entry (seam 5, clientEntryModules). Kept as the
|
|
17
|
+
// stable registration seam so the orchestrator can wire it uniformly.
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Config-source registration (COMPAT - may import core freely).
|
|
2
|
+
//
|
|
3
|
+
// registerConfigSource() wires the next.config.* loader into the core configSources seam. It runs earlier
|
|
4
|
+
// than the other compat sub-registrars: loadConfig invokes it lazily, before bootstrapCompat, so the
|
|
5
|
+
// next.config values feed pnext's resolved config for build AND start/dev. The orchestrator must call
|
|
6
|
+
// this from register.ts too, so a single registerCompatExtensions() pass leaves the source installed.
|
|
7
|
+
|
|
8
|
+
import { registerConfigSource as registerCoreConfigSource } from '../../config';
|
|
9
|
+
import type { ConfigSourceOverrides } from '../../config';
|
|
10
|
+
import { loadNextConfig } from '../next/config-loader';
|
|
11
|
+
|
|
12
|
+
export function registerConfigSource(): void {
|
|
13
|
+
registerCoreConfigSource(async (root, options): Promise<ConfigSourceOverrides> => {
|
|
14
|
+
const { overrides } = await loadNextConfig(root, options);
|
|
15
|
+
return overrides;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// CSS-extras registration (COMPAT).
|
|
2
|
+
//
|
|
3
|
+
// Wires the compat CSS features into core:
|
|
4
|
+
//
|
|
5
|
+
// 1. Sass/scss -> the CssExtensions registry. src/css.ts reads getCssExtensions() at its build sites:
|
|
6
|
+
// bundleCssChunk / buildGlobalCss add the sass chunk plugins and the `.scss`/`.sass` loader entries
|
|
7
|
+
// so the sass onLoad fires; registerCssRuntime and cssModuleClientPlugin consult resolveCssModule /
|
|
8
|
+
// loadCssModuleForClient for `*.module.{scss,sass}` before falling back to the empty-module default.
|
|
9
|
+
//
|
|
10
|
+
// 2. Sass loaders are also composed onto the JS bundle esbuild seams (client + server) as a safety net,
|
|
11
|
+
// so a `.scss` reachable through the JS graph resolves too. COMPOSED, not clobbered: the live plugin
|
|
12
|
+
// factories are read first and the sass module-loader appended. register-actions sets
|
|
13
|
+
// clientEsbuildPlugins wholesale, so this MUST run after it - and does, being later in register.ts.
|
|
14
|
+
//
|
|
15
|
+
// 3. useServerInsertedHTML, the CSP nonce and inline-CSS ship as standalone helpers consumed by the
|
|
16
|
+
// render layer / next-navigation re-export.
|
|
17
|
+
//
|
|
18
|
+
// Gated on next-compat: a pure-core or react-only app keeps every no-op default and never loads the sass
|
|
19
|
+
// module.
|
|
20
|
+
|
|
21
|
+
import type { Plugin } from 'esbuild';
|
|
22
|
+
import type { ResolvedConfig } from '../../config';
|
|
23
|
+
import {
|
|
24
|
+
getBundlerExtensions,
|
|
25
|
+
setBundlerExtensions,
|
|
26
|
+
setCssExtensions,
|
|
27
|
+
} from '../../extensions';
|
|
28
|
+
import { nextCompatEnabled } from '../../render/hooks';
|
|
29
|
+
import {
|
|
30
|
+
sassChunkPlugin,
|
|
31
|
+
sassLoadCssModuleForClient,
|
|
32
|
+
sassResolveCssModule,
|
|
33
|
+
} from '../css/sass-plugin';
|
|
34
|
+
import { isSassFile, isSassModuleFile, sassModuleMapping } from '../css/sass';
|
|
35
|
+
import {
|
|
36
|
+
nextCssLoadModuleForClient,
|
|
37
|
+
nextCssModuleChunkPlugin,
|
|
38
|
+
nextCssResolveModule,
|
|
39
|
+
} from '../css/modules';
|
|
40
|
+
import { nextPlanRouteCssChunks } from '../css/chunking';
|
|
41
|
+
import { inlineCssStylesheets } from '../css/inline-css';
|
|
42
|
+
|
|
43
|
+
export function registerCssExtrasExtensions(config: ResolvedConfig): void {
|
|
44
|
+
if (!nextCompatEnabled(config)) return;
|
|
45
|
+
|
|
46
|
+
// (1) CSS-chunk + module-map registry consumed by src/css.ts. The two entries
|
|
47
|
+
// the route scanner needs (extraCssExtensions, resolveCssDependency) plus the
|
|
48
|
+
// source materialization are boot facts — register-boot.ts owns them.
|
|
49
|
+
const resolveNextCssModule = nextCssResolveModule(config);
|
|
50
|
+
const loadNextCssModuleForClient = nextCssLoadModuleForClient(config);
|
|
51
|
+
const resolveSassCssModule = sassResolveCssModule(config);
|
|
52
|
+
const loadSassCssModuleForClient = sassLoadCssModuleForClient(config);
|
|
53
|
+
setCssExtensions({
|
|
54
|
+
deferRootNotFoundCss: () => true,
|
|
55
|
+
inlineStylesheets: inlineCssStylesheets,
|
|
56
|
+
cssChunkPlugins: () => [nextCssModuleChunkPlugin(config), sassChunkPlugin(config)],
|
|
57
|
+
resolveCssModule: file => resolveNextCssModule(file) ?? resolveSassCssModule(file),
|
|
58
|
+
loadCssModuleForClient: file =>
|
|
59
|
+
loadNextCssModuleForClient(file) ?? loadSassCssModuleForClient(file),
|
|
60
|
+
planRouteCssChunks: nextPlanRouteCssChunks,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// (2) Compose the sass module-loader onto the JS bundle esbuild seams.
|
|
64
|
+
const current = getBundlerExtensions();
|
|
65
|
+
const priorClient = current.clientEsbuildPlugins;
|
|
66
|
+
const priorServer = current.serverEsbuildPlugins;
|
|
67
|
+
setBundlerExtensions({
|
|
68
|
+
clientEsbuildPlugins: (cfg: ResolvedConfig): Plugin[] => [
|
|
69
|
+
...priorClient(cfg),
|
|
70
|
+
sassModuleLoaderPlugin(cfg),
|
|
71
|
+
],
|
|
72
|
+
serverEsbuildPlugins: (cfg: ResolvedConfig, opts?): Plugin[] => [
|
|
73
|
+
...priorServer(cfg, opts),
|
|
74
|
+
nextCssServerModuleLoaderPlugin(cfg),
|
|
75
|
+
sassModuleLoaderPlugin(cfg),
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function nextCssServerModuleLoaderPlugin(config: ResolvedConfig): Plugin {
|
|
81
|
+
const loadModule = nextCssLoadModuleForClient(config);
|
|
82
|
+
return {
|
|
83
|
+
name: 'pnext-compat-server-css-module',
|
|
84
|
+
setup(build) {
|
|
85
|
+
build.onLoad({ filter: /\.module\.css$/ }, ({ path: file }) => {
|
|
86
|
+
const contents = loadModule(file);
|
|
87
|
+
return contents ? { contents, loader: 'js' } : null;
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* esbuild onLoad for a `.scss`/`.sass` reached through a JS graph: a
|
|
95
|
+
* `*.module.*` import evaluates to its class map, a global import to an empty
|
|
96
|
+
* side-effect module (its bytes ship via the CSS chunk, not the JS bundle).
|
|
97
|
+
* Mirrors core's `cssModuleClientPlugin` for the sass extensions.
|
|
98
|
+
*/
|
|
99
|
+
function sassModuleLoaderPlugin(config: ResolvedConfig): Plugin {
|
|
100
|
+
return {
|
|
101
|
+
name: 'pnext-compat-sass-module',
|
|
102
|
+
setup(build) {
|
|
103
|
+
build.onLoad({ filter: /\.(?:scss|sass)$/ }, ({ path: file }) => {
|
|
104
|
+
if (!isSassFile(file)) return null;
|
|
105
|
+
const contents = isSassModuleFile(file)
|
|
106
|
+
? `export default ${JSON.stringify(sassModuleMapping(file, config.root, sassIncludePathsFor(config)))};`
|
|
107
|
+
: 'export default undefined;';
|
|
108
|
+
return { contents, loader: 'js' };
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Local include-paths read kept here to avoid importing sass-plugin internals;
|
|
115
|
+
// the JS-graph loader rarely needs includePaths (module maps resolve from the
|
|
116
|
+
// file itself), so an empty list is acceptable — the CSS-chunk plugin
|
|
117
|
+
// (sass-plugin.ts) threads the real sassOptions.includePaths.
|
|
118
|
+
function sassIncludePathsFor(_config: ResolvedConfig): string[] {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Error/404 pipeline registration (COMPAT).
|
|
2
|
+
//
|
|
3
|
+
// Wires the Next error-boundary behaviors into the core render/routing registries at the gated bootstrap
|
|
4
|
+
// seam: serializeError gets the digest protocol plus prod message redaction, and routeConventions gets
|
|
5
|
+
// global-error / global-not-found boundary discovery. A pure-core app registers none of these, keeping
|
|
6
|
+
// the compact core error UI and no digest/redaction.
|
|
7
|
+
|
|
8
|
+
import type { ResolvedConfig } from '../../config';
|
|
9
|
+
import { setRenderExtensions } from '../../extensions';
|
|
10
|
+
import { nextCompatEnabled } from '../../compat';
|
|
11
|
+
import {
|
|
12
|
+
serializeBoundaryError,
|
|
13
|
+
wrapThrownValue,
|
|
14
|
+
formatErrorLog,
|
|
15
|
+
} from '../lifecycle/error-serialize';
|
|
16
|
+
import {
|
|
17
|
+
httpAccessFallbackUi,
|
|
18
|
+
defaultGlobalErrorUi,
|
|
19
|
+
globalErrorReportScript,
|
|
20
|
+
} from '../lifecycle/error-ui';
|
|
21
|
+
import { getNextConfig } from '../next/config-loader';
|
|
22
|
+
|
|
23
|
+
// global-error / global-not-found are CORE document conventions (discovered by
|
|
24
|
+
// src/routing/routes.ts findGlobalError + src/render renderGlobalNotFoundResponse);
|
|
25
|
+
// compat only skins the Next-pixel-exact default UI strings/markup and the
|
|
26
|
+
// digest protocol here. forbidden/unauthorized stay compat conventions
|
|
27
|
+
// (registered in register-routing.ts).
|
|
28
|
+
export function registerErrorExtensions(config: ResolvedConfig): void {
|
|
29
|
+
if (!nextCompatEnabled(config)) return;
|
|
30
|
+
|
|
31
|
+
setRenderExtensions({
|
|
32
|
+
serializeError: serializeBoundaryError,
|
|
33
|
+
httpAccessFallbackUi,
|
|
34
|
+
defaultGlobalErrorUi,
|
|
35
|
+
globalErrorReportScript,
|
|
36
|
+
wrapThrownValue,
|
|
37
|
+
formatErrorLog,
|
|
38
|
+
// Read lazily per call: next.config loads after registration.
|
|
39
|
+
globalNotFoundEnabled: () => {
|
|
40
|
+
const experimental = getNextConfig().experimental as
|
|
41
|
+
| { globalNotFound?: boolean }
|
|
42
|
+
| undefined;
|
|
43
|
+
return experimental?.globalNotFound === true;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { nextCompatEnabled } from '../../compat';
|
|
2
|
+
import { onExtensionHostReset, registerBuildCompleteHooks } from '../../extensions';
|
|
3
|
+
import type { ResolvedConfig } from '../../config';
|
|
4
|
+
import { emitMetadataRouteArtifacts } from '../metadata-route-artifacts';
|
|
5
|
+
import { emitStaticExport } from '../export';
|
|
6
|
+
import { emitCustomServerShim } from '../next/custom-server';
|
|
7
|
+
|
|
8
|
+
let registered = false;
|
|
9
|
+
// Host-scoped guard: a fresh host must be registered into again.
|
|
10
|
+
onExtensionHostReset(() => (registered = false));
|
|
11
|
+
|
|
12
|
+
export function registerExportExtensions(config: ResolvedConfig): void {
|
|
13
|
+
if (registered) return;
|
|
14
|
+
if (!nextCompatEnabled(config)) return;
|
|
15
|
+
registered = true;
|
|
16
|
+
|
|
17
|
+
registerBuildCompleteHooks(async ctx => {
|
|
18
|
+
if (!nextCompatEnabled(ctx.config)) return;
|
|
19
|
+
await emitStaticExport(ctx);
|
|
20
|
+
await emitMetadataRouteArtifacts(ctx);
|
|
21
|
+
await emitCustomServerShim(ctx.config);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// next/font extension registration (COMPAT - may import core freely).
|
|
2
|
+
//
|
|
3
|
+
// Wires next/font preload delivery into core: requestExtensions.responseFinalizers gets the `Link`
|
|
4
|
+
// response header carrying the font preloads collected during the render.
|
|
5
|
+
//
|
|
6
|
+
// The font runtime stashes the render's preloadable font links on the request work unit. The registered
|
|
7
|
+
// finalizer, which runs before the first flush inside the same work unit, reads them back and emits a
|
|
8
|
+
// single `Link` header - matching Next, which delivers font preloads via a response header rather than
|
|
9
|
+
// HTML link tags.
|
|
10
|
+
//
|
|
11
|
+
// Registration is idempotent and also happens lazily on the first font-collection scope, so it is safe
|
|
12
|
+
// to call in a pure-core app and works before the orchestrator wires it in.
|
|
13
|
+
|
|
14
|
+
import type { ResolvedConfig } from '../../config';
|
|
15
|
+
import {
|
|
16
|
+
registerClientSourceTransforms,
|
|
17
|
+
registerServerSourceTransforms,
|
|
18
|
+
withSniff,
|
|
19
|
+
} from '../../extensions';
|
|
20
|
+
import { rewriteNextFontSource } from '../index';
|
|
21
|
+
import { registerFontFinalizerOnce } from '../next/font/runtime';
|
|
22
|
+
|
|
23
|
+
const fontSourceTransformRoots = new Set<string>();
|
|
24
|
+
|
|
25
|
+
export function registerFontExtensions(config: ResolvedConfig): void {
|
|
26
|
+
registerFontFinalizerOnce();
|
|
27
|
+
if (!config.compat?.next || fontSourceTransformRoots.has(config.root)) return;
|
|
28
|
+
fontSourceTransformRoots.add(config.root);
|
|
29
|
+
const sniff = ['next/font', 'next/root-params'];
|
|
30
|
+
registerServerSourceTransforms(
|
|
31
|
+
withSniff(sniff, (source, file) => rewriteNextFontSource(source, file, 'server', config.root)),
|
|
32
|
+
);
|
|
33
|
+
registerClientSourceTransforms(
|
|
34
|
+
withSniff(sniff, (source, file) => rewriteNextFontSource(source, file, 'client', config.root)),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Registration seam for the next/navigation router hooks (COMPAT).
|
|
3
|
+
//
|
|
4
|
+
// The hooks themselves (useSelectedLayoutSegment(s), usePathname,
|
|
5
|
+
// useSearchParams, useParams) need no runtime registration: compat/index.ts maps
|
|
6
|
+
// `next/navigation` to compat/next/{navigation,client-navigation}.ts, and the
|
|
7
|
+
// per-layout segment scope is installed by the core renderer (render/slots.ts +
|
|
8
|
+
// render/renderer.ts applyLayouts), gated on next-compat.
|
|
9
|
+
//
|
|
10
|
+
// The ONE thing that must be wired centrally is canonical-URL tracking for
|
|
11
|
+
// usePathname()/useSearchParams() on rewrites. After a same-origin rewrite the
|
|
12
|
+
// downstream render sees the DESTINATION URL, so the hooks need the original
|
|
13
|
+
// (as-requested) URL recorded on the work unit. The rewrite feeder already calls
|
|
14
|
+
// recordRewrite(from, to) (src/proxy.ts proxyRewriteObserver + register-proxy.ts;
|
|
15
|
+
// config rewrites via register-proxy). The orchestrator should also call
|
|
16
|
+
// recordCanonicalUrl(from) at the SAME site(s) so the canonical URL is stashed
|
|
17
|
+
// before the request URL is replaced with the destination.
|
|
18
|
+
//
|
|
19
|
+
// Reason it is not wired here: the rewrite observer slot
|
|
20
|
+
// (setProxyRewriteObserver) is single-valued and owned by register-proxy.ts.
|
|
21
|
+
// registerNavigationHooks() is provided so register.ts can call it in one place;
|
|
22
|
+
// today it only re-exports the canonical setter for the proxy wiring.
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
export { recordCanonicalUrl, canonicalUrlHref } from '../next/canonical-url';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Placeholder registration entry point kept for symmetry with the other register-<x> modules. The router
|
|
29
|
+
* hooks are wired declaratively (module map + renderer seam); the only imperative wiring
|
|
30
|
+
* (recordCanonicalUrl on rewrites) belongs in the proxy-rewrite observer.
|
|
31
|
+
*/
|
|
32
|
+
export function registerNavigationHooks(): void {
|
|
33
|
+
// No-op: nothing to install at runtime beyond the declarative wiring above.
|
|
34
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// next/image extension registration (COMPAT - may import core freely).
|
|
2
|
+
//
|
|
3
|
+
// Wires the next/image pipeline into core: requestExtensions.interceptors gets the /_next/image optimizer
|
|
4
|
+
// endpoint, and buildExtensions.steps gets images-manifest.json emission. Safe to call in a pure-core
|
|
5
|
+
// app: the interceptor and build step no-op unless compat.next is enabled.
|
|
6
|
+
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
9
|
+
import type { ResolvedConfig } from '../../config';
|
|
10
|
+
import { nextCompatEnabled } from '../../compat';
|
|
11
|
+
import {
|
|
12
|
+
registerBuildCompleteHooks,
|
|
13
|
+
registerBuildSteps,
|
|
14
|
+
registerRequestInterceptors,
|
|
15
|
+
type BuildStepContext,
|
|
16
|
+
type RequestInterceptor,
|
|
17
|
+
} from '../../extensions';
|
|
18
|
+
import { getImagesConfig, type ResolvedImagesConfig } from '../next/image/config';
|
|
19
|
+
import { isImageOptimizerRequest, serveImageOptimizer } from '../next/image/optimizer';
|
|
20
|
+
import { manifestLocalPatterns } from '../next/image/patterns';
|
|
21
|
+
import { getDocumentScriptExtensions, setDocumentScriptExtensions } from '../../render/hooks';
|
|
22
|
+
import { setWorkUnitRoute } from '../../request/context';
|
|
23
|
+
|
|
24
|
+
export function registerImageExtensions(config: ResolvedConfig): void {
|
|
25
|
+
globalThis.__PNEXT_IMAGE_CONFIG__ = getImagesConfig();
|
|
26
|
+
registerRequestInterceptors(imageOptimizerInterceptor);
|
|
27
|
+
registerBuildSteps(writeImagesManifestStep);
|
|
28
|
+
registerBuildCompleteHooks(async ctx => {
|
|
29
|
+
if (nextCompatEnabled(ctx.config)) await mirrorStaticMedia(ctx.config);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (nextCompatEnabled(config)) {
|
|
33
|
+
const previousHeadTags = getDocumentScriptExtensions().documentHeadTags;
|
|
34
|
+
setDocumentScriptExtensions({
|
|
35
|
+
documentHeadTags: (cfg, ctx) =>
|
|
36
|
+
`${previousHeadTags?.(cfg, ctx) ?? ''}${PLACEHOLDER_SCRIPT_TAG}`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Placeholder removal for images that never hydrate (a next/image rendered by a server component has no
|
|
42
|
+
// island, so no ClientImage effect runs). The server img carries `data-nimg-ph` = the loaded,
|
|
43
|
+
// placeholder-free style; once it settles we decode() then restore it, matching ClientImage's
|
|
44
|
+
// handleLoading. Images inside hydrating islands are skipped - their ClientImage owns the lifecycle.
|
|
45
|
+
//
|
|
46
|
+
// Fully self-contained and defensive: a single try/catch so it can never throw into the document, and
|
|
47
|
+
// per-element load/error handlers only (no global capture listener) so it cannot interfere with
|
|
48
|
+
// hydration. Binds on DOMContentLoaded - placeholder imgs live in the body, below this head script - and
|
|
49
|
+
// also settles images already complete by then.
|
|
50
|
+
//
|
|
51
|
+
// Conflict-free with ClientImage: the loaded style is re-read from the live `data-nimg-ph` attribute
|
|
52
|
+
// INSIDE the post-decode callback, not at bind time. A hydrating route's ClientImage vdom carries no
|
|
53
|
+
// `data-nimg-ph`, so preact's hydration strips the SSR attribute; by the time this callback fires the
|
|
54
|
+
// attribute is gone on any hydrated image, the check bails, and ClientImage stays the sole owner.
|
|
55
|
+
const PLACEHOLDER_SCRIPT_TAG = `<script>(function(){try{function b(){var l=document.querySelectorAll("img[data-nimg-ph]");for(var i=0;i<l.length;i++){(function(img){if(img.closest("[data-pnext-client]"))return;var done=false;function r(){if(done)return;done=true;("decode"in img?img.decode():Promise.resolve()).catch(function(){}).then(function(){var t=img.getAttribute("data-nimg-ph");if(t==null||!img.isConnected)return;img.style.cssText=t;img.removeAttribute("data-nimg-ph")})}if(img.complete&&img.naturalWidth>0)r();else{img.addEventListener("load",r);img.addEventListener("error",r)}})(l[i])}}if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",b);else b()}catch(e){}})();</script>`;
|
|
56
|
+
|
|
57
|
+
declare global {
|
|
58
|
+
var __PNEXT_IMAGE_CONFIG__: ResolvedImagesConfig | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const imageOptimizerInterceptor: RequestInterceptor = async (request, ctx) => {
|
|
62
|
+
const config = ctx.config;
|
|
63
|
+
if (!nextCompatEnabled(config)) return undefined;
|
|
64
|
+
const url = new URL(request.url);
|
|
65
|
+
const images = getImagesConfig();
|
|
66
|
+
if (!isImageOptimizerRequest(url, images)) return undefined;
|
|
67
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') return undefined;
|
|
68
|
+
// Optimizer responses own their headers outright — classify as a static
|
|
69
|
+
// asset so the app-router finalizers (Vary token merge, x-nextjs-* stamps)
|
|
70
|
+
// leave them untouched. Next serves /_next/image outside the router too.
|
|
71
|
+
setWorkUnitRoute('static-asset');
|
|
72
|
+
return serveImageOptimizer(request, config);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Next-compatible images-manifest.json (.next/): the qualities/localpatterns
|
|
76
|
+
// e2e suites read it in production to assert the resolved images config.
|
|
77
|
+
async function writeImagesManifestStep(ctx: BuildStepContext): Promise<void> {
|
|
78
|
+
const config = ctx.config;
|
|
79
|
+
if (!nextCompatEnabled(config)) return;
|
|
80
|
+
const images = getImagesConfig();
|
|
81
|
+
|
|
82
|
+
// normalizeLocalPatterns already appends the internal media patterns when
|
|
83
|
+
// localPatterns is configured, so manifest and runtime share one source.
|
|
84
|
+
const localPatterns = manifestLocalPatterns(images.localPatterns);
|
|
85
|
+
|
|
86
|
+
const manifest = {
|
|
87
|
+
version: 1,
|
|
88
|
+
images: {
|
|
89
|
+
contentDispositionType: images.contentDispositionType,
|
|
90
|
+
contentSecurityPolicy: images.contentSecurityPolicy,
|
|
91
|
+
dangerouslyAllowLocalIP: images.dangerouslyAllowLocalIP,
|
|
92
|
+
dangerouslyAllowSVG: images.dangerouslyAllowSVG,
|
|
93
|
+
deviceSizes: images.deviceSizes,
|
|
94
|
+
disableStaticImages: images.disableStaticImages,
|
|
95
|
+
domains: images.domains,
|
|
96
|
+
formats: images.formats,
|
|
97
|
+
imageSizes: images.imageSizes,
|
|
98
|
+
loader: images.loader,
|
|
99
|
+
loaderFile: images.loaderFile,
|
|
100
|
+
remotePatterns: images.remotePatterns,
|
|
101
|
+
localPatterns,
|
|
102
|
+
maximumRedirects: images.maximumRedirects,
|
|
103
|
+
maximumResponseBody: images.maximumResponseBody,
|
|
104
|
+
minimumCacheTTL: images.minimumCacheTTL,
|
|
105
|
+
path: images.path,
|
|
106
|
+
qualities: images.qualities,
|
|
107
|
+
sizes: [...images.deviceSizes, ...images.imageSizes],
|
|
108
|
+
unoptimized: images.unoptimized,
|
|
109
|
+
customCacheHandler: images.customCacheHandler,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const outDir = path.join(config.root, '.next');
|
|
114
|
+
await mkdir(outDir, { recursive: true });
|
|
115
|
+
await writeFile(path.join(outDir, 'images-manifest.json'), JSON.stringify(manifest, null, 2));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Tooling (and Next's e2e suites) discover fingerprinted static-import images
|
|
119
|
+
// by scanning <distDir>/static/media; pnext emits them under
|
|
120
|
+
// outPath/public/_next/static/media. Mirror them into .next so both layouts
|
|
121
|
+
// hold the same files.
|
|
122
|
+
async function mirrorStaticMedia(config: ResolvedConfig): Promise<void> {
|
|
123
|
+
const { cp } = await import('node:fs/promises');
|
|
124
|
+
for (const dir of ['media', 'immutable/media']) {
|
|
125
|
+
const source = path.join(config.outPath, 'public', '_next', 'static', dir);
|
|
126
|
+
const target = path.join(config.root, '.next', 'static', dir);
|
|
127
|
+
try {
|
|
128
|
+
await cp(source, target, { recursive: true, force: true });
|
|
129
|
+
} catch {
|
|
130
|
+
// no static media emitted for this build
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Compat registration entry point (COMPAT - may import core freely).
|
|
2
|
+
//
|
|
3
|
+
// registerCompatExtensions(config) is invoked exactly once, from the single core seam
|
|
4
|
+
// (src/compat-bootstrap.ts), when compat is enabled. It fans out to the per-domain sub-registrars, each
|
|
5
|
+
// in its OWN file. Each imports the real compat implementations and assigns them into the core
|
|
6
|
+
// registries in src/extensions.ts.
|
|
7
|
+
//
|
|
8
|
+
// Importing this module IS the expensive part of compat (the whole implementation graph), so the handful
|
|
9
|
+
// of facts core needs before its first compile live in ./register-boot, which the boot tier loads on its
|
|
10
|
+
// own. This file re-runs that registrar (idempotent) so calling it alone still yields a fully wired
|
|
11
|
+
// compat layer.
|
|
12
|
+
|
|
13
|
+
import type { ResolvedConfig } from '../../config';
|
|
14
|
+
import { registerCompatBootExtensions } from './boot';
|
|
15
|
+
import type * as BuildTier from './build-tier';
|
|
16
|
+
import { registerCacheExtensions } from './cache';
|
|
17
|
+
import { registerActionExtensions } from './actions';
|
|
18
|
+
import { registerRenderExtensions } from './render';
|
|
19
|
+
import { registerProxyExtensions } from './proxy';
|
|
20
|
+
import { registerConfigSource } from './config';
|
|
21
|
+
import {
|
|
22
|
+
registerProtocolExtensions,
|
|
23
|
+
registerProtocolRequestValidation,
|
|
24
|
+
} from './protocol';
|
|
25
|
+
import { registerLifecycleExtensions } from './lifecycle';
|
|
26
|
+
import { registerImageExtensions } from './image';
|
|
27
|
+
import { registerErrorExtensions } from './errors';
|
|
28
|
+
import { registerFontExtensions } from './font';
|
|
29
|
+
import { registerStaticImageExtensions } from './static-image';
|
|
30
|
+
import { registerUseCacheExtensions } from './usecache';
|
|
31
|
+
import { registerClientErrorExtensions } from './client-errors';
|
|
32
|
+
import { registerPprExtensions } from './ppr';
|
|
33
|
+
import { registerMdxExtensions } from './mdx';
|
|
34
|
+
import { registerOtelExtensions, registerOtelRootInterceptor } from './otel';
|
|
35
|
+
import { registerInstrumentationClientExtensions } from './instrumentation-client';
|
|
36
|
+
import { registerMiscExtensions } from './misc';
|
|
37
|
+
import { registerCssExtrasExtensions } from './css-extras';
|
|
38
|
+
import { registerSegmentExtensions } from './segment';
|
|
39
|
+
import { registerBundlerExtensions } from './bundler';
|
|
40
|
+
import { registerPagesApiExtensions } from './pages-api';
|
|
41
|
+
import { registerEdgeRuntimeExtensions } from './edge-runtime';
|
|
42
|
+
|
|
43
|
+
export interface RegisterCompatOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Serving only (the dev server). Skips the build-only domains — nothing on a
|
|
46
|
+
* request path reads what they register — so their module graphs never load.
|
|
47
|
+
*/
|
|
48
|
+
serve?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function registerCompatExtensions(
|
|
52
|
+
config: ResolvedConfig,
|
|
53
|
+
options: RegisterCompatOptions = {},
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
// Loaded up front so the calls below stay in their original order; skipped
|
|
56
|
+
// outright when only serving (see RegisterCompatOptions.serve).
|
|
57
|
+
const build: typeof BuildTier | undefined = options.serve
|
|
58
|
+
? undefined
|
|
59
|
+
: await import('./build-tier');
|
|
60
|
+
// Route conventions, page/CSS extensions, module aliases, proxy names and the
|
|
61
|
+
// lifecycle init hooks — already done when the boot tier ran first.
|
|
62
|
+
registerCompatBootExtensions(config);
|
|
63
|
+
build?.registerBuildCompatExtensions();
|
|
64
|
+
registerConfigSource();
|
|
65
|
+
// The otel ROOT-span interceptor must run before every short-circuiting
|
|
66
|
+
// interceptor (segment prefetch, RSC protocol, action dispatch) so those
|
|
67
|
+
// responses are traced too; the rest of otel registers last (below).
|
|
68
|
+
registerOtelRootInterceptor(config);
|
|
69
|
+
// Protocol validation next: an invalid next-router-state-tree must 500 before
|
|
70
|
+
// the segment/action interceptors answer the request.
|
|
71
|
+
registerProtocolRequestValidation(config);
|
|
72
|
+
// Typed-routes typegen and typecheck run before structural validation so a type error surfaces ahead of
|
|
73
|
+
// runtime checks, matching `next build`, which runs tsc before its own validations. The typecheck only
|
|
74
|
+
// covers .ts/.tsx pages/layouts/handlers via the generated validator, so JS-only fixtures still fall
|
|
75
|
+
// through to the structural validation below with their runtime error message.
|
|
76
|
+
build?.registerTypedRoutesExtensions(config);
|
|
77
|
+
// Build validation fails fast before the remaining build steps run.
|
|
78
|
+
build?.registerValidationExtensions(config);
|
|
79
|
+
registerCacheExtensions(config);
|
|
80
|
+
// Before actions: the /_tree prefetch responder must intercept ahead of the
|
|
81
|
+
// action dispatch interceptor.
|
|
82
|
+
registerSegmentExtensions(config);
|
|
83
|
+
registerActionExtensions(config);
|
|
84
|
+
registerPagesApiExtensions(config);
|
|
85
|
+
registerEdgeRuntimeExtensions();
|
|
86
|
+
registerRenderExtensions(config);
|
|
87
|
+
registerProxyExtensions(config);
|
|
88
|
+
registerProtocolExtensions(config);
|
|
89
|
+
registerLifecycleExtensions(config);
|
|
90
|
+
registerImageExtensions(config);
|
|
91
|
+
registerErrorExtensions(config);
|
|
92
|
+
registerFontExtensions(config);
|
|
93
|
+
build?.registerMiddlewareExtensions();
|
|
94
|
+
build?.registerExportExtensions(config);
|
|
95
|
+
registerStaticImageExtensions();
|
|
96
|
+
registerUseCacheExtensions(config);
|
|
97
|
+
registerClientErrorExtensions(config);
|
|
98
|
+
registerPprExtensions(config);
|
|
99
|
+
registerMiscExtensions(config);
|
|
100
|
+
registerBundlerExtensions(config);
|
|
101
|
+
// After registerActionExtensions: composes (not clobbers) clientEsbuildPlugins.
|
|
102
|
+
registerCssExtrasExtensions(config);
|
|
103
|
+
// MDX last: it composes (not clobbers) clientEsbuildPlugins, so it must
|
|
104
|
+
// capture every previously-registered plugin factory.
|
|
105
|
+
registerMdxExtensions(config);
|
|
106
|
+
// Otel after everything: its route re-stamp interceptor must observe the
|
|
107
|
+
// post-rewrite request (the root span opens in the EARLY interceptor above).
|
|
108
|
+
registerOtelExtensions(config);
|
|
109
|
+
// After otel: composes (not clobbers) the documentHeadTags extension.
|
|
110
|
+
registerInstrumentationClientExtensions(config);
|
|
111
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// instrumentation-client registration (COMPAT).
|
|
2
|
+
//
|
|
3
|
+
// Wires the client instrumentation emulation onto the core seams:
|
|
4
|
+
// - a BUILD STEP bundles the app's instrumentation-client.(ts|js), plus next.config
|
|
5
|
+
// `instrumentationClientInject` entries in order, into `<out>/public/assets/instrumentation-client.js`.
|
|
6
|
+
// Steps run before prerendering, so statically generated documents carry the tag too.
|
|
7
|
+
// - documentHeadTags injects the `<script type="module">` loader tag - COMPOSED with whatever a previous
|
|
8
|
+
// registrar installed, since setDocumentScriptExtensions overwrites per key. The orchestrator calls
|
|
9
|
+
// this AFTER registerOtelExtensions.
|
|
10
|
+
//
|
|
11
|
+
// The router-side hook is surfaced through the `window.__PNEXT_ON_ROUTER_TRANSITION_START__` global the
|
|
12
|
+
// bundle registers; the client router calls it at the start of push/replace/traverse navigations.
|
|
13
|
+
|
|
14
|
+
import type { ResolvedConfig } from '../../config';
|
|
15
|
+
import { registerBuildSteps } from '../../extensions';
|
|
16
|
+
import { getDocumentScriptExtensions, setDocumentScriptExtensions } from '../../render/hooks';
|
|
17
|
+
import { nextCompatEnabled } from '../index';
|
|
18
|
+
import {
|
|
19
|
+
buildInstrumentationClient,
|
|
20
|
+
instrumentationClientHeadTag,
|
|
21
|
+
} from '../lifecycle/instrumentation-client';
|
|
22
|
+
|
|
23
|
+
export function registerInstrumentationClientExtensions(config: ResolvedConfig): void {
|
|
24
|
+
if (!nextCompatEnabled(config)) return;
|
|
25
|
+
|
|
26
|
+
registerBuildSteps(async ctx => {
|
|
27
|
+
await buildInstrumentationClient(ctx.config);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const previousHeadTags = getDocumentScriptExtensions().documentHeadTags;
|
|
31
|
+
setDocumentScriptExtensions({
|
|
32
|
+
documentHeadTags: (cfg, ctx) =>
|
|
33
|
+
`${previousHeadTags?.(cfg, ctx) ?? ''}${instrumentationClientHeadTag(cfg)}`,
|
|
34
|
+
});
|
|
35
|
+
}
|