Skip to content

Commit c45e8eb

Browse files
egavrindevagent
andcommitted
fix: keep undici compatible with node 20
- Pin the runtime and publish bundle dependency to undici 6.x - Add publish smoke coverage for the installed undici engine floor Co-Authored-By: devagent <devagent@egavrin>
1 parent c60007b commit c45e8eb

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"node-html-markdown": "^2.0.0",
2626
"smol-toml": "^1.3.0",
2727
"typescript": "^5.9.3",
28-
"undici": "^8.1.0",
28+
"undici": "^6.22.0",
2929
"vscode-jsonrpc": "^8.2.1",
3030
"vscode-languageserver-protocol": "^3.17.5"
3131
},

scripts/bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const distPkg = {
104104
"typescript": "^5.7.0",
105105
"pyright": "^1.1.0",
106106
"bash-language-server": "^5.4.0",
107-
"undici": "^8.1.0",
107+
"undici": "^6.22.0",
108108
},
109109
};
110110

scripts/smoke-publish-bundle.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, write
55
import { tmpdir } from "node:os";
66
import { dirname, join, resolve } from "node:path";
77

8+
import { MINIMUM_NODE_MAJOR } from "../packages/cli/src/runtime-version.ts";
89
import type { ChildProcessWithoutNullStreams } from "node:child_process";
910

1011
const ROOT = resolve(import.meta.dirname, "..");
@@ -27,6 +28,7 @@ async function main(): Promise<void> {
2728
const npmBin = resolveNpmBinary();
2829
const stagedDist = stagePublishRuntime();
2930
installPublishDependencies(stagedDist, npmBin, nodeBin);
31+
verifyInstalledUndici(stagedDist, nodeBin);
3032
const expectedVersion = JSON.parse(readFileSync(join(stagedDist, "package.json"), "utf-8")).version as string;
3133

3234
const isolatedHome = mkdtempSync(join(tmpdir(), "devagent-bundle-smoke-"));
@@ -294,6 +296,30 @@ function installPublishDependencies(stagedDist: string, npmBin: string, nodeBin:
294296
}
295297
}
296298

299+
function verifyInstalledUndici(stagedDist: string, nodeBin: string): void {
300+
const script = `const undici = require("undici");
301+
const pkg = require("undici/package.json");
302+
const engine = pkg.engines?.node;
303+
const match = typeof engine === "string" ? />=\\s*(\\d+)/.exec(engine) : null;
304+
if (typeof undici.EnvHttpProxyAgent !== "function") throw new Error("Expected undici to expose EnvHttpProxyAgent.");
305+
if (!match) throw new Error("Unable to parse undici engines.node: " + String(engine));
306+
if (Number.parseInt(match[1], 10) > ${MINIMUM_NODE_MAJOR}) throw new Error("Installed undici requires Node " + engine + ", but DevAgent publishes node >=${MINIMUM_NODE_MAJOR}.");`;
307+
const result = spawnSync(
308+
nodeBin,
309+
["-e", script],
310+
{
311+
cwd: stagedDist,
312+
env: buildNodePreferredEnv(nodeBin),
313+
encoding: "utf-8",
314+
stdio: "pipe",
315+
},
316+
);
317+
318+
if (result.status !== 0) {
319+
throw new Error(`Installed undici publish dependency is incompatible: ${`${result.stdout}${result.stderr}`.trim()}`);
320+
}
321+
}
322+
297323
function buildNodePreferredEnv(nodeBin: string): NodeJS.ProcessEnv {
298324
const nodeDir = dirname(nodeBin);
299325
const pathSeparator = process.platform === "win32" ? ";" : ":";

0 commit comments

Comments
 (0)