vinext 0.1.1 → 0.1.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.
Files changed (147) hide show
  1. package/README.md +2 -5
  2. package/dist/build/client-build-config.d.ts +7 -1
  3. package/dist/build/client-build-config.js +9 -1
  4. package/dist/check.js +4 -3
  5. package/dist/client/navigation-runtime.d.ts +3 -2
  6. package/dist/client/window-next.d.ts +6 -4
  7. package/dist/config/config-matchers.d.ts +11 -4
  8. package/dist/config/config-matchers.js +15 -2
  9. package/dist/config/next-config.d.ts +13 -0
  10. package/dist/config/next-config.js +2 -0
  11. package/dist/deploy.js +9 -2
  12. package/dist/entries/app-rsc-entry.js +7 -1
  13. package/dist/entries/pages-client-entry.js +1 -1
  14. package/dist/entries/pages-server-entry.js +7 -6
  15. package/dist/index.d.ts +0 -2
  16. package/dist/index.js +86 -78
  17. package/dist/plugins/dynamic-preload-metadata.d.ts +13 -0
  18. package/dist/plugins/dynamic-preload-metadata.js +415 -0
  19. package/dist/plugins/og-assets.js +2 -2
  20. package/dist/plugins/optimize-imports.d.ts +8 -4
  21. package/dist/plugins/optimize-imports.js +16 -12
  22. package/dist/plugins/sass.d.ts +53 -24
  23. package/dist/plugins/sass.js +249 -1
  24. package/dist/plugins/wasm-module-import.d.ts +15 -0
  25. package/dist/plugins/wasm-module-import.js +50 -0
  26. package/dist/routing/app-route-graph.d.ts +23 -1
  27. package/dist/routing/app-route-graph.js +47 -8
  28. package/dist/routing/file-matcher.js +1 -1
  29. package/dist/server/app-browser-entry.js +108 -213
  30. package/dist/server/app-browser-error.d.ts +4 -1
  31. package/dist/server/app-browser-error.js +7 -1
  32. package/dist/server/app-browser-history-controller.d.ts +104 -0
  33. package/dist/server/app-browser-history-controller.js +210 -0
  34. package/dist/server/app-browser-navigation-controller.d.ts +3 -2
  35. package/dist/server/app-browser-navigation-controller.js +10 -7
  36. package/dist/server/app-browser-rsc-redirect.d.ts +11 -2
  37. package/dist/server/app-browser-rsc-redirect.js +30 -8
  38. package/dist/server/app-browser-state.js +4 -7
  39. package/dist/server/app-browser-visible-commit.js +1 -1
  40. package/dist/server/app-fallback-renderer.d.ts +2 -1
  41. package/dist/server/app-fallback-renderer.js +3 -1
  42. package/dist/server/app-middleware.js +1 -0
  43. package/dist/server/app-optimistic-routing.js +22 -1
  44. package/dist/server/app-page-boundary-render.d.ts +2 -1
  45. package/dist/server/app-page-boundary-render.js +4 -2
  46. package/dist/server/app-page-cache.js +9 -7
  47. package/dist/server/app-page-dispatch.d.ts +8 -0
  48. package/dist/server/app-page-dispatch.js +18 -5
  49. package/dist/server/app-page-element-builder.d.ts +22 -2
  50. package/dist/server/app-page-element-builder.js +37 -8
  51. package/dist/server/app-page-execution.d.ts +1 -1
  52. package/dist/server/app-page-execution.js +32 -17
  53. package/dist/server/app-page-render.d.ts +1 -1
  54. package/dist/server/app-page-render.js +7 -14
  55. package/dist/server/app-page-request.d.ts +1 -0
  56. package/dist/server/app-page-request.js +3 -2
  57. package/dist/server/app-page-response.js +1 -1
  58. package/dist/server/app-page-route-wiring.d.ts +3 -1
  59. package/dist/server/app-page-route-wiring.js +8 -7
  60. package/dist/server/app-page-stream.d.ts +1 -6
  61. package/dist/server/app-page-stream.js +1 -4
  62. package/dist/server/app-route-handler-response.js +11 -10
  63. package/dist/server/app-route-handler-runtime.js +12 -1
  64. package/dist/server/app-rsc-handler.js +1 -1
  65. package/dist/server/app-rsc-response-finalizer.js +1 -1
  66. package/dist/server/app-server-action-execution.d.ts +11 -0
  67. package/dist/server/app-server-action-execution.js +5 -2
  68. package/dist/server/app-ssr-entry.js +2 -2
  69. package/dist/server/app-ssr-stream.js +9 -1
  70. package/dist/server/dev-lockfile.js +2 -1
  71. package/dist/server/dev-server.js +43 -12
  72. package/dist/server/headers.d.ts +8 -1
  73. package/dist/server/headers.js +8 -1
  74. package/dist/server/instrumentation-runtime.d.ts +6 -0
  75. package/dist/server/instrumentation-runtime.js +8 -0
  76. package/dist/server/isr-decision.d.ts +79 -0
  77. package/dist/server/isr-decision.js +70 -0
  78. package/dist/server/metadata-route-response.js +5 -3
  79. package/dist/server/middleware-runtime.d.ts +13 -0
  80. package/dist/server/middleware-runtime.js +11 -7
  81. package/dist/server/middleware.js +1 -0
  82. package/dist/server/navigation-planner.d.ts +62 -1
  83. package/dist/server/navigation-planner.js +188 -0
  84. package/dist/server/navigation-trace.d.ts +11 -1
  85. package/dist/server/navigation-trace.js +11 -1
  86. package/dist/server/normalize-path.d.ts +0 -8
  87. package/dist/server/normalize-path.js +3 -1
  88. package/dist/server/otel-tracer-extension.d.ts +45 -0
  89. package/dist/server/otel-tracer-extension.js +89 -0
  90. package/dist/server/pages-api-route.d.ts +14 -3
  91. package/dist/server/pages-api-route.js +6 -1
  92. package/dist/server/pages-asset-tags.d.ts +15 -4
  93. package/dist/server/pages-asset-tags.js +18 -12
  94. package/dist/server/pages-data-route.js +5 -1
  95. package/dist/server/pages-node-compat.d.ts +3 -11
  96. package/dist/server/pages-node-compat.js +174 -121
  97. package/dist/server/pages-page-data.d.ts +28 -0
  98. package/dist/server/pages-page-data.js +61 -17
  99. package/dist/server/pages-page-handler.d.ts +1 -0
  100. package/dist/server/pages-page-handler.js +22 -6
  101. package/dist/server/pages-page-response.d.ts +45 -1
  102. package/dist/server/pages-page-response.js +66 -5
  103. package/dist/server/pages-readiness.d.ts +1 -1
  104. package/dist/server/pages-request-pipeline.d.ts +15 -1
  105. package/dist/server/pages-request-pipeline.js +23 -2
  106. package/dist/server/prod-server.d.ts +39 -1
  107. package/dist/server/prod-server.js +98 -34
  108. package/dist/shims/cache-runtime.js +9 -2
  109. package/dist/shims/dynamic-preload-chunks.d.ts +8 -0
  110. package/dist/shims/dynamic-preload-chunks.js +77 -0
  111. package/dist/shims/dynamic.d.ts +4 -0
  112. package/dist/shims/dynamic.js +4 -2
  113. package/dist/shims/error-boundary.d.ts +4 -4
  114. package/dist/shims/error.js +37 -11
  115. package/dist/shims/fetch-cache.d.ts +9 -1
  116. package/dist/shims/fetch-cache.js +11 -1
  117. package/dist/shims/head.js +6 -1
  118. package/dist/shims/headers.d.ts +16 -2
  119. package/dist/shims/headers.js +37 -1
  120. package/dist/shims/image-config.js +7 -1
  121. package/dist/shims/internal/app-route-detection.d.ts +6 -3
  122. package/dist/shims/internal/app-route-detection.js +10 -6
  123. package/dist/shims/internal/app-router-context.d.ts +5 -0
  124. package/dist/shims/metadata.d.ts +6 -2
  125. package/dist/shims/metadata.js +32 -14
  126. package/dist/shims/navigation.d.ts +7 -16
  127. package/dist/shims/navigation.js +33 -16
  128. package/dist/shims/router.js +28 -1
  129. package/dist/shims/script-nonce-context.d.ts +1 -1
  130. package/dist/shims/script-nonce-context.js +11 -3
  131. package/dist/shims/server.d.ts +17 -1
  132. package/dist/shims/server.js +31 -6
  133. package/dist/shims/slot.js +1 -1
  134. package/dist/shims/unified-request-context.js +1 -0
  135. package/dist/typegen.js +1 -0
  136. package/dist/utils/client-build-manifest.js +15 -5
  137. package/dist/utils/client-runtime-metadata.d.ts +45 -0
  138. package/dist/utils/client-runtime-metadata.js +63 -0
  139. package/dist/utils/hash.d.ts +17 -1
  140. package/dist/utils/hash.js +36 -1
  141. package/dist/utils/lazy-chunks.d.ts +27 -1
  142. package/dist/utils/lazy-chunks.js +65 -1
  143. package/dist/utils/manifest-paths.d.ts +20 -2
  144. package/dist/utils/manifest-paths.js +38 -3
  145. package/dist/utils/path.d.ts +2 -1
  146. package/dist/utils/path.js +5 -1
  147. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { detectPackageManager } from "./utils/project.js";
