Skip to content

Commit

Permalink
Fixes yarn run when used on workspaces + pnp
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Sep 27, 2018
1 parent 3fc13c1 commit 93415ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/cli/commands/run.js
Expand Up @@ -36,14 +36,15 @@ export async function getBinEntries(config: Config): Promise<Map<string, string>
// Same thing, but for the pnp dependencies, located inside the cache
if (await fs.exists(`${config.lockfileFolder}/${constants.PNP_FILENAME}`)) {
const pnpApi = dynamicRequire(`${config.lockfileFolder}/${constants.PNP_FILENAME}`);
const topLevelInformation = pnpApi.getPackageInformation({name: null, reference: null});

for (const [name, reference] of topLevelInformation.packageDependencies.entries()) {
const packageLocator = pnpApi.getPackageLocator(`${config.cwd}/`);
const packageInformation = pnpApi.getPackageInformation(packageLocator);

for (const [name, reference] of packageInformation.packageDependencies.entries()) {
const dependencyInformation = pnpApi.getPackageInformation({name, reference});

if (dependencyInformation.packageLocation) {
const fullPath = path.resolve(config.lockfileFolder, dependencyInformation.packageLocation);
binFolders.add(`${fullPath}/.bin`);
binFolders.add(`${dependencyInformation.packageLocation}/.bin`);
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/util/execute-lifecycle-script.js
Expand Up @@ -212,15 +212,13 @@ export async function makeEnv(
}
}

// Otherwise, only add the top-level dependencies to the PATH
// Note that this isn't enough when executing scripts from subdependencies, but since dependencies with postinstall
// scripts have other issues that require us to make them fallback to regular node_modules installation (like sharing
// artifacts), we can sit on this one until we fix everything at once.
if (await fs.exists(`${config.lockfileFolder}/${constants.PNP_FILENAME}`)) {
const pnpApi = dynamicRequire(`${config.lockfileFolder}/${constants.PNP_FILENAME}`);
const topLevelInformation = pnpApi.getPackageInformation({name: null, reference: null});

for (const [name, reference] of topLevelInformation.packageDependencies.entries()) {
const packageLocator = pnpApi.getPackageLocator(`${config.cwd}/`);
const packageInformation = pnpApi.getPackageInformation(packageLocator);

for (const [name, reference] of packageInformation.packageDependencies.entries()) {
const dependencyInformation = pnpApi.getPackageInformation({name, reference});

if (!dependencyInformation || !dependencyInformation.packageLocation) {
Expand Down

0 comments on commit 93415ec

Please sign in to comment.