@next-community/adapter-vercel 0.0.0 → 0.0.1-beta.1
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.
- package/dist/index.js +63 -24
- package/dist/node-handler.js +83 -20
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -9650,7 +9650,7 @@ async function validateSize(script, wasmFiles) {
|
|
|
9650
9650
|
// src/outputs.ts
|
|
9651
9651
|
var import_node_handler = require("./node-handler");
|
|
9652
9652
|
function fallbackHasFilePath(fallback) {
|
|
9653
|
-
return fallback !== void 0 && "filePath" in fallback;
|
|
9653
|
+
return fallback !== void 0 && "filePath" in fallback && typeof fallback.filePath === "string";
|
|
9654
9654
|
}
|
|
9655
9655
|
var copy = async (src, dest) => {
|
|
9656
9656
|
await import_fs_extra3.default.remove(dest);
|
|
@@ -9841,8 +9841,11 @@ async function handleNodeOutputs(nodeOutputs, {
|
|
|
9841
9841
|
}
|
|
9842
9842
|
async function handlePrerenderOutputs(prerenderOutputs, {
|
|
9843
9843
|
config,
|
|
9844
|
+
hasAppEntries,
|
|
9844
9845
|
vercelOutputDir,
|
|
9845
|
-
nodeOutputsParentMap
|
|
9846
|
+
nodeOutputsParentMap,
|
|
9847
|
+
rscContentType,
|
|
9848
|
+
varyHeader
|
|
9846
9849
|
}) {
|
|
9847
9850
|
const prerenderParentIds = /* @__PURE__ */ new Set();
|
|
9848
9851
|
const fsSema = new import_async_sema.Sema(16, { capacity: prerenderOutputs.length });
|
|
@@ -9864,7 +9867,18 @@ async function handlePrerenderOutputs(prerenderOutputs, {
|
|
|
9864
9867
|
output.pathname,
|
|
9865
9868
|
config
|
|
9866
9869
|
)}.prerender-fallback${import_node_path.default.extname(output.fallback.filePath)}`
|
|
9867
|
-
) :
|
|
9870
|
+
) : (
|
|
9871
|
+
// Use the fallback value for the RSC route if the route doesn't
|
|
9872
|
+
// vary based on the route parameters and there's an actual postponed
|
|
9873
|
+
// state to fallback to.
|
|
9874
|
+
output.fallback?.postponedState && output.config.allowQuery && output.config.allowQuery.length === 0 ? import_node_path.default.join(
|
|
9875
|
+
functionsDir,
|
|
9876
|
+
`${normalizeIndexPathname(
|
|
9877
|
+
output.pathname,
|
|
9878
|
+
config
|
|
9879
|
+
)}.prerender-fallback${import_node_path.default.extname(output.pathname)}`
|
|
9880
|
+
) : void 0
|
|
9881
|
+
);
|
|
9868
9882
|
const { parentOutputId } = output;
|
|
9869
9883
|
prerenderParentIds.add(parentOutputId);
|
|
9870
9884
|
const parentNodeOutput = nodeOutputsParentMap.get(parentOutputId);
|
|
@@ -9901,18 +9915,27 @@ async function handlePrerenderOutputs(prerenderOutputs, {
|
|
|
9901
9915
|
}
|
|
9902
9916
|
const initialHeaders = Object.assign(
|
|
9903
9917
|
{},
|
|
9918
|
+
hasAppEntries ? { vary: varyHeader } : {},
|
|
9904
9919
|
output.fallback?.initialHeaders
|
|
9905
9920
|
);
|
|
9921
|
+
const isRscOutput = import_node_path.default.extname(output.pathname) === ".rsc";
|
|
9906
9922
|
if (output.fallback?.postponedState && fallbackHasFilePath(output.fallback) && prerenderFallbackPath) {
|
|
9907
|
-
const
|
|
9923
|
+
const fallbackContent = await import_promises.default.readFile(
|
|
9908
9924
|
output.fallback.filePath,
|
|
9909
9925
|
"utf8"
|
|
9910
9926
|
);
|
|
9911
9927
|
await writeIfNotExists(
|
|
9912
9928
|
prerenderFallbackPath,
|
|
9913
|
-
`${output.fallback.postponedState}${
|
|
9929
|
+
`${output.fallback.postponedState}${fallbackContent}`
|
|
9930
|
+
);
|
|
9931
|
+
const originContentType = isRscOutput ? rscContentType : "text/html; charset=utf-8";
|
|
9932
|
+
initialHeaders["content-type"] = `application/x-nextjs-pre-render; state-length=${output.fallback.postponedState.length}; origin=${JSON.stringify(originContentType)}`;
|
|
9933
|
+
} else if (output.fallback?.postponedState && !fallbackHasFilePath(output.fallback) && prerenderFallbackPath) {
|
|
9934
|
+
await writeIfNotExists(
|
|
9935
|
+
prerenderFallbackPath,
|
|
9936
|
+
output.fallback.postponedState
|
|
9914
9937
|
);
|
|
9915
|
-
initialHeaders["content-type"] = `application/x-nextjs-pre-render; state-length=${output.fallback.postponedState.length}; origin
|
|
9938
|
+
initialHeaders["content-type"] = `application/x-nextjs-pre-render; state-length=${output.fallback.postponedState.length}; origin=${JSON.stringify(rscContentType)}`;
|
|
9916
9939
|
}
|
|
9917
9940
|
await import_promises.default.mkdir(import_node_path.default.dirname(prerenderConfigPath), { recursive: true });
|
|
9918
9941
|
await writeIfNotExists(
|
|
@@ -9936,18 +9959,24 @@ async function handlePrerenderOutputs(prerenderOutputs, {
|
|
|
9936
9959
|
fallback: prerenderFallbackPath ? import_node_path.default.posix.relative(
|
|
9937
9960
|
import_node_path.default.dirname(prerenderConfigPath),
|
|
9938
9961
|
prerenderFallbackPath
|
|
9939
|
-
) :
|
|
9962
|
+
) : null,
|
|
9940
9963
|
chain: output.pprChain ? {
|
|
9941
9964
|
...output.pprChain,
|
|
9942
|
-
outputPath: import_node_path.default.posix.join(
|
|
9965
|
+
outputPath: import_node_path.default.posix.join(
|
|
9966
|
+
"./",
|
|
9967
|
+
`${normalizeIndexPathname(output.pathname, config)}`
|
|
9968
|
+
)
|
|
9943
9969
|
} : void 0
|
|
9944
9970
|
}
|
|
9945
9971
|
)
|
|
9946
9972
|
);
|
|
9947
|
-
if (fallbackHasFilePath(output.fallback) && prerenderFallbackPath && // if postponed state is present we write the fallback file above
|
|
9973
|
+
if (fallbackHasFilePath(output.fallback) && prerenderFallbackPath && // if postponed state is not present we write the fallback file above
|
|
9948
9974
|
!output.fallback.postponedState) {
|
|
9949
9975
|
await copy(output.fallback.filePath, prerenderFallbackPath);
|
|
9950
9976
|
}
|
|
9977
|
+
if (output.fallback && Object.keys(initialHeaders || {}).length === 0) {
|
|
9978
|
+
throw new Error("empty initialHeaders");
|
|
9979
|
+
}
|
|
9951
9980
|
} catch (err) {
|
|
9952
9981
|
console.error(`Failed to handle output:`, output);
|
|
9953
9982
|
throw err;
|
|
@@ -9982,11 +10011,10 @@ async function handleEdgeOutputs(edgeOutputs, {
|
|
|
9982
10011
|
if (jsRegex.test(fsPath)) {
|
|
9983
10012
|
files[relPath] = import_node_path.default.posix.relative(repoRoot, fsPath);
|
|
9984
10013
|
} else {
|
|
9985
|
-
|
|
9986
|
-
files[assetPath] = import_node_path.default.posix.relative(repoRoot, fsPath);
|
|
10014
|
+
files[`assets/${relPath}`] = import_node_path.default.posix.relative(repoRoot, fsPath);
|
|
9987
10015
|
nonJsAssetFiles.push({
|
|
9988
10016
|
name: relPath,
|
|
9989
|
-
path:
|
|
10017
|
+
path: `assets/${relPath}`
|
|
9990
10018
|
});
|
|
9991
10019
|
}
|
|
9992
10020
|
}
|
|
@@ -9995,8 +10023,8 @@ async function handleEdgeOutputs(edgeOutputs, {
|
|
|
9995
10023
|
}
|
|
9996
10024
|
files[import_node_path.default.posix.relative(projectDir, output.filePath)] = import_node_path.default.posix.relative(repoRoot, output.filePath);
|
|
9997
10025
|
const filePaths = [
|
|
9998
|
-
import_node_path.default.posix.relative(projectDir,
|
|
9999
|
-
|
|
10026
|
+
...Object.values(output.assets).map((item) => import_node_path.default.posix.relative(projectDir, item)).filter((item) => jsRegex.test(item)),
|
|
10027
|
+
import_node_path.default.posix.relative(projectDir, output.filePath)
|
|
10000
10028
|
];
|
|
10001
10029
|
const params = {
|
|
10002
10030
|
name: output.id.replace(/\.rsc$/, ""),
|
|
@@ -10191,6 +10219,10 @@ function modifyWithRewriteHeaders(rewrites, {
|
|
|
10191
10219
|
if (index !== -1) {
|
|
10192
10220
|
query = query.substring(0, index);
|
|
10193
10221
|
}
|
|
10222
|
+
query = query.split("&").filter((part) => {
|
|
10223
|
+
const key = part.split("=")[0];
|
|
10224
|
+
return !key.startsWith("nxtP") && !key.startsWith("nxtI");
|
|
10225
|
+
}).join("&") || null;
|
|
10194
10226
|
} else {
|
|
10195
10227
|
index = pathname.indexOf("#");
|
|
10196
10228
|
if (index !== -1) {
|
|
@@ -10511,22 +10543,26 @@ var myAdapter = {
|
|
|
10511
10543
|
...outputs.appPages,
|
|
10512
10544
|
...outputs.appRoutes,
|
|
10513
10545
|
...outputs.pages,
|
|
10514
|
-
...outputs.pagesApi
|
|
10546
|
+
...outputs.pagesApi,
|
|
10547
|
+
...outputs.staticFiles
|
|
10515
10548
|
]) {
|
|
10516
|
-
if (output.pathname.endsWith("/_not-found")) {
|
|
10517
|
-
hasNotFoundOutput = true;
|
|
10518
|
-
}
|
|
10519
10549
|
if (output.pathname.endsWith("/404")) {
|
|
10550
|
+
hasNotFoundOutput = false;
|
|
10520
10551
|
has404Output = true;
|
|
10521
10552
|
}
|
|
10553
|
+
if (!has404Output && output.pathname.endsWith("/_not-found")) {
|
|
10554
|
+
hasNotFoundOutput = true;
|
|
10555
|
+
}
|
|
10522
10556
|
if (output.pathname.endsWith("/500")) {
|
|
10523
10557
|
has500Output = true;
|
|
10524
10558
|
}
|
|
10525
|
-
if (
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10559
|
+
if ("runtime" in output) {
|
|
10560
|
+
if (output.runtime === "nodejs") {
|
|
10561
|
+
nodeOutputsParentMap.set(output.id, output);
|
|
10562
|
+
nodeOutputs.push(output);
|
|
10563
|
+
} else if (output.runtime === "edge") {
|
|
10564
|
+
edgeOutputs.push(output);
|
|
10565
|
+
}
|
|
10530
10566
|
}
|
|
10531
10567
|
}
|
|
10532
10568
|
for (const output of outputs.staticFiles) {
|
|
@@ -10591,8 +10627,11 @@ var myAdapter = {
|
|
|
10591
10627
|
});
|
|
10592
10628
|
await handlePrerenderOutputs(outputs.prerenders, {
|
|
10593
10629
|
config,
|
|
10630
|
+
hasAppEntries: outputs.appPages.length > 0,
|
|
10631
|
+
varyHeader: routing.rsc.varyHeader,
|
|
10594
10632
|
vercelOutputDir,
|
|
10595
|
-
nodeOutputsParentMap
|
|
10633
|
+
nodeOutputsParentMap,
|
|
10634
|
+
rscContentType: routing.rsc.contentTypeHeader
|
|
10596
10635
|
});
|
|
10597
10636
|
const shouldHandleSegmentPrefetches = outputs.appPages.length > 0;
|
|
10598
10637
|
const convertedRewrites = normalizeRewrites(routing);
|
package/dist/node-handler.js
CHANGED
|
@@ -22,6 +22,7 @@ __export(node_handler_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(node_handler_exports);
|
|
24
24
|
const getHandlerSource = (ctx) => `
|
|
25
|
+
process.env.NODE_ENV = 'production';
|
|
25
26
|
require('next/dist/server/node-environment');
|
|
26
27
|
require('next/dist/server/node-polyfill-crypto');
|
|
27
28
|
|
|
@@ -33,7 +34,7 @@ const getHandlerSource = (ctx) => `
|
|
|
33
34
|
|
|
34
35
|
process.chdir(__dirname);
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
const _n_handler = (${ctx.isMiddleware ? () => {
|
|
37
38
|
const path = require("path");
|
|
38
39
|
const relativeDistDir = process.env.__PRIVATE_RELATIVE_DIST_DIR;
|
|
39
40
|
const SYMBOL_FOR_REQ_CONTEXT = Symbol.for("@vercel/request-context");
|
|
@@ -69,11 +70,22 @@ const getHandlerSource = (ctx) => `
|
|
|
69
70
|
const hydrateRoutesManifestItem = (item) => {
|
|
70
71
|
return {
|
|
71
72
|
...item,
|
|
72
|
-
|
|
73
|
+
namedRegex: new RegExp(item.namedRegex || item.regex)
|
|
73
74
|
};
|
|
74
75
|
};
|
|
76
|
+
const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g;
|
|
77
|
+
function escapeStringRegexp(str) {
|
|
78
|
+
return str.replace(matchOperatorsRegex, "\\$&");
|
|
79
|
+
}
|
|
75
80
|
const dynamicRoutes = dynamicRoutesRaw.map(hydrateRoutesManifestItem);
|
|
76
|
-
const staticRoutes = staticRoutesRaw.map(
|
|
81
|
+
const staticRoutes = staticRoutesRaw.map((route) => {
|
|
82
|
+
return {
|
|
83
|
+
...route,
|
|
84
|
+
namedRegex: new RegExp(
|
|
85
|
+
"^" + escapeStringRegexp(route.page) + "$"
|
|
86
|
+
)
|
|
87
|
+
};
|
|
88
|
+
});
|
|
77
89
|
let appPathRoutesManifest = {};
|
|
78
90
|
try {
|
|
79
91
|
appPathRoutesManifest = require("./" + path.posix.join(
|
|
@@ -115,7 +127,7 @@ const getHandlerSource = (ctx) => `
|
|
|
115
127
|
}
|
|
116
128
|
return pathname;
|
|
117
129
|
}
|
|
118
|
-
function matchUrlToPage(
|
|
130
|
+
function matchUrlToPage(urlPathname) {
|
|
119
131
|
urlPathname = normalizeDataPath(urlPathname);
|
|
120
132
|
console.log("before normalize", urlPathname);
|
|
121
133
|
for (const suffixRegex of [
|
|
@@ -132,8 +144,20 @@ const getHandlerSource = (ctx) => `
|
|
|
132
144
|
urlPathname = normalizeResult.pathname;
|
|
133
145
|
console.log("after normalize", normalizeResult);
|
|
134
146
|
urlPathname = urlPathname.replace(/\/$/, "") || "/";
|
|
147
|
+
const combinedRoutes = [...staticRoutes, ...dynamicRoutes];
|
|
148
|
+
for (const route of combinedRoutes) {
|
|
149
|
+
if (route.page === urlPathname) {
|
|
150
|
+
console.log("matched direct page", route);
|
|
151
|
+
return {
|
|
152
|
+
matchedPathname: inversedAppRoutesManifest[route.page] || route.page,
|
|
153
|
+
locale: normalizeResult.locale
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
135
157
|
for (const route of [...staticRoutes, ...dynamicRoutes]) {
|
|
136
|
-
|
|
158
|
+
console.log("testing", route.namedRegex, "against", urlPathname);
|
|
159
|
+
const matches = urlPathname.match(route.namedRegex);
|
|
160
|
+
if (matches || urlPathname === "/index" && route.namedRegex.test("/")) {
|
|
137
161
|
const fallbackFalseMap = prerenderFallbackFalseMap[route.page];
|
|
138
162
|
if (fallbackFalseMap && !(fallbackFalseMap.includes(urlPathname) || fallbackFalseMap.includes(urlPathnameWithLocale))) {
|
|
139
163
|
console.log("fallback: false but not prerendered", {
|
|
@@ -144,10 +168,11 @@ const getHandlerSource = (ctx) => `
|
|
|
144
168
|
});
|
|
145
169
|
continue;
|
|
146
170
|
}
|
|
147
|
-
console.log("matched route", route, urlPathname);
|
|
171
|
+
console.log("matched route", route, urlPathname, matches);
|
|
148
172
|
return {
|
|
149
173
|
matchedPathname: inversedAppRoutesManifest[route.page] || route.page,
|
|
150
|
-
locale: normalizeResult.locale
|
|
174
|
+
locale: normalizeResult.locale,
|
|
175
|
+
matches
|
|
151
176
|
};
|
|
152
177
|
}
|
|
153
178
|
}
|
|
@@ -172,13 +197,26 @@ const getHandlerSource = (ctx) => `
|
|
|
172
197
|
async render404(req, res) {
|
|
173
198
|
let mod;
|
|
174
199
|
try {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
200
|
+
try {
|
|
201
|
+
mod = await require("./" + path.posix.join(
|
|
202
|
+
relativeDistDir,
|
|
203
|
+
"server",
|
|
204
|
+
"app",
|
|
205
|
+
`_not-found`,
|
|
206
|
+
"page.js"
|
|
207
|
+
));
|
|
208
|
+
console.log("using _not-found.js for render404");
|
|
209
|
+
} catch {
|
|
210
|
+
}
|
|
211
|
+
if (!mod) {
|
|
212
|
+
mod = await require("./" + path.posix.join(
|
|
213
|
+
relativeDistDir,
|
|
214
|
+
"server",
|
|
215
|
+
"pages",
|
|
216
|
+
`404.js`
|
|
217
|
+
));
|
|
218
|
+
console.log("using 404.js for render404");
|
|
219
|
+
}
|
|
182
220
|
} catch (_) {
|
|
183
221
|
mod = await require("./" + path.posix.join(
|
|
184
222
|
relativeDistDir,
|
|
@@ -204,7 +242,7 @@ const getHandlerSource = (ctx) => `
|
|
|
204
242
|
}
|
|
205
243
|
}
|
|
206
244
|
};
|
|
207
|
-
return async function handler(req, res) {
|
|
245
|
+
return async function handler(req, res, internalMetadata) {
|
|
208
246
|
try {
|
|
209
247
|
const parsedUrl = new URL(req.url || "/", "http://n");
|
|
210
248
|
let urlPathname = req.headers["x-matched-path"];
|
|
@@ -212,11 +250,24 @@ const getHandlerSource = (ctx) => `
|
|
|
212
250
|
console.log("no x-matched-path", { url: req.url });
|
|
213
251
|
urlPathname = parsedUrl.pathname || "/";
|
|
214
252
|
}
|
|
215
|
-
const {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
253
|
+
const {
|
|
254
|
+
matchedPathname: page,
|
|
255
|
+
locale,
|
|
256
|
+
matches
|
|
257
|
+
} = matchUrlToPage(urlPathname);
|
|
219
258
|
const isAppDir = page.match(/\/(page|route)$/);
|
|
259
|
+
let addedMatchesToUrl = false;
|
|
260
|
+
for (const matchKey in matches?.groups || {}) {
|
|
261
|
+
const matchValue = matches?.groups?.[matchKey];
|
|
262
|
+
if (!parsedUrl.searchParams.has(matchKey) && matchValue) {
|
|
263
|
+
parsedUrl.searchParams.set(matchKey, matchValue);
|
|
264
|
+
addedMatchesToUrl = true;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (addedMatchesToUrl) {
|
|
268
|
+
console.log("updating URL with new matches", matches, req.url);
|
|
269
|
+
req.url = `${parsedUrl.pathname}${parsedUrl.searchParams.size > 0 ? "?" : ""}${parsedUrl.searchParams.toString()}`;
|
|
270
|
+
}
|
|
220
271
|
console.log("invoking handler", {
|
|
221
272
|
page,
|
|
222
273
|
url: req.url,
|
|
@@ -231,6 +282,7 @@ const getHandlerSource = (ctx) => `
|
|
|
231
282
|
await mod.handler(req, res, {
|
|
232
283
|
waitUntil: getRequestContext().waitUntil,
|
|
233
284
|
requestMeta: {
|
|
285
|
+
...internalMetadata,
|
|
234
286
|
minimalMode: true,
|
|
235
287
|
// we use '.' for relative project dir since we process.chdir
|
|
236
288
|
// to the same directory as the handler file so everything is
|
|
@@ -244,7 +296,18 @@ const getHandlerSource = (ctx) => `
|
|
|
244
296
|
throw error;
|
|
245
297
|
}
|
|
246
298
|
};
|
|
247
|
-
}).toString()})()
|
|
299
|
+
}).toString()})()
|
|
300
|
+
|
|
301
|
+
module.exports = _n_handler
|
|
302
|
+
|
|
303
|
+
${ctx.isMiddleware ? "" : `
|
|
304
|
+
module.exports.getRequestHandlerWithMetadata = (metadata) => {
|
|
305
|
+
console.log('using getRequestHandlerWithMetadata', metadata)
|
|
306
|
+
return (req, res) => _n_handler(req, res, metadata)
|
|
307
|
+
}
|
|
308
|
+
`}
|
|
309
|
+
|
|
310
|
+
`.replaceAll(
|
|
248
311
|
"process.env.__PRIVATE_RELATIVE_DIST_DIR",
|
|
249
312
|
`"${ctx.projectRelativeDistDir}"`
|
|
250
313
|
).replaceAll(
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-community/adapter-vercel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"url": "https://github.com/nextjs/adapter-vercel"
|
|
11
|
+
},
|
|
9
12
|
"devDependencies": {
|
|
10
13
|
"@types/bytes": "3.1.1",
|
|
11
14
|
"@types/convert-source-map": "1.5.2",
|