2
+ import { normalizePathSeparators, stripViteModuleQuery } from "./utils/path.js";
2
3
  import { normalizePathnameForRouteMatchStrict } from "./routing/utils.js";
3
4
  import { buildViteResolveExtensions, createValidFileMatcher, findFileWithExts } from "./routing/file-matcher.js";
4
5
  import { apiRouter, invalidateRouteCache, matchRoute, pagesRouter } from "./routing/pages-router.js";
5
- import { normalizePathSeparators } from "./utils/path.js";
6
- import { INTERNAL_HEADERS, VINEXT_INTERNAL_HEADERS, VINEXT_MW_CTX_HEADER, VINEXT_TIMING_HEADER } from "./server/headers.js";
6
+ import { INTERNAL_HEADERS, NEXTJS_DEPLOYMENT_ID_HEADER, VINEXT_INTERNAL_HEADERS, VINEXT_MW_CTX_HEADER, VINEXT_TIMING_HEADER } from "./server/headers.js";
7
7
  import { normalizePath as normalizePath$1 } from "./server/normalize-path.js";
8
8
  import { proxyExternalRequest } from "./config/config-matchers.js";
9
9
  import { filterInternalHeaders, isOpenRedirectShaped, normalizeTrailingSlash } from "./server/request-pipeline.js";
