1
- /*
2
- * Script that re-installs all Angular dependencies using the GitHub build snapshots. We need to
3
- * do this after the locked node modules have been installed because otherwise `--frozen-lockfile`
4
- * would complain about outdated lock files.
1
+ /**
2
+ * Script that re-installs all Angular dependencies using the GitHub build snapshots.
3
+ * We need to do this after the locked node modules have been installed because
4
+ * otherwise "--frozen-lockfile" would complain about outdated lock files.
5
5
*/
6
6
7
7
const path = require ( 'path' ) ;
8
- const fs = require ( 'fs' ) ;
9
8
const execSync = require ( 'child_process' ) . execSync ;
10
9
const packageJsonPath = path . join ( __dirname , '../package.json' ) ;
11
- const packageJson = require ( packageJsonPath ) ;
10
+ const { dependencies , devDependencies } = require ( packageJsonPath ) ;
12
11
13
- /**
14
- * Updates all Angular dependencies for a given type by replacing the version with a Github URL
15
- * that refers to the corresponding Github builds repository.
16
- * @param dependencyType Either `dependencies` or `devDependencies`
17
- */
18
- function updateAngularDependencies ( dependencyType ) {
19
- Object . keys ( packageJson [ dependencyType ] )
20
- . filter ( depName => depName . startsWith ( '@angular/' ) )
21
- . forEach ( depName => {
22
- packageJson [ dependencyType ] [ depName ] = `github:angular/${ depName . split ( '/' ) [ 1 ] } -builds`
23
- } ) ;
24
- }
12
+ // List of snapshot package URLs that can be passed to Yarn in order to install the Angular
13
+ // snapshot builds from Github (e.g. github:angular/core-builds)
14
+ const snapshotPackageUrls = Object . keys ( { ...dependencies , ...devDependencies } )
15
+ . filter ( depName => depName . startsWith ( '@angular/' ) )
16
+ . map ( depName => `github:angular/${ depName . split ( '/' ) [ 1 ] } -builds` ) ;
25
17
26
- // Update `dependencies` and `devDependencies` in the "packageJson" object, so that
27
- // we can write the changes to disk afterwards. We cannot just run `yarn add ${all_deps}` because
28
- // Yarn will complain that some dependencies are already set up in the package.json file.
29
- updateAngularDependencies ( 'dependencies' ) ;
30
- updateAngularDependencies ( 'devDependencies' ) ;
31
-
32
- // Write the dependencies changes to the original "package.json" file.
33
- fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) ) ;
34
-
35
- // Run "yarn install" in order to install the packages that have been written to the package.json.
36
- execSync ( 'yarn install' , {
18
+ // Run "yarn add" in order to install the packages that have been written to the package.json.
19
+ // Note that we need to pass "--force" because Yarn will complain for packages that are
20
+ // already specified in the "package.json".
21
+ execSync ( `yarn add ${ snapshotPackageUrls . join ( ' ' ) } --force` , {
37
22
stdio : 'inherit' ,
38
23
shell : true ,
39
24
cwd : path . join ( __dirname , '../' )
40
25
} ) ;
41
26
42
- console . log ( 'Finished installing the Angular snapshot builds.' ) ;
27
+ console . log ( 'Finished installing the Angular snapshot builds.' ) ;
0 commit comments