@vercel/next 29.0.0 → 29.1.0-snapshot-9209a1e84cf9
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/bin/LICENSE.nextjs +21 -0
- package/dist/bin/proxy-linux-amd64 +0 -0
- package/dist/go-runtime/packager.js +574 -0
- package/dist/index.js +11521 -2576
- package/package.json +6 -3
- package/LICENSE +0 -202
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vercel, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
Binary file
|
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// ../../internals/ipc-proxy/dist/dev-proxy.js
|
|
34
|
+
var require_dev_proxy = __commonJS({
|
|
35
|
+
"../../internals/ipc-proxy/dist/dev-proxy.js"(exports, module2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var __defProp2 = Object.defineProperty;
|
|
38
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
39
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
40
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
41
|
+
var __export2 = (target, all) => {
|
|
42
|
+
for (var name in all)
|
|
43
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
44
|
+
};
|
|
45
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
46
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
47
|
+
for (let key of __getOwnPropNames2(from))
|
|
48
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
49
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
50
|
+
}
|
|
51
|
+
return to;
|
|
52
|
+
};
|
|
53
|
+
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
54
|
+
var dev_proxy_exports = {};
|
|
55
|
+
__export2(dev_proxy_exports, {
|
|
56
|
+
createDevProxyServer: () => createDevProxyServer,
|
|
57
|
+
findFreePort: () => findFreePort,
|
|
58
|
+
normalizeServiceRoutePrefix: () => normalizeServiceRoutePrefix,
|
|
59
|
+
resolveServiceRoutePrefix: () => resolveServiceRoutePrefix,
|
|
60
|
+
rewriteRequestUrl: () => rewriteRequestUrl,
|
|
61
|
+
sanitizeHeaders: () => sanitizeHeaders,
|
|
62
|
+
startDevProxy: () => startDevProxy,
|
|
63
|
+
stripServiceRoutePrefix: () => stripServiceRoutePrefix,
|
|
64
|
+
waitForPort: () => waitForPort
|
|
65
|
+
});
|
|
66
|
+
module2.exports = __toCommonJS2(dev_proxy_exports);
|
|
67
|
+
var import_node_http = require("http");
|
|
68
|
+
var import_node_net = require("net");
|
|
69
|
+
var PING_PATH = "/_vercel/ping";
|
|
70
|
+
var INTERNAL_HEADER_PREFIX = "x-vercel-internal-";
|
|
71
|
+
var LOCALHOST = "127.0.0.1";
|
|
72
|
+
var DEFAULT_READINESS_TIMEOUT = 5 * 6e4;
|
|
73
|
+
var READINESS_POLL_INTERVAL = 100;
|
|
74
|
+
var READINESS_DIAL_TIMEOUT = 1e3;
|
|
75
|
+
function normalizeServiceRoutePrefix(rawPrefix) {
|
|
76
|
+
if (!rawPrefix)
|
|
77
|
+
return "";
|
|
78
|
+
let prefix = rawPrefix.trim();
|
|
79
|
+
if (!prefix)
|
|
80
|
+
return "";
|
|
81
|
+
if (!prefix.startsWith("/")) {
|
|
82
|
+
prefix = `/${prefix}`;
|
|
83
|
+
}
|
|
84
|
+
if (prefix !== "/") {
|
|
85
|
+
prefix = prefix.replace(/\/+$/, "");
|
|
86
|
+
if (!prefix)
|
|
87
|
+
prefix = "/";
|
|
88
|
+
}
|
|
89
|
+
return prefix === "/" ? "" : prefix;
|
|
90
|
+
}
|
|
91
|
+
function resolveServiceRoutePrefix(env = process.env) {
|
|
92
|
+
const strip = (env.VERCEL_SERVICE_ROUTE_PREFIX_STRIP ?? "").trim().toLowerCase();
|
|
93
|
+
if (strip !== "1" && strip !== "true")
|
|
94
|
+
return "";
|
|
95
|
+
return normalizeServiceRoutePrefix(env.VERCEL_SERVICE_ROUTE_PREFIX);
|
|
96
|
+
}
|
|
97
|
+
function stripServiceRoutePrefix(pathValue, prefix) {
|
|
98
|
+
if (pathValue === "*")
|
|
99
|
+
return pathValue;
|
|
100
|
+
let normalized = pathValue;
|
|
101
|
+
if (!normalized) {
|
|
102
|
+
normalized = "/";
|
|
103
|
+
} else if (!normalized.startsWith("/")) {
|
|
104
|
+
normalized = `/${normalized}`;
|
|
105
|
+
}
|
|
106
|
+
if (!prefix)
|
|
107
|
+
return normalized;
|
|
108
|
+
if (normalized === prefix)
|
|
109
|
+
return "/";
|
|
110
|
+
if (normalized.startsWith(`${prefix}/`)) {
|
|
111
|
+
return normalized.slice(prefix.length) || "/";
|
|
112
|
+
}
|
|
113
|
+
return normalized;
|
|
114
|
+
}
|
|
115
|
+
function splitUrl(url) {
|
|
116
|
+
const queryIndex = url.indexOf("?");
|
|
117
|
+
if (queryIndex === -1)
|
|
118
|
+
return { pathname: url, search: "" };
|
|
119
|
+
return { pathname: url.slice(0, queryIndex), search: url.slice(queryIndex) };
|
|
120
|
+
}
|
|
121
|
+
function rewriteRequestUrl(url, prefix) {
|
|
122
|
+
const { pathname, search } = splitUrl(url || "/");
|
|
123
|
+
return `${stripServiceRoutePrefix(pathname, prefix)}${search}`;
|
|
124
|
+
}
|
|
125
|
+
function sanitizeHeaders(headers) {
|
|
126
|
+
const sanitized = {};
|
|
127
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
128
|
+
if (key.toLowerCase().startsWith(INTERNAL_HEADER_PREFIX))
|
|
129
|
+
continue;
|
|
130
|
+
sanitized[key] = value;
|
|
131
|
+
}
|
|
132
|
+
const forwardedHost = headers["x-forwarded-host"];
|
|
133
|
+
const host = Array.isArray(forwardedHost) ? forwardedHost[0] : forwardedHost;
|
|
134
|
+
if (host) {
|
|
135
|
+
sanitized.host = host;
|
|
136
|
+
}
|
|
137
|
+
return sanitized;
|
|
138
|
+
}
|
|
139
|
+
function findFreePort() {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
const server = (0, import_node_net.createServer)();
|
|
142
|
+
server.unref();
|
|
143
|
+
server.once("error", reject);
|
|
144
|
+
server.listen(0, LOCALHOST, () => {
|
|
145
|
+
const address = server.address();
|
|
146
|
+
if (!address || typeof address === "string") {
|
|
147
|
+
server.close(() => reject(new Error("Failed to allocate a free port")));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const { port } = address;
|
|
151
|
+
server.close(() => resolve(port));
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function isPortReachable(port) {
|
|
156
|
+
return new Promise((resolve) => {
|
|
157
|
+
const socket = (0, import_node_net.createConnection)({ port, host: LOCALHOST });
|
|
158
|
+
const done = (reachable) => {
|
|
159
|
+
socket.removeAllListeners();
|
|
160
|
+
socket.destroy();
|
|
161
|
+
resolve(reachable);
|
|
162
|
+
};
|
|
163
|
+
socket.setTimeout(READINESS_DIAL_TIMEOUT);
|
|
164
|
+
socket.once("connect", () => done(true));
|
|
165
|
+
socket.once("timeout", () => done(false));
|
|
166
|
+
socket.once("error", () => done(false));
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function sleep(ms) {
|
|
170
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
171
|
+
}
|
|
172
|
+
async function waitForPort(port, child, timeout, label = "Dev server") {
|
|
173
|
+
let exited;
|
|
174
|
+
let spawnError;
|
|
175
|
+
const onExit = (code, signal) => {
|
|
176
|
+
exited = { code, signal };
|
|
177
|
+
};
|
|
178
|
+
const onError = (err) => {
|
|
179
|
+
spawnError = err;
|
|
180
|
+
};
|
|
181
|
+
child.once("exit", onExit);
|
|
182
|
+
child.once("error", onError);
|
|
183
|
+
try {
|
|
184
|
+
const start = Date.now();
|
|
185
|
+
while (Date.now() - start < timeout) {
|
|
186
|
+
if (spawnError)
|
|
187
|
+
throw spawnError;
|
|
188
|
+
if (exited) {
|
|
189
|
+
throw new Error(
|
|
190
|
+
`${label} exited before it started listening (code: ${exited.code}, signal: ${exited.signal})`
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
if (await isPortReachable(port))
|
|
194
|
+
return;
|
|
195
|
+
await sleep(READINESS_POLL_INTERVAL);
|
|
196
|
+
}
|
|
197
|
+
throw new Error(`${label} did not start listening within ${timeout}ms`);
|
|
198
|
+
} finally {
|
|
199
|
+
child.removeListener("exit", onExit);
|
|
200
|
+
child.removeListener("error", onError);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function createDevProxyServer(options) {
|
|
204
|
+
const { targetPort } = options;
|
|
205
|
+
const routePrefix = normalizeServiceRoutePrefix(options.routePrefix);
|
|
206
|
+
const server = (0, import_node_http.createServer)((req, res) => {
|
|
207
|
+
const { pathname } = splitUrl(req.url || "/");
|
|
208
|
+
if (pathname === PING_PATH) {
|
|
209
|
+
res.writeHead(200, { "content-type": "text/plain" });
|
|
210
|
+
res.end("OK");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const proxyReq = (0, import_node_http.request)(
|
|
214
|
+
{
|
|
215
|
+
host: LOCALHOST,
|
|
216
|
+
port: targetPort,
|
|
217
|
+
method: req.method,
|
|
218
|
+
path: rewriteRequestUrl(req.url || "/", routePrefix),
|
|
219
|
+
headers: sanitizeHeaders(req.headers)
|
|
220
|
+
},
|
|
221
|
+
(proxyRes) => {
|
|
222
|
+
res.writeHead(proxyRes.statusCode ?? 502, proxyRes.headers);
|
|
223
|
+
proxyRes.pipe(res);
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
proxyReq.once("error", (err) => {
|
|
227
|
+
if (!res.headersSent) {
|
|
228
|
+
res.writeHead(502, { "content-type": "text/plain" });
|
|
229
|
+
}
|
|
230
|
+
res.end(`Dev proxy error: ${err.message}`);
|
|
231
|
+
});
|
|
232
|
+
res.once("close", () => {
|
|
233
|
+
if (!res.writableFinished)
|
|
234
|
+
proxyReq.destroy();
|
|
235
|
+
});
|
|
236
|
+
req.pipe(proxyReq);
|
|
237
|
+
});
|
|
238
|
+
server.on("upgrade", (req, clientSocket, head) => {
|
|
239
|
+
const headers = sanitizeHeaders(req.headers);
|
|
240
|
+
const path = rewriteRequestUrl(req.url || "/", routePrefix);
|
|
241
|
+
const upstream = (0, import_node_net.createConnection)(
|
|
242
|
+
{ host: LOCALHOST, port: targetPort },
|
|
243
|
+
() => {
|
|
244
|
+
const lines = [`${req.method} ${path} HTTP/${req.httpVersion}`];
|
|
245
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
246
|
+
if (Array.isArray(value)) {
|
|
247
|
+
for (const entry of value)
|
|
248
|
+
lines.push(`${key}: ${entry}`);
|
|
249
|
+
} else if (value !== void 0) {
|
|
250
|
+
lines.push(`${key}: ${value}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
upstream.write(`${lines.join("\r\n")}\r
|
|
254
|
+
\r
|
|
255
|
+
`);
|
|
256
|
+
if (head?.length)
|
|
257
|
+
upstream.write(new Uint8Array(head));
|
|
258
|
+
upstream.pipe(clientSocket);
|
|
259
|
+
clientSocket.pipe(upstream);
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
const destroy = () => {
|
|
263
|
+
upstream.destroy();
|
|
264
|
+
clientSocket.destroy();
|
|
265
|
+
};
|
|
266
|
+
upstream.once("error", destroy);
|
|
267
|
+
clientSocket.once("error", destroy);
|
|
268
|
+
});
|
|
269
|
+
return server;
|
|
270
|
+
}
|
|
271
|
+
async function startDevProxy(options) {
|
|
272
|
+
const {
|
|
273
|
+
spawnServer,
|
|
274
|
+
env = process.env,
|
|
275
|
+
readinessTimeout = DEFAULT_READINESS_TIMEOUT,
|
|
276
|
+
label = "Dev server"
|
|
277
|
+
} = options;
|
|
278
|
+
const internalPort = await findFreePort();
|
|
279
|
+
const child = spawnServer(internalPort);
|
|
280
|
+
let server;
|
|
281
|
+
const close = async () => {
|
|
282
|
+
if (server) {
|
|
283
|
+
await new Promise((resolve) => {
|
|
284
|
+
server?.close(() => resolve());
|
|
285
|
+
server?.closeAllConnections?.();
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
289
|
+
child.kill("SIGTERM");
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
try {
|
|
293
|
+
await waitForPort(internalPort, child, readinessTimeout, label);
|
|
294
|
+
server = createDevProxyServer({
|
|
295
|
+
targetPort: internalPort,
|
|
296
|
+
routePrefix: resolveServiceRoutePrefix(env)
|
|
297
|
+
});
|
|
298
|
+
const listenPort = options.port ?? await findFreePort();
|
|
299
|
+
await new Promise((resolve, reject) => {
|
|
300
|
+
server?.once("error", reject);
|
|
301
|
+
server?.listen(listenPort, () => resolve());
|
|
302
|
+
});
|
|
303
|
+
if (!child.pid) {
|
|
304
|
+
throw new Error(`${label} started without a PID`);
|
|
305
|
+
}
|
|
306
|
+
return { port: listenPort, pid: child.pid, child, close };
|
|
307
|
+
} catch (err) {
|
|
308
|
+
await close();
|
|
309
|
+
throw err;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// ../../internals/ipc-proxy/dist/index.js
|
|
316
|
+
var require_dist = __commonJS({
|
|
317
|
+
"../../internals/ipc-proxy/dist/index.js"(exports, module2) {
|
|
318
|
+
"use strict";
|
|
319
|
+
var __defProp2 = Object.defineProperty;
|
|
320
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
321
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
322
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
323
|
+
var __export2 = (target, all) => {
|
|
324
|
+
for (var name in all)
|
|
325
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
326
|
+
};
|
|
327
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
328
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
329
|
+
for (let key of __getOwnPropNames2(from))
|
|
330
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
331
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
332
|
+
}
|
|
333
|
+
return to;
|
|
334
|
+
};
|
|
335
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps2(target, mod, "default"), secondTarget && __copyProps2(secondTarget, mod, "default"));
|
|
336
|
+
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
337
|
+
var src_exports = {};
|
|
338
|
+
__export2(src_exports, {
|
|
339
|
+
createStandaloneLambda: () => createStandaloneLambda,
|
|
340
|
+
getBootstrapDir: () => getBootstrapDir,
|
|
341
|
+
getProxyBinaryPath: () => getProxyBinaryPath,
|
|
342
|
+
getStandaloneExecutableFiles: () => getStandaloneExecutableFiles2
|
|
343
|
+
});
|
|
344
|
+
module2.exports = __toCommonJS2(src_exports);
|
|
345
|
+
var import_node_path = require("path");
|
|
346
|
+
var import_node_fs = require("fs");
|
|
347
|
+
var import_promises2 = require("fs/promises");
|
|
348
|
+
var import_build_utils = require("@vercel/build-utils");
|
|
349
|
+
__reExport(src_exports, require_dev_proxy(), module2.exports);
|
|
350
|
+
function proxyBinaryName(architecture) {
|
|
351
|
+
return architecture === "arm64" ? "proxy-linux-arm64" : "proxy-linux-amd64";
|
|
352
|
+
}
|
|
353
|
+
function getProxyBinaryPath(architecture) {
|
|
354
|
+
const binPath = (0, import_node_path.join)(__dirname, "..", "bin", proxyBinaryName(architecture));
|
|
355
|
+
if (!(0, import_node_fs.existsSync)(binPath)) {
|
|
356
|
+
throw new Error(
|
|
357
|
+
`IPC proxy binary not found for architecture "${architecture}" at ${binPath}. Ensure @vercel-internals/ipc-proxy has been built and its prebuilt binaries copied alongside the consumer's dist output.`
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
return binPath;
|
|
361
|
+
}
|
|
362
|
+
function getBootstrapDir() {
|
|
363
|
+
return (0, import_node_path.join)(__dirname, "..", "bootstrap");
|
|
364
|
+
}
|
|
365
|
+
function getStandaloneExecutableFiles2(options) {
|
|
366
|
+
return {
|
|
367
|
+
executable: {
|
|
368
|
+
fsPath: getProxyBinaryPath(options.architecture),
|
|
369
|
+
mode: 493
|
|
370
|
+
},
|
|
371
|
+
"user-server": { fsPath: options.userServerPath, mode: 493 }
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
async function createStandaloneLambda(options) {
|
|
375
|
+
const {
|
|
376
|
+
userServerPath,
|
|
377
|
+
architecture,
|
|
378
|
+
lambdaOptions,
|
|
379
|
+
includedFiles,
|
|
380
|
+
runtimeLanguage,
|
|
381
|
+
supportsResponseStreaming = true
|
|
382
|
+
} = options;
|
|
383
|
+
const executableFiles = getStandaloneExecutableFiles2({
|
|
384
|
+
userServerPath,
|
|
385
|
+
architecture
|
|
386
|
+
});
|
|
387
|
+
const [proxyData, userServerData] = await Promise.all([
|
|
388
|
+
(0, import_promises2.readFile)(executableFiles.executable.fsPath),
|
|
389
|
+
(0, import_promises2.readFile)(executableFiles["user-server"].fsPath)
|
|
390
|
+
]);
|
|
391
|
+
return new import_build_utils.Lambda({
|
|
392
|
+
...lambdaOptions,
|
|
393
|
+
files: {
|
|
394
|
+
...includedFiles,
|
|
395
|
+
executable: new import_build_utils.FileBlob({
|
|
396
|
+
mode: executableFiles.executable.mode,
|
|
397
|
+
data: proxyData
|
|
398
|
+
}),
|
|
399
|
+
"user-server": new import_build_utils.FileBlob({
|
|
400
|
+
mode: executableFiles["user-server"].mode,
|
|
401
|
+
data: userServerData
|
|
402
|
+
})
|
|
403
|
+
},
|
|
404
|
+
handler: "executable",
|
|
405
|
+
runtime: "executable",
|
|
406
|
+
supportsResponseStreaming,
|
|
407
|
+
architecture,
|
|
408
|
+
runtimeLanguage
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// src/go-runtime/packager.ts
|
|
415
|
+
var packager_exports = {};
|
|
416
|
+
__export(packager_exports, {
|
|
417
|
+
prepareGoFunction: () => prepareGoFunction,
|
|
418
|
+
version: () => version
|
|
419
|
+
});
|
|
420
|
+
module.exports = __toCommonJS(packager_exports);
|
|
421
|
+
var import_promises = require("fs/promises");
|
|
422
|
+
var import_ipc_proxy = __toESM(require_dist());
|
|
423
|
+
var version = 1;
|
|
424
|
+
var ELF_HEADER_SIZE = 64;
|
|
425
|
+
var PROGRAM_HEADER_SIZE = 56;
|
|
426
|
+
function invalidExecutable(path, reason) {
|
|
427
|
+
return new Error(
|
|
428
|
+
`Invalid Go server executable at "${path}": ${reason}. The Next.js Go proof of concept requires a statically linked Linux x86_64 executable (CGO_ENABLED=0).`
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
async function readExactly(file, size, offset, path) {
|
|
432
|
+
const bytes = new Uint8Array(size);
|
|
433
|
+
let bytesRead = 0;
|
|
434
|
+
while (bytesRead < size) {
|
|
435
|
+
const result = await file.read(
|
|
436
|
+
bytes,
|
|
437
|
+
bytesRead,
|
|
438
|
+
size - bytesRead,
|
|
439
|
+
offset + bytesRead
|
|
440
|
+
);
|
|
441
|
+
if (result.bytesRead === 0) {
|
|
442
|
+
throw invalidExecutable(path, "truncated ELF data");
|
|
443
|
+
}
|
|
444
|
+
bytesRead += result.bytesRead;
|
|
445
|
+
}
|
|
446
|
+
return Buffer.from(bytes.buffer);
|
|
447
|
+
}
|
|
448
|
+
function fileOffset(value, size, path) {
|
|
449
|
+
if (value > BigInt(size)) {
|
|
450
|
+
throw invalidExecutable(path, "ELF data extends beyond the file");
|
|
451
|
+
}
|
|
452
|
+
return Number(value);
|
|
453
|
+
}
|
|
454
|
+
async function validateExecutable(path) {
|
|
455
|
+
const file = await (0, import_promises.open)(path, "r");
|
|
456
|
+
try {
|
|
457
|
+
const stats = await file.stat();
|
|
458
|
+
if (!stats.isFile() || stats.size < ELF_HEADER_SIZE) {
|
|
459
|
+
throw invalidExecutable(path, "expected an ELF executable file");
|
|
460
|
+
}
|
|
461
|
+
const header = await readExactly(file, ELF_HEADER_SIZE, 0, path);
|
|
462
|
+
if (header.readUInt32BE(0) !== 2135247942 || header[4] !== 2 || header[5] !== 1 || header[6] !== 1 || header[7] !== 0 && header[7] !== 3 || header.readUInt32LE(20) !== 1) {
|
|
463
|
+
throw invalidExecutable(path, "expected a 64-bit little-endian ELF file");
|
|
464
|
+
}
|
|
465
|
+
const executableType = header.readUInt16LE(16);
|
|
466
|
+
if (executableType !== 2 && executableType !== 3 || header.readUInt16LE(18) !== 62) {
|
|
467
|
+
throw invalidExecutable(path, "expected an x86_64 executable");
|
|
468
|
+
}
|
|
469
|
+
const entrypoint = header.readBigUInt64LE(24);
|
|
470
|
+
const programHeaderOffset = fileOffset(
|
|
471
|
+
header.readBigUInt64LE(32),
|
|
472
|
+
stats.size,
|
|
473
|
+
path
|
|
474
|
+
);
|
|
475
|
+
const programHeaderCount = header.readUInt16LE(56);
|
|
476
|
+
if (header.readUInt16LE(52) !== ELF_HEADER_SIZE || header.readUInt16LE(54) !== PROGRAM_HEADER_SIZE || programHeaderCount === 0 || // Extended counts require section headers, which this small validator
|
|
477
|
+
// deliberately does not interpret.
|
|
478
|
+
programHeaderCount === 65535 || programHeaderOffset < ELF_HEADER_SIZE || programHeaderOffset + programHeaderCount * PROGRAM_HEADER_SIZE > stats.size) {
|
|
479
|
+
throw invalidExecutable(path, "invalid ELF program headers");
|
|
480
|
+
}
|
|
481
|
+
const programHeaders = await readExactly(
|
|
482
|
+
file,
|
|
483
|
+
programHeaderCount * PROGRAM_HEADER_SIZE,
|
|
484
|
+
programHeaderOffset,
|
|
485
|
+
path
|
|
486
|
+
);
|
|
487
|
+
let hasExecutableEntrypoint = false;
|
|
488
|
+
for (let i = 0; i < programHeaderCount; i++) {
|
|
489
|
+
const offset = i * PROGRAM_HEADER_SIZE;
|
|
490
|
+
const type = programHeaders.readUInt32LE(offset);
|
|
491
|
+
if (type === 3) {
|
|
492
|
+
throw invalidExecutable(
|
|
493
|
+
path,
|
|
494
|
+
"dynamic ELF interpreters are unsupported"
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
const dataOffset = fileOffset(
|
|
498
|
+
programHeaders.readBigUInt64LE(offset + 8),
|
|
499
|
+
stats.size,
|
|
500
|
+
path
|
|
501
|
+
);
|
|
502
|
+
const dataSize = fileOffset(
|
|
503
|
+
programHeaders.readBigUInt64LE(offset + 32),
|
|
504
|
+
stats.size,
|
|
505
|
+
path
|
|
506
|
+
);
|
|
507
|
+
if (dataOffset + dataSize > stats.size) {
|
|
508
|
+
throw invalidExecutable(path, "ELF segment extends beyond the file");
|
|
509
|
+
}
|
|
510
|
+
if (type === 1) {
|
|
511
|
+
const address = programHeaders.readBigUInt64LE(offset + 16);
|
|
512
|
+
const memorySize = programHeaders.readBigUInt64LE(offset + 40);
|
|
513
|
+
if (memorySize < BigInt(dataSize)) {
|
|
514
|
+
throw invalidExecutable(path, "invalid ELF load segment");
|
|
515
|
+
}
|
|
516
|
+
if (programHeaders.readUInt32LE(offset + 4) & 1 && entrypoint >= address && entrypoint < address + BigInt(dataSize)) {
|
|
517
|
+
hasExecutableEntrypoint = true;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (type === 2) {
|
|
521
|
+
if (dataSize % 16 !== 0) {
|
|
522
|
+
throw invalidExecutable(path, "invalid ELF dynamic table");
|
|
523
|
+
}
|
|
524
|
+
let hasTerminator = false;
|
|
525
|
+
for (let dynamicOffset = 0; dynamicOffset < dataSize && !hasTerminator; dynamicOffset += 65536) {
|
|
526
|
+
const entries = await readExactly(
|
|
527
|
+
file,
|
|
528
|
+
Math.min(65536, dataSize - dynamicOffset),
|
|
529
|
+
dataOffset + dynamicOffset,
|
|
530
|
+
path
|
|
531
|
+
);
|
|
532
|
+
for (let entryOffset = 0; entryOffset < entries.length; entryOffset += 16) {
|
|
533
|
+
const tag = entries.readBigUInt64LE(entryOffset);
|
|
534
|
+
if (tag === BigInt(1)) {
|
|
535
|
+
throw invalidExecutable(
|
|
536
|
+
path,
|
|
537
|
+
"dynamic library dependencies are unsupported"
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
if (tag === BigInt(0)) {
|
|
541
|
+
hasTerminator = true;
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (!hasTerminator) {
|
|
547
|
+
throw invalidExecutable(path, "unterminated ELF dynamic table");
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (!hasExecutableEntrypoint) {
|
|
552
|
+
throw invalidExecutable(
|
|
553
|
+
path,
|
|
554
|
+
"entrypoint is outside executable ELF load segments"
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
} finally {
|
|
558
|
+
await file.close();
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
async function prepareGoFunction(options) {
|
|
562
|
+
await validateExecutable(options.userServerPath);
|
|
563
|
+
return {
|
|
564
|
+
files: (0, import_ipc_proxy.getStandaloneExecutableFiles)({
|
|
565
|
+
userServerPath: options.userServerPath,
|
|
566
|
+
architecture: "x86_64"
|
|
567
|
+
})
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
571
|
+
0 && (module.exports = {
|
|
572
|
+
prepareGoFunction,
|
|
573
|
+
version
|
|
574
|
+
});
|