@@ -40,7 +40,6 @@ import { emitNextClientRuntimeManifests } from "./build/next-client-runtime-mani
40
40
  import { collectInlineCssManifest, injectInlineCssManifestGlobal } from "./build/inline-css.js";
41
41
  import { installDevStackSourcemapMiddleware } from "./server/dev-stack-sourcemap.js";
42
42
  import { runPagesRequest } from "./server/pages-request-pipeline.js";
43
- import { manifestFilesWithBase } from "./utils/manifest-paths.js";
44
43
  import { asyncHooksStubPlugin } from "./plugins/async-hooks-stub.js";
45
44
  import { clientReferenceDedupPlugin } from "./plugins/client-reference-dedup.js";
46
45
  import { dataUrlCssPlugin } from "./plugins/css-data-url.js";
@@ -49,23 +48,24 @@ import { createInstrumentationClientTransformPlugin } from "./plugins/instrument
49
48
  import { INSTRUMENTATION_CLIENT_EMPTY_MODULE, generateInstrumentationClientInjectModule } from "./client/instrumentation-client-inject.js";
50
49
  import { createMiddlewareServerOnlyPlugin } from "./plugins/middleware-server-only.js";
51
50
  import { createOptimizeImportsPlugin } from "./plugins/optimize-imports.js";
51
+ import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
52
+ import { createDynamicPreloadMetadataPlugin } from "./plugins/dynamic-preload-metadata.js";
52
53
  import { createOgAssetsPlugin, createOgInlineFetchAssetsPlugin } from "./plugins/og-assets.js";
53
54
  import { generateRouteTypes } from "./typegen.js";
54
55
  import { SSR_EXTERNAL_REACT_ENTRIES, VINEXT_OPTIMIZE_DEPS_EXCLUDE, mergeOptimizeDepsExclude } from "./plugins/rsc-client-shim-excludes.js";
55
56
  import { createServerExternalsManifestPlugin } from "./plugins/server-externals-manifest.js";
56
- import { computeLazyChunks } from "./utils/lazy-chunks.js";
57
- import { findClientEntryFile, findPagesClientEntryFile, readClientBuildManifest } from "./utils/client-build-manifest.js";
58
- import { VINEXT_CLIENT_ENTRY_MANIFEST, findClientEntryFileFromVinextManifest, findPagesClientEntryFileFromVinextManifest, readClientEntryManifest } from "./utils/client-entry-manifest.js";
57
+ import { VINEXT_CLIENT_ENTRY_MANIFEST } from "./utils/client-entry-manifest.js";
58
+ import { buildRuntimeGlobalsScript, computeClientRuntimeMetadata } from "./utils/client-runtime-metadata.js";
59
59
  import { formatMissingCloudflarePluginError, hasWranglerConfig } from "./deploy.js";
60
60
  import { resolvePostcssStringPlugins } from "./plugins/postcss.js";
