From 6acb5d0db113ff71fc9dc027e6c18bfe4b75a95b Mon Sep 17 00:00:00 2001 From: katerina Date: Tue, 5 Jan 2021 12:51:38 +0200 Subject: [PATCH] (fix) reference nx function to read non-angularCli configs --- app/angular/package.json | 6 ++++ app/angular/src/server/angular-cli_config.ts | 35 ++++++++++++++------ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/angular/package.json b/app/angular/package.json index d70272eb68cf..2dae937585e3 100644 --- a/app/angular/package.json +++ b/app/angular/package.json @@ -90,10 +90,16 @@ "@angular/platform-browser": ">=6.0.0", "@angular/platform-browser-dynamic": ">=6.0.0", "@babel/core": "*", + "@nrwl/workspace": ">=11.1.0", "rxjs": "^6.0.0", "typescript": "^3.4.0 || >=4.0.0", "zone.js": "^0.8.29 || ^0.9.0 || ^0.10.0 || ^0.11.0" }, + "peerDependenciesMeta": { + "@nrwl/workspace": { + "optional": true + } + }, "engines": { "node": ">=8.0.0" }, diff --git a/app/angular/src/server/angular-cli_config.ts b/app/angular/src/server/angular-cli_config.ts index 8f37ad93bdbb..c6e3f46dc427 100644 --- a/app/angular/src/server/angular-cli_config.ts +++ b/app/angular/src/server/angular-cli_config.ts @@ -47,17 +47,32 @@ function getTsConfigOptions(tsConfigPath: Path) { } export function getAngularCliConfig(dirToSearch: string) { - const possibleConfigNames = ['angular.json', 'workspace.json']; - const possibleConfigPaths = possibleConfigNames.map((name) => path.join(dirToSearch, name)); - - const validIndex = possibleConfigPaths.findIndex((configPath) => fs.existsSync(configPath)); - - if (validIndex === -1) { - logger.error(`Could not find angular.json using ${possibleConfigPaths[0]}`); - return undefined; + let angularCliConfig; + try { + /** + * Apologies for the following line + * If there's a better way to do it, let's do it + */ + /* eslint-disable global-require */ + angularCliConfig = require('@nrwl/workspace').readWorkspaceConfig({ + format: 'angularCli', + }); + } catch (e) { + const possibleConfigNames = ['angular.json', 'workspace.json']; + const possibleConfigPaths = possibleConfigNames.map((name) => path.join(dirToSearch, name)); + + const validIndex = possibleConfigPaths.findIndex((configPath) => fs.existsSync(configPath)); + + if (validIndex === -1) { + logger.error(`Could not find angular.json using ${possibleConfigPaths[0]}`); + return undefined; + } + + angularCliConfig = JSON.parse( + stripJsonComments(fs.readFileSync(possibleConfigPaths[validIndex], 'utf8')) + ); } - - return JSON.parse(stripJsonComments(fs.readFileSync(possibleConfigPaths[validIndex], 'utf8'))); + return angularCliConfig; } export function getLeadingAngularCliProject(ngCliConfig: any) {