4
4
* would complain about outdated lock files.
5
5
*/
6
6
7
- const join = require ( 'path' ) . join ;
7
+ const path = require ( 'path' ) ;
8
+ const fs = require ( 'fs' ) ;
8
9
const execSync = require ( 'child_process' ) . execSync ;
9
- const packageJson = require ( '../package.json' ) ;
10
+ const packageJsonPath = path . join ( __dirname , '../package.json' ) ;
11
+ const packageJson = require ( packageJsonPath ) ;
10
12
11
- // List of Angular packages that are specified in the "package.json". Packages will be listed
12
- // without the "@angular/" scope.
13
- const angularPackages = Object
14
- . keys ( { ...packageJson . dependencies , ...packageJson . devDependencies } )
15
- . filter ( depName => depName . startsWith ( '@angular/' ) )
16
- . map ( depName => depName . split ( '/' ) . slice ( 1 ) ) ;
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
+ }
17
25
18
- // List of URLs that refer to the Github snapshot builds for all Angular packages.
19
- const githubBuildUrls = angularPackages . map ( name => `github:angular/${ name } -builds` ) ;
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' ) ;
20
31
21
- // Run yarn add {URLs}, so that it replaces the Angular npm packages with the Github builds.
22
- execSync ( `yarn add ${ githubBuildUrls . join ( ' ' ) } ` , {
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' , {
23
37
stdio : 'inherit' ,
24
38
shell : true ,
25
- cwd : join ( __dirname , '../' )
39
+ cwd : path . join ( __dirname , '../' )
26
40
} ) ;
27
41
28
42
console . log ( 'Finished installing the Angular snapshot builds.' ) ;
0 commit comments