vinext 0.1.4 → 0.1.6

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 +2 -2
  2. package/dist/build/css-url-assets.d.ts +1 -1
  3. package/dist/build/css-url-assets.js +9 -7
  4. package/dist/build/google-fonts/find-font-files-in-css.d.ts +16 -0
  5. package/dist/build/google-fonts/find-font-files-in-css.js +28 -0
  6. package/dist/build/prerender.js +2 -1
  7. package/dist/build/report.d.ts +1 -2
  8. package/dist/build/report.js +2 -11
  9. package/dist/build/run-prerender.js +1 -1
  10. package/dist/cache/cache-adapters-virtual.js +1 -1
  11. package/dist/check.js +3 -3
  12. package/dist/client/pages-router-link-navigation.d.ts +10 -0
  13. package/dist/client/pages-router-link-navigation.js +3 -3
  14. package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
  15. package/dist/deploy.js +3 -3
  16. package/dist/entries/app-rsc-entry.js +25 -20
  17. package/dist/entries/app-rsc-manifest.js +76 -46
  18. package/dist/entries/pages-server-entry.js +3 -1
  19. package/dist/index.js +254 -198
  20. package/dist/init.d.ts +5 -4
  21. package/dist/init.js +27 -8
  22. package/dist/plugins/css-data-url.js +30 -26
  23. package/dist/plugins/extensionless-dynamic-import.js +27 -24
  24. package/dist/plugins/fonts.js +3 -1
  25. package/dist/plugins/import-meta-url.js +21 -15
  26. package/dist/plugins/instrumentation-client.js +1 -1
  27. package/dist/plugins/middleware-export-validation.d.ts +5 -0
  28. package/dist/plugins/middleware-export-validation.js +36 -0
  29. package/dist/plugins/middleware-server-only.js +7 -6
  30. package/dist/plugins/og-asset-ownership.d.ts +27 -0
  31. package/dist/plugins/og-asset-ownership.js +285 -0
  32. package/dist/plugins/og-assets.js +66 -46
  33. package/dist/plugins/optimize-imports.js +9 -3
  34. package/dist/plugins/remove-console.d.ts +7 -1
  35. package/dist/plugins/remove-console.js +4 -1
  36. package/dist/plugins/require-context.js +21 -20
  37. package/dist/plugins/strip-server-exports.d.ts +7 -1
  38. package/dist/plugins/strip-server-exports.js +4 -1
  39. package/dist/server/accept-encoding.d.ts +29 -0
  40. package/dist/server/accept-encoding.js +95 -0
  41. package/dist/server/app-bfcache-identity.d.ts +26 -0
  42. package/dist/server/app-bfcache-identity.js +127 -0
  43. package/dist/server/app-browser-entry.js +17 -11
  44. package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
  45. package/dist/server/app-browser-rsc-redirect.js +8 -1
  46. package/dist/server/app-browser-state.d.ts +2 -21
  47. package/dist/server/app-browser-state.js +4 -128
  48. package/dist/server/app-browser-stream.js +1 -1
  49. package/dist/server/app-browser-visible-commit.js +3 -2
  50. package/dist/server/app-fallback-renderer.d.ts +1 -1
  51. package/dist/server/app-layout-param-observation.d.ts +1 -1
  52. package/dist/server/app-layout-param-observation.js +1 -1
  53. package/dist/server/app-middleware.d.ts +1 -0
  54. package/dist/server/app-middleware.js +3 -1
  55. package/dist/server/app-page-boundary-render.d.ts +1 -1
  56. package/dist/server/app-page-boundary.js +1 -1
  57. package/dist/server/app-page-cache-finalizer.d.ts +62 -0
  58. package/dist/server/app-page-cache-finalizer.js +122 -0
  59. package/dist/server/app-page-cache-render.d.ts +2 -2
  60. package/dist/server/app-page-cache-render.js +1 -1
  61. package/dist/server/app-page-cache.d.ts +2 -53
  62. package/dist/server/app-page-cache.js +5 -131
  63. package/dist/server/app-page-dispatch.d.ts +4 -4
  64. package/dist/server/app-page-dispatch.js +10 -8
  65. package/dist/server/app-page-head.js +2 -2
  66. package/dist/server/app-page-probe.js +3 -2
  67. package/dist/server/app-page-render-observation.js +2 -2
  68. package/dist/server/app-page-render.d.ts +3 -3
  69. package/dist/server/app-page-render.js +3 -2
  70. package/dist/server/app-page-request.d.ts +7 -0
  71. package/dist/server/app-page-request.js +19 -1
  72. package/dist/server/app-page-stream.d.ts +2 -9
  73. package/dist/server/app-page-stream.js +1 -35
  74. package/dist/server/app-prerender-endpoints.d.ts +3 -3
  75. package/dist/server/app-prerender-endpoints.js +3 -4
  76. package/dist/server/app-request-context.d.ts +1 -2
  77. package/dist/server/app-request-context.js +2 -1
  78. package/dist/server/app-route-handler-dispatch.js +3 -2
  79. package/dist/server/app-route-handler-execution.d.ts +1 -1
  80. package/dist/server/app-route-handler-execution.js +1 -1
  81. package/dist/server/app-route-handler-response.d.ts +1 -1
  82. package/dist/server/app-route-module-loader.d.ts +62 -14
  83. package/dist/server/app-route-module-loader.js +61 -10
  84. package/dist/server/app-router-entry.js +2 -1
  85. package/dist/server/app-rsc-handler.d.ts +7 -6
  86. package/dist/server/app-rsc-handler.js +51 -40
  87. package/dist/server/app-rsc-response-finalizer.js +1 -1
  88. package/dist/server/app-rsc-route-matching.d.ts +9 -0
  89. package/dist/server/app-rsc-route-matching.js +13 -0
  90. package/dist/server/app-server-action-execution.d.ts +1 -1
  91. package/dist/server/app-server-action-execution.js +5 -4
  92. package/dist/server/app-ssr-entry.d.ts +1 -1
  93. package/dist/server/app-ssr-entry.js +9 -7
  94. package/dist/server/app-ssr-router-instance.d.ts +6 -0
  95. package/dist/server/app-ssr-router-instance.js +24 -0
  96. package/dist/server/app-ssr-stream.js +1 -1
  97. package/dist/server/artifact-compatibility.js +1 -1
  98. package/dist/server/client-reuse-manifest.js +1 -1
  99. package/dist/server/defer-until-stream-consumed.d.ts +7 -0
  100. package/dist/server/defer-until-stream-consumed.js +34 -0
  101. package/dist/server/dev-server.js +1 -1
  102. package/dist/server/headers.d.ts +5 -1
  103. package/dist/server/headers.js +5 -1
  104. package/dist/server/instrumentation.js +1 -1
  105. package/dist/server/isr-cache.d.ts +1 -1
  106. package/dist/server/isr-cache.js +1 -1
  107. package/dist/server/isr-decision.d.ts +1 -1
  108. package/dist/server/metadata-route-response.d.ts +3 -3
  109. package/dist/server/middleware-matcher.js +8 -6
  110. package/dist/server/middleware-runtime.d.ts +2 -1
  111. package/dist/server/middleware-runtime.js +21 -10
  112. package/dist/server/middleware.d.ts +2 -2
  113. package/dist/server/middleware.js +26 -11
  114. package/dist/server/open-redirect.d.ts +12 -0
  115. package/dist/server/open-redirect.js +21 -0
  116. package/dist/server/pages-page-data.d.ts +1 -1
  117. package/dist/server/pages-page-response.d.ts +1 -1
  118. package/dist/server/pages-page-response.js +2 -2
  119. package/dist/server/pages-request-pipeline.d.ts +3 -1
  120. package/dist/server/pages-request-pipeline.js +4 -2
  121. package/dist/server/prod-server.d.ts +1 -1
  122. package/dist/server/prod-server.js +87 -73
  123. package/dist/server/request-pipeline.d.ts +1 -24
  124. package/dist/server/request-pipeline.js +1 -33
  125. package/dist/server/seed-cache.d.ts +1 -1
  126. package/dist/shims/cache-handler.d.ts +106 -0
  127. package/dist/shims/cache-handler.js +176 -0
  128. package/dist/shims/cache-request-state.d.ts +47 -0
  129. package/dist/shims/cache-request-state.js +126 -0
  130. package/dist/shims/cache-runtime.d.ts +2 -2
  131. package/dist/shims/cache-runtime.js +3 -14
  132. package/dist/shims/cache.d.ts +3 -231
  133. package/dist/shims/cache.js +17 -383
  134. package/dist/shims/cdn-cache.d.ts +1 -1
  135. package/dist/shims/cdn-cache.js +1 -1
  136. package/dist/shims/error-boundary-navigation.d.ts +7 -0
  137. package/dist/shims/error-boundary-navigation.js +44 -0
  138. package/dist/shims/error-boundary.js +10 -8
  139. package/dist/shims/error.js +2 -1
  140. package/dist/shims/fetch-cache.js +1 -1
  141. package/dist/shims/font-google-base.d.ts +1 -0
  142. package/dist/shims/font-google-base.js +6 -21
  143. package/dist/shims/form.js +1 -1
  144. package/dist/shims/image.js +67 -9
  145. package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
  146. package/dist/shims/internal/app-page-props-cache-key.js +16 -0
  147. package/dist/shims/internal/interpolate-as.d.ts +25 -0
  148. package/dist/shims/internal/interpolate-as.js +196 -0
  149. package/dist/shims/internal/navigation-untracked.js +2 -1
  150. package/dist/shims/layout-segment-context.d.ts +1 -1
  151. package/dist/shims/layout-segment-context.js +2 -1
  152. package/dist/shims/link.js +26 -3
  153. package/dist/shims/navigation-context-state.d.ts +40 -0
  154. package/dist/shims/navigation-context-state.js +116 -0
  155. package/dist/shims/navigation-errors.d.ts +55 -0
  156. package/dist/shims/navigation-errors.js +110 -0
  157. package/dist/shims/navigation-server.d.ts +3 -0
  158. package/dist/shims/navigation-server.js +3 -0
  159. package/dist/shims/navigation-state.d.ts +1 -2
  160. package/dist/shims/navigation-state.js +2 -1
  161. package/dist/shims/navigation.d.ts +3 -291
  162. package/dist/shims/navigation.js +13 -444
  163. package/dist/shims/navigation.react-server.d.ts +2 -2
  164. package/dist/shims/navigation.react-server.js +4 -2
  165. package/dist/shims/request-state-types.d.ts +3 -3
  166. package/dist/shims/router.d.ts +1 -3
  167. package/dist/shims/router.js +62 -18
  168. package/dist/shims/script.js +1 -1
  169. package/dist/shims/slot.js +3 -1
  170. package/dist/shims/unified-request-context.d.ts +2 -2
  171. package/dist/typegen.js +2 -10
  172. package/dist/utils/project.d.ts +7 -1
  173. package/dist/utils/project.js +16 -2
  174. package/dist/utils/virtual-module.d.ts +5 -0
  175. package/dist/utils/virtual-module.js +0 -0
  176. package/package.json +7 -3
