/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
scripts/build-packages-dist.mts
137 строк
5 KB
Joey Perrott
build: update to bazel version 8.4.2 (#32490)
08 дек 2025, 21:10
Не верифицирован
08 дек 2025, 21:10
fa73b35
Код
Авторство
О чём код?
/** * 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 {execSync} from 'child_process'; import {join, dirname} from 'path'; import {BuiltPackage} from '@angular/ng-dev'; import {fileURLToPath} from 'url'; import sh from 'shelljs'; // ShellJS should exit if a command fails. sh.set('-e'); /** 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'] || `pnpm -s bazel`; /** Command that queries Bazel for all release package targets. */ const queryPackagesCmd = `${bazelCmd} query --output=label "filter(':npm_package$', ` + `attr('tags', '\\[.*${releaseTargetTag}.*\\]', //src/...))"`; /** 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. "src/cdk:npm_package", or "src/material:npm_package". const targets = exec(queryPackagesCmd, true).split(/\r?\n/); const packageNames = getPackageNamesOfTargets(targets); // TODO: Remove --ignore_all_rc_files flag once a repository can be loaded in bazelrc during info // commands again. See https://github.com/bazelbuild/bazel/issues/25145 for more context. const bazelBinPath = exec(`${bazelCmd} --ignore_all_rc_files info bazel-bin`, true); const getBazelOutputPath = (pkgName: string) => join(bazelBinPath, 'src', pkgName, 'npm_package'); const getDistPath = (pkgName: string) => join(distPath, pkgName); // Build with "--config=release" or `--config=snapshot-build` 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-build' : 'release'}`; exec(`${bazelCmd} build ${stampConfigArg} ${targets.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. sh.rm('-rf', distPath); sh.mkdir('-p', distPath); // Copy the package output into the specified distribution folder. packageNames.forEach(pkgName => { const outputPath = getBazelOutputPath(pkgName); const targetFolder = getDistPath(pkgName); console.log(`> Copying package output to "${targetFolder}"`); sh.cp('-R', outputPath, targetFolder); sh.chmod('-R', 'u+w', targetFolder); }); return packageNames.map(pkg => { return { name: `@angular/${pkg}`, outputPath: getDistPath(pkg), }; }); } /** * Gets the package names of the specified Bazel targets. * e.g. //src/material:npm_package = material */ function getPackageNamesOfTargets(targets: string[]): string[] { const seen = new Set<string>(); for (const targetName of targets) { const match = targetName.match(/\/\/src\/(.*):npm_package/)?.[1]; if (!match) { throw new Error( `Found Bazel target with "${releaseTargetTag}" tag, but could not ` + `determine release output name: ${targetName}`, ); } if (seen.has(match)) { throw new Error( `Detected duplicate package "${match}". The duplication can cause issues when publishing ` + `to npm and needs to be resolved.`, ); } seen.add(match); } return Array.from(seen); } /** 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(); } }