Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .circleci/dynamic_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ jobs:

publish_artifacts:
executor: action-executor
resource_class: medium
environment:
steps:
- custom_attach_workspace
Expand All @@ -342,7 +343,7 @@ jobs:
name: Copy tarballs to folder
command: |
mkdir -p dist/artifacts/
cp dist/*.tgz dist/artifacts/
cp dist/releases/*.tgz dist/artifacts/
- store_artifacts:
path: dist/artifacts/
destination: angular
Expand Down
10 changes: 6 additions & 4 deletions .ng-dev/release.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import '../lib/bootstrap-local.js';

import { ReleaseConfig } from '@angular/ng-dev';
import packages from '../lib/packages.js';
import buildPackages from '../scripts/build.js';

const npmPackages = Object.entries(packages.releasePackages).map(([name, { experimental }]) => ({
name,
Expand All @@ -13,7 +10,12 @@ const npmPackages = Object.entries(packages.releasePackages).map(([name, { exper
export const release: ReleaseConfig = {
representativeNpmPackage: '@angular/cli',
npmPackages,
buildPackages: () => buildPackages.default(),
buildPackages: async () => {
// The `performNpmReleaseBuild` function is loaded at runtime to avoid loading additional
// files and dependencies unless a build is required.
const { performNpmReleaseBuild } = await import('../scripts/build-packages-dist.mjs');
return performNpmReleaseBuild();
},
releaseNotes: {
groupOrder: [
'@angular/cli',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"@types/progress": "^2.0.3",
"@types/resolve": "^1.17.1",
"@types/semver": "^7.3.12",
"@types/shelljs": "^0.8.11",
"@types/tar": "^6.1.2",
"@types/text-table": "^0.2.1",
"@types/yargs": "^17.0.8",
Expand Down
1 change: 1 addition & 0 deletions packages/angular/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pkg_npm(
"//packages/angular_devkit/schematics:package.json",
"//packages/schematics/angular:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":angular-cli",
Expand Down
1 change: 1 addition & 0 deletions packages/angular/create/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ genrule(

pkg_npm(
name = "npm_package",
tags = ["release-package"],
visibility = ["//visibility:public"],
deps = [
":README.md",
Expand Down
1 change: 1 addition & 0 deletions packages/angular/pwa/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pkg_npm(
"//packages/angular_devkit/schematics:package.json",
"//packages/schematics/angular:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":license",
Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/architect/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pkg_npm(
pkg_deps = [
"//packages/angular_devkit/core:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":architect",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/architect/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ ts_library(
"//packages/angular_devkit/architect",
"//packages/angular_devkit/core",
"//packages/angular_devkit/core/node",
"//tests/angular_devkit/architect/node/jobs:jobs_test_lib",
"@npm//@types/node",
"@npm//rxjs",
],
Expand All @@ -40,6 +39,7 @@ ts_library(
deps = [
":node",
"//packages/angular_devkit/architect",
"//tests/angular_devkit/architect/node/jobs:jobs_test_lib",
],
)

Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/architect_cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pkg_npm(
"//packages/angular_devkit/architect:package.json",
"//packages/angular_devkit/core:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":architect_cli",
Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/build_angular/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pkg_npm(
"//packages/angular_devkit/core:package.json",
"//packages/ngtools/webpack:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":build_angular",
Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/build_webpack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pkg_npm(
pkg_deps = [
"//packages/angular_devkit/architect:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":build_webpack",
Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ genrule(

pkg_npm(
name = "npm_package",
tags = ["release-package"],
deps = [
":README.md",
":core",
Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pkg_npm(
pkg_deps = [
"//packages/angular_devkit/core:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":collection-schema.json",
Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/schematics_cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pkg_npm(
"//packages/angular_devkit/schematics:package.json",
"//packages/angular_devkit/core:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":license",
Expand Down
1 change: 1 addition & 0 deletions packages/ngtools/webpack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ genrule(

pkg_npm(
name = "npm_package",
tags = ["release-package"],
deps = [
":README.md",
":license",
Expand Down
1 change: 1 addition & 0 deletions packages/schematics/angular/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pkg_npm(
"//packages/angular_devkit/schematics:package.json",
"//packages/angular_devkit/core:package.json",
],
tags = ["release-package"],
deps = [
":README.md",
":angular",
Expand Down
168 changes: 168 additions & 0 deletions scripts/build-packages-dist.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/**
* @license
* Copyright Google LLC 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
*/

