diff --git a/.circleci/config.yml b/.circleci/config.yml index 0249cdf975..65a26772e3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: diff --git a/aio/tools/ng-packages-installer/index.js b/aio/tools/ng-packages-installer/index.js index 63ae532483..8db9a480af 100644 --- a/aio/tools/ng-packages-installer/index.js +++ b/aio/tools/ng-packages-installer/index.js @@ -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}"`; /** diff --git a/aio/tools/ng-packages-installer/index.spec.js b/aio/tools/ng-packages-installer/index.spec.js index 7511e86200..04cfb9f52e 100644 --- a/aio/tools/ng-packages-installer/index.spec.js +++ b/aio/tools/ng-packages-installer/index.spec.js @@ -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'); diff --git a/docs/DEBUG_COMPONENTS_REPO_IVY.md b/docs/DEBUG_COMPONENTS_REPO_IVY.md index 4dc2e5b56c..59feffafb8 100644 --- a/docs/DEBUG_COMPONENTS_REPO_IVY.md +++ b/docs/DEBUG_COMPONENTS_REPO_IVY.md @@ -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)). diff --git a/docs/DEVELOPER.md b/docs/DEVELOPER.md index 38ddf18c9c..cae2d95ce9 100644 --- a/docs/DEVELOPER.md +++ b/docs/DEVELOPER.md @@ -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: diff --git a/integration/README.md b/integration/README.md index 071b2cf312..84b9dbe21e 100644 --- a/integration/README.md +++ b/integration/README.md @@ -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. diff --git a/integration/cli-hello-world-ivy-compat/debug-test.sh b/integration/cli-hello-world-ivy-compat/debug-test.sh index fc9aca7945..38013c4ffc 100755 --- a/integration/cli-hello-world-ivy-compat/debug-test.sh +++ b/integration/cli-hello-world-ivy-compat/debug-test.sh @@ -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 diff --git a/integration/cli-hello-world-ivy-minimal/debug-test.sh b/integration/cli-hello-world-ivy-minimal/debug-test.sh index fc9aca7945..38013c4ffc 100755 --- a/integration/cli-hello-world-ivy-minimal/debug-test.sh +++ b/integration/cli-hello-world-ivy-minimal/debug-test.sh @@ -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 diff --git a/integration/ivy-i18n/debug-test.sh b/integration/ivy-i18n/debug-test.sh index fc9aca7945..38013c4ffc 100755 --- a/integration/ivy-i18n/debug-test.sh +++ b/integration/ivy-i18n/debug-test.sh @@ -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 diff --git a/integration/language_service_plugin/package.json b/integration/language_service_plugin/package.json index c097f840da..7c9b73c6de 100644 --- a/integration/language_service_plugin/package.json +++ b/integration/language_service_plugin/package.json @@ -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" diff --git a/integration/ng_elements_schematics/package.json b/integration/ng_elements_schematics/package.json index 96c5faf6a1..626a119310 100644 --- a/integration/ng_elements_schematics/package.json +++ b/integration/ng_elements_schematics/package.json @@ -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" } } diff --git a/integration/ngcc/debug-test.sh b/integration/ngcc/debug-test.sh index d7ed06be59..83d3ed6894 100755 --- a/integration/ngcc/debug-test.sh +++ b/integration/ngcc/debug-test.sh @@ -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 diff --git a/integration/run_tests.sh b/integration/run_tests.sh index 0e97016da9..ed9cd09578 100755 --- a/integration/run_tests.sh +++ b/integration/run_tests.sh @@ -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. diff --git a/scripts/build-package-dist.js b/scripts/build-package-dist.js new file mode 100755 index 0000000000..db67b5f956 --- /dev/null +++ b/scripts/build-package-dist.js @@ -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); diff --git a/scripts/build-packages-dist.js b/scripts/build-packages-dist.js deleted file mode 100755 index 97d1568d10..0000000000 --- a/scripts/build-packages-dist.js +++ /dev/null @@ -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); diff --git a/scripts/build-ivy-npm-packages.js b/scripts/build/build-ivy-npm-packages.js similarity index 85% rename from scripts/build-ivy-npm-packages.js rename to scripts/build/build-ivy-npm-packages.js index 8577c0e6de..04bdec2776 100755 --- a/scripts/build-ivy-npm-packages.js +++ b/scripts/build/build-ivy-npm-packages.js @@ -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'); diff --git a/scripts/build/build-packages-dist.js b/scripts/build/build-packages-dist.js new file mode 100755 index 0000000000..446add09b5 --- /dev/null +++ b/scripts/build/build-packages-dist.js @@ -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(); diff --git a/scripts/package-builder.js b/scripts/build/package-builder.js old mode 100755 new mode 100644 similarity index 97% rename from scripts/package-builder.js rename to scripts/build/package-builder.js index 668f35762a..b5c2d53350 --- a/scripts/package-builder.js +++ b/scripts/build/package-builder.js @@ -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(''); } /** diff --git a/scripts/build/zone-js-builder.js b/scripts/build/zone-js-builder.js new file mode 100644 index 0000000000..59cb8de31f --- /dev/null +++ b/scripts/build/zone-js-builder.js @@ -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(''); +}