package/dist/init.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * 4. Rename CJS config files to .cjs
11
11
  * 5. Add vinext scripts to package.json
12
12
  * 6. Generate vite.config.ts
13
- * 7. Update .gitignore to include /dist/
13
+ * 7. Update .gitignore to include /dist/ and .vinext/
14
14
  * 8. Print summary
15
15
  *
16
16
  * Non-destructive: does NOT modify next.config, tsconfig, or source files.
@@ -32,7 +32,7 @@ type InitResult = {
32
32
  renamedConfigs: Array<[string, string]>; /** Whether scripts were added to package.json */
33
33
  addedScripts: string[]; /** Whether vite.config.ts was generated */
34
34
  generatedViteConfig: boolean; /** Whether vite.config.ts generation was skipped (already exists) */
35
- skippedViteConfig: boolean; /** Whether .gitignore was updated to include /dist/ */
35
+ skippedViteConfig: boolean; /** Whether .gitignore was updated to include vinext-generated output */
36
36
  updatedGitignore: boolean;
37
37
  };
38
38
  declare function generateViteConfig(_isAppRouter: boolean): string;
@@ -59,8 +59,9 @@ declare function isDepInstalled(root: string, dep: string): boolean;
59
59
  */
60
60
  declare function getReactUpgradeDeps(root: string): string[];
