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(() => {
|
||||
mockNxJson = {
|
||||
implicitDependencies: {
|
||||
'nx.json': '*',
|
||||
},
|
||||
projects: {
|
||||
app1: {
|
||||
tags: [],
|
||||
@ -126,4 +129,23 @@ describe('assertWorkspaceValidity', () => {
|
||||
});
|
||||
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 || {}
|
||||
)
|
||||
.reduce((acc, entry) => {
|
||||
function recur(value, acc = []) {
|
||||
function recur(value, acc = [], path: string[]) {
|
||||
if (value === '*') {
|
||||
// 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)) {
|
||||
acc.push([entry[0], value]);
|
||||
} else {
|
||||
Object.values(value).forEach((v) => {
|
||||
recur(v, acc);
|
||||
Object.entries(value).forEach(([k, v]) => {
|
||||
recur(v, acc, [...path, k]);
|
||||
});
|
||||
}
|
||||
}
|
||||
recur(entry[1], acc);
|
||||
recur(entry[1], acc, [entry[0]]);
|
||||
return acc;
|
||||
}, [])
|
||||
.reduce((map, [filename, projectNames]: [string, string[]]) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user