/**
* Script that builds the release output of all packages which have the "release-package
* Bazel tag set. The script builds all those packages and copies the release output to the
* distribution folder within the project.
*/

import { BuiltPackage } from '@angular/ng-dev';
import { execSync } from 'node:child_process';
import { chmodSync, copyFileSync, mkdirSync, rmSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import sh from 'shelljs';

/** Name of the Bazel tag that will be used to find release package targets. */
const releaseTargetTag = 'release-package';

/** Path to the project directory. */
const projectDir = join(dirname(fileURLToPath(import.meta.url)), '../');

/** Command that runs Bazel. */
const bazelCmd = process.env.BAZEL || `yarn -s bazel`;

/** Command that queries Bazel for all release package targets. */
const queryPackagesCmd =
`${bazelCmd} query --output=label "attr('tags', '\\[.*${releaseTargetTag}.*\\]', //packages/...) ` +
`intersect kind('pkg_npm', //packages/...)"`;

/** Path for the default distribution output directory. */
const defaultDistPath = join(projectDir, 'dist/releases');

/** Builds the release packages for NPM. */
export function performNpmReleaseBuild(): BuiltPackage[] {
return buildReleasePackages(defaultDistPath, /* isSnapshotBuild */ false);
}

/**
* Builds the release packages as snapshot build. This means that the current
* Git HEAD SHA is included in the version (for easier debugging and back tracing).
*/
export function performDefaultSnapshotBuild(): BuiltPackage[] {
return buildReleasePackages(defaultDistPath, /* isSnapshotBuild */ true);
}

/**
* Builds the release packages with the given compile mode and copies
* the package output into the given directory.
*/
function buildReleasePackages(distPath: string, isSnapshotBuild: boolean): BuiltPackage[] {
console.log('######################################');
console.log(' Building release packages...');
console.log('######################################');

// List of targets to build. e.g. "packages/angular/cli:npm_package"
const targets = exec(queryPackagesCmd, true).split(/\r?\n/);
const packageNames = getPackageNamesOfTargets(targets);
const bazelBinPath = exec(`${bazelCmd} info bazel-bin`, true);
const getBazelOutputPath = (pkgName: string) =>
join(bazelBinPath, 'packages', pkgName, 'npm_package');
const getDistPath = (pkgName: string) => join(distPath, pkgName);

// Build with "--config=release" or `--config=snapshot` so that Bazel
// runs the workspace stamping script. The stamping script ensures that the
// version placeholder is populated in the release output.
const stampConfigArg = `--config=${isSnapshotBuild ? 'snapshot' : 'release'}`;

// Walk through each release package and clear previous "npm_package" outputs. This is
// a workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1219. We need to
// do this to ensure that the version placeholders are properly populated.
packageNames.forEach((pkgName) => {
// Directory output is created by the npm_package target
const directoryOutputPath = getBazelOutputPath(pkgName);
// Archive output is created by the npm_package_archive target
const archiveOutputPath = directoryOutputPath + '_archive.tgz';

if (sh.test('-d', directoryOutputPath)) {
sh.chmod('-R', 'u+w', directoryOutputPath);
sh.rm('-rf', directoryOutputPath);
}
try {
chmodSync(archiveOutputPath, '0755');
rmSync(archiveOutputPath, { force: true });
} catch {}
});

// Build both the npm_package and npm_package_archive targets for each package
// TODO: Consider switching to only using the archive for publishing
const buildTargets = targets.flatMap((target) => [target, target + '_archive']);
exec(`${bazelCmd} build ${stampConfigArg} ${buildTargets.join(' ')}`);

// Delete the distribution directory so that the output is guaranteed to be clean. Re-create
// the empty directory so that we can copy the release packages into it later.
rmSync(distPath, { force: true, recursive: true, maxRetries: 3 });
mkdirSync(distPath, { recursive: true });

// Copy the package output into the specified distribution folder.
packageNames.forEach((pkgName) => {
// Directory output is created by the npm_package target
const directoryOutputPath = getBazelOutputPath(pkgName);
// Archive output is created by the npm_package_archive target
const archiveOutputPath = directoryOutputPath + '_archive.tgz';

const targetFolder = getDistPath(pkgName);
console.log(`> Copying package output to "${targetFolder}"`);

// Ensure package scope directory exists prior to copying
mkdirSync(dirname(targetFolder), { recursive: true });

// Copy package contents to target directory
sh.cp('-R', directoryOutputPath, targetFolder);
sh.chmod('-R', 'u+w', targetFolder);

// Copy archive of package to target directory
const archiveTargetPath = join(distPath, `${pkgName.replace('/', '_')}.tgz`);
copyFileSync(archiveOutputPath, archiveTargetPath);
chmodSync(archiveTargetPath, '0755');
});

return packageNames.map((pkg) => {
return {
// Package names on disk do not have the @ scope prefix and use underscores instead of dashes
name: `@${pkg.replace(/_/g, '-')}`,
outputPath: getDistPath(pkg),
};
});
}

/**
* Gets the package names of the specified Bazel targets.
* e.g. //packages/angular/cli:npm_package = angular/cli
*/
function getPackageNamesOfTargets(targets: string[]): string[] {
return targets.map((targetName) => {
const matches = targetName.match(/\/\/packages\/(.*?):/);
if (matches === null) {
throw Error(
`Found Bazel target with "${releaseTargetTag}" tag, but could not ` +
`determine release output name: ${targetName}`,
);
}

return matches[1];
});
}

/** Executes the given command in the project directory. */
function exec(command: string): void;
/** Executes the given command in the project directory and returns its stdout. */
function exec(command: string, captureStdout: true): string;
function exec(command: string, captureStdout?: true) {
const stdout = execSync(command, {
cwd: projectDir,
stdio: ['inherit', captureStdout ? 'pipe' : 'inherit', 'inherit'],
});

if (captureStdout) {
process.stdout.write(stdout);

return stdout.toString().trim();
}
}
3 changes: 2 additions & 1 deletion tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"tests/**/*",
"tools/**/*",
".ng-dev/**/*",
"**/*_spec.ts"
"**/*_spec.ts",
"scripts/**/*.mts"
]
}
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@

