1
1
import * as OctokitApi from '@octokit/rest' ;
2
2
import chalk from 'chalk' ;
3
- import { readFileSync , writeFileSync } from 'fs' ;
3
+ import { existsSync , readFileSync , writeFileSync } from 'fs' ;
4
4
import { join } from 'path' ;
5
5
import { BaseReleaseTask } from './base-release-task' ;
6
6
import { promptAndGenerateChangelog } from './changelog' ;
@@ -12,6 +12,9 @@ import {parseVersionName, Version} from './version-name/parse-version';
12
12
/** Default filename for the changelog. */
13
13
export const CHANGELOG_FILE_NAME = 'CHANGELOG.md' ;
14
14
15
+ /** Path to the Bazel file that configures the release output. */
16
+ const BAZEL_RELEASE_CONFIG_PATH = './packages.bzl' ;
17
+
15
18
/**
16
19
* Class that can be instantiated in order to stage a new release. The tasks requires user
17
20
* interaction/input through command line prompts.
@@ -89,6 +92,7 @@ class StageReleaseTask extends BaseReleaseTask {
89
92
const publishBranch = this . switchToPublishBranch ( newVersion ) ;
90
93
91
94
this . verifyLocalCommitsMatchUpstream ( publishBranch ) ;
95
+ this . _verifyAngularPeerDependencyVersion ( newVersion ) ;
92
96
await this . _verifyPassingGithubStatus ( publishBranch ) ;
93
97
94
98
if ( ! this . git . checkoutNewBranch ( stagingBranch ) ) {
@@ -147,6 +151,52 @@ class StageReleaseTask extends BaseReleaseTask {
147
151
writeFileSync ( this . packageJsonPath , JSON . stringify ( newPackageJson , null , 2 ) + '\n' ) ;
148
152
}
149
153
154
+ /**
155
+ * Ensures that the Angular version placeholder has been correctly updated to support
156
+ * given Angular versions. The following rules apply:
157
+ * `N.x.x` requires Angular `^N.0.0 || (N+1).0.0-0`
158
+ * `N.0.0-x` requires Angular `^N.0.0-0 || (N+1).0.0-0`
159
+ */
160
+ private _verifyAngularPeerDependencyVersion ( newVersion : Version ) {
161
+ const currentVersionRange = this . _getAngularVersionPlaceholderOrExit ( ) ;
162
+ const isMajorWithPrerelease = newVersion . minor === 0 && newVersion . patch === 0 &&
163
+ newVersion . prereleaseLabel !== null ;
164
+ const requiredRange = isMajorWithPrerelease ?
165
+ `^${ newVersion . major } .0.0-0 || ^${ newVersion . major + 1 } .0.0-0` :
166
+ `^${ newVersion . major } .0.0 || ^${ newVersion . major + 1 } .0.0-0` ;
167
+
168
+ if ( requiredRange !== currentVersionRange ) {
169
+ console . error ( chalk . red ( ` ✘ Cannot stage release. The required Angular version range ` +
170
+ `is invalid. The version range should be: ${ requiredRange } ` ) ) ;
171
+ console . error ( chalk . red ( ` Please manually update the version range ` +
172
+ `in: ${ BAZEL_RELEASE_CONFIG_PATH } ` ) ) ;
173
+ return process . exit ( 1 ) ;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Gets the Angular version placeholder from the bazel release config. If
179
+ * the placeholder could not be found, the process will be terminated.
180
+ */
181
+ private _getAngularVersionPlaceholderOrExit ( ) : string {
182
+ const bzlConfigPath = join ( this . projectDir , BAZEL_RELEASE_CONFIG_PATH ) ;
183
+ if ( ! existsSync ( bzlConfigPath ) ) {
184
+ console . error ( chalk . red ( ` ✘ Cannot stage release. Could not find the file which sets ` +
185
+ `the Angular peerDependency placeholder value. Looked for: ${ bzlConfigPath } ` ) ) ;
186
+ return process . exit ( 1 ) ;
187
+ }
188
+
189
+ const configFileContent = readFileSync ( bzlConfigPath , 'utf8' ) ;
190
+ const matches = configFileContent . match ( / A N G U L A R _ P A C K A G E _ V E R S I O N = [ " ' ] ( [ ^ " ' ] + ) / ) ;
191
+ if ( ! matches || ! matches [ 1 ] ) {
192
+ console . error ( chalk . red ( ` ✘ Cannot stage release. Could not find the ` +
193
+ `"ANGULAR_PACKAGE_VERSION" variable. Please ensure this variable exists. ` +
194
+ `Looked in: ${ bzlConfigPath } ` ) ) ;
195
+ return process . exit ( 1 ) ;
196
+ }
197
+ return matches [ 1 ] ;
198
+ }
199
+
150
200
/** Verifies that the latest commit of the current branch is passing all Github statuses. */
151
201
private async _verifyPassingGithubStatus ( expectedPublishBranch : string ) {
152
202
const commitRef = this . git . getLocalCommitSha ( 'HEAD' ) ;
0 commit comments