Skip to content
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
11 changes: 10 additions & 1 deletion packages/angular_devkit/core/src/workspace/json/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Does the node provide location info? line/column info may be useful for fixing the underlying problem.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually a value, we can change this to be the actual Node quite easily, but I prefer if this was done in a separate PR.

},
};

Expand Down Expand Up @@ -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<JsonValue>(projectNodeValue)) {
switch (name) {
Expand Down
18 changes: 18 additions & 0 deletions packages/angular_devkit/core/src/workspace/json/reader_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,24 @@ describe('readJsonWorkpace Parsing', () => {
/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', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/schematics/angular/utility/workspace_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { getWorkspace as readWorkspace, updateWorkspace, writeWorkspace } from '
const TEST_WORKSPACE_CONTENT = JSON.stringify({
version: 1,
projects: {
'test': {},
test: {
root: '',
},
},
});

Expand Down