Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources: merge execOutput and exec into single function #3698

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions resources/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as os from 'node:os';
import * as path from 'node:path';
import * as url from 'node:url';

import { exec, execOutput, localRepoPath } from './utils';
import { exec, localRepoPath } from './utils';

const NS_PER_SEC = 1e9;
const LOCAL = 'local';
Expand Down Expand Up @@ -77,7 +77,7 @@ function prepareBenchmarkProjects(
}

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

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

const distDir = path.join(repoDir, 'npmDist');
const archiveName = execOutput(`npm --quiet pack ${distDir}`, {
const archiveName = exec(`npm --quiet pack ${distDir}`, {
cwd: repoDir,
});
return path.join(repoDir, archiveName);
Expand Down
6 changes: 3 additions & 3 deletions resources/diff-npm-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';

import { exec, execOutput, localRepoPath, writeGeneratedFile } from './utils';
import { exec, localRepoPath, writeGeneratedFile } from './utils';

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

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

if (diff === '') {
console.log('No changes found!');
Expand Down Expand Up @@ -83,7 +83,7 @@ function prepareNPMPackage(revision: string): string {
}

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

const repoDir = path.join(tmpDir, hash);
Expand Down
14 changes: 5 additions & 9 deletions resources/gen-changelog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execOutput, readPackageJSON } from './utils';
import { exec, readPackageJSON } from './utils';

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

let tag: string | null = null;
let commitsList = execOutput(`git rev-list --reverse v${version}..`);
let commitsList = exec(`git rev-list --reverse v${version}..`);
if (commitsList === '') {
const parentPackageJSON = execOutput(
'git cat-file blob HEAD~1:package.json',
);
const parentPackageJSON = exec('git cat-file blob HEAD~1:package.json');
const parentVersion = JSON.parse(parentPackageJSON).version;
commitsList = execOutput(
`git rev-list --reverse v${parentVersion}..HEAD~1`,
);
commitsList = exec(`git rev-list --reverse v${parentVersion}..HEAD~1`);
tag = `v${version}`;
}

const date = execOutput('git log -1 --format=%cd --date=short');
const date = exec('git log -1 --format=%cd --date=short');
return getCommitsInfo(commitsList.split('\n'))
.then((commitsInfo) => getPRsInfo(commitsInfoToPRs(commitsInfo)))
.then((prsInfo) => genChangeLog(tag, date, prsInfo));
Expand Down
9 changes: 3 additions & 6 deletions resources/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ export function localRepoPath(...paths: ReadonlyArray<string>): string {
return path.join(__dirname, '..', ...paths);
}

export function exec(command: string, options?: { cwd: string }): void {
childProcess.execSync(command, options);
}

export function execOutput(command: string, options?: { cwd: string }): string {
type ExecOptions = Parameters<typeof childProcess.execSync>[1];
export function exec(command: string, options?: ExecOptions): string {
const output = childProcess.execSync(command, {
maxBuffer: 10 * 1024 * 1024, // 10MB
stdio: ['inherit', 'pipe', 'inherit'],
encoding: 'utf-8',
...options,
});
return output.trimEnd();
return output.toString().trimEnd();
}

export function readdirRecursive(
Expand Down