2020-02-29 20:25:49 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2020-02-29 20:25:49 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2020-02-29 20:25:49 +00:00
|
|
|
*/
|
|
|
|
|
|
2022-06-22 16:13:15 +00:00
|
|
|
import {join} from 'path';
|
|
|
|
|
import sh from 'shelljs';
|
2020-02-29 20:25:49 +00:00
|
|
|
|
2022-06-22 16:13:15 +00:00
|
|
|
import {projectDir, bazelCmd, exec} from './package-builder.mjs';
|
2020-02-29 20:25:49 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the `zone.js` npm package into `dist/bin/packages/zone.js/npm_package/` and copy it to
|
2021-04-05 16:05:54 +00:00
|
|
|
* `destDir` for other scripts/tests to use.
|
2020-02-29 20:25:49 +00:00
|
|
|
*
|
|
|
|
|
* 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).
|
2020-02-29 19:05:23 +00:00
|
|
|
*
|
2021-04-05 16:05:54 +00:00
|
|
|
* @param {string} destDir Path to the output directory into which we copy the npm package.
|
2020-02-29 19:05:23 +00:00
|
|
|
* This path should either be absolute or relative to the project root.
|
2020-02-29 20:25:49 +00:00
|
|
|
*/
|
2022-06-22 16:13:15 +00:00
|
|
|
export function buildZoneJsPackage(destDir: string): void {
|
2020-02-29 20:25:49 +00:00
|
|
|
console.info('##############################');
|
|
|
|
|
console.info(' Building zone.js npm package');
|
|
|
|
|
console.info('##############################');
|
2022-06-22 16:13:15 +00:00
|
|
|
|
2021-01-27 17:09:36 +00:00
|
|
|
exec(`${bazelCmd} run //packages/zone.js:npm_package.pack`);
|
2020-02-29 20:25:49 +00:00
|
|
|
|
2020-02-29 19:05:23 +00:00
|
|
|
// Create the output directory.
|
2022-06-22 16:13:15 +00:00
|
|
|
if (!sh.test('-d', destDir)) {
|
|
|
|
|
sh.mkdir('-p', destDir);
|
2021-04-05 16:05:54 +00:00
|
|
|
}
|
2020-02-29 19:05:23 +00:00
|
|
|
|
2022-06-22 16:13:15 +00:00
|
|
|
const bazelBinPath = exec(`${bazelCmd} info bazel-bin`, true);
|
|
|
|
|
|
2021-04-05 16:05:54 +00:00
|
|
|
// Copy artifacts to `destDir`, so they can be easier persisted on CI and used by non-bazel
|
2020-02-29 19:05:23 +00:00
|
|
|
// scripts/tests.
|
2022-06-22 16:13:15 +00:00
|
|
|
const buildOutputDir = join(bazelBinPath, 'packages/zone.js/npm_package');
|
|
|
|
|
const distTargetDir = join(destDir, 'zone.js');
|
2020-02-29 20:25:49 +00:00
|
|
|
|
2020-08-31 04:48:41 +00:00
|
|
|
console.info(`# Copy npm_package artifacts to ${distTargetDir}`);
|
2022-06-22 16:13:15 +00:00
|
|
|
|
|
|
|
|
sh.rm('-rf', distTargetDir);
|
|
|
|
|
sh.cp('-R', buildOutputDir, distTargetDir);
|
|
|
|
|
sh.chmod('-R', 'u+w', distTargetDir);
|
2020-02-29 20:25:49 +00:00
|
|
|
|
2021-04-05 16:05:54 +00:00
|
|
|
// Copy `zone.js.tgz` to `destDir`, so we can test
|
2020-08-31 04:48:41 +00:00
|
|
|
// the archive generated by the `npm_package.pack` rule.
|
2022-06-22 16:13:15 +00:00
|
|
|
const distArchiveTargetDir = `${destDir}/archive`;
|
2020-08-31 04:48:41 +00:00
|
|
|
console.info(`# Copy npm_package archive file to ${distArchiveTargetDir}`);
|
2022-06-22 16:13:15 +00:00
|
|
|
sh.rm('-rf', distArchiveTargetDir);
|
|
|
|
|
sh.mkdir('-p', distArchiveTargetDir);
|
|
|
|
|
sh.mv(`${projectDir}/zone.js-*.tgz`, `${distArchiveTargetDir}/zone.js.tgz`);
|
2020-02-29 20:25:49 +00:00
|
|
|
}
|