Skip to content

Commit 6afe888

Browse files
authored
build: adjust peer dependency to include all minor pre-releases (#26421)
Pre-release versions of Angular Material should be compatible with the same pre-release versions of FW (being worked on at the same time). Additionally we want to expand the peer dependency so that the pre-release Material version is also compatible future pre-release of framework. e.g. consider the scenario where Angular framework already released `15.2.0-next.0`, while both CLI and COMP are still on `15.1.0-next.0`. CLI in this case want to depend on the latest versions, but with the recent stricter NPM version this would break as Material wouldn't allow `v15.2.0-next.0` We switch to a more simpler model that requires less changes by the caretaker. For `@next` releases we will be more flexible and allow for all pre-releases of the current major and (N+1)-next/rc Also we no longer require the peer dep to be updated manually. This simplifies the caretaker experience as the peer dependency would no longer need to be updated manually every time the release version changes.
1 parent 769e204 commit 6afe888

File tree

8 files changed

+68
-90
lines changed

8 files changed

+68
-90
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ test --test_output=errors
4545

4646
# Configures script to do version stamping.
4747
# See https://docs.bazel.build/versions/master/user-manual.html#flag--workspace_status_command
48-
build:release --workspace_status_command="yarn -s ng-dev release build-env-stamp --mode=release"
48+
build:release --workspace_status_command="yarn -s ng-dev:stamp --mode=release"
4949
build:release --stamp
5050

51-
build:snapshot-build --workspace_status_command="yarn -s ng-dev release build-env-stamp --mode=snapshot"
51+
build:snapshot-build --workspace_status_command="yarn -s ng-dev:stamp --mode=snapshot"
5252
build:snapshot-build --stamp
5353

5454
####################################

.ng-dev/release.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import semver from 'semver';
22
import {ReleaseConfig} from '@angular/ng-dev';
3-
import {assertValidFrameworkPeerDependency} from '../tools/release-checks/check-framework-peer-dependency.mjs';
43
import {assertValidUpdateMigrationCollections} from '../tools/release-checks/check-migration-collections.mjs';
54
import {assertValidNpmPackageOutput} from '../tools/release-checks/npm-package-output/index.mjs';
65

@@ -52,7 +51,6 @@ export const release: ReleaseConfig = {
5251
prereleaseCheck: async (newVersionStr, builtPackagesWithInfo) => {
5352
const newVersion = new semver.SemVer(newVersionStr);
5453

55-
await assertValidFrameworkPeerDependency(newVersion);
5654
await assertValidUpdateMigrationCollections(newVersion);
5755
await assertValidNpmPackageOutput(builtPackagesWithInfo, newVersion);
5856
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"scripts": {
1717
"postinstall": "node tools/postinstall/apply-patches.js",
1818
"ng-dev": "cross-env TS_NODE_PROJECT=$PWD/.ng-dev/tsconfig.json TS_NODE_TRANSPILE_ONLY=1 node --no-warnings --loader ts-node/esm node_modules/@angular/ng-dev/bundles/cli.mjs",
19+
"ng-dev:stamp": "yarn -s ng-dev release build-env-stamp --additional-stamping-script=tools/bazel-additional-stamp.mjs",
1920
"build": "ts-node --esm --project scripts/tsconfig.json ./scripts/build-packages-dist-main.mts",
2021
"build-docs-content": "ts-node --esm --project scripts/tsconfig.json ./scripts/build-docs-content-main.mts",
2122
"build-and-check-release-output": "ts-node --esm --project scripts/tsconfig.json scripts/build-and-check-release-output.mts",
@@ -77,7 +78,7 @@
7778
"@angular/cli": "^15.1.0-rc.0",
7879
"@angular/compiler-cli": "^15.1.0-rc.0",
7980
"@angular/localize": "^15.1.0-rc.0",
80-
"@angular/ng-dev": "https://github.com/angular/dev-infra-private-ng-dev-builds.git#20d1bd232100d278c53820226427039f51881d3f",
81+
"@angular/ng-dev": "https://github.com/angular/dev-infra-private-ng-dev-builds.git#757a386a63e960c4006efd26482f0d52dd0a1604",
8182
"@angular/platform-browser-dynamic": "^15.1.0-rc.0",
8283
"@angular/platform-server": "^15.1.0-rc.0",
8384
"@angular/router": "^15.1.0-rc.0",

packages.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Each individual package uses a placeholder for the version of Angular to ensure they're
22
# all in-sync. This map is passed to each ng_package rule to stamp out the appropriate
33
# version for the placeholders.
4-
ANGULAR_PACKAGE_VERSION = "^15.0.0 || ^16.0.0"
54
MDC_PACKAGE_VERSION = "15.0.0-canary.fd95ca7ef.0"
65
TSLIB_PACKAGE_VERSION = "^2.3.0"
76
RXJS_PACKAGE_VERSION = "^6.5.3 || ^7.4.0"
@@ -12,8 +11,8 @@ RXJS_PACKAGE_VERSION = "^6.5.3 || ^7.4.0"
1211
NPM_PACKAGE_SUBSTITUTIONS = {
1312
# Version of `material-components-web`
1413
"0.0.0-MDC": MDC_PACKAGE_VERSION,
15-
# Version of `@angular/core`
16-
"0.0.0-NG": ANGULAR_PACKAGE_VERSION,
14+
# Peer dependency version on the Angular framework.
15+
"0.0.0-NG": "{STABLE_FRAMEWORK_PEER_DEP_RANGE}",
1716
# Version of `tslib`
1817
"0.0.0-TSLIB": TSLIB_PACKAGE_VERSION,
1918
# Version of the local package being built, generated via the `--workspace_status_command` flag.
@@ -26,6 +25,7 @@ NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS = dict(NPM_PACKAGE_SUBSTITUTIONS, **{
2625
# When building NPM packages for tests (where stamping is disabled),
2726
# we use `0.0.0` for the version placeholder.
2827
"0.0.0-PLACEHOLDER": "0.0.0",
28+
"0.0.0-NG": ">=0.0.0",
2929
})
3030

3131
# List of MDC packages (used for package externals and for Sass target deps)

scripts/docs-deploy/deploy-ci-push.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {
44
ActiveReleaseTrains,
55
getBranchesForMajorVersions,
6-
getVersionForVersionBranch,
6+
convertVersionBranchToSemVer,
77
isVersionBranch,
88
} from '@angular/ng-dev';
99
import {firebaseConfig, sites} from './utils.mjs';
@@ -90,7 +90,7 @@ async function main() {
9090
return;
9191
}
9292

93-
const branchVersion = getVersionForVersionBranch(branchName)!;
93+
const branchVersion = convertVersionBranchToSemVer(branchName)!;
9494
const branchMajor = branchVersion.major;
9595
const branchesForMajor = await getBranchesForMajorVersions(repo, [branchMajor]);
9696

tools/bazel-additional-stamp.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import fs from 'fs';
10+
import path from 'path';
11+
import url from 'url';
12+
import semver from 'semver';
13+
14+
/** Custom stamping on top of the default `ng-dev` release stamping. */
15+
export default async function (mode) {
16+
const scriptDir = path.dirname(url.fileURLToPath(import.meta.url));
17+
const projectDir = path.join(scriptDir, '../');
18+
const packageJsonRaw = await fs.promises.readFile(path.join(projectDir, 'package.json'));
19+
const {version: versionRaw} = JSON.parse(packageJsonRaw);
20+
const version = semver.parse(versionRaw);
21+
22+
console.info(`STABLE_FRAMEWORK_PEER_DEP_RANGE ${computeFrameworkPeerDependency(version)}`);
23+
}
24+
25+
/**
26+
* Computes the Angular peer dependency range. The following rules apply:
27+
*
28+
* `N.x.x` requires Angular `^N.0.0 || ^(N+1).0.0`
29+
* `N.x.x-x` requires Angular `^N.0.0-0 || ^N.1.0-0 || ^N.2.0-0 || ^N.3.0-0 || ^(N+1).0.0-0`
30+
*
31+
* The rationale is that we want to satisfy peer dependencies if we are publishing
32+
* pre-releases for a major while Angular framework cuts pre-releases as well. e.g.
33+
* Angular CDK v14.0.0-rc.1 should also work with `@angular/core@v14.0.0-rc.1`.
34+
*
35+
* Note: When we cut pre-releases, the peer dependency includes all anticipated
36+
* pre-releases because a range like `^15.0.0-0` itself would not allow for future minor
37+
* releases like `15.1.0-next.0`. NPM requires the explicit minors pre-release ranges.
38+
*
39+
* @param {semver.SemVer} version Current project version.
40+
* @returns {string} The NPM peer dependency for depending on framework.
41+
*/
42+
function computeFrameworkPeerDependency(version) {
43+
if (version.prerelease[0] !== undefined) {
44+
return (
45+
`^${version.major}.0.0-0 || ` +
46+
`^${version.major}.1.0-0 || ` +
47+
`^${version.major}.2.0-0 || ` +
48+
`^${version.major}.3.0-0 || ` +
49+
`^${version.major + 1}.0.0-0`
50+
);
51+
}
52+
53+
return `^${version.major}.0.0 || ^${version.major + 1}.0.0`;
54+
}

tools/release-checks/check-framework-peer-dependency.mts

Lines changed: 0 additions & 75 deletions
This file was deleted.

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,12 @@
373373
glob "8.0.3"
374374
yargs "^17.2.1"
375375

376-
"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#20d1bd232100d278c53820226427039f51881d3f":
377-
version "0.0.0-0a49ed85541ecbb28a0e19eefce7a874c1eaab5e"
378-
resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#20d1bd232100d278c53820226427039f51881d3f"
376+
"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#757a386a63e960c4006efd26482f0d52dd0a1604":
377+
version "0.0.0-668a07a6f07d0a75f530728f77da8e3c78f0374a"
378+
resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#757a386a63e960c4006efd26482f0d52dd0a1604"
379379
dependencies:
380380
"@yarnpkg/lockfile" "^1.1.0"
381-
typescript "~4.8.0"
381+
typescript "~4.9.0"
382382

383383
"@angular/platform-browser-dynamic@^15.1.0-rc.0":
384384
version "15.1.0-rc.0"
@@ -15565,7 +15565,7 @@ typescript@^3.9.10, typescript@^3.9.5, typescript@^3.9.7:
1556515565
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8"
1556615566
integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==
1556715567

15568-
typescript@~4.5.4, typescript@~4.8.0, typescript@~4.9.3:
15568+
typescript@~4.5.4, typescript@~4.8.0, typescript@~4.9.0, typescript@~4.9.3:
1556915569
version "4.9.4"
1557015570
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78"
1557115571
integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==

0 commit comments

Comments
 (0)