Skip to content

Commit 8c24df6

Browse files
committed
fix(@angular/cli): add packageGroup for @angular/cli
This should add ng-update support to updating packages that are published from this repo. The build script only updates package.json's ng-update packageGroup dependencies, so these should be kept up to date in the future (when new packages are created). Fixes angular#13581
1 parent cdda1c3 commit 8c24df6

File tree

12 files changed

+241
-43
lines changed

12 files changed

+241
-43
lines changed

packages/angular/cli/package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@
4141
"symbol-observable": "1.2.0"
4242
},
4343
"ng-update": {
44-
"migrations": "@schematics/angular/migrations/migration-collection.json"
44+
"migrations": "@schematics/angular/migrations/migration-collection.json",
45+
"packageGroupName": "@angular/cli",
46+
"packageGroup": {
47+
"@angular-devkit/architect": "0.0.0",
48+
"@angular-devkit/build-angular": "0.0.0",
49+
"@angular-devkit/build-ng-packagr": "0.0.0",
50+
"@angular-devkit/build-optimizer": "0.0.0",
51+
"@angular-devkit/build-webpack": "0.0.0",
52+
"@angular-devkit/core": "0.0.0",
53+
"@angular-devkit/schematics": "0.0.0",
54+
"@ngtools/webpack": "0.0.0",
55+
"@schematics/angular": "0.0.0",
56+
"@schematics/update": "0.0.0"
57+
}
4558
}
4659
}

packages/angular_devkit/architect/package.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,20 @@
99
"@angular-devkit/core": "0.0.0",
1010
"rxjs": "6.4.0"
1111
},
12-
"builders": "./builders/builders.json"
12+
"builders": "./builders/builders.json",
13+
"ng-update": {
14+
"packageGroupName": "@angular/cli",
15+
"packageGroup": {
16+
"@angular-devkit/architect": "0.0.0",
17+
"@angular-devkit/build-angular": "0.0.0",
18+
"@angular-devkit/build-ng-packagr": "0.0.0",
19+
"@angular-devkit/build-optimizer": "0.0.0",
20+
"@angular-devkit/build-webpack": "0.0.0",
21+
"@angular-devkit/core": "0.0.0",
22+
"@angular-devkit/schematics": "0.0.0",
23+
"@ngtools/webpack": "0.0.0",
24+
"@schematics/angular": "0.0.0",
25+
"@schematics/update": "0.0.0"
26+
}
27+
}
1328
}

packages/angular_devkit/build_angular/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,20 @@
8585
"popper.js": "^1.14.1",
8686
"protractor": "~5.4.0",
8787
"zone.js": "^0.8.19"
88+
},
89+
"ng-update": {
90+
"packageGroupName": "@angular/cli",
91+
"packageGroup": {
92+
"@angular-devkit/architect": "0.0.0",
93+
"@angular-devkit/build-angular": "0.0.0",
94+
"@angular-devkit/build-ng-packagr": "0.0.0",
95+
"@angular-devkit/build-optimizer": "0.0.0",
96+
"@angular-devkit/build-webpack": "0.0.0",
97+
"@angular-devkit/core": "0.0.0",
98+
"@angular-devkit/schematics": "0.0.0",
99+
"@ngtools/webpack": "0.0.0",
100+
"@schematics/angular": "0.0.0",
101+
"@schematics/update": "0.0.0"
102+
}
88103
}
89104
}

packages/angular_devkit/build_ng_packagr/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,20 @@
2121
"ng-packagr": "^4.2.0",
2222
"tsickle": ">=0.34.0",
2323
"tslib": "^1.9.0"
24+
},
25+
"ng-update": {
26+
"packageGroupName": "@angular/cli",
27+
"packageGroup": {
28+
"@angular-devkit/architect": "0.0.0",
29+
"@angular-devkit/build-angular": "0.0.0",
30+
"@angular-devkit/build-ng-packagr": "0.0.0",
31+
"@angular-devkit/build-optimizer": "0.0.0",
32+
"@angular-devkit/build-webpack": "0.0.0",
33+
"@angular-devkit/core": "0.0.0",
34+
"@angular-devkit/schematics": "0.0.0",
35+
"@ngtools/webpack": "0.0.0",
36+
"@schematics/angular": "0.0.0",
37+
"@schematics/update": "0.0.0"
38+
}
2439
}
2540
}

