Skip to content

Commit 58671d3

Browse files
committed
fix(@angular-devkit/core): provide actionable error when a workspace 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: #21310
1 parent 54551bb commit 58671d3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/angular_devkit/core/src/workspace/json/reader.ts

+6
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ function parseProject(
167167
}
168168

169169
const projectNodeValue = getNodeValue(projectNode);
170+
if (!('root' in projectNodeValue)) {
171+
context.error(
172+
`Project "${projectName}" is missing a required property "root".`,
173+
projectNodeValue,
174+
);
175+
}
170176

171177
for (const [name, value] of Object.entries<JsonValue>(projectNodeValue)) {
172178
switch (name) {

packages/angular_devkit/core/src/workspace/json/reader_spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ describe('readJsonWorkpace Parsing', () => {
137137
/version specifier not found/,
138138
);
139139
});
140+
141+
it('errors on missing root property in a project', async () => {
142+
const host = createTestHost(stripIndent`
143+
{
144+
"version": 1,
145+
"projects": {
146+
"foo": {}
147+
}
148+
}
149+
`);
150+
151+
await expectAsync(readJsonWorkspace('', host)).toBeRejectedWithError(
152+
/Project "foo" is missing a required property "root"/,
153+
);
154+
});
140155
});
141156

142157
describe('JSON WorkspaceDefinition Tracks Workspace Changes', () => {

0 commit comments

Comments
 (0)