Skip to content
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

Fixes dependencies using bins from their own dependencies #6712

Merged
merged 1 commit into from
Nov 21, 2018
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
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