mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 11:03:53 +08:00
fix(@angular-devkit/core): provide actionable warning when a workspace project has missing root
property
The `root` property is required in a workspace project. Now we issue an actionable warning message when this is missing. Note: this will become an error in the next major version. Closes: #21310
This commit is contained in:
parent
3d6ed0caf3
commit
624e0b0ec6
@ -60,8 +60,10 @@ export async function readJsonWorkspace(
|
|||||||
// TODO: Diagnostic reporting support
|
// TODO: Diagnostic reporting support
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
},
|
},
|
||||||
warn(_message, _node) {
|
warn(message, _node) {
|
||||||
// TODO: Diagnostic reporting support
|
// TODO: Diagnostic reporting support
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn(message);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -167,6 +169,13 @@ function parseProject(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const projectNodeValue = getNodeValue(projectNode);
|
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)) {
|
for (const [name, value] of Object.entries<JsonValue>(projectNodeValue)) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
@ -137,6 +137,24 @@ describe('readJsonWorkpace Parsing', () => {
|
|||||||
/version specifier not found/,
|
/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', () => {
|
describe('JSON WorkspaceDefinition Tracks Workspace Changes', () => {
|
||||||
|
@ -12,7 +12,9 @@ import { getWorkspace as readWorkspace, updateWorkspace, writeWorkspace } from '
|
|||||||
const TEST_WORKSPACE_CONTENT = JSON.stringify({
|
const TEST_WORKSPACE_CONTENT = JSON.stringify({
|
||||||
version: 1,
|
version: 1,
|
||||||
projects: {
|
projects: {
|
||||||
'test': {},
|
test: {
|
||||||
|
root: '',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user