fix(core): cross-workspace implicitDependencies should be safely ignored (#28845)
This commit is contained in:
parent
cc251e4378
commit
0fd3442e47
@ -767,3 +767,45 @@ describe('global installation', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('cross-workspace implicit dependencies', () => {
|
||||||
|
beforeAll(() =>
|
||||||
|
newProject({
|
||||||
|
packages: ['@nx/js'],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
afterAll(() => cleanupProject());
|
||||||
|
|
||||||
|
it('should successfully build a project graph when cross-workspace implicit dependencies are present', () => {
|
||||||
|
const npmPackage = uniq('npm-package');
|
||||||
|
runCLI(`generate @nx/workspace:npm-package ${npmPackage}`);
|
||||||
|
|
||||||
|
function setImplicitDependencies(deps: string[]) {
|
||||||
|
updateFile(join(npmPackage, 'package.json'), (content) => {
|
||||||
|
const json = JSON.parse(content);
|
||||||
|
json.nx = {
|
||||||
|
...json.nx,
|
||||||
|
implicitDependencies: deps,
|
||||||
|
};
|
||||||
|
return JSON.stringify(json, null, 2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// First set the implicit dependencies to an intentionally invalid value to prove the command fails during project graph construction
|
||||||
|
setImplicitDependencies(['this-project-does-not-exist']);
|
||||||
|
expect(
|
||||||
|
runCLI(`test ${npmPackage}`, {
|
||||||
|
silenceError: true,
|
||||||
|
})
|
||||||
|
).toContain('Failed to process project graph');
|
||||||
|
|
||||||
|
// Now set the implicit dependencies to a cross-workspace reference to prove that it is valid, despite not being resolvable in the current workspace
|
||||||
|
setImplicitDependencies(['nx-cloud:another-workspace']);
|
||||||
|
expect(
|
||||||
|
runCLI(`test ${npmPackage}`, {
|
||||||
|
silenceError: true,
|
||||||
|
})
|
||||||
|
).toContain('Successfully ran target test');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -114,7 +114,10 @@ function detectAndSetInvalidProjectGlobValues(
|
|||||||
const projectName = implicit.startsWith('!')
|
const projectName = implicit.startsWith('!')
|
||||||
? implicit.substring(1)
|
? implicit.substring(1)
|
||||||
: implicit;
|
: implicit;
|
||||||
|
// Do not error on cross-workspace implicit dependency references
|
||||||
|
if (projectName.startsWith('nx-cloud:')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return !(
|
return !(
|
||||||
projectConfigurations[projectName] ||
|
projectConfigurations[projectName] ||
|
||||||
findMatchingProjects([implicit], projects).length
|
findMatchingProjects([implicit], projects).length
|
||||||
|
|||||||
@ -49,7 +49,8 @@ export function findMatchingProjects(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const stringPattern of patterns) {
|
for (const stringPattern of patterns) {
|
||||||
if (!stringPattern.length) {
|
// Do not waste time attempting to look up cross-workspace references which will never match
|
||||||
|
if (!stringPattern.length || stringPattern.startsWith('nx-cloud:')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user