Skip to content

Commit 9c29a40

Browse files
josephperrottkirjs
authored andcommitted
build: remove shelljs from build scripts (#64042)
Remove shelljs from package building scripts PR Close #64042
1 parent e31f4bc commit 9c29a40

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

scripts/build/angular-in-memory-web-api.mts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
*/
88

99
import {join} from 'path';
10-
import sh from 'shelljs';
1110

12-
import {projectDir, bazelCmd, exec} from './package-builder.mjs';
11+
import {bazelCmd, exec} from './package-builder.mjs';
1312

1413
/**
1514
* Build the `angular-in-memory-web-api` npm package and copies it into the release
@@ -28,12 +27,9 @@ export function buildAngularInMemoryWebApiPackage(destDir: string): void {
2827
console.info(' Building angular-in-memory-web-api npm package');
2928
console.info('##############################');
3029

31-
exec(`${bazelCmd} build //packages/misc/angular-in-memory-web-api:npm_package`);
32-
33-
// Create the output directory.
34-
if (!sh.test('-d', destDir)) {
35-
sh.mkdir('-p', destDir);
36-
}
30+
exec(`${bazelCmd} build //packages/misc/angular-in-memory-web-api:npm_package`, true);
31+
// Ensure the output directory is available.
32+
exec(`mkdir -p ${destDir}`);
3733

3834
const bazelBinPath = exec(`${bazelCmd} info bazel-bin`, true);
3935

@@ -44,7 +40,7 @@ export function buildAngularInMemoryWebApiPackage(destDir: string): void {
4440

4541
console.info(`# Copy npm_package artifacts to ${distTargetDir}`);
4642

47-
sh.rm('-rf', distTargetDir);
48-
sh.cp('-R', buildOutputDir, distTargetDir);
49-
sh.chmod('-R', 'u+w', distTargetDir);
43+
exec(`rm -rf ${distTargetDir}`);
44+
exec(`cp -R ${buildOutputDir} ${distTargetDir}`);
45+
exec(`chmod -R u+w ${distTargetDir}`);
5046
}

scripts/build/package-builder.mts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {execSync} from 'child_process';
9+
import {execSync, spawnSync} from 'child_process';
1010
import {join, dirname} from 'path';
1111
import {BuiltPackage} from '@angular/ng-dev';
1212
import {fileURLToPath} from 'url';
13-
import sh from 'shelljs';
14-
15-
// ShellJS should exit if a command fails.
16-
sh.set('-e');
1713

1814
/** Path to the project directory. */
1915
export const projectDir: string = join(dirname(fileURLToPath(import.meta.url)), '../..');
@@ -76,26 +72,26 @@ function buildReleasePackages(
7672
// do this to ensure that the version placeholders are properly populated.
7773
packageNames.forEach((pkgName) => {
7874
const outputPath = getBazelOutputPath(pkgName);
79-
if (sh.test('-d', outputPath)) {
80-
sh.chmod('-R', 'u+w', outputPath);
81-
sh.rm('-rf', outputPath);
75+
if (spawnSync(`[ -d ${outputPath} ]`).status !== 0) {
76+
exec(`chmod -R u+w ${outputPath}`);
77+
exec(`rm -rf ${outputPath}`);
8278
}
8379
});
8480

8581
exec(`${bazelCmd} build ${stampConfigArg} ${targets.join(' ')}`);
8682

8783
// Delete the distribution directory so that the output is guaranteed to be clean. Re-create
8884
// the empty directory so that we can copy the release packages into it later.
89-
sh.rm('-rf', distPath);
90-
sh.mkdir('-p', distPath);
85+
exec(`rm -rf ${distPath}`);
86+
exec(`mkdir -p ${distPath}`);
9187

9288
// Copy the package output into the specified distribution folder.
9389
packageNames.forEach((pkgName) => {
9490
const outputPath = getBazelOutputPath(pkgName);
9591
const targetFolder = getDistPath(pkgName);
9692
console.info(`> Copying package output to "${targetFolder}"`);
97-
sh.cp('-R', outputPath, targetFolder);
98-
sh.chmod('-R', 'u+w', targetFolder);
93+
exec(`cp -R ${outputPath} ${targetFolder}`);
94+
exec(`chmod -R u+w ${targetFolder}`);
9995
});
10096

10197
return packageNames.map((pkg) => {

scripts/build/zone-js-builder.mts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
*/
88

99
import {join} from 'path';
10-
import sh from 'shelljs';
1110

12-
import {projectDir, bazelCmd, exec} from './package-builder.mjs';
11+
import {bazelCmd, exec} from './package-builder.mjs';
1312

1413
/**
1514
* Build the `zone.js` npm package into `dist/bin/packages/zone.js/npm_package/` and copy it to
@@ -29,11 +28,8 @@ export function buildZoneJsPackage(destDir: string): void {
2928
console.info('##############################');
3029

3130
exec(`${bazelCmd} build //packages/zone.js:npm_package`);
32-
33-
// Create the output directory.
34-
if (!sh.test('-d', destDir)) {
35-
sh.mkdir('-p', destDir);
36-
}
31+
// Ensure the output directory is available.
32+
exec(`mkdir -p ${destDir}`);
3733

3834
const bazelBinPath = exec(`${bazelCmd} info bazel-bin`, true);
3935

@@ -44,7 +40,7 @@ export function buildZoneJsPackage(destDir: string): void {
4440

4541
console.info(`# Copy npm_package artifacts to ${distTargetDir}`);
4642

47-
sh.rm('-rf', distTargetDir);
48-
sh.cp('-R', buildOutputDir, distTargetDir);
49-
sh.chmod('-R', 'u+w', distTargetDir);
43+
exec(`rm -rf ${distTargetDir}`);
44+
exec(`cp -R ${buildOutputDir} ${distTargetDir}`);
45+
exec(`chmod -R u+w ${distTargetDir}`);
5046
}

scripts/compare-main-to-patch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* features are only released to main.
2020
*/
2121

22-
const {exec} = require('shelljs');
22+
const {execSync} = require('child_process');
2323
const semver = require('semver');
2424

2525
// Ignore commits that have specific patterns in commit message, it's ok for these commits to be
@@ -44,7 +44,7 @@ const initialVersion = 'initial';
4444
// Helper methods
4545

4646
function execGitCommand(gitCommand) {
47-
const output = exec(gitCommand, {silent: true});
47+
const output = execSync(gitCommand, {silent: true});
4848
if (output.code !== 0) {
4949
console.error(`Error: git command "${gitCommand}" failed: \n\n ${output.stderr}`);
5050
process.exit(1);

0 commit comments

Comments
 (0)