@vercel/next 31.0.2 → 32.0.0
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/adapter/index.js +163 -73
- package/dist/bin/proxy-linux-amd64 +0 -0
- package/dist/go-runtime/packager.js +117 -19
- package/package.json +8 -7
package/dist/adapter/index.js
CHANGED
|
@@ -10379,6 +10379,8 @@ async function getSourceFilePathFromPage({
|
|
|
10379
10379
|
}
|
|
10380
10380
|
|
|
10381
10381
|
// src/go-outputs.ts
|
|
10382
|
+
var GO_PACKAGER_VERSION = 2;
|
|
10383
|
+
var IMAGE_DIR = "image";
|
|
10382
10384
|
var RESERVED_NAMES = /* @__PURE__ */ new Set([
|
|
10383
10385
|
"executable",
|
|
10384
10386
|
"user-server",
|
|
@@ -10429,7 +10431,32 @@ function assertGoRouteOutput(value) {
|
|
|
10429
10431
|
"Go outputs require assets, assetsHashes, and config objects"
|
|
10430
10432
|
);
|
|
10431
10433
|
}
|
|
10432
|
-
|
|
10434
|
+
}
|
|
10435
|
+
async function resolveGoSourceFile(output, projectDir, usesSrcDir) {
|
|
10436
|
+
if (output.type === import_constants2.AdapterOutputType.MIDDLEWARE) {
|
|
10437
|
+
const sourceFile2 = `${output.sourcePage.slice(1)}.go`;
|
|
10438
|
+
if (!(await import_promises2.default.stat(import_node_path2.default.join(projectDir, sourceFile2))).isFile())
|
|
10439
|
+
throw new Error(`Could not resolve Go proxy source: ${sourceFile2}`);
|
|
10440
|
+
return sourceFile2;
|
|
10441
|
+
}
|
|
10442
|
+
const sourceFile = (await getSourceFilePathFromPage({
|
|
10443
|
+
workPath: projectDir,
|
|
10444
|
+
page: output.sourcePage,
|
|
10445
|
+
pageExtensions: ["go"],
|
|
10446
|
+
usesSrcDir,
|
|
10447
|
+
pageTypes: ["app"],
|
|
10448
|
+
allowExtensionless: false,
|
|
10449
|
+
allowDirectoryIndex: false
|
|
10450
|
+
})).replace(/\\/g, "/");
|
|
10451
|
+
if (!/^(src\/)?app\/(?:.*\/)?route\.go$/.test(sourceFile)) {
|
|
10452
|
+
throw new Error(
|
|
10453
|
+
`Could not resolve Go route.go source for ${output.sourcePage}`
|
|
10454
|
+
);
|
|
10455
|
+
}
|
|
10456
|
+
return sourceFile;
|
|
10457
|
+
}
|
|
10458
|
+
function assertGoAssets(assets) {
|
|
10459
|
+
const destinations = Object.keys(assets);
|
|
10433
10460
|
const portableDestinations = /* @__PURE__ */ new Set();
|
|
10434
10461
|
const portablePaths = /* @__PURE__ */ new Map();
|
|
10435
10462
|
for (const destination of destinations) {
|
|
@@ -10452,7 +10479,7 @@ function assertGoRouteOutput(value) {
|
|
|
10452
10479
|
}
|
|
10453
10480
|
portablePaths.set(portablePrefix, prefix);
|
|
10454
10481
|
}
|
|
10455
|
-
const source =
|
|
10482
|
+
const source = assets[destination];
|
|
10456
10483
|
if (typeof source !== "string" || !import_node_path2.default.isAbsolute(source)) {
|
|
10457
10484
|
throw new Error(
|
|
10458
10485
|
`Go asset ${destination} requires an absolute source path`
|
|
@@ -10526,28 +10553,39 @@ function loadGoPackager() {
|
|
|
10526
10553
|
);
|
|
10527
10554
|
}
|
|
10528
10555
|
const packager = require(modulePath);
|
|
10529
|
-
if (!isRecord(packager) || packager.version !==
|
|
10556
|
+
if (!isRecord(packager) || packager.version !== GO_PACKAGER_VERSION || typeof packager.prepareGoFunction !== "function" || packager.close !== void 0 && typeof packager.close !== "function") {
|
|
10530
10557
|
throw new Error(
|
|
10531
|
-
|
|
10558
|
+
`Unsupported @vercel/next Go packager: expected protocol version ${GO_PACKAGER_VERSION}`
|
|
10532
10559
|
);
|
|
10533
10560
|
}
|
|
10534
10561
|
return packager;
|
|
10535
10562
|
}
|
|
10563
|
+
function hasExactKeys(value, keys) {
|
|
10564
|
+
return isRecord(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
|
|
10565
|
+
}
|
|
10566
|
+
function isGoExecutableFile(value) {
|
|
10567
|
+
return isRecord(value) && typeof value.fsPath === "string" && import_node_path2.default.isAbsolute(value.fsPath) && value.mode === 493 && Object.keys(value).every((key) => key === "fsPath" || key === "mode");
|
|
10568
|
+
}
|
|
10536
10569
|
function assertPreparedGoFunction(value) {
|
|
10537
|
-
if (
|
|
10538
|
-
|
|
10570
|
+
if (isRecord(value) && "files" in value) {
|
|
10571
|
+
if (!hasExactKeys(value, ["files"]) || !hasExactKeys(value.files, ["executable", "user-server"]) || !isGoExecutableFile(value.files.executable) || !isGoExecutableFile(value.files["user-server"])) {
|
|
10572
|
+
throw new Error(
|
|
10573
|
+
"Go packager must provide executable and user-server files"
|
|
10574
|
+
);
|
|
10575
|
+
}
|
|
10576
|
+
return;
|
|
10539
10577
|
}
|
|
10540
|
-
if (
|
|
10578
|
+
if (!isRecord(value) || typeof value.handler !== "string" || !value.handler || Object.keys(value).some((key) => key !== "handler" && key !== "image")) {
|
|
10541
10579
|
throw new Error(
|
|
10542
|
-
"Go packager must
|
|
10580
|
+
"Go packager must return a container image handler and optional image"
|
|
10543
10581
|
);
|
|
10544
10582
|
}
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10583
|
+
if (value.image !== void 0 && (!isRecord(value.image) || value.image.type !== "oci-layout" || typeof value.image.directory !== "string" || !import_node_path2.default.isAbsolute(value.image.directory) || Object.keys(value.image).some(
|
|
10584
|
+
(key) => key !== "type" && key !== "directory"
|
|
10585
|
+
))) {
|
|
10586
|
+
throw new Error(
|
|
10587
|
+
"Go packager image must be an OCI layout with an absolute directory"
|
|
10588
|
+
);
|
|
10551
10589
|
}
|
|
10552
10590
|
}
|
|
10553
10591
|
function preferredRegions(preferredRegion) {
|
|
@@ -10587,7 +10625,7 @@ async function existingGoFunction(functionDir) {
|
|
|
10587
10625
|
return void 0;
|
|
10588
10626
|
}
|
|
10589
10627
|
})();
|
|
10590
|
-
if (!isRecord(previousConfig) || previousConfig.runtime !== "executable"
|
|
10628
|
+
if (!isRecord(previousConfig) || previousConfig.runtime !== "container" && !(previousConfig.runtime === "executable" && previousConfig.handler === "executable") || previousConfig.runtimeLanguage !== "go" || !isRecord(previousConfig.framework) || previousConfig.framework.slug !== "nextjs") {
|
|
10591
10629
|
throw outputCollision(functionDir);
|
|
10592
10630
|
}
|
|
10593
10631
|
return true;
|
|
@@ -10630,6 +10668,29 @@ async function handleGoOutputs(outputs, {
|
|
|
10630
10668
|
}) {
|
|
10631
10669
|
if (!outputs.length) return;
|
|
10632
10670
|
const packager = loadGoPackager();
|
|
10671
|
+
let closeFailure;
|
|
10672
|
+
try {
|
|
10673
|
+
await writeGoFunctions(packager, outputs, {
|
|
10674
|
+
config,
|
|
10675
|
+
projectDir,
|
|
10676
|
+
nextVersion,
|
|
10677
|
+
vercelOutputDir
|
|
10678
|
+
});
|
|
10679
|
+
} finally {
|
|
10680
|
+
try {
|
|
10681
|
+
await packager.close?.();
|
|
10682
|
+
} catch (error) {
|
|
10683
|
+
closeFailure = { error };
|
|
10684
|
+
}
|
|
10685
|
+
}
|
|
10686
|
+
if (closeFailure) throw closeFailure.error;
|
|
10687
|
+
}
|
|
10688
|
+
async function writeGoFunctions(packager, outputs, {
|
|
10689
|
+
config,
|
|
10690
|
+
projectDir,
|
|
10691
|
+
nextVersion,
|
|
10692
|
+
vercelOutputDir
|
|
10693
|
+
}) {
|
|
10633
10694
|
const builderConfig = JSON.parse(
|
|
10634
10695
|
process.env.NEXT_ADAPTER_VERCEL_CONFIG || "{}"
|
|
10635
10696
|
);
|
|
@@ -10646,71 +10707,100 @@ async function handleGoOutputs(outputs, {
|
|
|
10646
10707
|
throw new Error(`Conflicting Go function output: ${pathname}`);
|
|
10647
10708
|
functionPaths.set(caseInsensitivePath, functionPath);
|
|
10648
10709
|
}
|
|
10649
|
-
|
|
10650
|
-
|
|
10651
|
-
|
|
10652
|
-
|
|
10653
|
-
|
|
10654
|
-
|
|
10655
|
-
usesSrcDir,
|
|
10656
|
-
pageTypes: ["app"],
|
|
10657
|
-
allowExtensionless: false,
|
|
10658
|
-
allowDirectoryIndex: false
|
|
10659
|
-
})).replace(/\\/g, "/");
|
|
10660
|
-
if (isMiddleware) {
|
|
10661
|
-
if (!(await import_promises2.default.stat(import_node_path2.default.join(projectDir, sourceFile))).isFile())
|
|
10662
|
-
throw new Error(`Could not resolve Go proxy source: ${sourceFile}`);
|
|
10663
|
-
} else if (!/^(src\/)?app\/(?:.*\/)?route\.go$/.test(sourceFile)) {
|
|
10664
|
-
throw new Error(
|
|
10665
|
-
`Could not resolve Go route.go source for ${output.sourcePage}`
|
|
10666
|
-
);
|
|
10667
|
-
}
|
|
10668
|
-
const overrides = await (0, import_build_utils2.getLambdaOptionsFromFunction)({
|
|
10669
|
-
sourceFile,
|
|
10670
|
-
config: builderConfig
|
|
10671
|
-
});
|
|
10672
|
-
const prepared = await packager.prepareGoFunction({
|
|
10673
|
-
userServerPath: output.filePath
|
|
10674
|
-
});
|
|
10675
|
-
assertPreparedGoFunction(prepared);
|
|
10676
|
-
if (overrides.architecture && overrides.architecture !== "x86_64") {
|
|
10677
|
-
throw new Error(
|
|
10678
|
-
`Go target architecture conflicts with function configuration for ${sourceFile}`
|
|
10710
|
+
const results = await Promise.allSettled(
|
|
10711
|
+
outputs.map(async (output) => {
|
|
10712
|
+
const sourceFile = await resolveGoSourceFile(
|
|
10713
|
+
output,
|
|
10714
|
+
projectDir,
|
|
10715
|
+
usesSrcDir
|
|
10679
10716
|
);
|
|
10680
|
-
|
|
10681
|
-
|
|
10682
|
-
|
|
10717
|
+
const overrides = await (0, import_build_utils2.getLambdaOptionsFromFunction)({
|
|
10718
|
+
sourceFile,
|
|
10719
|
+
config: builderConfig
|
|
10720
|
+
});
|
|
10721
|
+
if (overrides.architecture && overrides.architecture !== "x86_64") {
|
|
10722
|
+
throw new Error(
|
|
10723
|
+
`Go target architecture conflicts with function configuration for ${sourceFile}`
|
|
10724
|
+
);
|
|
10725
|
+
}
|
|
10726
|
+
const regions = overrides.regions ?? preferredRegions(output.config.preferredRegion);
|
|
10727
|
+
const packaged = await packager.prepareGoFunction({
|
|
10728
|
+
userServerPath: output.filePath,
|
|
10729
|
+
type: output.type === import_constants2.AdapterOutputType.MIDDLEWARE ? "middleware" : "route"
|
|
10730
|
+
});
|
|
10731
|
+
assertPreparedGoFunction(packaged);
|
|
10732
|
+
if ("files" in packaged) {
|
|
10733
|
+
assertGoAssets(output.assets);
|
|
10734
|
+
} else if (Object.keys(output.assets).length > 0) {
|
|
10735
|
+
throw new Error(
|
|
10736
|
+
`Go function ${sourceFile} cannot include separate assets because it runs as a container image. Embed them in the executable, for example with go:embed.`
|
|
10737
|
+
);
|
|
10738
|
+
}
|
|
10739
|
+
const pathname = output.type === import_constants2.AdapterOutputType.MIDDLEWARE ? output.pathname : normalizeIndexPathname(output.pathname, config);
|
|
10740
|
+
return {
|
|
10741
|
+
functionDir: import_node_path2.default.join(functionsDir, `${pathname.slice(1)}.func`),
|
|
10742
|
+
// Deliberately omit Node launcher, multipayload and bundling properties.
|
|
10743
|
+
functionConfig: {
|
|
10744
|
+
...overrides,
|
|
10745
|
+
..."files" in packaged ? {
|
|
10746
|
+
runtime: "executable",
|
|
10747
|
+
handler: "executable"
|
|
10748
|
+
} : {
|
|
10749
|
+
runtime: "container",
|
|
10750
|
+
handler: packaged.handler,
|
|
10751
|
+
...packaged.image && {
|
|
10752
|
+
image: { type: "oci-layout", path: IMAGE_DIR }
|
|
10753
|
+
}
|
|
10754
|
+
},
|
|
10755
|
+
runtimeLanguage: "go",
|
|
10756
|
+
architecture: "x86_64",
|
|
10757
|
+
supportsResponseStreaming: true,
|
|
10758
|
+
maxDuration: output.config.maxDuration ?? overrides.maxDuration,
|
|
10759
|
+
regions,
|
|
10760
|
+
operationType: "API",
|
|
10761
|
+
framework: { slug: "nextjs", version: nextVersion }
|
|
10762
|
+
},
|
|
10763
|
+
packaged,
|
|
10764
|
+
assets: output.assets
|
|
10765
|
+
};
|
|
10766
|
+
})
|
|
10767
|
+
);
|
|
10768
|
+
const prepared = results.map((result) => {
|
|
10769
|
+
if (result.status === "rejected") throw result.reason;
|
|
10770
|
+
return result.value;
|
|
10771
|
+
});
|
|
10772
|
+
for (const { functionDir, functionConfig, packaged, assets } of prepared) {
|
|
10683
10773
|
await ensureFunctionParent(functionsDir, functionDir);
|
|
10684
10774
|
await existingGoFunction(functionDir);
|
|
10685
10775
|
const stagingDir = await import_promises2.default.mkdtemp(
|
|
10686
10776
|
import_node_path2.default.join(import_node_path2.default.dirname(functionDir), ".go-function-")
|
|
10687
10777
|
);
|
|
10688
10778
|
try {
|
|
10689
|
-
|
|
10690
|
-
const
|
|
10691
|
-
|
|
10692
|
-
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10702
|
-
|
|
10703
|
-
|
|
10704
|
-
|
|
10705
|
-
|
|
10706
|
-
|
|
10707
|
-
|
|
10708
|
-
|
|
10709
|
-
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
|
|
10713
|
-
}
|
|
10779
|
+
if ("files" in packaged) {
|
|
10780
|
+
for (const [destination, source] of Object.entries(assets)) {
|
|
10781
|
+
const sourceStat = await import_promises2.default.stat(source);
|
|
10782
|
+
if (!sourceStat.isFile())
|
|
10783
|
+
throw new Error(`Go asset is not a regular file: ${destination}`);
|
|
10784
|
+
const destinationPath = import_node_path2.default.join(stagingDir, destination);
|
|
10785
|
+
await import_promises2.default.mkdir(import_node_path2.default.dirname(destinationPath), { recursive: true });
|
|
10786
|
+
await import_promises2.default.copyFile(source, destinationPath);
|
|
10787
|
+
await import_promises2.default.chmod(destinationPath, sourceStat.mode & 511);
|
|
10788
|
+
}
|
|
10789
|
+
for (const [destination, file] of Object.entries(packaged.files)) {
|
|
10790
|
+
await import_promises2.default.copyFile(file.fsPath, import_node_path2.default.join(stagingDir, destination));
|
|
10791
|
+
await import_promises2.default.chmod(import_node_path2.default.join(stagingDir, destination), file.mode);
|
|
10792
|
+
}
|
|
10793
|
+
} else if (packaged.image) {
|
|
10794
|
+
await import_promises2.default.cp(
|
|
10795
|
+
packaged.image.directory,
|
|
10796
|
+
import_node_path2.default.join(stagingDir, IMAGE_DIR),
|
|
10797
|
+
{
|
|
10798
|
+
recursive: true,
|
|
10799
|
+
errorOnExist: true,
|
|
10800
|
+
force: false
|
|
10801
|
+
}
|
|
10802
|
+
);
|
|
10803
|
+
}
|
|
10714
10804
|
await import_promises2.default.writeFile(
|
|
10715
10805
|
import_node_path2.default.join(stagingDir, ".vc-config.json"),
|
|
10716
10806
|
JSON.stringify(functionConfig, null, 2)
|
|
Binary file
|
|
@@ -278,7 +278,7 @@ var require_dev_proxy = __commonJS({
|
|
|
278
278
|
const internalPort = await findFreePort();
|
|
279
279
|
const child = spawnServer(internalPort);
|
|
280
280
|
let server;
|
|
281
|
-
const
|
|
281
|
+
const close2 = async () => {
|
|
282
282
|
if (server) {
|
|
283
283
|
await new Promise((resolve) => {
|
|
284
284
|
server?.close(() => resolve());
|
|
@@ -303,9 +303,9 @@ var require_dev_proxy = __commonJS({
|
|
|
303
303
|
if (!child.pid) {
|
|
304
304
|
throw new Error(`${label} started without a PID`);
|
|
305
305
|
}
|
|
306
|
-
return { port: listenPort, pid: child.pid, child, close };
|
|
306
|
+
return { port: listenPort, pid: child.pid, child, close: close2 };
|
|
307
307
|
} catch (err) {
|
|
308
|
-
await
|
|
308
|
+
await close2();
|
|
309
309
|
throw err;
|
|
310
310
|
}
|
|
311
311
|
}
|
|
@@ -342,17 +342,17 @@ var require_dist = __commonJS({
|
|
|
342
342
|
getStandaloneExecutableFiles: () => getStandaloneExecutableFiles2
|
|
343
343
|
});
|
|
344
344
|
module2.exports = __toCommonJS2(src_exports);
|
|
345
|
-
var
|
|
346
|
-
var
|
|
347
|
-
var
|
|
345
|
+
var import_node_path2 = require("path");
|
|
346
|
+
var import_node_fs2 = require("fs");
|
|
347
|
+
var import_promises3 = require("fs/promises");
|
|
348
348
|
var import_build_utils = require("@vercel/build-utils");
|
|
349
349
|
__reExport(src_exports, require_dev_proxy(), module2.exports);
|
|
350
350
|
function proxyBinaryName(architecture) {
|
|
351
351
|
return architecture === "arm64" ? "proxy-linux-arm64" : "proxy-linux-amd64";
|
|
352
352
|
}
|
|
353
353
|
function getProxyBinaryPath(architecture) {
|
|
354
|
-
const binPath = (0,
|
|
355
|
-
if (!(0,
|
|
354
|
+
const binPath = (0, import_node_path2.join)(__dirname, "..", "bin", proxyBinaryName(architecture));
|
|
355
|
+
if (!(0, import_node_fs2.existsSync)(binPath)) {
|
|
356
356
|
throw new Error(
|
|
357
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
358
|
);
|
|
@@ -360,7 +360,7 @@ var require_dist = __commonJS({
|
|
|
360
360
|
return binPath;
|
|
361
361
|
}
|
|
362
362
|
function getBootstrapDir() {
|
|
363
|
-
return (0,
|
|
363
|
+
return (0, import_node_path2.join)(__dirname, "..", "bootstrap");
|
|
364
364
|
}
|
|
365
365
|
function getStandaloneExecutableFiles2(options) {
|
|
366
366
|
return {
|
|
@@ -385,8 +385,8 @@ var require_dist = __commonJS({
|
|
|
385
385
|
architecture
|
|
386
386
|
});
|
|
387
387
|
const [proxyData, userServerData] = await Promise.all([
|
|
388
|
-
(0,
|
|
389
|
-
(0,
|
|
388
|
+
(0, import_promises3.readFile)(executableFiles.executable.fsPath),
|
|
389
|
+
(0, import_promises3.readFile)(executableFiles["user-server"].fsPath)
|
|
390
390
|
]);
|
|
391
391
|
return new import_build_utils.Lambda({
|
|
392
392
|
...lambdaOptions,
|
|
@@ -414,13 +414,20 @@ var require_dist = __commonJS({
|
|
|
414
414
|
// src/go-runtime/packager.ts
|
|
415
415
|
var packager_exports = {};
|
|
416
416
|
__export(packager_exports, {
|
|
417
|
+
close: () => close,
|
|
417
418
|
prepareGoFunction: () => prepareGoFunction,
|
|
418
419
|
version: () => version
|
|
419
420
|
});
|
|
420
421
|
module.exports = __toCommonJS(packager_exports);
|
|
421
|
-
var import_promises = require("fs/promises");
|
|
422
422
|
var import_ipc_proxy = __toESM(require_dist());
|
|
423
|
-
var
|
|
423
|
+
var import_node_crypto = require("crypto");
|
|
424
|
+
var import_node_fs = require("fs");
|
|
425
|
+
var import_promises2 = require("fs/promises");
|
|
426
|
+
var import_node_os = require("os");
|
|
427
|
+
var import_node_path = require("path");
|
|
428
|
+
|
|
429
|
+
// src/go-runtime/validate-executable.ts
|
|
430
|
+
var import_promises = require("fs/promises");
|
|
424
431
|
var ELF_HEADER_SIZE = 64;
|
|
425
432
|
var PROGRAM_HEADER_SIZE = 56;
|
|
426
433
|
function invalidExecutable(path, reason) {
|
|
@@ -558,17 +565,108 @@ async function validateExecutable(path) {
|
|
|
558
565
|
await file.close();
|
|
559
566
|
}
|
|
560
567
|
}
|
|
561
|
-
|
|
562
|
-
|
|
568
|
+
|
|
569
|
+
// src/go-runtime/packager.ts
|
|
570
|
+
var version = 2;
|
|
571
|
+
var GO_CONTAINER_REPOSITORY = "next-go";
|
|
572
|
+
var DIGEST_PINNED_VCR_REF = /^vcr\.vercel\.com\/[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)*@sha256:[a-f0-9]{64}$/;
|
|
573
|
+
var SHA256_DIGEST_RE = /^sha256:[a-f0-9]{64}$/;
|
|
574
|
+
var state;
|
|
575
|
+
var OCI_LAYOUT_ENV = "VERCEL_CONTAINER_OCI_LAYOUT";
|
|
576
|
+
function registryModeEnv(env) {
|
|
577
|
+
const { [OCI_LAYOUT_ENV]: _ociLayout, ...rest } = env;
|
|
578
|
+
return rest;
|
|
579
|
+
}
|
|
580
|
+
function getState() {
|
|
581
|
+
if (!state) {
|
|
582
|
+
const builder = import("@vercel/container").then(
|
|
583
|
+
(container) => container.ExecutableImageBuilder.create({
|
|
584
|
+
repository: GO_CONTAINER_REPOSITORY,
|
|
585
|
+
env: registryModeEnv(process.env)
|
|
586
|
+
})
|
|
587
|
+
);
|
|
588
|
+
builder.catch(() => {
|
|
589
|
+
});
|
|
590
|
+
state = {
|
|
591
|
+
builder,
|
|
592
|
+
layoutsDir: (0, import_promises2.mkdtemp)((0, import_node_path.join)((0, import_node_os.tmpdir)(), "next-go-images-")),
|
|
593
|
+
images: /* @__PURE__ */ new Map()
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
return state;
|
|
597
|
+
}
|
|
598
|
+
async function sha256File(path) {
|
|
599
|
+
const hash = (0, import_node_crypto.createHash)("sha256");
|
|
600
|
+
for await (const chunk of (0, import_node_fs.createReadStream)(path)) {
|
|
601
|
+
hash.update(chunk);
|
|
602
|
+
}
|
|
603
|
+
return hash.digest("hex");
|
|
604
|
+
}
|
|
605
|
+
async function toPreparedFunction(image, userServerPath, layoutDir) {
|
|
606
|
+
if (image.kind === "registry") {
|
|
607
|
+
if (typeof image.reference !== "string" || !DIGEST_PINNED_VCR_REF.test(image.reference)) {
|
|
608
|
+
throw new Error(
|
|
609
|
+
`Expected a digest-pinned Vercel Container Registry image for Go server "${userServerPath}".`
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
return { handler: image.reference };
|
|
613
|
+
}
|
|
614
|
+
if (image.kind !== "oci-layout" || typeof image.manifestDigest !== "string" || !SHA256_DIGEST_RE.test(image.manifestDigest) || image.directory !== layoutDir || !(await (0, import_promises2.lstat)(layoutDir).catch(() => void 0))?.isDirectory()) {
|
|
615
|
+
throw new Error(
|
|
616
|
+
`Expected a verified OCI image layout for Go server "${userServerPath}".`
|
|
617
|
+
);
|
|
618
|
+
}
|
|
563
619
|
return {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
architecture: "x86_64"
|
|
567
|
-
})
|
|
620
|
+
handler: image.manifestDigest,
|
|
621
|
+
image: { type: "oci-layout", directory: layoutDir }
|
|
568
622
|
};
|
|
569
623
|
}
|
|
624
|
+
async function buildImage(current, userServerPath, executablePath, digest) {
|
|
625
|
+
const builder = await current.builder;
|
|
626
|
+
const layoutDir = (0, import_node_path.join)(await current.layoutsDir, digest);
|
|
627
|
+
const image = await builder.build({ executablePath, layoutDir });
|
|
628
|
+
return toPreparedFunction(image, userServerPath, layoutDir);
|
|
629
|
+
}
|
|
630
|
+
async function prepareGoFunction(options) {
|
|
631
|
+
if (options.type !== "route" && options.type !== "middleware") {
|
|
632
|
+
throw new Error(
|
|
633
|
+
`Unsupported Go function type ${JSON.stringify(options.type)}: expected "route" or "middleware".`
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
await validateExecutable(options.userServerPath);
|
|
637
|
+
if (options.type === "middleware") {
|
|
638
|
+
return {
|
|
639
|
+
files: (0, import_ipc_proxy.getStandaloneExecutableFiles)({
|
|
640
|
+
userServerPath: options.userServerPath,
|
|
641
|
+
architecture: "x86_64"
|
|
642
|
+
})
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
const executablePath = await (0, import_promises2.realpath)(options.userServerPath);
|
|
646
|
+
const digest = await sha256File(executablePath);
|
|
647
|
+
const current = getState();
|
|
648
|
+
let image = current.images.get(digest);
|
|
649
|
+
if (!image) {
|
|
650
|
+
image = buildImage(current, options.userServerPath, executablePath, digest);
|
|
651
|
+
current.images.set(digest, image);
|
|
652
|
+
}
|
|
653
|
+
return image;
|
|
654
|
+
}
|
|
655
|
+
async function close() {
|
|
656
|
+
const current = state;
|
|
657
|
+
state = void 0;
|
|
658
|
+
if (!current)
|
|
659
|
+
return;
|
|
660
|
+
try {
|
|
661
|
+
const builder = await current.builder.catch(() => void 0);
|
|
662
|
+
await builder?.close();
|
|
663
|
+
} finally {
|
|
664
|
+
await (0, import_promises2.rm)(await current.layoutsDir, { recursive: true, force: true });
|
|
665
|
+
}
|
|
666
|
+
}
|
|
570
667
|
// Annotate the CommonJS export names for ESM import in node:
|
|
571
668
|
0 && (module.exports = {
|
|
669
|
+
close,
|
|
572
670
|
prepareGoFunction,
|
|
573
671
|
version
|
|
574
672
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/next",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "32.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
|
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@vercel/nft": "1.10.0"
|
|
16
|
+
"@vercel/nft": "1.10.0",
|
|
17
|
+
"@vercel/container": "28.0.0"
|
|
17
18
|
},
|
|
18
19
|
"peerDependencies": {
|
|
19
|
-
"@vercel/build-utils": "15.
|
|
20
|
+
"@vercel/build-utils": "15.6.0"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"@next-community/adapter-vercel": "0.1.0-beta.
|
|
23
|
+
"@next-community/adapter-vercel": "0.1.0-beta.41",
|
|
23
24
|
"@types/aws-lambda": "8.10.19",
|
|
24
25
|
"@types/buffer-crc32": "0.2.0",
|
|
25
26
|
"@types/bytes": "3.1.1",
|
|
@@ -60,10 +61,10 @@
|
|
|
60
61
|
"vite": "6.4.3",
|
|
61
62
|
"vitest": "4.1.10",
|
|
62
63
|
"webpack-sources": "3.2.3",
|
|
63
|
-
"@vercel/build-utils": "15.
|
|
64
|
+
"@vercel/build-utils": "15.6.0",
|
|
65
|
+
"@vercel/go": "31.0.0",
|
|
64
66
|
"@vercel-internals/ipc-proxy": "1.1.4",
|
|
65
|
-
"@vercel/routing-utils": "6.6.1"
|
|
66
|
-
"@vercel/go": "30.0.0"
|
|
67
|
+
"@vercel/routing-utils": "6.6.1"
|
|
67
68
|
},
|
|
68
69
|
"scripts": {
|
|
69
70
|
"build": "node build.mjs",
|