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,7 +1,9 @@
1
1
  import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
2
- import { DYNAMIC_IMPORT_PRESCAN, collectBindingNames, forEachAstChild, hasRange, isAstRecord, isIdentifierNamed, mayContainDynamicImport, nodeArray } from "./ast-utils.js";
3
- import { createTransformCache } from "./transform-cache.js";
2
+ import { stripViteModuleQuery } from "../utils/path.js";
3
+ import { magicStringTransformResult } from "./transform-result.js";
4
+ import { DYNAMIC_IMPORT_PRESCAN, SCRIPT_MODULE_ID_RE, collectBindingNames, forEachAstChild, hasRange, isAstRecord, isIdentifierNamed, mayContainDynamicImport, nodeArray, scriptParserLanguage, stringLiteralValue, unwrapExpression } from "./ast-utils.js";
4
5
  import { collectDirectScopeBindings, collectLoopScopeBindings, collectSwitchScopeBindings, collectVarScopeBindings, hasAstBinding, isFunctionNode } from "./ast-scope.js";
6
+ import { createTransformCache } from "./transform-cache.js";
5
7
  import { parseAst } from "vite";
6
8
  import { fileURLToPath } from "node:url";
7
9
  import MagicString from "magic-string";
@@ -12,37 +14,9 @@ const DYNAMIC_REQUEST_PRESCAN = new RegExp(String.raw`(?:${REQUIRE_PRESCAN.sourc
12
14
  const MAX_CONSTANT_BINDING_DEPTH = 1500;
13
15
  const VINEXT_SOURCE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
14
16
  const PLUGIN_RSC_PATH = /[\\/]node_modules[\\/](?:\.pnpm[\\/][^/\\]+[\\/]node_modules[\\/])?@vitejs[\\/]plugin-rsc[\\/]/;
15
- const TRANSFORMABLE_EXTENSIONS = /* @__PURE__ */ new Set([
16
- ".js",
17
- ".jsx",
18
- ".mjs",
19
- ".cjs",
20
- ".ts",
21
- ".tsx",
22
- ".mts",
23
- ".cts"
24
- ]);
25
- const TRANSPARENT_EXPRESSIONS = /* @__PURE__ */ new Set([
26
- "ChainExpression",
27
- "ParenthesizedExpression",
28
- "TSAsExpression",
29
- "TSInstantiationExpression",
30
- "TSNonNullExpression",
31
- "TSSatisfiesExpression",
32
- "TSTypeAssertion"
33
- ]);
34
17
  function astNode(value) {
35
18
  return isAstRecord(value) ? value : null;
36
19
  }
37
- function unwrapExpression(value) {
38
- const node = astNode(value);
39
- if (!node || !TRANSPARENT_EXPRESSIONS.has(node.type)) return node;
40
- return unwrapExpression(node.expression);
41
- }
42
- function stringValue(node) {
43
- if ((node.type === "Literal" || node.type === "StringLiteral") && typeof node.value === "string") return node.value;
44
- return null;
45
- }
46
20
  function stringFromCharCodeValue(value, scope) {
47
21
  const node = unwrapExpression(value);
48
22
  if (node?.type !== "CallExpression") return null;
@@ -61,10 +35,10 @@ function stringFromCharCodeValue(value, scope) {
61
35
  function isUnboundNumericGlobal(node, scope) {
62
36
  return node.type === "Identifier" && typeof node.name === "string" && !hasAstBinding(scope, node.name) && (isIdentifierNamed(node, "NaN") || isIdentifierNamed(node, "Infinity"));
63
37
  }
64
- function staticStringValue(value, scope, resolution) {
38
+ function evaluateStaticString(value, scope, resolution) {
65
39
  const node = unwrapExpression(value);
66
40
  if (!node) return null;
67
- const valueString = stringValue(node);
41
+ const valueString = stringLiteralValue(node);
68
42
  if (valueString !== null) return valueString;
69
43
  if (node.type === "TemplateLiteral" && nodeArray(node.expressions).length === 0) {
70
44
  const quasiValue = astNode(nodeArray(node.quasis)[0])?.value;
@@ -73,19 +47,19 @@ function staticStringValue(value, scope, resolution) {
73
47
  return typeof cooked === "string" ? cooked : typeof raw === "string" ? raw : null;
74
48
  }
75
49
  if (node.type === "BinaryExpression" && node.operator === "+") {
76
- const left = staticStringValue(node.left, scope, resolution);
77
- const right = staticStringValue(node.right, scope, resolution);
50
+ const left = evaluateStaticString(node.left, scope, resolution);
51
+ const right = evaluateStaticString(node.right, scope, resolution);
78
52
  return left === null || right === null ? null : left + right;
79
53
  }
80
54
  if (node.type === "ConditionalExpression") {
81
55
  const truthiness = staticTruthiness(node.test, scope, resolution);
82
- if (truthiness !== null) return staticStringValue(truthiness ? node.consequent : node.alternate, scope, resolution);
83
- const consequent = staticStringValue(node.consequent, scope, resolution);
84
- const alternate = staticStringValue(node.alternate, scope, resolution);
56
+ if (truthiness !== null) return evaluateStaticString(truthiness ? node.consequent : node.alternate, scope, resolution);
57
+ const consequent = evaluateStaticString(node.consequent, scope, resolution);
58
+ const alternate = evaluateStaticString(node.alternate, scope, resolution);
85
59
  return consequent !== null && consequent === alternate ? consequent : null;
86
60
  }
87
- if (node.type === "SequenceExpression") return staticStringValue(nodeArray(node.expressions).at(-1), scope, resolution);
88
- if (node.type === "Identifier" && typeof node.name === "string") return resolveConstantBinding(scope, node.name, resolution, null, staticStringValue);
61
+ if (node.type === "SequenceExpression") return evaluateStaticString(nodeArray(node.expressions).at(-1), scope, resolution);
62
+ if (node.type === "Identifier" && typeof node.name === "string") return resolveConstantBinding(scope, node.name, resolution, null, evaluateStaticString);
89
63
  return null;
90
64
  }
91
65
  function hasSignificantPathPart(value) {
@@ -196,7 +170,7 @@ function templateTruthiness(node, scope, resolution, useRaw = false) {
196
170
  if (nodeArray(node.quasis).filter(isAstRecord).some((quasi) => templateElementValue(quasi, useRaw) !== "")) return true;
197
171
  let hasUnknownExpression = false;
198
172
  for (const expression of nodeArray(node.expressions)) {
199
- const string = staticStringValue(expression, scope, resolution);
173
+ const string = evaluateStaticString(expression, scope, resolution);
200
174
  if (string !== null) {
201
175
  if (string !== "") return true;
202
176
  continue;
@@ -218,7 +192,7 @@ function staticTruthiness(value, scope, resolution = createConstantResolution())
218
192
  return quasi?.type === "TemplateLiteral" ? templateTruthiness(quasi, scope, resolution, true) : null;
219
193
  }
220
194
  if (node.type === "BinaryExpression" && node.operator === "+") {
221
- const string = staticStringValue(node, scope, resolution);
195
+ const string = evaluateStaticString(node, scope, resolution);
222
196
  return string === null ? null : Boolean(string);
223
197
  }
224
198
  if (isIdentifierNamed(node, "undefined") && !hasAstBinding(scope, "undefined")) return false;
@@ -272,7 +246,7 @@ function stringConcatHasStaticPart(node, scope, resolution) {
272
246
  if (node.type !== "CallExpression") return null;
273
247
  const callee = unwrapExpression(node.callee);
274
248
  const property = callee?.type === "MemberExpression" ? unwrapExpression(callee.property) : null;
275
- if (callee?.type !== "MemberExpression" || (callee.computed === true ? property === null || staticStringValue(property, scope, resolution) !== "concat" : !isIdentifierNamed(property, "concat"))) return null;
249
+ if (callee?.type !== "MemberExpression" || (callee.computed === true ? property === null || evaluateStaticString(property, scope, resolution) !== "concat" : !isIdentifierNamed(property, "concat"))) return null;
276
250
  const receiver = unwrapExpression(callee.object);
277
251
  if (!receiver || !isStaticStringExpression(receiver, scope, resolution)) return null;
278
252
  if (requestHasStaticPart(receiver, scope, resolution)) return true;
@@ -284,7 +258,7 @@ function stringConcatHasStaticPart(node, scope, resolution) {
284
258
  function isStaticStringExpression(value, scope, resolution) {
285
259
  const node = unwrapExpression(value);
286
260
  if (!node) return false;
287
- if (stringValue(node) !== null || node.type === "TemplateLiteral") return true;
261
+ if (stringLiteralValue(node) !== null || node.type === "TemplateLiteral") return true;
288
262
  if (node.type === "Identifier" && typeof node.name === "string") return resolveConstantBinding(scope, node.name, resolution, false, isStaticStringExpression);
289
263
  if (node.type === "BinaryExpression" && node.operator === "+") return additionContainsString(node, scope, resolution);
290
264
  if (node.type === "ConditionalExpression") return isStaticStringExpression(node.consequent, scope, resolution) && isStaticStringExpression(node.alternate, scope, resolution);
@@ -295,7 +269,7 @@ function isStaticStringExpression(value, scope, resolution) {
295
269
  function additionContainsString(value, scope, resolution) {
296
270
  const node = unwrapExpression(value);
297
271
  if (!node) return false;
298
- if (stringValue(node) !== null || node.type === "TemplateLiteral") return true;
272
+ if (stringLiteralValue(node) !== null || node.type === "TemplateLiteral") return true;
299
273
  if (node.type === "Identifier" && typeof node.name === "string") return resolveConstantBinding(scope, node.name, resolution, false, additionContainsString);
300
274
  if (node.type === "BinaryExpression" && node.operator === "+") return additionContainsString(node.left, scope, resolution) || additionContainsString(node.right, scope, resolution);
301
275
  if (node.type === "ConditionalExpression") return additionContainsString(node.consequent, scope, resolution) && additionContainsString(node.alternate, scope, resolution);
@@ -305,7 +279,7 @@ function additionContainsString(value, scope, resolution) {
305
279
  function requestHasStaticPart(value, scope, resolution = createConstantResolution()) {
306
280
  const node = unwrapExpression(value);
307
281
  if (!node) return false;
308
- const constantString = stringValue(node);
282
+ const constantString = stringLiteralValue(node);
309
283
  if (constantString !== null) return constantString.replaceAll("\\", "/") !== "/";
310
284
  if (node.type === "Literal") return true;
311
285
  if (isUnboundNumericGlobal(node, scope)) return true;
@@ -325,8 +299,8 @@ function requestHasStaticPart(value, scope, resolution = createConstantResolutio
325
299
  if (!additionContainsString(node, scope, resolution)) return false;
326
300
  const left = unwrapExpression(node.left);
327
301
  const right = unwrapExpression(node.right);
328
- const leftString = left ? stringValue(left) : null;
329
- const rightString = right ? stringValue(right) : null;
302
+ const leftString = left ? stringLiteralValue(left) : null;
303
+ const rightString = right ? stringLiteralValue(right) : null;
330
304
  return leftString !== null && hasSignificantPathPart(leftString) || rightString !== null && hasSignificantPathPart(rightString) || leftString === null && requestHasStaticPart(left, scope, resolution) || rightString === null && requestHasStaticPart(right, scope, resolution);
331
305
  }
332
306
  if (node.type === "ConditionalExpression") {
@@ -401,8 +375,7 @@ function dynamicImportReplacement() {
401
375
  }
402
376
  function transformVeryDynamicRequests(code, id) {
403
377
  if (!REQUIRE_PRESCAN.test(code) && !mayContainDynamicImport(code)) return null;
404
- const extension = path.extname(id.split("?", 1)[0]);
405
- const lang = extension === ".ts" || extension === ".mts" || extension === ".cts" ? "ts" : extension === ".tsx" ? "tsx" : extension === ".js" || extension === ".jsx" || extension === ".mjs" || extension === ".cjs" ? "jsx" : "js";
378
+ const lang = scriptParserLanguage(id) ?? "js";
406
379
  let ast;
407
380
  try {
408
381
  ast = parseAst(code, { lang });
@@ -521,13 +494,10 @@ function transformVeryDynamicRequests(code, id) {
521
494
  }
522
495
  for (const statement of nodeArray(root.body)) if (isAstRecord(statement)) visit(statement, rootScope);
523
496
  if (!changed) return null;
524
- return {
525
- code: output.toString(),
526
- map: output.generateMap({
527
- hires: "boundary",
528
- source: id
529
- })
530
- };
497
+ return magicStringTransformResult(output, {
498
+ hires: "boundary",
499
+ source: id
500
+ });
531
501
  }
532
502
  function createIgnoreDynamicRequestsPlugin(getTranspiledPackages = () => []) {
533
503
  const cached = createTransformCache();
@@ -536,12 +506,12 @@ function createIgnoreDynamicRequestsPlugin(getTranspiledPackages = () => []) {
536
506
  enforce: "pre",
537
507
  transform: {
538
508
  filter: {
539
- id: { include: /\.(?:[cm]?[jt]s|[jt]sx)(?:\?.*)?$/ },
509
+ id: { include: SCRIPT_MODULE_ID_RE },
540
510
  code: DYNAMIC_REQUEST_PRESCAN
541
511
  },
542
512
  handler(code, id) {
543
- const cleanId = id.split("?", 1)[0];
544
- if (!TRANSFORMABLE_EXTENSIONS.has(path.extname(cleanId))) return null;
513
+ const cleanId = stripViteModuleQuery(id);
514
+ if (scriptParserLanguage(cleanId) === null) return null;
545
515
  if (!shouldTransformVeryDynamicRequests(this.environment, cleanId, getTranspiledPackages())) return null;
546
516
  const absoluteId = path.resolve(cleanId);
547
517
  if (absoluteId === VINEXT_SOURCE_ROOT || absoluteId.startsWith(`${VINEXT_SOURCE_ROOT}/`) || PLUGIN_RSC_PATH.test(absoluteId)) return null;
@@ -1,15 +1,21 @@
1
- import { Plugin } from "vite";
2
- import MagicString from "magic-string";
1
+ import { MagicStringTransformResult } from "./transform-result.js";
2
+ import { Plugin, ResolvedConfig } from "vite";
3
3
  //#region src/plugins/import-meta-url.d.ts
4
4
  type ImportMetaUrlEnvironment = "client" | "server";
5
- type RewriteResult = {
6
- code: string;
7
- map: ReturnType<MagicString["generateMap"]>;
5
+ type ImportMetaUrlCapability = {
6
+ /** The Vite app plugin. Owns project, dependency, and emitted-chunk identity. */
7
+ vitePlugin: Plugin;
8
+ /** Thin adapter for Vite's independent dependency-optimizer Rolldown pipeline. */
9
+ optimizeDepsPlugin: Plugin;
10
+ /** Cached dependency identity/format classifier shared by both plugin pipelines. */
11
+ isBundledCommonJsDependencyId: (id: string) => boolean;
8
12
  };
13
+ type EmittedModuleFileNameResolver = (environmentName: string | undefined, fileName: string) => string;
9
14
  declare function createImportMetaUrlPlugin(options: {
10
15
  getRoot: () => string | undefined;
11
- }): Plugin;
12
- declare function rewriteImportMetaUrl(code: string, id: string, root: string, environment: ImportMetaUrlEnvironment): RewriteResult | null;
13
- declare function rewriteServerCjsGlobals(code: string, id: string, root: string): RewriteResult | null;
16
+ createEmittedModuleFileNameResolver?: (config: ResolvedConfig) => EmittedModuleFileNameResolver | undefined;
17
+ }): ImportMetaUrlCapability;
18
+ declare function rewriteImportMetaUrl(code: string, id: string, root: string, environment: ImportMetaUrlEnvironment): MagicStringTransformResult | null;
19
+ declare function rewriteServerCjsGlobals(code: string, id: string, root: string): MagicStringTransformResult | null;
14
20
  //#endregion
15
- export { createImportMetaUrlPlugin, rewriteImportMetaUrl, rewriteServerCjsGlobals };
21
+ export { EmittedModuleFileNameResolver, ImportMetaUrlCapability, createImportMetaUrlPlugin, rewriteImportMetaUrl, rewriteServerCjsGlobals };