61
61
  /**
62
- * Ensure /dist/ is listed in .gitignore. Creates the file if it doesn't exist.
63
- * Returns true if the file was modified (or created), false if /dist/ was already present.
62
+ * Ensure vinext-generated output directories are listed in .gitignore.
63
+ * Creates the file if it doesn't exist. Returns true if the file was modified
64
+ * (or created), false if all entries were already present.
64
65
  */
65
66
  declare function updateGitignore(root: string): boolean;
66
67
  declare function init(options: InitOptions): Promise<InitResult>;
package/dist/init.js CHANGED
@@ -16,7 +16,7 @@ import { execFileSync } from "node:child_process";
16
16
  * 4. Rename CJS config files to .cjs
17
17
  * 5. Add vinext scripts to package.json
18
18
  * 6. Generate vite.config.ts
19
- * 7. Update .gitignore to include /dist/
19
+ * 7. Update .gitignore to include /dist/ and .vinext/
20
20
  * 8. Print summary
21
21
  *
22
22
  * Non-destructive: does NOT modify next.config, tsconfig, or source files.
@@ -140,20 +140,39 @@ function installDeps(root, deps, exec, { dev = true } = {}) {
140
140
  });
141
141
  }
142
142
  /**
143
- * Ensure /dist/ is listed in .gitignore. Creates the file if it doesn't exist.
144
- * Returns true if the file was modified (or created), false if /dist/ was already present.
143
+ * Ensure vinext-generated output directories are listed in .gitignore.
144
+ * Creates the file if it doesn't exist. Returns true if the file was modified
145
+ * (or created), false if all entries were already present.
145
146
  */
