Skip to content

Commit 8f0d129

Browse files
committed
fix(core): handle self-referencing build dependencies (#5177)
* fix(core): handle self-referencing build dependencies * chore: revert e2e trigger * fix(core): handle self-referencing virtual workspace build dependencies
1 parent 06cec36 commit 8f0d129

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

.yarn/versions/6059c9c1.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-link"
18+
- "@yarnpkg/plugin-nm"
19+
- "@yarnpkg/plugin-npm"
20+
- "@yarnpkg/plugin-npm-cli"
21+
- "@yarnpkg/plugin-pack"
22+
- "@yarnpkg/plugin-patch"
23+
- "@yarnpkg/plugin-pnp"
24+
- "@yarnpkg/plugin-pnpm"
25+
- "@yarnpkg/plugin-stage"
26+
- "@yarnpkg/plugin-typescript"
27+
- "@yarnpkg/plugin-version"
28+
- "@yarnpkg/plugin-workspace-tools"
29+
- "@yarnpkg/builder"
30+
- "@yarnpkg/doctor"
31+
- "@yarnpkg/extensions"
32+
- "@yarnpkg/nm"
33+
- "@yarnpkg/pnpify"
34+
- "@yarnpkg/sdks"

packages/acceptance-tests/pkg-tests-specs/sources/commands/install.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,70 @@ describe(`Commands`, () => {
444444
),
445445
);
446446

447+
test(
448+
`should support a self-referencing build dependency`,
449+
makeTemporaryEnv(
450+
{
451+
name: `foo`,
452+
dependencies: {
453+
'no-deps': `1.0.0`,
454+
},
455+
scripts: {
456+
postinstall: `echo foo`,
457+
},
458+
},
459+
async ({path, run, source}) => {
460+
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
461+
packageExtensions: {
462+
'no-deps@*': {
463+
dependencies: {
464+
foo: `workspace:*`,
465+
},
466+
},
467+
},
468+
});
469+
470+
await expect(run(`install`, `--inline-builds`)).resolves.toMatchObject({
471+
code: 0,
472+
});
473+
},
474+
),
475+
);
476+
477+
test(
478+
`should support a self-referencing virtual workspace build dependency`,
479+
makeTemporaryMonorepoEnv(
480+
{
481+
workspaces: [`packages/*`],
482+
},
483+
{
484+
'packages/foo': {
485+
name: `foo`,
486+
peerDependencies: {
487+
'no-deps': `1.0.0`,
488+
},
489+
dependencies: {
490+
bar: `workspace:*`,
491+
},
492+
scripts: {
493+
postinstall: `echo foo`,
494+
},
495+
},
496+
'packages/bar': {
497+
name: `bar`,
498+
dependencies: {
499+
foo: `workspace:*`,
500+
},
501+
},
502+
},
503+
async ({path, run, source}) => {
504+
await expect(run(`install`, `--inline-builds`)).resolves.toMatchObject({
505+
code: 0,
506+
});
507+
},
508+
),
509+
);
510+
447511
test(
448512
`it should print a warning when using \`enableScripts: false\``,
449513
makeTemporaryEnv({

packages/yarnpkg-core/sources/Project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ export class Project {
13281328
if (!resolution)
13291329
throw new Error(`Assertion failed: The resolution (${structUtils.prettyDescriptor(this.configuration, dependency)}) should have been registered`);
13301330

1331-
if (buildablePackages.has(resolution))
1331+
if (resolution !== locator.locatorHash && buildablePackages.has(resolution))
13321332
return false;
13331333

13341334
// Virtual workspaces don't have build scripts but the original might so we need to check it.
@@ -1338,7 +1338,7 @@ export class Project {
13381338

13391339
const workspace = this.tryWorkspaceByLocator(dependencyPkg);
13401340
if (workspace) {
1341-
if (buildablePackages.has(workspace.anchoredLocator.locatorHash))
1341+
if (workspace.anchoredLocator.locatorHash !== locator.locatorHash && buildablePackages.has(workspace.anchoredLocator.locatorHash))
13421342
return false;
13431343

13441344
hashesToCheck.add(workspace.anchoredLocator.locatorHash);

0 commit comments

Comments
 (0)