1414 * Read more here: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions
1515 */
1616
17+ /**
18+ * Array defining the packages we would like to install snapshots for.
19+ *
20+ * Additionally each entry will have a mapping to the corresponding snapshot
21+ * builds repo name. This is necessary as the repository names are inconsistent.
22+ */
23+ const snapshotPackages = [
24+ { matcher : / ^ @ a n g u l a r \/ ( .+ ) $ / , repoName : `angular/$1-builds` } ,
25+ { matcher : / ^ @ a n g u l a r - d e v k i t \/ ( .+ ) $ / , repoName : `angular/angular-devkit-$1-builds` } ,
26+ { matcher : / ^ @ s c h e m a t i c s \/ ( .+ ) $ / , repoName : `angular/schematics-$1-builds` } ,
27+ ] ;
28+
1729/** List of packages which should not be updated to a snapshot build. */
1830const ignorePackages = [
1931 // Skip update for the shared dev-infra package. We do not want to update to a snapshot
@@ -35,33 +47,45 @@ const packageSuffix = tag ? ` (${tag})` : '';
3547// See: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions for the API.
3648packageJson [ 'resolutions' ] = packageJson [ 'resolutions' ] || { } ;
3749
38- // List of packages which should be updated to their most recent snapshot version, or
39- // snapshot version based on the specified tag.
40- const snapshotPackages = Object . keys ( {
50+ const packagesToConsider = Object . keys ( {
4151 ...packageJson . dependencies ,
4252 ...packageJson . devDependencies ,
43- } ) . filter (
44- packageName => packageName . startsWith ( '@angular/' ) && ! ignorePackages . includes ( packageName ) ,
45- ) ;
53+ } ) ;
54+
55+ // List of packages which should be updated to their most recent snapshot version, or
56+ // snapshot version based on the specified tag.
57+ const packagesToUpdate = packagesToConsider . reduce ( ( result , name ) => {
58+ if ( ignorePackages . includes ( name ) ) {
59+ return result ;
60+ }
61+
62+ const matchedEntry = snapshotPackages . find ( p => p . matcher . test ( name ) ) ;
63+ if ( matchedEntry === undefined ) {
64+ return result ;
65+ }
66+ const repoName = name . replace ( matchedEntry . matcher , matchedEntry . repoName ) ;
67+
68+ return result . concat ( [ { name, repoName} ] ) ;
69+ } , [ ] ) ;
4670
4771console . log ( 'Setting up snapshot builds for:\n' ) ;
48- console . log ( ` ${ snapshotPackages . map ( n => `${ n } ${ packageSuffix } ` ) . join ( '\n ' ) } \n` ) ;
72+ console . log ( ` ${ packagesToUpdate . map ( p => `${ p . name } ${ packageSuffix } ` ) . join ( '\n ' ) } \n` ) ;
4973
5074// Setup the snapshot version for each Angular package specified in the "package.json" file.
51- snapshotPackages . forEach ( packageName => {
52- const buildsUrl = `github:angular/${ packageName . split ( '/' ) [ 1 ] } -builds ${ tag ? `#${ tag } ` : '' } ` ;
75+ packagesToUpdate . forEach ( ( { name , repoName } ) => {
76+ const buildsUrl = `github:angular/${ repoName } ${ tag ? `#${ tag } ` : '' } ` ;
5377
5478 // Add resolutions for each package in the format "**/{PACKAGE}" so that all
5579 // nested versions of that specific Angular package will have the same version.
56- packageJson . resolutions [ `**/${ packageName } ` ] = buildsUrl ;
80+ packageJson . resolutions [ `**/${ name } ` ] = buildsUrl ;
5781
5882 // Since the resolutions only cover the version of all nested installs, we also need
5983 // to explicitly set the version for the package listed in the project "package.json".
60- packageJson . dependencies [ packageName ] = buildsUrl ;
84+ packageJson . dependencies [ name ] = buildsUrl ;
6185
6286 // In case this dependency was previously a dev dependency, just remove it because we
6387 // re-added it as a normal dependency for simplicity.
64- delete packageJson . devDependencies [ packageName ] ;
88+ delete packageJson . devDependencies [ name ] ;
6589} ) ;
6690
6791// Write changes to the "packageJson", so that we can install the new versions afterwards.
0 commit comments