Skip to content

Commit

Permalink
fix(@angular-devkit/core): provide actionable error when a workspace …
Browse files Browse the repository at this point in the history
…project has missing `root` property

The `root` property is required in a workspace project. Now we issue an actionable error message when this is missing.

Closes: angular#21310
  • Loading branch information
alan-agius4 committed Jun 30, 2022
1 parent 54551bb commit 404383b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/angular_devkit/core/src/workspace/json/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ function parseProject(
}

const projectNodeValue = getNodeValue(projectNode);
if (!('root' in projectNodeValue)) {
context.error(
`Project "${projectName}" is missing a required property "root".`,
projectNodeValue,
);
}

for (const [name, value] of Object.entries<JsonValue>(projectNodeValue)) {
switch (name) {
Expand Down
15 changes: 15 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,21 @@ describe('readJsonWorkpace Parsing', () => {
/version specifier not found/,
);
});

it('errors on missing root property in a project', async () => {
const host = createTestHost(stripIndent`
{
"version": 1,
"projects": {
"foo": {}
}
}
`);

await expectAsync(readJsonWorkspace('', host)).toBeRejectedWithError(
/Project "foo" is missing a required property "root"/,
);
});
});

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

0 comments on commit 404383b

Please sign in to comment.