vinext 0.1.3 → 0.1.4

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 (82) hide show
  1. package/dist/build/client-build-config.d.ts +11 -2
  2. package/dist/build/client-build-config.js +17 -6
  3. package/dist/build/prerender.js +1 -0
  4. package/dist/client/pages-router-link-navigation.d.ts +33 -7
  5. package/dist/client/pages-router-link-navigation.js +32 -2
  6. package/dist/client/vinext-next-data.js +2 -0
  7. package/dist/config/config-matchers.d.ts +11 -1
  8. package/dist/config/config-matchers.js +14 -2
  9. package/dist/config/tsconfig-paths.js +14 -1
  10. package/dist/deploy.js +20 -13
  11. package/dist/entries/app-rsc-entry.js +3 -2
  12. package/dist/entries/pages-client-entry.js +14 -13
  13. package/dist/entries/pages-server-entry.js +6 -26
  14. package/dist/index.js +217 -40
  15. package/dist/plugins/dynamic-preload-metadata.js +2 -4
  16. package/dist/plugins/fonts.js +5 -4
  17. package/dist/plugins/strip-server-exports.d.ts +9 -7
  18. package/dist/plugins/strip-server-exports.js +493 -46
  19. package/dist/routing/app-route-graph.js +2 -2
  20. package/dist/server/app-browser-action-result.js +1 -1
  21. package/dist/server/app-browser-entry.js +8 -1
  22. package/dist/server/app-browser-navigation-controller.d.ts +1 -1
  23. package/dist/server/app-browser-state.d.ts +1 -1
  24. package/dist/server/app-browser-state.js +19 -11
  25. package/dist/server/app-browser-visible-commit.d.ts +1 -1
  26. package/dist/server/app-pages-bridge.d.ts +5 -1
  27. package/dist/server/app-pages-bridge.js +5 -13
  28. package/dist/server/app-rsc-handler.d.ts +3 -0
  29. package/dist/server/app-rsc-handler.js +51 -15
  30. package/dist/server/app-rsc-route-matching.js +6 -2
  31. package/dist/server/app-server-action-execution.js +5 -2
  32. package/dist/server/app-ssr-entry.js +1 -29
  33. package/dist/server/before-interactive-head.d.ts +17 -0
  34. package/dist/server/before-interactive-head.js +35 -0
  35. package/dist/server/csp.js +1 -4
  36. package/dist/server/dev-server.js +81 -36
  37. package/dist/server/middleware-matcher.js +12 -3
  38. package/dist/server/middleware-runtime.d.ts +3 -4
  39. package/dist/server/middleware-runtime.js +2 -0
  40. package/dist/server/navigation-planner.d.ts +3 -12
  41. package/dist/server/navigation-planner.js +24 -0
  42. package/dist/server/navigation-trace.d.ts +2 -1
  43. package/dist/server/navigation-trace.js +1 -0
  44. package/dist/server/operation-token.d.ts +40 -0
  45. package/dist/server/operation-token.js +85 -0
  46. package/dist/server/pages-data-route.d.ts +1 -1
  47. package/dist/server/pages-data-route.js +7 -4
  48. package/dist/server/pages-dev-module-url.d.ts +4 -0
  49. package/dist/server/pages-dev-module-url.js +15 -0
  50. package/dist/server/pages-document-initial-props.d.ts +4 -15
  51. package/dist/server/pages-document-initial-props.js +27 -56
  52. package/dist/server/pages-i18n.js +2 -2
  53. package/dist/server/pages-page-data.js +3 -1
  54. package/dist/server/pages-page-handler.js +3 -1
  55. package/dist/server/pages-page-response.d.ts +2 -0
  56. package/dist/server/pages-page-response.js +4 -4
  57. package/dist/server/pages-readiness.js +1 -1
  58. package/dist/server/pages-request-pipeline.d.ts +7 -7
  59. package/dist/server/pages-request-pipeline.js +63 -21
  60. package/dist/server/prod-server.d.ts +3 -1
  61. package/dist/server/prod-server.js +41 -10
  62. package/dist/server/static-file-cache.js +16 -4
  63. package/dist/shims/before-interactive-context.d.ts +14 -3
  64. package/dist/shims/document.d.ts +15 -20
  65. package/dist/shims/document.js +5 -8
  66. package/dist/shims/image.js +9 -2
  67. package/dist/shims/internal/pages-data-fetch-dedup.d.ts +6 -7
  68. package/dist/shims/internal/pages-data-fetch-dedup.js +67 -14
  69. package/dist/shims/internal/pages-data-target.js +1 -1
  70. package/dist/shims/link.js +37 -16
  71. package/dist/shims/metadata.js +4 -4
  72. package/dist/shims/navigation.js +2 -0
  73. package/dist/shims/router.d.ts +6 -2
  74. package/dist/shims/router.js +99 -20
  75. package/dist/shims/script.js +8 -4
  76. package/dist/utils/has-trailing-comma.d.ts +24 -0
  77. package/dist/utils/has-trailing-comma.js +62 -0
  78. package/dist/utils/text-stream.d.ts +1 -1
  79. package/dist/utils/text-stream.js +2 -2
  80. package/dist/utils/vite-version.d.ts +12 -1
  81. package/dist/utils/vite-version.js +9 -1
  82. package/package.json +1 -1