packages/angular_devkit/build_optimizer/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,20 @@
1313
"source-map": "0.5.6",
1414
"typescript": "3.2.4",
1515
"webpack-sources": "1.3.0"
16+
},
17+
"ng-update": {
18+
"packageGroupName": "@angular/cli",
19+
"packageGroup": {
20+
"@angular-devkit/architect": "0.0.0",
21+
"@angular-devkit/build-angular": "0.0.0",
22+
"@angular-devkit/build-ng-packagr": "0.0.0",
23+
"@angular-devkit/build-optimizer": "0.0.0",
24+
"@angular-devkit/build-webpack": "0.0.0",
25+
"@angular-devkit/core": "0.0.0",
26+
"@angular-devkit/schematics": "0.0.0",
27+
"@ngtools/webpack": "0.0.0",
28+
"@schematics/angular": "0.0.0",
29+
"@schematics/update": "0.0.0"
30+
}
1631
}
1732
}

packages/angular_devkit/build_webpack/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,20 @@
1919
"devDependencies": {
2020
"webpack": "4.29.6",
2121
"webpack-dev-server": "^3.1.4"
22+
},
23+
"ng-update": {
24+
"packageGroupName": "@angular/cli",
25+
"packageGroup": {
26+
"@angular-devkit/architect": "0.0.0",
27+
"@angular-devkit/build-angular": "0.0.0",
28+
"@angular-devkit/build-ng-packagr": "0.0.0",
29+
"@angular-devkit/build-optimizer": "0.0.0",
30+
"@angular-devkit/build-webpack": "0.0.0",
31+
"@angular-devkit/core": "0.0.0",
32+
"@angular-devkit/schematics": "0.0.0",
33+
"@ngtools/webpack": "0.0.0",
34+
"@schematics/angular": "0.0.0",
35+
"@schematics/update": "0.0.0"
36+
}
2237
}
2338
}

packages/angular_devkit/core/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,20 @@
1515
},
1616
"devDependencies": {
1717
"seedrandom": "^2.4.4"
18+
},
19+
"ng-update": {
20+
"packageGroupName": "@angular/cli",
21+
"packageGroup": {
22+
"@angular-devkit/architect": "0.0.0",
23+
"@angular-devkit/build-angular": "0.0.0",
24+
"@angular-devkit/build-ng-packagr": "0.0.0",
25+
"@angular-devkit/build-optimizer": "0.0.0",
26+
"@angular-devkit/build-webpack": "0.0.0",
27+
"@angular-devkit/core": "0.0.0",
28+
"@angular-devkit/schematics": "0.0.0",
29+
"@ngtools/webpack": "0.0.0",
30+
"@schematics/angular": "0.0.0",
31+
"@schematics/update": "0.0.0"
32+
}
1833
}
1934
}

packages/angular_devkit/schematics/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,20 @@
1515
"dependencies": {
1616
"@angular-devkit/core": "0.0.0",
1717
"rxjs": "6.4.0"
18+
},
19+
"ng-update": {
20+
"packageGroupName": "@angular/cli",
21+
"packageGroup": {
22+
"@angular-devkit/architect": "0.0.0",
23+
"@angular-devkit/build-angular": "0.0.0",
24+
"@angular-devkit/build-ng-packagr": "0.0.0",
25+
"@angular-devkit/build-optimizer": "0.0.0",
26+
"@angular-devkit/build-webpack": "0.0.0",
27+
"@angular-devkit/core": "0.0.0",
28+
"@angular-devkit/schematics": "0.0.0",
29+
"@ngtools/webpack": "0.0.0",
30+
"@schematics/angular": "0.0.0",
31+
"@schematics/update": "0.0.0"
32+
}
1833
}
1934
}

