Skip to content

Commit 08e91a9

Browse files
hanslvikerman
authored andcommitted
build: refactor QoL on monorepo.json
This should make it easier to manage and diff. This takes 2 things into account: 1. we have either stable or experimental versions and each are kept in monorepo. 2. we dont keep hash and update only changed packages. This commit also removed the hash to make sure this does not happen.
1 parent a24c461 commit 08e91a9

File tree

14 files changed

+62
-109
lines changed

14 files changed

+62
-109
lines changed

.monorepo.json

+3-41
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,10 @@
4242
},
4343
"packages": {
4444
"@_/benchmark": {
45-
"version": "0.14.0-beta.5",
46-
"hash": "5225044ecf49d630564a68b710f6b82f"
4745
},
4846
"@_/builders": {
49-
"version": "0.14.0-beta.4",
50-
"hash": "569aef8bc23693c344e71b9755e62c50"
5147
},
5248
"devkit": {
53-
"version": "0.14.0-beta.5",
54-
"hash": "ee31237492de354cdeb804a77ddb99a2"
5549
},
5650
"@angular/cli": {
5751
"name": "Angular CLI",
@@ -62,15 +56,11 @@
6256
"url": "/packages/angular/cli/README.md"
6357
}
6458
],
65-
"version": "8.0.0-beta.5",
66-
"snapshotRepo": "angular/cli-builds",
67-
"hash": "a7d8ce7ece9ffcd1bf4fa095d48848fc"
59+
"snapshotRepo": "angular/cli-builds"
6860
},
6961
"@angular/pwa": {
7062
"name": "Angular PWA Schematics",
7163
"section": "Schematics",
72-
"version": "0.14.0-beta.5",
73-
"hash": "c384b8179204563116fd10c0b177344d",
7464
"snapshotRepo": "angular/angular-pwa-builds"
7565
},
7666
"@angular-devkit/architect": {
@@ -81,21 +71,15 @@
8171
"url": "/packages/angular_devkit/architect/README.md"
8272
}
8373
],
84-
"version": "0.14.0-beta.5",
85-
"hash": "49d84280d90a0596e2f12fabed1b3bc5",
8674
"snapshotRepo": "angular/angular-devkit-architect-builds"
8775
},
8876
"@angular-devkit/architect-cli": {
8977
"name": "Architect CLI",
90-
"version": "0.14.0-beta.5",
91-
"hash": "f4a1216b5864f85521607ac9d0837a52",
9278
"snapshotRepo": "angular/angular-devkit-architect-cli-builds"
9379
},
9480
"@angular-devkit/benchmark": {
9581
"name": "Benchmark",
96-
"section": "Tooling",
97-
"version": "1.2.0-beta.5",
98-
"hash": "a97cd421a1deac9b478d52c4e950cc1e"
82+
"section": "Tooling"
9983
},
10084
"@angular-devkit/build-optimizer": {
10185
"name": "Build Optimizer",
@@ -105,8 +89,6 @@
10589
"url": "/packages/angular_devkit/build_optimizer/README.md"
10690
}
10791
],
108-
"version": "0.14.0-beta.5",
109-
"hash": "5250a56331833383ca39c17f9be70fe8",
11092
"snapshotRepo": "angular/angular-devkit-build-optimizer-builds"
11193
},
11294
"@angular-devkit/build-ng-packagr": {
@@ -117,8 +99,6 @@
11799
"url": "/packages/angular_devkit/build_ng_packagr/README.md"
118100
}
119101
],
120-
"version": "0.14.0-beta.5",
121-
"hash": "e87e58f07bad54fe46c169bbd4196ab7",
122102
"snapshotRepo": "angular/angular-devkit-build-ng-packagr-builds"
123103
},
124104
"@angular-devkit/build-angular": {
@@ -129,8 +109,6 @@
129109
"url": "/packages/angular_devkit/build_angular/README.md"
130110
}
131111
],
132-
"version": "0.14.0-beta.5",
133-
"hash": "71d3197702ff8bad96d185c91a31bd3d",
134112
"snapshotRepo": "angular/angular-devkit-build-angular-builds"
135113
},
136114
"@angular-devkit/build-webpack": {
@@ -141,9 +119,7 @@
141119
"url": "/packages/angular_devkit/build_webpack/README.md"
142120
}
143121
],
144-
"version": "0.14.0-beta.5",
145-
"snapshotRepo": "angular/angular-devkit-build-webpack-builds",
146-
"hash": "a7395f447b3e24d7f178ef54263c198c"
122+
"snapshotRepo": "angular/angular-devkit-build-webpack-builds"
147123
},
148124
"@angular-devkit/core": {
149125
"name": "Core",
@@ -153,8 +129,6 @@
153129
"url": "/packages/angular_devkit/core/README.md"
154130
}
155131
],
156-
"version": "8.0.0-beta.5",
157-
"hash": "5f82ed72531a97dc657aa79ab0207227",
158132
"snapshotRepo": "angular/angular-devkit-core-builds"
159133
},
160134
"@angular-devkit/schematics": {
@@ -165,43 +139,31 @@
165139
"url": "/packages/angular_devkit/schematics/README.md"
166140
}
167141
],
168-
"version": "8.0.0-beta.5",
169-
"hash": "3f925d566c97375d6101fddbcbef33e3",
170142
"snapshotRepo": "angular/angular-devkit-schematics-builds"
171143
},
172144
"@angular-devkit/schematics-cli": {
173145
"name": "Schematics CLI",
174146
"section": "Tooling",
175-
"version": "0.14.0-beta.5",
176-
"hash": "2a856bf23cc1bf74a6eb981dc6c316a2",
177147
"snapshotRepo": "angular/angular-devkit-schematics-cli-builds"
178148
},
179149
"@ngtools/webpack": {
180150
"name": "Webpack Angular Plugin",
181-
"version": "8.0.0-beta.5",
182151
"section": "Misc",
183-
"hash": "dde27b96d50a58c9738ad4bc27646077",
184152
"snapshotRepo": "angular/ngtools-webpack-builds"
185153
},
186154
"@schematics/angular": {
187155
"name": "Angular Schematics",
188156
"section": "Schematics",
189-
"version": "8.0.0-beta.5",
190-
"hash": "834d6c3ac93c047886db71717f43b959",
191157
"snapshotRepo": "angular/schematics-angular-builds"
192158
},
193159
"@schematics/schematics": {
194160
"name": "Schematics Schematics",
195-
"version": "0.14.0-beta.5",
196161
"section": "Schematics",
197-
"hash": "c8967c19e9137071c1e89809d0af2699",
198162
"snapshotRepo": "angular/schematics-schematics-builds"
199163
},
200164
"@schematics/update": {
201165
"name": "Package Update Schematics",
202-
"version": "0.14.0-beta.5",
203166
"section": "Schematics",
204-
"hash": "bc9b7216998a5c42f4b5ab9a993ef64b",
205167
"snapshotRepo": "angular/schematics-update-builds"
206168
}
207169
}

