Skip to content

Commit ac23dc0

Browse files
Alan AgiusKeen Yee Liau
Alan Agius
authored and
Keen Yee Liau
committed
fix(@schematics/angular): tsconfig with comments breaks universal schematic
Fixes #14371
1 parent 04b8549 commit ac23dc0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/schematics/angular/universal/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {
9+
JsonParseMode,
910
Path,
1011
basename,
1112
join,
@@ -206,7 +207,7 @@ function getTsConfigOutDir(host: Tree, tsConfigPath: string): string {
206207
throw new SchematicsException(`Could not read ${tsConfigPath}`);
207208
}
208209
const tsConfigContent = tsConfigBuffer.toString();
209-
const tsConfig = parseJson(tsConfigContent);
210+
const tsConfig = parseJson(tsConfigContent, JsonParseMode.Loose);
210211
if (tsConfig === null || typeof tsConfig !== 'object' || Array.isArray(tsConfig) ||
211212
tsConfig.compilerOptions === null || typeof tsConfig.compilerOptions !== 'object' ||
212213
Array.isArray(tsConfig.compilerOptions)) {

packages/schematics/angular/universal/index_spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Schema as ApplicationOptions, Style } from '../application/schema';
1010
import { Schema as WorkspaceOptions } from '../workspace/schema';
1111
import { Schema as UniversalOptions } from './schema';
1212

13+
// tslint:disable-next-line:no-big-function
1314
describe('Universal Schematic', () => {
1415
const schematicRunner = new SchematicTestRunner(
1516
'@schematics/angular',
@@ -82,7 +83,6 @@ describe('Universal Schematic', () => {
8283
const tree = await schematicRunner
8384
.runSchematicAsync('universal', workspaceUniversalOptions, appTree)
8485
.toPromise();
85-
debugger;
8686
const filePath = '/tsconfig.server.json';
8787
expect(tree.exists(filePath)).toEqual(true);
8888
const contents = tree.readContent(filePath);
@@ -204,4 +204,17 @@ describe('Universal Schematic', () => {
204204
expect(schematicRunner.tasks[0].name).toBe('node-package');
205205
expect((schematicRunner.tasks[0].options as {command: string}).command).toBe('install');
206206
});
207+
208+
it(`should work when 'tsconfig.app.json' has comments`, async () => {
209+
const appTsConfigPath = '/projects/bar/tsconfig.app.json';
210+
const appTsConfigContent = appTree.readContent(appTsConfigPath);
211+
appTree.overwrite(appTsConfigPath, '// comment in json file\n' + appTsConfigContent);
212+
213+
const tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
214+
.toPromise();
215+
216+
const filePath = '/projects/bar/tsconfig.server.json';
217+
expect(tree.exists(filePath)).toEqual(true);
218+
});
219+
207220
});

0 commit comments

Comments
 (0)