Skip to content

Commit d248d83

Browse files
devversionAndrewKushnir
authored andcommitted
build: convert release package build scripts to typescript (angular#46456)
Follow-up to: cce395a. PR Close angular#46456
1 parent 2d713f5 commit d248d83

25 files changed

+258
-324
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ build:release --workspace_status_command="yarn -s ng-dev release build-env-stamp
5353
build:release --stamp
5454

5555
# Snapshots should also be stamped with version control information.
56-
build:snapshot --workspace_status_command="yarn -s ng-dev release build-env-stamp --mode=snapshot"
57-
build:snapshot --stamp
56+
build:snapshot-build --workspace_status_command="yarn -s ng-dev release build-env-stamp --mode=snapshot"
57+
build:snapshot-build --stamp
5858

5959
###############################
6060
# Output #

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ jobs:
442442
steps:
443443
- custom_attach_workspace
444444
- init_environment
445-
- run: node scripts/build/build-packages-dist.js
445+
- run: yarn build
446446

447447
# Save the npm packages from //packages/... for other workflow jobs to read
448448
- persist_to_workspace:

.ng-dev/release.mts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {ReleaseConfig} from '@angular/dev-infra-private/ng-dev';
2-
import {join} from 'path';
32

43
/** Configuration for the `ng-dev release` command. */
54
export const release: ReleaseConfig = {
@@ -24,12 +23,10 @@ export const release: ReleaseConfig = {
2423
{name: '@angular/upgrade'},
2524
],
2625
buildPackages: async () => {
27-
// The buildTargetPackages function is loaded at runtime as the loading the script causes an
28-
// invocation of bazel.
29-
const packageBuilder = await import('../scripts/build/package-builder.js');
30-
31-
return packageBuilder.default.buildTargetPackages(
32-
'dist/release-output', 'Release', /* isRelease */ true);
26+
// The buildTargetPackages function is loaded at runtime as the loading the script
27+
// causes an invocation of Bazel.
28+
const {performNpmReleaseBuild} = await import('../scripts/build/package-builder.mjs');
29+
return performNpmReleaseBuild();
3330
},
3431
releaseNotes: {
3532
hiddenScopes: ['aio', 'bazel', 'dev-infra', 'docs-infra', 'zone.js', 'devtools'],

aio/tools/ng-packages-installer/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const ANGULAR_ROOT_DIR = path.resolve(__dirname, '../../..');
1616
const ANGULAR_DIST_PACKAGES_DIR = path.join(ANGULAR_ROOT_DIR, 'dist/packages-dist');
1717
const AIMWA_DIST_PACKAGES_DIR = path.join(ANGULAR_ROOT_DIR, 'dist/angular-in-memory-web-api-dist');
1818
const ZONEJS_DIST_PACKAGES_DIR = path.join(ANGULAR_ROOT_DIR, 'dist/zone.js-dist');
19-
const DIST_PACKAGES_BUILD_SCRIPT = path.join(ANGULAR_ROOT_DIR, 'scripts/build/build-packages-dist.js');
20-
const DIST_PACKAGES_BUILD_CMD = `"${process.execPath}" "${DIST_PACKAGES_BUILD_SCRIPT}"`;
19+
const DIST_PACKAGES_BUILD_CMD = 'yarn -s build';
2120

2221
/**
2322
* A tool that can install Angular/Zone.js dependencies for a project from NPM or from the
@@ -181,14 +180,14 @@ class NgPackagesInstaller {
181180
const canBuild = process.platform !== 'win32';
182181

183182
if (canBuild) {
184-
this._log(`Building the local packages with: ${DIST_PACKAGES_BUILD_SCRIPT}`);
185-
shelljs.exec(DIST_PACKAGES_BUILD_CMD);
183+
this._log(`Building the local packages with: ${DIST_PACKAGES_BUILD_CMD} in ${ANGULAR_ROOT_DIR}`);
184+
shelljs.exec(DIST_PACKAGES_BUILD_CMD, {cwd: ANGULAR_ROOT_DIR});
186185
} else {
187186
this._warn([
188187
'Automatically building the local Angular/angular-in-memory-web-api/zone.js packages is currently not ' +
189188
'supported on Windows.',
190189
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}', '${AIMWA_DIST_PACKAGES_DIR}' and ` +
191-
`'${ZONEJS_DIST_PACKAGES_DIR}' exist and are up-to-date (e.g. by running '${DIST_PACKAGES_BUILD_SCRIPT}' ` +
190+
`'${ZONEJS_DIST_PACKAGES_DIR}' exist and are up-to-date (e.g. by running "${DIST_PACKAGES_BUILD_CMD}" ` +
192191
'in Git Bash for Windows, Windows Subsystem for Linux or a Linux docker container or VM).',
193192
'',
194193
'Proceeding anyway...',

aio/tools/ng-packages-installer/index.spec.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,25 +305,20 @@ describe('NgPackagesInstaller', () => {
305305
};
306306

307307
it('should build the local packages, when not on Windows', () => {
308-
const buildScript = path.join(ngRootDir, 'scripts/build/build-packages-dist.js');
309-
const buildCmd = `"${process.execPath}" "${buildScript}"`;
308+
const buildCmd = 'yarn -s build';
310309

311310
buildDistPackagesOnPlatform('linux');
312-
expect(shelljs.exec).toHaveBeenCalledWith(buildCmd);
311+
expect(shelljs.exec).toHaveBeenCalledWith(buildCmd, {cwd: ngRootDir});
313312

314313
shelljs.exec.calls.reset();
315314

316315
buildDistPackagesOnPlatform('darwin');
317-
expect(shelljs.exec).toHaveBeenCalledWith(buildCmd);
316+
expect(shelljs.exec).toHaveBeenCalledWith(buildCmd, {cwd: ngRootDir});
318317

319318
shelljs.exec.calls.reset();
320319

321320
buildDistPackagesOnPlatform('anythingButWindows :(');
322-
expect(shelljs.exec).toHaveBeenCalledWith(buildCmd);
323-
324-
// Ensure that the script does actually exist (e.g. it was not renamed/moved).
325-
fs.existsSync.and.callThrough();
326-
expect(fs.existsSync(buildScript)).toBe(true);
321+
expect(shelljs.exec).toHaveBeenCalledWith(buildCmd, {cwd: ngRootDir});
327322
});
328323

329324
it('should print a warning, when on Windows', () => {

devtools/src/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pkg_web(
283283
"@npm//:node_modules/tslib/tslib.js",
284284
],
285285
# Currently, ibazel doesn't allow passing in flags to bazel run.
286-
# This means we are not able to use --config snapshot
286+
# This means we are not able to use --config snapshot-build
287287
# to access the current commit SHA.
288288
# Since we still want to be able to use ibazel to speed up
289289
# local development, we supply an empty string for the SHA substitution.

docs/BAZEL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ The `msys64` library and associated tools (like `mkdir`) are required to build A
297297

298298
Make sure you have `C:\msys64\usr\bin` in the "system" `PATH` rather than the "user" `PATH`.
299299

300-
After that, a `git clean -xfd`, `yarn`, and `node scripts\build\build-packages-dist.js` should resolve this issue.
300+
After that, a `git clean -xfd`, `yarn`, and `yarn build` should resolve this issue.
301301

302302
### Xcode
303303

docs/DEBUG_COMPONENTS_REPO_IVY.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Currently all changes to Ivy are validated against the test suite of the
44
`angular/components` repository. In order to debug the `components-repo-unit-tests` CI
55
job, the following steps can be used:
66

7-
1\) Build the Ivy package output by running `node ./scripts/build/build-packages-dist.js` in
8-
the `angular/angular` repo.
7+
1\) Build the Ivy package output by running `yarn build` in the `angular/angular` repo.
98

109
2\) Clone the `angular/components` repository if not done yet ([quick link to repo](https://github.com/angular/components)).
1110

docs/DEVELOPER.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ yarn install
6767
To build Angular run:
6868

6969
```shell
70-
node ./scripts/build/build-packages-dist.js
70+
yarn build
7171
```
7272

7373
* Results are put in the `dist/packages-dist` folder.
@@ -197,7 +197,7 @@ c. Some package managers (such as `pnpm` or `yarn pnp`) might not work correctly
197197
### Publishing to GitHub Repos
198198
You can also manually publish `*-builds` snapshots just like our CircleCI build does for upstream
199199
builds. Before being able to publish the packages, you need to build them locally by running the
200-
`./scripts/build/build-packages-dist.js` script.
200+
`yarn build` command.
201201

202202
First time, you need to create the GitHub repositories:
203203

integration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This directory contains end-to-end tests for Angular. Each directory is a self-c
44
that exactly mimics how a user might expect Angular to work, so they allow high-fidelity
55
reproductions of real-world issues.
66

7-
For this to work, we first build the Angular distribution via `./scripts/build/build-packages-dist.js`, then
7+
For this to work, we first build the Angular distribution via `yarn build`, then
88
install the distribution into each app.
99

1010
To test Angular CLI applications, we use the `cli-hello-world-*` integration tests.

integration/cli-hello-world-ivy-compat/debug-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ set -u -e -o pipefail
1111

1212
cd "$(dirname "$0")"
1313

14-
node $(pwd)/../../scripts/build/build-packages-dist.js
14+
# Go to the project directory and build the release packages.
15+
(cd $(pwd)/../../ && yarn build)
1516

1617
# Workaround https://github.com/yarnpkg/yarn/issues/2165
1718
# Yarn will cache file://dist URIs and not update Angular code

integration/cli-hello-world-ivy-minimal/debug-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ set -u -e -o pipefail
1111

1212
cd "$(dirname "$0")"
1313

14-
node $(pwd)/../../scripts/build/build-packages-dist.js
14+
# Go to the project directory and build the release packages.
15+
(cd $(pwd)/../../ && yarn build)
1516

1617
# Workaround https://github.com/yarnpkg/yarn/issues/2165
1718
# Yarn will cache file://dist URIs and not update Angular code

integration/ivy-i18n/debug-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ set -u -e -o pipefail
1111

1212
cd "$(dirname "$0")"
1313

14-
node $(pwd)/../../scripts/build/build-packages-dist.js
14+
# Go to the project directory and build the release packages.
15+
(cd $(pwd)/../../ && yarn build)
1516

1617
# Workaround https://github.com/yarnpkg/yarn/issues/2165
1718
# Yarn will cache file://dist URIs and not update Angular code

integration/ngcc/debug-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ set -u -e -o pipefail
1111

1212
cd "$(dirname "$0")"
1313

14-
node $(pwd)/../../scripts/build/build-packages-dist.js
14+
# Go to the project directory and build the release packages.
15+
(cd $(pwd)/../../ && yarn build)
1516

1617
# Workaround https://github.com/yarnpkg/yarn/issues/2165
1718
# Yarn will cache file://dist URIs and not update Angular code

integration/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ echo ${RUN_TESTS}
2020

2121
# Build the packages-dist directory.
2222
# This should be fast on incremental re-build.
23-
node ../scripts/build/build-packages-dist.js
23+
yarn build
2424

2525
# Workaround https://github.com/yarnpkg/yarn/issues/2165
2626
# Yarn will cache file://dist URIs and not update Angular code

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"postinstall": "node scripts/webdriver-manager-update.js && node --preserve-symlinks --preserve-symlinks-main ./tools/postinstall-patches.js",
2626
"prepare": "husky install",
2727
"ng-dev": "ts-node --esm --project .ng-dev/tsconfig.json node_modules/@angular/dev-infra-private/ng-dev/bundles/cli.mjs",
28+
"build": "ts-node --esm --project scripts/tsconfig.json scripts/build/build-packages-dist.mts",
2829
"test": "bazelisk test",
2930
"test:ci": "bazelisk test -- //... -//devtools/... -//aio/...",
3031
"test-tsec": "bazelisk test //... --build_tag_filters=tsec --test_tag_filters=tsec",
@@ -36,11 +37,11 @@
3637
"symbol-extractor:update": "node tools/symbol-extractor/run_all_symbols_extractor_tests.js accept",
3738
"ts-circular-deps:check": "yarn -s ng-dev ts-circular-deps check --config ./packages/circular-deps-test.conf.js",
3839
"ts-circular-deps:approve": "yarn -s ng-dev ts-circular-deps approve --config ./packages/circular-deps-test.conf.js",
39-
"check-tooling-setup": "yarn tsc --project .ng-dev/tsconfig.json",
40+
"check-tooling-setup": "yarn tsc --project .ng-dev/tsconfig.json && yarn tsc --project scripts/tsconfig.json",
4041
"devtools:devserver": "ibazel run //devtools/src:devserver",
41-
"devtools:build:chrome": "bazelisk build --config snapshot --//devtools/projects/shell-browser/src:flag_browser=chrome -- devtools/projects/shell-browser/src:prodapp",
42-
"devtools:build:firefox": "bazelisk build --config snapshot --//devtools/projects/shell-browser/src:flag_browser=firefox -- devtools/projects/shell-browser/src:prodapp",
43-
"devtools:test": "bazelisk test --config snapshot --//devtools/projects/shell-browser/src:flag_browser=chrome -- //devtools/..."
42+
"devtools:build:chrome": "bazelisk build --config snapshot-build --//devtools/projects/shell-browser/src:flag_browser=chrome -- devtools/projects/shell-browser/src:prodapp",
43+
"devtools:build:firefox": "bazelisk build --config snapshot-build --//devtools/projects/shell-browser/src:flag_browser=firefox -- devtools/projects/shell-browser/src:prodapp",
44+
"devtools:test": "bazelisk test --config snapshot-build --//devtools/projects/shell-browser/src:flag_browser=chrome -- //devtools/..."
4445
},
4546
"// 1": "dependencies are used locally and by bazel",
4647
"dependencies": {

scripts/build-package-dist.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {join} from 'path';
10+
import sh from 'shelljs';
11+
12+
import {projectDir, bazelCmd, exec} from './package-builder.mjs';
13+
14+
/**
15+
* Build the `angular-in-memory-web-api` npm package and copies it into the release
16+
* distribution directory.
17+
*
18+
* NOTE: The `angular-in-memory-web-api` package is not built as part of `package-builder`'s
19+
* `buildTargetPackages()` nor is it copied into the same directory as the Angular packages (e.g.
20+
* `dist/packages-dist/`) despite its source's being inside `packages/`, because it is not
21+
* published to npm under the `@angular` scope (as happens for the rest of the packages).
22+
*
23+
* @param {string} destDir Path to the output directory into which we copy the npm package.
24+
* This path should either be absolute or relative to the project root.
25+
*/
26+
export function buildAngularInMemoryWebApiPackage(destDir: string): void {
27+
console.info('##############################');
28+
console.info(' Building angular-in-memory-web-api npm package');
29+
console.info('##############################');
30+
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+
}
37+
38+
const bazelBinPath = exec(`${bazelCmd} info bazel-bin`, true);
39+
40+
// Copy artifacts to `destDir`, so they can be easier persisted on CI and used by non-bazel
41+
// scripts/tests.
42+
const buildOutputDir = join(bazelBinPath, 'packages/misc/angular-in-memory-web-api/npm_package');
43+
const distTargetDir = join(destDir, 'angular-in-memory-web-api');
44+
45+
console.info(`# Copy npm_package artifacts to ${distTargetDir}`);
46+
47+
sh.rm('-rf', distTargetDir);
48+
sh.cp('-R', buildOutputDir, distTargetDir);
49+
sh.chmod('-R', 'u+w', distTargetDir);
50+
}

scripts/build/build-packages-dist.js renamed to scripts/build/build-packages-dist.mts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
23
/**
34
* @license
45
* Copyright Google LLC All Rights Reserved.
@@ -7,15 +8,13 @@
78
* found in the LICENSE file at https://angular.io/license
89
*/
910

10-
'use strict';
11-
12-
const {buildAngularInMemoryWebApiPackage} = require('./angular-in-memory-web-api');
13-
const {buildTargetPackages} = require('./package-builder');
14-
const {buildZoneJsPackage} = require('./zone-js-builder');
11+
import {buildAngularInMemoryWebApiPackage} from './angular-in-memory-web-api.mjs';
12+
import {performDefaultSnapshotBuild} from './package-builder.mjs';
13+
import {buildZoneJsPackage} from './zone-js-builder.mjs';
1514

1615

1716
// Build the legacy (view engine) npm packages into `dist/packages-dist/`.
18-
buildTargetPackages('dist/packages-dist', 'Production');
17+
performDefaultSnapshotBuild();
1918

2019
// Build the `angular-in-memory-web-api` npm package into `dist/angular-in-memory-web-api-dist/`,
2120
// because it might be needed by other scripts/targets.

0 commit comments

Comments
 (0)