From 0a1100aaf752ae2531bea2bf9a837f8841c3a63b Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Tue, 10 Mar 2026 10:08:53 -0700 Subject: [PATCH] Fix port assignment to respect user-defined PORT vars --- src/cli/index.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index d25b178..f73bf30 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -94,16 +94,15 @@ $ true console.error("--port-from must be an integer") process.exit(1) } - let nextPort = portFrom ?? 0 + let nextPort = portFrom - const runOne = async (filePath: string) => { + const runOne = async (filePath: string, port: number | undefined) => { const content = await readFile(filePath, "utf-8") const parsed = parse(relative(cwd, filePath), content) // Resolve directives in a single pass. Setup @env is collected separately // so that the user file's @env always takes precedence. const envVars: Record = {} - if (portFrom !== undefined) envVars["PORT"] = String(nextPort++) const setupEnvVars: Record = {} const userEnvVars: Record = {} const setupCommands: Command[] = [] @@ -124,6 +123,9 @@ $ true } } Object.assign(envVars, setupEnvVars, userEnvVars) + if (port !== undefined && !("PORT" in userEnvVars) && !("PORT" in setupEnvVars)) { + envVars["PORT"] = String(port) + } const merged: ShoutFile = { ...parsed, commands: [...setupCommands, ...parsed.commands] } const fileResult = await runFile(merged, { @@ -188,8 +190,7 @@ $ true } if (opts.parallel) { - const tasks = files.map(f => runOne(f)) - const all = await Promise.all(tasks) + const all = await Promise.all(files.map(f => runOne(f, nextPort !== undefined ? nextPort++ : undefined))) for (const r of all) { printDots(r) results.push(r) @@ -197,7 +198,7 @@ $ true process.stdout.write("\n") } else { for (const filePath of files) { - const r = await runOne(filePath) + const r = await runOne(filePath, nextPort !== undefined ? nextPort++ : undefined) printDots(r) results.push(r) }