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
@@ -44,5 +44,69 @@ function computeLazyChunks(buildManifest) {
44
44
  }
45
45
  return lazyChunks;
46
46
  }
47
+ function normalizeManifestKey(key) {
48
+ return key.split("?")[0].replace(/\\/g, "/").replace(/^\/+/, "");
49
+ }
50
+ function addFile(files, seen, file) {
51
+ if (!file || seen.has(file)) return;
52
+ seen.add(file);
53
+ files.push(file);
54
+ }
55
+ function collectStaticChunkFiles(buildManifest, key, files, seenFiles, visitedChunks) {
56
+ if (visitedChunks.has(key)) return;
57
+ visitedChunks.add(key);
58
+ const chunk = buildManifest[key];
59
+ if (!chunk) return;
60
+ if (chunk.file.endsWith(".js")) addFile(files, seenFiles, chunk.file);
61
+ for (const cssFile of chunk.css ?? []) addFile(files, seenFiles, cssFile);
62
+ for (const importedKey of chunk.imports ?? []) collectStaticChunkFiles(buildManifest, importedKey, files, seenFiles, visitedChunks);
63
+ }
64
+ /**
65
+ * Compute the production preload files for each module referenced by a
66
+ * `next/dynamic()` boundary.
67
+ *
68
+ * Next.js records module IDs during compilation, then resolves those IDs
69
+ * against its react-loadable manifest at render time. Vinext's equivalent
70
+ * source of truth is Vite's build manifest: each chunk lists the modules it
71
+ * reaches through `dynamicImports`, and each dynamic entry lists the JS/CSS
72
+ * files required to evaluate it.
73
+ *
74
+ * Note on shared chunks: a boundary's static-import tree (`collectStaticChunkFiles`)
75
+ * can include chunks that the page entry ALSO loads eagerly (a shared vendor
76
+ * chunk imported by both). Those files are intentionally NOT subtracted here, so
77
+ * a rendered boundary may emit a `<link rel="preload">` / `<link rel="stylesheet">`
78
+ * for a chunk the page already `<link rel="modulepreload">`s. This is harmless —
79
+ * the browser dedupes preloads by URL, `ReactDOM.preload()` dedupes script hints,
80
+ * and React's stylesheet resource model dedupes by href + precedence — and it
81
+ * mirrors Next.js listing a module's full file set in its react-loadable
82
+ * manifest. Subtracting the eager set would couple this to the entry's import
83
+ * closure for no correctness gain.
84
+ *
85
+ * @returns A map keyed by root-relative module ID, with JS/CSS files that
86
+ * should be preloaded when that dynamic boundary is rendered.
87
+ */
88
+ function computeDynamicImportPreloads(buildManifest) {
89
+ const preloads = {};
90
+ for (const chunk of Object.values(buildManifest)) for (const dynamicKey of chunk.dynamicImports ?? []) {
91
+ const files = [];
92
+ collectStaticChunkFiles(buildManifest, dynamicKey, files, /* @__PURE__ */ new Set(), /* @__PURE__ */ new Set());
93
+ if (files.length === 0) continue;
94
+ const normalizedKey = normalizeManifestKey(dynamicKey);
95
+ const existing = preloads[normalizedKey] ?? [];
96
+ const merged = new Set(existing);
97
+ for (const file of files) {
98
+ if (merged.has(file)) continue;
99
+ merged.add(file);
100
+ existing.push(file);
101
+ }
102
+ preloads[normalizedKey] = existing;
103
+ }
104
+ return preloads;
105
+ }
106
+ function dynamicImportPreloadsWithBase(preloads, applyBase) {
107
+ const withBase = {};
108
+ for (const [key, files] of Object.entries(preloads)) withBase[key] = files.map(applyBase);
109
+ return withBase;
110
+ }
47
111
  //#endregion
48
- export { computeLazyChunks };
112
+ export { computeDynamicImportPreloads, computeLazyChunks, dynamicImportPreloadsWithBase };
@@ -1,6 +1,24 @@
1
1
  //#region src/utils/manifest-paths.d.ts
