vinext 0.1.5 → 0.1.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 (93) hide show
  1. package/README.md +2 -2
  2. package/dist/build/client-build-config.d.ts +4 -6
  3. package/dist/build/client-build-config.js +27 -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 +1 -2
  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/check.js +3 -3
  11. package/dist/client/pages-router-link-navigation.d.ts +10 -0
  12. package/dist/client/pages-router-link-navigation.js +3 -3
  13. package/dist/deploy.js +3 -3
  14. package/dist/entries/app-rsc-entry.d.ts +2 -1
  15. package/dist/entries/app-rsc-entry.js +35 -9
  16. package/dist/entries/app-rsc-manifest.js +76 -46
  17. package/dist/entries/pages-server-entry.js +1 -0
  18. package/dist/index.js +116 -74
  19. package/dist/init.d.ts +5 -4
  20. package/dist/init.js +27 -8
  21. package/dist/plugins/fonts.js +3 -1
  22. package/dist/plugins/middleware-export-validation.d.ts +5 -0
  23. package/dist/plugins/middleware-export-validation.js +36 -0
  24. package/dist/plugins/og-asset-ownership.d.ts +27 -0
  25. package/dist/plugins/og-asset-ownership.js +285 -0
  26. package/dist/plugins/og-assets.js +28 -10
  27. package/dist/plugins/remove-console.js +1 -1
  28. package/dist/plugins/strip-server-exports.js +2 -1
  29. package/dist/server/accept-encoding.d.ts +29 -0
  30. package/dist/server/accept-encoding.js +95 -0
  31. package/dist/server/app-action-request.d.ts +4 -0
  32. package/dist/server/app-action-request.js +9 -0
  33. package/dist/server/app-bfcache-identity.d.ts +12 -2
  34. package/dist/server/app-bfcache-identity.js +52 -23
  35. package/dist/server/app-browser-entry.js +8 -5
  36. package/dist/server/app-browser-navigation-controller.js +1 -1
  37. package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
  38. package/dist/server/app-browser-rsc-redirect.js +8 -1
  39. package/dist/server/app-browser-state.js +1 -1
  40. package/dist/server/app-browser-visible-commit.js +1 -1
  41. package/dist/server/app-history-state.d.ts +1 -2
  42. package/dist/server/app-history-state.js +1 -1
  43. package/dist/server/app-middleware.d.ts +1 -0
  44. package/dist/server/app-middleware.js +1 -0
  45. package/dist/server/app-page-dispatch.d.ts +2 -2
  46. package/dist/server/app-page-head.js +2 -2
  47. package/dist/server/app-page-method.js +1 -1
  48. package/dist/server/app-page-request.d.ts +7 -0
  49. package/dist/server/app-page-request.js +19 -1
  50. package/dist/server/app-page-stream.js +2 -1
  51. package/dist/server/app-prerender-endpoints.d.ts +3 -3
  52. package/dist/server/app-prerender-endpoints.js +3 -4
  53. package/dist/server/app-route-handler-cache.js +1 -1
  54. package/dist/server/app-route-handler-dispatch.js +2 -2
  55. package/dist/server/app-route-handler-execution.js +3 -2
  56. package/dist/server/app-route-handler-policy.d.ts +1 -1
  57. package/dist/server/app-route-handler-policy.js +1 -6
  58. package/dist/server/app-route-module-loader.d.ts +62 -14
  59. package/dist/server/app-route-module-loader.js +61 -10
  60. package/dist/server/app-rsc-errors.d.ts +12 -1
  61. package/dist/server/app-rsc-errors.js +22 -2
  62. package/dist/server/app-rsc-handler.d.ts +16 -14
  63. package/dist/server/app-rsc-handler.js +47 -44
  64. package/dist/server/app-rsc-response-finalizer.js +5 -1
  65. package/dist/server/app-rsc-route-matching.d.ts +9 -0
  66. package/dist/server/app-rsc-route-matching.js +13 -0
  67. package/dist/server/app-server-action-execution.js +1 -1
  68. package/dist/server/app-ssr-entry.js +9 -7
  69. package/dist/server/headers.d.ts +5 -1
  70. package/dist/server/headers.js +5 -1
  71. package/dist/server/metadata-route-response.d.ts +3 -3
  72. package/dist/server/middleware-runtime.d.ts +2 -1
  73. package/dist/server/middleware-runtime.js +19 -8
  74. package/dist/server/middleware.d.ts +2 -2
  75. package/dist/server/middleware.js +26 -11
  76. package/dist/server/pages-request-pipeline.d.ts +3 -1
  77. package/dist/server/pages-request-pipeline.js +4 -2
  78. package/dist/server/prod-server.d.ts +1 -1
  79. package/dist/server/prod-server.js +85 -72
  80. package/dist/shims/dynamic.js +1 -1
  81. package/dist/shims/font-google-base.d.ts +1 -0
  82. package/dist/shims/font-google-base.js +6 -21
  83. package/dist/shims/internal/interpolate-as.d.ts +25 -0
  84. package/dist/shims/internal/interpolate-as.js +196 -0
  85. package/dist/shims/link.js +24 -1
  86. package/dist/shims/navigation.js +1 -1
  87. package/dist/shims/navigation.react-server.js +1 -1
  88. package/dist/shims/router.d.ts +1 -3
  89. package/dist/shims/router.js +62 -18
  90. package/dist/typegen.js +2 -10
  91. package/dist/utils/project.d.ts +7 -1
  92. package/dist/utils/project.js +16 -2
  93. package/package.json +3 -3
