Skip to content

Commit 280a233

Browse files
authored
build: release script producing duplicate results (angular#30999)
The release script decides which packages to publish by looking for targets with the `release-package` tag, however with the latest infra changes there are actually two targets per package: `npm_package` and `npm_package_files`. This resulted in the release script trying to publish to npm twice which in turn cause an error since versions can't be published over. These changes resolve the issue by: 1. Adjusting the query so it only returns the `npm_package` target. 2. Adding validation that we don't resolve the same package twice.
1 parent 2c078ac commit 280a233

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

scripts/build-packages-dist.mts

+21-8
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const bazelCmd = process.env['BAZEL'] || `pnpm -s bazel`;
2424

2525
/** Command that queries Bazel for all release package targets. */
2626
const queryPackagesCmd =
27-
`${bazelCmd} query --output=label "attr('tags', '\\[.*${releaseTargetTag}.*\\]', //src/...) ` +
28-
`intersect kind('.*_package', //src/...)"`;
27+
`${bazelCmd} query --output=label "filter(':npm_package$', ` +
28+
`attr('tags', '\\[.*${releaseTargetTag}.*\\]', //src/...))"`;
2929

3030
/** Path for the default distribution output directory. */
3131
const defaultDistPath = join(projectDir, 'dist/releases');
@@ -93,16 +93,29 @@ function buildReleasePackages(distPath: string, isSnapshotBuild: boolean): Built
9393
* e.g. //src/material:npm_package = material
9494
*/
9595
function getPackageNamesOfTargets(targets: string[]): string[] {
96-
return targets.map(targetName => {
97-
const matches = targetName.match(/\/\/src\/(.*):npm_package/);
98-
if (matches === null) {
99-
throw Error(
96+
const seen = new Set<string>();
97+
98+
for (const targetName of targets) {
99+
const match = targetName.match(/\/\/src\/(.*):npm_package/)?.[1];
100+
101+
if (!match) {
102+
throw new Error(
100103
`Found Bazel target with "${releaseTargetTag}" tag, but could not ` +
101104
`determine release output name: ${targetName}`,
102105
);
103106
}
104-
return matches[1];
105-
});
107+
108+
if (seen.has(match)) {
109+
throw new Error(
110+
`Detected duplicate package "${match}". The duplication can cause issues when publishing ` +
111+
`to npm and needs to be resolved.`,
112+
);
113+
}
114+
115+
seen.add(match);
116+
}
117+
118+
return Array.from(seen);
106119
}
107120

108121
/** Executes the given command in the project directory. */

0 commit comments

Comments
 (0)