Skip to content
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
5 changes: 5 additions & 0 deletions .yarn/versions/a46c1d8d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
releases:
"@yarnpkg/plugin-nm": patch

declined:
- "@yarnpkg/cli"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "one-dep-alias-bins",
"version": "1.0.0",
"dependencies": {
"@fixture/old": "npm:has-bin-entries@1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {WindowsLinkType} from '@yarnpkg/core';
import {xfs, npath, PortablePath, ppath, Filename} from '@yarnpkg/fslib';
import {parseSyml} from '@yarnpkg/parsers';


const {
Expand Down Expand Up @@ -150,6 +151,34 @@ describe(`Node_Modules`, () => {
),
);

test(`should prefer direct dependency bins over transitive dependency bins`,
makeTemporaryEnv(
{
dependencies: {
[`@fixture/native`]: `npm:has-bin-entries@2.0.0`,
[`has-bin-entries`]: `npm:one-dep-alias-bins@1.0.0`,
},
},
{
nodeLinker: `node-modules`,
},
async ({path, run}) => {
await run(`install`);

const installState = parseSyml(await xfs.readFilePromise(ppath.join(path, `node_modules/.yarn-state.yml` as PortablePath), `utf8`));
const rootState = Object.values<any>(installState).find(({locations}) => locations?.includes(``));

expect(rootState?.bin?.[`.`]?.[`has-bin-entries-with-relative-require`]).toEqual(`@fixture/native/bin-with-relative-require.js`);

if (process.platform !== `win32`) {
await expect(run(`node`, `${path}/node_modules/.bin/has-bin-entries-with-relative-require`)).resolves.toMatchObject({
stdout: `2.0.0\n`,
});
}
},
),
);

test(`should support dependency via link: protocol to a missing folder`,
makeTemporaryEnv(
{
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-nm/sources/NodeModulesLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,9 @@ async function createBinSymlinkMap(installState: NodeModulesLocatorMap, location
for (const [childLocation, childNode] of node.children) {
const childSymlinks = getBinSymlinks(ppath.join(location, childLocation), parentLocatorLocation, childNode);
for (const [name, symlinkTarget] of childSymlinks) {
symlinks.set(name, symlinkTarget);
if (!symlinks.has(name)) {
symlinks.set(name, symlinkTarget);
}
}
}
}
Expand Down
Loading