build: move build scripts to dedicated directory (#35780)

This commit moves the build-related scripts
(`build-ivy-npm-packages.js`, `build-packages-dist.js` and
`package-builder.js`) to a dedicated directory to keep the `scripts/`
directory cleaner.

It also moves the logic for building the `zone.js` package to a separate
script, `zone-js-builder.js`, to make it re-usable. A subsequent commit
will use it to build the `zone.js` package when building the Ivy Angular
packages as well.

PR Close #35780
This commit is contained in:
George Kalpakas 2020-02-29 22:25:49 +02:00 committed by atscott
parent 2e728f7fff
commit 3f88de9407
19 changed files with 116 additions and 66 deletions

View File

@ -520,7 +520,7 @@ jobs:
steps:
- custom_attach_workspace
- init_environment
- run: node scripts/build-packages-dist.js
- run: node scripts/build/build-packages-dist.js
# Save the npm packages from //packages/... for other workflow jobs to read
- persist_to_workspace:
@ -545,7 +545,7 @@ jobs:
steps:
- custom_attach_workspace
- init_environment
- run: node scripts/build-ivy-npm-packages.js
- run: node scripts/build/build-ivy-npm-packages.js
# Save the npm packages from //packages/... for other workflow jobs to read
- persist_to_workspace:

View File

@ -15,7 +15,7 @@ const PACKAGE_JSON_REGEX = /^[^/]+\/package\.json$/;
const ANGULAR_ROOT_DIR = path.resolve(__dirname, '../../..');
const ANGULAR_DIST_PACKAGES = path.join(ANGULAR_ROOT_DIR, 'dist/packages-dist');
const ANGULAR_DIST_PACKAGES_BUILD_SCRIPT = path.join(ANGULAR_ROOT_DIR, 'scripts/build-packages-dist.js');
const ANGULAR_DIST_PACKAGES_BUILD_SCRIPT = path.join(ANGULAR_ROOT_DIR, 'scripts/build/build-packages-dist.js');
const ANGULAR_DIST_PACKAGES_BUILD_CMD = `"${process.execPath}" "${ANGULAR_DIST_PACKAGES_BUILD_SCRIPT}"`;
/**

View File

@ -253,7 +253,7 @@ describe('NgPackagesInstaller', () => {
};
it('should build the local packages, when not on Windows', () => {
const buildScript = path.join(ngRootDir, 'scripts/build-packages-dist.js');
const buildScript = path.join(ngRootDir, 'scripts/build/build-packages-dist.js');
const buildCmd = `"${process.execPath}" "${buildScript}"`;
buildDistPackagesOnPlatform('linux');

View File

@ -4,7 +4,7 @@ Currently all changes to Ivy are validated against the test suite of the
`angular/components` repository. In order to debug the `components-repo-unit-tests` CI
job, the following steps can be used:
1\) Build the Ivy package output by running `node ./scripts/build-ivy-npm-packages.js` in
1\) Build the Ivy package output by running `node ./scripts/build/build-ivy-npm-packages.js` in
the `angular/angular` repo.
2\) Clone the `angular/components` repository if not done yet ([quick link to repo](https://github.com/angular/components)).

View File

@ -69,7 +69,7 @@ yarn install
To build Angular run:
```shell
node ./scripts/build-packages-dist.js
node ./scripts/build/build-packages-dist.js
```
* Results are put in the `dist/packages-dist` folder.
@ -190,7 +190,7 @@ c. Some package managers (such as `pnpm` or `yarn pnp`) might not work correctly
### Publishing to GitHub repos
You can also manually publish `*-builds` snapshots just like our CircleCI build does for upstream
builds. Before being able to publish the packages, you need to build them locally by running the
`./scripts/build-packages-dist.js` script.
`./scripts/build/build-packages-dist.js` script.
First time, you need to create the GitHub repositories:

View File

@ -4,7 +4,7 @@ This directory contains end-to-end tests for Angular. Each directory is a self-c
that exactly mimics how a user might expect Angular to work, so they allow high-fidelity
reproductions of real-world issues.
For this to work, we first build the Angular distribution via `./scripts/build-packages-dist.js`, then
For this to work, we first build the Angular distribution via `./scripts/build/build-packages-dist.js`, then
install the distribution into each app.
To test Angular CLI applications, we use the `cli-hello-world-*` integration tests.

View File

@ -11,7 +11,7 @@ set -u -e -o pipefail
cd "$(dirname "$0")"
node $(pwd)/../../scripts/build-packages-dist.js
node $(pwd)/../../scripts/build/build-packages-dist.js
# Workaround https://github.com/yarnpkg/yarn/issues/2165
# Yarn will cache file://dist URIs and not update Angular code

View File

@ -11,7 +11,7 @@ set -u -e -o pipefail
cd "$(dirname "$0")"
node $(pwd)/../../scripts/build-packages-dist.js
node $(pwd)/../../scripts/build/build-packages-dist.js
# Workaround https://github.com/yarnpkg/yarn/issues/2165
# Yarn will cache file://dist URIs and not update Angular code

View File

@ -11,7 +11,7 @@ set -u -e -o pipefail
cd "$(dirname "$0")"
node $(pwd)/../../scripts/build-packages-dist.js
node $(pwd)/../../scripts/build/build-packages-dist.js
# Workaround https://github.com/yarnpkg/yarn/issues/2165
# Yarn will cache file://dist URIs and not update Angular code

View File

@ -13,7 +13,7 @@
},
"scripts": {
"build": "tsc -p tsconfig.json",
"build-dist": "node ../../scripts/build-packages-dist.js && yarn install --check-files",
"build-dist": "node ../../scripts/build/build-packages-dist.js && yarn install --check-files",
"cleanup": "rm -rf ti-*.log tsserver.log",
"golden": "yarn build && node generate.js",
"test": "yarn cleanup && yarn build && jasmine test.js"

View File

@ -11,7 +11,7 @@
},
"scripts": {
"build": "tsc -p tsconfig.json",
"build-dist": "node ../../scripts/build-packages-dist.js && yarn install --check-files",
"build-dist": "node ../../scripts/build/build-packages-dist.js && yarn install --check-files",
"test": "yarn build && node test.js"
}
}

View File

@ -11,7 +11,7 @@ set -u -e -o pipefail
cd "$(dirname "$0")"
node $(pwd)/../../scripts/build-packages-dist.js
node $(pwd)/../../scripts/build/build-packages-dist.js
# Workaround https://github.com/yarnpkg/yarn/issues/2165
# Yarn will cache file://dist URIs and not update Angular code

View File

@ -34,7 +34,7 @@ if $CI; then
else
# Not on CircleCI so let's build the packages-dist directory.
# This should be fast on incremental re-build.
node ${basedir}/scripts/build-packages-dist.js
node ${basedir}/scripts/build/build-packages-dist.js
# If we aren't running on CircleCI, we do not shard tests because this would be the job of
# Bazel eventually. For now, we just run all tests sequentially when running locally.

27
scripts/build-package-dist.js Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env node
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// The build script used to be here but has been moved to `scripts/build/` in PR
// https://github.com/angular/angular/pull/35780. This is a temporary placeholder script for people
// that are not aware of the change and expect to find the script here.
//
// TODO: This script can be removed early May 2020.
'use strict';
const {red} = require('chalk');
const {relative, resolve} = require('path');
const absoluteScriptPath = resolve(`${__dirname}/build/build-packages-dist.js`);
const relativeScriptPath = relative(process.cwd(), absoluteScriptPath);
console.error(red('ERROR: The build script has been moved to \'scripts/build/\'.'));
console.error(red(` Run: node ${relativeScriptPath}`));
process.exit(1);

View File

@ -1,48 +0,0 @@
#!/usr/bin/env node
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
'use strict';
const {chmod, cp, mkdir, rm} = require('shelljs');
const {
baseDir,
bazelBin,
bazelCmd,
buildTargetPackages,
exec,
scriptPath,
} = require('./package-builder');
// Build the legacy (view engine) npm packages into `dist/packages-dist/`.
buildTargetPackages('dist/packages-dist', false, 'Production');
// Build the `zone.js` npm package (into `dist/bin/packages/zone.js/npm_package/`), because it might
// be needed by other scripts/tests.
//
// NOTE: The `zone.js` package is not built as part of `buildTargetPackages()` above, nor is it
// copied into the `dist/packages-dist/` directory (despite its source's being inside
// `packages/`), because it is not published to npm under the `@angular` scope (as happens for
// the rest of the packages).
console.info('');
console.info('##############################');
console.info(`${scriptPath}:`);
console.info(' Building zone.js npm package');
console.info('##############################');
exec(`${bazelCmd} build //packages/zone.js:npm_package`);
// Copy artifacts to `dist/zone.js-dist/`, so they can be easier persisted on CI.
const buildOutputDir = `${bazelBin}/packages/zone.js/npm_package`;
const distTargetDir = `${baseDir}/dist/zone.js-dist/zone.js`;
console.info(`# Copy artifacts to ${distTargetDir}`);
mkdir('-p', distTargetDir);
rm('-rf', distTargetDir);
cp('-R', buildOutputDir, distTargetDir);
chmod('-R', 'u+w', distTargetDir);

View File

@ -6,10 +6,11 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
'use strict';
const {buildTargetPackages} = require('./package-builder');
// Build the ivy packages.
// Build the ivy packages into `dist/packages-dist-ivy-aot/`.
buildTargetPackages('dist/packages-dist-ivy-aot', true, 'Ivy AOT');

View File

@ -0,0 +1,21 @@
#!/usr/bin/env node
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
'use strict';
const {buildZoneJsPackage} = require('./zone-js-builder');
const {buildTargetPackages} = require('./package-builder');
// Build the legacy (view engine) npm packages into `dist/packages-dist/`.
buildTargetPackages('dist/packages-dist', false, 'Production');
// Build the `zone.js` npm package into `dist/zone.js-dist/`, because it might be needed by other
// scripts/tests.
buildZoneJsPackage();

View File

@ -31,7 +31,7 @@ set('-e');
/** @type {string} The absolute path to the project root directory. */
const baseDir = resolve(`${__dirname}/..`);
const baseDir = resolve(`${__dirname}/../..`);
/** @type {string} The command to use for running bazel. */
const bazelCmd = `yarn --cwd "${baseDir}" --silent bazel`;
@ -47,7 +47,7 @@ const bazelBin = exec(`${bazelCmd} info bazel-bin`, true);
const scriptPath = relative(baseDir, require.main.filename);
module.exports = {
baseDir, bazelBin, bazelCmd, buildTargetPackages, exec, scriptPath,
baseDir, bazelBin, bazelCmd, buildTargetPackages, exec, scriptPath,
};
/**
@ -93,6 +93,8 @@ function buildTargetPackages(destPath, enableIvy, description) {
chmod('-R', 'u+w', destDir);
}
});
console.info('');
}
/**

View File

@ -0,0 +1,47 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
'use strict';
const {chmod, cp, mkdir, rm} = require('shelljs');
const {baseDir, bazelBin, bazelCmd, exec, scriptPath} = require('./package-builder');
module.exports = {
buildZoneJsPackage,
};
/**
* Build the `zone.js` npm package into `dist/bin/packages/zone.js/npm_package/` and copy it to
* `dist/zone.js-dist/` for other scripts/tests to use.
*
* NOTE: The `zone.js` package is not built as part of `package-builder`'s `buildTargetPackages()`
* nor is it copied into the same directory as the Angular packages (e.g.
* `dist/packages-dist/`) despite its source's being inside `packages/`, because it is not
* published to npm under the `@angular` scope (as happens for the rest of the packages).
*/
function buildZoneJsPackage() {
console.info('##############################');
console.info(`${scriptPath}:`);
console.info(' Building zone.js npm package');
console.info('##############################');
exec(`${bazelCmd} build //packages/zone.js:npm_package`);
// Copy artifacts to `dist/zone.js-dist/`, so they can be easier persisted on CI and used by
// non-bazel scripts/tests.
const buildOutputDir = `${bazelBin}/packages/zone.js/npm_package`;
const distTargetDir = `${baseDir}/dist/zone.js-dist/zone.js`;
console.info(`# Copy artifacts to ${distTargetDir}`);
mkdir('-p', distTargetDir);
rm('-rf', distTargetDir);
cp('-R', buildOutputDir, distTargetDir);
chmod('-R', 'u+w', distTargetDir);
console.info('');
}