Skip to content

Commit 184c842

Browse files
committed
Updates
1 parent d6874b9 commit 184c842

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

scripts/install-angular-snapshots.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,39 @@
44
* would complain about outdated lock files.
55
*/
66

7-
const join = require('path').join;
7+
const path = require('path');
8+
const fs = require('fs');
89
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);
1012

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+
}
1725

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');
2031

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', {
2337
stdio: 'inherit',
2438
shell: true,
25-
cwd: join(__dirname, '../')
39+
cwd: path.join(__dirname, '../')
2640
});
2741

2842
console.log('Finished installing the Angular snapshot builds.');

0 commit comments

Comments
 (0)