Skip to content

Commit 77f04c3

Browse files
authored
Fixes dependencies using bins from their own dependencies (#6712)
1 parent 0d48610 commit 77f04c3

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* @flow */
2+
3+
module.exports = require(`./package.json`);
4+
5+
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
6+
for (const dep of Object.keys(module.exports[key] || {})) {
7+
// $FlowFixMe The whole point of this file is to be dynamic
8+
module.exports[key][dep] = require(dep);
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "one-dep-scripted",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"has-bin-entries": "1.0.0"
6+
},
7+
"scripts": {
8+
"install": "has-bin-entries"
9+
}
10+
}

packages/pkg-tests/pkg-tests-specs/sources/script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,17 @@ module.exports = (makeTemporaryEnv: PackageDriver) => {
203203
]);
204204
}),
205205
);
206+
207+
test(
208+
`it should allow dependencies with install scripts to run the binaries exposed by their own dependencies`,
209+
makeTemporaryEnv(
210+
{
211+
dependencies: {[`one-dep-scripted`]: `1.0.0`},
212+
},
213+
async ({path, run, source}) => {
214+
await run(`install`);
215+
},
216+
),
217+
);
206218
});
207219
};

src/util/execute-lifecycle-script.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,21 @@ export async function makeEnv(
203203
}
204204
}
205205

206-
const pnpFile = `${config.lockfileFolder}/${constants.PNP_FILENAME}`;
207-
if (await fs.exists(pnpFile)) {
206+
let pnpFile;
207+
208+
if (process.versions.pnp) {
209+
pnpFile = dynamicRequire.resolve('pnpapi');
210+
} else {
211+
const candidate = `${config.lockfileFolder}/${constants.PNP_FILENAME}`;
212+
if (await fs.exists(candidate)) {
213+
pnpFile = candidate;
214+
}
215+
}
216+
217+
if (pnpFile) {
208218
const pnpApi = dynamicRequire(pnpFile);
209219

210-
const packageLocator = pnpApi.findPackageLocator(`${config.cwd}/`);
220+
const packageLocator = pnpApi.findPackageLocator(`${cwd}/`);
211221
const packageInformation = pnpApi.getPackageInformation(packageLocator);
212222

213223
for (const [name, reference] of packageInformation.packageDependencies.entries()) {

0 commit comments

Comments
 (0)