Skip to content

Commit 7819f72

Browse files
resources: merge execOutput and exec into single function (#3698)
1 parent 743f42b commit 7819f72

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

resources/benchmark.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as os from 'node:os';
55
import * as path from 'node:path';
66
import * as url from 'node:url';
77

8-
import { exec, execOutput, localRepoPath } from './utils';
8+
import { exec, localRepoPath } from './utils';
99

1010
const NS_PER_SEC = 1e9;
1111
const LOCAL = 'local';
@@ -77,7 +77,7 @@ function prepareBenchmarkProjects(
7777
}
7878

7979
// Returns the complete git hash for a given git revision reference.
80-
const hash = execOutput(`git rev-parse "${revision}"`);
80+
const hash = exec(`git rev-parse "${revision}"`);
8181

8282
const archivePath = path.join(tmpDir, `graphql-${hash}.tgz`);
8383
if (fs.existsSync(archivePath)) {
@@ -99,7 +99,7 @@ function prepareBenchmarkProjects(
9999
exec('npm --quiet run build:npm', { cwd: repoDir });
100100

101101
const distDir = path.join(repoDir, 'npmDist');
102-
const archiveName = execOutput(`npm --quiet pack ${distDir}`, {
102+
const archiveName = exec(`npm --quiet pack ${distDir}`, {
103103
cwd: repoDir,
104104
});
105105
return path.join(repoDir, archiveName);

resources/diff-npm-package.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from 'node:fs';
33
import * as os from 'node:os';
44
import * as path from 'node:path';
55

6-
import { exec, execOutput, localRepoPath, writeGeneratedFile } from './utils';
6+
import { exec, localRepoPath, writeGeneratedFile } from './utils';
77

88
const LOCAL = 'local';
99
const tmpDir = path.join(os.tmpdir(), 'graphql-js-npm-diff');
@@ -27,7 +27,7 @@ console.log(`📦 Building NPM package for ${toRevision}...`);
2727
const toPackage = prepareNPMPackage(toRevision);
2828

2929
console.log('➖➕ Generating diff...');
30-
const diff = execOutput(`npm diff --diff=${fromPackage} --diff=${toPackage}`);
30+
const diff = exec(`npm diff --diff=${fromPackage} --diff=${toPackage}`);
3131

3232
if (diff === '') {
3333
console.log('No changes found!');
@@ -83,7 +83,7 @@ function prepareNPMPackage(revision: string): string {
8383
}
8484

8585
// Returns the complete git hash for a given git revision reference.
86-
const hash = execOutput(`git rev-parse "${revision}"`);
86+
const hash = exec(`git rev-parse "${revision}"`);
8787
assert(hash != null);
8888

8989
const repoDir = path.join(tmpDir, hash);

resources/gen-changelog.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execOutput, readPackageJSON } from './utils';
1+
import { exec, readPackageJSON } from './utils';
22

33
const packageJSON = readPackageJSON();
44
const labelsConfig: { [label: string]: { section: string; fold?: boolean } } = {
@@ -64,19 +64,15 @@ function getChangeLog(): Promise<string> {
6464
const { version } = packageJSON;
6565

6666
let tag: string | null = null;
67-
let commitsList = execOutput(`git rev-list --reverse v${version}..`);
67+
let commitsList = exec(`git rev-list --reverse v${version}..`);
6868
if (commitsList === '') {
69-
const parentPackageJSON = execOutput(
70-
'git cat-file blob HEAD~1:package.json',
71-
);
69+
const parentPackageJSON = exec('git cat-file blob HEAD~1:package.json');
7270
const parentVersion = JSON.parse(parentPackageJSON).version;
73-
commitsList = execOutput(
74-
`git rev-list --reverse v${parentVersion}..HEAD~1`,
75-
);
71+
commitsList = exec(`git rev-list --reverse v${parentVersion}..HEAD~1`);
7672
tag = `v${version}`;
7773
}
7874

79-
const date = execOutput('git log -1 --format=%cd --date=short');
75+
const date = exec('git log -1 --format=%cd --date=short');
8076
return getCommitsInfo(commitsList.split('\n'))
8177
.then((commitsInfo) => getPRsInfo(commitsInfoToPRs(commitsInfo)))
8278
.then((prsInfo) => genChangeLog(tag, date, prsInfo));

resources/utils.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ export function localRepoPath(...paths: ReadonlyArray<string>): string {
99
return path.join(__dirname, '..', ...paths);
1010
}
1111

12-
export function exec(command: string, options?: { cwd: string }): void {
13-
childProcess.execSync(command, options);
14-
}
15-
16-
export function execOutput(command: string, options?: { cwd: string }): string {
12+
type ExecOptions = Parameters<typeof childProcess.execSync>[1];
13+
export function exec(command: string, options?: ExecOptions): string {
1714
const output = childProcess.execSync(command, {
1815
maxBuffer: 10 * 1024 * 1024, // 10MB
1916
stdio: ['inherit', 'pipe', 'inherit'],
2017
encoding: 'utf-8',
2118
...options,
2219
});
23-
return output.trimEnd();
20+
return output.toString().trimEnd();
2421
}
2522

2623
export function readdirRecursive(

0 commit comments

Comments
 (0)