@@ -113,8 +113,10 @@ function extractBeforeInteractiveInlineContent(children, dangerouslySetInnerHTML
113
113
  const REACT_TO_HTML_ATTR = {
114
114
  acceptCharset: "accept-charset",
115
115
  className: "class",
116
+ crossOrigin: "crossorigin",
116
117
  htmlFor: "for",
117
- httpEquiv: "http-equiv"
118
+ httpEquiv: "http-equiv",
119
+ referrerPolicy: "referrerpolicy"
118
120
  };
119
121
  /**
120
122
  * Convert the residual `<Script>` props into a plain string-attributes record
@@ -331,10 +333,11 @@ function Script(props) {
331
333
  }
332
334
  if (strategy === "beforeInteractive") {
333
335
  const inlineContent = src ? null : extractBeforeInteractiveInlineContent(children, dangerouslySetInnerHTML);
334
- if (inlineContent !== null && registerBeforeInteractive) {
336
+ if ((src || inlineContent !== null) && registerBeforeInteractive) {
335
337
  registerBeforeInteractive({
336
338
  id,
337
- innerHTML: escapeInlineContent(inlineContent, "script"),
339
+ src: src ?? void 0,
340
+ innerHTML: inlineContent !== null ? escapeInlineContent(inlineContent, "script") : void 0,
338
341
  nonce: resolvedNonce,
339
342
  attributes: collectBeforeInteractiveAttributes(rest)
340
343
  });
@@ -351,7 +354,8 @@ function Script(props) {
351
354
  return null;
352
355
  }
353
356
  if (strategy === "beforeInteractive") {
354
- if ((src ? null : extractBeforeInteractiveInlineContent(children, dangerouslySetInnerHTML)) !== null && hasAppNavigationRuntimeBootstrap()) return null;
357
+ const inlineContent = src ? null : extractBeforeInteractiveInlineContent(children, dangerouslySetInnerHTML);
358
+ if ((src || inlineContent !== null) && hasAppNavigationRuntimeBootstrap()) return null;
355
359
  return React.createElement("script", buildBeforeInteractiveScriptProps({
356
360
  src,
357
361
  id,
@@ -0,0 +1,24 @@
1
+ //#region src/utils/has-trailing-comma.d.ts
2
+ /**
3
+ * Return the last syntactically significant character of a JS source fragment,
4
+ * skipping whitespace and comments. A forward scan tracks string and comment
5
+ * state so that `//` or `/*` sequences appearing INSIDE a string literal (e.g. a
6
+ * URL such as `"https://example.com"` or a path with a double slash) are NOT
7
+ * mistaken for comments.
8
+ *
9
+ * This is deliberately stricter than a whole-string comment strip: stripping
10
+ * every `//...`/`/* ... *\/` would also delete those sequences from inside
11
+ * string literals, which can swallow the real trailing comma that follows them
12
+ * and corrupt the trailing-comma / empty-object detection this feeds.
13
+ *
14
+ * Returns "" for an empty / whitespace-only / comment-only fragment.
15
+ */
16
+ declare function lastSignificantChar(source: string): string;
17
+ /**
18
+ * True when `source` ends — ignoring trailing whitespace and comments — with a
19
+ * real trailing comma. Used to avoid splicing a second comma (`,,` is a syntax
20
+ * error) when injecting a property or argument into existing source.
21
+ */
22
+ declare function hasTrailingComma(source: string): boolean;
23
+ //#endregion
24
+ export { hasTrailingComma, lastSignificantChar };
@@ -0,0 +1,62 @@
1
+ //#region src/utils/has-trailing-comma.ts
2
+ /**
3
+ * Return the last syntactically significant character of a JS source fragment,
4
+ * skipping whitespace and comments. A forward scan tracks string and comment
5
+ * state so that `//` or `/*` sequences appearing INSIDE a string literal (e.g. a
6
+ * URL such as `"https://example.com"` or a path with a double slash) are NOT
7
+ * mistaken for comments.
8
+ *
9
+ * This is deliberately stricter than a whole-string comment strip: stripping
10
+ * every `//...`/`/* ... *\/` would also delete those sequences from inside
11
+ * string literals, which can swallow the real trailing comma that follows them
12
+ * and corrupt the trailing-comma / empty-object detection this feeds.
13
+ *
14
+ * Returns "" for an empty / whitespace-only / comment-only fragment.
15
+ */
16
+ function lastSignificantChar(source) {
17
+ let last = "";
18
+ let i = 0;
19
+ const n = source.length;
20
+ while (i < n) {
21
+ const c = source[i];
22
+ const next = source[i + 1];
23
+ if (c === "/" && next === "/") {
24
+ i += 2;
25
+ while (i < n && source[i] !== "\n") i += 1;
26
+ continue;
27
+ }
28
+ if (c === "/" && next === "*") {
29
+ i += 2;
30
+ while (i < n && !(source[i] === "*" && source[i + 1] === "/")) i += 1;
31
+ i += 2;
32
+ continue;
33
+ }
34
+ if (c === "\"" || c === "'" || c === "`") {
35
+ i += 1;
36
+ while (i < n && source[i] !== c) {
37
+ if (source[i] === "\\") i += 1;
38
+ i += 1;
39
+ }
40
+ last = c;
41
+ i += 1;
42
+ continue;
43
+ }
44
+ if (/\s/.test(c)) {
45
+ i += 1;
46
+ continue;
47
+ }
48
+ last = c;
49
+ i += 1;
50
+ }
51
+ return last;
52
+ }
53
+ /**
54
+ * True when `source` ends — ignoring trailing whitespace and comments — with a
55
+ * real trailing comma. Used to avoid splicing a second comma (`,,` is a syntax
56
+ * error) when injecting a property or argument into existing source.
57
+ */
58
+ function hasTrailingComma(source) {
59
+ return lastSignificantChar(source) === ",";
60
+ }
61
+ //#endregion
62
+ export { hasTrailingComma, lastSignificantChar };
@@ -16,7 +16,7 @@
16
16
  declare function readStreamAsText(stream: ReadableStream<Uint8Array>): Promise<string>;
17
17
  /**
18
18
  * Drain a UTF-8 byte stream up to `maxBytes` of *raw* input, returning the
19
- * decoded text. If the raw size limit is exceeded, the reader is cancelled
19
+ * decoded text. If the raw size limit is exceeded, cancellation is signalled
20
20
  * and `onLimitExceeded` is invoked; it MUST throw — its return type is
21
21
  * `never` to enforce that. Each caller passes its own error type.
22
22
  *
@@ -31,7 +31,7 @@ async function readStreamAsText(stream) {
31
31
  }
32
32
  /**
33
33
  * Drain a UTF-8 byte stream up to `maxBytes` of *raw* input, returning the
34
- * decoded text. If the raw size limit is exceeded, the reader is cancelled
34
+ * decoded text. If the raw size limit is exceeded, cancellation is signalled
35
35
  * and `onLimitExceeded` is invoked; it MUST throw — its return type is
36
36
  * `never` to enforce that. Each caller passes its own error type.
37
37
  *
@@ -49,7 +49,7 @@ async function readStreamAsTextWithLimit(stream, maxBytes, onLimitExceeded) {
49
49
  if (result.done) break;
50
50
  totalSize += result.value.byteLength;
51
51
  if (totalSize > maxBytes) {
52
- await reader.cancel();
52
+ reader.cancel();
53
53
  onLimitExceeded();
54
54
  }
55
55
  chunks.push(decoder.decode(result.value, { stream: true }));
@@ -1,4 +1,15 @@
1
1
  //#region src/utils/vite-version.d.ts
2
+ declare function serializeViteDefine(value: unknown): string;
3
+ declare function getDepOptimizeNodeEnvOptions(viteMajorVersion: number, nodeEnvDefine: string): {
4
+ rolldownOptions?: {
5
+ transform: {
6
+ define: Record<string, string>;
7
+ };
8
+ };
9
+ esbuildOptions?: {
10
+ define: Record<string, string>;
11
+ };
12
+ };
2
13
  /**
3
14
  * Detect Vite major version at runtime by resolving from cwd.
4
15
  * The plugin may be installed in a workspace root with Vite 7 but used
@@ -7,4 +18,4 @@
7
18
  */
8
19
  declare function getViteMajorVersion(): number;
9
20
  //#endregion
10
- export { getViteMajorVersion };
21
+ export { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine };
@@ -9,6 +9,14 @@ import path from "node:path";
9
9
  * `rolldownOptions`) or Vite 7 (Rollup/esbuild). This helper centralizes the
10
10
  * detection so the Vite-major gate is computed the same way everywhere.
11
11
  */
12
+ function serializeViteDefine(value) {
13
+ if (typeof value === "string") return value;
14
+ return JSON.stringify(value) ?? "undefined";
15
+ }
16
+ function getDepOptimizeNodeEnvOptions(viteMajorVersion, nodeEnvDefine) {
17
+ const define = { "process.env.NODE_ENV": nodeEnvDefine };
18
+ return viteMajorVersion >= 8 ? { rolldownOptions: { transform: { define } } } : { esbuildOptions: { define } };
19
+ }
12
20
  /**
13
21
  * Detect Vite major version at runtime by resolving from cwd.
14
22
  * The plugin may be installed in a workspace root with Vite 7 but used
@@ -31,4 +39,4 @@ function getViteMajorVersion() {
31
39
  }
32
40
  }
33
41
  //#endregion
34
- export { getViteMajorVersion };
42
+ export { getDepOptimizeNodeEnvOptions, getViteMajorVersion, serializeViteDefine };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vinext",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Run Next.js apps on Vite. Drop-in replacement for the next CLI.",
5
5
  "license": "MIT",
6
6
  "repository": {