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
23 changes: 23 additions & 0 deletions .yarn/versions/944c0a3d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": 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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

console.log(require(`./package.json`).version);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@scoped/has-bin-entry",
"version": "2.0.0",
"bin": {
"@scoped/has-bin-entry": "./bin.js"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,81 @@ describe(`Node_Modules`, () => {
),
);

it(`should set correct permissions on binaries in installed packages`,
makeTemporaryEnv(
{
dependencies: {
[`has-bin-entries`]: `1.0.0`,
},
},
{
nodeLinker: `node-modules`,
},
async ({path, run}) => {
await run(`install`);
const {mode} = await xfs.lstatPromise(npath.toPortablePath(`${path}/node_modules/has-bin-entries/bin.js`));
const permissions = (mode & 0o777).toString(8);
expect(permissions).toBe(process.platform === `win32` ? `666` : `755`);
},
),
);

it(`should set correct permissions on binaries in packages that were upgraded`,
makeTemporaryEnv(
{
dependencies: {
[`has-bin-entries`]: `1.0.0`,
[`scoped/has-bin-entry`]: `1.0.0`,
},
},
{
nodeLinker: `node-modules`,
},
async ({path, run}) => {
await run(`install`);
await xfs.writeJsonPromise(`${path}/package.json` as PortablePath, {
dependencies: {
'has-bin-entries': `2.0.0`,
'@scoped/has-bin-entry': `2.0.0`,
},
});
await run(`install`);

const binaries = [
`has-bin-entries/bin.js`,
`@scoped/has-bin-entry/bin.js`,
];

for (const binary of binaries) {
const {mode} = await xfs.lstatPromise(npath.toPortablePath(`${path}/node_modules/${binary}`));
const permissions = (mode & 0o777).toString(8);
expect(permissions).toBe(process.platform === `win32` ? `666` : `755`);
}
},
),
);

it(`should reinstall and set correct permissions on next install when packages have been deleted by the user`,
makeTemporaryEnv(
{
dependencies: {
[`has-bin-entries`]: `1.0.0`,
},
},
{
nodeLinker: `node-modules`,
},
async ({path, run}) => {
await run(`install`);
await xfs.removePromise(`${path}/node_modules/has-bin-entries` as PortablePath);
await run(`install`);
const {mode} = await xfs.lstatPromise(npath.toPortablePath(`${path}/node_modules/has-bin-entries/bin.js`));
const permissions = (mode & 0o777).toString(8);
expect(permissions).toBe(process.platform === `win32` ? `666` : `755`);
},
),
);

it(`should only reinstall scoped dependencies deleted by the user on the next install`,
makeTemporaryEnv(
{
Expand Down
23 changes: 23 additions & 0 deletions packages/plugin-nm/sources/NodeModulesLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,28 @@ export function getGlobalHardlinksStore(configuration: Configuration): PortableP
return ppath.join(configuration.get(`globalFolder`), `store` as Filename);
}

/**
* Mutate binSymlinks by removing binaries related to the changedLocations.
*/
function invalidateBinSymlinks(binSymlinks: BinSymlinkMap, changedLocations: Set<PortablePath>): void {
const getLocationPackageRoot = (targetPath: PortablePath): PortablePath => {
const parts = targetPath.split(ppath.sep);
const nmIndex = parts.lastIndexOf(NODE_MODULES);
if (nmIndex < 0 || nmIndex == parts.length - 1)
throw new Error(`Assertion failed. Path is outside of any node_modules package ${targetPath}`);

return parts.slice(0, nmIndex + (parts[nmIndex + 1].startsWith(`@`) ? 3 : 2)).join(ppath.sep) as PortablePath;
};

for (const binSymlinkMap of binSymlinks.values()) {
for (const [binFile, binLocation] of binSymlinkMap) {
if (changedLocations.has(getLocationPackageRoot(binLocation))) {
binSymlinkMap.delete(binFile);
}
}
}
}

async function persistNodeModules(preinstallState: InstallState, installState: NodeModulesLocatorMap, {baseFs, project, report, loadManifest, realLocatorChecksums}: {project: Project, baseFs: FakeFS<PortablePath>, report: Report, loadManifest: LoadManifest, realLocatorChecksums: Map<LocatorHash, string | null>}) {
const rootNmDirPath = ppath.join(project.cwd, NODE_MODULES);

Expand Down Expand Up @@ -1314,6 +1336,7 @@ async function persistNodeModules(preinstallState: InstallState, installState: N

await xfs.mkdirPromise(rootNmDirPath, {recursive: true});

invalidateBinSymlinks(prevBinSymlinks, new Set(addList.map(l => l.dstDir)));
const binSymlinks = await createBinSymlinkMap(installState, locationTree, project.cwd, {loadManifest});
await persistBinSymlinks(prevBinSymlinks, binSymlinks, project.cwd, windowsLinkType);

Expand Down