vinext 1.0.0-beta.6 → 1.0.0-beta.7

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 (176) hide show
  1. package/README.md +20 -3
  2. package/dist/build/action-owner-manifest.d.ts +42 -0
  3. package/dist/build/action-owner-manifest.js +110 -0
  4. package/dist/build/clean-output.js +1 -4
  5. package/dist/build/client-build-config.js +10 -11
  6. package/dist/build/prerender.d.ts +1 -1
  7. package/dist/build/prerender.js +12 -6
  8. package/dist/build/report.d.ts +1 -1
  9. package/dist/build/route-classification-manifest.d.ts +1 -1
  10. package/dist/build/static-export.d.ts +1 -1
  11. package/dist/client/app-nav-failure-handler.js +1 -0
  12. package/dist/client/navigation-runtime.d.ts +5 -3
  13. package/dist/client/navigation-runtime.js +4 -8
  14. package/dist/entries/app-browser-entry.d.ts +1 -1
  15. package/dist/entries/app-rsc-entry.d.ts +2 -1
  16. package/dist/entries/app-rsc-entry.js +111 -8
  17. package/dist/entries/pages-client-entry.d.ts +1 -1
  18. package/dist/entries/pages-server-entry.d.ts +1 -1
  19. package/dist/index.js +108 -22
  20. package/dist/plugins/action-owner-manifest.d.ts +14 -0
  21. package/dist/plugins/action-owner-manifest.js +84 -0
  22. package/dist/plugins/ast-utils.d.ts +30 -1
  23. package/dist/plugins/ast-utils.js +76 -1
  24. package/dist/plugins/css-module-imports.d.ts +2 -2
  25. package/dist/plugins/css-module-imports.js +5 -13
  26. package/dist/plugins/dynamic-preload-metadata.js +13 -34
  27. package/dist/plugins/environment.d.ts +11 -0
  28. package/dist/plugins/environment.js +7 -0
  29. package/dist/plugins/extensionless-dynamic-import.js +11 -35
  30. package/dist/plugins/fonts.js +8 -12
  31. package/dist/plugins/ignore-dynamic-requests.d.ts +2 -4
  32. package/dist/plugins/ignore-dynamic-requests.js +29 -59
  33. package/dist/plugins/import-meta-url.d.ts +15 -9
  34. package/dist/plugins/import-meta-url.js +309 -85
  35. package/dist/plugins/instrumentation-client.js +4 -5
  36. package/dist/plugins/middleware-export-validation.js +5 -17
  37. package/dist/plugins/middleware-server-only.js +2 -2
  38. package/dist/plugins/og-asset-ownership.js +18 -26
  39. package/dist/plugins/og-assets.js +2 -4
  40. package/dist/plugins/optimize-imports.js +2 -4
  41. package/dist/plugins/pages-node-externals.js +13 -40
  42. package/dist/plugins/remove-console.js +2 -4
  43. package/dist/plugins/require-condition-resolution.d.ts +16 -0
  44. package/dist/plugins/require-condition-resolution.js +167 -0
  45. package/dist/plugins/require-context.js +11 -46
  46. package/dist/plugins/sass.js +1 -1
  47. package/dist/plugins/server-externals-manifest.js +1 -23
  48. package/dist/plugins/strip-server-exports.js +13 -19
  49. package/dist/plugins/styled-jsx.js +17 -19
  50. package/dist/plugins/transform-result.d.ts +10 -0
  51. package/dist/plugins/transform-result.js +10 -0
  52. package/dist/plugins/transitive-externals.js +7 -21
  53. package/dist/plugins/typeof-window.d.ts +3 -8
  54. package/dist/plugins/typeof-window.js +5 -15
  55. package/dist/plugins/use-cache-callable.js +12 -22
  56. package/dist/plugins/wasm-module-import.js +1 -1
  57. package/dist/plugins/worker-image-imports.d.ts +12 -0
  58. package/dist/plugins/worker-image-imports.js +136 -0
  59. package/dist/routing/app-route-graph.d.ts +3 -2
  60. package/dist/routing/app-route-graph.js +1 -1
  61. package/dist/routing/route-pattern.d.ts +8 -1
  62. package/dist/routing/route-pattern.js +28 -1
  63. package/dist/routing/route-validation.js +7 -1
  64. package/dist/server/accept-encoding.d.ts +1 -2
  65. package/dist/server/accept-encoding.js +1 -4
  66. package/dist/server/app-action-forwarding.d.ts +18 -0
  67. package/dist/server/app-action-forwarding.js +140 -0
  68. package/dist/server/app-browser-entry.js +231 -50
  69. package/dist/server/app-browser-error.d.ts +1 -2
  70. package/dist/server/app-browser-error.js +1 -5
  71. package/dist/server/app-browser-history-controller.d.ts +16 -1
  72. package/dist/server/app-browser-history-controller.js +135 -18
  73. package/dist/server/app-browser-navigation-abort.d.ts +16 -0
  74. package/dist/server/app-browser-navigation-abort.js +29 -0
  75. package/dist/server/app-browser-navigation-controller.d.ts +4 -0
  76. package/dist/server/app-browser-navigation-controller.js +22 -6
  77. package/dist/server/app-browser-navigation-response.d.ts +11 -0
  78. package/dist/server/app-browser-navigation-response.js +8 -0
  79. package/dist/server/app-browser-popstate.d.ts +6 -1
  80. package/dist/server/app-browser-popstate.js +6 -2
  81. package/dist/server/app-browser-server-action-client.js +1 -1
  82. package/dist/server/app-browser-state.d.ts +2 -2
  83. package/dist/server/app-browser-state.js +3 -3
  84. package/dist/server/app-browser-stream.d.ts +0 -2
  85. package/dist/server/app-browser-supplemental-refresh.d.ts +49 -0
  86. package/dist/server/app-browser-supplemental-refresh.js +190 -0
  87. package/dist/server/app-browser-visible-commit.js +23 -12
  88. package/dist/server/app-elements-wire.d.ts +2 -0
  89. package/dist/server/app-elements-wire.js +7 -0
  90. package/dist/server/app-history-state.d.ts +22 -1
  91. package/dist/server/app-history-state.js +93 -9
  92. package/dist/server/app-optimistic-routing.d.ts +22 -1
  93. package/dist/server/app-optimistic-routing.js +137 -12
  94. package/dist/server/app-page-cache-finalizer.d.ts +3 -1
  95. package/dist/server/app-page-cache-finalizer.js +6 -6
  96. package/dist/server/app-page-cache.d.ts +2 -1
  97. package/dist/server/app-page-cache.js +2 -2
  98. package/dist/server/app-page-dispatch.d.ts +4 -1
  99. package/dist/server/app-page-dispatch.js +10 -1
  100. package/dist/server/app-page-element-builder.d.ts +1 -0
  101. package/dist/server/app-page-element-builder.js +1 -0
  102. package/dist/server/app-page-ppr-runtime.js +3 -2
  103. package/dist/server/app-page-render.d.ts +2 -1
  104. package/dist/server/app-page-render.js +6 -3
  105. package/dist/server/app-page-request.d.ts +2 -33
  106. package/dist/server/app-page-request.js +1 -27
  107. package/dist/server/app-page-route-wiring.d.ts +1 -0
  108. package/dist/server/app-page-route-wiring.js +4 -0
  109. package/dist/server/app-page-segment-state.d.ts +2 -2
  110. package/dist/server/app-page-segment-state.js +14 -8
  111. package/dist/server/app-ppr-fallback-shell.d.ts +2 -2
  112. package/dist/server/app-ppr-fallback-shell.js +3 -6
  113. package/dist/server/app-route-handler-dispatch.js +4 -1
  114. package/dist/server/app-route-handler-execution.js +1 -1
  115. package/dist/server/app-rsc-cache-busting.d.ts +2 -1
  116. package/dist/server/app-rsc-cache-busting.js +34 -8
  117. package/dist/server/app-rsc-handler.d.ts +4 -2
  118. package/dist/server/app-rsc-handler.js +57 -9
  119. package/dist/server/app-rsc-request-normalization.d.ts +2 -0
  120. package/dist/server/app-rsc-request-normalization.js +5 -1
  121. package/dist/server/app-rsc-route-matching.d.ts +4 -3
  122. package/dist/server/app-rsc-route-matching.js +14 -42
  123. package/dist/server/app-server-action-execution.d.ts +3 -0
  124. package/dist/server/app-server-action-execution.js +77 -2
  125. package/dist/server/app-ssr-entry.js +6 -6
  126. package/dist/server/app-ssr-stream.d.ts +1 -1
  127. package/dist/server/app-ssr-stream.js +2 -2
  128. package/dist/server/app-visited-response-cache.d.ts +6 -1
  129. package/dist/server/app-visited-response-cache.js +18 -2
  130. package/dist/server/dev-route-files.js +2 -5
  131. package/dist/server/dev-server.d.ts +5 -13
  132. package/dist/server/dev-server.js +22 -22
  133. package/dist/server/dev-stack-sourcemap.d.ts +1 -2
  134. package/dist/server/dev-stack-sourcemap.js +1 -4
  135. package/dist/server/headers.d.ts +5 -1
  136. package/dist/server/headers.js +5 -1
  137. package/dist/server/isr-cache.d.ts +6 -14
  138. package/dist/server/isr-cache.js +6 -27
  139. package/dist/server/middleware.d.ts +3 -16
  140. package/dist/server/middleware.js +2 -19
  141. package/dist/server/navigation-planner.d.ts +1 -0
  142. package/dist/server/navigation-planner.js +57 -9
  143. package/dist/server/navigation-trace.d.ts +1 -0
  144. package/dist/server/navigation-trace.js +1 -0
  145. package/dist/server/pages-data-route.d.ts +1 -10
  146. package/dist/server/pages-data-route.js +1 -12
  147. package/dist/server/pages-node-compat.d.ts +1 -4
  148. package/dist/server/pages-node-compat.js +1 -7
  149. package/dist/server/pages-readiness.js +4 -4
  150. package/dist/server/prerender-route-params.d.ts +1 -2
  151. package/dist/server/prerender-route-params.js +1 -4
  152. package/dist/server/prod-server.js +3 -1
  153. package/dist/shims/cache-runtime.js +39 -22
  154. package/dist/shims/cache.d.ts +1 -1
  155. package/dist/shims/dynamic.d.ts +3 -3
  156. package/dist/shims/dynamic.js +4 -6
  157. package/dist/shims/error.js +1 -1
  158. package/dist/shims/fetch-cache.d.ts +3 -1
  159. package/dist/shims/fetch-cache.js +23 -4
  160. package/dist/shims/internal/app-route-prefetch-policy.d.ts +6 -7
  161. package/dist/shims/internal/app-route-prefetch-policy.js +5 -4
  162. package/dist/shims/link.js +1 -1
  163. package/dist/shims/navigation.d.ts +12 -3
  164. package/dist/shims/navigation.js +46 -11
  165. package/dist/shims/navigation.react-server.js +1 -1
  166. package/dist/shims/request-state-types.d.ts +1 -1
  167. package/dist/shims/router.js +75 -4
  168. package/dist/shims/unified-request-context.d.ts +1 -1
  169. package/dist/shims/unified-request-context.js +1 -0
  170. package/dist/utils/built-asset-url.d.ts +1 -1
  171. package/dist/utils/built-asset-url.js +4 -2
  172. package/dist/utils/package-name.d.ts +11 -0
  173. package/dist/utils/package-name.js +18 -0
  174. package/dist/utils/path.d.ts +8 -1
  175. package/dist/utils/path.js +21 -1
  176. package/package.json +2 -1
