Skip to content

fix(@schematics/angular): tsconfig with comments breaks universal sch… #14372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/schematics/angular/universal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {
JsonParseMode,
Path,
basename,
join,
Expand Down Expand Up @@ -206,7 +207,7 @@ function getTsConfigOutDir(host: Tree, tsConfigPath: string): string {
throw new SchematicsException(`Could not read ${tsConfigPath}`);
}
const tsConfigContent = tsConfigBuffer.toString();
const tsConfig = parseJson(tsConfigContent);
const tsConfig = parseJson(tsConfigContent, JsonParseMode.Loose);
if (tsConfig === null || typeof tsConfig !== 'object' || Array.isArray(tsConfig) ||
tsConfig.compilerOptions === null || typeof tsConfig.compilerOptions !== 'object' ||
Array.isArray(tsConfig.compilerOptions)) {
Expand Down
15 changes: 14 additions & 1 deletion packages/schematics/angular/universal/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Schema as ApplicationOptions, Style } from '../application/schema';
import { Schema as WorkspaceOptions } from '../workspace/schema';
import { Schema as UniversalOptions } from './schema';

// tslint:disable-next-line:no-big-function
describe('Universal Schematic', () => {
const schematicRunner = new SchematicTestRunner(
'@schematics/angular',
Expand Down Expand Up @@ -82,7 +83,6 @@ describe('Universal Schematic', () => {
const tree = await schematicRunner
.runSchematicAsync('universal', workspaceUniversalOptions, appTree)
.toPromise();
debugger;
const filePath = '/tsconfig.server.json';
expect(tree.exists(filePath)).toEqual(true);
const contents = tree.readContent(filePath);
Expand Down Expand Up @@ -204,4 +204,17 @@ describe('Universal Schematic', () => {
expect(schematicRunner.tasks[0].name).toBe('node-package');
expect((schematicRunner.tasks[0].options as {command: string}).command).toBe('install');
});

it(`should work when 'tsconfig.app.json' has comments`, async () => {
const appTsConfigPath = '/projects/bar/tsconfig.app.json';
const appTsConfigContent = appTree.readContent(appTsConfigPath);
appTree.overwrite(appTsConfigPath, '// comment in json file\n' + appTsConfigContent);

const tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
.toPromise();

const filePath = '/projects/bar/tsconfig.server.json';
expect(tree.exists(filePath)).toEqual(true);
});

});