Skip to content

Commit 9810c6c

Browse files
alan-agius4jasonaden
authored andcommittedApr 3, 2019
fix(bazel): support running ng-add on minimal applications (#29681)
Minimal applications don't have `test` and `e2e` targets but we are not currently checking if they exists. Fixes #29680 PR Close #29681
1 parent 8e83b3b commit 9810c6c

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed
 

‎packages/bazel/src/schematics/ng-add/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,18 @@ function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
154154
},
155155
},
156156
indent);
157-
replacePropertyInAstObject(
158-
recorder, architect, 'test', {
159-
builder: '@angular/bazel:build',
160-
options: {'bazelCommand': 'test', 'targetLabel': '//src/...'},
161-
},
162-
indent);
157+
158+
if (findPropertyInAstObject(architect, 'test')) {
159+
replacePropertyInAstObject(
160+
recorder, architect, 'test', {
161+
builder: '@angular/bazel:build',
162+
options: {'bazelCommand': 'test', 'targetLabel': '//src/...'},
163+
},
164+
indent);
165+
}
163166

164167
const e2eArchitect = findE2eArchitect(workspaceJsonAst, name);
165-
if (e2eArchitect) {
168+
if (e2eArchitect && findPropertyInAstObject(e2eArchitect, 'e2e')) {
166169
replacePropertyInAstObject(
167170
recorder, e2eArchitect, 'e2e', {
168171
builder: '@angular/bazel:build',

‎packages/bazel/src/schematics/ng-add/index_spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,23 @@ describe('ng-add schematic', () => {
246246
const json = JSON.parse(content);
247247
expect(json.scripts.postinstall).toBe('ngc -p ./angular-metadata.tsconfig.json');
248248
});
249+
250+
it('should work when run on a minimal project (without test and e2e targets)', () => {
251+
host.overwrite('angular.json', JSON.stringify({
252+
projects: {
253+
'demo': {
254+
architect: {
255+
build: {},
256+
serve: {},
257+
'extract-i18n': {
258+
builder: '@angular-devkit/build-angular:extract-i18n',
259+
},
260+
},
261+
},
262+
},
263+
}));
264+
265+
expect(() => schematicRunner.runSchematic('ng-add', defaultOptions, host)).not.toThrowError();
266+
});
267+
249268
});

0 commit comments

Comments
 (0)
Please sign in to comment.