diff --git a/packages/angular_devkit/core/src/workspace/json/reader.ts b/packages/angular_devkit/core/src/workspace/json/reader.ts index d780145636db..b0e4fbb6d17c 100644 --- a/packages/angular_devkit/core/src/workspace/json/reader.ts +++ b/packages/angular_devkit/core/src/workspace/json/reader.ts @@ -60,8 +60,10 @@ export async function readJsonWorkspace( // TODO: Diagnostic reporting support throw new Error(message); }, - warn(_message, _node) { + warn(message, _node) { // TODO: Diagnostic reporting support + // eslint-disable-next-line no-console + console.warn(message); }, }; @@ -167,6 +169,13 @@ function parseProject( } const projectNodeValue = getNodeValue(projectNode); + if (!('root' in projectNodeValue)) { + // TODO(alan-agius4): change this to error in v15. + context.warn( + `Project "${projectName}" is missing a required property "root". This will become an error in the next major version.`, + projectNodeValue, + ); + } for (const [name, value] of Object.entries(projectNodeValue)) { switch (name) { diff --git a/packages/angular_devkit/core/src/workspace/json/reader_spec.ts b/packages/angular_devkit/core/src/workspace/json/reader_spec.ts index 1ac13b474700..4b0af1043513 100644 --- a/packages/angular_devkit/core/src/workspace/json/reader_spec.ts +++ b/packages/angular_devkit/core/src/workspace/json/reader_spec.ts @@ -143,6 +143,24 @@ describe('readJsonWorkpace Parsing', () => { expect(e.message).toContain('version specifier not found'); } }); + + it('warns on missing root property in a project', async () => { + const host = createTestHost(stripIndent` + { + "version": 1, + "projects": { + "foo": {} + } + } + `); + + const consoleWarnSpy = spyOn(console, 'warn').and.callFake(() => undefined); + await expectAsync(readJsonWorkspace('', host)); + + expect(consoleWarnSpy).toHaveBeenCalledWith( + `Project "foo" is missing a required property "root". This will become an error in the next major version.`, + ); + }); }); describe('JSON WorkspaceDefinition Tracks Workspace Changes', () => { diff --git a/packages/schematics/angular/utility/workspace_spec.ts b/packages/schematics/angular/utility/workspace_spec.ts index f5b9978719a6..56f6a14b9c59 100644 --- a/packages/schematics/angular/utility/workspace_spec.ts +++ b/packages/schematics/angular/utility/workspace_spec.ts @@ -12,7 +12,9 @@ import { getWorkspace as readWorkspace, updateWorkspace, writeWorkspace } from ' const TEST_WORKSPACE_CONTENT = JSON.stringify({ version: 1, projects: { - 'test': {}, + test: { + root: '', + }, }, });