fix(core): throw an error if implicit dependency is a string that is not '*' (#5176)
This commit is contained in:
parent
03d16676ac
commit
a300e7613d
@ -7,6 +7,9 @@ describe('assertWorkspaceValidity', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockNxJson = {
|
mockNxJson = {
|
||||||
|
implicitDependencies: {
|
||||||
|
'nx.json': '*',
|
||||||
|
},
|
||||||
projects: {
|
projects: {
|
||||||
app1: {
|
app1: {
|
||||||
tags: [],
|
tags: [],
|
||||||
@ -126,4 +129,23 @@ describe('assertWorkspaceValidity', () => {
|
|||||||
});
|
});
|
||||||
mockExit.mockRestore();
|
mockExit.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw for a project-level implicit dependency that is a string', () => {
|
||||||
|
spyOn(output, 'error');
|
||||||
|
mockNxJson.implicitDependencies['nx.json'] = 'invalidproj';
|
||||||
|
|
||||||
|
const mockExit = jest
|
||||||
|
.spyOn(process, 'exit')
|
||||||
|
.mockImplementation(((code?: number) => {}) as any);
|
||||||
|
assertWorkspaceValidity(mockWorkspaceJson, mockNxJson);
|
||||||
|
|
||||||
|
expect(mockExit).toHaveBeenCalledWith(1);
|
||||||
|
expect(output.error).toHaveBeenCalledWith({
|
||||||
|
title: 'Configuration Error',
|
||||||
|
bodyLines: [
|
||||||
|
'nx.json is not configured properly. "nx.json" is improperly configured to implicitly depend on "invalidproj" but should be an array of project names or "*".',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
mockExit.mockRestore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -48,18 +48,30 @@ export function assertWorkspaceValidity(workspaceJson, nxJson: NxJson) {
|
|||||||
nxJson.implicitDependencies || {}
|
nxJson.implicitDependencies || {}
|
||||||
)
|
)
|
||||||
.reduce((acc, entry) => {
|
.reduce((acc, entry) => {
|
||||||
function recur(value, acc = []) {
|
function recur(value, acc = [], path: string[]) {
|
||||||
if (value === '*') {
|
if (value === '*') {
|
||||||
// do nothing since '*' is calculated and always valid.
|
// do nothing since '*' is calculated and always valid.
|
||||||
|
} else if (typeof value === 'string') {
|
||||||
|
// This is invalid because the only valid string is '*'
|
||||||
|
|
||||||
|
output.error({
|
||||||
|
title: 'Configuration Error',
|
||||||
|
bodyLines: [
|
||||||
|
`nx.json is not configured properly. "${path.join(
|
||||||
|
' > '
|
||||||
|
)}" is improperly configured to implicitly depend on "${value}" but should be an array of project names or "*".`,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
} else if (Array.isArray(value)) {
|
} else if (Array.isArray(value)) {
|
||||||
acc.push([entry[0], value]);
|
acc.push([entry[0], value]);
|
||||||
} else {
|
} else {
|
||||||
Object.values(value).forEach((v) => {
|
Object.entries(value).forEach(([k, v]) => {
|
||||||
recur(v, acc);
|
recur(v, acc, [...path, k]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recur(entry[1], acc);
|
recur(entry[1], acc, [entry[0]]);
|
||||||
return acc;
|
return acc;
|
||||||
}, [])
|
}, [])
|
||||||
.reduce((map, [filename, projectNames]: [string, string[]]) => {
|
.reduce((map, [filename, projectNames]: [string, string[]]) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user