2
2
  declare function manifestFileWithBase(file: string, base: string): string;
3
- declare function manifestFilesWithBase(files: string[], base: string): string[];
3
+ declare function manifestFileWithAssetPrefix(file: string, base: string, assetPrefix: string): string;
4
+ /**
5
+ * Resolve the URL a client asset is actually SERVED from, starting from a
6
+ * base-anchored manifest / SSR-manifest value (no leading slash), e.g.
7
+ * `"docs/cdn/_next/static/x.js"`.
8
+ *
9
+ * Next.js semantics: `assetPrefix` REPLACES `basePath` for asset URLs (they do
10
+ * not stack). So when an `assetPrefix` is configured we strip the basePath
11
+ * segment and re-anchor under the assetPrefix — matching how `next/dynamic`
12
+ * preloads are computed (`manifestFileWithAssetPrefix`) and what the prod server
13
+ * / Cloudflare ASSETS binding actually serve. Without this, a `basePath` +
14
+ * path-style `assetPrefix` build emits `/<basePath>/<assetPrefix>/_next/...`
15
+ * which 404s. When no `assetPrefix` is set, the base-anchored value is already
16
+ * the served URL and is returned unchanged (just root-anchored).
17
+ *
18
+ * Returns an absolute URL for an absolute `assetPrefix`, otherwise a
19
+ * root-relative URL beginning with `/`.
20
+ */
21
+ declare function assetServingUrlFromBaseAnchored(value: string, basePath: string, assetPrefix: string): string;
4
22
  /**
5
23
  * Strip a `base` prefix that Vite applied twice: it bakes `base` into the
6
24
  * on-disk chunk fileName and then prepends it again in `ssr-manifest.json`,
@@ -9,4 +27,4 @@ declare function manifestFilesWithBase(files: string[], base: string): string[];
9
27
  */
10
28
  declare function collapseDuplicateBase(file: string, base: string): string;
11
29
  //#endregion
12
- export { collapseDuplicateBase, manifestFileWithBase, manifestFilesWithBase };
30
+ export { assetServingUrlFromBaseAnchored, collapseDuplicateBase, manifestFileWithAssetPrefix, manifestFileWithBase };
@@ -1,3 +1,4 @@
1
+ import { ASSET_PREFIX_URL_DIR, isAbsoluteAssetPrefix, resolveAssetUrlPrefix, resolveAssetsDir } from "./asset-prefix.js";
1
2
  //#region src/utils/manifest-paths.ts
