build: correctly publish `angular-in-memory-web-api` as CI build artifact (#41429)

Previously, the `angular-in-memory-web-api` package was built in
`dist/packages-dist/misc/angular-in-memory-web-api/`. This was different
from other Angular packages, which were placed directly in
`dist/packages-dist/`. This caused the `create-package-archives.sh`
script to create an invalid `misc.tgz` archive (i.e. treating the
`misc/` subdirectory as a package).
See, for example, the artifacts [here][1].

This commit changes the build scripts to have the
`angular-in-memory-web-api` package built in
`dist/angular-in-memory-web-api-dist/`, similar to how the `zone.js`
package is handled. It also updates the CircleCI config to correctly
publish the `angular-in-memory-web-api` package to CI build artifacts.

[1]: https://circleci.com/gh/angular/angular/951491

PR Close #41429
This commit is contained in:
George Kalpakas 2021-04-05 19:05:54 +03:00 committed by Andrew Scott
parent e7179893f9
commit 4ae57cabd8
6 changed files with 52 additions and 19 deletions

View File

@ -501,6 +501,7 @@ jobs:
root: *workspace_location
paths:
- ng/dist/packages-dist
- ng/dist/angular-in-memory-web-api-dist
- ng/dist/zone.js-dist
# Save dependencies and bazel repository cache to use on subsequent runs.
@ -527,6 +528,7 @@ jobs:
root: *workspace_location
paths:
- ng/dist/packages-dist-ivy-aot
- ng/dist/angular-in-memory-web-api-dist-ivy-aot
- ng/dist/zone.js-dist-ivy-aot
# This job creates compressed tarballs (`.tgz` files) for all Angular packages and stores them as
@ -537,6 +539,8 @@ jobs:
publish_packages_as_artifacts:
executor: default-executor
environment:
AIMWA_PACKAGES_DIR: &aimwa_packages_dir 'dist/angular-in-memory-web-api-dist'
AIMWA_PACKAGES_ARCHIVES_DIR: &aimwa_packages_archives_dir 'dist/angular-in-memory-web-api-dist-archives'
NG_PACKAGES_DIR: &ng_packages_dir 'dist/packages-dist'
NG_PACKAGES_ARCHIVES_DIR: &ng_packages_archives_dir 'dist/packages-dist-archives'
ZONEJS_PACKAGES_DIR: &zonejs_packages_dir 'dist/zone.js-dist'
@ -551,9 +555,17 @@ jobs:
- store_artifacts:
path: *ng_packages_archives_dir
destination: angular
# Publish `zone.js` package.
# Publish the `angular-in-memory-web-api` package.
- run:
name: Create artifacts for zone.js package
name: Create artifacts for the `angular-in-memory-web-api` package
# Need to remove the zone.js.tgz before archive
command: ./scripts/ci/create-package-archives.sh $CI_BRANCH $CI_COMMIT $AIMWA_PACKAGES_DIR $AIMWA_PACKAGES_ARCHIVES_DIR
- store_artifacts:
path: *aimwa_packages_archives_dir
destination: angular-in-memory-web-api
# Publish the `zone.js` package.
- run:
name: Create artifacts for the `zone.js` package
# Need to remove the zone.js.tgz before archive
command: rm -rf $ZONEJS_PACKAGES_DIR/archive && ./scripts/ci/create-package-archives.sh $CI_BRANCH $CI_COMMIT $ZONEJS_PACKAGES_DIR $ZONEJS_PACKAGES_ARCHIVES_DIR
- store_artifacts:

View File

@ -14,8 +14,8 @@ const LOCAL_MARKER_PATH = 'node_modules/_local_.json';
const ANGULAR_ROOT_DIR = path.resolve(__dirname, '../../..');
const ANGULAR_DIST_PACKAGES_DIR = path.join(ANGULAR_ROOT_DIR, 'dist/packages-dist');
const AIMWA_DIST_PACKAGES_DIR = path.join(ANGULAR_ROOT_DIR, 'dist/angular-in-memory-web-api-dist');
const ZONEJS_DIST_PACKAGES_DIR = path.join(ANGULAR_ROOT_DIR, 'dist/zone.js-dist');
const ANGULAR_MISC_DIST_PACKAGES = path.join(ANGULAR_ROOT_DIR, 'dist/packages-dist/misc');
const DIST_PACKAGES_BUILD_SCRIPT = path.join(ANGULAR_ROOT_DIR, 'scripts/build/build-packages-dist.js');
const DIST_PACKAGES_BUILD_CMD = `"${process.execPath}" "${DIST_PACKAGES_BUILD_SCRIPT}"`;
@ -187,8 +187,8 @@ class NgPackagesInstaller {
this._warn([
'Automatically building the local Angular/angular-in-memory-web-api/zone.js packages is currently not ' +
'supported on Windows.',
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}', '${ZONEJS_DIST_PACKAGES_DIR}' and ` +
`'${ANGULAR_MISC_DIST_PACKAGES}' exist and are up-to-date (e.g. by running '${DIST_PACKAGES_BUILD_SCRIPT}' ` +
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}', '${AIMWA_DIST_PACKAGES_DIR}' and ` +
`'${ZONEJS_DIST_PACKAGES_DIR}' exist and are up-to-date (e.g. by running '${DIST_PACKAGES_BUILD_SCRIPT}' ` +
'in Git Bash for Windows, Windows Subsystem for Linux or a Linux docker container or VM).',
'',
'Proceeding anyway...',
@ -224,9 +224,9 @@ class NgPackagesInstaller {
* 'package.json' file.)
*/
_getDistPackages() {
this._log(`Angular distributable directory: ${ANGULAR_DIST_PACKAGES_DIR}.`);
this._log(`Zone.js distributable directory: ${ZONEJS_DIST_PACKAGES_DIR}.`);
this._log(`angular-in-memory-web-api distributable directory: ${ANGULAR_MISC_DIST_PACKAGES}.`);
this._log(`Distributable directory for Angular framework: ${ANGULAR_DIST_PACKAGES_DIR}`);
this._log(`Distributable directory for angular-in-memory-web-api: ${AIMWA_DIST_PACKAGES_DIR}`);
this._log(`Distributable directory for zone.js: ${ZONEJS_DIST_PACKAGES_DIR}`);
if (this.buildPackages) {
this._buildDistPackages();
@ -264,8 +264,8 @@ class NgPackagesInstaller {
const packageConfigs = {
...collectPackages(ANGULAR_DIST_PACKAGES_DIR),
...collectPackages(AIMWA_DIST_PACKAGES_DIR),
...collectPackages(ZONEJS_DIST_PACKAGES_DIR),
...collectPackages(ANGULAR_MISC_DIST_PACKAGES),
};
this._log('Found the following Angular distributables:', ...Object.keys(packageConfigs).map(key => `\n - ${key}`));

View File

@ -15,6 +15,7 @@ describe('NgPackagesInstaller', () => {
const yarnLockPath = path.resolve(absoluteProjectDir, 'yarn.lock');
const ngRootDir = path.resolve(__dirname, '../../..');
const packagesDir = path.join(ngRootDir, 'dist/packages-dist');
const aimwaDir = path.join(ngRootDir, 'dist/angular-in-memory-web-api-dist');
const zoneJsDir = path.join(ngRootDir, 'dist/zone.js-dist');
const toolsDir = path.join(ngRootDir, 'dist/tools/@angular');
let installer;
@ -104,6 +105,13 @@ describe('NgPackagesInstaller', () => {
peerDependencies: { tsickle: '^1.4.0' }
}
},
'angular-in-memory-web-api': {
packageDir: `${aimwaDir}/angular-in-memory-web-api`,
packageJsonPath: `${aimwaDir}/angular-in-memory-web-api/package.json`,
config: {
dependencies: { rxjs: '^6.3.0' }
}
},
'zone.js': {
packageDir: `${zoneJsDir}/zone.js`,
packageJsonPath: `${zoneJsDir}/zone.js/package.json`,
@ -124,6 +132,7 @@ describe('NgPackagesInstaller', () => {
},
devDependencies: {
'@angular/compiler-cli': '4.4.1',
'angular-in-memory-web-api': '^0.11.0',
'rxjs-dev': '^6.3.0'
}
};
@ -149,6 +158,7 @@ describe('NgPackagesInstaller', () => {
},
devDependencies: {
'@angular/compiler-cli': `file:${toolsDir}/compiler-cli`,
'angular-in-memory-web-api': `file:${aimwaDir}/angular-in-memory-web-api`,
'rxjs-dev': '^6.3.0',
'some-package': '5.0.1',
typescript: '^2.4.2'
@ -200,10 +210,10 @@ describe('NgPackagesInstaller', () => {
const stringifyConfig = config => JSON.stringify(config, null, 2);
const allArgs = fs.writeFileSync.calls.allArgs();
const firstSixArgs = allArgs.slice(0, 6);
const lastSixArgs = allArgs.slice(-6);
const firstSevenArgs = allArgs.slice(0, 7);
const lastSevenArgs = allArgs.slice(-7);
expect(firstSixArgs).toEqual([
expect(firstSevenArgs).toEqual([
[
pkgJsonPathFor('@angular/core'),
stringifyConfig(overwriteConfigFor('@angular/core', {private: true})),
@ -230,18 +240,23 @@ describe('NgPackagesInstaller', () => {
devDependencies: { '@angular/common': `file:${packagesDir}/common` },
})),
],
[
pkgJsonPathFor('angular-in-memory-web-api'),
stringifyConfig(overwriteConfigFor('angular-in-memory-web-api', {private: true})),
],
[
pkgJsonPathFor('zone.js'),
stringifyConfig(overwriteConfigFor('zone.js', {private: true})),
],
]);
expect(lastSixArgs).toEqual([
expect(lastSevenArgs).toEqual([
'@angular/core',
'@angular/common',
'@angular/compiler',
'@angular/compiler-cli',
'@angular/tsc-wrapped',
'angular-in-memory-web-api',
'zone.js',
].map(pkgName => [pkgJsonPathFor(pkgName), stringifyConfig(pkgConfigFor(pkgName))]));
});

View File

@ -21,6 +21,11 @@ module.exports = {
* Build the `angular-in-memory-web-api` npm package and copy it to `destDir` for other
* scripts/tests to use.
*
* NOTE: The `angular-in-memory-web-api` 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).
*
* @param {string} destDir Path to the output directory into which we copy the npm package.
* This path should either be absolute or relative to the project root.
*/

View File

@ -17,14 +17,15 @@ const {buildZoneJsPackage} = require('./zone-js-builder');
// Build the ivy packages into `dist/packages-dist-ivy-aot/`.
buildTargetPackages('dist/packages-dist-ivy-aot', true, 'Ivy AOT');
// Build the `angular-in-memory-web-api` npm package into `dist/packages-dist-ivy-aot/misc/`,
// because it might be needed by other scripts/targets.
// Build the `angular-in-memory-web-api` npm package into
// `dist/angular-in-memory-web-api-dist-ivy-aot/`, because it might be needed by other
// scripts/targets.
//
// NOTE:
// The `-ivy-aot` suffix is only used to differentiate from the packages built by the
// `build-packages-dist.js` script, so that there is no conflict when persisting them to the
// workspace on CI.
buildAngularInMemoryWebApiPackage('dist/packages-dist-ivy-aot/misc');
buildAngularInMemoryWebApiPackage('dist/angular-in-memory-web-api-dist-ivy-aot');
// Build the `zone.js` npm package into `dist/zone.js-dist-ivy-aot/`, because it might be needed by
// other scripts/tests.

View File

@ -21,9 +21,9 @@ buildTargetPackages('dist/packages-dist', false, 'Production');
// Build the `angular-dev-infra` npm package into `dist/packages-dist/`.
buildDevInfraPackage('dist/packages-dist');
// Build the `angular-in-memory-web-api` npm package into `dist/packages-dist/misc/`, because it
// might be needed by other scripts/targets.
buildAngularInMemoryWebApiPackage('dist/packages-dist/misc');
// Build the `angular-in-memory-web-api` npm package into `dist/angular-in-memory-web-api-dist/`,
// because it might be needed by other scripts/targets.
buildAngularInMemoryWebApiPackage('dist/angular-in-memory-web-api-dist');
// Build the `zone.js` npm package into `dist/zone.js-dist/`, because it might be needed by other
// scripts/tests.