61
- import { buildSassPreprocessorOptions } from "./plugins/sass.js";
62
- import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
61
+ import { buildSassPreprocessorOptions, createSassAwareFileSystemLoader, createSassTildeImporter } from "./plugins/sass.js";
62
+ import { createClientAssetFileNames, createClientCodeSplittingConfig, createClientFileNameConfig, createClientManualChunks, createClientOutputConfig, createRscFrameworkChunkOutputConfig, getBuildBundlerOptions, getClientTreeshakeConfigForVite, withBuildBundlerOptions } from "./build/client-build-config.js";
63
63
  import { markCssUrlAssetReferences, restoreDedupedCssAssetReferences } from "./build/css-url-assets.js";
64
- import { augmentSsrManifestFromBundle, relativeWithinRoot, tryRealpathSync } from "./build/ssr-manifest.js";
65
64
  import { stripServerExports } from "./plugins/strip-server-exports.js";
66
65
  import { removeConsoleCalls } from "./plugins/remove-console.js";
67
66
  import { createImportMetaUrlPlugin } from "./plugins/import-meta-url.js";
68
67
  import { createRequireContextPlugin } from "./plugins/require-context.js";
68
+ import { createWasmModuleImportPlugin } from "./plugins/wasm-module-import.js";
69
69
  import { hasMdxFiles } from "./utils/mdx-scan.js";
70
70
  import { scanPublicFileRoutes } from "./utils/public-routes.js";
71
71
  import { staticExportApp, staticExportPages } from "./build/static-export.js";
@@ -80,10 +80,6 @@ import MagicString from "magic-string";
80
80
  import tsconfigPaths from "vite-tsconfig-paths";
81
81
  //#region src/index.ts
82
82
  installSocketErrorBackstop();