@@ -1,3 +1,5 @@
1
+ import { magicStringTransformResult } from "./transform-result.js";
2
+ import { getAstName } from "./ast-utils.js";
1
3
  import { parseAst } from "vite";
2
4
  import MagicString from "magic-string";
3
5
  //#region src/plugins/strip-server-exports.ts
@@ -49,11 +51,6 @@ function hasExportAllCandidate(code) {
49
51
  }
50
52
  return false;
51
53
  }
52
- function nodeName(node) {
53
- if (!node || typeof node !== "object") return void 0;
54
- const value = node;
55
- return value.name ?? value.value;
56
- }
57
54
  function isInsideRanges(position, ranges) {
58
55
  return ranges.some((range) => position >= range.start && position < range.end);
59
56
  }
@@ -95,10 +92,10 @@ function isReferenceIdentifier(node, parent) {
95
92
  if (parent.type === "CatchClause" && parent.param === node) return false;
96
93
  return true;
97
94
  }
98
- function walkAst(node, visit, parent, ancestors = []) {
95
+ function walkAstWithAncestors(node, visit, parent, ancestors = []) {
99
96
  if (!node || typeof node !== "object") return;
100
97
  if (Array.isArray(node)) {
101
- for (const child of node) walkAst(child, visit, parent, ancestors);
98
+ for (const child of node) walkAstWithAncestors(child, visit, parent, ancestors);
102
99
  return;
103
100
  }
104
101
  const current = node;
@@ -107,8 +104,8 @@ function walkAst(node, visit, parent, ancestors = []) {
107
104
  const childAncestors = [...ancestors, current];
108
105
  for (const [key, value] of Object.entries(current)) {
109
106
  if (key === "parent" || key === "loc" || key === "start" || key === "end") continue;
110
- if (Array.isArray(value)) for (const child of value) walkAst(child, visit, current, childAncestors);
111
- else if (value && typeof value === "object") walkAst(value, visit, current, childAncestors);
107
+ if (Array.isArray(value)) for (const child of value) walkAstWithAncestors(child, visit, current, childAncestors);
108
+ else if (value && typeof value === "object") walkAstWithAncestors(value, visit, current, childAncestors);
112
109
  }
113
110
  }
114
111
  function renderImportDeclaration(code, statement, removed) {
@@ -271,7 +268,7 @@ function stripServerExports(code) {
271
268
  });
272
269
  }
273
270
  else if (statement.type === "ImportDeclaration") for (const specifier of statement.specifiers) {
274
- const name = nodeName(specifier.local);
271
+ const name = getAstName(specifier.local);
275
272
  if (!name) continue;
276
273
  bindingPositions.add(specifier.local.start);
277
274
  bindings.set(name, {
@@ -302,7 +299,7 @@ function stripServerExports(code) {
302
299
  ranges.push(range);
303
300
  shadowRanges.set(name, ranges);
304
301
  };
305
- walkAst(ast.body, (node, parent, ancestors = []) => {
302
+ walkAstWithAncestors(ast.body, (node, parent, ancestors = []) => {
306
303
  if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
307
304
  for (const parameter of node.params) for (const name of bindingNames(parameter)) addShadowRange(name, node);
308
305
  if (node.type === "FunctionDeclaration" && node.id) addShadowRange(node.id.name, findLexicalScope(ancestors));
@@ -319,7 +316,7 @@ function stripServerExports(code) {
319
316
  for (const name of bindingNames(node.id)) addShadowRange(name, scope);
320
317
  }
321
318
  });
322
- walkAst(ast.body, (node, parent, ancestors = []) => {
319
+ walkAstWithAncestors(ast.body, (node, parent, ancestors = []) => {
323
320
  if (!isReferenceIdentifier(node, parent)) return;
324
321
  if (bindingPositions.has(node.start)) return;
325
322
  if (isInsideRanges(node.start, shadowRanges.get(node.name) ?? [])) return;
@@ -366,16 +363,16 @@ function stripServerExports(code) {
366
363
  }
367
364
  const removed = /* @__PURE__ */ new Set();
368
365
  for (const specifier of statement.specifiers) {
369
- const exportedName = nodeName(specifier.exported);
366
+ const exportedName = getAstName(specifier.exported);
370
367
  if (exportedName && SERVER_EXPORTS.has(exportedName)) {
371
368
  noteDataExport(exportedName);
372
369
  removed.add(specifier);
373
370
  if (!statement.source) {
374
- const localName = nodeName(specifier.local);
371
+ const localName = getAstName(specifier.local);
375
372
  if (localName) candidateBindings.add(localName);
376
373
  }
377
374
  } else if (!statement.source) {
378
- const localName = nodeName(specifier.local);
375
+ const localName = getAstName(specifier.local);
379
376
  if (localName) {
380
377
  const positions = references.get(localName) ?? [];
381
378
  positions.push(specifier.local.start);
@@ -510,10 +507,7 @@ function stripServerExports(code) {
510
507
  string.overwrite(edit.start, edit.end, edit.replacement);
511
508
  lastStart = edit.start;
512
509
  }
513
- return {
514
- code: string.toString(),
515
- map: string.generateMap({ hires: "boundary" })
516
- };
510
+ return magicStringTransformResult(string);
517
511
  }
518
512
  //#endregion
519
513
  export { hasExportAllCandidate, hasServerExportCandidate, stripServerExports, validatePageExports };
@@ -1,14 +1,15 @@
1
1
  import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
+ import { NODE_MODULES_PATH_RE, stripViteModuleQuery } from "../utils/path.js";
3
+ import { SCRIPT_MODULE_ID_RE, walkAst } from "./ast-utils.js";
2
4
  import { createRequire } from "node:module";
3
5
  import { parseAst } from "vite";
4
6
  import { pathToFileURL } from "node:url";
5
7
  //#region src/plugins/styled-jsx.ts
6
8
  const STYLED_JSX_IMPORT_RE = /^styled-jsx(?:\/.*)?$/;
7
- const NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
8
9
  const STYLED_JSX_SOURCE_RE = /(?:<style\b|from\s+["']styled-jsx\/css["']|require\s*\(\s*["']styled-jsx\/css["']\s*\))/;
9
10
  const STYLED_JSX_CSS_RE = /(?:from\s+["']styled-jsx\/css["']|require\s*\(\s*["']styled-jsx\/css["']\s*\))/;
10
11
  function hasStyledJsxTag(source, id) {
11
- const cleanId = id.split("?")[0];
12
+ const cleanId = stripViteModuleQuery(id);
12
13
  const extension = path.extname(cleanId);
13
14
  const lang = extension === ".ts" || extension === ".mts" || extension === ".cts" ? "ts" : "tsx";
14
15
  let ast;
@@ -17,13 +18,9 @@ function hasStyledJsxTag(source, id) {
17
18
  } catch {
18
19
  return false;
19
20
  }
20
- const pending = [ast];
21
- const visited = /* @__PURE__ */ new Set();
22
- while (pending.length > 0) {
23
- const value = pending.pop();
24
- if (!value || typeof value !== "object" || visited.has(value)) continue;
25
- visited.add(value);
26
- const node = value;
21
+ let found = false;
22
+ walkAst(ast, (node) => {
23
+ if (found) return false;
27
24
  if (node.type === "JSXOpeningElement") {
28
25
  const name = node.name;
29
26
  if (name?.type === "JSXIdentifier" && name.name === "style") {
@@ -31,13 +28,14 @@ function hasStyledJsxTag(source, id) {
31
28
  if (attribute.type !== "JSXAttribute") return false;
32
29
  const attributeName = attribute.name;
33
30
  return attributeName?.type === "JSXIdentifier" && attributeName.name === "jsx";
34
- })) return true;
31
+ })) {
32
+ found = true;
33
+ return false;
34
+ }
35
35
  }
36
36
  }
37
- for (const child of Object.values(node)) if (Array.isArray(child)) pending.push(...child);
38
- else if (child && typeof child === "object") pending.push(child);
39
- }
40
- return false;
37
+ });
38
+ return found;
41
39
  }
42
40
  function createProjectRequire(projectRoot) {
43
41
  return createRequire(path.join(projectRoot, "package.json"));
@@ -50,7 +48,7 @@ function resolveNextRequire(projectRoot) {
50
48
  }
51
49
  }
52
50
  function parserOptions(id) {
53
- const extension = path.extname(id.split("?")[0]);
51
+ const extension = path.extname(stripViteModuleQuery(id));
54
52
  if (extension === ".ts" || extension === ".tsx") return {
55
53
  syntax: "typescript",
56
54
  tsx: extension === ".tsx",
@@ -110,19 +108,19 @@ function createStyledJsxPlugin(initialProjectRoot, options = {}) {
110
108
  transform: {
111
109
  filter: {
112
110
  id: {
113
- include: /\.[cm]?[jt]sx?(?:\?.*)?$/,
114
- exclude: NODE_MODULES_RE
111
+ include: SCRIPT_MODULE_ID_RE,
112
+ exclude: NODE_MODULES_PATH_RE
115
113
  },
116
114
  code: STYLED_JSX_SOURCE_RE
117
115
  },
118
116
  async handler(source, id) {
119
- if (NODE_MODULES_RE.test(id.split("?")[0])) return null;
117
+ if (NODE_MODULES_PATH_RE.test(stripViteModuleQuery(id))) return null;
120
118
  const hasStyledJsxCss = STYLED_JSX_CSS_RE.test(source);
121
119
  const hasStyledJsxElement = !hasStyledJsxCss && hasStyledJsxTag(source, id);
122
120
  if (!hasStyledJsxCss && !hasStyledJsxElement) return null;
123
121
  if (!getNextRequire()) throw new Error("[vinext] styled-jsx requires an installed next package so vinext can use its matching compiler.");
124
122
  const result = await (await getCompiler()).transform(source, {
125
- filename: id.split("?")[0],
123
+ filename: stripViteModuleQuery(id),
126
124
  sourceMaps: true,
127
125
  module: { type: "es6" },
128
126
  styledJsx: { useLightningcss: false },
@@ -0,0 +1,10 @@
1
+ import MagicString from "magic-string";
2
+ //#region src/plugins/transform-result.d.ts
3
+ type MagicStringTransformResult = {
4
+ code: string;
5
+ map: ReturnType<MagicString["generateMap"]>;
6
+ };
7
+ /** Build the standard code + sourcemap result returned by source transforms. */
8
+ declare function magicStringTransformResult(output: MagicString, options?: Parameters<MagicString["generateMap"]>[0]): MagicStringTransformResult;
9
+ //#endregion
10
+ export { MagicStringTransformResult, magicStringTransformResult };
@@ -0,0 +1,10 @@
1
+ //#region src/plugins/transform-result.ts
2
+ /** Build the standard code + sourcemap result returned by source transforms. */
3
+ function magicStringTransformResult(output, options = { hires: "boundary" }) {
4
+ return {
5
+ code: output.toString(),
6
+ map: output.generateMap(options)
7
+ };
8
+ }
9
+ //#endregion
10
+ export { magicStringTransformResult };
@@ -1,24 +1,10 @@
1
- import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { stripViteModuleQuery } from "../utils/path.js";
1
+ import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
+ import { canonicalizeFilePath, stripViteModuleQuery } from "../utils/path.js";
3
+ import { BARE_PACKAGE_SPECIFIER_RE, packageNameFromSpecifier } from "../utils/package-name.js";
4
+ import { isServerEnvironment } from "./environment.js";
3
5
  import { createRequire } from "node:module";
4
- import fs from "node:fs";
5
6
  import { createIdResolver } from "vite";
6
7
  //#region src/plugins/transitive-externals.ts
7
- const BARE_PACKAGE_SPECIFIER_RE = /^(?:@[A-Za-z0-9._~-]+\/[A-Za-z0-9._~-]+|[A-Za-z0-9_~-][A-Za-z0-9._~-]*)(?:\/[^?#]*)?$/;
8
- function realpath(resolvedPath) {
9
- try {
10
- return toSlash(fs.realpathSync.native(resolvedPath));
11
- } catch {
12
- return toSlash(resolvedPath);
13
- }
14
- }
15
- function packageNameFromSpecifier(specifier) {
16
- if (specifier.startsWith("@")) {
17
- const parts = specifier.split("/");
18
- return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : null;
19
- }
20
- return specifier.split("/")[0] || null;
21
- }
22
8
  function moduleMode(kind) {
23
9
  return kind === "require-call" ? "require" : "import";
24
10
  }
@@ -29,9 +15,9 @@ function moduleMode(kind) {
29
15
  * same root-level package.
30
16
  */
31
17
  function compareTransitiveExternalResolutions(importerResolution, rootResolution) {
32
- const importerRealpath = realpath(importerResolution);
18
+ const importerRealpath = canonicalizeFilePath(importerResolution);
33
19
  if (!rootResolution) return importerRealpath;
34
- return importerRealpath === realpath(rootResolution) ? null : importerRealpath;
20
+ return importerRealpath === canonicalizeFilePath(rootResolution) ? null : importerRealpath;
35
21
  }
36
22
  /**
37
23
  * CommonJS fallback used when Vite cannot resolve a require-call with its
@@ -77,7 +63,7 @@ function createTransitiveExternalsPlugin(options) {
77
63
  apply: "build",
78
64
  enforce: "pre",
79
65
  applyToEnvironment(environment) {
80
- return environment.name !== "client" && environment.config.consumer !== "client";
66
+ return isServerEnvironment(environment);
81
67
  },
82
68
  configResolved(config) {
83
69
  const root = options.getRoot();
@@ -1,3 +1,4 @@
1
+ import { MagicStringTransformResult } from "./transform-result.js";
1
2
  //#region src/plugins/typeof-window.d.ts
2
3
  type WindowType = "object" | "undefined";
3
4
  declare const consumerEnvironmentConditionFilter: RegExp;
@@ -12,13 +13,7 @@ type EnvironmentLike = {
12
13
  };
13
14
  };
14
15
  declare function getTypeofWindowReplacement(environment: EnvironmentLike): WindowType;
15
- declare function replaceTypeofWindow(code: string, replacement: WindowType, id?: string): {
16
- code: string;
17
- map: import("magic-string").SourceMap;
18
- } | null;
19
- declare function replaceConsumerEnvironmentConditions(code: string, replacements: ConsumerEnvironmentReplacements, id?: string): {
20
- code: string;
21
- map: import("magic-string").SourceMap;
22
- } | null;
16
+ declare function replaceTypeofWindow(code: string, replacement: WindowType, id?: string): MagicStringTransformResult | null;
17
+ declare function replaceConsumerEnvironmentConditions(code: string, replacements: ConsumerEnvironmentReplacements, id?: string): MagicStringTransformResult | null;
23
18
  //#endregion
24
19
  export { ConsumerEnvironmentReplacements, consumerEnvironmentConditionFilter, getTypeofWindowReplacement, replaceConsumerEnvironmentConditions, replaceTypeofWindow };
@@ -1,5 +1,7 @@
1
1
  import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { collectBindingNames, forEachAstChild, hasRange, isAstRecord, isIdentifierNamed, nodeArray } from "./ast-utils.js";
2
+ import { stripViteModuleQuery } from "../utils/path.js";
3
+ import { magicStringTransformResult } from "./transform-result.js";
4
+ import { booleanLiteralValue, collectBindingNames, forEachAstChild, hasRange, isAstRecord, isIdentifierNamed, nodeArray, stringLiteralValue } from "./ast-utils.js";
3
5
  import { collectDirectScopeBindings, collectLoopScopeBindings, collectSwitchScopeBindings, collectVarScopeBindings, createAstScope, hasAstBinding, isFunctionNode } from "./ast-scope.js";
4
6
  import { parseAst } from "vite";
5
7
  import MagicString from "magic-string";
@@ -19,11 +21,6 @@ function createChildScope(node, parent) {
19
21
  function getTypeofWindowReplacement(environment) {
20
22
  return environment.config.consumer === "client" ? "object" : "undefined";
21
23
  }
22
- function stringLiteralValue(node) {
23
- if (!isAstRecord(node)) return null;
24
- if (node.type === "Literal" && typeof node.value === "string") return node.value;
25
- return null;
26
- }
27
24
  function evaluateTypeofWindowComparison(node, replacement, scope) {
28
25
  if (!isAstRecord(node) || node.type !== "BinaryExpression") return null;
29
26
  if (![
@@ -46,10 +43,6 @@ function isProcessBrowserMember(node, scope) {
46
43
  if (!isAstRecord(candidate) || candidate.type !== "MemberExpression") return false;
47
44
  return isIdentifierNamed(candidate.object, "process") && (candidate.computed ? stringLiteralValue(candidate.property) === "browser" : isIdentifierNamed(candidate.property, "browser")) && !hasAstBinding(scope, "process");
48
45
  }
49
- function booleanLiteralValue(node) {
50
- if (!isAstRecord(node) || node.type !== "Literal" || typeof node.value !== "boolean") return null;
51
- return node.value;
52
- }
53
46
  function evaluateProcessBrowserCondition(node, replacement, scope) {
54
47
  if (isProcessBrowserMember(node, scope)) return replacement;
55
48
  if (isAstRecord(node) && node.type === "UnaryExpression" && node.operator === "!") {
@@ -125,7 +118,7 @@ function replaceConsumerEnvironmentConditions(code, replacements, id = "file.js"
125
118
  const mayContainTypeofWindow = replacements.typeofWindow !== void 0 && /typeof\s+window/.test(code);
126
119
  const mayContainProcessBrowser = replacements.processBrowser !== void 0 && (/\bprocess\b/.test(code) && /\bbrowser\b/.test(code) || sourceEscapePattern.test(code));
127
120
  if (!mayContainTypeofWindow && !mayContainProcessBrowser) return null;
128
- const extension = path.extname(id.split("?", 1)[0]);
121
+ const extension = path.extname(stripViteModuleQuery(id));
129
122
  const lang = extension === ".ts" || extension === ".mts" || extension === ".cts" ? "ts" : extension === ".tsx" ? "tsx" : extension === ".jsx" ? "jsx" : "js";
130
123
  let ast;
131
124
  try {
@@ -241,10 +234,7 @@ function replaceConsumerEnvironmentConditions(code, replacements, id = "file.js"
241
234
  }
242
235
  for (const node of ast.body) if (isAstRecord(node)) visit(node, rootScope);
243
236
  if (!changed) return null;
244
- return {
245
- code: output.toString(),
246
- map: output.generateMap({ hires: "boundary" })
247
- };
237
+ return magicStringTransformResult(output);
248
238
  }
249
239
  //#endregion
250
240
  export { consumerEnvironmentConditionFilter, getTypeofWindowReplacement, replaceConsumerEnvironmentConditions, replaceTypeofWindow };
@@ -1,12 +1,12 @@
1
1
  import path from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { stripViteModuleQuery } from "../utils/path.js";
2
+ import { NODE_MODULES_PATH_RE, isPathInside, stripViteModuleQuery } from "../utils/path.js";
3
+ import { magicStringTransformResult } from "./transform-result.js";
3
4
  import { createRequire } from "node:module";
4
5
  import { parseAstAsync } from "vite";
5
6
  import { pathToFileURL } from "node:url";
6
7
  //#region src/plugins/use-cache-callable.ts
7
8
  const PLUGIN_NAME = "vinext:server-function-directives";
8
9
  const SOURCE_MODULE_ID_RE = /\.(?:tsx?|jsx?|mjs)(?:\?.*)?$/;
9
- const DEPENDENCY_MODULE_ID_RE = /[\\/]node_modules[\\/]/;
10
10
  const RESOLVED_VIRTUAL_MODULE_ID_RE = new RegExp(`^${String.fromCharCode(0)}`);
11
11
  const USE_CACHE_DIRECTIVE = /^use cache(?:: ([^\s].*))?$/;
12
12
  const USE_CACHE_DIRECTIVE_CANDIDATE = /^use cache.*$/;
@@ -43,16 +43,12 @@ function acceptsSecondArgument(meta) {
43
43
  if (node?.type !== "FunctionDeclaration" && node?.type !== "FunctionExpression" && node?.type !== "ArrowFunctionExpression") return true;
44
44
  return node.params.length >= 2 || node.params.some((parameter) => parameter.type === "RestElement");
45
45
  }
46
- function isInsideDirectory(directory, filePath) {
47
- const relativePath = path.relative(directory, filePath);
48
- return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
49
- }
50
46
  function isAppPageDefaultExport(options, id, name, isModuleDirective) {
51
47
  const appDir = options.getAppDir();
52
48
  if (!isModuleDirective || name !== "default" || !appDir) return false;
53
49
  const modulePath = stripViteModuleQuery(id);
54
50
  const moduleFileName = path.basename(modulePath);
55
- return isInsideDirectory(appDir, modulePath) && path.parse(moduleFileName).name === "page" && options.matchesPageExtension(moduleFileName);
51
+ return isPathInside(appDir, modulePath) && path.parse(moduleFileName).name === "page" && options.matchesPageExtension(moduleFileName);
56
52
  }
57
53
  function shouldTransformModuleExport(name, id, meta) {
58
54
  if (meta.isFunction === false && (name !== "default" && meta.valueNode?.type === "Literal" || meta.valueNode?.type === "ObjectExpression" || meta.valueNode?.type === "ArrayExpression")) return false;
@@ -100,7 +96,7 @@ async function createUseCacheCallablePlugin(options) {
100
96
  transform: {
101
97
  filter: { id: {
102
98
  include: SOURCE_MODULE_ID_RE,
103
- exclude: [DEPENDENCY_MODULE_ID_RE, RESOLVED_VIRTUAL_MODULE_ID_RE]
99
+ exclude: [NODE_MODULES_PATH_RE, RESOLVED_VIRTUAL_MODULE_ID_RE]
104
100
  } },
105
101
  async handler(code, id) {
106
102
  if (!manager) return;
@@ -150,13 +146,10 @@ async function createUseCacheCallablePlugin(options) {
150
146
  });
151
147
  const runtimeEnvironment = this.environment.name === "client" ? "browser" : "ssr";
152
148
  result.output.prepend(`import * as $$ReactClient from "@vitejs/plugin-rsc/react/${runtimeEnvironment}";\n`);
153
- return {
154
- code: result.output.toString(),
155
- map: result.output.generateMap({
156
- hires: "boundary",
157
- source: id
158
- })
159
- };
149
+ return magicStringTransformResult(result.output, {
150
+ hires: "boundary",
151
+ source: id
152
+ });
160
153
  }
161
154
  const wrap = (value, name, directiveMatch, meta, isModuleDirective) => {
162
155
  const variant = directiveMatch[1] ?? "";
@@ -194,13 +187,10 @@ async function createUseCacheCallablePlugin(options) {
194
187
  });
195
188
  const importPosition = ast.body.find((node) => !("directive" in node))?.start ?? code.length;
196
189
  result.output.prependLeft(importPosition, [`import * as $$cacheRuntime from ${JSON.stringify(options.cacheRuntime)};`, needsReactServer && `import * as $$VinextReactServer from "@vitejs/plugin-rsc/react/rsc/server";`].filter(Boolean).join("\n") + "\n");
197
- return {
198
- code: result.output.toString(),
199
- map: result.output.generateMap({
200
- hires: "boundary",
201
- source: id
202
- })
203
- };
190
+ return magicStringTransformResult(result.output, {
191
+ hires: "boundary",
192
+ source: id
193
+ });
204
194
  }
205
195
  }
206
196
  };
@@ -18,7 +18,7 @@ function createWasmModuleImportPlugin() {
18
18
  filter: { id: /\.wasm\?module$/ },
19
19
  async handler(source, importer) {
20
20
  if (this.environment?.name === "client") return null;
21
- if ((importer ? (importer.startsWith("\0") ? importer.slice(1) : importer).split("?")[0] : "").includes("@vercel/og")) return null;
21
+ if ((importer ? stripViteModuleQuery(importer.startsWith("\0") ? importer.slice(1) : importer) : "").includes("@vercel/og")) return null;
22
22
  const resolved = await this.resolve(source, importer, { skipSelf: true });
23
23
  if (!resolved) return null;
24
24
  if (resolved.external) return resolved;
@@ -0,0 +1,12 @@
1
+ import { Plugin } from "vite";
2
+ //#region src/plugins/worker-image-imports.d.ts
3
+ /**
4
+ * Preserve Next.js's StaticImageData shape for dynamic image imports inside
5
+ * Vite worker graphs. Worker builds use their own plugin container, so the
6
+ * top-level vinext:image-imports plugin cannot perform this transform.
7
+ */
8
+ declare function createWorkerImageImportsPlugin(options?: {
9
+ deploymentId?: string;
10
+ }): Plugin;
11
+ //#endregion
12
+ export { createWorkerImageImportsPlugin };
@@ -0,0 +1,136 @@
1
+ import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
+ import { appendDeploymentIdQuery } from "../utils/deployment-id.js";
3
+ import { NODE_MODULES_PATH_RE, stripViteModuleQuery } from "../utils/path.js";
4
+ import { magicStringTransformResult } from "./transform-result.js";
5
+ import { staticStringValue, walkAst } from "./ast-utils.js";
6
+ import fs from "node:fs";
7
+ import { parseAst } from "vite";
8
+ import MagicString from "magic-string";
9
+ //#region src/plugins/worker-image-imports.ts
10
+ const WORKER_IMAGE_METADATA_PREFIX = "\0vinext-worker-image-meta:";
11
+ const WORKER_IMAGE_METADATA_RE = /^\0vinext-worker-image-meta:/;
12
+ const WORKER_SCRIPT_RE = /\.(?:[cm]?[jt]sx?)$/;
13
+ const WORKER_IMAGE_DYNAMIC_IMPORT_RE = /import\(\s*["'][^"']+\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?)["']\s*\)/;
14
+ const WORKER_IMAGE_EXTENSION_RE = /\.(?:png|jpe?g|gif|webp|avif|svg|ico|bmp|tiff?)$/;
15
+ function workerChunkSpecifier(hostFileName, targetFileName) {
16
+ const relative = path.relative(path.dirname(hostFileName), targetFileName);
17
+ return relative.startsWith(".") ? relative : `./${relative}`;
18
+ }
19
+ /**
20
+ * Preserve Next.js's StaticImageData shape for dynamic image imports inside
21
+ * Vite worker graphs. Worker builds use their own plugin container, so the
22
+ * top-level vinext:image-imports plugin cannot perform this transform.
23
+ */
24
+ function createWorkerImageImportsPlugin(options = {}) {
25
+ const dimensionCache = /* @__PURE__ */ new Map();
26
+ return {
27
+ name: "vinext:worker-image-imports",
28
+ enforce: "pre",
29
+ watchChange(id) {
30
+ dimensionCache.delete(toSlash(id));
31
+ },
32
+ resolveId: {
33
+ filter: { id: WORKER_IMAGE_METADATA_RE },
34
+ handler(source) {
35
+ return source;
36
+ }
37
+ },
38
+ load: {
39
+ filter: { id: WORKER_IMAGE_METADATA_RE },
40
+ async handler(id) {
41
+ const imagePath = id.slice(26);
42
+ this.addWatchFile(imagePath);
43
+ let dimensions = dimensionCache.get(imagePath);
44
+ if (!dimensions) {
45
+ try {
46
+ const { imageSize } = await import("../deps/.pnpm/image-size@2.0.2/deps/image-size/dist/index.js");
47
+ const result = imageSize(fs.readFileSync(imagePath));
48
+ dimensions = {
49
+ width: result.width ?? 0,
50
+ height: result.height ?? 0
51
+ };
52
+ } catch {
53
+ dimensions = {
54
+ width: 0,
55
+ height: 0
56
+ };
57
+ }
58
+ dimensionCache.set(imagePath, dimensions);
59
+ }
60
+ return `export default ${JSON.stringify(dimensions)};`;
61
+ }
62
+ },
63
+ transform: {
64
+ filter: {
65
+ id: {
66
+ include: WORKER_SCRIPT_RE,
67
+ exclude: NODE_MODULES_PATH_RE
68
+ },
69
+ code: WORKER_IMAGE_DYNAMIC_IMPORT_RE
70
+ },
71
+ async handler(code, id) {
72
+ const sourceId = toSlash(stripViteModuleQuery(id));
73
+ let ast;
74
+ try {
75
+ ast = parseAst(code, { lang: /\.(?:[cm]?ts)$/.test(sourceId) ? "ts" : "tsx" });
76
+ } catch {
77
+ return null;
78
+ }
79
+ const output = new MagicString(code);
80
+ const imageImports = [];
81
+ walkAst(ast, (value) => {
82
+ const node = value;
83
+ if (node.type === "ImportExpression" && typeof node.start === "number" && typeof node.end === "number" && node.source?.type === "Literal" && typeof node.source.value === "string" && WORKER_IMAGE_EXTENSION_RE.test(node.source.value)) {
84
+ imageImports.push({
85
+ end: node.end,
86
+ importPath: node.source.value,
87
+ start: node.start
88
+ });
89
+ return false;
90
+ }
91
+ });
92
+ let changed = false;
93
+ for (const imageImport of imageImports) {
94
+ const resolved = await this.resolve(imageImport.importPath, sourceId, { skipSelf: true });
95
+ const resolvedId = resolved ? stripViteModuleQuery(resolved.id) : void 0;
96
+ const imagePath = resolvedId ? toSlash(resolvedId) : imageImport.importPath.startsWith(".") ? path.resolve(path.dirname(sourceId), imageImport.importPath) : null;
97
+ if (!imagePath || !fs.existsSync(imagePath)) continue;
98
+ output.overwrite(imageImport.start, imageImport.end, `Promise.all([import(${JSON.stringify(imageImport.importPath)}), import(${JSON.stringify(WORKER_IMAGE_METADATA_PREFIX + imagePath)})]).then(([url, metadata]) => ({ default: { src: url.default, width: metadata.default.width, height: metadata.default.height } }))`);
99
+ changed = true;
100
+ }
101
+ if (!changed) return null;
102
+ return magicStringTransformResult(output);
103
+ }
104
+ },
105
+ renderChunk: {
106
+ order: "pre",
107
+ handler(code, chunk) {
108
+ if (!options.deploymentId) return null;
109
+ const chunkSpecifiers = new Set([...chunk.imports, ...chunk.dynamicImports].map((target) => workerChunkSpecifier(chunk.fileName, target)));
110
+ if (chunkSpecifiers.size === 0) return null;
111
+ let ast;
112
+ try {
113
+ ast = parseAst(code);
114
+ } catch {
115
+ return null;
116
+ }
117
+ const output = new MagicString(code);
118
+ let changed = false;
119
+ walkAst(ast, (value) => {
120
+ const node = value;
121
+ const source = node.type === "ImportExpression" || node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration" ? node.source : null;
122
+ const specifier = staticStringValue(source);
123
+ if (specifier !== null && chunkSpecifiers.has(specifier) && typeof source?.start === "number" && typeof source.end === "number") {
124
+ output.overwrite(source.start, source.end, JSON.stringify(appendDeploymentIdQuery(specifier, options.deploymentId)));
125
+ changed = true;
126
+ return false;
127
+ }
128
+ });
129
+ if (!changed) return null;
130
+ return magicStringTransformResult(output);
131
+ }
132
+ }
133
+ };
134
+ }
135
+ //#endregion
136
+ export { createWorkerImageImportsPlugin };
@@ -1,5 +1,5 @@
1
- import { ValidFileMatcher } from "./file-matcher.js";
2
1
  import { isInvisibleSegment } from "./utils.js";
2
+ import { ValidFileMatcher } from "./file-matcher.js";
3
3
  //#region src/routing/app-route-graph.d.ts
4
4
  type InterceptingRoute = {
5
5
  /** Graph-owned identity for this interception edge. */
@@ -364,6 +364,7 @@ type RouteManifest = {
364
364
  graphVersion: GraphVersion;
365
365
  segmentGraph: StaticSegmentGraph;
366
366
  };
367
+ declare function createAppRouteGraphInterceptionId(slotId: string, sourcePattern: string, targetPattern: string): string;
367
368
  /**
368
369
  * Build the App Router route graph by scanning `appDir`.
369
370
  */
@@ -426,4 +427,4 @@ declare function computeAppRouteStaticSiblings(allRoutes: readonly {
426
427
  patternParts?: readonly string[] | null;
427
428
  }): string[];
428
429
  //#endregion
429
- export { AppRoute, AppRouteGraphRoute, AppRouteSemanticIds, GraphVersion, RootBoundaryId, RouteManifest, RouteManifestInterception, RouteManifestRootBoundary, RouteManifestRoute, RouteManifestSlotBinding, StaticSegmentGraph, buildAppRouteGraph, computeAppRouteStaticSiblings, computeRootParamNames, convertSegmentsToRouteParts, findOwnerRouteForDir, isInvisibleSegment, patternsStructurallyEquivalent };
430
+ export { AppRoute, AppRouteGraphRoute, AppRouteSemanticIds, GraphVersion, RootBoundaryId, RouteManifest, RouteManifestInterception, RouteManifestRootBoundary, RouteManifestRoute, RouteManifestSlotBinding, StaticSegmentGraph, buildAppRouteGraph, computeAppRouteStaticSiblings, computeRootParamNames, convertSegmentsToRouteParts, createAppRouteGraphInterceptionId, findOwnerRouteForDir, isInvisibleSegment, patternsStructurallyEquivalent };
@@ -1752,4 +1752,4 @@ function computeAppRouteStaticSiblings(allRoutes, matchedRoute) {
1752
1752
  return Array.from(siblings);
1753
1753
  }
1754
1754
  //#endregion
1755
- export { buildAppRouteGraph, computeAppRouteStaticSiblings, computeRootParamNames, convertSegmentsToRouteParts, findOwnerRouteForDir, isInvisibleSegment, patternsStructurallyEquivalent };
1755
+ export { buildAppRouteGraph, computeAppRouteStaticSiblings, computeRootParamNames, convertSegmentsToRouteParts, createAppRouteGraphInterceptionId, findOwnerRouteForDir, isInvisibleSegment, patternsStructurallyEquivalent };
@@ -5,6 +5,13 @@ declare function routePattern(pathname: string): string;
5
5
  declare function fillRoutePatternSegments(pathname: string, params: RoutePatternParams): string | null;
6
6
  declare function matchRoutePattern(urlParts: readonly string[], patternParts: readonly string[]): RoutePatternParams | null;
7
7
  declare function matchRoutePatternRaw(urlParts: readonly string[], patternParts: readonly string[]): RoutePatternParams | null;
8
+ /**
9
+ * Extract params from the original encoded URL parts after route selection has
10
+ * already succeeded against normalized parts. Static parts are positional and
11
+ * intentionally not compared because their raw encoding can differ from the
12
+ * normalized route spelling (for example `%5Fsites` versus `_sites`).
13
+ */
14
+ declare function extractRawRoutePatternParams(patternParts: readonly string[], urlParts: readonly string[]): RoutePatternParams;
8
15
  declare function matchRoutePatternPrefix(pathParts: readonly string[], patternParts: readonly string[]): boolean;
9
16
  declare function matchRoutePatternWithOptionalDynamicSegments(pathParts: readonly string[], patternParts: readonly string[]): boolean;
10
17
  /**
@@ -62,4 +69,4 @@ declare function normalizeStaticPathname(pathname: string): string;
62
69
  */
63
70
  declare function normalizeStaticPathsEntry(entry: StaticPathsEntry, routePattern: string): NormalizedStaticPathsEntry;
64
71
  //#endregion
65
- export { RoutePatternParams, StaticPathsEntry, fillRoutePatternSegments, matchRoutePattern, matchRoutePatternPrefix, matchRoutePatternRaw, matchRoutePatternWithOptionalDynamicSegments, normalizeStaticPathname, normalizeStaticPathsEntry, routePattern, routePatternParts };
72
+ export { RoutePatternParams, StaticPathsEntry, extractRawRoutePatternParams, fillRoutePatternSegments, matchRoutePattern, matchRoutePatternPrefix, matchRoutePatternRaw, matchRoutePatternWithOptionalDynamicSegments, normalizeStaticPathname, normalizeStaticPathsEntry, routePattern, routePatternParts };