Skip to content

Commit 93415ec

Browse files
author
Maël Nison
committed
Fixes yarn run when used on workspaces + pnp
1 parent 3fc13c1 commit 93415ec

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

Diff for: src/cli/commands/run.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ export async function getBinEntries(config: Config): Promise<Map<string, string>
3636
// Same thing, but for the pnp dependencies, located inside the cache
3737
if (await fs.exists(`${config.lockfileFolder}/${constants.PNP_FILENAME}`)) {
3838
const pnpApi = dynamicRequire(`${config.lockfileFolder}/${constants.PNP_FILENAME}`);
39-
const topLevelInformation = pnpApi.getPackageInformation({name: null, reference: null});
4039

41-
for (const [name, reference] of topLevelInformation.packageDependencies.entries()) {
40+
const packageLocator = pnpApi.getPackageLocator(`${config.cwd}/`);
41+
const packageInformation = pnpApi.getPackageInformation(packageLocator);
42+
43+
for (const [name, reference] of packageInformation.packageDependencies.entries()) {
4244
const dependencyInformation = pnpApi.getPackageInformation({name, reference});
4345

4446
if (dependencyInformation.packageLocation) {
45-
const fullPath = path.resolve(config.lockfileFolder, dependencyInformation.packageLocation);
46-
binFolders.add(`${fullPath}/.bin`);
47+
binFolders.add(`${dependencyInformation.packageLocation}/.bin`);
4748
}
4849
}
4950
}

Diff for: src/util/execute-lifecycle-script.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,13 @@ export async function makeEnv(
212212
}
213213
}
214214

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

223-
for (const [name, reference] of topLevelInformation.packageDependencies.entries()) {
218+
const packageLocator = pnpApi.getPackageLocator(`${config.cwd}/`);
219+
const packageInformation = pnpApi.getPackageInformation(packageLocator);
220+
221+
for (const [name, reference] of packageInformation.packageDependencies.entries()) {
224222
const dependencyInformation = pnpApi.getPackageInformation({name, reference});
225223

226224
if (!dependencyInformation || !dependencyInformation.packageLocation) {

0 commit comments

Comments
 (0)