Skip to content

Commit e20e397

Browse files
clydinalan-agius4
authored andcommitted
build: remove usage of built package from build script
Previously, the `@angular/core` package which was being built was used during the build process. This package was only used for logging and has now been replaced with the Console instead. This prevents potential logging issues if there are bugs or errors within the package being built.
1 parent 9797305 commit e20e397

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

scripts/build.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { logging } from '@angular-devkit/core';
109
import { spawn } from 'child_process';
1110
import fs from 'fs';
1211
import { dirname, join, relative, resolve } from 'path';
@@ -35,7 +34,7 @@ function _copy(from: string, to: string) {
3534
fs.writeFileSync(to, buffer);
3635
}
3736

38-
function _recursiveCopy(from: string, to: string, logger: logging.Logger) {
37+
function _recursiveCopy(from: string, to: string, logger: Console) {
3938
if (!fs.existsSync(from)) {
4039
logger.error(`File "${from}" does not exist.`);
4140
process.exit(4);
@@ -53,13 +52,13 @@ function rimraf(location: string) {
5352
fs.rmSync(location, { force: true, recursive: true, maxRetries: 3 });
5453
}
5554

56-
function _clean(logger: logging.Logger) {
55+
function _clean(logger: Console) {
5756
logger.info('Cleaning...');
5857
logger.info(' Removing dist/...');
5958
rimraf(join(__dirname, '../dist'));
6059
}
6160

62-
function _exec(cmd: string, captureStdout: boolean, logger: logging.Logger): Promise<string> {
61+
function _exec(cmd: string, captureStdout: boolean, logger: Console): Promise<string> {
6362
return new Promise((resolve, reject) => {
6463
const proc = spawn(cmd, {
6564
stdio: 'pipe',
@@ -89,36 +88,40 @@ function _exec(cmd: string, captureStdout: boolean, logger: logging.Logger): Pro
8988
});
9089
}
9190

92-
async function _build(logger: logging.Logger, mode: BuildMode): Promise<string[]> {
93-
logger.info(`Building (mode=${mode})...`);
91+
async function _build(logger: Console, mode: BuildMode): Promise<string[]> {
92+
logger.group(`Building (mode=${mode})...`);
9493

95-
const queryLogger = logger.createChild('query');
94+
logger.group('Finding targets...');
9695
const queryTargetsCmd =
9796
`${bazelCmd} query --output=label "attr(name, npm_package_archive, //packages/...` +
9897
' except //packages/angular/ssr/schematics/...)"';
99-
const targets = (await _exec(queryTargetsCmd, true, queryLogger)).split(/\r?\n/);
100-
101-
const buildLogger = logger.createChild('build');
98+
const targets = (await _exec(queryTargetsCmd, true, logger)).split(/\r?\n/);
99+
logger.groupEnd();
102100

103101
// If we are in release mode, run `bazel clean` to ensure the execroot and action cache
104102
// are not populated. This is necessary because targets using `npm_package` rely on
105103
// workspace status variables for the package version. Such NPM package targets are not
106104
// rebuilt if only the workspace status variables change. This could result in accidental
107105
// re-use of previously built package output with a different `version` in the `package.json`.
108106
if (mode == 'release') {
109-
buildLogger.info('Building in release mode. Resetting the Bazel execroot and action cache.');
110-
await _exec(`${bazelCmd} clean`, false, buildLogger);
107+
logger.info('Building in release mode. Resetting the Bazel execroot and action cache.');
108+
await _exec(`${bazelCmd} clean`, false, logger);
111109
}
112110

113-
await _exec(`${bazelCmd} build --config=${mode} ${targets.join(' ')}`, false, buildLogger);
111+
logger.group('Building targets...');
112+
await _exec(`${bazelCmd} build --config=${mode} ${targets.join(' ')}`, false, logger);
113+
logger.groupEnd();
114+
115+
logger.groupEnd();
114116

115117
return targets;
116118
}
117119

118120
export default async function (
119121
argv: { local?: boolean; snapshot?: boolean } = {},
120-
logger: logging.Logger = new logging.Logger('build-logger'),
121122
): Promise<{ name: string; outputPath: string }[]> {
123+
const logger = globalThis.console;
124+
122125
const bazelBin = await _exec(`${bazelCmd} info bazel-bin`, true, logger);
123126

124127
_clean(logger);
@@ -135,8 +138,7 @@ export default async function (
135138
const targets = await _build(logger, buildMode);
136139
const output: { name: string; outputPath: string }[] = [];
137140

138-
logger.info('Moving packages and tars to dist/');
139-
const packageLogger = logger.createChild('packages');
141+
logger.group('Moving packages and tars to dist/');
140142

141143
for (const target of targets) {
142144
const packageDir = target.replace(/\/\/packages\/(.*):npm_package_archive/, '$1');
@@ -146,13 +148,15 @@ export default async function (
146148
const packageName = require(packageJsonPath).name;
147149
const destDir = `${distRoot}/${packageName}`;
148150

149-
packageLogger.info(packageName);
151+
logger.info(packageName);
150152

151153
_recursiveCopy(bazelOutDir, destDir, logger);
152154
_copy(tarPath, `${distRoot}/${packageName.replace('@', '_').replace('/', '_')}.tgz`);
153155

154156
output.push({ name: packageDir, outputPath: destDir });
155157
}
156158

159+
logger.groupEnd();
160+
157161
return output;
158162
}

0 commit comments

Comments
 (0)