146
147
  function updateGitignore(root) {
147
148
  const gitignorePath = path.join(root, ".gitignore");
148
- const exactEntry = "/dist/";
149
+ const entries = [{
150
+ entry: "/dist/",
151
+ coveredBy: new Set([
152
+ "/dist/",
153
+ "/dist",
154
+ "dist/",
155
+ "dist"
156
+ ])
157
+ }, {
158
+ entry: ".vinext/",
159
+ coveredBy: new Set([
160
+ "/.vinext/",
161
+ "/.vinext",
162
+ ".vinext/",
163
+ ".vinext"
164
+ ])
165
+ }];
149
166
  let content = "";
167
+ let lines = [];
150
168
  if (fs.existsSync(gitignorePath)) {
151
169
  content = fs.readFileSync(gitignorePath, "utf-8");
152
- const lines = content.split("\n").map((l) => l.trim());
153
- if (lines.includes(exactEntry) || lines.includes("dist/") || lines.includes("dist")) return false;
170
+ lines = content.split("\n").map((l) => l.trim());
154
171
  }
172
+ const missingEntries = entries.filter(({ coveredBy }) => !lines.some((line) => coveredBy.has(line))).map(({ entry }) => entry);
173
+ if (missingEntries.length === 0) return false;
155
174
  const separator = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
156
- fs.writeFileSync(gitignorePath, content + separator + "/dist/\n", "utf-8");
175
+ fs.writeFileSync(gitignorePath, content + separator + missingEntries.join("\n") + "\n", "utf-8");
157
176
  return true;
158
177
  }
