Skip to content

fix(ng-update): parse cli workspace config as json5 #16218

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,24 @@ describe('ng-update project-tsconfig-paths', () => {

expect(getProjectTsConfigPaths(testTree)).toEqual(['tsconfig.json']);
});

it('should be able to read workspace configuration which is using JSON5 features', () => {
testTree.create('/my-build-config.json', '');
testTree.create('/angular.json', `{
// Comments, unquoted properties or trailing commas are only supported in JSON5.
projects: {
with_tests: {
targets: {
build: {
options: {
tsConfig: './my-build-config.json',
}
}
}
}
},
}`);

expect(getProjectTsConfigPaths(testTree)).toEqual(['my-build-config.json']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {normalize} from '@angular-devkit/core';
import {JsonParseMode, normalize, parseJson} from '@angular-devkit/core';
import {Tree} from '@angular-devkit/schematics';

/** Name of the default Angular CLI workspace configuration files. */
Expand Down Expand Up @@ -63,7 +63,9 @@ function getWorkspaceConfigGracefully(tree: Tree): any {
}

try {
return JSON.parse(configBuffer.toString());
// Parse the workspace file as JSON5 which is also supported for CLI
// workspace configurations.
return parseJson(configBuffer.toString(), JsonParseMode.Json5);
} catch {
return null;
}
Expand Down