@vercel/go 3.9.0 → 3.9.2
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/bin/proxy-linux-amd64 +0 -0
- package/bin/proxy-linux-arm64 +0 -0
- package/dev-server.go +5 -2
- package/dist/index.js +180 -54
- package/package.json +2 -2
package/bin/proxy-linux-amd64
CHANGED
|
Binary file
|
package/bin/proxy-linux-arm64
CHANGED
|
Binary file
|
package/dev-server.go
CHANGED
|
@@ -12,8 +12,11 @@ func main() {
|
|
|
12
12
|
// create a new handler
|
|
13
13
|
handler := http.HandlerFunc(__HANDLER_FUNC_NAME)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
addr := "127.0.0.1:0"
|
|
16
|
+
if devPort := os.Getenv("VERCEL_DEV_PORT"); devPort != "" {
|
|
17
|
+
addr = "127.0.0.1:" + devPort
|
|
18
|
+
}
|
|
19
|
+
listener, err := net.Listen("tcp", addr)
|
|
17
20
|
if err != nil {
|
|
18
21
|
panic(err)
|
|
19
22
|
}
|
package/dist/index.js
CHANGED
|
@@ -11025,7 +11025,7 @@ __export(src_exports, {
|
|
|
11025
11025
|
diagnostics: () => diagnostics,
|
|
11026
11026
|
getNewHandlerFunctionName: () => getNewHandlerFunctionName,
|
|
11027
11027
|
prepareCache: () => prepareCache,
|
|
11028
|
-
shouldServe: () =>
|
|
11028
|
+
shouldServe: () => shouldServe,
|
|
11029
11029
|
startDevServer: () => startDevServer,
|
|
11030
11030
|
version: () => version
|
|
11031
11031
|
});
|
|
@@ -14804,6 +14804,7 @@ var detectEntrypoint = async ({ workPath }) => {
|
|
|
14804
14804
|
|
|
14805
14805
|
// src/standalone-server.ts
|
|
14806
14806
|
var import_child_process = require("child_process");
|
|
14807
|
+
var import_net = require("net");
|
|
14807
14808
|
var import_path6 = require("path");
|
|
14808
14809
|
var import_fs_extra3 = __toESM(require_lib2());
|
|
14809
14810
|
var import_build_utils4 = require("@vercel/build-utils");
|
|
@@ -15008,69 +15009,194 @@ async function buildStandaloneServer({
|
|
|
15008
15009
|
});
|
|
15009
15010
|
return { output: lambda };
|
|
15010
15011
|
}
|
|
15011
|
-
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
const devUtils = (0, import_path6.join)(__dirname, "../bootstrap/utils.go");
|
|
15020
|
-
(0, import_build_utils4.debug)(
|
|
15021
|
-
`Starting standalone Go dev server wrapper: go run ${devWrapper} (target ${runTarget}, port ${port})`
|
|
15022
|
-
);
|
|
15023
|
-
const child = (0, import_child_process.spawn)("go", ["run", "-tags", "vcdev", devWrapper, devUtils], {
|
|
15024
|
-
cwd: workPath,
|
|
15025
|
-
env: {
|
|
15026
|
-
...env,
|
|
15027
|
-
__VC_GO_DEV_RUN_TARGET: runTarget
|
|
15028
|
-
},
|
|
15029
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
15030
|
-
});
|
|
15031
|
-
child.stdout?.on("data", (data) => {
|
|
15032
|
-
const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
15033
|
-
if (opts.onStdout) {
|
|
15034
|
-
opts.onStdout(chunk);
|
|
15012
|
+
var DEV_SERVER_STARTUP_TIMEOUT = 5 * 6e4;
|
|
15013
|
+
var PERSISTENT_SERVERS = /* @__PURE__ */ new Map();
|
|
15014
|
+
var PENDING_STARTS = /* @__PURE__ */ new Map();
|
|
15015
|
+
var cleanupHandlersInstalled = false;
|
|
15016
|
+
function killStandaloneDevServer(pid) {
|
|
15017
|
+
try {
|
|
15018
|
+
if (process.platform === "win32") {
|
|
15019
|
+
process.kill(pid, "SIGTERM");
|
|
15035
15020
|
} else {
|
|
15036
|
-
process.
|
|
15021
|
+
process.kill(-pid, "SIGTERM");
|
|
15037
15022
|
}
|
|
15038
|
-
})
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15023
|
+
} catch (err) {
|
|
15024
|
+
(0, import_build_utils4.debug)(`Error killing standalone Go dev server ${pid}: ${err}`);
|
|
15025
|
+
}
|
|
15026
|
+
}
|
|
15027
|
+
function installGlobalCleanupHandlers() {
|
|
15028
|
+
if (cleanupHandlersInstalled)
|
|
15029
|
+
return;
|
|
15030
|
+
cleanupHandlersInstalled = true;
|
|
15031
|
+
const killAll = () => {
|
|
15032
|
+
for (const [key, info] of PERSISTENT_SERVERS.entries()) {
|
|
15033
|
+
killStandaloneDevServer(info.pid);
|
|
15034
|
+
PERSISTENT_SERVERS.delete(key);
|
|
15045
15035
|
}
|
|
15036
|
+
};
|
|
15037
|
+
process.on("SIGINT", () => {
|
|
15038
|
+
killAll();
|
|
15046
15039
|
});
|
|
15047
|
-
|
|
15048
|
-
|
|
15049
|
-
cleanup();
|
|
15050
|
-
resolve();
|
|
15051
|
-
}, 2e3);
|
|
15052
|
-
const onExit = (code, signal) => {
|
|
15053
|
-
cleanup();
|
|
15054
|
-
reject(
|
|
15055
|
-
new Error(
|
|
15056
|
-
`Standalone Go dev server exited before startup completed (code: ${code}, signal: ${signal})`
|
|
15057
|
-
)
|
|
15058
|
-
);
|
|
15059
|
-
};
|
|
15060
|
-
const cleanup = () => {
|
|
15061
|
-
clearTimeout(timeout);
|
|
15062
|
-
child.removeListener("exit", onExit);
|
|
15063
|
-
};
|
|
15064
|
-
child.once("exit", onExit);
|
|
15040
|
+
process.on("SIGTERM", () => {
|
|
15041
|
+
killAll();
|
|
15065
15042
|
});
|
|
15066
|
-
|
|
15067
|
-
|
|
15068
|
-
|
|
15043
|
+
process.on("exit", () => {
|
|
15044
|
+
killAll();
|
|
15045
|
+
});
|
|
15046
|
+
}
|
|
15047
|
+
function isPortReachable(port) {
|
|
15048
|
+
return new Promise((resolve) => {
|
|
15049
|
+
const socket = (0, import_net.createConnection)({ port, host: "127.0.0.1" });
|
|
15050
|
+
const done = (result) => {
|
|
15051
|
+
socket.removeAllListeners();
|
|
15052
|
+
socket.destroy();
|
|
15053
|
+
resolve(result);
|
|
15054
|
+
};
|
|
15055
|
+
socket.setTimeout(1e3);
|
|
15056
|
+
socket.once("connect", () => done(true));
|
|
15057
|
+
socket.once("timeout", () => done(false));
|
|
15058
|
+
socket.once("error", () => done(false));
|
|
15059
|
+
});
|
|
15060
|
+
}
|
|
15061
|
+
function sleep(ms2) {
|
|
15062
|
+
return new Promise((resolve) => setTimeout(resolve, ms2));
|
|
15063
|
+
}
|
|
15064
|
+
async function waitForPort(port, child, timeout) {
|
|
15065
|
+
let exited = null;
|
|
15066
|
+
let spawnError = null;
|
|
15067
|
+
const onExit = (code, signal) => {
|
|
15068
|
+
exited = { code, signal };
|
|
15069
15069
|
};
|
|
15070
|
+
const onError = (err) => {
|
|
15071
|
+
spawnError = err;
|
|
15072
|
+
};
|
|
15073
|
+
child.once("exit", onExit);
|
|
15074
|
+
child.once("error", onError);
|
|
15075
|
+
try {
|
|
15076
|
+
const start = Date.now();
|
|
15077
|
+
while (Date.now() - start < timeout) {
|
|
15078
|
+
if (spawnError) {
|
|
15079
|
+
throw spawnError;
|
|
15080
|
+
}
|
|
15081
|
+
if (exited) {
|
|
15082
|
+
const { code, signal } = exited;
|
|
15083
|
+
throw new Error(
|
|
15084
|
+
`Standalone Go dev server exited before startup completed (code: ${code}, signal: ${signal})`
|
|
15085
|
+
);
|
|
15086
|
+
}
|
|
15087
|
+
if (await isPortReachable(port)) {
|
|
15088
|
+
return;
|
|
15089
|
+
}
|
|
15090
|
+
await sleep(100);
|
|
15091
|
+
}
|
|
15092
|
+
throw new Error(
|
|
15093
|
+
`Standalone Go dev server did not start within ${timeout}ms`
|
|
15094
|
+
);
|
|
15095
|
+
} finally {
|
|
15096
|
+
child.removeListener("exit", onExit);
|
|
15097
|
+
child.removeListener("error", onError);
|
|
15098
|
+
}
|
|
15099
|
+
}
|
|
15100
|
+
async function startStandaloneDevServer(opts, resolvedEntrypoint) {
|
|
15101
|
+
const { workPath, meta = {} } = opts;
|
|
15102
|
+
const serverKey = `${workPath}::${resolvedEntrypoint}`;
|
|
15103
|
+
const existing = PERSISTENT_SERVERS.get(serverKey);
|
|
15104
|
+
if (existing) {
|
|
15105
|
+
return {
|
|
15106
|
+
port: existing.port,
|
|
15107
|
+
pid: existing.pid,
|
|
15108
|
+
shutdown: async () => {
|
|
15109
|
+
}
|
|
15110
|
+
};
|
|
15111
|
+
}
|
|
15112
|
+
const pending = PENDING_STARTS.get(serverKey);
|
|
15113
|
+
if (pending) {
|
|
15114
|
+
const { port, pid } = await pending;
|
|
15115
|
+
return { port, pid, shutdown: async () => {
|
|
15116
|
+
} };
|
|
15117
|
+
}
|
|
15118
|
+
const startPromise = (async () => {
|
|
15119
|
+
const port = typeof meta.port === "number" ? meta.port : Math.floor(Math.random() * (65535 - 49152) + 49152);
|
|
15120
|
+
const env = (0, import_build_utils4.cloneEnv)(process.env, meta.env, {
|
|
15121
|
+
PORT: String(port)
|
|
15122
|
+
});
|
|
15123
|
+
const entrypointDir = (0, import_path6.dirname)((0, import_path6.join)(workPath, resolvedEntrypoint));
|
|
15124
|
+
const { goModPath } = await findGoModPath(entrypointDir, workPath);
|
|
15125
|
+
const modulePath = goModPath ? (0, import_path6.dirname)(goModPath) : workPath;
|
|
15126
|
+
const go = await createGo({
|
|
15127
|
+
modulePath,
|
|
15128
|
+
opts: { cwd: workPath, env },
|
|
15129
|
+
workPath
|
|
15130
|
+
});
|
|
15131
|
+
const runTarget = resolvedEntrypoint === "main.go" ? "." : "./" + (0, import_path6.dirname)(resolvedEntrypoint);
|
|
15132
|
+
const devWrapper = (0, import_path6.join)(__dirname, "../bootstrap/vc-init-dev.go");
|
|
15133
|
+
const devUtils = (0, import_path6.join)(__dirname, "../bootstrap/utils.go");
|
|
15134
|
+
(0, import_build_utils4.debug)(
|
|
15135
|
+
`Starting standalone Go dev server wrapper: go run ${devWrapper} (target ${runTarget}, port ${port})`
|
|
15136
|
+
);
|
|
15137
|
+
const child = (0, import_child_process.spawn)("go", ["run", "-tags", "vcdev", devWrapper, devUtils], {
|
|
15138
|
+
cwd: workPath,
|
|
15139
|
+
env: {
|
|
15140
|
+
...go.getEnv(),
|
|
15141
|
+
__VC_GO_DEV_RUN_TARGET: runTarget
|
|
15142
|
+
},
|
|
15143
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
15144
|
+
detached: process.platform !== "win32"
|
|
15145
|
+
});
|
|
15146
|
+
child.stdout?.on("data", (data) => {
|
|
15147
|
+
const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
15148
|
+
if (opts.onStdout) {
|
|
15149
|
+
opts.onStdout(chunk);
|
|
15150
|
+
} else {
|
|
15151
|
+
process.stdout.write(chunk.toString());
|
|
15152
|
+
}
|
|
15153
|
+
});
|
|
15154
|
+
child.stderr?.on("data", (data) => {
|
|
15155
|
+
const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
15156
|
+
if (opts.onStderr) {
|
|
15157
|
+
opts.onStderr(chunk);
|
|
15158
|
+
} else {
|
|
15159
|
+
process.stderr.write(chunk.toString());
|
|
15160
|
+
}
|
|
15161
|
+
});
|
|
15162
|
+
const pid = child.pid;
|
|
15163
|
+
try {
|
|
15164
|
+
await waitForPort(port, child, DEV_SERVER_STARTUP_TIMEOUT);
|
|
15165
|
+
} catch (err) {
|
|
15166
|
+
if (pid) {
|
|
15167
|
+
killStandaloneDevServer(pid);
|
|
15168
|
+
}
|
|
15169
|
+
throw err;
|
|
15170
|
+
}
|
|
15171
|
+
if (!pid) {
|
|
15172
|
+
throw new Error("Standalone Go dev server started without a PID");
|
|
15173
|
+
}
|
|
15174
|
+
PERSISTENT_SERVERS.set(serverKey, { port, pid, child });
|
|
15175
|
+
child.once("exit", () => {
|
|
15176
|
+
PERSISTENT_SERVERS.delete(serverKey);
|
|
15177
|
+
});
|
|
15178
|
+
installGlobalCleanupHandlers();
|
|
15179
|
+
return { port, pid };
|
|
15180
|
+
})();
|
|
15181
|
+
PENDING_STARTS.set(serverKey, startPromise);
|
|
15182
|
+
try {
|
|
15183
|
+
const { port, pid } = await startPromise;
|
|
15184
|
+
return { port, pid, shutdown: async () => {
|
|
15185
|
+
} };
|
|
15186
|
+
} finally {
|
|
15187
|
+
PENDING_STARTS.delete(serverKey);
|
|
15188
|
+
}
|
|
15070
15189
|
}
|
|
15071
15190
|
|
|
15072
15191
|
// src/index.ts
|
|
15073
15192
|
var TMP = (0, import_os2.tmpdir)();
|
|
15193
|
+
var shouldServe = (opts) => {
|
|
15194
|
+
const framework = opts.config.framework;
|
|
15195
|
+
if (framework === "go" || framework === "services") {
|
|
15196
|
+
return true;
|
|
15197
|
+
}
|
|
15198
|
+
return (0, import_build_utils5.shouldServe)(opts);
|
|
15199
|
+
};
|
|
15074
15200
|
var MAIN_GO_FILENAME = "main__vc__go__.go";
|
|
15075
15201
|
var HANDLER_FILENAME = `bootstrap${OUT_EXTENSION}`;
|
|
15076
15202
|
async function initPrivateGit(credentials) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/go",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"xdg-app-paths": "5.1.0",
|
|
34
34
|
"yauzl-promise": "2.1.3",
|
|
35
35
|
"@vercel-internals/ipc-proxy": "1.0.0",
|
|
36
|
-
"@vercel/build-utils": "13.
|
|
36
|
+
"@vercel/build-utils": "13.31.1"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "node build.mjs",
|