docs/process/release.md

+2-9
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,9 @@ Consider if you need to update `packages/schematics/angular/utility/latest-versi
4949

5050
## Shepparding
5151

52-
As commits are cherry-picked when PRs are merged, creating the release should be a matter of updating the version
53-
numbers. This can be done with the following command.
52+
As commits are cherry-picked when PRs are merged, creating the release should be a matter of creating a tag.
5453

55-
See `scripts/release.ts` for the full list of release types, e.g. patch updates the third number per semver.
56-
57-
```bash
58-
devkit-admin release patch --force # replace with minor-beta etc.
59-
```
60-
61-
Make sure you update the package versions in `packages/schematics/angular/utility/latest-versions.ts`. After that:
54+
**Make sure you update the package versions in `packages/schematics/angular/utility/latest-versions.ts`.**
6255

6356
```bash
6457
git commit -a -m 'release: vXX'

lib/packages.ts

+36-52
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
// tslint:disable-next-line:no-implicit-dependencies
99
import { JsonObject } from '@angular-devkit/core';
1010
import { execSync } from 'child_process';
11-
import * as crypto from 'crypto';
1211
import * as fs from 'fs';
1312
import * as path from 'path';
1413
import * as ts from 'typescript';
1514

16-
const glob = require('glob');
1715
const distRoot = path.join(__dirname, '../dist');
18-
const { packages: monorepoPackages } = require('../.monorepo.json');
16+
const { versions: monorepoVersions, packages: monorepoPackages } = require('../.monorepo.json');
1917

