14
14
* Read more here: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions
15
15
*/
16
16
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
+
17
29
/** List of packages which should not be updated to a snapshot build. */
18
30
const ignorePackages = [
19
31
// 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})` : '';
35
47
// See: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions for the API.
36
48
packageJson [ 'resolutions' ] = packageJson [ 'resolutions' ] || { } ;
37
49
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 ( {
41
51
...packageJson . dependencies ,
42
52
...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
+ } , [ ] ) ;
46
70
47
71
console . 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` ) ;
49
73
50
74
// 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 } ` : '' } ` ;
53
77
54
78
// Add resolutions for each package in the format "**/{PACKAGE}" so that all
55
79
// nested versions of that specific Angular package will have the same version.
56
- packageJson . resolutions [ `**/${ packageName } ` ] = buildsUrl ;
80
+ packageJson . resolutions [ `**/${ name } ` ] = buildsUrl ;
57
81
58
82
// Since the resolutions only cover the version of all nested installs, we also need
59
83
// to explicitly set the version for the package listed in the project "package.json".
60
- packageJson . dependencies [ packageName ] = buildsUrl ;
84
+ packageJson . dependencies [ name ] = buildsUrl ;
61
85
62
86
// In case this dependency was previously a dev dependency, just remove it because we
63
87
// re-added it as a normal dependency for simplicity.
64
- delete packageJson . devDependencies [ packageName ] ;
88
+ delete packageJson . devDependencies [ name ] ;
65
89
} ) ;
66
90
67
91
// Write changes to the "packageJson", so that we can install the new versions afterwards.
0 commit comments