83
- function stripViteModuleQuery(id) {
84
- const queryIndex = id.search(/[?#]/);
85
- return queryIndex === -1 ? id : id.slice(0, queryIndex);
86
- }
87
83
  function isInsideDirectory(dir, filePath) {
88
84
  const relativePath = path.relative(dir, filePath);
89
85
  return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
@@ -148,10 +144,10 @@ function resolveShimModulePath(shimsDir, moduleName) {
148
144
  ".tsx",
149
145
  ".js"
150
146
  ]) {
151
- const candidate = path.join(shimsDir, `${moduleName}${ext}`);
147
+ const candidate = path.posix.join(shimsDir, `${moduleName}${ext}`);
152
148
  if (fs.existsSync(candidate)) return candidate;
153
149
  }
154
- return path.join(shimsDir, `${moduleName}.js`);
150
+ return path.posix.join(shimsDir, `${moduleName}.js`);
155
151
  }
156
152
  function isVercelOgImport(id) {
157
153
  return id === "@vercel/og" || id === "@vercel/og.js";
@@ -300,8 +296,14 @@ const RESOLVED_INSTRUMENTATION_CLIENT = `\0${VIRTUAL_INSTRUMENTATION_CLIENT}.mjs
300
296
  /** Image file extensions handled by the vinext:image-imports plugin.
301
297
  * Shared between the Rolldown hook filter and the transform handler regex. */
302
298
  const IMAGE_EXTS = "png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?";
303
- /** Absolute path to vinext's shims directory, used by clientManualChunks. */
304
- const _shimsDir = path.resolve(__dirname, "shims") + "/";
299
+ /**
300
+ * Absolute path to vinext's shims directory, with a trailing slash. Normalized
301
+ * to forward slashes because it is prefix-matched against Vite module ids (which
302
+ * Vite always normalizes to forward slashes) in the font plugins and
303
+ * clientManualChunks — a raw path.resolve value has backslashes on Windows and
304
+ * the `id.startsWith(_shimsDir)` checks would never match.
305
+ */
306
+ const _shimsDir = normalizePathSeparators(path.resolve(__dirname, "shims")) + "/";
305
307
  const _fontGoogleShimPath = resolveShimModulePath(_shimsDir, "font-google");
306
308
  function isValidExportIdentifier(name) {
307
309
  return /^[$A-Z_a-z][$\w]*$/.test(name);
@@ -386,6 +388,7 @@ const clientManualChunks = createClientManualChunks(_shimsDir);
386
388
  const clientCodeSplittingConfig = createClientCodeSplittingConfig(clientManualChunks);
387
389
  function getClientOutputConfigForVite(viteMajorVersion, assetsDir) {
388
390
  return viteMajorVersion >= 8 ? {
391
+ ...createClientFileNameConfig(assetsDir),
389
392
  assetFileNames: createClientAssetFileNames(assetsDir),
390
393
  codeSplitting: clientCodeSplittingConfig
391
394
  } : createClientOutputConfig(clientManualChunks, assetsDir);
@@ -409,6 +412,7 @@ function vinext(options = {}) {
409
412
  let hasNitroPlugin = false;
410
413
  let rscCompatibilityId;
411
414
  const draftModeSecret = randomUUID();
415
+ const sassComposesLoader = createSassAwareFileSystemLoader();
412
416
  let rscClassificationManifest = null;
413
417
  const shimsDir = path.resolve(__dirname, "shims");
414
418
  const canonicalize = (p) => tryRealpathSync(p) ?? p;
@@ -547,7 +551,7 @@ function vinext(options = {}) {
547
551
  name: "vinext:config",
548
552
  enforce: "pre",
549
553
  async config(config, env) {
550
- root = config.root ?? process.cwd();
554
+ root = normalizePathSeparators(config.root ?? process.cwd());
551
555
  const userResolve = config.resolve;
552
556
  const shouldEnableNativeTsconfigPaths = viteMajorVersion >= 8 && userResolve?.tsconfigPaths === void 0;
553
557
  const tsconfigPathAliases = resolveTsconfigAliases(root);
@@ -560,18 +564,18 @@ function vinext(options = {}) {
560
564
  else resolvedNodeEnv = "development";
561
565
  if (process.env.NODE_ENV !== resolvedNodeEnv) process.env.NODE_ENV = resolvedNodeEnv;
562
566
  let baseDir;
563
- if (options.appDir) baseDir = path.isAbsolute(options.appDir) ? options.appDir : path.resolve(root, options.appDir);
567
+ if (options.appDir) baseDir = normalizePathSeparators(path.isAbsolute(options.appDir) ? options.appDir : path.resolve(root, options.appDir));
564
568
  else {
565
- const hasRootApp = fs.existsSync(path.join(root, "app"));
566
- const hasRootPages = fs.existsSync(path.join(root, "pages"));
567
- const hasSrcApp = fs.existsSync(path.join(root, "src", "app"));
568
- const hasSrcPages = fs.existsSync(path.join(root, "src", "pages"));
569
+ const hasRootApp = fs.existsSync(path.posix.join(root, "app"));
570
+ const hasRootPages = fs.existsSync(path.posix.join(root, "pages"));
571
+ const hasSrcApp = fs.existsSync(path.posix.join(root, "src", "app"));
572
+ const hasSrcPages = fs.existsSync(path.posix.join(root, "src", "pages"));
569
573
  if (hasRootApp || hasRootPages) baseDir = root;
570
- else if (hasSrcApp || hasSrcPages) baseDir = path.join(root, "src");
574
+ else if (hasSrcApp || hasSrcPages) baseDir = path.posix.join(root, "src");
571
575
  else baseDir = root;
572
576
  }
573
- pagesDir = path.join(baseDir, "pages");
574
- appDir = path.join(baseDir, "app");
577
+ pagesDir = path.posix.join(baseDir, "pages");
578
+ appDir = path.posix.join(baseDir, "app");
575
579
  hasPagesDir = fs.existsSync(pagesDir);
576
580
  hasAppDir = !options.disableAppRouter && fs.existsSync(appDir);
577
581
  if (!nextConfig) {
@@ -612,6 +616,7 @@ function vinext(options = {}) {
612
616
  defines["process.env.__NEXT_ROUTER_BASEPATH"] = JSON.stringify(nextConfig.basePath);
613
617
  defines["process.env.__NEXT_CLIENT_ROUTER_STATIC_STALETIME"] = JSON.stringify(String(nextConfig.staleTimes.static));
614
618
  defines["process.env.__VINEXT_PREFETCH_INLINING"] = JSON.stringify(nextConfig.prefetchInlining ? "true" : "false");
619
+ defines["process.env.__NEXT_GESTURE_TRANSITION"] = JSON.stringify(nextConfig.gestureTransition);
615
620
  defines["process.env.__VINEXT_TRAILING_SLASH"] = JSON.stringify(nextConfig.trailingSlash ? "true" : "false");
616
621
  defines["process.env.__VINEXT_IMAGE_REMOTE_PATTERNS"] = JSON.stringify(JSON.stringify(nextConfig.images?.remotePatterns ?? []));
617
622
  defines["process.env.__VINEXT_IMAGE_DOMAINS"] = JSON.stringify(JSON.stringify(nextConfig.images?.domains ?? []));
@@ -645,9 +650,10 @@ function vinext(options = {}) {
645
650
  defines["process.env.__VINEXT_RSC_COMPATIBILITY_ID"] = JSON.stringify(rscCompatibilityId);
646
651
  defines["process.env.__VINEXT_DEPLOYMENT_ID"] = JSON.stringify(nextConfig.deploymentId ?? "");
647
652
  defines["process.env.NEXT_DEPLOYMENT_ID"] = nextConfig.deploymentId ? JSON.stringify(nextConfig.deploymentId) : "false";
653
+ defines["process.env.NEXT_RUNTIME"] = "\"\"";
648
654
  defines["process.env.__NEXT_VERSION"] = JSON.stringify(getVinextVersion());
649
655
  defines["process.env.__NEXT_APP_SHELLS"] = JSON.stringify(nextConfig.appShells);
650
- defines["process.env.__NEXT_CACHE_COMPONENTS"] = JSON.stringify(String(nextConfig.cacheComponents ?? false));
656
+ defines["process.env.__NEXT_CACHE_COMPONENTS"] = JSON.stringify(nextConfig.cacheComponents ?? false);
651
657
  for (const [key, value] of Object.entries(nextConfig.compilerDefine)) {
652
658
  if (key in defines) throw new Error(`The \`compiler.define\` option is configured to replace the \`${key}\` variable. This variable is either part of a built-in or is already configured.`);
653
659
  defines[key] = value;
@@ -735,6 +741,7 @@ function vinext(options = {}) {
735
741
  ...typeof config.server?.hmr === "object" ? config.server.hmr : {},
736
742
  overlay: false
737
743
  };
744
+ const cssModulesOverride = config.css?.modules === false || typeof config.css?.modules === "object" && "Loader" in config.css.modules ? {} : { modules: { Loader: sassComposesLoader.Loader } };
738
745
  const viteConfig = {
739
746
  appType: "custom",
740
747
  build: {
@@ -801,13 +808,21 @@ function vinext(options = {}) {
801
808
  const dirPrefix = resolveAssetsDir(nextConfig.assetPrefix) + "/";
802
809
  return urlPrefix + (filename.startsWith(dirPrefix) ? filename.slice(dirPrefix.length) : filename.startsWith(`_next/static/`) ? filename.slice(ASSET_PREFIX_URL_DIR.length + 1) : filename);
803
810
  } } } : {},
804
- ...postcssOverride || sassPreprocessorOptions ? { css: {
811
+ css: {
805
812
  ...postcssOverride ? { postcss: postcssOverride } : {},
806
- ...sassPreprocessorOptions ? { preprocessorOptions: {
807
- scss: sassPreprocessorOptions,
808
- sass: sassPreprocessorOptions
809
- } } : {}
810
- } } : {}
813
+ preprocessorOptions: (() => {
814
+ const tildeImporter = createSassTildeImporter(root);
815
+ const baseOpts = {
816
+ ...sassPreprocessorOptions,
817
+ importers: [tildeImporter, ...sassPreprocessorOptions?.importers ?? []]
818
+ };
819
+ return {
820
+ scss: baseOpts,
821
+ sass: baseOpts
822
+ };
823
+ })(),
824
+ ...cssModulesOverride
825
+ }
811
826
  };
