@@ -5,6 +5,7 @@ import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, write
55import { tmpdir } from "node:os" ;
66import { dirname , join , resolve } from "node:path" ;
77
8+ import { MINIMUM_NODE_MAJOR } from "../packages/cli/src/runtime-version.ts" ;
89import type { ChildProcessWithoutNullStreams } from "node:child_process" ;
910
1011const 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+
297323function buildNodePreferredEnv ( nodeBin : string ) : NodeJS . ProcessEnv {
298324 const nodeDir = dirname ( nodeBin ) ;
299325 const pathSeparator = process . platform === "win32" ? ";" : ":" ;
0 commit comments