Skip to content

Commit 24a1724

Browse files
larixermerceyz
authored andcommitted
Linker doesn't try to create self-reference symlinks for external portals (#4207)
1 parent 630757e commit 24a1724

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

.yarn/versions/e724089e.yml

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

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Yarn now accepts sponsorships! Please give a look at our [OpenCollective](https:
88

99
**Note:** features in `master` can be tried out by running `yarn set version from sources` in your project (existing contrib plugins are updated automatically, while new contrib plugins can be added by running `yarn plugin import from sources <name>`).
1010

11+
### Installs
12+
13+
- The node-modules linker does not fail anymore if portal dependency points to an external project with multiple interdependent workspaces
1114
## 3.2.0
1215

1316
Various improvements have been made in the core to improve performance. Additionally:

packages/acceptance-tests/pkg-tests-specs/sources/node-modules.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,4 +1619,53 @@ describe(`Node_Modules`, () => {
16191619
});
16201620
}),
16211621
);
1622+
1623+
it(`should support portals to external workspaces`,
1624+
makeTemporaryEnv(
1625+
{
1626+
workspaces: [`ws`],
1627+
dependencies: {
1628+
'no-deps': `1.0.0`,
1629+
},
1630+
},
1631+
{
1632+
nodeLinker: `node-modules`,
1633+
},
1634+
async ({path, run}) => {
1635+
await xfs.mktempPromise(async portalTarget => {
1636+
await xfs.writeJsonPromise(`${path}/package.json` as PortablePath, {
1637+
dependencies: {
1638+
ws1: `^1.0.0`,
1639+
ws2: `^1.0.0`,
1640+
},
1641+
resolutions: {
1642+
ws1: `portal:${portalTarget}/ws1`,
1643+
ws2: `portal:${portalTarget}/ws2`,
1644+
},
1645+
});
1646+
1647+
await xfs.writeJsonPromise(`${portalTarget}/package.json` as PortablePath, {
1648+
name: `portal`,
1649+
workspaces: [`ws1`, `ws2`],
1650+
});
1651+
1652+
await xfs.mkdirpPromise(ppath.join(portalTarget, `ws1` as PortablePath));
1653+
await xfs.writeJsonPromise(`${portalTarget}/ws1/package.json` as PortablePath, {
1654+
name: `ws1`,
1655+
workspaces: [`ws1`],
1656+
});
1657+
1658+
await xfs.mkdirpPromise(ppath.join(portalTarget, `ws2` as PortablePath));
1659+
await xfs.writeJsonPromise(`${portalTarget}/ws2/package.json` as PortablePath, {
1660+
name: `ws2`,
1661+
workspaces: [`ws2`],
1662+
dependencies: {
1663+
ws1: `^1.0.0`,
1664+
},
1665+
});
1666+
1667+
await expect(run(`install`)).resolves.not.toThrow();
1668+
});
1669+
}),
1670+
);
16221671
});

packages/yarnpkg-nm/sources/buildNodeModulesTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ const buildPackageTree = (pnp: PnpApi, options: NodeModulesTreeOptions): { packa
367367
}
368368
}
369369

370-
if (pkg !== parentPkg || pkg.linkType !== LinkType.SOFT || !options.selfReferencesByCwd || options.selfReferencesByCwd.get(parentRelativeCwd))
370+
if (pkg !== parentPkg || pkg.linkType !== LinkType.SOFT || (!isExternalSoftLinkPackage && (!options.selfReferencesByCwd || options.selfReferencesByCwd.get(parentRelativeCwd))))
371371
parent.dependencies.add(node);
372372

373373
const isWorkspaceDependency = locator !== topLocator && pkg.linkType === LinkType.SOFT && !locator.name.endsWith(WORKSPACE_NAME_SUFFIX) && !isExternalSoftLinkPackage;

0 commit comments

Comments
 (0)