packages/ngtools/webpack/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,20 @@
3737
"@angular/compiler-cli": "^7.2.0-rc.0",
3838
"typescript": "3.2.4",
3939
"webpack": "4.29.6"
40+
},
41+
"ng-update": {
42+
"packageGroupName": "@angular/cli",
43+
"packageGroup": {
44+
"@angular-devkit/architect": "0.0.0",
45+
"@angular-devkit/build-angular": "0.0.0",
46+
"@angular-devkit/build-ng-packagr": "0.0.0",
47+
"@angular-devkit/build-optimizer": "0.0.0",
48+
"@angular-devkit/build-webpack": "0.0.0",
49+
"@angular-devkit/core": "0.0.0",
50+
"@angular-devkit/schematics": "0.0.0",
51+
"@ngtools/webpack": "0.0.0",
52+
"@schematics/angular": "0.0.0",
53+
"@schematics/update": "0.0.0"
54+
}
4055
}
4156
}

packages/schematics/angular/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,20 @@
1111
"dependencies": {
1212
"@angular-devkit/core": "0.0.0",
1313
"@angular-devkit/schematics": "0.0.0"
14+
},
15+
"ng-update": {
16+
"packageGroupName": "@angular/cli",
17+
"packageGroup": {
18+
"@angular-devkit/architect": "0.0.0",
19+
"@angular-devkit/build-angular": "0.0.0",
20+
"@angular-devkit/build-ng-packagr": "0.0.0",
21+
"@angular-devkit/build-optimizer": "0.0.0",
22+
"@angular-devkit/build-webpack": "0.0.0",
23+
"@angular-devkit/core": "0.0.0",
24+
"@angular-devkit/schematics": "0.0.0",
25+
"@ngtools/webpack": "0.0.0",
26+
"@schematics/angular": "0.0.0",
27+
"@schematics/update": "0.0.0"
28+
}
1429
}
1530
}

packages/schematics/update/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,20 @@
1919
"semver": "5.6.0",
2020
"semver-intersect": "1.4.0",
2121
"rxjs": "6.4.0"
22+
},
23+
"ng-update": {
24+
"packageGroupName": "@angular/cli",
25+
"packageGroup": {
26+
"@angular-devkit/architect": "0.0.0",
27+
"@angular-devkit/build-angular": "0.0.0",
28+
"@angular-devkit/build-ng-packagr": "0.0.0",
29+
"@angular-devkit/build-optimizer": "0.0.0",
30+
"@angular-devkit/build-webpack": "0.0.0",
31+
"@angular-devkit/core": "0.0.0",
32+
"@angular-devkit/schematics": "0.0.0",
33+
"@ngtools/webpack": "0.0.0",
34+
"@schematics/angular": "0.0.0",
35+
"@schematics/update": "0.0.0"
36+
}
2237
}
2338
}

scripts/build.ts

+76-41
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,79 @@ async function _bazel(logger: logging.Logger) {
203203
// _exec('bazel', ['build', '//packages/...'], {}, logger);
204204
}
205205