2018

2119
export interface PackageInfo {
@@ -28,53 +26,19 @@ export interface PackageInfo {
2826
build: string;
2927
tar: string;
3028
private: boolean;
29+
experimental: boolean;
3130
packageJson: JsonObject;
3231
dependencies: string[];
3332

3433
snapshot: boolean;
3534
snapshotRepo: string;
3635
snapshotHash: string;
3736

38-
dirty: boolean;
39-
hash: string;
4037
version: string;
4138
}
4239
export type PackageMap = { [name: string]: PackageInfo };
4340

4441

45-
const hashCache: {[name: string]: string | null} = {};
46-
function _getHashOf(pkg: PackageInfo): string {
47-
if (!(pkg.name in hashCache)) {
48-
hashCache[pkg.name] = null;
49-
const md5Stream = crypto.createHash('md5');
50-
51-
// Update the stream with all files content.
52-
const files: string[] = glob.sync(path.join(pkg.root, '**'), { nodir: true });
53-
files.forEach(filePath => {
54-
md5Stream.write(`\0${filePath}\0`);
55-
md5Stream.write(fs.readFileSync(filePath));
56-
});
57-
// Update the stream with all versions of upstream dependencies.
58-
pkg.dependencies.forEach(depName => {
59-
md5Stream.write(`\0${depName}\0${_getHashOf(packages[depName])}\0`);
60-
});
61-
62-
md5Stream.end();
63-
64-
hashCache[pkg.name] = (md5Stream.read() as Buffer).toString('hex');
65-
}
66-
67-
const value = hashCache[pkg.name];
68-
if (!value) {
69-
// Protect against circular dependency.
70-
throw new Error('Circular dependency detected between the following packages: '
71-
+ Object.keys(hashCache).filter(key => hashCache[key] == null).join(', '));
72-
}
73-
74-
return value;
75-
}
76-
77-
7842
function loadPackageJson(p: string) {
7943
const root = require('../package.json');
8044
const pkg = require(p);
@@ -174,16 +138,42 @@ const packageJsonPaths = _findAllPackageJson(path.join(__dirname, '..'), exclude
174138
.filter(p => p != path.join(__dirname, '../package.json'));
175139

176140

141+
function _exec(cmd: string) {
142+
return execSync(cmd).toString().trim();
143+
}
144+
145+
177146
let gitShaCache: string;
178147
function _getSnapshotHash(_pkg: PackageInfo): string {
179148
if (!gitShaCache) {
180-
gitShaCache = execSync('git log --format=%h -n1').toString().trim();
149+
gitShaCache = _exec('git log --format=%h -n1');
181150
}
182151

183152
return gitShaCache;
184153
}
185154

186155

156+
let stableVersion = '';
157+
let experimentalVersion = '';
158+
function _getVersionFromGit(experimental: boolean): string {
159+
if (stableVersion && experimentalVersion) {
160+
return experimental ? experimentalVersion : stableVersion;
161+
}
162+
163+
const hasLocalChanges = _exec(`git status --porcelain`) != '';
164+
const scmVersionTagRaw = _exec(`git describe --match v[0-9].[0-9].[0-9]* --abbrev=7 --tags`)
165+
.slice(1);
166+
stableVersion = scmVersionTagRaw.replace(/-([0-9]+)-g/, '+$1.')
167+
+ (hasLocalChanges ? '.with-local-changes' : '');
168+
169+
experimentalVersion = `0.${stableVersion.replace(/^(\d+)\.(\d+)/, (_, major, minor) => {
170+
return '' + (parseInt(major, 10) * 100 + parseInt(minor, 10));
171+
})}`;
172+
173+
return experimental ? experimentalVersion : stableVersion;
174+
}
175+
176+
187177
// All the supported packages. Go through the packages directory and create a map of
188178
// name => PackageInfo. This map is partial as it lacks some information that requires the
189179
// map itself to finish building.
@@ -213,13 +203,16 @@ export const packages: PackageMap =
213203
bin[binName] = p;
214204
});
215205

206+
const experimental = !!packageJson.private || !!packageJson.experimental;
207+
216208
packages[name] = {
217209
build: path.join(distRoot, pkgRoot.substr(path.dirname(__dirname).length)),
218210
dist: path.join(distRoot, name),
219211
root: pkgRoot,
220212
relative: path.relative(path.dirname(__dirname), pkgRoot),
221213
main: path.resolve(pkgRoot, 'src/index.ts'),
222-
private: packageJson.private,
214+
private: !!packageJson.private,
215+
experimental,
223216
// yarn doesn't take kindly to @ in tgz filenames
224217
// https://github.com/yarnpkg/yarn/issues/6339
225218
tar: path.join(distRoot, name.replace(/\/|@/g, '_') + '.tgz'),
@@ -234,9 +227,9 @@ export const packages: PackageMap =
234227
},
235228

236229
dependencies: [],
237-
hash: '',
238-
dirty: false,
239-
version: monorepoPackages[name] && monorepoPackages[name].version || '0.0.0',
230+
get version() {
231+
return _getVersionFromGit(experimental);
232+
},
240233
};
241234