@@ -0,0 +1,285 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { promisify } from "node:util";
4
+ //#region src/plugins/og-asset-ownership.ts
5
+ const realpathNative = promisify(fs.realpath.native);
6
+ function isPathInside(root, target) {
7
+ const relative = path.relative(root, target);
8
+ return relative === "" || !path.isAbsolute(relative) && !relative.startsWith(`..${path.sep}`) && relative !== "..";
9
+ }
10
+ async function findPackageRoot(moduleDir, expectedPackageName) {
11
+ let currentDir = moduleDir;
12
+ while (true) {
13
+ try {
14
+ const packageJsonPath = path.join(currentDir, "package.json");
15
+ if ((await fs.promises.stat(packageJsonPath)).isFile()) {
16
+ const manifest = JSON.parse(await fs.promises.readFile(packageJsonPath, "utf8"));
17
+ return expectedPackageName === void 0 || manifest.name === expectedPackageName ? currentDir : null;
18
+ }
19
+ } catch {}
20
+ const parentDir = path.dirname(currentDir);
21
+ if (parentDir === currentDir) return null;
22
+ currentDir = parentDir;
23
+ }
24
+ }
25
+ function getPackageNameFromSpecifier(specifier) {
26
+ if (specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("\0") || specifier.startsWith("#")) return null;
27
+ const segments = specifier.split("/");
28
+ if (specifier.startsWith("@")) return segments.length >= 2 ? `${segments[0]}/${segments[1]}` : null;
29
+ return segments[0] || null;
30
+ }
31
+ function getAliasedPackageName(value) {
32
+ if (typeof value !== "string") return null;
33
+ return value.match(/^(?:npm:|workspace:)(@[^/]+\/[^@]+|[^@*~^]+)(?:@|$)/)?.[1] ?? null;
34
+ }
35
+ function aliasMatches(find, source) {
36
+ if (typeof find === "string") return source === find || source.startsWith(`${find}/`);
37
+ find.lastIndex = 0;
38
+ return find.test(source);
39
+ }
40
+ function applyAlias(find, replacement, source) {
41
+ if (typeof find === "string") return replacement + source.slice(find.length);
42
+ find.lastIndex = 0;
43
+ return source.replace(find, replacement);
44
+ }
45
+ function getNodeModulesPackageRoot(logicalProjectRoot, logicalModulePath) {
46
+ const isProjectPath = isPathInside(logicalProjectRoot, logicalModulePath);
47
+ const parsedPath = path.parse(logicalModulePath);
48
+ const baseRoot = isProjectPath ? logicalProjectRoot : parsedPath.root;
49
+ const segments = (isProjectPath ? path.relative(logicalProjectRoot, logicalModulePath) : logicalModulePath.slice(parsedPath.root.length)).split(path.sep);
50
+ const nodeModulesIndex = segments.lastIndexOf("node_modules");
51
+ if (nodeModulesIndex === -1) return null;
52
+ const packageSegment = segments[nodeModulesIndex + 1];
53
+ if (!packageSegment) return null;
54
+ const packageSegmentCount = packageSegment.startsWith("@") ? 2 : 1;
55
+ if (segments.length <= nodeModulesIndex + packageSegmentCount) return null;
56
+ if (packageSegmentCount === 2 && !segments[nodeModulesIndex + 2]) return null;
57
+ return path.join(baseRoot, ...segments.slice(0, nodeModulesIndex + 1 + packageSegmentCount));
58
+ }
59
+ async function readPackageName(packageRoot) {
60
+ try {
61
+ const manifest = JSON.parse(await fs.promises.readFile(path.join(packageRoot, "package.json"), "utf8"));
62
+ return typeof manifest.name === "string" ? manifest.name : null;
63
+ } catch {
64
+ return null;
65
+ }
66
+ }
67
+ async function packageOwnsAliasFile(packageRoot, packageName, aliasFile) {
68
+ try {
69
+ const manifest = JSON.parse(await fs.promises.readFile(path.join(packageRoot, "package.json"), "utf8"));
70
+ if (packageName !== null && manifest.name === packageName) return true;
71
+ return [
72
+ "main",
73
+ "module",
74
+ "source",
75
+ "browser"
76
+ ].some((field) => typeof manifest[field] === "string" && path.resolve(packageRoot, manifest[field]) === aliasFile);
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+ async function packageOwnsAliasDirectory(packageRoot, packageName, aliasDirectory) {
82
+ if (aliasDirectory === packageRoot) return true;
83
+ try {
84
+ const manifest = JSON.parse(await fs.promises.readFile(path.join(packageRoot, "package.json"), "utf8"));
85
+ if (packageName !== null && manifest.name === packageName) return true;
86
+ return [
87
+ "main",
88
+ "module",
89
+ "source",
90
+ "browser"
91
+ ].some((field) => typeof manifest[field] === "string" && isPathInside(aliasDirectory, path.resolve(packageRoot, manifest[field])));
92
+ } catch {
93
+ return false;
94
+ }
95
+ }
96
+ var OgAssetOwnership = class {
97
+ projectRoot = process.cwd();
98
+ linkedPackageRoots = /* @__PURE__ */ new Set();
99
+ dependencyPackageNames = /* @__PURE__ */ new Map();
100
+ stringAliasesByFirstCharacter = /* @__PURE__ */ new Map();
101
+ regularExpressionAliases = [];
102
+ configuredAliases = [];
103
+ configure(projectRoot, aliases) {
104
+ this.projectRoot = path.resolve(projectRoot);
105
+ this.dependencyPackageNames.clear();
106
+ try {
107
+ const manifest = JSON.parse(fs.readFileSync(path.join(this.projectRoot, "package.json"), "utf8"));
108
+ for (const field of [
109
+ "dependencies",
110
+ "devDependencies",
111
+ "optionalDependencies",
112
+ "peerDependencies"
113
+ ]) {
114
+ const dependencies = manifest[field];
115
+ if (dependencies === null || typeof dependencies !== "object") continue;
116
+ for (const [packageName, value] of Object.entries(dependencies)) this.dependencyPackageNames.set(packageName, getAliasedPackageName(value) ?? packageName);
117
+ }
118
+ } catch {}
119
+ this.stringAliasesByFirstCharacter.clear();
120
+ this.regularExpressionAliases = [];
121
+ this.configuredAliases = [];
122
+ for (const [index, alias] of aliases.entries()) {
123
+ const indexedAlias = {
124
+ ...alias,
125
+ index
126
+ };
127
+ this.configuredAliases.push(indexedAlias);
128
+ if (typeof alias.find === "string") {
129
+ const firstCharacter = alias.find[0];
130
+ if (firstCharacter === void 0) continue;
131
+ const matchingAliases = this.stringAliasesByFirstCharacter.get(firstCharacter) ?? [];
132
+ matchingAliases.push(indexedAlias);
133
+ this.stringAliasesByFirstCharacter.set(firstCharacter, matchingAliases);
134
+ } else this.regularExpressionAliases.push(indexedAlias);
135
+ }
136
+ }
137
+ reset() {
138
+ this.linkedPackageRoots.clear();
139
+ }
140
+ shouldTrackImport(source) {
141
+ return this.findAlias(source) !== void 0 || this.getExpectedPackageName(source) !== void 0;
142
+ }
143
+ async recordResolvedImport(source, resolvedId) {
144
+ const configuredAlias = this.findAlias(source);
145
+ const sourcePackageName = getPackageNameFromSpecifier(source);
146
+ const expectedPackageName = this.getExpectedPackageName(source);
147
+ if (configuredAlias === void 0 && expectedPackageName === void 0) return;
148
+ let realResolvedPath;
149
+ try {
150
+ realResolvedPath = await realpathNative(path.resolve(resolvedId.split("?")[0]));
151
+ } catch {
152
+ return;
153
+ }
154
+ let packageRoot;
155
+ if (configuredAlias !== void 0) packageRoot = await this.resolveAliasPackageRoot(configuredAlias, source, sourcePackageName, realResolvedPath);
156
+ else packageRoot = await findPackageRoot(path.dirname(realResolvedPath), expectedPackageName);
157
+ if (packageRoot !== null) this.linkedPackageRoots.add(packageRoot);
158
+ }
159
+ async resolveModuleBoundary(moduleId) {
160
+ const modulePath = path.resolve(moduleId.split("?")[0]);
161
+ let realProjectRoot;
162
+ let realModulePath;
163
+ try {
164
+ [realProjectRoot, realModulePath] = await Promise.all([realpathNative(this.projectRoot), realpathNative(modulePath)]);
165
+ } catch {
166
+ try {
167
+ realProjectRoot = await realpathNative(this.projectRoot);
168
+ const realModuleDir = await realpathNative(path.dirname(modulePath));
169
+ realModulePath = path.join(realModuleDir, path.basename(modulePath));
170
+ } catch {
171
+ return null;
172
+ }
173
+ }
174
+ const moduleDir = path.dirname(realModulePath);
175
+ const logicalPackageRoot = getNodeModulesPackageRoot(this.projectRoot, modulePath);
176
+ if (logicalPackageRoot !== null) {
177
+ let realPackageRoot;
178
+ try {
179
+ realPackageRoot = await realpathNative(logicalPackageRoot);
180
+ } catch {
181
+ return null;
182
+ }
183
+ if (isPathInside(realPackageRoot, realModulePath)) return {
184
+ assetRoot: realPackageRoot,
185
+ moduleDir
186
+ };
187
+ const declaredPackageName = await readPackageName(logicalPackageRoot);
188
+ if (declaredPackageName === null) return null;
189
+ const logicalModuleRelativePath = path.relative(logicalPackageRoot, modulePath);
190
+ if (path.isAbsolute(logicalModuleRelativePath) || logicalModuleRelativePath === ".." || logicalModuleRelativePath.startsWith(`..${path.sep}`)) return null;
191
+ const canonicalPackageRoot = await findPackageRoot(moduleDir, declaredPackageName);
192
+ if (canonicalPackageRoot === null) return null;
193
+ if (path.relative(canonicalPackageRoot, realModulePath) !== logicalModuleRelativePath) return null;
194
+ return {
195
+ assetRoot: canonicalPackageRoot,
196
+ moduleDir
197
+ };
198
+ }
199
+ if (isPathInside(realProjectRoot, realModulePath)) return {
200
+ assetRoot: realProjectRoot,
201
+ moduleDir
202
+ };
203
+ const linkedPackageRoot = [...this.linkedPackageRoots].filter((root) => isPathInside(root, realModulePath)).sort((a, b) => b.length - a.length)[0];
204
+ if (linkedPackageRoot !== void 0) return {
205
+ assetRoot: linkedPackageRoot,
206
+ moduleDir
207
+ };
208
+ const configuredAliasRoot = await this.resolveConfiguredAliasRoot(realModulePath);
209
+ return configuredAliasRoot === null ? null : {
210
+ assetRoot: configuredAliasRoot,
211
+ moduleDir
212
+ };
213
+ }
214
+ async resolveContainedAsset(assetRoot, assetPath) {
215
+ try {
216
+ const realPath = await realpathNative(assetPath);
217
+ return isPathInside(assetRoot, realPath) ? realPath : null;
218
+ } catch {
219
+ return null;
220
+ }
221
+ }
222
+ findAlias(source) {
223
+ return [...this.stringAliasesByFirstCharacter.get(source[0] ?? "") ?? [], ...this.regularExpressionAliases].filter((alias) => aliasMatches(alias.find, source)).sort((a, b) => a.index - b.index)[0];
224
+ }
225
+ getExpectedPackageName(source) {
226
+ const packageName = getPackageNameFromSpecifier(source);
227
+ return packageName === null ? void 0 : this.dependencyPackageNames.get(packageName);
228
+ }
229
+ async resolveAliasPackageRoot(alias, source, sourcePackageName, realResolvedPath) {
230
+ const aliasTarget = applyAlias(alias.find, alias.replacement, source);
231
+ if (!path.isAbsolute(aliasTarget)) return null;
232
+ try {
233
+ const realAliasTarget = await realpathNative(aliasTarget);
234
+ const aliasTargetStat = await fs.promises.stat(realAliasTarget);
235
+ const hasCapture = alias.find instanceof RegExp && alias.replacement.includes("$");
236
+ let configuredDirectory = null;
237
+ if (!hasCapture) {
238
+ const realReplacement = await realpathNative(alias.replacement);
239
+ if ((await fs.promises.stat(realReplacement)).isDirectory()) configuredDirectory = realReplacement;
240
+ }
241
+ if (configuredDirectory !== null || aliasTargetStat.isDirectory()) {
242
+ const aliasBoundary = configuredDirectory ?? realAliasTarget;
243
+ const packageRoot = await findPackageRoot(path.dirname(realResolvedPath));
244
+ if (packageRoot === null || !isPathInside(aliasBoundary, packageRoot) || !isPathInside(packageRoot, realResolvedPath)) return null;
245
+ return packageRoot;
246
+ }
247
+ const packageRoot = await findPackageRoot(path.dirname(realResolvedPath));
248
+ if (packageRoot === null || !await packageOwnsAliasFile(packageRoot, sourcePackageName, realAliasTarget) || !isPathInside(packageRoot, realResolvedPath)) return null;
249
+ return packageRoot;
250
+ } catch {
251
+ return null;
252
+ }
253
+ }
254
+ async resolveConfiguredAliasRoot(realModulePath) {
255
+ const packageRoot = await findPackageRoot(path.dirname(realModulePath));
256
+ if (packageRoot === null || !isPathInside(packageRoot, realModulePath)) return null;
257
+ for (const alias of this.configuredAliases) {
258
+ if (!path.isAbsolute(alias.replacement)) continue;
259
+ const packageName = typeof alias.find === "string" ? getPackageNameFromSpecifier(alias.find) : null;
260
+ if (alias.replacement.indexOf("$") !== -1) {
261
+ const packageManifestName = await readPackageName(packageRoot);
262
+ if (packageManifestName === null || !aliasMatches(alias.find, packageManifestName)) continue;
263
+ const aliasTarget = applyAlias(alias.find, alias.replacement, packageManifestName);
264
+ if (!path.isAbsolute(aliasTarget)) continue;
265
+ try {
266
+ const realAliasTarget = await realpathNative(aliasTarget);
267
+ const aliasTargetStat = await fs.promises.stat(realAliasTarget);
268
+ if (aliasTargetStat.isDirectory() && isPathInside(realAliasTarget, realModulePath) || aliasTargetStat.isFile() && realAliasTarget === realModulePath) return packageRoot;
269
+ } catch {}
270
+ continue;
271
+ }
272
+ try {
273
+ const realReplacement = await realpathNative(alias.replacement);
274
+ if ((await fs.promises.stat(realReplacement)).isDirectory()) {
275
+ if (isPathInside(packageRoot, realReplacement) && isPathInside(realReplacement, realModulePath) && await packageOwnsAliasDirectory(packageRoot, packageName, realReplacement)) return packageRoot;
276
+ continue;
277
+ }
278
+ if (realReplacement === realModulePath && await packageOwnsAliasFile(packageRoot, packageName, realReplacement)) return packageRoot;
279
+ } catch {}
280
+ }
281
+ return null;
282
+ }
283
+ };
284
+ //#endregion
285
+ export { OgAssetOwnership };
@@ -1,3 +1,4 @@
1
+ import { OgAssetOwnership } from "./og-asset-ownership.js";
1
2
  import { createRequire } from "node:module";
2
3
  import fs from "node:fs";
3
4
  import path from "node:path";
@@ -15,29 +16,46 @@ import MagicString from "magic-string";
15
16
  */
16
17
  function createOgInlineFetchAssetsPlugin() {
17
18
  const cache = /* @__PURE__ */ new Map();
19
+ const ownership = new OgAssetOwnership();
18
20
  let isBuild = false;
19
21
  return {
20
22
  name: "vinext:og-inline-fetch-assets",
21
23
  enforce: "pre",
22
24
  configResolved(config) {
23
25
  isBuild = config.command === "build";
26
+ ownership.configure(config.root, config.resolve.alias);
24
27
  },
25
28
  buildStart() {
26
29
  if (isBuild) cache.clear();
30
+ ownership.reset();
31
+ },
32
+ async resolveId(source, importer, options) {
33
+ if (!ownership.shouldTrackImport(source)) return null;
34
+ const resolved = await this.resolve(source, importer, {
35
+ ...options,
36
+ skipSelf: true
37
+ });
38
+ if (resolved === null || resolved.external) return null;
39
+ await ownership.recordResolvedImport(source, resolved.id);
40
+ return null;
27
41
  },
28
42
  transform: {
29
43
  filter: { code: "import.meta.url" },
30
44
  async handler(code, id) {
31
45
  const useCache = isBuild;
32
- const moduleDir = path.dirname(id);
33
- let newCode = code;
46
+ const boundary = await ownership.resolveModuleBoundary(id);
47
+ if (boundary === null) return null;
48
+ const { assetRoot, moduleDir } = boundary;
49
+ const s = new MagicString(code);
34
50
  let didReplace = false;
35
51
  const readAsBase64 = async (absPath) => {
36
- const cached = useCache ? cache.get(absPath) : void 0;
52
+ const realPath = await ownership.resolveContainedAsset(assetRoot, absPath);
53
+ if (realPath === null) return null;
54
+ const cached = useCache ? cache.get(realPath) : void 0;
37
55
  if (cached !== void 0) return cached;
38
56
  try {
39
- const b64 = (await fs.promises.readFile(absPath)).toString("base64");
40
- if (useCache) cache.set(absPath, b64);
57
+ const b64 = (await fs.promises.readFile(realPath)).toString("base64");
58
+ if (useCache) cache.set(realPath, b64);
41
59
  return b64;
42
60
  } catch {
43
61
  return null;
@@ -57,22 +75,22 @@ function createOgInlineFetchAssetsPlugin() {
57
75
  `return Promise.resolve(a.buffer);`,
58
76
  `})()`
59
77
  ].join("");
60
- newCode = newCode.replaceAll(fullMatch, inlined);
78
+ s.overwrite(match.index, match.index + fullMatch.length, inlined);
61
79
  didReplace = true;
62
80
  }
63
- if (code.includes("readFileSync(")) for (const match of newCode.matchAll(/[a-zA-Z_$][a-zA-Z0-9_$]*\.readFileSync\(\s*(?:[a-zA-Z_$][a-zA-Z0-9_$]*\.)?fileURLToPath\(\s*new URL\(\s*(["'])(\.[^"']+)\1\s*,\s*import\.meta\.url\s*\)\s*\)\s*\)/g)) {
81
+ if (code.includes("readFileSync(")) for (const match of code.matchAll(/[a-zA-Z_$][a-zA-Z0-9_$]*\.readFileSync\(\s*(?:[a-zA-Z_$][a-zA-Z0-9_$]*\.)?fileURLToPath\(\s*new URL\(\s*(["'])(\.[^"']+)\1\s*,\s*import\.meta\.url\s*\)\s*\)\s*\)/g)) {
64
82
  const fullMatch = match[0];
65
83
  const relPath = match[2];
66
84
  const fileBase64 = await readAsBase64(path.resolve(moduleDir, relPath));
67
85
  if (fileBase64 === null) continue;
68
86
  const inlined = `Buffer.from(${JSON.stringify(fileBase64)},"base64")`;
69
- newCode = newCode.replaceAll(fullMatch, inlined);
87
+ s.overwrite(match.index, match.index + fullMatch.length, inlined);
70
88
  didReplace = true;
71
89
  }
72
90
  if (!didReplace) return null;
73
91
  return {
74
- code: newCode,
75
- map: null
92
+ code: s.toString(),
93
+ map: s.generateMap({ hires: "boundary" })
76
94
  };
77
95
  }
78
96
  }
@@ -32,7 +32,6 @@ const SCOPE_ENTERING_TYPES = new Set([
32
32
  */
33
33
  function removeConsoleCalls(code, config) {
34
34
  if (config === false) return null;
35
- const excluded = typeof config === "object" ? new Set(config.exclude.map((s) => s.toLowerCase())) : /* @__PURE__ */ new Set();
36
35
  if (!code.match(/\bconsole\b/)) return null;
37
36
  let ast;
38
37
  try {
@@ -40,6 +39,7 @@ function removeConsoleCalls(code, config) {
40
39
  } catch {
41
40
  return null;
42
41
  }
42
+ const excluded = typeof config === "object" ? new Set(config.exclude.map((s) => s.toLowerCase())) : /* @__PURE__ */ new Set();
43
43
  const scopeStack = [{ shadowed: false }];
44
44
  function currentScope() {
45
45
  return scopeStack[scopeStack.length - 1];
@@ -13,7 +13,8 @@ const SERVER_EXPORTS = new Set([
13
13
  const SERVER_PROPS_SSG_CONFLICT = "You can not use getStaticProps or getStaticPaths with getServerSideProps. To use SSG, please remove getServerSideProps";
14
14
  const EXPORT_ALL_IN_PAGE_ERROR = "Using `export * from '...'` in a page is disallowed. Please use `export { default } from '...'` instead.\nRead more: https://nextjs.org/docs/messages/export-all-in-page";
15
15
  function hasServerExportCandidate(code) {
16
- return [...SERVER_EXPORTS].some((name) => code.includes(name));
16
+ for (const name of SERVER_EXPORTS) if (code.includes(name)) return true;
17
+ return false;
17
18
  }
18
19
  function hasExportAllCandidate(code) {
19
20
  let searchFrom = 0;
@@ -0,0 +1,29 @@
1
+ import { IncomingMessage } from "node:http";
2
+
3
+ //#region src/server/accept-encoding.d.ts
4
+ type ContentEncoding = "zstd" | "br" | "gzip" | "deflate";
5
+ type NegotiatedEncoding = ContentEncoding | "identity";
6
+ /** Parsed explicit coding qualities plus the wildcard quality, when present. */
7
+ type ParsedAcceptEncoding = {
8
+ qualities: Map<string, number>;
9
+ orders: Map<string, number>;
10
+ wildcardQuality: number | null;
11
+ };
12
+ /** Parse an Accept-Encoding header into exact-token numeric qualities. */
13
+ declare function parseAcceptedEncodings(accept: string): ParsedAcceptEncoding;
14
+ /** Return the effective quality for a coding, including wildcard/identity rules. */
15
+ declare function getEncodingQuality(parsed: ParsedAcceptEncoding, encoding: string): number;
16
+ declare function isEncodingAccepted(parsed: ParsedAcceptEncoding, encoding: string): boolean;
17
+ /** Choose the highest-quality available coding, using array order as the tie-breaker. */
18
+ declare function selectAcceptedEncoding<T extends string>(parsed: ParsedAcceptEncoding, available: readonly T[]): T | null;
19
+ /**
20
+ * Select a content coding while matching Next.js's compression middleware:
21
+ * an explicit identity preference can win, but implicit identity remains a
22
+ * fallback rather than suppressing an otherwise acceptable encoding.
23
+ */
24
+ declare function selectContentEncoding<T extends ContentEncoding>(parsed: ParsedAcceptEncoding, available: readonly T[]): T | "identity";
25
+ declare const HAS_ZSTD: boolean;
26
+ /** Select by client q-value first, then zstd > br > gzip > deflate > identity. */
27
+ declare function negotiateEncoding(req: IncomingMessage): NegotiatedEncoding;
28
+ //#endregion
29
+ export { HAS_ZSTD, NegotiatedEncoding, ParsedAcceptEncoding, getEncodingQuality, isEncodingAccepted, negotiateEncoding, parseAcceptedEncodings, selectAcceptedEncoding, selectContentEncoding };
@@ -0,0 +1,95 @@
1
+ import zlib from "node:zlib";
2
+ //#region src/server/accept-encoding.ts
3
+ /** Parse an Accept-Encoding header into exact-token numeric qualities. */
4
+ function parseAcceptedEncodings(accept) {
5
+ const qualities = /* @__PURE__ */ new Map();
6
+ const orders = /* @__PURE__ */ new Map();
7
+ let wildcardQuality = null;
8
+ for (const [order, part] of accept.split(",").entries()) {
9
+ const trimmed = part.trim();
10
+ if (trimmed.length === 0) continue;
11
+ const semi = trimmed.indexOf(";");
12
+ const token = (semi === -1 ? trimmed : trimmed.slice(0, semi)).trim().toLowerCase();
13
+ if (token.length === 0) continue;
14
+ let quality = 1;
15
+ if (semi !== -1) {
16
+ let qStr;
17
+ for (const param of trimmed.slice(semi + 1).split(";")) {
18
+ const [name, value] = param.trim().split("=");
19
+ if (name !== "q") continue;
20
+ qStr = value ?? "";
21
+ break;
22
+ }
23
+ if (qStr !== void 0) quality = Number.parseFloat(qStr);
24
+ }
25
+ if (token === "*") {
26
+ if (wildcardQuality === null || Number.isNaN(quality) || Number.isNaN(wildcardQuality) || quality >= wildcardQuality) wildcardQuality = quality;
27
+ } else {
28
+ const currentQuality = qualities.get(token);
29
+ if (currentQuality === void 0 || Number.isNaN(quality) || Number.isNaN(currentQuality) || quality >= currentQuality) {
30
+ qualities.set(token, quality);
31
+ orders.set(token, order);
32
+ }
33
+ }
34
+ }
35
+ return {
36
+ qualities,
37
+ orders,
38
+ wildcardQuality
39
+ };
40
+ }
41
+ /** Return the effective quality for a coding, including wildcard/identity rules. */
42
+ function getEncodingQuality(parsed, encoding) {
43
+ const normalized = encoding.toLowerCase();
44
+ const explicit = parsed.qualities.get(normalized);
45
+ if (explicit !== void 0) return Number.isNaN(explicit) ? 0 : explicit;
46
+ if (normalized === "identity") return parsed.wildcardQuality === 0 ? 0 : 1;
47
+ if (parsed.wildcardQuality !== null) return Number.isNaN(parsed.wildcardQuality) ? 0 : parsed.wildcardQuality;
48
+ return 0;
49
+ }
50
+ function isEncodingAccepted(parsed, encoding) {
51
+ return getEncodingQuality(parsed, encoding) > 0;
52
+ }
53
+ /** Choose the highest-quality available coding, using array order as the tie-breaker. */
54
+ function selectAcceptedEncoding(parsed, available) {
55
+ let selected = null;
56
+ let selectedQuality = 0;
57
+ for (const encoding of available) {
58
+ const quality = getEncodingQuality(parsed, encoding);
59
+ if (quality > selectedQuality) {
60
+ selected = encoding;
61
+ selectedQuality = quality;
62
+ }
63
+ }
64
+ return selected;
65
+ }
66
+ /**
67
+ * Select a content coding while matching Next.js's compression middleware:
68
+ * an explicit identity preference can win, but implicit identity remains a
69
+ * fallback rather than suppressing an otherwise acceptable encoding.
70
+ */
71
+ function selectContentEncoding(parsed, available) {
72
+ const selected = selectAcceptedEncoding(parsed, available);
73
+ if (selected === null) return "identity";
74
+ const identityQuality = parsed.qualities.get("identity");
75
+ if (identityQuality === void 0 || Number.isNaN(identityQuality)) return selected;
76
+ const selectedQuality = getEncodingQuality(parsed, selected);
77
+ if (identityQuality > selectedQuality) return "identity";
78
+ if (identityQuality < selectedQuality) return selected;
79
+ if (!parsed.qualities.has(selected)) return "identity";
80
+ return (parsed.orders.get("identity") ?? Number.POSITIVE_INFINITY) < (parsed.orders.get(selected) ?? Number.POSITIVE_INFINITY) ? "identity" : selected;
81
+ }
82
+ const HAS_ZSTD = typeof zlib.createZstdCompress === "function";
83
+ /** Select by client q-value first, then zstd > br > gzip > deflate > identity. */
84
+ function negotiateEncoding(req) {
85
+ const accept = req.headers["accept-encoding"];
86
+ if (typeof accept !== "string") return "identity";
87
+ return selectContentEncoding(parseAcceptedEncodings(accept), [
88
+ ...HAS_ZSTD ? ["zstd"] : [],
89
+ "br",
90
+ "gzip",
91
+ "deflate"
92
+ ]);
93
+ }
94
+ //#endregion
95
+ export { HAS_ZSTD, getEncodingQuality, isEncodingAccepted, negotiateEncoding, parseAcceptedEncodings, selectAcceptedEncoding, selectContentEncoding };
@@ -0,0 +1,4 @@
1
+ //#region src/server/app-action-request.d.ts
2
+ declare function isPossibleAppRouteActionRequest(request: Pick<Request, "headers" | "method">): boolean;
3
+ //#endregion
4
+ export { isPossibleAppRouteActionRequest };
@@ -0,0 +1,9 @@
1
+ import "./headers.js";
2
+ //#region src/server/app-action-request.ts
3
+ function isPossibleAppRouteActionRequest(request) {
4
+ if (request.method.toUpperCase() !== "POST") return false;
5
+ const contentType = request.headers.get("content-type");
6
+ return request.headers.has("x-rsc-action") || request.headers.has("next-action") || contentType === "application/x-www-form-urlencoded" || contentType?.startsWith("multipart/form-data") === true;
7
+ }
8
+ //#endregion
9
+ export { isPossibleAppRouteActionRequest };
@@ -1,13 +1,23 @@
1
- import { AppElements } from "./app-elements-wire.js";
1
+ import { AppElements, AppElementsWire } from "./app-elements-wire.js";
2
2
  import { BfcacheIdMap } from "./app-history-state.js";
3
3
 
4
4
  //#region src/server/app-bfcache-identity.d.ts
5
5
  type BfcacheStateKeyMap = Readonly<Record<string, string>>;
6
+ type InitialBfcacheMaps = Readonly<{
7
+ bfcacheIds: BfcacheIdMap;
8
+ stateKeys: BfcacheStateKeyMap;
9
+ }>;
10
+ type AppElementsMetadata = ReturnType<typeof AppElementsWire.readMetadata>;
6
11
  declare function createInitialBfcacheIdMap(elements: AppElements): BfcacheIdMap;
7
12
  declare function createBfcacheSegmentStateKeyMap(options: {
8
13
  elements: AppElements;
9
14
  pathname: string;
10
15
  }): BfcacheStateKeyMap;
16
+ declare function createInitialBfcacheMaps(options: {
17
+ elements: AppElements;
18
+ metadata: AppElementsMetadata;
19
+ pathname: string;
20
+ }): InitialBfcacheMaps;
11
21
  declare function createNextBfcacheIdMap(options: {
12
22
  current: BfcacheIdMap;
13
23
  currentElements: AppElements;
@@ -23,4 +33,4 @@ declare function preserveBfcacheIdsForMergedElements(options: {
23
33
  previous: BfcacheIdMap;
24
34
  }): BfcacheIdMap;
25
35
  //#endregion
26
- export { BfcacheStateKeyMap, createBfcacheSegmentStateKeyMap, createInitialBfcacheIdMap, createNextBfcacheIdMap, preserveBfcacheIdsForMergedElements };
36
+ export { BfcacheStateKeyMap, InitialBfcacheMaps, createBfcacheSegmentStateKeyMap, createInitialBfcacheIdMap, createInitialBfcacheMaps, createNextBfcacheIdMap, preserveBfcacheIdsForMergedElements };