159
178
  async function init(options) {
@@ -212,7 +231,7 @@ async function init(options) {
212
231
  for (const script of addedScripts) console.log(` \u2713 Added ${script} script`);
213
232
  if (generatedViteConfig) console.log(` \u2713 Generated vite.config.ts`);
214
233
  if (skippedViteConfig) console.log(` - Skipped vite.config.ts (already exists, use --force to overwrite)`);
215
- if (updatedGitignore) console.log(` \u2713 Added /dist/ to .gitignore`);
234
+ if (updatedGitignore) console.log(` \u2713 Added vinext output directories to .gitignore`);
216
235
  console.log(`
217
236
  Next steps:
218
237
  ${pmName} run dev:vinext Start the vinext dev server
@@ -36,33 +36,37 @@ function dataUrlCssPlugin() {
36
36
  return {
37
37
  name: "vinext:css-data-url",
38
38
  enforce: "pre",
39
- transform(code, id) {
40
- if (!code.includes(DATA_URL_HINT)) return null;
41
- if (id.startsWith(VIRTUAL_PREFIX)) return null;
42
- let mutated = false;
43
- const rewritten = code.replace(DATA_URL_IMPORT_RE, (_match, quote, moduleFlag, base64Flag, payload) => {
44
- const isModule = moduleFlag === "+module";
45
- const isBase64 = base64Flag === ";base64";
46
- let css;
47
- try {
48
- css = decode(payload, isBase64);
49
- } catch (err) {
50
- throw new Error(`[vinext] Failed to decode CSS data URL import in ${id}: ${err.message}`);
51
- }
52
- const ext = isModule ? ".module.css" : ".css";
53
- const syntheticId = `${VIRTUAL_PREFIX}${hash(css + ext)}${ext}`;
54
- entries.set(syntheticId, {
55
- css,
56
- isModule
39
+ transform: {
40
+ filter: {
41
+ id: { exclude: new RegExp(`^${VIRTUAL_PREFIX}`) },
42
+ code: DATA_URL_HINT
43
+ },
44
+ handler(code, id) {
45
+ let mutated = false;
46
+ const rewritten = code.replace(DATA_URL_IMPORT_RE, (_match, quote, moduleFlag, base64Flag, payload) => {
47
+ const isModule = moduleFlag === "+module";
48
+ const isBase64 = base64Flag === ";base64";
49
+ let css;
50
+ try {
51
+ css = decode(payload, isBase64);
52
+ } catch (err) {
53
+ throw new Error(`[vinext] Failed to decode CSS data URL import in ${id}: ${err.message}`);
54
+ }
55
+ const ext = isModule ? ".module.css" : ".css";
56
+ const syntheticId = `${VIRTUAL_PREFIX}${hash(css + ext)}${ext}`;
57
+ entries.set(syntheticId, {
58
+ css,
59
+ isModule
60
+ });
61
+ mutated = true;
62
+ return `${quote}${syntheticId}${quote}`;
57
63
  });
58
- mutated = true;
59
- return `${quote}${syntheticId}${quote}`;
60
- });
61
- if (!mutated) return null;
62
- return {
63
- code: rewritten,
64
- map: null
65
- };
64
+ if (!mutated) return null;
65
+ return {
66
+ code: rewritten,
67
+ map: null
68
+ };
69
+ }
66
70
  },
67
71
  resolveId(id) {
68
72
  if (id.startsWith(VIRTUAL_PREFIX)) return id;
@@ -29,28 +29,34 @@ function createExtensionlessDynamicImportPlugin() {
29
29
  configResolved(config) {
30
30
  moduleExtensions = getModuleExtensions(config);
31
31
  },
32
- transform(code, id) {
33
- if (!/\bimport\s*\(/.test(code)) return null;
34
- if (isDependencyId(id)) return null;
35
- const lang = langForId(id);
36
- if (!lang) return null;
37
- let ast;
38
- try {
39
- ast = parseAst(code, { lang });
40
- } catch {
41
- return null;
32
+ transform: {
33
+ filter: {
34
+ id: {
35
+ include: /\.(?:[cm]?[jt]s|[jt]sx)(?:\?.*)?$/i,
36
+ exclude: /[\\/]node_modules[\\/]/
37
+ },
38
+ code: /\bimport\s*\(/
39
+ },
40
+ handler(code, id) {
41
+ const lang = langForId(id);
42
+ let ast;
43
+ try {
44
+ ast = parseAst(code, { lang });
45
+ } catch {
46
+ return null;
47
+ }
48
+ const imports = collectExtensionlessImports(ast, code, moduleExtensions);
49
+ if (imports.length === 0) return null;
50
+ const output = new MagicString(code);
51
+ for (const dynamicImport of imports) {
52
+ const source = code.slice(dynamicImport.sourceStart, dynamicImport.sourceEnd);
53
+ output.overwrite(dynamicImport.start, dynamicImport.end, buildReplacement(source, dynamicImport.globPattern, dynamicImport.moduleExtensions));
54
+ }
55
+ return {
56
+ code: output.toString(),
57
+ map: output.generateMap({ hires: "boundary" })
58
+ };
42
59
  }
43
- const imports = collectExtensionlessImports(ast, code, moduleExtensions);
44
- if (imports.length === 0) return null;
45
- const output = new MagicString(code);
46
- for (const dynamicImport of imports) {
47
- const source = code.slice(dynamicImport.sourceStart, dynamicImport.sourceEnd);
48
- output.overwrite(dynamicImport.start, dynamicImport.end, buildReplacement(source, dynamicImport.globPattern, dynamicImport.moduleExtensions));
49
- }
50
- return {
51
- code: output.toString(),
52
- map: output.generateMap({ hires: "boundary" })
53
- };
54
60
  }
55
61
  };
56
62
  }
@@ -64,9 +70,6 @@ function langForId(id) {
64
70
  if (ext === ".tsx") return "tsx";
65
71
  return "jsx";
66
72
  }
67
- function isDependencyId(id) {
68
- return id.split("?", 1)[0].replaceAll("\\", "/").includes("/node_modules/");
69
- }
70
73
  function collectExtensionlessImports(ast, code, moduleExtensions) {
71
74
  const imports = [];
72
75
  function visit(value) {
@@ -4,6 +4,7 @@ import { buildFallbackFontFace, getFallbackFontOverrideMetrics } from "../build/
4
4
  import { validateGoogleFontOptions } from "../build/google-fonts/validate.js";
5
5
  import { getFontAxes } from "../build/google-fonts/get-axes.js";
6
6
  import { buildGoogleFontsUrl } from "../build/google-fonts/build-url.js";
7
+ import { findFontFilesInCss } from "../build/google-fonts/find-font-files-in-css.js";
7
8
  import { ASSET_PREFIX_URL_DIR } from "../utils/asset-prefix.js";
8
9
  import { CONTENT_TYPES } from "../server/static-file-cache.js";
9
10
  import fs from "node:fs";
@@ -543,11 +544,12 @@ function createGoogleFontsPlugin(fontGoogleShimPath, shimsDir) {
543
544
  return;
544
545
  }
545
546
  const servedCSS = _rewriteCachedFontCssToServedUrls(localCSS, cacheDir, transformAssetsDir);
547
+ const preloadUrls = findFontFilesInCss(servedCSS, validated.preload ? validated.subsets : void 0).filter((file) => file.preloadFontFile).map((file) => file.googleFontFileUrl);
546
548
  const fallbackMetrics = validated.adjustFontFallback === false ? void 0 : getFallbackFontOverrideMetrics(family);
547
549
  const adjustedFallbackCSS = fallbackMetrics ? buildFallbackFontFace(family, fallbackMetrics) : void 0;
548
550
  const validatedFontWeight = validated.weights.length === 1 && validated.weights[0] !== "variable" ? Number(validated.weights[0]) : void 0;
549
551
  const validatedFontStyle = validated.styles.length === 1 ? validated.styles[0] : void 0;
550
- const internalFontProperties = [`selfHostedCSS: ${JSON.stringify(servedCSS)}`];
552
+ const internalFontProperties = [`selfHostedCSS: ${JSON.stringify(servedCSS)}`, `preloadUrls: ${JSON.stringify(preloadUrls)}`];
551
553
  if (adjustedFallbackCSS) internalFontProperties.push(`adjustedFallbackCSS: ${JSON.stringify(adjustedFallbackCSS)}`);
552
554
  if (Number.isFinite(validatedFontWeight)) internalFontProperties.push(`fontWeight: ${validatedFontWeight}`);
553
555
  if (validatedFontStyle) internalFontProperties.push(`fontStyle: ${JSON.stringify(validatedFontStyle)}`);
@@ -1,3 +1,4 @@
1
+ import { VIRTUAL_MODULE_ID_RE } from "../utils/virtual-module.js";
1
2
  import { collectBindingNames, forEachAstChild, hasRange, isAstRecord, isIdentifierNamed, nodeArray } from "./ast-utils.js";
2
3
  import { tryRealpathSync } from "../build/ssr-manifest.js";
3
4
  import path from "node:path";
@@ -32,18 +33,26 @@ function createImportMetaUrlPlugin(options) {
32
33
  outputDirs = [config.build.outDir];
33
34
  rootPaths = createRootPaths(root, { outputDirs });
34
35
  },
35
- transform(code, id) {
36
- if (!mayContainSourceIdentityToken(code)) return null;
37
- const paths = getRootPaths();
38
- if (!paths) return null;
39
- const canonicalId = transformableModuleCanonicalId(cleanModuleId(id), paths);
40
- if (!canonicalId) return null;
41
- const rewritten = rewriteCanonicalSourceIdentity(code, canonicalId, paths, this.environment?.name === "client" ? "client" : "server");
42
- if (!rewritten) return null;
43
- return {
44
- code: rewritten.code,
45
- map: rewritten.map
46
- };
36
+ transform: {
37
+ filter: {
38
+ id: {
39
+ include: /\.(?:[cm]?[jt]s|[jt]sx)(?:\?.*)?$/,
40
+ exclude: [/[\\/]node_modules[\\/]/, VIRTUAL_MODULE_ID_RE]
41
+ },
42
+ code: /import\.meta(?:\.|\?\.)url|__filename|__dirname/
43
+ },
44
+ handler(code, id) {
45
+ const paths = getRootPaths();
46
+ if (!paths) return null;
47
+ const canonicalId = transformableModuleCanonicalId(cleanModuleId(id), paths);
48
+ if (!canonicalId) return null;
49
+ const rewritten = rewriteCanonicalSourceIdentity(code, canonicalId, paths, this.environment?.name === "client" ? "client" : "server");
50
+ if (!rewritten) return null;
51
+ return {
52
+ code: rewritten.code,
53
+ map: rewritten.map
54
+ };
55
+ }
47
56
  }
48
57
  };
49
58
  }
@@ -120,9 +129,6 @@ function mayContainImportMetaUrl(code) {
120
129
  function mayContainServerCjsGlobal(code) {
121
130
  return code.includes("__filename") || code.includes("__dirname");
122
131
  }
123
- function mayContainSourceIdentityToken(code) {
124
- return mayContainImportMetaUrl(code) || mayContainServerCjsGlobal(code);
125
- }
126
132
  function excludedRelativePrefixes(canonicalRoot, normalizedRoot, options) {
127
133
  const prefixes = new Set([
128
134
  ".next",
@@ -8,7 +8,7 @@ function createInstrumentationClientTransformPlugin(getInstrumentationClientPath
8
8
  transform(code, id) {
9
9
  const instrumentationClientPath = getInstrumentationClientPath();
10
10
  if (!instrumentationClientPath) return null;
11
- if (normalizePath(id.split("?", 1)[0]) !== normalizePath(instrumentationClientPath)) return null;
11
+ if (normalizePath(id.split("?", 1)[0]) !== instrumentationClientPath) return null;
12
12
  if (code.includes("__vinextInstrumentationClientStart")) return null;
13
13
  const ast = parseAst(code);
14
14
  let insertPos = 0;
@@ -0,0 +1,5 @@
1
+ //#region src/plugins/middleware-export-validation.d.ts
2
+ declare function hasValidMiddlewareModuleExport(source: string, id: string, isProxy: boolean): boolean;
3
+ declare function validateMiddlewareModuleExports(source: string, id: string, filePath: string, isProxy: boolean): void;
4
+ //#endregion
5
+ export { hasValidMiddlewareModuleExport, validateMiddlewareModuleExports };
@@ -0,0 +1,36 @@
1
+ import { stripViteModuleQuery } from "../utils/path.js";
2
+ import { createMiddlewareMissingExportError } from "../server/middleware-runtime.js";
3
+ import { parseAst } from "vite";
4
+ //#region src/plugins/middleware-export-validation.ts
5
+ function parserLanguage(id) {
6
+ const cleanId = stripViteModuleQuery(id).toLowerCase();
7
+ if (cleanId.endsWith(".tsx")) return "tsx";
8
+ if (cleanId.endsWith(".ts") || cleanId.endsWith(".mts") || cleanId.endsWith(".cts")) return "ts";
9
+ return "jsx";
10
+ }
11
+ function astName(value) {
12
+ if (!value) return null;
13
+ if (typeof value.name === "string") return value.name;
14
+ if (typeof value.value === "string") return value.value;
15
+ return null;
16
+ }
17
+ function hasValidMiddlewareModuleExport(source, id, isProxy) {
18
+ const ast = parseAst(source, { lang: parserLanguage(id) });
19
+ const expectedExport = isProxy ? "proxy" : "middleware";
20
+ for (const statement of ast.body) {
21
+ if (statement.type === "ExportDefaultDeclaration") return true;
22
+ if (statement.type !== "ExportNamedDeclaration") continue;
23
+ const declaration = statement.declaration;
24
+ if (declaration?.type === "FunctionDeclaration" && astName(declaration.id) === expectedExport) return true;
25
+ if (declaration?.type === "VariableDeclaration") {
26
+ for (const declarator of declaration.declarations ?? []) if (astName(declarator.id) === expectedExport) return true;
27
+ }
28
+ for (const specifier of statement.specifiers ?? []) if (astName(specifier.exported ?? specifier.local) === expectedExport) return true;
29
+ }
30
+ return false;
31
+ }
32
+ function validateMiddlewareModuleExports(source, id, filePath, isProxy) {
33
+ if (!hasValidMiddlewareModuleExport(source, id, isProxy)) throw createMiddlewareMissingExportError(filePath, isProxy);
34
+ }
35
+ //#endregion
36
+ export { hasValidMiddlewareModuleExport, validateMiddlewareModuleExports };
@@ -1,3 +1,4 @@
1
+ import { normalizePathSeparators } from "../utils/path.js";
1
2
  //#region src/plugins/middleware-server-only.ts
2
3
  /**
3
4
  * Allow `import 'server-only'` from middleware (and any module reachable
@@ -44,16 +45,16 @@
44
45
  */
45
46
  function createMiddlewareServerOnlyPlugin(options) {
46
47
  const tainted = /* @__PURE__ */ new Set();
48
+ function canonicalizeId(id) {
49
+ const queryIndex = id.indexOf("?");
50
+ return normalizePathSeparators(queryIndex === -1 ? id : id.slice(0, queryIndex));
51
+ }
47
52
  function isTainted(id) {
48
53
  if (!id) return false;
49
- if (tainted.has(id)) return true;
50
- const queryIndex = id.indexOf("?");
51
- if (queryIndex !== -1) return tainted.has(id.slice(0, queryIndex));
52
- return false;
54
+ return tainted.has(canonicalizeId(id));
53
55
  }
54
56
  function addTainted(id) {
55
- const queryIndex = id.indexOf("?");
56
- tainted.add(queryIndex === -1 ? id : id.slice(0, queryIndex));
57
+ tainted.add(canonicalizeId(id));
57
58
  }
58
59
  return {
59
60
  name: "vinext:middleware-server-only",
@@ -0,0 +1,27 @@
1
+ import { Alias } from "vite";
2
+
3
+ //#region src/plugins/og-asset-ownership.d.ts
4
+ type OgAssetModuleBoundary = {
5
+ assetRoot: string;
6
+ moduleDir: string;
7
+ };
8
+ declare class OgAssetOwnership {
9
+ private projectRoot;
10
+ private readonly linkedPackageRoots;
11
+ private readonly dependencyPackageNames;
12
+ private readonly stringAliasesByFirstCharacter;
13
+ private regularExpressionAliases;
14
+ private configuredAliases;
15
+ configure(projectRoot: string, aliases: readonly Alias[]): void;
16
+ reset(): void;
17
+ shouldTrackImport(source: string): boolean;
18
+ recordResolvedImport(source: string, resolvedId: string): Promise<void>;
19
+ resolveModuleBoundary(moduleId: string): Promise<OgAssetModuleBoundary | null>;
20
+ resolveContainedAsset(assetRoot: string, assetPath: string): Promise<string | null>;
21
+ private findAlias;
22
+ private getExpectedPackageName;
23
+ private resolveAliasPackageRoot;
24
+ private resolveConfiguredAliasRoot;
25
+ }
26
+ //#endregion
27
+ export { OgAssetModuleBoundary, OgAssetOwnership };