206+
async function _setVersions(
207+
sortedPackages: string[],
208+
argv: { local?: boolean, snapshot?: boolean },
209+
logger: logging.Logger,
210+
) {
211+
for (const packageName of sortedPackages) {
212+
logger.info(packageName);
213+
const pkg = packages[packageName];
214+
const packageJsonPath = path.join(pkg.dist, 'package.json');
215+
const packageJson = pkg.packageJson;
216+
const version = pkg.version;
217+
218+
if (version) {
219+
packageJson['version'] = version;
220+
} else {
221+
logger.error('No version found... Only updating dependencies.');
222+
}
223+
224+
for (const depName of Object.keys(packages)) {
225+
const v = packages[depName].version;
226+
for (const depKey of ['dependencies', 'peerDependencies', 'devDependencies']) {
227+
const obj = packageJson[depKey] as JsonObject | null;
228+
if (obj && obj[depName]) {
229+
if (argv.local) {
230+
obj[depName] = packages[depName].tar;
231+
} else if (argv.snapshot) {
232+
const pkg = packages[depName];
233+
if (!pkg.snapshotRepo) {
234+
logger.error(
235+
`Package ${JSON.stringify(depName)} is not published as a snapshot. `
236+
+ `Fixing to current version ${v}.`,
237+
);
238+
obj[depName] = v;
239+
} else {
240+
obj[depName] = `github:${pkg.snapshotRepo}#${pkg.snapshotHash}`;
241+
}
242+
} else if ((obj[depName] as string).match(/\b0\.0\.0\b/)) {
243+
obj[depName] = (obj[depName] as string).replace(/\b0\.0\.0\b/, v);
244+
}
245+
}
246+
}
247+
}
248+
249+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
250+
}
251+
}
252+
253+
async function _setPackageGroups(sortedPackages: string[], logger: logging.Logger) {
254+
for (const packageName of sortedPackages) {
255+
logger.info(packageName);
256+
const pkg = packages[packageName];
257+
258+
const packageJsonPath = path.join(pkg.dist, 'package.json');
259+
const packageJson = pkg.packageJson;
260+
// tslint:disable-next-line:no-any
261+
const ngUpdateJson: any = packageJson['ng-update'] || (packageJson['ng-update'] = {});
262+
const packageGroup = ngUpdateJson['packageGroup'] || (ngUpdateJson['packageGroup'] = {});
263+
264+
let changed = false;
265+
for (const subPackageName of sortedPackages) {
266+
const subpkg = packages[subPackageName];
267+
if (packageGroup[subPackageName] === '0.0.0') {
268+
packageGroup[subPackageName] = subpkg.version;
269+
changed = true;
270+
}
271+
}
272+
273+
if (changed) {
274+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
275+
}
276+
}
277+
}
278+
206279
export default async function(
207280
argv: { local?: boolean, snapshot?: boolean },
208281
logger: logging.Logger,
@@ -350,48 +423,10 @@ export default async function(
350423
}
351424

352425
logger.info('Setting versions...');
426+
await _setVersions(sortedPackages, argv, logger.createChild('versions'));
353427

354-
const versionLogger = logger.createChild('versions');
355-
for (const packageName of sortedPackages) {
356-
versionLogger.info(packageName);
357-
const pkg = packages[packageName];
358-
const packageJsonPath = path.join(pkg.dist, 'package.json');
359-
const packageJson = pkg.packageJson;
360-
const version = pkg.version;
361-
362-
if (version) {
363-
packageJson['version'] = version;
364-
} else {
365-
versionLogger.error('No version found... Only updating dependencies.');
366-
}
367-
368-
for (const depName of Object.keys(packages)) {
369-
const v = packages[depName].version;
370-
for (const depKey of ['dependencies', 'peerDependencies', 'devDependencies']) {
371-
const obj = packageJson[depKey] as JsonObject | null;
372-
if (obj && obj[depName]) {
373-
if (argv.local) {
374-
obj[depName] = packages[depName].tar;
375-
} else if (argv.snapshot) {
376-
const pkg = packages[depName];
377-
if (!pkg.snapshotRepo) {
378-
versionLogger.error(
379-
`Package ${JSON.stringify(depName)} is not published as a snapshot. `
380-
+ `Fixing to current version ${v}.`,
381-
);
382-
obj[depName] = v;
383-
} else {
384-
obj[depName] = `github:${pkg.snapshotRepo}#${pkg.snapshotHash}`;
385-
}
386-
} else if ((obj[depName] as string).match(/\b0\.0\.0\b/)) {
387-
obj[depName] = (obj[depName] as string).replace(/\b0\.0\.0\b/, v);
388-
}
389-
}
390-
}
391-
}
392-
393-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
394-
}
428+
logger.info('Setting packageGroups...');
429+
await _setPackageGroups(sortedPackages, logger.createChild('packageGroups'));
395430

396431
logger.info('Tarring all packages...');
397432
const tarLogger = logger.createChild('license');

0 commit comments

Comments
 (0)