Skip to content

Commit d4c0962

Browse files
gkalpakatscott
authored andcommitted
refactor(dev-infra): use the exec() helper from utils/shelljs whenever possible (angular#37444)
There is an `exec()` helper provided by `utils/shelljs.ts`, which is a wrapper around ShellJS' `exec()` with some default options (currently `silent: true`). The intention is to avoid having to pass these options to every invocation of the `exec()` function. This commit updates all code inside `dev-infra/` to use this helper whenever possible). NOTE: For simplicity, the `utils/shelljs` helper does not support some of the less common call signatures of the original `exec()` helper, so in some cases we still need to use the original. PR Close angular#37444
1 parent e31208b commit d4c0962

File tree

6 files changed

+12
-18
lines changed

6 files changed

+12
-18
lines changed

dev-infra/commit-message/validate-range.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {exec} from 'shelljs';
9-
108
import {info} from '../utils/console';
9+
import {exec} from '../utils/shelljs';
1110

1211
import {parseCommitMessage, validateCommitMessage, ValidateCommitMessageOptions} from './validate';
1312

@@ -26,7 +25,7 @@ export function validateCommitRange(range: string) {
2625
const gitLogFormat = `%s%n%n%b${randomValueSeparator}`;
2726

2827
// Retrieve the commits in the provided range.
29-
const result = exec(`git log --reverse --format=${gitLogFormat} ${range}`, {silent: true});
28+
const result = exec(`git log --reverse --format=${gitLogFormat} ${range}`);
3029
if (result.code) {
3130
throw new Error(`Failed to get all commits in the range: \n ${result.stderr}`);
3231
}

dev-infra/release/env-stamp.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {exec as _exec} from 'shelljs';
10-
11-
import {info} from '../utils/console';
9+
import {exec as _exec} from '../utils/shelljs';
1210

1311
/**
1412
* Log the environment variables expected by bazel for stamping.
@@ -32,7 +30,7 @@ export function buildEnvStamp() {
3230

3331
/** Run the exec command and return the stdout as a trimmed string. */
3432
function exec(cmd: string) {
35-
return _exec(cmd, {silent: true}).toString().trim();
33+
return _exec(cmd).trim();
3634
}
3735

3836
/** Whether the repo has local changes. */

dev-infra/utils/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import {existsSync} from 'fs';
1010
import {dirname, join} from 'path';
11-
import {exec} from 'shelljs';
1211

1312
import {error} from './console';
13+
import {exec} from './shelljs';
1414
import {isTsNodeAvailable} from './ts-node';
1515

1616
/**
@@ -119,7 +119,7 @@ export function assertNoErrors(errors: string[]) {
119119

120120
/** Gets the path of the directory for the repository base. */
121121
export function getRepoBaseDir() {
122-
const baseRepoDir = exec(`git rev-parse --show-toplevel`, {silent: true});
122+
const baseRepoDir = exec(`git rev-parse --show-toplevel`);
123123
if (baseRepoDir.code) {
124124
throw Error(
125125
`Unable to find the path to the base directory of the repository.\n` +

dev-infra/utils/git.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {exec} from '../utils/shelljs';
9+
import {exec} from './shelljs';
1010

1111

1212
/** Whether the repo has any local changes. */

dev-infra/utils/repo-files.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {exec} from 'shelljs';
109
import {getRepoBaseDir} from './config';
10+
import {exec} from './shelljs';
1111

1212
/**
1313
* A list of all files currently in the repo which have been modified since the provided sha.
@@ -33,8 +33,5 @@ export function allFiles() {
3333

3434

3535
function gitOutputAsArray(cmd: string) {
36-
return exec(cmd, {cwd: getRepoBaseDir(), silent: true})
37-
.split('\n')
38-
.map(x => x.trim())
39-
.filter(x => !!x);
36+
return exec(cmd, {cwd: getRepoBaseDir()}).split('\n').map(x => x.trim()).filter(x => !!x);
4037
}

dev-infra/utils/shelljs.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {exec as _exec, ShellString} from 'shelljs';
9+
import {exec as _exec, ExecOptions, ShellString} from 'shelljs';
1010

1111
/* Run an exec command as silent. */
12-
export function exec(cmd: string): ShellString {
13-
return _exec(cmd, {silent: true});
12+
export function exec(cmd: string, opts?: ExecOptions&{async?: false}): ShellString {
13+
return _exec(cmd, {silent: true, ...opts});
1414
}

0 commit comments

Comments
 (0)