vinext 1.0.0-beta.0 → 1.0.0-beta.2
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 +21 -2
- package/dist/build/assets-ignore.js +1 -1
- package/dist/build/clean-output.js +1 -1
- package/dist/build/client-build-config.js +7 -4
- package/dist/build/css-url-assets.js +3 -3
- package/dist/build/google-fonts/fallback-metrics.js +1 -1
- package/dist/build/google-fonts/font-metadata.js +1 -1
- package/dist/build/inject-pregenerated-paths.js +1 -1
- package/dist/build/inline-css.js +2 -5
- package/dist/build/module-dependency-cache.d.ts +4 -0
- package/dist/build/module-dependency-cache.js +13 -0
- package/dist/build/next-client-runtime-manifests.js +1 -1
- package/dist/build/pages-client-assets-module.js +1 -1
- package/dist/build/precompress.js +7 -7
- package/dist/build/prerender-paths.d.ts +2 -2
- package/dist/build/prerender-paths.js +10 -15
- package/dist/build/prerender-server-pool.js +2 -2
- package/dist/build/prerender.js +1 -1
- package/dist/build/preview-credentials.d.ts +11 -0
- package/dist/build/preview-credentials.js +19 -0
- package/dist/build/report.d.ts +8 -4
- package/dist/build/report.js +14 -6
- package/dist/build/run-prerender.d.ts +2 -11
- package/dist/build/run-prerender.js +2 -10
- package/dist/build/server-manifest.js +1 -1
- package/dist/build/ssr-manifest.d.ts +4 -0
- package/dist/build/ssr-manifest.js +10 -6
- package/dist/build/standalone.js +37 -37
- package/dist/cache/cache-adapters-virtual.d.ts +1 -17
- package/dist/cache/cache-adapters-virtual.js +20 -11
- package/dist/check.d.ts +0 -16
- package/dist/check.js +27 -36
- package/dist/cli.js +61 -55
- package/dist/client/instrumentation-client-inject.js +1 -1
- package/dist/client/pages-router-link-navigation.js +1 -1
- package/dist/config/config-matchers.d.ts +13 -37
- package/dist/config/config-matchers.js +33 -123
- package/dist/config/dotenv.js +1 -1
- package/dist/config/next-config.d.ts +7 -3
- package/dist/config/next-config.js +84 -15
- package/dist/config/prerender.d.ts +2 -2
- package/dist/config/prerender.js +7 -15
- package/dist/config/request-context.d.ts +14 -0
- package/dist/config/request-context.js +26 -0
- package/dist/config/server-external-packages.js +1 -1
- package/dist/config/tsconfig-paths.js +2 -2
- package/dist/{node_modules/.pnpm/am-i-vibing@0.5.0/node_modules → deps/.pnpm/am-i-vibing@0.5.0/deps}/am-i-vibing/dist/detector-1yx2Hoe0.js +2 -2
- package/dist/deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js +50 -0
- package/dist/entries/app-rsc-entry.js +39 -14
- package/dist/entries/app-rsc-manifest.js +21 -4
- package/dist/entries/pages-client-entry.js +6 -5
- package/dist/entries/pages-server-entry.js +18 -28
- package/dist/entries/runtime-entry-module.js +2 -2
- package/dist/index.js +314 -230
- package/dist/init-cloudflare.js +1 -1
- package/dist/init-platform.js +1 -1
- package/dist/init.d.ts +6 -4
- package/dist/init.js +25 -27
- package/dist/plugins/ast-utils.js +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +7 -7
- package/dist/plugins/extensionless-dynamic-import.js +1 -1
- package/dist/plugins/fonts.js +3 -3
- package/dist/plugins/ignore-dynamic-requests.js +13 -8
- package/dist/plugins/import-meta-url.js +16 -17
- package/dist/plugins/middleware-export-validation.js +1 -1
- package/dist/plugins/middleware-server-only.js +2 -2
- package/dist/plugins/og-asset-ownership.js +7 -6
- package/dist/plugins/og-assets.js +5 -6
- package/dist/plugins/optimize-imports.js +12 -13
- package/dist/plugins/postcss.js +1 -1
- package/dist/plugins/remove-console.js +1 -1
- package/dist/plugins/require-context.js +1 -1
- package/dist/plugins/sass.js +2 -2
- package/dist/plugins/server-externals-manifest.js +1 -1
- package/dist/plugins/strip-server-exports.js +1 -1
- package/dist/plugins/styled-jsx.js +3 -2
- package/dist/plugins/typeof-window.js +1 -1
- package/dist/routing/app-route-graph.d.ts +16 -15
- package/dist/routing/app-route-graph.js +86 -88
- package/dist/routing/app-router.d.ts +0 -5
- package/dist/routing/app-router.js +12 -11
- package/dist/routing/file-matcher.d.ts +13 -28
- package/dist/routing/file-matcher.js +31 -44
- package/dist/routing/pages-router.js +26 -32
- package/dist/routing/route-matching.d.ts +14 -1
- package/dist/routing/route-matching.js +13 -1
- package/dist/routing/route-pattern.d.ts +2 -1
- package/dist/routing/route-pattern.js +7 -4
- package/dist/routing/route-trie.d.ts +5 -1
- package/dist/routing/route-trie.js +5 -2
- package/dist/server/api-handler.js +41 -33
- package/dist/server/app-browser-entry.js +18 -11
- package/dist/server/app-browser-history-controller.d.ts +1 -1
- package/dist/server/app-browser-history-controller.js +3 -3
- package/dist/server/app-browser-navigation-controller.js +4 -2
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-elements-wire.d.ts +2 -1
- package/dist/server/app-fallback-renderer.d.ts +11 -0
- package/dist/server/app-fallback-renderer.js +16 -2
- package/dist/server/app-middleware.js +2 -1
- package/dist/server/app-page-boundary-render.d.ts +26 -2
- package/dist/server/app-page-boundary-render.js +190 -55
- package/dist/server/app-page-cache-finalizer.d.ts +1 -1
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-dispatch.d.ts +12 -2
- package/dist/server/app-page-dispatch.js +37 -51
- package/dist/server/app-page-element-builder.d.ts +8 -2
- package/dist/server/app-page-element-builder.js +112 -27
- package/dist/server/app-page-execution.d.ts +3 -1
- package/dist/server/app-page-execution.js +31 -39
- package/dist/server/app-page-head.d.ts +54 -2
- package/dist/server/app-page-head.js +164 -78
- package/dist/server/app-page-http-access-fallback-metadata.d.ts +29 -0
- package/dist/server/app-page-http-access-fallback-metadata.js +106 -0
- package/dist/server/app-page-render.d.ts +2 -2
- package/dist/server/app-page-render.js +1 -1
- package/dist/server/app-page-request.d.ts +12 -0
- package/dist/server/app-page-request.js +134 -14
- package/dist/server/app-page-route-wiring.d.ts +9 -0
- package/dist/server/app-page-route-wiring.js +44 -4
- package/dist/server/app-post-middleware-context.d.ts +1 -1
- package/dist/server/app-post-middleware-context.js +1 -1
- package/dist/server/app-route-handler-dispatch.js +31 -17
- package/dist/server/app-route-handler-execution.d.ts +6 -1
- package/dist/server/app-route-handler-execution.js +41 -15
- package/dist/server/app-route-handler-policy.d.ts +2 -0
- package/dist/server/app-route-handler-policy.js +3 -3
- package/dist/server/app-route-module-loader.d.ts +3 -1
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-route-tree-prefetch.js +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +1 -1
- package/dist/server/app-rsc-cache-busting.js +1 -1
- package/dist/server/app-rsc-errors.d.ts +1 -1
- package/dist/server/app-rsc-errors.js +12 -2
- package/dist/server/app-rsc-handler.d.ts +10 -5
- package/dist/server/app-rsc-handler.js +51 -23
- package/dist/server/app-rsc-redirect-flight.d.ts +66 -0
- package/dist/server/app-rsc-redirect-flight.js +71 -0
- package/dist/server/app-rsc-request-normalization.d.ts +3 -2
- package/dist/server/app-rsc-request-normalization.js +8 -2
- package/dist/server/app-rsc-response-finalizer.d.ts +2 -2
- package/dist/server/app-rsc-response-finalizer.js +5 -11
- package/dist/server/app-rsc-route-matching.d.ts +20 -0
- package/dist/server/app-rsc-route-matching.js +87 -11
- package/dist/server/app-segment-config.js +15 -5
- package/dist/server/app-server-action-execution.d.ts +3 -1
- package/dist/server/app-server-action-execution.js +8 -6
- package/dist/server/app-ssr-entry.js +4 -1
- package/dist/server/app-ssr-stream.d.ts +2 -7
- package/dist/server/app-ssr-stream.js +5 -10
- package/dist/server/cache-proof.js +1 -1
- package/dist/server/config-headers.d.ts +24 -0
- package/dist/server/config-headers.js +52 -0
- package/dist/server/default-global-error-module.d.ts +3 -1
- package/dist/server/default-not-found-module.d.ts +3 -1
- package/dist/server/dev-initial-server-error.d.ts +1 -1
- package/dist/server/dev-lockfile.js +2 -3
- package/dist/server/dev-route-files.js +1 -1
- package/dist/server/dev-server.js +281 -173
- package/dist/server/dev-stack-sourcemap.js +4 -3
- package/dist/server/headers.d.ts +3 -1
- package/dist/server/headers.js +3 -1
- package/dist/server/image-optimization.js +2 -2
- package/dist/server/implicit-tags.js +2 -1
- package/dist/server/instrumentation.js +2 -2
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +1 -1
- package/dist/server/metadata-routes.js +4 -4
- package/dist/server/middleware-matcher-pattern.d.ts +22 -0
- package/dist/server/middleware-matcher-pattern.js +219 -0
- package/dist/server/middleware-matcher.d.ts +2 -7
- package/dist/server/middleware-matcher.js +13 -60
- package/dist/server/middleware-path-to-regexp.d.ts +14 -0
- package/dist/server/middleware-path-to-regexp.js +228 -0
- package/dist/server/middleware-response-headers.js +1 -1
- package/dist/server/middleware-runtime.js +5 -4
- package/dist/server/middleware.d.ts +2 -1
- package/dist/server/middleware.js +3 -2
- package/dist/server/navigation-planner.d.ts +2 -0
- package/dist/server/navigation-planner.js +8 -2
- package/dist/server/next-error-digest.d.ts +9 -24
- package/dist/server/next-error-digest.js +23 -15
- package/dist/server/operation-token.js +1 -1
- package/dist/server/pages-body-parser-config.js +2 -1
- package/dist/server/pages-data-route.d.ts +11 -1
- package/dist/server/pages-data-route.js +16 -1
- package/dist/server/pages-dev-hydration.d.ts +14 -0
- package/dist/server/pages-dev-hydration.js +83 -0
- package/dist/server/pages-dev-module-url.js +2 -2
- package/dist/server/pages-get-initial-props.d.ts +15 -2
- package/dist/server/pages-get-initial-props.js +16 -6
- package/dist/server/pages-node-compat.d.ts +13 -6
- package/dist/server/pages-node-compat.js +44 -45
- package/dist/server/pages-page-data.d.ts +4 -2
- package/dist/server/pages-page-data.js +20 -10
- package/dist/server/pages-page-handler.d.ts +4 -2
- package/dist/server/pages-page-handler.js +74 -43
- package/dist/server/pages-page-response.d.ts +2 -2
- package/dist/server/pages-page-response.js +1 -1
- package/dist/server/pages-preview.d.ts +26 -0
- package/dist/server/pages-preview.js +165 -0
- package/dist/server/pages-readiness.d.ts +5 -4
- package/dist/server/pages-readiness.js +4 -2
- package/dist/server/pages-request-pipeline.d.ts +1 -0
- package/dist/server/pages-request-pipeline.js +25 -11
- package/dist/server/pages-router-entry.js +6 -0
- package/dist/server/prerender-route-params.js +2 -2
- package/dist/server/prod-server.d.ts +1 -4
- package/dist/server/prod-server.js +44 -30
- package/dist/server/request-pipeline.d.ts +15 -29
- package/dist/server/request-pipeline.js +25 -60
- package/dist/server/rsc-stream-hints.js +122 -18
- package/dist/server/seed-cache.js +1 -1
- package/dist/server/socket-error-backstop.js +1 -1
- package/dist/server/static-file-cache.js +7 -8
- package/dist/server/worker-utils.js +1 -1
- package/dist/shims/app.d.ts +1 -1
- package/dist/shims/cache-request-state.d.ts +27 -1
- package/dist/shims/cache-request-state.js +60 -1
- package/dist/shims/cache-runtime.d.ts +12 -1
- package/dist/shims/cache-runtime.js +22 -7
- package/dist/shims/cache.d.ts +5 -5
- package/dist/shims/cache.js +28 -11
- package/dist/shims/constants.js +1 -1
- package/dist/shims/document.d.ts +42 -83
- package/dist/shims/document.js +62 -53
- package/dist/shims/dynamic.d.ts +5 -25
- package/dist/shims/dynamic.js +29 -8
- package/dist/shims/error-boundary.d.ts +4 -4
- package/dist/shims/error.d.ts +22 -6
- package/dist/shims/error.js +53 -15
- package/dist/shims/fetch-cache.js +13 -4
- package/dist/shims/font-google-base.d.ts +11 -4
- package/dist/shims/font-local.d.ts +10 -3
- package/dist/shims/font-utils.js +1 -1
- package/dist/shims/form.d.ts +1 -1
- package/dist/shims/head.d.ts +13 -2
- package/dist/shims/head.js +6 -6
- package/dist/shims/headers.d.ts +28 -31
- package/dist/shims/headers.js +115 -53
- package/dist/shims/image.d.ts +27 -37
- package/dist/shims/image.js +21 -14
- package/dist/shims/internal/cookie-serialize.d.ts +3 -1
- package/dist/shims/internal/cookie-serialize.js +3 -1
- package/dist/shims/internal/hybrid-client-route-owner.js +3 -1
- package/dist/shims/internal/pages-data-fetch-dedup.js +5 -3
- package/dist/shims/internal/utils.d.ts +3 -3
- package/dist/shims/layout-segment-context.d.ts +1 -1
- package/dist/shims/legacy-image.d.ts +3 -37
- package/dist/shims/legacy-image.js +6 -16
- package/dist/shims/link.d.ts +16 -21
- package/dist/shims/link.js +25 -13
- package/dist/shims/navigation-context-state.d.ts +1 -1
- package/dist/shims/navigation-errors.d.ts +2 -1
- package/dist/shims/navigation-errors.js +9 -13
- package/dist/shims/navigation.d.ts +8 -4
- package/dist/shims/navigation.js +29 -18
- package/dist/shims/next-shims-augmentations.d.ts +1 -0
- package/dist/shims/next-shims-public.d.ts +1 -0
- package/dist/shims/public-shim-map.json.js +103 -0
- package/dist/shims/readonly-url-search-params.d.ts +3 -3
- package/dist/shims/readonly-url-search-params.js +3 -3
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/router-state.d.ts +1 -0
- package/dist/shims/router.d.ts +57 -22
- package/dist/shims/router.js +178 -46
- package/dist/shims/script.d.ts +6 -10
- package/dist/shims/script.js +7 -4
- package/dist/shims/server.d.ts +45 -22
- package/dist/shims/server.js +46 -7
- package/dist/shims/slot.d.ts +1 -1
- package/dist/shims/thenable-params.js +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/shims/url-safety.d.ts +1 -1
- package/dist/shims/url-safety.js +2 -2
- package/dist/typegen.d.ts +8 -2
- package/dist/typegen.js +84 -25
- package/dist/utils/client-build-manifest.js +2 -2
- package/dist/utils/client-entry-manifest.js +1 -1
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/commonjs-loader.js +3 -3
- package/dist/utils/domain-locale.d.ts +2 -2
- package/dist/utils/external-url.d.ts +5 -0
- package/dist/utils/external-url.js +7 -0
- package/dist/utils/mdx-scan.js +1 -1
- package/dist/utils/path.d.ts +1 -13
- package/dist/utils/path.js +1 -15
- package/dist/utils/plugin-options.d.ts +4 -0
- package/dist/utils/plugin-options.js +8 -0
- package/dist/utils/project.d.ts +0 -6
- package/dist/utils/project.js +2 -8
- package/dist/utils/public-routes.js +2 -2
- package/dist/utils/react-version.js +1 -1
- package/dist/utils/redirect-digest.d.ts +9 -0
- package/dist/utils/redirect-digest.js +25 -0
- package/dist/utils/regex-safety.d.ts +8 -0
- package/dist/utils/regex-safety.js +737 -0
- package/dist/utils/vinext-root.js +1 -1
- package/dist/utils/vite-version.d.ts +5 -2
- package/dist/utils/vite-version.js +43 -17
- package/package.json +16 -4
- /package/dist/build/google-fonts/{fallback-metrics-data.js → fallback-metrics-data.json.js} +0 -0
- /package/dist/build/google-fonts/{font-data.js → font-data.json.js} +0 -0
- /package/dist/{node_modules/.pnpm/process-ancestry@0.1.0/node_modules → deps/.pnpm/process-ancestry@0.1.0/deps}/process-ancestry/dist/index.js +0 -0
package/dist/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import path, { toSlash } from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
1
2
|
import { detectPackageManager, formatMissingCloudflarePluginError, hasWranglerConfig } from "./utils/project.js";
|
|
2
|
-
import { normalizePathSeparators, stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
3
3
|
import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
|
|
4
|
-
import { escapeRegExp } from "./utils/regex.js";
|
|
5
4
|
import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts, normalizeViteResolveExtensions } from "./routing/file-matcher.js";
|
|
5
|
+
import { hasBasePath, stripBasePath } from "./utils/base-path.js";
|
|
6
6
|
import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
|
|
7
7
|
import { VINEXT_MW_CTX_HEADER } from "./utils/protocol-headers.js";
|
|
8
8
|
import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_TIMING_HEADER } from "./server/headers.js";
|
|
9
9
|
import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
|
|
10
10
|
import { matchesRewriteSource, proxyExternalRequest } from "./config/config-matchers.js";
|
|
11
|
+
import { validateMiddlewareMatcherPatterns } from "./server/middleware-matcher-pattern.js";
|
|
11
12
|
import { isOpenRedirectShaped } from "./server/open-redirect.js";
|
|
12
|
-
import { filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
13
|
+
import { canonicalizeRequestUrlPathname, filterInternalHeaders, normalizeTrailingSlash } from "./server/request-pipeline.js";
|
|
13
14
|
import { findMiddlewareFile, isProxyFile, runMiddleware } from "./server/middleware.js";
|
|
14
|
-
import { extractMiddlewareMatcherConfig, hasExportedName } from "./build/report.js";
|
|
15
|
+
import { extractMiddlewareMatcherConfig, extractMiddlewareMatcherConfigValue, hasExportedName } from "./build/report.js";
|
|
15
16
|
import { generateServerEntry } from "./entries/pages-server-entry.js";
|
|
16
17
|
import { generateClientEntry } from "./entries/pages-client-entry.js";
|
|
17
18
|
import { appRouteGraph, appRouter, invalidateAppRouteCache, matchAppRoute } from "./routing/app-router.js";
|
|
@@ -19,8 +20,9 @@ import { findInstrumentationClientFile, findInstrumentationFile, runInstrumentat
|
|
|
19
20
|
import { isUnknownRecord } from "./utils/record.js";
|
|
20
21
|
import { logRequest, now } from "./server/request-log.js";
|
|
21
22
|
import { resolvePagesI18nRequest, stripI18nLocaleForApiRoute } from "./server/pages-i18n.js";
|
|
22
|
-
import { isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname } from "./server/pages-data-route.js";
|
|
23
|
+
import { encodeUrlParserIgnoredCharacters, isNextDataPathname, normalizeNextDataPagePathname, parseNextDataPathname, urlParserCreatesPagesDataPath } from "./server/pages-data-route.js";
|
|
23
24
|
import { resolveAssetsDir } from "./utils/asset-prefix.js";
|
|
25
|
+
import { getPagesPreviewModeId } from "./server/pages-preview.js";
|
|
24
26
|
import { createSSRHandler } from "./server/dev-server.js";
|
|
25
27
|
import { handleApiRoute } from "./server/api-handler.js";
|
|
26
28
|
import { DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, isImageOptimizationPath, resolveDevImageRedirect } from "./server/image-optimization.js";
|
|
@@ -38,7 +40,7 @@ import { collectRouteClassificationManifest } from "./build/route-classification
|
|
|
38
40
|
import { planRouteClassificationInjection } from "./build/route-classification-injector.js";
|
|
39
41
|
import { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD } from "./shims/constants.js";
|
|
40
42
|
import { RESOLVED_VIRTUAL_GOOGLE_FONTS, VIRTUAL_GOOGLE_FONTS, createGoogleFontsPlugin, createLocalFontsPlugin, generateGoogleFontsVirtualModule, parseStaticObjectLiteral } from "./plugins/fonts.js";
|
|
41
|
-
import { createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
43
|
+
import { VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY, createRscCompatibilityId, findNextConfigPath, loadNextConfig, resolveNextConfig, resolveNextConfigInput } from "./config/next-config.js";
|
|
42
44
|
import { mergeServerExternalPackages } from "./config/server-external-packages.js";
|
|
43
45
|
import { precompressAssets } from "./build/precompress.js";
|
|
44
46
|
import { ensureAssetsIgnore } from "./build/assets-ignore.js";
|
|
@@ -59,6 +61,7 @@ import { createInstrumentationClientTransformPlugin } from "./plugins/instrument
|
|
|
59
61
|
import { createStyledJsxPlugin } from "./plugins/styled-jsx.js";
|
|
60
62
|
import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
|
|
61
63
|
import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
|
|
64
|
+
import { stripJsExtension, stripViteModuleQuery } from "./utils/path.js";
|
|
62
65
|
import { validateMiddlewareModuleExports } from "./plugins/middleware-export-validation.js";
|
|
63
66
|
import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
|
|
64
67
|
import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
|
|
@@ -67,9 +70,12 @@ import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins
|
|
|
67
70
|
import { generateRouteTypes } from "./typegen.js";
|
|
68
71
|
import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
|
|
69
72
|
import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
|
|
73
|
+
import public_shim_map_default from "./shims/public-shim-map.json.js";
|
|
70
74
|
import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
|
|
71
75
|
import { computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
|
|
72
76
|
import { PAGES_CLIENT_ASSETS_MODULE, buildPagesClientAssetsModule, setPagesClientAssetsBuildMetadata, takePagesClientAssetsBuildMetadata, writePagesClientAssetsModuleIfMissing } from "./build/pages-client-assets-module.js";
|
|
77
|
+
import { createPreviewBuildCredentials, getPreviewBuildCredentials } from "./build/preview-credentials.js";
|
|
78
|
+
import { createModuleDependencyCache } from "./build/module-dependency-cache.js";
|
|
73
79
|
import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
|
|
74
80
|
import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
|
|
75
81
|
import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassCssUrlAssetImporter, createSassTildeImporter } from "./plugins/sass.js";
|
|
@@ -89,10 +95,9 @@ import { VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY, VINEXT_ROUTE_ROOT_CONFIG_PLUGI
|
|
|
89
95
|
import { staticExportApp, staticExportPages } from "./build/static-export.js";
|
|
90
96
|
import { createRequire } from "node:module";
|
|
91
97
|
import fs from "node:fs";
|
|
92
|
-
import path from "node:path";
|
|
93
98
|
import { createLogger, loadEnv, parseAst, transformWithOxc } from "vite";
|
|
94
99
|
import { pathToFileURL } from "node:url";
|
|
95
|
-
import { createHash, randomBytes
|
|
100
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
96
101
|
import commonjs from "vite-plugin-commonjs";
|
|
97
102
|
import MagicString from "magic-string";
|
|
98
103
|
//#region src/index.ts
|
|
@@ -109,10 +114,6 @@ const OPTIONAL_OPTIMIZE_DEPS_WARNING_RE = /Failed to resolve dependency: .*use-s
|
|
|
109
114
|
const VINEXT_FILTERED_OPTIMIZE_DEPS_WARN = Symbol.for("vinext.filteredOptimizeDepsWarn");
|
|
110
115
|
const ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
111
116
|
installSocketErrorBackstop();
|
|
112
|
-
function getCacheDirPrefix(cacheDir) {
|
|
113
|
-
const normalizedCacheDir = normalizePathSeparators(cacheDir);
|
|
114
|
-
return normalizedCacheDir.endsWith("/") ? normalizedCacheDir : `${normalizedCacheDir}/`;
|
|
115
|
-
}
|
|
116
117
|
function isInsideDirectory(dir, filePath) {
|
|
117
118
|
const relativePath = path.relative(dir, filePath);
|
|
118
119
|
return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
|
@@ -165,21 +166,22 @@ function resolveShimModulePath(shimsDir, moduleName) {
|
|
|
165
166
|
".tsx",
|
|
166
167
|
".js"
|
|
167
168
|
]) {
|
|
168
|
-
const candidate = path.
|
|
169
|
+
const candidate = path.join(shimsDir, `${moduleName}${ext}`);
|
|
169
170
|
if (fs.existsSync(candidate)) return candidate;
|
|
170
171
|
}
|
|
171
|
-
return path.
|
|
172
|
+
return path.join(shimsDir, `${moduleName}.js`);
|
|
172
173
|
}
|
|
173
174
|
function isVercelOgImport(id) {
|
|
174
175
|
return id === "@vercel/og" || id === "@vercel/og.js";
|
|
175
176
|
}
|
|
176
177
|
function isVinextOgShimImporter(importer) {
|
|
177
178
|
if (!importer) return false;
|
|
178
|
-
const
|
|
179
|
+
const cleanImporter = (importer.startsWith("\0") ? importer.slice(1) : importer).split("?")[0];
|
|
180
|
+
const normalizedImporter = toSlash(cleanImporter);
|
|
179
181
|
return normalizedImporter.endsWith("/shims/og.tsx") || normalizedImporter.endsWith("/shims/og.js") || normalizedImporter.endsWith("/dist/shims/og.js");
|
|
180
182
|
}
|
|
181
183
|
function toRelativeFileEntry(root, absPath) {
|
|
182
|
-
return path.relative(root, absPath)
|
|
184
|
+
return path.relative(root, absPath);
|
|
183
185
|
}
|
|
184
186
|
const DEV_PAGES_CLIENT_ENTRY = "/@id/__x00__virtual:vinext-client-entry";
|
|
185
187
|
const STYLESHEET_IMPORT_RE = /\.(?:css|scss|sass)$/i;
|
|
@@ -243,7 +245,7 @@ function isScriptModuleId(id) {
|
|
|
243
245
|
return SCRIPT_IMPORT_RE.test(stripViteModuleQuery(id).toLowerCase());
|
|
244
246
|
}
|
|
245
247
|
function skipCommonjsForLocalCjs(id) {
|
|
246
|
-
const cleanId =
|
|
248
|
+
const cleanId = toSlash(stripViteModuleQuery(id));
|
|
247
249
|
return /\.c[jt]s$/i.test(cleanId) && !cleanId.includes("node_modules") ? false : void 0;
|
|
248
250
|
}
|
|
249
251
|
function hasOnlyTypeSpecifiers(statement) {
|
|
@@ -255,24 +257,37 @@ function resolvedStylesheetToDevManifestAsset(root, resolvedId) {
|
|
|
255
257
|
const rootForRelative = tryRealpathSync(root) ?? root;
|
|
256
258
|
const fileForRelative = tryRealpathSync(cleanId) ?? cleanId;
|
|
257
259
|
const relativePath = path.relative(rootForRelative, fileForRelative);
|
|
258
|
-
if (relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath)) return
|
|
259
|
-
return `@fs/${
|
|
260
|
+
if (relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath)) return relativePath;
|
|
261
|
+
return `@fs/${toSlash(cleanId).replace(/^\/+/, "")}`;
|
|
260
262
|
}
|
|
261
|
-
async function collectDevPagesAppStylesheetAssets(
|
|
263
|
+
async function collectDevPagesAppStylesheetAssets(appFilePath, getModuleDependencies) {
|
|
262
264
|
const stylesheetAssets = [];
|
|
263
265
|
const seenAssets = /* @__PURE__ */ new Set();
|
|
264
266
|
const seenModules = /* @__PURE__ */ new Set();
|
|
265
267
|
async function visitModule(modulePath) {
|
|
268
|
+
if (seenModules.has(modulePath)) return;
|
|
269
|
+
seenModules.add(modulePath);
|
|
270
|
+
for (const dependency of await getModuleDependencies(modulePath)) if (dependency.type === "stylesheet") {
|
|
271
|
+
if (seenAssets.has(dependency.asset)) continue;
|
|
272
|
+
seenAssets.add(dependency.asset);
|
|
273
|
+
stylesheetAssets.push(dependency.asset);
|
|
274
|
+
} else await visitModule(dependency.id);
|
|
275
|
+
}
|
|
276
|
+
await visitModule(appFilePath);
|
|
277
|
+
return stylesheetAssets;
|
|
278
|
+
}
|
|
279
|
+
function createDevPagesModuleDependencyReader(root, resolve) {
|
|
280
|
+
return createModuleDependencyCache(collectModuleDependencies);
|
|
281
|
+
async function collectModuleDependencies(modulePath) {
|
|
266
282
|
const cleanModulePath = stripViteModuleQuery(modulePath);
|
|
267
|
-
if (!path.isAbsolute(cleanModulePath) || !fs.existsSync(cleanModulePath)) return;
|
|
268
|
-
if (seenModules.has(cleanModulePath)) return;
|
|
269
|
-
seenModules.add(cleanModulePath);
|
|
283
|
+
if (!path.isAbsolute(cleanModulePath) || !fs.existsSync(cleanModulePath)) return [];
|
|
270
284
|
let ast;
|
|
271
285
|
try {
|
|
272
286
|
ast = parseAst(fs.readFileSync(cleanModulePath, "utf-8"), { lang: parserLanguageForScript(cleanModulePath) });
|
|
273
287
|
} catch {
|
|
274
|
-
return;
|
|
288
|
+
return [];
|
|
275
289
|
}
|
|
290
|
+
const dependencies = [];
|
|
276
291
|
for (const statement of ast.body) {
|
|
277
292
|
if (statement.type !== "ImportDeclaration" && statement.type !== "ExportNamedDeclaration" && statement.type !== "ExportAllDeclaration") continue;
|
|
278
293
|
if (statement.importKind === "type") continue;
|
|
@@ -285,17 +300,17 @@ async function collectDevPagesAppStylesheetAssets(root, appFilePath, resolve) {
|
|
|
285
300
|
if (!resolved?.id) continue;
|
|
286
301
|
if (isStylesheetSpecifier(specifier)) {
|
|
287
302
|
const asset = resolvedStylesheetToDevManifestAsset(root, resolved.id);
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
303
|
+
if (asset) dependencies.push({
|
|
304
|
+
type: "stylesheet",
|
|
305
|
+
asset
|
|
306
|
+
});
|
|
307
|
+
} else if (!specifier.includes("?") && !specifier.includes("#") && isScriptModuleId(resolved.id)) dependencies.push({
|
|
308
|
+
type: "script",
|
|
309
|
+
id: resolved.id
|
|
310
|
+
});
|
|
295
311
|
}
|
|
312
|
+
return dependencies;
|
|
296
313
|
}
|
|
297
|
-
await visitModule(appFilePath);
|
|
298
|
-
return stylesheetAssets;
|
|
299
314
|
}
|
|
300
315
|
const TSCONFIG_FILES = ["tsconfig.json", "jsconfig.json"];
|
|
301
316
|
function resolveTsconfigPathCandidate(candidate) {
|
|
@@ -353,11 +368,11 @@ function materializeTsconfigPathAliases(pathsConfig, baseUrl, projectRoot) {
|
|
|
353
368
|
return aliases;
|
|
354
369
|
}
|
|
355
370
|
function toViteAliasReplacement(absolutePath, projectRoot) {
|
|
356
|
-
const normalizedPath = absolutePath
|
|
357
|
-
const rootCandidates = new Set([projectRoot]);
|
|
371
|
+
const normalizedPath = toSlash(absolutePath);
|
|
372
|
+
const rootCandidates = /* @__PURE__ */ new Set([projectRoot]);
|
|
358
373
|
const realRoot = tryRealpathSync(projectRoot);
|
|
359
374
|
if (realRoot) rootCandidates.add(realRoot);
|
|
360
|
-
const pathCandidates = new Set([absolutePath]);
|
|
375
|
+
const pathCandidates = /* @__PURE__ */ new Set([absolutePath]);
|
|
361
376
|
const realPath = tryRealpathSync(absolutePath);
|
|
362
377
|
if (realPath) pathCandidates.add(realPath);
|
|
363
378
|
for (const rootCandidate of rootCandidates) for (const pathCandidate of pathCandidates) {
|
|
@@ -378,7 +393,7 @@ function resolveSwcHelpersAlias(root) {
|
|
|
378
393
|
resolvers.push(rootRequire, createRequire(import.meta.url));
|
|
379
394
|
for (const resolver of resolvers) try {
|
|
380
395
|
const packageJsonPath = resolver.resolve("@swc/helpers/package.json");
|
|
381
|
-
return
|
|
396
|
+
return path.join(path.dirname(packageJsonPath), "_");
|
|
382
397
|
} catch {}
|
|
383
398
|
}
|
|
384
399
|
function loadTsconfigPathAliases(configPath, projectRoot, seen = /* @__PURE__ */ new Set()) {
|
|
@@ -432,7 +447,7 @@ function getVinextVersion() {
|
|
|
432
447
|
return _vinextVersionCache;
|
|
433
448
|
}
|
|
434
449
|
function mergeStringArrayValues(value, additions) {
|
|
435
|
-
return [
|
|
450
|
+
return [.../* @__PURE__ */ new Set([...value === void 0 ? [] : Array.isArray(value) ? value : [value], ...additions])];
|
|
436
451
|
}
|
|
437
452
|
function stripAnsi(value) {
|
|
438
453
|
return value.replace(ANSI_ESCAPE_RE, "");
|
|
@@ -579,14 +594,14 @@ function createStaticImageAsset(imagePath) {
|
|
|
579
594
|
};
|
|
580
595
|
}
|
|
581
596
|
/**
|
|
582
|
-
* Absolute path to vinext's shims directory, with a trailing slash.
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
597
|
+
* Absolute path to vinext's shims directory, with a trailing slash. Forward
|
|
598
|
+
* slashes are guaranteed by pathslash's `path.resolve`, matching the Vite
|
|
599
|
+
* module ids (always forward-slash) that the `id.startsWith(_shimsDir)`
|
|
600
|
+
* prefix checks in the font plugins and clientManualChunks compare against.
|
|
601
|
+
* The trailing "/" keeps those prefix checks directory-exact.
|
|
587
602
|
*/
|
|
588
|
-
const _shimsDir =
|
|
589
|
-
const _serverDir =
|
|
603
|
+
const _shimsDir = path.resolve(__dirname, "shims") + "/";
|
|
604
|
+
const _serverDir = path.resolve(__dirname, "server");
|
|
590
605
|
const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
|
|
591
606
|
const _appBrowserServerActionClientPath = resolveShimModulePath(_serverDir, "app-browser-server-action-client");
|
|
592
607
|
const _appRscHandlerPath = resolveShimModulePath(_serverDir, "app-rsc-handler");
|
|
@@ -597,8 +612,8 @@ function isValidExportIdentifier(name) {
|
|
|
597
612
|
}
|
|
598
613
|
function isVirtualEntryFacade(id, virtualId) {
|
|
599
614
|
if (!id) return false;
|
|
600
|
-
const cleanId = id.startsWith("\0") ? id.slice(1) : id;
|
|
601
|
-
return cleanId === virtualId || cleanId.endsWith("/" + virtualId)
|
|
615
|
+
const cleanId = toSlash(id.startsWith("\0") ? id.slice(1) : id);
|
|
616
|
+
return cleanId === virtualId || cleanId.endsWith("/" + virtualId);
|
|
602
617
|
}
|
|
603
618
|
/**
|
|
604
619
|
* Returns the leading React `"use client"` or `"use server"` directive after
|
|
@@ -655,27 +670,14 @@ function generateRootParamsModule(rootParamNames) {
|
|
|
655
670
|
const exports = names.map((name) => `export function ${name}() { return getRootParam(${JSON.stringify(name)}); }`).join("\n");
|
|
656
671
|
return `import { getRootParam } from ${JSON.stringify(rootParamsShimPath)};\n${exports}\n`;
|
|
657
672
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
* control resolution per-environment.
|
|
667
|
-
*
|
|
668
|
-
* To add a new react-server shim:
|
|
669
|
-
* 1. Create `<name>.react-server.ts` in src/shims/
|
|
670
|
-
* 2. Add entries here for each import specifier.
|
|
671
|
-
*/
|
|
672
|
-
const _reactServerShims = new Map([
|
|
673
|
-
["next/navigation", "navigation"],
|
|
674
|
-
["next/navigation.js", "navigation"],
|
|
675
|
-
["next/dist/client/components/navigation", "navigation"],
|
|
676
|
-
["next/error", "error"],
|
|
677
|
-
["next/error.js", "error"]
|
|
678
|
-
]);
|
|
673
|
+
const _publicNextShimMap = public_shim_map_default;
|
|
674
|
+
const _reactServerShims = /* @__PURE__ */ new Map();
|
|
675
|
+
for (const [specifier, definition] of Object.entries(_publicNextShimMap)) {
|
|
676
|
+
if (!definition.reactServer) continue;
|
|
677
|
+
_reactServerShims.set(specifier, definition.shim);
|
|
678
|
+
_reactServerShims.set(`${specifier}.js`, definition.shim);
|
|
679
|
+
}
|
|
680
|
+
_reactServerShims.set("next/dist/client/components/navigation", "navigation");
|
|
679
681
|
const clientCodeSplittingConfig = createClientCodeSplittingConfig(createClientManualChunks(_shimsDir));
|
|
680
682
|
const appClientCodeSplittingConfig = createClientCodeSplittingConfig(createClientManualChunks(_shimsDir, true));
|
|
681
683
|
function getClientOutputConfig(assetsDir, preserveAppRouteBoundaries = false) {
|
|
@@ -687,7 +689,7 @@ function getClientOutputConfig(assetsDir, preserveAppRouteBoundaries = false) {
|
|
|
687
689
|
};
|
|
688
690
|
}
|
|
689
691
|
function vinext(options = {}) {
|
|
690
|
-
assertSupportedViteVersion();
|
|
692
|
+
const { supportsNativeTypeofWindowFolding: useNativeTypeofWindowFolding } = assertSupportedViteVersion();
|
|
691
693
|
const prerenderConfig = normalizeVinextPrerenderConfig(options.prerender);
|
|
692
694
|
let root;
|
|
693
695
|
let pagesDir;
|
|
@@ -706,17 +708,18 @@ function vinext(options = {}) {
|
|
|
706
708
|
let hasCloudflarePlugin = false;
|
|
707
709
|
let warnedInlineNextConfigOverride = false;
|
|
708
710
|
let hasNitroPlugin = false;
|
|
711
|
+
let nitroTraceDepsFromServerExternals = [];
|
|
709
712
|
let isServeCommand = false;
|
|
710
713
|
let pagesOptimizeEntries = [];
|
|
711
714
|
const pagesClientAssetsOutputDirs = /* @__PURE__ */ new Set();
|
|
712
715
|
let pagesClientAssetsModule = null;
|
|
713
716
|
let rscCompatibilityId;
|
|
714
|
-
|
|
717
|
+
let draftModeSecret = getPagesPreviewModeId();
|
|
718
|
+
let previewBuildCredentials;
|
|
715
719
|
const sassComposesLoader = createSassAwareFileSystemLoader();
|
|
716
|
-
const typeofWindowIdFilter = { exclude: /(?!)/ };
|
|
717
720
|
let rscClassificationManifest = null;
|
|
718
|
-
const shimsDir =
|
|
719
|
-
const canonicalize = (p) =>
|
|
721
|
+
const shimsDir = path.resolve(__dirname, "shims");
|
|
722
|
+
const canonicalize = (p) => toSlash(tryRealpathSync(p) ?? p);
|
|
720
723
|
const pageTransformCanonicalPaths = /* @__PURE__ */ new Map();
|
|
721
724
|
const canonicalizePageTransformPath = (modulePath) => {
|
|
722
725
|
const cached = pageTransformCanonicalPaths.get(modulePath);
|
|
@@ -761,10 +764,9 @@ function vinext(options = {}) {
|
|
|
761
764
|
});
|
|
762
765
|
}
|
|
763
766
|
async function writeRouteTypes() {
|
|
764
|
-
if (!hasAppDir) return;
|
|
765
767
|
await generateRouteTypes({
|
|
766
768
|
root,
|
|
767
|
-
appDir,
|
|
769
|
+
appDir: hasAppDir ? appDir : null,
|
|
768
770
|
pageExtensions: nextConfig.pageExtensions
|
|
769
771
|
});
|
|
770
772
|
}
|
|
@@ -801,11 +803,32 @@ function vinext(options = {}) {
|
|
|
801
803
|
if (!pluginApi || pluginApi.manager.isScanBuild) return true;
|
|
802
804
|
return Object.keys(pluginApi.manager.serverReferenceMetaMap).length > 0;
|
|
803
805
|
}
|
|
804
|
-
const
|
|
806
|
+
const configuredReactOptions = options.react && options.react !== true ? options.react : void 0;
|
|
807
|
+
const reactOptions = configuredReactOptions;
|
|
805
808
|
let reactPluginPromise = null;
|
|
806
809
|
if (options.react !== false) {
|
|
807
810
|
if (!resolvedReactPath) throw new Error("vinext: @vitejs/plugin-react is not installed.\nRun: " + detectPackageManager(process.cwd()) + " @vitejs/plugin-react");
|
|
808
|
-
reactPluginPromise = import(pathToFileURL(resolvedReactPath).href).then((mod) =>
|
|
811
|
+
reactPluginPromise = import(pathToFileURL(resolvedReactPath).href).then((mod) => {
|
|
812
|
+
const react = mod.default;
|
|
813
|
+
const limitToCommand = (plugin, command) => {
|
|
814
|
+
const originalApply = plugin.apply;
|
|
815
|
+
return {
|
|
816
|
+
...plugin,
|
|
817
|
+
apply(config, env) {
|
|
818
|
+
if (env.command !== command) return false;
|
|
819
|
+
if (!originalApply) return true;
|
|
820
|
+
if (typeof originalApply === "function") return originalApply(config, env);
|
|
821
|
+
return originalApply === env.command;
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
};
|
|
825
|
+
const buildPlugins = react(reactOptions).map((plugin) => limitToCommand(plugin, "build"));
|
|
826
|
+
const servePlugins = react(configuredReactOptions !== void 0 && Object.prototype.hasOwnProperty.call(configuredReactOptions, "include") ? reactOptions : {
|
|
827
|
+
...reactOptions,
|
|
828
|
+
include: /\.(?:[tj]sx?|mdx)$/i
|
|
829
|
+
}).map((plugin) => limitToCommand(plugin, "serve"));
|
|
830
|
+
return [...buildPlugins, ...servePlugins];
|
|
831
|
+
}).catch((cause) => {
|
|
809
832
|
throw new Error("vinext: Failed to load @vitejs/plugin-react.", { cause });
|
|
810
833
|
});
|
|
811
834
|
}
|
|
@@ -845,8 +868,36 @@ function vinext(options = {}) {
|
|
|
845
868
|
})();
|
|
846
869
|
return mdxDelegatePromise;
|
|
847
870
|
}
|
|
871
|
+
const mdxProxyPlugin = {
|
|
872
|
+
name: "vinext:mdx",
|
|
873
|
+
enforce: "pre",
|
|
874
|
+
transform: {
|
|
875
|
+
filter: { id: {
|
|
876
|
+
include: /\.mdx$/i,
|
|
877
|
+
exclude: /\?/
|
|
878
|
+
} },
|
|
879
|
+
async handler(code, id, options) {
|
|
880
|
+
const delegate = mdxDelegate ?? await ensureMdxDelegate("on-demand");
|
|
881
|
+
if (delegate?.transform) {
|
|
882
|
+
const hook = delegate.transform;
|
|
883
|
+
return (typeof hook === "function" ? hook : hook.handler).call(this, code, id, options);
|
|
884
|
+
}
|
|
885
|
+
if (!hasUserMdxPlugin) throw new Error(`[vinext] Encountered MDX module ${id} but no MDX plugin is configured. Install @mdx-js/rollup or register an MDX plugin manually.`);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
const mdxConfigProxyPlugin = {
|
|
890
|
+
name: "vinext:mdx-config",
|
|
891
|
+
enforce: "pre",
|
|
892
|
+
config(config, env) {
|
|
893
|
+
if (!mdxDelegate?.config) return;
|
|
894
|
+
const hook = mdxDelegate.config;
|
|
895
|
+
return (typeof hook === "function" ? hook : hook.handler).call(this, config, env);
|
|
896
|
+
}
|
|
897
|
+
};
|
|
848
898
|
const plugins = [
|
|
849
899
|
createStyledJsxPlugin(earlyBaseDir),
|
|
900
|
+
mdxProxyPlugin,
|
|
850
901
|
reactPluginPromise,
|
|
851
902
|
createIgnoreDynamicRequestsPlugin(() => nextConfig?.turbopackTranspilePackages ?? []),
|
|
852
903
|
commonjs({ filter: skipCommonjsForLocalCjs }),
|
|
@@ -860,7 +911,7 @@ function vinext(options = {}) {
|
|
|
860
911
|
code: /\.(?:css|scss|sass)['"]/
|
|
861
912
|
},
|
|
862
913
|
handler(code, id) {
|
|
863
|
-
const cleanId =
|
|
914
|
+
const cleanId = toSlash(stripViteModuleQuery(id));
|
|
864
915
|
if (!globalNotFoundCssIsolationPath || canonicalize(cleanId) !== canonicalize(globalNotFoundCssIsolationPath)) return null;
|
|
865
916
|
return isolateGlobalNotFoundStylesheetImports(code, cleanId);
|
|
866
917
|
}
|
|
@@ -905,6 +956,7 @@ function vinext(options = {}) {
|
|
|
905
956
|
name: "vinext:config",
|
|
906
957
|
enforce: "pre",
|
|
907
958
|
[VINEXT_PRERENDER_CONFIG_PLUGIN_PROPERTY]: prerenderConfig,
|
|
959
|
+
[VINEXT_NEXT_CONFIG_PLUGIN_PROPERTY]: options.nextConfig ?? null,
|
|
908
960
|
[VINEXT_ROUTE_ROOT_CONFIG_PLUGIN_PROPERTY]: {
|
|
909
961
|
appDir: options.appDir,
|
|
910
962
|
disableAppRouter: options.disableAppRouter,
|
|
@@ -914,7 +966,7 @@ function vinext(options = {}) {
|
|
|
914
966
|
[VINEXT_CACHE_CONFIG_PLUGIN_PROPERTY]: options.cache ?? null,
|
|
915
967
|
async config(config, env) {
|
|
916
968
|
isServeCommand = env.command === "serve";
|
|
917
|
-
root =
|
|
969
|
+
root = toSlash(config.root ?? process.cwd());
|
|
918
970
|
const shouldEnableNativeTsconfigPaths = config.resolve?.tsconfigPaths === void 0;
|
|
919
971
|
const tsconfigPathAliases = resolveTsconfigAliases(root);
|
|
920
972
|
const swcHelpersAlias = resolveSwcHelpersAlias(root);
|
|
@@ -926,23 +978,27 @@ function vinext(options = {}) {
|
|
|
926
978
|
if (mode === "test") resolvedNodeEnv = "test";
|
|
927
979
|
else if (env?.command === "build" || env?.isPreview === true) resolvedNodeEnv = "production";
|
|
928
980
|
else resolvedNodeEnv = "development";
|
|
929
|
-
if (process.env.NODE_ENV !== resolvedNodeEnv) process.env
|
|
981
|
+
if (process.env.NODE_ENV !== resolvedNodeEnv) Reflect.set(process.env, "NODE_ENV", resolvedNodeEnv);
|
|
982
|
+
if (env?.command === "build") previewBuildCredentials = getPreviewBuildCredentials() ?? createPreviewBuildCredentials();
|
|
983
|
+
draftModeSecret = previewBuildCredentials?.id ?? getPagesPreviewModeId();
|
|
930
984
|
let baseDir;
|
|
931
|
-
if (options.appDir) baseDir =
|
|
985
|
+
if (options.appDir) baseDir = toSlash(path.isAbsolute(options.appDir) ? options.appDir : path.resolve(root, options.appDir));
|
|
932
986
|
else {
|
|
933
|
-
const hasRootApp = fs.existsSync(path.
|
|
934
|
-
const hasRootPages = fs.existsSync(path.
|
|
935
|
-
const hasSrcApp = fs.existsSync(path.
|
|
936
|
-
const hasSrcPages = fs.existsSync(path.
|
|
987
|
+
const hasRootApp = fs.existsSync(path.join(root, "app"));
|
|
988
|
+
const hasRootPages = fs.existsSync(path.join(root, "pages"));
|
|
989
|
+
const hasSrcApp = fs.existsSync(path.join(root, "src", "app"));
|
|
990
|
+
const hasSrcPages = fs.existsSync(path.join(root, "src", "pages"));
|
|
937
991
|
if (hasRootApp || hasRootPages) baseDir = root;
|
|
938
|
-
else if (hasSrcApp || hasSrcPages) baseDir = path.
|
|
992
|
+
else if (hasSrcApp || hasSrcPages) baseDir = path.join(root, "src");
|
|
939
993
|
else baseDir = root;
|
|
940
994
|
}
|
|
941
|
-
pagesDir = path.
|
|
995
|
+
pagesDir = path.join(baseDir, "pages");
|
|
942
996
|
canonicalPagesDir = canonicalize(pagesDir);
|
|
943
|
-
appDir = path.
|
|
997
|
+
appDir = path.join(baseDir, "app");
|
|
944
998
|
hasPagesDir = fs.existsSync(pagesDir);
|
|
945
999
|
hasAppDir = !options.disableAppRouter && fs.existsSync(appDir);
|
|
1000
|
+
invalidateRouteCache(pagesDir);
|
|
1001
|
+
invalidateAppRouteCache();
|
|
946
1002
|
if (!nextConfig) {
|
|
947
1003
|
const phase = env?.command === "build" ? PHASE_PRODUCTION_BUILD : PHASE_DEVELOPMENT_SERVER;
|
|
948
1004
|
let rawConfig;
|
|
@@ -969,8 +1025,12 @@ function vinext(options = {}) {
|
|
|
969
1025
|
globalNotFoundCssIsolationPath = env?.command === "build" && nextConfig.globalNotFound ? findFileWithExts(appDir, "global-not-found", fileMatcher) : null;
|
|
970
1026
|
instrumentationPath = findInstrumentationFile(root, fileMatcher);
|
|
971
1027
|
instrumentationClientPath = findInstrumentationClientFile(root, fileMatcher);
|
|
972
|
-
const middlewareConventionDir = canonicalize(baseDir) === canonicalize(path.
|
|
1028
|
+
const middlewareConventionDir = canonicalize(baseDir) === canonicalize(path.join(root, "src")) ? path.join(root, "src") : root;
|
|
973
1029
|
middlewarePath = findMiddlewareFile(root, fileMatcher, middlewareConventionDir);
|
|
1030
|
+
if (middlewarePath) {
|
|
1031
|
+
const staticMatcher = extractMiddlewareMatcherConfigValue(middlewarePath);
|
|
1032
|
+
if (staticMatcher !== void 0) validateMiddlewareMatcherPatterns(staticMatcher);
|
|
1033
|
+
}
|
|
974
1034
|
const instrumentationClientInjects = nextConfig.instrumentationClientInject.map((spec) => spec.startsWith("./") || spec.startsWith("../") ? path.resolve(root, spec) : spec);
|
|
975
1035
|
clientInjectModule = instrumentationClientInjects.length ? generateInstrumentationClientInjectModule(instrumentationClientInjects, instrumentationClientPath, INSTRUMENTATION_CLIENT_EMPTY_MODULE) : null;
|
|
976
1036
|
if (env?.command === "build") await writeRouteTypes();
|
|
@@ -985,6 +1045,10 @@ function vinext(options = {}) {
|
|
|
985
1045
|
}
|
|
986
1046
|
defines["process.env.__NEXT_ROUTER_BASEPATH"] = JSON.stringify(nextConfig.basePath);
|
|
987
1047
|
defines["process.env.__VINEXT_HAS_PAGES_ROUTER"] = JSON.stringify(String(hasPagesDir));
|
|
1048
|
+
defines["process.env.__VINEXT_HAS_CLIENT_REWRITES"] = JSON.stringify(String(nextConfig.rewrites.beforeFiles.length > 0 || nextConfig.rewrites.afterFiles.length > 0 || nextConfig.rewrites.fallback.length > 0));
|
|
1049
|
+
defines["process.env.__VINEXT_HAS_CONFIG_HEADERS"] = JSON.stringify(String(nextConfig.headers.length > 0));
|
|
1050
|
+
defines["process.env.__VINEXT_HAS_CONFIG_REDIRECTS"] = JSON.stringify(String(nextConfig.redirects.length > 0));
|
|
1051
|
+
defines["process.env.__VINEXT_HAS_CONFIG_REWRITES"] = JSON.stringify(String(nextConfig.rewrites.beforeFiles.length > 0 || nextConfig.rewrites.afterFiles.length > 0 || nextConfig.rewrites.fallback.length > 0));
|
|
988
1052
|
defines["process.env.__NEXT_CLIENT_ROUTER_DYNAMIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.dynamic));
|
|
989
1053
|
defines["process.env.__NEXT_CLIENT_ROUTER_STATIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.static));
|
|
990
1054
|
defines["process.env.__VINEXT_PREFETCH_INLINING"] = JSON.stringify(nextConfig.prefetchInlining ? "true" : "false");
|
|
@@ -1036,55 +1100,34 @@ function vinext(options = {}) {
|
|
|
1036
1100
|
}
|
|
1037
1101
|
for (const key of Object.keys(nextConfig.compilerDefineServer)) if (key in defines) throw new Error(`The \`compiler.defineServer\` option is configured to replace the \`${key}\` variable. This variable is either part of a built-in or is already configured.`);
|
|
1038
1102
|
nextShimMap = Object.fromEntries(Object.entries({
|
|
1039
|
-
|
|
1040
|
-
"next/
|
|
1041
|
-
"next/router": path.
|
|
1042
|
-
"next/
|
|
1043
|
-
"next/
|
|
1044
|
-
"next/
|
|
1045
|
-
"next/
|
|
1046
|
-
"next/
|
|
1047
|
-
"next/
|
|
1048
|
-
"next/
|
|
1049
|
-
"next/
|
|
1050
|
-
"next/
|
|
1051
|
-
"next/
|
|
1052
|
-
"next/
|
|
1053
|
-
"
|
|
1054
|
-
"
|
|
1055
|
-
"
|
|
1056
|
-
"
|
|
1057
|
-
"
|
|
1058
|
-
"
|
|
1059
|
-
"
|
|
1060
|
-
"
|
|
1061
|
-
"
|
|
1062
|
-
"
|
|
1063
|
-
"
|
|
1064
|
-
"
|
|
1065
|
-
"
|
|
1066
|
-
"
|
|
1067
|
-
"next/dist/compiled/@edge-runtime/cookies": path.posix.join(shimsDir, "internal", "cookies"),
|
|
1068
|
-
"next/dist/server/app-render/work-unit-async-storage.external": path.posix.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
1069
|
-
"next/dist/client/components/work-unit-async-storage.external": path.posix.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
1070
|
-
"next/dist/client/components/request-async-storage.external": path.posix.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
1071
|
-
"next/dist/client/components/request-async-storage": path.posix.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
1072
|
-
"next/dist/server/request/root-params": path.posix.join(shimsDir, "root-params"),
|
|
1073
|
-
"next/dist/server/config-shared": path.posix.join(shimsDir, "internal", "utils"),
|
|
1074
|
-
"server-only": path.posix.join(shimsDir, "server-only"),
|
|
1075
|
-
"client-only": path.posix.join(shimsDir, "client-only"),
|
|
1076
|
-
"vinext/error-boundary": path.posix.join(shimsDir, "error-boundary"),
|
|
1077
|
-
"vinext/layout-segment-context": path.posix.join(shimsDir, "layout-segment-context"),
|
|
1078
|
-
"vinext/metadata": path.posix.join(shimsDir, "metadata"),
|
|
1079
|
-
"vinext/fetch-cache": path.posix.join(shimsDir, "fetch-cache"),
|
|
1080
|
-
"vinext/cache-runtime": path.posix.join(shimsDir, "cache-runtime"),
|
|
1081
|
-
"vinext/navigation-state": path.posix.join(shimsDir, "navigation-state"),
|
|
1082
|
-
"vinext/unified-request-context": path.posix.join(shimsDir, "unified-request-context"),
|
|
1083
|
-
"vinext/pages-router-runtime": path.posix.join(shimsDir, "pages-router-runtime"),
|
|
1084
|
-
"vinext/router-state": path.posix.join(shimsDir, "router-state"),
|
|
1085
|
-
"vinext/head-state": path.posix.join(shimsDir, "head-state"),
|
|
1086
|
-
"vinext/i18n-state": path.posix.join(shimsDir, "i18n-state"),
|
|
1087
|
-
"vinext/i18n-context": path.posix.join(shimsDir, "i18n-context"),
|
|
1103
|
+
...Object.fromEntries(Object.entries(_publicNextShimMap).filter(([, definition]) => !definition.reactServer).map(([specifier, definition]) => [specifier, path.join(shimsDir, definition.shim)])),
|
|
1104
|
+
"next/dist/shared/lib/app-router-context.shared-runtime": path.join(shimsDir, "internal", "app-router-context"),
|
|
1105
|
+
"next/dist/shared/lib/app-router-context": path.join(shimsDir, "internal", "app-router-context"),
|
|
1106
|
+
"next/dist/shared/lib/router-context.shared-runtime": path.join(shimsDir, "internal", "router-context"),
|
|
1107
|
+
"next/dist/shared/lib/utils": path.join(shimsDir, "internal", "utils"),
|
|
1108
|
+
"next/dist/server/api-utils": path.join(shimsDir, "internal", "api-utils"),
|
|
1109
|
+
"next/dist/server/web/spec-extension/cookies": path.join(shimsDir, "internal", "cookies"),
|
|
1110
|
+
"next/dist/compiled/@edge-runtime/cookies": path.join(shimsDir, "internal", "cookies"),
|
|
1111
|
+
"next/dist/server/app-render/work-unit-async-storage.external": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
1112
|
+
"next/dist/client/components/work-unit-async-storage.external": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
1113
|
+
"next/dist/client/components/request-async-storage.external": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
1114
|
+
"next/dist/client/components/request-async-storage": path.join(shimsDir, "internal", "work-unit-async-storage"),
|
|
1115
|
+
"next/dist/server/request/root-params": path.join(shimsDir, "root-params"),
|
|
1116
|
+
"next/dist/server/config-shared": path.join(shimsDir, "internal", "utils"),
|
|
1117
|
+
"server-only": path.join(shimsDir, "server-only"),
|
|
1118
|
+
"client-only": path.join(shimsDir, "client-only"),
|
|
1119
|
+
"vinext/error-boundary": path.join(shimsDir, "error-boundary"),
|
|
1120
|
+
"vinext/layout-segment-context": path.join(shimsDir, "layout-segment-context"),
|
|
1121
|
+
"vinext/metadata": path.join(shimsDir, "metadata"),
|
|
1122
|
+
"vinext/fetch-cache": path.join(shimsDir, "fetch-cache"),
|
|
1123
|
+
"vinext/cache-runtime": path.join(shimsDir, "cache-runtime"),
|
|
1124
|
+
"vinext/navigation-state": path.join(shimsDir, "navigation-state"),
|
|
1125
|
+
"vinext/unified-request-context": path.join(shimsDir, "unified-request-context"),
|
|
1126
|
+
"vinext/pages-router-runtime": path.join(shimsDir, "pages-router-runtime"),
|
|
1127
|
+
"vinext/router-state": path.join(shimsDir, "router-state"),
|
|
1128
|
+
"vinext/head-state": path.join(shimsDir, "head-state"),
|
|
1129
|
+
"vinext/i18n-state": path.join(shimsDir, "i18n-state"),
|
|
1130
|
+
"vinext/i18n-context": path.join(shimsDir, "i18n-context"),
|
|
1088
1131
|
"vinext/cache": path.resolve(__dirname, "cache"),
|
|
1089
1132
|
"vinext/instrumentation": path.resolve(__dirname, "server", "instrumentation"),
|
|
1090
1133
|
"vinext/instrumentation-client": path.resolve(__dirname, "client", "instrumentation-client"),
|
|
@@ -1108,6 +1151,7 @@ function vinext(options = {}) {
|
|
|
1108
1151
|
const isSSR = !!config.build?.ssr;
|
|
1109
1152
|
const serverTranspilePackages = [...nextConfig?.turbopackTranspilePackages ?? [], ...nextConfig?.optimizePackageImports ?? []];
|
|
1110
1153
|
const nextServerExternal = mergeServerExternalPackages(nextConfig?.serverExternalPackages, serverTranspilePackages);
|
|
1154
|
+
nitroTraceDepsFromServerExternals = nextServerExternal;
|
|
1111
1155
|
const isMultiEnv = hasAppDir || hasCloudflarePlugin || hasNitroPlugin;
|
|
1112
1156
|
const hasBuildInput = getBuildBundlerOptions(config.build)?.input !== void 0;
|
|
1113
1157
|
const shouldInjectPlainPagesEnvironments = !hasAppDir && !hasCloudflarePlugin && !isSSR && !hasBuildInput;
|
|
@@ -1245,7 +1289,7 @@ function vinext(options = {}) {
|
|
|
1245
1289
|
if (hasAppDir) {
|
|
1246
1290
|
const appEntries = [`${path.relative(root, appDir)}/**/*.{tsx,ts,jsx,js}`];
|
|
1247
1291
|
const explicitInstrumentationEntries = [instrumentationPath, instrumentationClientPath].flatMap((entry) => entry ? [toRelativeFileEntry(root, entry)] : []);
|
|
1248
|
-
const optimizeEntries = [
|
|
1292
|
+
const optimizeEntries = [.../* @__PURE__ */ new Set([...appEntries, ...explicitInstrumentationEntries])];
|
|
1249
1293
|
const appClientInput = { index: VIRTUAL_APP_BROWSER_ENTRY };
|
|
1250
1294
|
if (hasPagesDir) appClientInput["vinext-client-entry"] = VIRTUAL_CLIENT_ENTRY;
|
|
1251
1295
|
viteConfig.environments = {
|
|
@@ -1263,7 +1307,7 @@ function vinext(options = {}) {
|
|
|
1263
1307
|
optimizeDeps: {
|
|
1264
1308
|
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE),
|
|
1265
1309
|
entries: optimizeEntries,
|
|
1266
|
-
include: [
|
|
1310
|
+
include: [.../* @__PURE__ */ new Set([...incomingInclude, "react-server-dom-webpack/static.edge"])],
|
|
1267
1311
|
...depOptimizeNodeEnvOptions
|
|
1268
1312
|
},
|
|
1269
1313
|
build: {
|
|
@@ -1298,7 +1342,7 @@ function vinext(options = {}) {
|
|
|
1298
1342
|
optimizeDeps: {
|
|
1299
1343
|
exclude: mergeOptimizeDepsExclude(incomingExclude, VINEXT_OPTIMIZE_DEPS_EXCLUDE, nextServerExternal),
|
|
1300
1344
|
entries: optimizeEntries,
|
|
1301
|
-
include: [
|
|
1345
|
+
include: [.../* @__PURE__ */ new Set([
|
|
1302
1346
|
...incomingInclude,
|
|
1303
1347
|
"react",
|
|
1304
1348
|
"react-dom",
|
|
@@ -1394,14 +1438,12 @@ function vinext(options = {}) {
|
|
|
1394
1438
|
config.optimizeDeps.exclude = mergeOptimizeDepsExclude(config.optimizeDeps.exclude ?? [], VINEXT_OPTIMIZE_DEPS_EXCLUDE, PAGES_CLOUDFLARE_WORKER_OPTIMIZE_DEPS_EXCLUDE);
|
|
1395
1439
|
}
|
|
1396
1440
|
const configuredExtensions = name === "client" ? nextConfig.resolveExtensions : nextConfig.serverResolveExtensions;
|
|
1397
|
-
const extensions = configuredExtensions === null ? buildViteResolveExtensions(
|
|
1441
|
+
const extensions = configuredExtensions === null ? buildViteResolveExtensions(config.resolve?.extensions) : normalizeViteResolveExtensions(configuredExtensions);
|
|
1398
1442
|
config.resolve ??= {};
|
|
1399
1443
|
config.resolve.extensions = extensions;
|
|
1400
1444
|
return null;
|
|
1401
1445
|
},
|
|
1402
1446
|
async configResolved(config) {
|
|
1403
|
-
const cacheDirPrefix = getCacheDirPrefix(config.cacheDir);
|
|
1404
|
-
typeofWindowIdFilter.exclude = new RegExp(`^${escapeRegExp(cacheDirPrefix)}`);
|
|
1405
1447
|
if (isServeCommand && hasCloudflarePlugin && hasPagesDir && !hasAppDir) suppressOptionalOptimizeDepsWarnings(config.logger);
|
|
1406
1448
|
sassComposesLoader.setResolvedConfig(config);
|
|
1407
1449
|
if (config.command === "build" && hasAppDir && hasPagesDir) {
|
|
@@ -1441,7 +1483,7 @@ function vinext(options = {}) {
|
|
|
1441
1483
|
resolveId: {
|
|
1442
1484
|
filter: { id: /(?:next\/|vinext\/(?:shims\/|server\/app-rsc-handler)|virtual:vinext-|@vercel\/og(?:\.js)?$)/ },
|
|
1443
1485
|
handler(id, importer) {
|
|
1444
|
-
const cleanId =
|
|
1486
|
+
const cleanId = toSlash(id.startsWith("\0") ? id.slice(1) : id);
|
|
1445
1487
|
if (cleanId === "vinext/server/app-rsc-handler") {
|
|
1446
1488
|
if (_canExternalizeAppRscHandler && this.environment?.name === "rsc" && this.environment.config?.command === "serve") return {
|
|
1447
1489
|
id: _appRscHandlerPath,
|
|
@@ -1473,7 +1515,10 @@ function vinext(options = {}) {
|
|
|
1473
1515
|
return RESOLVED_VIRTUAL_GOOGLE_FONTS + cleanId.slice(queryIndex + VIRTUAL_GOOGLE_FONTS.length);
|
|
1474
1516
|
}
|
|
1475
1517
|
const reactServerShim = _reactServerShims.get(cleanId);
|
|
1476
|
-
if (reactServerShim !== void 0)
|
|
1518
|
+
if (reactServerShim !== void 0) {
|
|
1519
|
+
const shimName = this.environment?.name === "rsc" ? `${reactServerShim}.react-server` : reactServerShim;
|
|
1520
|
+
return resolveShimModulePath(_shimsDir, shimName);
|
|
1521
|
+
}
|
|
1477
1522
|
}
|
|
1478
1523
|
},
|
|
1479
1524
|
load: {
|
|
@@ -1488,9 +1533,10 @@ function vinext(options = {}) {
|
|
|
1488
1533
|
const appFilePath = findFileWithExts(pagesDir, "_app", fileMatcher);
|
|
1489
1534
|
const pagesRoutes = await pagesRouter(pagesDir, nextConfig?.pageExtensions, fileMatcher);
|
|
1490
1535
|
const moduleFilePaths = [...appFilePath ? [appFilePath] : [], ...pagesRoutes.map((route) => route.filePath)];
|
|
1536
|
+
const getModuleDependencies = createDevPagesModuleDependencyReader(root, this.resolve.bind(this));
|
|
1491
1537
|
for (const moduleFilePath of moduleFilePaths) {
|
|
1492
|
-
const stylesheetAssets = await collectDevPagesAppStylesheetAssets(
|
|
1493
|
-
if (stylesheetAssets.length > 0) ssrManifest[
|
|
1538
|
+
const stylesheetAssets = await collectDevPagesAppStylesheetAssets(moduleFilePath, getModuleDependencies);
|
|
1539
|
+
if (stylesheetAssets.length > 0) ssrManifest[toSlash(moduleFilePath)] = stylesheetAssets;
|
|
1494
1540
|
}
|
|
1495
1541
|
if (Object.keys(ssrManifest).length > 0) metadata.ssrManifest = ssrManifest;
|
|
1496
1542
|
return `export default ${JSON.stringify(metadata)};`;
|
|
@@ -1606,13 +1652,13 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1606
1652
|
resolveId: {
|
|
1607
1653
|
filter: { id: /virtual:vinext-pages-client-assets$/ },
|
|
1608
1654
|
handler(id) {
|
|
1609
|
-
const cleanId =
|
|
1655
|
+
const cleanId = toSlash(id.startsWith("\0") ? id.slice(1) : id);
|
|
1610
1656
|
if (cleanId !== VIRTUAL_PAGES_CLIENT_ASSETS && !cleanId.endsWith("/virtual:vinext-pages-client-assets")) return;
|
|
1611
1657
|
if (this.environment?.config.command !== "build") return RESOLVED_PAGES_CLIENT_ASSETS;
|
|
1612
1658
|
const buildRoot = this.environment.config.root ?? process.cwd();
|
|
1613
1659
|
const environmentOutDir = path.resolve(buildRoot, this.environment.config.build.outDir);
|
|
1614
1660
|
const sidecarDir = !hasAppDir && this.environment.name === "ssr" ? path.dirname(environmentOutDir) : environmentOutDir;
|
|
1615
|
-
let externalId =
|
|
1661
|
+
let externalId = path.relative(environmentOutDir, path.join(sidecarDir, PAGES_CLIENT_ASSETS_MODULE));
|
|
1616
1662
|
if (!externalId.startsWith(".")) externalId = `./${externalId}`;
|
|
1617
1663
|
pagesClientAssetsOutputDirs.add(sidecarDir);
|
|
1618
1664
|
return {
|
|
@@ -1715,29 +1761,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1715
1761
|
}
|
|
1716
1762
|
},
|
|
1717
1763
|
...options.experimental?.clientReferenceDedup ? [clientReferenceDedupPlugin()] : [],
|
|
1718
|
-
|
|
1719
|
-
name: "vinext:mdx",
|
|
1720
|
-
enforce: "pre",
|
|
1721
|
-
config(config, env) {
|
|
1722
|
-
if (!mdxDelegate?.config) return;
|
|
1723
|
-
const hook = mdxDelegate.config;
|
|
1724
|
-
return (typeof hook === "function" ? hook : hook.handler).call(this, config, env);
|
|
1725
|
-
},
|
|
1726
|
-
transform: {
|
|
1727
|
-
filter: { id: {
|
|
1728
|
-
include: /\.mdx$/i,
|
|
1729
|
-
exclude: /\?/
|
|
1730
|
-
} },
|
|
1731
|
-
async handler(code, id, options) {
|
|
1732
|
-
const delegate = mdxDelegate ?? await ensureMdxDelegate("on-demand");
|
|
1733
|
-
if (delegate?.transform) {
|
|
1734
|
-
const hook = delegate.transform;
|
|
1735
|
-
return (typeof hook === "function" ? hook : hook.handler).call(this, code, id, options);
|
|
1736
|
-
}
|
|
1737
|
-
if (!hasUserMdxPlugin) throw new Error(`[vinext] Encountered MDX module ${id} but no MDX plugin is configured. Install @mdx-js/rollup or register an MDX plugin manually.`);
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
},
|
|
1764
|
+
mdxConfigProxyPlugin,
|
|
1741
1765
|
createCssModuleImportCompatibilityPlugin({ compiledMdx: true }),
|
|
1742
1766
|
{
|
|
1743
1767
|
name: "vinext:react-canary",
|
|
@@ -1778,39 +1802,42 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1778
1802
|
},
|
|
1779
1803
|
{
|
|
1780
1804
|
name: "vinext:pages-router",
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
const
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
return [];
|
|
1805
|
+
// @vitejs/plugin-react to handle normal module updates. Next.js preserves
|
|
1806
|
+
hotUpdate: {
|
|
1807
|
+
order: "post",
|
|
1808
|
+
handler(options) {
|
|
1809
|
+
if (!hasPagesDir) return;
|
|
1810
|
+
const isPagesAppFile = (filePath) => {
|
|
1811
|
+
const relativePath = path.relative(pagesDir, filePath);
|
|
1812
|
+
return !relativePath.includes("/") && relativePath.startsWith("_app.") && fileMatcher.extensionRegex.test(filePath);
|
|
1813
|
+
};
|
|
1814
|
+
const isPotentialPagesAssetGraphScript = (filePath) => {
|
|
1815
|
+
const cleanPath = stripViteModuleQuery(filePath);
|
|
1816
|
+
if (!path.isAbsolute(cleanPath)) return false;
|
|
1817
|
+
if (!isScriptModuleId(cleanPath) || cleanPath.endsWith(".d.ts")) return false;
|
|
1818
|
+
const relativeRootPath = path.relative(root, cleanPath);
|
|
1819
|
+
if (relativeRootPath.startsWith("..") || path.isAbsolute(relativeRootPath)) return false;
|
|
1820
|
+
if (relativeRootPath.includes("/node_modules/") || relativeRootPath.startsWith("node_modules/")) return false;
|
|
1821
|
+
const relativeAppPath = path.relative(appDir, cleanPath);
|
|
1822
|
+
return relativeAppPath.startsWith("..") || path.isAbsolute(relativeAppPath);
|
|
1823
|
+
};
|
|
1824
|
+
const pagesAppChanged = isPagesAppFile(options.file);
|
|
1825
|
+
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(options.file);
|
|
1826
|
+
if (pagesAppChanged || STYLESHEET_FILE_RE.test(options.file) || pagesAssetGraphScriptChanged) for (const env of Object.values(options.server.environments)) {
|
|
1827
|
+
const mod = env.moduleGraph.getModuleById(RESOLVED_PAGES_CLIENT_ASSETS);
|
|
1828
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1829
|
+
}
|
|
1830
|
+
if (this.environment?.name === "ssr" && pagesAssetGraphScriptChanged) {
|
|
1831
|
+
for (const mod of options.modules) this.environment.moduleGraph.invalidateModule(mod, /* @__PURE__ */ new Set(), options.timestamp, true);
|
|
1832
|
+
return [];
|
|
1833
|
+
}
|
|
1811
1834
|
}
|
|
1812
1835
|
},
|
|
1813
1836
|
configureServer(server) {
|
|
1837
|
+
server.middlewares.use((req, _res, next) => {
|
|
1838
|
+
req.__vinextOriginalEncodedUrl ??= req.url;
|
|
1839
|
+
next();
|
|
1840
|
+
});
|
|
1814
1841
|
const pageExtensions = fileMatcher.extensionRegex;
|
|
1815
1842
|
let pagesRunner = null;
|
|
1816
1843
|
let cachedSSRHandler = null;
|
|
@@ -1857,13 +1884,12 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1857
1884
|
}
|
|
1858
1885
|
pagesRunner?.clearCache();
|
|
1859
1886
|
}
|
|
1860
|
-
function invalidatePagesClientAssetsModule(
|
|
1887
|
+
function invalidatePagesClientAssetsModule() {
|
|
1861
1888
|
for (const env of Object.values(server.environments)) {
|
|
1862
1889
|
const mod = env.moduleGraph.getModuleById(RESOLVED_PAGES_CLIENT_ASSETS);
|
|
1863
1890
|
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
1864
1891
|
}
|
|
1865
1892
|
pagesRunner?.clearCache();
|
|
1866
|
-
if (reloadDocument) server.ws.send({ type: "full-reload" });
|
|
1867
1893
|
}
|
|
1868
1894
|
function invalidateAppRoutingModules() {
|
|
1869
1895
|
invalidateAppRouteCache();
|
|
@@ -1913,17 +1939,17 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1913
1939
|
let appRouteTypeGeneration = null;
|
|
1914
1940
|
let appRouteTypeGenerationPending = false;
|
|
1915
1941
|
function isPagesAppFile(filePath) {
|
|
1916
|
-
const relativePath =
|
|
1942
|
+
const relativePath = path.relative(pagesDir, filePath);
|
|
1917
1943
|
return !relativePath.includes("/") && relativePath.startsWith("_app.") && fileMatcher.extensionRegex.test(filePath);
|
|
1918
1944
|
}
|
|
1919
1945
|
function isPotentialPagesAssetGraphScript(filePath) {
|
|
1920
1946
|
const cleanPath = stripViteModuleQuery(filePath);
|
|
1921
1947
|
if (!path.isAbsolute(cleanPath)) return false;
|
|
1922
1948
|
if (!isScriptModuleId(cleanPath) || cleanPath.endsWith(".d.ts")) return false;
|
|
1923
|
-
const relativeRootPath =
|
|
1949
|
+
const relativeRootPath = path.relative(root, cleanPath);
|
|
1924
1950
|
if (relativeRootPath.startsWith("..") || path.isAbsolute(relativeRootPath)) return false;
|
|
1925
1951
|
if (relativeRootPath.includes("/node_modules/") || relativeRootPath.startsWith("node_modules/")) return false;
|
|
1926
|
-
const relativeAppPath =
|
|
1952
|
+
const relativeAppPath = path.relative(appDir, cleanPath);
|
|
1927
1953
|
return relativeAppPath.startsWith("..") || path.isAbsolute(relativeAppPath);
|
|
1928
1954
|
}
|
|
1929
1955
|
function warnRouteTypeGenerationFailure(error) {
|
|
@@ -1956,8 +1982,8 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1956
1982
|
let routeChanged = false;
|
|
1957
1983
|
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1958
1984
|
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1959
|
-
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(
|
|
1960
|
-
if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1985
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
|
|
1986
|
+
if (hasPagesDir && toSlash(filePath).startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1961
1987
|
invalidateRouteCache(pagesDir);
|
|
1962
1988
|
routeChanged = true;
|
|
1963
1989
|
}
|
|
@@ -1968,6 +1994,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1968
1994
|
}
|
|
1969
1995
|
if (routeChanged) {
|
|
1970
1996
|
invalidatePagesServerEntry();
|
|
1997
|
+
if (!hasAppDir) server.ws.send({ type: "full-reload" });
|
|
1971
1998
|
invalidateHybridClientEntries();
|
|
1972
1999
|
revalidateHybridRoutes();
|
|
1973
2000
|
}
|
|
@@ -1975,14 +2002,14 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1975
2002
|
server.watcher.on("change", (filePath) => {
|
|
1976
2003
|
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1977
2004
|
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1978
|
-
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(
|
|
2005
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
|
|
1979
2006
|
});
|
|
1980
2007
|
server.watcher.on("unlink", (filePath) => {
|
|
1981
2008
|
let routeChanged = false;
|
|
1982
2009
|
const pagesAppChanged = isPagesAppFile(filePath);
|
|
1983
2010
|
const pagesAssetGraphScriptChanged = isPotentialPagesAssetGraphScript(filePath);
|
|
1984
|
-
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule(
|
|
1985
|
-
if (hasPagesDir && filePath.startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
2011
|
+
if (hasPagesDir && (pagesAppChanged || STYLESHEET_FILE_RE.test(filePath) || pagesAssetGraphScriptChanged)) invalidatePagesClientAssetsModule();
|
|
2012
|
+
if (hasPagesDir && toSlash(filePath).startsWith(pagesDir) && pageExtensions.test(filePath)) {
|
|
1986
2013
|
invalidateRouteCache(pagesDir);
|
|
1987
2014
|
routeChanged = true;
|
|
1988
2015
|
}
|
|
@@ -1993,6 +2020,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
1993
2020
|
}
|
|
1994
2021
|
if (routeChanged) {
|
|
1995
2022
|
invalidatePagesServerEntry();
|
|
2023
|
+
if (!hasAppDir) server.ws.send({ type: "full-reload" });
|
|
1996
2024
|
invalidateHybridClientEntries();
|
|
1997
2025
|
revalidateHybridRoutes();
|
|
1998
2026
|
}
|
|
@@ -2147,9 +2175,25 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2147
2175
|
res.end();
|
|
2148
2176
|
return;
|
|
2149
2177
|
}
|
|
2178
|
+
const originalEncodedUrl = req.__vinextOriginalEncodedUrl ?? url;
|
|
2179
|
+
const originalEncodedPathname = originalEncodedUrl.split("?")[0];
|
|
2180
|
+
if (isOpenRedirectShaped(originalEncodedPathname)) {
|
|
2181
|
+
res.writeHead(404);
|
|
2182
|
+
res.end("This page could not be found");
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
const canonicalOriginalUrl = canonicalizeRequestUrlPathname(originalEncodedUrl);
|
|
2186
|
+
url = canonicalizeRequestUrlPathname(url);
|
|
2150
2187
|
const rawPathname = url.split("?")[0];
|
|
2151
2188
|
if (rawPathname.endsWith("/index.html")) url = url.replace("/index.html", "/");
|
|
2152
2189
|
else if (rawPathname.endsWith(".html")) url = url.replace(/\.html(?=\?|$)/, "");
|
|
2190
|
+
let middlewareUrl = canonicalOriginalUrl;
|
|
2191
|
+
let routeUrl = middlewareUrl;
|
|
2192
|
+
{
|
|
2193
|
+
const routePathname = routeUrl.split("?")[0];
|
|
2194
|
+
if (routePathname.endsWith("/index.html")) routeUrl = routeUrl.replace("/index.html", "/");
|
|
2195
|
+
else if (routePathname.endsWith(".html")) routeUrl = routeUrl.replace(/\.html(?=\?|$)/, "");
|
|
2196
|
+
}
|
|
2153
2197
|
let pathname = url.split("?")[0];
|
|
2154
2198
|
if (isOpenRedirectShaped(pathname)) {
|
|
2155
2199
|
res.writeHead(404);
|
|
@@ -2164,20 +2208,42 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2164
2208
|
res.end("Bad Request");
|
|
2165
2209
|
return;
|
|
2166
2210
|
}
|
|
2211
|
+
if (urlParserCreatesPagesDataPath(pathname)) {
|
|
2212
|
+
res.writeHead(404);
|
|
2213
|
+
res.end("This page could not be found");
|
|
2214
|
+
return;
|
|
2215
|
+
}
|
|
2216
|
+
pathname = encodeUrlParserIgnoredCharacters(pathname);
|
|
2167
2217
|
{
|
|
2168
2218
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
2169
2219
|
url = pathname + qs;
|
|
2170
2220
|
}
|
|
2171
2221
|
const capturedMiddlewarePath = middlewarePath;
|
|
2172
2222
|
const bp = nextConfig?.basePath ?? "";
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2223
|
+
const viteBase = server.config.base;
|
|
2224
|
+
const viteBasePath = viteBase.startsWith("/") && viteBase !== "/" ? viteBase.replace(/\/+$/, "") : "";
|
|
2225
|
+
const routingBasePath = bp || viteBasePath;
|
|
2226
|
+
if (routingBasePath) {
|
|
2227
|
+
if (hasBasePath(pathname, routingBasePath)) {
|
|
2228
|
+
const stripped = stripBasePath(pathname, routingBasePath);
|
|
2229
|
+
url = stripped + (url.includes("?") ? url.slice(url.indexOf("?")) : "");
|
|
2230
|
+
pathname = stripped;
|
|
2231
|
+
}
|
|
2232
|
+
const middlewarePathname = middlewareUrl.split("?")[0];
|
|
2233
|
+
if (hasBasePath(middlewarePathname, routingBasePath)) {
|
|
2234
|
+
const middlewareQs = middlewareUrl.includes("?") ? middlewareUrl.slice(middlewareUrl.indexOf("?")) : "";
|
|
2235
|
+
middlewareUrl = stripBasePath(middlewarePathname, routingBasePath) + middlewareQs;
|
|
2236
|
+
}
|
|
2237
|
+
const routePathname = routeUrl.split("?")[0];
|
|
2238
|
+
if (hasBasePath(routePathname, routingBasePath)) {
|
|
2239
|
+
const routeQs = routeUrl.includes("?") ? routeUrl.slice(routeUrl.indexOf("?")) : "";
|
|
2240
|
+
routeUrl = stripBasePath(routePathname, routingBasePath) + routeQs;
|
|
2241
|
+
}
|
|
2177
2242
|
}
|
|
2243
|
+
let configMatchPathname = stripBasePath(middlewareUrl.split("?")[0], routingBasePath);
|
|
2178
2244
|
if (nextConfig) {
|
|
2179
2245
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
2180
|
-
const trailingSlashRedirect = normalizeTrailingSlash(
|
|
2246
|
+
const trailingSlashRedirect = normalizeTrailingSlash(routeUrl.split("?")[0], bp, nextConfig.trailingSlash, qs);
|
|
2181
2247
|
if (trailingSlashRedirect) {
|
|
2182
2248
|
const location = trailingSlashRedirect.headers.get("Location");
|
|
2183
2249
|
res.writeHead(trailingSlashRedirect.status, location ? { Location: location } : void 0);
|
|
@@ -2195,7 +2261,10 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2195
2261
|
const qs = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
2196
2262
|
const pagePathname = normalizeNextDataPagePathname(dataMatch.pagePathname, capturedMiddlewarePath !== null && nextConfig?.trailingSlash === true);
|
|
2197
2263
|
url = pagePathname + qs;
|
|
2264
|
+
middlewareUrl = url;
|
|
2265
|
+
routeUrl = url;
|
|
2198
2266
|
pathname = pagePathname;
|
|
2267
|
+
configMatchPathname = pagePathname;
|
|
2199
2268
|
req.url = url;
|
|
2200
2269
|
} else {
|
|
2201
2270
|
const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
|
|
@@ -2230,7 +2299,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2230
2299
|
for (const header of INTERNAL_HEADERS) delete req.headers[header];
|
|
2231
2300
|
for (const header of VINEXT_INTERNAL_HEADERS) delete req.headers[header];
|
|
2232
2301
|
const method = req.method ?? "GET";
|
|
2233
|
-
const webRequest = new Request(new URL(
|
|
2302
|
+
const webRequest = new Request(new URL(routeUrl, requestOrigin), {
|
|
2234
2303
|
method,
|
|
2235
2304
|
headers: nodeRequestHeaders
|
|
2236
2305
|
});
|
|
@@ -2241,11 +2310,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2241
2310
|
const devRunMiddlewareAdapter = capturedMiddlewarePath ? async (_request, _ctx, opts) => {
|
|
2242
2311
|
const rawProto = process.env.VINEXT_TRUST_PROXY === "1" || (process.env.VINEXT_TRUSTED_HOSTS ?? "").split(",").some((h) => h.trim()) ? String(req.headers["x-forwarded-proto"] || "").split(",")[0].trim() : "";
|
|
2243
2312
|
const mwOrigin = `${rawProto === "https" || rawProto === "http" ? rawProto : "http"}://${requestHost}`;
|
|
2244
|
-
const middlewareRequest = new Request(new URL(
|
|
2313
|
+
const middlewareRequest = new Request(new URL(middlewareUrl, mwOrigin), {
|
|
2245
2314
|
method: req.method,
|
|
2246
2315
|
headers: nodeRequestHeaders
|
|
2247
2316
|
});
|
|
2248
|
-
const result = await runMiddleware(getPagesRunner(), capturedMiddlewarePath, middlewareRequest, nextConfig?.i18n, nextConfig?.basePath, nextConfig?.trailingSlash, opts.isDataRequest);
|
|
2317
|
+
const result = await runMiddleware(getPagesRunner(), capturedMiddlewarePath, middlewareRequest, nextConfig?.i18n, nextConfig?.basePath, nextConfig?.trailingSlash, opts.isDataRequest, pathname);
|
|
2249
2318
|
if (hasAppDir && result.continue) {
|
|
2250
2319
|
const mwCtxEntries = [];
|
|
2251
2320
|
if (result.responseHeaders) {
|
|
@@ -2289,6 +2358,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2289
2358
|
isDataRequest,
|
|
2290
2359
|
hasMiddleware: capturedMiddlewarePath !== null,
|
|
2291
2360
|
rawSearch: url.includes("?") ? url.slice(url.indexOf("?")) : "",
|
|
2361
|
+
configMatchPathname,
|
|
2292
2362
|
runMiddleware: devRunMiddlewareAdapter,
|
|
2293
2363
|
matchPageRoute: (resolvedPathname, request) => {
|
|
2294
2364
|
const m = matchRoute(nextConfig?.i18n ? resolvePagesI18nRequest(resolvedPathname, nextConfig.i18n, request.headers, getUrlHostname(request.url), bp, nextConfig.trailingSlash ?? false).url : resolvedPathname, devPageRoutes);
|
|
@@ -2474,15 +2544,23 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2474
2544
|
},
|
|
2475
2545
|
{
|
|
2476
2546
|
name: "vinext:typeof-window",
|
|
2547
|
+
configEnvironment(_name, environment) {
|
|
2548
|
+
if (!useNativeTypeofWindowFolding) return null;
|
|
2549
|
+
return { define: { "typeof window": environment.consumer === "client" ? "\"object\"" : "\"undefined\"" } };
|
|
2550
|
+
}
|
|
2551
|
+
},
|
|
2552
|
+
{
|
|
2553
|
+
name: "vinext:typeof-window-scan",
|
|
2554
|
+
apply(_config, environment) {
|
|
2555
|
+
return !useNativeTypeofWindowFolding || environment.command === "build";
|
|
2556
|
+
},
|
|
2477
2557
|
enforce: "post",
|
|
2478
2558
|
transform: {
|
|
2479
|
-
filter: {
|
|
2480
|
-
id: typeofWindowIdFilter,
|
|
2481
|
-
code: /typeof\s+window/
|
|
2482
|
-
},
|
|
2559
|
+
filter: { code: /\btypeof\s+window\b/ },
|
|
2483
2560
|
handler(code, id) {
|
|
2484
|
-
|
|
2485
|
-
|
|
2561
|
+
if (useNativeTypeofWindowFolding && this.environment.config.build.write !== false) return null;
|
|
2562
|
+
const cacheDir = `${toSlash(this.environment.config.cacheDir).replace(/\/$/, "")}/`;
|
|
2563
|
+
if (toSlash(id).startsWith(cacheDir)) return null;
|
|
2486
2564
|
return replaceTypeofWindow(code, getTypeofWindowReplacement(this.environment), id);
|
|
2487
2565
|
}
|
|
2488
2566
|
}
|
|
@@ -2495,6 +2573,11 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2495
2573
|
serverDefines["process.env.NEXT_RUNTIME"] = JSON.stringify("nodejs");
|
|
2496
2574
|
const sharedRevalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
|
|
2497
2575
|
if (sharedRevalidateSecret) serverDefines["process.env.__VINEXT_REVALIDATE_SECRET"] = JSON.stringify(sharedRevalidateSecret);
|
|
2576
|
+
if (previewBuildCredentials) {
|
|
2577
|
+
serverDefines["process.env.__VINEXT_PREVIEW_MODE_ID"] = JSON.stringify(previewBuildCredentials.id);
|
|
2578
|
+
serverDefines["process.env.__VINEXT_PREVIEW_MODE_SIGNING_KEY"] = JSON.stringify(previewBuildCredentials.signingKey);
|
|
2579
|
+
serverDefines["process.env.__VINEXT_PREVIEW_MODE_ENCRYPTION_KEY"] = JSON.stringify(previewBuildCredentials.encryptionKey);
|
|
2580
|
+
}
|
|
2498
2581
|
return { define: serverDefines };
|
|
2499
2582
|
}
|
|
2500
2583
|
},
|
|
@@ -2519,7 +2602,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2519
2602
|
staticImageAssets.clear();
|
|
2520
2603
|
},
|
|
2521
2604
|
watchChange(id) {
|
|
2522
|
-
const key =
|
|
2605
|
+
const key = toSlash(id);
|
|
2523
2606
|
imageImportDimCache.delete(key);
|
|
2524
2607
|
staticImageAssets.delete(key);
|
|
2525
2608
|
staticImageImportsByModule.delete(key);
|
|
@@ -2597,7 +2680,7 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2597
2680
|
const dir = path.dirname(id);
|
|
2598
2681
|
const resolvedImage = importPath.startsWith(".") ? path.resolve(dir, importPath) : (await this.resolve(importPath, id, { skipSelf: true }))?.id;
|
|
2599
2682
|
if (!resolvedImage) continue;
|
|
2600
|
-
const absImagePath =
|
|
2683
|
+
const absImagePath = toSlash(resolvedImage.split("?", 1)[0]);
|
|
2601
2684
|
if (!fs.existsSync(absImagePath)) continue;
|
|
2602
2685
|
imageImports.add(absImagePath);
|
|
2603
2686
|
const urlVar = `__vinext_img_url_${varName}`;
|
|
@@ -2800,9 +2883,10 @@ export const loadServerActionClient = ${hasServerActions ? `() => import(${JSON.
|
|
|
2800
2883
|
{
|
|
2801
2884
|
name: "vinext:nitro-route-rules",
|
|
2802
2885
|
nitro: { setup: async (nitro) => {
|
|
2803
|
-
if (nitro.options.dev) return;
|
|
2804
2886
|
if (!nextConfig) return;
|
|
2805
2887
|
if (!hasAppDir && !hasPagesDir) return;
|
|
2888
|
+
if (nitroTraceDepsFromServerExternals.length > 0) nitro.options.traceDeps = [.../* @__PURE__ */ new Set([...nitro.options.traceDeps ?? [], ...nitroTraceDepsFromServerExternals])];
|
|
2889
|
+
if (nitro.options.dev) return;
|
|
2806
2890
|
const { collectNitroRouteRules, mergeNitroRouteRules } = await import("./build/nitro-route-rules.js");
|
|
2807
2891
|
const generatedRouteRules = await collectNitroRouteRules({
|
|
2808
2892
|
appDir: hasAppDir ? appDir : null,
|