2
3
  function normalizeManifestFile(file) {
3
4
  return file.startsWith("/") ? file.slice(1) : file;
@@ -10,8 +11,42 @@ function manifestFileWithBase(file, base) {
10
11
  if (normalizedFile.startsWith(normalizedBase + "/")) return normalizedFile;
11
12
  return normalizedBase + "/" + normalizedFile;
12
13
  }
13
- function manifestFilesWithBase(files, base) {
14
- return files.map((file) => manifestFileWithBase(file, base));
14
+ function manifestFileWithAssetPrefix(file, base, assetPrefix) {
15
+ if (!assetPrefix) return manifestFileWithBase(file, base);
16
+ const normalizedFile = normalizeManifestFile(file);
17
+ const onDiskDirPrefix = normalizeManifestFile(resolveAssetsDir(assetPrefix)) + "/";
18
+ const staticDirPrefix = ASSET_PREFIX_URL_DIR + "/";
19
+ const stripped = normalizedFile.startsWith(onDiskDirPrefix) ? normalizedFile.slice(onDiskDirPrefix.length) : normalizedFile.startsWith(staticDirPrefix) ? normalizedFile.slice(staticDirPrefix.length) : normalizedFile;
20
+ const urlPrefix = resolveAssetUrlPrefix(assetPrefix);
21
+ return (isAbsoluteAssetPrefix(assetPrefix) ? urlPrefix : normalizeManifestFile(urlPrefix)) + stripped;
22
+ }
23
+ function stripBasePathSegment(file, basePath) {
24
+ const normalizedBase = normalizeManifestFile(basePath).replace(/\/+$/, "");
25
+ if (!normalizedBase) return file;
26
+ return file.startsWith(normalizedBase + "/") ? file.slice(normalizedBase.length + 1) : file;
27
+ }
28
+ /**
29
+ * Resolve the URL a client asset is actually SERVED from, starting from a
30
+ * base-anchored manifest / SSR-manifest value (no leading slash), e.g.
31
+ * `"docs/cdn/_next/static/x.js"`.
32
+ *
33
+ * Next.js semantics: `assetPrefix` REPLACES `basePath` for asset URLs (they do
34
+ * not stack). So when an `assetPrefix` is configured we strip the basePath
35
+ * segment and re-anchor under the assetPrefix — matching how `next/dynamic`
36
+ * preloads are computed (`manifestFileWithAssetPrefix`) and what the prod server
37
+ * / Cloudflare ASSETS binding actually serve. Without this, a `basePath` +
38
+ * path-style `assetPrefix` build emits `/<basePath>/<assetPrefix>/_next/...`
39
+ * which 404s. When no `assetPrefix` is set, the base-anchored value is already
40
+ * the served URL and is returned unchanged (just root-anchored).
41
+ *
42
+ * Returns an absolute URL for an absolute `assetPrefix`, otherwise a
43
+ * root-relative URL beginning with `/`.
44
+ */
45
+ function assetServingUrlFromBaseAnchored(value, basePath, assetPrefix) {
46
+ const normalized = normalizeManifestFile(value);
47
+ if (!assetPrefix) return "/" + normalized;
48
+ const anchored = manifestFileWithAssetPrefix(stripBasePathSegment(normalized, basePath), "/", assetPrefix);
49
+ return isAbsoluteAssetPrefix(assetPrefix) ? anchored : "/" + anchored;
15
50
  }
16
51
  /**
17
52
  * Strip a `base` prefix that Vite applied twice: it bakes `base` into the
@@ -28,4 +63,4 @@ function collapseDuplicateBase(file, base) {
28
63
  return normalizedFile.startsWith(doubledPrefix) ? normalizedFile.slice(normalizedBase.length + 1) : normalizedFile;
29
64
  }
30
65
  //#endregion
31
- export { collapseDuplicateBase, manifestFileWithBase, manifestFilesWithBase };
66
+ export { assetServingUrlFromBaseAnchored, collapseDuplicateBase, manifestFileWithAssetPrefix, manifestFileWithBase };
@@ -11,5 +11,6 @@
11
11
  * appear in filesystem paths on Linux/macOS.
12
12
  */
13
13
  declare function normalizePathSeparators(p: string): string;
14
+ declare function stripViteModuleQuery(id: string): string;
14
15
  //#endregion
15
- export { normalizePathSeparators };
16
+ export { normalizePathSeparators, stripViteModuleQuery };
@@ -14,5 +14,9 @@ const isWindows = process.platform === "win32";
14
14
  function normalizePathSeparators(p) {
15
15
  return isWindows ? p.replace(/\\/g, "/") : p;
16
16
  }
17
+ function stripViteModuleQuery(id) {
18
+ const queryIndex = id.search(/[?#]/);
19
+ return queryIndex === -1 ? id : id.slice(0, queryIndex);
20
+ }
17
21
  //#endregion
18
- export { normalizePathSeparators };
22
+ export { normalizePathSeparators, stripViteModuleQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vinext",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Run Next.js apps on Vite. Drop-in replacement for the next CLI.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -101,7 +101,7 @@
101
101
  "react-server-dom-webpack": "^19.2.7",
102
102
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.24",
103
103
  "vite-plus": "0.1.24",
104
- "@vinext/cloudflare": "0.1.0"
104
+ "@vinext/cloudflare": "0.1.1"
105
105
  },
106
106
  "peerDependencies": {
107
107
  "@mdx-js/rollup": "^3.0.0",