diff --git a/lib/compiler/helpers/get-value-or-default.ts b/lib/compiler/helpers/get-value-or-default.ts index 978ac6289..12b451671 100644 --- a/lib/compiler/helpers/get-value-or-default.ts +++ b/lib/compiler/helpers/get-value-or-default.ts @@ -17,7 +17,7 @@ export function getValueOrDefault( if (configuration.projects && configuration.projects[appName]) { const perAppValue = getValueOfPath( configuration, - `projects.${appName}.`.concat(propertyPath), + `projects."${appName}".`.concat(propertyPath), ); if (perAppValue !== undefined) { return perAppValue as T; @@ -30,18 +30,38 @@ export function getValueOrDefault( return value; } -function getValueOfPath( +export function getValueOfPath( object: Record, propertyPath: string, ): T { const fragments = propertyPath.split('.'); let propertyValue = object; + let isConcatInProgress = false; + let path = ''; + for (const fragment of fragments) { if (!propertyValue) { break; } - propertyValue = propertyValue[fragment]; + /** + * When path is escaped with "" double quotes, + * concatenate the property path. + * Reference: https://github.com/nestjs/nest-cli/issues/947 + */ + if (fragment.startsWith('"')) { + path += fragment.replace('"', '') + '.'; + isConcatInProgress = true; + continue; + } else if (isConcatInProgress) { + path += '.'; + continue; + } else if (fragment.endsWith('"')) { + path += fragment.replace('"', ''); + isConcatInProgress = false; + } + propertyValue = propertyValue[path]; + path = ''; } return propertyValue as T; } diff --git a/test/lib/compiler/helpers/get-value-or-default.spec.ts b/test/lib/compiler/helpers/get-value-or-default.spec.ts index 8fde69c20..4b8720245 100644 --- a/test/lib/compiler/helpers/get-value-or-default.spec.ts +++ b/test/lib/compiler/helpers/get-value-or-default.spec.ts @@ -170,4 +170,29 @@ describe('Get Value or Default', () => { ); expect(value).toBeUndefined(); }); + + it('should concatenate property path when app name contains dots', async () => { + let configuration: Required = { + monorepo: true, + sourceRoot: '', + entryFile: '', + projects: { + 'test.project.v1.api': { + compilerOptions: {}, + }, + }, + language: '', + collection: '', + compilerOptions: { + webpack: true, + }, + generateOptions: {}, + }; + let value = getValueOrDefault( + configuration, + 'compilerOptions.webpack', + 'test.project.v1.api', + ); + expect(value).toEqual(true); + }); });