"@angular/build-tooling@https://github.com/angular/dev-infra-private-build-tooling-builds.git#0940d31b019e41ca5283c1758d74fd648afd6a42":
version "0.0.0-f7d207b79899e466f312ae4fea2804f7978278ad"
uid "0940d31b019e41ca5283c1758d74fd648afd6a42"
resolved "https://github.com/angular/dev-infra-private-build-tooling-builds.git#0940d31b019e41ca5283c1758d74fd648afd6a42"
dependencies:
"@angular-devkit/build-angular" "15.1.0-next.3"
Expand Down Expand Up @@ -284,7 +283,6 @@

"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#9dccce65ac86e8bb222f600d978b713f8e19c2f8":
version "0.0.0-f7d207b79899e466f312ae4fea2804f7978278ad"
uid "9dccce65ac86e8bb222f600d978b713f8e19c2f8"
resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#9dccce65ac86e8bb222f600d978b713f8e19c2f8"
dependencies:
"@yarnpkg/lockfile" "^1.1.0"
Expand Down Expand Up @@ -3088,7 +3086,7 @@
"@types/qs" "*"
"@types/serve-static" "*"

"@types/glob@^8.0.0":
"@types/glob@*", "@types/glob@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-8.0.0.tgz#321607e9cbaec54f687a0792b2d1d370739455d2"
integrity sha512-l6NQsDDyQUVeoTynNpC9uRvCUint/gSUXQA2euwmTuWGvPY5LSDUu6tkCtJB2SvGQlJQzLaKqcGZP4//7EDveA==
Expand Down Expand Up @@ -3356,6 +3354,14 @@
"@types/mime" "*"
"@types/node" "*"

"@types/shelljs@^0.8.11":
version "0.8.11"
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.11.tgz#17a5696c825974e96828e96e89585d685646fcb8"
integrity sha512-x9yaMvEh5BEaZKeVQC4vp3l+QoFj3BXcd4aYfuKSzIIyihjdVARAadYy3SMNIz0WCCdS2vB9JL/U6GQk5PaxQw==
dependencies:
"@types/glob" "*"
"@types/node" "*"

"@types/sockjs@^0.3.33":
version "0.3.33"
resolved "https://registry.yarnpkg.com/@types/sockjs/-/sockjs-0.3.33.tgz#570d3a0b99ac995360e3136fd6045113b1bd236f"
Expand Down Expand Up @@ -10164,7 +10170,6 @@ sass@1.56.2, sass@^1.55.0:

"sauce-connect-proxy@https://saucelabs.com/downloads/sc-4.8.1-linux.tar.gz":
version "0.0.0"
uid "9c16682e4c9716734432789884f868212f95f563"
resolved "https://saucelabs.com/downloads/sc-4.8.1-linux.tar.gz#9c16682e4c9716734432789884f868212f95f563"

saucelabs@^1.5.0:
Expand Down