@vercel/go 3.10.5 → 4.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.
Binary file
Binary file
package/dist/index.js CHANGED
@@ -10938,6 +10938,288 @@ var require_xdg_app_paths = __commonJS({
10938
10938
  }
10939
10939
  });
10940
10940
 
10941
+ // ../../internals/ipc-proxy/dist/dev-proxy.js
10942
+ var require_dev_proxy = __commonJS({
10943
+ "../../internals/ipc-proxy/dist/dev-proxy.js"(exports, module2) {
10944
+ "use strict";
10945
+ var __defProp2 = Object.defineProperty;
10946
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
10947
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
10948
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
10949
+ var __export2 = (target, all) => {
10950
+ for (var name in all)
10951
+ __defProp2(target, name, { get: all[name], enumerable: true });
10952
+ };
10953
+ var __copyProps2 = (to2, from, except, desc) => {
10954
+ if (from && typeof from === "object" || typeof from === "function") {
10955
+ for (let key of __getOwnPropNames2(from))
10956
+ if (!__hasOwnProp2.call(to2, key) && key !== except)
10957
+ __defProp2(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
10958
+ }
10959
+ return to2;
10960
+ };
10961
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
10962
+ var dev_proxy_exports = {};
10963
+ __export2(dev_proxy_exports, {
10964
+ createDevProxyServer: () => createDevProxyServer,
10965
+ findFreePort: () => findFreePort,
10966
+ normalizeServiceRoutePrefix: () => normalizeServiceRoutePrefix,
10967
+ resolveServiceRoutePrefix: () => resolveServiceRoutePrefix,
10968
+ rewriteRequestUrl: () => rewriteRequestUrl,
10969
+ sanitizeHeaders: () => sanitizeHeaders,
10970
+ startDevProxy: () => startDevProxy,
10971
+ stripServiceRoutePrefix: () => stripServiceRoutePrefix,
10972
+ waitForPort: () => waitForPort2
10973
+ });
10974
+ module2.exports = __toCommonJS2(dev_proxy_exports);
10975
+ var import_node_http = require("http");
10976
+ var import_node_net = require("net");
10977
+ var PING_PATH = "/_vercel/ping";
10978
+ var INTERNAL_HEADER_PREFIX = "x-vercel-internal-";
10979
+ var LOCALHOST = "127.0.0.1";
10980
+ var DEFAULT_READINESS_TIMEOUT = 5 * 6e4;
10981
+ var READINESS_POLL_INTERVAL = 100;
10982
+ var READINESS_DIAL_TIMEOUT = 1e3;
10983
+ function normalizeServiceRoutePrefix(rawPrefix) {
10984
+ if (!rawPrefix)
10985
+ return "";
10986
+ let prefix = rawPrefix.trim();
10987
+ if (!prefix)
10988
+ return "";
10989
+ if (!prefix.startsWith("/")) {
10990
+ prefix = `/${prefix}`;
10991
+ }
10992
+ if (prefix !== "/") {
10993
+ prefix = prefix.replace(/\/+$/, "");
10994
+ if (!prefix)
10995
+ prefix = "/";
10996
+ }
10997
+ return prefix === "/" ? "" : prefix;
10998
+ }
10999
+ function resolveServiceRoutePrefix(env = process.env) {
11000
+ const strip = (env.VERCEL_SERVICE_ROUTE_PREFIX_STRIP ?? "").trim().toLowerCase();
11001
+ if (strip !== "1" && strip !== "true")
11002
+ return "";
11003
+ return normalizeServiceRoutePrefix(env.VERCEL_SERVICE_ROUTE_PREFIX);
11004
+ }
11005
+ function stripServiceRoutePrefix(pathValue, prefix) {
11006
+ if (pathValue === "*")
11007
+ return pathValue;
11008
+ let normalized = pathValue;
11009
+ if (!normalized) {
11010
+ normalized = "/";
11011
+ } else if (!normalized.startsWith("/")) {
11012
+ normalized = `/${normalized}`;
11013
+ }
11014
+ if (!prefix)
11015
+ return normalized;
11016
+ if (normalized === prefix)
11017
+ return "/";
11018
+ if (normalized.startsWith(`${prefix}/`)) {
11019
+ return normalized.slice(prefix.length) || "/";
11020
+ }
11021
+ return normalized;
11022
+ }
11023
+ function splitUrl(url) {
11024
+ const queryIndex = url.indexOf("?");
11025
+ if (queryIndex === -1)
11026
+ return { pathname: url, search: "" };
11027
+ return { pathname: url.slice(0, queryIndex), search: url.slice(queryIndex) };
11028
+ }
11029
+ function rewriteRequestUrl(url, prefix) {
11030
+ const { pathname, search } = splitUrl(url || "/");
11031
+ return `${stripServiceRoutePrefix(pathname, prefix)}${search}`;
11032
+ }
11033
+ function sanitizeHeaders(headers) {
11034
+ const sanitized = {};
11035
+ for (const [key, value] of Object.entries(headers)) {
11036
+ if (key.toLowerCase().startsWith(INTERNAL_HEADER_PREFIX))
11037
+ continue;
11038
+ sanitized[key] = value;
11039
+ }
11040
+ const forwardedHost = headers["x-forwarded-host"];
11041
+ const host = Array.isArray(forwardedHost) ? forwardedHost[0] : forwardedHost;
11042
+ if (host) {
11043
+ sanitized.host = host;
11044
+ }
11045
+ return sanitized;
11046
+ }
11047
+ function findFreePort() {
11048
+ return new Promise((resolve, reject) => {
11049
+ const server = (0, import_node_net.createServer)();
11050
+ server.unref();
11051
+ server.once("error", reject);
11052
+ server.listen(0, LOCALHOST, () => {
11053
+ const address = server.address();
11054
+ if (!address || typeof address === "string") {
11055
+ server.close(() => reject(new Error("Failed to allocate a free port")));
11056
+ return;
11057
+ }
11058
+ const { port } = address;
11059
+ server.close(() => resolve(port));
11060
+ });
11061
+ });
11062
+ }
11063
+ function isPortReachable2(port) {
11064
+ return new Promise((resolve) => {
11065
+ const socket = (0, import_node_net.createConnection)({ port, host: LOCALHOST });
11066
+ const done = (reachable) => {
11067
+ socket.removeAllListeners();
11068
+ socket.destroy();
11069
+ resolve(reachable);
11070
+ };
11071
+ socket.setTimeout(READINESS_DIAL_TIMEOUT);
11072
+ socket.once("connect", () => done(true));
11073
+ socket.once("timeout", () => done(false));
11074
+ socket.once("error", () => done(false));
11075
+ });
11076
+ }
11077
+ function sleep2(ms2) {
11078
+ return new Promise((resolve) => setTimeout(resolve, ms2));
11079
+ }
11080
+ async function waitForPort2(port, child, timeout, label = "Dev server") {
11081
+ let exited;
11082
+ let spawnError;
11083
+ const onExit = (code, signal) => {
11084
+ exited = { code, signal };
11085
+ };
11086
+ const onError = (err) => {
11087
+ spawnError = err;
11088
+ };
11089
+ child.once("exit", onExit);
11090
+ child.once("error", onError);
11091
+ try {
11092
+ const start = Date.now();
11093
+ while (Date.now() - start < timeout) {
11094
+ if (spawnError)
11095
+ throw spawnError;
11096
+ if (exited) {
11097
+ throw new Error(
11098
+ `${label} exited before it started listening (code: ${exited.code}, signal: ${exited.signal})`
11099
+ );
11100
+ }
11101
+ if (await isPortReachable2(port))
11102
+ return;
11103
+ await sleep2(READINESS_POLL_INTERVAL);
11104
+ }
11105
+ throw new Error(`${label} did not start listening within ${timeout}ms`);
11106
+ } finally {
11107
+ child.removeListener("exit", onExit);
11108
+ child.removeListener("error", onError);
11109
+ }
11110
+ }
11111
+ function createDevProxyServer(options) {
11112
+ const { targetPort } = options;
11113
+ const routePrefix = normalizeServiceRoutePrefix(options.routePrefix);
11114
+ const server = (0, import_node_http.createServer)((req, res) => {
11115
+ const { pathname } = splitUrl(req.url || "/");
11116
+ if (pathname === PING_PATH) {
11117
+ res.writeHead(200, { "content-type": "text/plain" });
11118
+ res.end("OK");
11119
+ return;
11120
+ }
11121
+ const proxyReq = (0, import_node_http.request)(
11122
+ {
11123
+ host: LOCALHOST,
11124
+ port: targetPort,
11125
+ method: req.method,
11126
+ path: rewriteRequestUrl(req.url || "/", routePrefix),
11127
+ headers: sanitizeHeaders(req.headers)
11128
+ },
11129
+ (proxyRes) => {
11130
+ res.writeHead(proxyRes.statusCode ?? 502, proxyRes.headers);
11131
+ proxyRes.pipe(res);
11132
+ }
11133
+ );
11134
+ proxyReq.once("error", (err) => {
11135
+ if (!res.headersSent) {
11136
+ res.writeHead(502, { "content-type": "text/plain" });
11137
+ }
11138
+ res.end(`Dev proxy error: ${err.message}`);
11139
+ });
11140
+ res.once("close", () => {
11141
+ if (!res.writableFinished)
11142
+ proxyReq.destroy();
11143
+ });
11144
+ req.pipe(proxyReq);
11145
+ });
11146
+ server.on("upgrade", (req, clientSocket, head) => {
11147
+ const headers = sanitizeHeaders(req.headers);
11148
+ const path = rewriteRequestUrl(req.url || "/", routePrefix);
11149
+ const upstream = (0, import_node_net.createConnection)(
11150
+ { host: LOCALHOST, port: targetPort },
11151
+ () => {
11152
+ const lines = [`${req.method} ${path} HTTP/${req.httpVersion}`];
11153
+ for (const [key, value] of Object.entries(headers)) {
11154
+ if (Array.isArray(value)) {
11155
+ for (const entry of value)
11156
+ lines.push(`${key}: ${entry}`);
11157
+ } else if (value !== void 0) {
11158
+ lines.push(`${key}: ${value}`);
11159
+ }
11160
+ }
11161
+ upstream.write(`${lines.join("\r\n")}\r
11162
+ \r
11163
+ `);
11164
+ if (head?.length)
11165
+ upstream.write(new Uint8Array(head));
11166
+ upstream.pipe(clientSocket);
11167
+ clientSocket.pipe(upstream);
11168
+ }
11169
+ );
11170
+ const destroy = () => {
11171
+ upstream.destroy();
11172
+ clientSocket.destroy();
11173
+ };
11174
+ upstream.once("error", destroy);
11175
+ clientSocket.once("error", destroy);
11176
+ });
11177
+ return server;
11178
+ }
11179
+ async function startDevProxy(options) {
11180
+ const {
11181
+ spawnServer,
11182
+ env = process.env,
11183
+ readinessTimeout = DEFAULT_READINESS_TIMEOUT,
11184
+ label = "Dev server"
11185
+ } = options;
11186
+ const internalPort = await findFreePort();
11187
+ const child = spawnServer(internalPort);
11188
+ let server;
11189
+ const close = async () => {
11190
+ if (server) {
11191
+ await new Promise((resolve) => {
11192
+ server?.close(() => resolve());
11193
+ server?.closeAllConnections?.();
11194
+ });
11195
+ }
11196
+ if (child.exitCode === null && child.signalCode === null) {
11197
+ child.kill("SIGTERM");
11198
+ }
11199
+ };
11200
+ try {
11201
+ await waitForPort2(internalPort, child, readinessTimeout, label);
11202
+ server = createDevProxyServer({
11203
+ targetPort: internalPort,
11204
+ routePrefix: resolveServiceRoutePrefix(env)
11205
+ });
11206
+ const listenPort = options.port ?? await findFreePort();
11207
+ await new Promise((resolve, reject) => {
11208
+ server?.once("error", reject);
11209
+ server?.listen(listenPort, () => resolve());
11210
+ });
11211
+ if (!child.pid) {
11212
+ throw new Error(`${label} started without a PID`);
11213
+ }
11214
+ return { port: listenPort, pid: child.pid, child, close };
11215
+ } catch (err) {
11216
+ await close();
11217
+ throw err;
11218
+ }
11219
+ }
11220
+ }
11221
+ });
11222
+
10941
11223
  // ../../internals/ipc-proxy/dist/index.js
10942
11224
  var require_dist2 = __commonJS({
10943
11225
  "../../internals/ipc-proxy/dist/index.js"(exports, module2) {
@@ -10958,6 +11240,7 @@ var require_dist2 = __commonJS({
10958
11240
  }
10959
11241
  return to2;
10960
11242
  };
11243
+ var __reExport = (target, mod, secondTarget) => (__copyProps2(target, mod, "default"), secondTarget && __copyProps2(secondTarget, mod, "default"));
10961
11244
  var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
10962
11245
  var src_exports2 = {};
10963
11246
  __export2(src_exports2, {
@@ -10970,6 +11253,7 @@ var require_dist2 = __commonJS({
10970
11253
  var import_node_fs7 = require("fs");
10971
11254
  var import_promises2 = require("fs/promises");
10972
11255
  var import_build_utils6 = require("@vercel/build-utils");
11256
+ __reExport(src_exports2, require_dev_proxy(), module2.exports);
10973
11257
  function proxyBinaryName(architecture) {
10974
11258
  return architecture === "arm64" ? "proxy-linux-arm64" : "proxy-linux-amd64";
10975
11259
  }
@@ -14894,15 +15178,29 @@ async function generateProjectManifest({
14894
15178
  var diagnostics = (0, import_build_utils3.createDiagnostics)("go");
14895
15179
 
14896
15180
  // src/standalone-server.ts
15181
+ var STANDALONE_LAMBDA_PATH = "go";
15182
+ function ownsRouteTable(service) {
15183
+ return !(service?.name && service.type);
15184
+ }
14897
15185
  function getStandaloneServerRoutes(service) {
14898
- if (!service?.name || service.type) {
15186
+ if (!ownsRouteTable(service)) {
14899
15187
  return void 0;
14900
15188
  }
14901
15189
  return [
14902
15190
  { handle: "filesystem" },
15191
+ // This route matches the resolved destination after rewrites. Copy that
15192
+ // path into the runtime request before dispatching the Go server so its
15193
+ // application routing observes the rewrite.
14903
15194
  {
14904
15195
  src: "/(.*)",
14905
- dest: "/index"
15196
+ dest: `/${STANDALONE_LAMBDA_PATH}`,
15197
+ transforms: [
15198
+ {
15199
+ type: "request.path",
15200
+ op: "set",
15201
+ args: "/$1"
15202
+ }
15203
+ ]
14906
15204
  }
14907
15205
  ];
14908
15206
  }
@@ -14925,7 +15223,21 @@ async function findGoModPath(entrypointDir, workPath) {
14925
15223
  isGoModInRootDir
14926
15224
  };
14927
15225
  }
14928
- async function buildStandaloneServer({
15226
+ async function buildStandaloneServer(options) {
15227
+ const lambda = await createStandaloneServerLambda(options);
15228
+ const { service } = options;
15229
+ if (!ownsRouteTable(service)) {
15230
+ return { resultVersion: 3, result: { output: lambda } };
15231
+ }
15232
+ return {
15233
+ resultVersion: 2,
15234
+ result: {
15235
+ output: { [STANDALONE_LAMBDA_PATH]: lambda },
15236
+ routes: getStandaloneServerRoutes(service)
15237
+ }
15238
+ };
15239
+ }
15240
+ async function createStandaloneServerLambda({
14929
15241
  files,
14930
15242
  entrypoint,
14931
15243
  config,
@@ -15019,8 +15331,7 @@ async function buildStandaloneServer({
15019
15331
  framework: config.framework ?? void 0,
15020
15332
  serviceType: service ? (0, import_build_utils4.getReportedServiceType)(service) : void 0
15021
15333
  });
15022
- const routes = getStandaloneServerRoutes(service);
15023
- return { output: lambda, ...routes ? { routes } : {} };
15334
+ return lambda;
15024
15335
  }
15025
15336
  var DEV_SERVER_STARTUP_TIMEOUT = 5 * 6e4;
15026
15337
  var PERSISTENT_SERVERS = /* @__PURE__ */ new Map();
@@ -15231,7 +15542,7 @@ function getRenamedEntrypoint(entrypoint) {
15231
15542
  }
15232
15543
  return void 0;
15233
15544
  }
15234
- var version = 3;
15545
+ var version = -1;
15235
15546
  async function build(options) {
15236
15547
  const {
15237
15548
  files,
@@ -15396,7 +15707,8 @@ Manually assigning 'GO111MODULE' is not recommended.
15396
15707
  });
15397
15708
  }
15398
15709
  return {
15399
- output: lambda
15710
+ resultVersion: 3,
15711
+ result: { output: lambda }
15400
15712
  };
15401
15713
  } catch (error) {
15402
15714
  (0, import_build_utils5.debug)(`Go Builder Error: ${error}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/go",
3
- "version": "3.10.5",
3
+ "version": "4.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
@@ -15,6 +15,10 @@
15
15
  "bin",
16
16
  "bootstrap"
17
17
  ],
18
+ "dependencies": {},
19
+ "peerDependencies": {
20
+ "@vercel/build-utils": "14.3.0"
21
+ },
18
22
  "devDependencies": {
19
23
  "@tootallnate/once": "1.1.2",
20
24
  "@types/async-retry": "1.4.5",
@@ -32,13 +36,14 @@
32
36
  "vitest": "4.1.10",
33
37
  "xdg-app-paths": "5.1.0",
34
38
  "yauzl-promise": "2.1.3",
35
- "@vercel/build-utils": "14.0.5",
39
+ "@vercel/build-utils": "14.3.0",
36
40
  "@vercel-internals/ipc-proxy": "1.0.0"
37
41
  },
38
42
  "scripts": {
39
43
  "build": "node build.mjs",
40
44
  "test": "vitest run --config ../../vitest.config.mts",
41
45
  "test-e2e": "vitest run --config ../../vitest.config.mts test/integration-",
46
+ "test-e2e-builder": "pnpm run test-e2e",
42
47
  "type-check": "tsc --noEmit"
43
48
  }
44
49
  }