242235
return packages;
@@ -252,12 +245,3 @@ for (const pkgName of Object.keys(packages)) {
252245
|| name in (pkgJson.devDependencies || {});
253246
});
254247
}
255-
256-
257-
// Update the hash values of each.
258-
for (const pkgName of Object.keys(packages)) {
259-
packages[pkgName].hash = _getHashOf(packages[pkgName]);
260-
if (!monorepoPackages[pkgName] || packages[pkgName].hash != monorepoPackages[pkgName].hash) {
261-
packages[pkgName].dirty = true;
262-
}
263-
}

packages/angular/pwa/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular/pwa",
33
"version": "0.0.0",
44
"description": "PWA schematics for Angular",
5+
"experimental": true,
56
"keywords": [
67
"blueprints",
78
"code generation",
@@ -15,4 +16,4 @@
1516
"parse5-html-rewriting-stream": "5.1.0",
1617
"rxjs": "6.4.0"
1718
}
18-
}
19+
}

packages/angular_devkit/architect/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular-devkit/architect",
33
"version": "0.0.0",
44
"description": "Angular Build Facade",
5+
"experimental": true,
56
"main": "src/index.js",
67
"typings": "src/index.d.ts",
78
"dependencies": {

packages/angular_devkit/architect_cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular-devkit/architect-cli",
33
"version": "0.0.0",
44
"description": "Angular Architect CLI",
5+
"experimental": true,
56
"bin": {
67
"architect": "./bin/architect.js"
78
},

packages/angular_devkit/build_angular/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular-devkit/build-angular",
33
"version": "0.0.0",
44
"description": "Angular Webpack Build Facade",
5+
"experimental": true,
56
"main": "src/index.js",
67
"typings": "src/index.d.ts",
78
"builders": "builders.json",

packages/angular_devkit/build_ng_packagr/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular-devkit/build-ng-packagr",
33
"version": "0.0.0",
44
"description": "Angular Build Architect for ng-packagr",
5+
"experimental": true,
56
"main": "src/index.js",
67
"typings": "src/index.d.ts",
78
"builders": "builders.json",

packages/angular_devkit/build_optimizer/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular-devkit/build-optimizer",
33
"version": "0.0.0",
44
"description": "Angular Build Optimizer",
5+
"experimental": true,
56
"main": "src/index.js",
67
"typings": "src/index.d.ts",
78
"bin": {

packages/angular_devkit/build_webpack/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular-devkit/build-webpack",
33
"version": "0.0.0",
44
"description": "Webpack Builder for Architect",
5+
"experimental": true,
56
"main": "src/index.js",
67
"typings": "src/index.d.ts",
78
"builders": "builders.json",

packages/angular_devkit/schematics_cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular-devkit/schematics-cli",
33
"version": "0.0.0",
44
"description": "Angular Schematics - CLI",
5+
"experimental": true,
56
"bin": {
67
"schematics": "./bin/schematics.js"
78
},

0 commit comments

Comments
 (0)