Skip to content

Commit

Permalink
Fixes dependencies using bins from their own dependencies (#6712)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis authored Nov 21, 2018
1 parent 0d48610 commit 77f04c3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "one-dep-scripted",
"version": "1.0.0",
"dependencies": {
"has-bin-entries": "1.0.0"
},
"scripts": {
"install": "has-bin-entries"
}
}
12 changes: 12 additions & 0 deletions packages/pkg-tests/pkg-tests-specs/sources/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,17 @@ module.exports = (makeTemporaryEnv: PackageDriver) => {
]);
}),
);

test(
`it should allow dependencies with install scripts to run the binaries exposed by their own dependencies`,
makeTemporaryEnv(
{
dependencies: {[`one-dep-scripted`]: `1.0.0`},
},
async ({path, run, source}) => {
await run(`install`);
},
),
);
});
};
16 changes: 13 additions & 3 deletions src/util/execute-lifecycle-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,21 @@ export async function makeEnv(
}
}

const pnpFile = `${config.lockfileFolder}/${constants.PNP_FILENAME}`;
if (await fs.exists(pnpFile)) {
let pnpFile;

if (process.versions.pnp) {
pnpFile = dynamicRequire.resolve('pnpapi');
} else {
const candidate = `${config.lockfileFolder}/${constants.PNP_FILENAME}`;
if (await fs.exists(candidate)) {
pnpFile = candidate;
}
}

if (pnpFile) {
const pnpApi = dynamicRequire(pnpFile);

const packageLocator = pnpApi.findPackageLocator(`${config.cwd}/`);
const packageLocator = pnpApi.findPackageLocator(`${cwd}/`);
const packageInformation = pnpApi.getPackageInformation(packageLocator);

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

0 comments on commit 77f04c3

Please sign in to comment.