Skip to content

fix(nm): Support portals to external interdependent workspaces #4207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .yarn/versions/e724089e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/nm": patch
"@yarnpkg/plugin-nm": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/pnpify"
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Yarn now accepts sponsorships! Please give a look at our [OpenCollective](https:

**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>`).

### Installs

- The node-modules linker does not fail anymore if portal dependency points to an external project with multiple interdependent workspaces
## 3.2.0

Various improvements have been made in the core to improve performance. Additionally:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1619,4 +1619,53 @@ describe(`Node_Modules`, () => {
});
}),
);

it(`should support portals to external workspaces`,
makeTemporaryEnv(
{
workspaces: [`ws`],
dependencies: {
'no-deps': `1.0.0`,
},
},
{
nodeLinker: `node-modules`,
},
async ({path, run}) => {
await xfs.mktempPromise(async portalTarget => {
await xfs.writeJsonPromise(`${path}/package.json` as PortablePath, {
dependencies: {
ws1: `^1.0.0`,
ws2: `^1.0.0`,
},
resolutions: {
ws1: `portal:${portalTarget}/ws1`,
ws2: `portal:${portalTarget}/ws2`,
},
});

await xfs.writeJsonPromise(`${portalTarget}/package.json` as PortablePath, {
name: `portal`,
workspaces: [`ws1`, `ws2`],
});

await xfs.mkdirpPromise(ppath.join(portalTarget, `ws1` as PortablePath));
await xfs.writeJsonPromise(`${portalTarget}/ws1/package.json` as PortablePath, {
name: `ws1`,
workspaces: [`ws1`],
});

await xfs.mkdirpPromise(ppath.join(portalTarget, `ws2` as PortablePath));
await xfs.writeJsonPromise(`${portalTarget}/ws2/package.json` as PortablePath, {
name: `ws2`,
workspaces: [`ws2`],
dependencies: {
ws1: `^1.0.0`,
},
});

await expect(run(`install`)).resolves.not.toThrow();
});
}),
);
});
2 changes: 1 addition & 1 deletion packages/yarnpkg-nm/sources/buildNodeModulesTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ const buildPackageTree = (pnp: PnpApi, options: NodeModulesTreeOptions): { packa
}
}

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

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