Skip to content

Commit ba8fe14

Browse files
jamietannaClaude Sonnet 4.5
andcommitted
refactor(tools): use asynchronous execa
Co-authored-by: Claude Sonnet 4.5 <jamie.tanna+github-copilot@mend.io>
1 parent 2f960b3 commit ba8fe14

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

tools/mkdocs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command } from 'commander';
2-
import type { ExecaSyncReturnValue } from 'execa';
2+
import type { ExecaReturnValue } from 'execa';
33
import fs from 'fs-extra';
44
import { logger } from '../lib/logger/index.ts';
55
import { generateDocs } from './docs/index.ts';
@@ -26,15 +26,15 @@ program
2626
if (opts.strict) {
2727
args.push('--strict');
2828
}
29-
const res = exec('pdm', args, {
29+
const res = await exec('pdm', args, {
3030
cwd: 'tools/mkdocs',
3131
stdio: 'inherit',
3232
env: {
3333
...process.env,
3434
RENOVATE_VERSION: opts.version ?? '',
3535
},
3636
});
37-
checkResult(res);
37+
await checkResult(res);
3838
});
3939

4040
program
@@ -50,11 +50,11 @@ program
5050
if (opts.strict) {
5151
args.push('--strict');
5252
}
53-
const res = exec('pdm', args, {
53+
const res = await exec('pdm', args, {
5454
cwd: 'tools/mkdocs',
5555
stdio: 'inherit',
5656
});
57-
checkResult(res);
57+
await checkResult(res);
5858
});
5959

6060
async function prepareDocs(opts: any): Promise<void> {
@@ -68,7 +68,7 @@ async function prepareDocs(opts: any): Promise<void> {
6868
}
6969
}
7070

71-
function checkResult(res: ExecaSyncReturnValue<string>): void {
71+
async function checkResult(res: ExecaReturnValue<string>): Promise<void> {
7272
if (res.signal) {
7373
logger.error(`Signal received: ${res.signal}`);
7474
process.exit(-1);

tools/prepare-deps.mjs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { execaSync } from 'execa';
1+
import { execa } from 'execa';
22

3-
function testRe2() {
4-
execaSync(
3+
async function testRe2() {
4+
await execa(
55
'node',
66
[
77
'-e',
@@ -12,8 +12,8 @@ function testRe2() {
1212
console.log(`Ok.`);
1313
}
1414

15-
function testSqlite() {
16-
execaSync(
15+
async function testSqlite() {
16+
await execa(
1717
'node',
1818
[
1919
'-e',
@@ -24,19 +24,19 @@ function testSqlite() {
2424
console.log(`Ok.`);
2525
}
2626

27-
(() => {
27+
(async () => {
2828
console.log('Checking re2 ... ');
2929
try {
30-
testRe2();
30+
await testRe2();
3131
} catch (e) {
3232
console.error(`Failed.\n${e}`);
3333
try {
3434
if (e.exitCode === 1) {
3535
console.log(`Retry re2 install ...`);
36-
execaSync('pnpm', ['rb', 're2'], {
36+
await execa('pnpm', ['rb', 're2'], {
3737
stdio: 'inherit',
3838
});
39-
testRe2();
39+
await testRe2();
4040
return;
4141
}
4242
} catch (e1) {
@@ -47,19 +47,19 @@ function testSqlite() {
4747
}
4848
})();
4949

50-
(() => {
50+
(async () => {
5151
console.log('Checking better-sqlite3 ... ');
5252
try {
53-
testSqlite();
53+
await testSqlite();
5454
} catch (e) {
5555
console.error(`Failed.\n${e}`);
5656
try {
5757
if (e.exitCode === 1) {
5858
console.log(`Retry better-sqlite3 install ...`);
59-
execaSync('pnpm', ['rb', 'better-sqlite3'], {
59+
await execa('pnpm', ['rb', 'better-sqlite3'], {
6060
stdio: 'inherit',
6161
});
62-
testSqlite();
62+
await testSqlite();
6363
return;
6464
}
6565
} catch (e1) {

tools/prepare-release.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ void (async () => {
3131
await program.parseAsync();
3232
const opts = program.opts();
3333
logger.info(`Preparing v${opts.version?.toString()} ...`);
34-
build();
34+
await build();
3535
await generateDocs(undefined, undefined, opts.version?.toString());
3636
await bake('build', opts);
3737
})();
3838

39-
function build(): void {
39+
async function build(): Promise<void> {
4040
logger.info('Building ...');
41-
const res = exec('pnpm', ['build']);
41+
const res = await exec('pnpm', ['build']);
4242

4343
if (res.signal) {
4444
logger.error(`Signal received: ${res.signal}`);

tools/utils/exec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import type { ExecaSyncReturnValue, SyncOptions } from 'execa';
2-
import { execaSync } from 'execa';
1+
import type { ExecaReturnValue, Options } from 'execa';
2+
import { execa } from 'execa';
33

44
const maxBuffer = 20 * 1024 * 1024;
55

66
/**
7-
* Execute a command synchronously using execa
7+
* Execute a command asynchronously using execa
88
* @param {string} cmd
99
* @param {string[]} args
1010
*/
11-
export function exec(
11+
export async function exec(
1212
cmd: string,
1313
args: string[] = [],
14-
opts: SyncOptions = {},
15-
): ExecaSyncReturnValue<string> {
16-
return execaSync(cmd, args, {
14+
opts: Options = {},
15+
): Promise<ExecaReturnValue<string>> {
16+
return await execa(cmd, args, {
1717
...opts,
1818
maxBuffer,
1919
encoding: 'utf8',

0 commit comments

Comments
 (0)