812
827
  const nextServerExternal = nextConfig?.serverExternalPackages ?? [];
813
828
  const userSsrExternal = Array.isArray(config.ssr?.external) ? [...config.ssr.external, ...nextServerExternal] : config.ssr?.external === true ? true : nextServerExternal;
@@ -884,7 +899,7 @@ function vinext(options = {}) {
884
899
  ])]
885
900
  },
886
901
  build: {
887
- ...hasCloudflarePlugin || hasPagesDir ? { manifest: true } : {},
902
+ manifest: true,
888
903
  ...hasPagesDir ? { ssrManifest: true } : {},
889
904
  assetsInlineLimit: clientAssetsInlineLimit,
890
905
  ...withBuildBundlerOptions(viteMajorVersion, {
@@ -952,6 +967,7 @@ function vinext(options = {}) {
952
967
  return viteConfig;
953
968
  },
954
969
  configResolved(config) {
970
+ sassComposesLoader.setResolvedConfig(config);
955
971
  if (hasAppDir) {
956
972
  const ssrEnv = config.environments?.ssr;
957
973
  if (ssrEnv?.resolve?.external === true && Array.isArray(ssrEnv.resolve.noExternal)) ssrEnv.resolve.noExternal = ssrEnv.resolve.noExternal.filter((entry) => typeof entry !== "string" || !SSR_EXTERNAL_REACT_ENTRIES.includes(entry));
@@ -1444,7 +1460,10 @@ function vinext(options = {}) {
1444
1460
  pathname = dataMatch.pagePathname;
1445
1461
  req.url = url;
1446
1462
  } else {
1447
- res.writeHead(404, { "Content-Type": "application/json" });
1463
+ const deploymentId = process.env.__VINEXT_DEPLOYMENT_ID || process.env.NEXT_DEPLOYMENT_ID;
1464
+ const notFoundHeaders = { "Content-Type": "application/json" };
1465
+ if (deploymentId) notFoundHeaders[NEXTJS_DEPLOYMENT_ID_HEADER] = deploymentId;
1466
+ res.writeHead(404, notFoundHeaders);
1448
1467
  res.end("{}");
1449
1468
  return;
1450
1469
  }
@@ -1629,9 +1648,9 @@ function vinext(options = {}) {
1629
1648
  configEnvironment(name) {
1630
1649
  if (name === "client") return null;
1631
1650
  const serverDefines = { ...nextConfig.compilerDefineServer };
1651
+ serverDefines["process.env.NEXT_RUNTIME"] = JSON.stringify("nodejs");
1632
1652
  const sharedRevalidateSecret = process.env.__VINEXT_SHARED_REVALIDATE_SECRET;
1633
1653
  if (sharedRevalidateSecret) serverDefines["process.env.__VINEXT_REVALIDATE_SECRET"] = JSON.stringify(sharedRevalidateSecret);
1634
- if (Object.keys(serverDefines).length === 0) return null;
1635
1654
  return { define: serverDefines };
1636
1655
  }
1637
1656
  },
@@ -1721,6 +1740,7 @@ function vinext(options = {}) {
1721
1740
  createGoogleFontsPlugin(_fontGoogleShimPath, _shimsDir),
1722
1741
  createLocalFontsPlugin(_shimsDir),
1723
1742
  createOptimizeImportsPlugin(() => nextConfig, () => root),
1743
+ createDynamicPreloadMetadataPlugin(),
1724
1744
  {
1725
1745
  name: "vinext:use-cache",
1726
1746
  transform: {
@@ -2057,22 +2077,15 @@ function vinext(options = {}) {
2057
2077
  const distDir = path.resolve(buildRoot, "dist");
2058
2078
  if (!fs.existsSync(distDir)) return;
2059
2079
  const clientDir = path.resolve(buildRoot, "dist", "client");
2060
- const clientBase = envConfig.base ?? "/";
2061
- let lazyChunksData = null;
2062
- let clientEntryFile = null;
2063
- const clientEntryManifest = readClientEntryManifest(clientDir);
2064
- clientEntryFile = (hasAppDir && hasPagesDir ? findPagesClientEntryFileFromVinextManifest : findClientEntryFileFromVinextManifest)(clientEntryManifest, clientBase) ?? null;
2065
- const buildManifest = readClientBuildManifest(path.join(clientDir, ".vite", "manifest.json"));
2066
- if (buildManifest) {
2067
- if (!clientEntryFile) clientEntryFile = (hasAppDir && hasPagesDir ? findPagesClientEntryFile : findClientEntryFile)({
2068
- buildManifest,
2069
- clientDir,
2070
- assetsSubdir: resolveAssetsDir(nextConfig?.assetPrefix),
2071
- assetBase: clientBase
2072
- }) ?? null;
2073
- const lazy = manifestFilesWithBase(computeLazyChunks(buildManifest), clientBase);
2074
- if (lazy.length > 0) lazyChunksData = lazy;
2075
- }
2080
+ const runtimeMetadata = computeClientRuntimeMetadata({
2081
+ clientDir,
2082
+ assetBase: envConfig.base ?? "/",
2083
+ assetPrefix: nextConfig.assetPrefix,
2084
+ includeClientEntry: !hasAppDir ? true : hasPagesDir ? "pages-client-entry" : false
2085
+ });
2086
+ const lazyChunksData = runtimeMetadata.lazyChunks ?? null;
2087
+ const dynamicPreloadsData = runtimeMetadata.dynamicPreloads ?? null;
2088
+ let clientEntryFile = runtimeMetadata.clientEntryFile ?? null;
2076
2089
  let ssrManifestData = null;
2077
2090
  const ssrManifestPath = path.join(clientDir, ".vite", "ssr-manifest.json");
2078
2091
  if (fs.existsSync(ssrManifestPath)) try {
@@ -2080,19 +2093,17 @@ function vinext(options = {}) {
2080
2093
  } catch {}
2081
2094
  if (hasAppDir) {
2082
2095
  const workerEntry = path.resolve(distDir, "server", "index.js");
2083
- if (!clientEntryFile && hasPagesDir) clientEntryFile = findPagesClientEntryFile({
2084
- clientDir,
2085
- assetsSubdir: resolveAssetsDir(nextConfig?.assetPrefix),
2086
- assetBase: clientBase
2087
- }) ?? null;
2088
- if (fs.existsSync(workerEntry) && (lazyChunksData || ssrManifestData || hasPagesDir && clientEntryFile)) {
2089
- let code = fs.readFileSync(workerEntry, "utf-8");
2090
- const globals = [];
2091
- if (hasPagesDir && clientEntryFile) globals.push(`globalThis.__VINEXT_CLIENT_ENTRY__ = ${JSON.stringify(clientEntryFile)};`);
2092
- if (ssrManifestData) globals.push(`globalThis.__VINEXT_SSR_MANIFEST__ = ${JSON.stringify(ssrManifestData)};`);
2093
- if (lazyChunksData) globals.push(`globalThis.__VINEXT_LAZY_CHUNKS__ = ${JSON.stringify(lazyChunksData)};`);
2094
- code = globals.join("\n") + "\n" + code;
2095
- fs.writeFileSync(workerEntry, code);
2096
+ if (fs.existsSync(workerEntry)) {
2097
+ const script = buildRuntimeGlobalsScript({
2098
+ clientEntryFile,
2099
+ ssrManifest: ssrManifestData,
2100
+ lazyChunks: lazyChunksData,
2101
+ dynamicPreloads: dynamicPreloadsData
2102
+ });
2103
+ if (script) {
2104
+ const code = fs.readFileSync(workerEntry, "utf-8");
2105
+ fs.writeFileSync(workerEntry, script + "\n" + code);
2106
+ }
2096
2107
  }
2097
2108
  } else {
2098
2109
  let workerOutDir = null;
@@ -2107,19 +2118,15 @@ function vinext(options = {}) {
2107
2118
  if (!workerOutDir) return;
2108
2119
  const workerEntry = path.join(workerOutDir, "index.js");
2109
2120
  if (!fs.existsSync(workerEntry)) return;
2110
- if (!clientEntryFile) clientEntryFile = findClientEntryFile({
2111
- clientDir,
2112
- assetsSubdir: resolveAssetsDir(nextConfig?.assetPrefix),
2113
- assetBase: clientBase
2114
- }) ?? null;
2115
- if (clientEntryFile || ssrManifestData || lazyChunksData) {
2116
- let code = fs.readFileSync(workerEntry, "utf-8");
2117
- const globals = [];
2118
- if (clientEntryFile) globals.push(`globalThis.__VINEXT_CLIENT_ENTRY__ = ${JSON.stringify(clientEntryFile)};`);
2119
- if (ssrManifestData) globals.push(`globalThis.__VINEXT_SSR_MANIFEST__ = ${JSON.stringify(ssrManifestData)};`);
2120
- if (lazyChunksData) globals.push(`globalThis.__VINEXT_LAZY_CHUNKS__ = ${JSON.stringify(lazyChunksData)};`);
2121
- code = globals.join("\n") + "\n" + code;
2122
- fs.writeFileSync(workerEntry, code);
2121
+ const script = buildRuntimeGlobalsScript({
2122
+ clientEntryFile,
2123
+ ssrManifest: ssrManifestData,
2124
+ lazyChunks: lazyChunksData,
2125
+ dynamicPreloads: dynamicPreloadsData
2126
+ });
2127
+ if (script) {
2128
+ const code = fs.readFileSync(workerEntry, "utf-8");
2129
+ fs.writeFileSync(workerEntry, script + "\n" + code);
2123
2130
  }
2124
2131
  }
2125
2132
  const headersPath = path.join(clientDir, "_headers");
@@ -2137,6 +2144,7 @@ function vinext(options = {}) {
2137
2144
  }
2138
2145
  }
2139
2146
  },
2147
+ createWasmModuleImportPlugin(),
2140
2148
  {
2141
2149
  name: "vinext:og-font-patch",
2142
2150
  enforce: "pre",
@@ -0,0 +1,13 @@
1
+ import { Plugin } from "vite";
2
+ import MagicString from "magic-string";
3
+
4
+ //#region src/plugins/dynamic-preload-metadata.d.ts
5
+ type TransformResult = {
6
+ code: string;
7
+ map: ReturnType<MagicString["generateMap"]>;
8
+ };
9
+ type ResolveDynamicImport = (specifier: string, importer: string) => Promise<string | null>;
10
+ declare function transformNextDynamicPreloadMetadata(code: string, id: string, root: string, resolveDynamicImport: ResolveDynamicImport): Promise<TransformResult | null>;
11
+ declare function createDynamicPreloadMetadataPlugin(): Plugin;
12
+ //#endregion
13
+ export { createDynamicPreloadMetadataPlugin, transformNextDynamicPreloadMetadata };