Skip to content

Commit 58f3191

Browse files
committed
fix(deps): adapt to execa 10 api
execa dropped its default export and the subprocess no longer emits events directly, so imports are now named, execa.sync is execaSync, lifecycle events come from nodeChildProcess, and exitCode is optional.
1 parent fde7846 commit 58f3191

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/job.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {GitData} from "./git-data.js";
99
import assert, {AssertionError} from "node:assert";
1010
import {Mutex} from "./mutex.js";
1111
import {Argv} from "./argv.js";
12-
import execa from "execa";
12+
import {execa} from "execa";
1313
import {CICDVariable} from "./variables-from-files.js";
1414
import {GitlabRunnerCPUsPresetValue, GitlabRunnerMemoryPresetValue, GitlabRunnerPresetValues} from "./gitlab-preset.js";
1515
import {handler} from "./handler.js";
@@ -932,10 +932,12 @@ If you know what you're doing and would like to suppress this warning, use one o
932932
shell: "bash",
933933
stdio: ["inherit", "inherit", "inherit"],
934934
env: {...expanded, ...process.env},
935+
reject: false,
935936
});
937+
const interactiveChildProcess = await interactiveCp.nodeChildProcess;
936938
return new Promise<number>((resolve, reject) => {
937-
void interactiveCp.on("exit", (code) => resolve(code ?? 0));
938-
void interactiveCp.on("error", (err) => reject(err));
939+
void interactiveChildProcess.on("exit", (code) => resolve(code ?? 0));
940+
void interactiveChildProcess.on("error", (err) => reject(err));
939941
});
940942
}
941943

@@ -1143,7 +1145,9 @@ If you know what you're doing and would like to suppress this warning, use one o
11431145
cwd,
11441146
shell: "bash",
11451147
env: imageName ? process.env : expanded,
1148+
reject: false,
11461149
});
1150+
const childProcess = await cp.nodeChildProcess;
11471151

11481152
// eslint-disable-next-line no-control-regex
11491153
const sectionRegex = /\x1b\[0Ksection_(start|end):(\d+):([^\s[]+)(?:\[[^\]]*\])?\r\x1b\[0K/;
@@ -1187,11 +1191,11 @@ If you know what you're doing and would like to suppress this warning, use one o
11871191
}
11881192
// Wait for "close" rather than "exit" so all stdout/stderr data events
11891193
// have flushed to the output log file before we resolve.
1190-
void cp.on("close", (code) => {
1194+
void childProcess.on("close", (code) => {
11911195
clearTimeout(this._longRunningSilentTimeout);
11921196
return resolve(code ?? 0);},
11931197
);
1194-
void cp.on("error", (err) => {
1198+
void childProcess.on("error", (err) => {
11951199
clearTimeout(this._longRunningSilentTimeout);
11961200
return reject(err);
11971201
});

src/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {needsComplex} from "./data-expander.js";
66
import fs from "fs-extra";
77
import checksum from "checksum";
88
import base64url from "base64url";
9-
import execa, {ExecaError} from "execa";
9+
import {execa, execaSync, ExecaError} from "execa";
1010
import assert from "node:assert";
1111
import {createHash} from "node:crypto";
1212
import {CICDVariable} from "./variables-from-files.js";
@@ -30,11 +30,11 @@ type ExpandWith = {
3030
};
3131

3232
export class Utils {
33-
static bashMulti (scripts: string[], cwd = process.cwd()): Promise<{stdout: string; stderr: string; exitCode: number}> {
33+
static bashMulti (scripts: string[], cwd = process.cwd()): Promise<{stdout: string; stderr: string; exitCode?: number}> {
3434
return execa(scripts.join(" && \\"), {shell: "bash", cwd});
3535
}
3636

37-
static bash (shellScript: string, cwd = process.cwd()): Promise<{stdout: string; stderr: string; exitCode: number}> {
37+
static bash (shellScript: string, cwd = process.cwd()): Promise<{stdout: string; stderr: string; exitCode?: number}> {
3838
return execa(shellScript, {shell: "bash", cwd});
3939
}
4040

@@ -43,7 +43,7 @@ export class Utils {
4343
}
4444

4545
static syncSpawn (cmdArgs: string[], cwd = process.cwd()): {stdout: string; stderr: string} {
46-
return execa.sync(cmdArgs[0], cmdArgs.slice(1), {cwd});
46+
return execaSync(cmdArgs[0], cmdArgs.slice(1), {cwd});
4747
}
4848

4949
static fsUrl (url: string): string {

tests/test-cases/dependency-proxy/integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe("dependency-proxy", () => {
7575
}, writeStreams);
7676
} catch (e: any) {
7777
// In ci environment, gitlab.com:443 is not authenticated, but at least this shows that we're pulling from the correct path
78-
expect(e.shortMessage).toEqual("Command failed with exit code 1: docker pull gitlab.com:443/gcl/dependency_proxy/containers/busybox:latest");
78+
expect(e.command).toEqual("docker pull gitlab.com:443/gcl/dependency_proxy/containers/busybox:latest");
7979
return;
8080
}
8181
throw new Error("Error is expected but not thrown/caught");

0 commit comments

Comments
 (0)