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

fix(core) resolve cwd using realpath when running yarn commands in a workspace #2659

Merged
merged 4 commits into from
May 3, 2021
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
31 changes: 31 additions & 0 deletions .yarn/versions/b469be37.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
releases:
"@yarnpkg/core": patch
"@yarnpkg/cli": patch


declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/pnpify"
24 changes: 23 additions & 1 deletion packages/yarnpkg-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,29 @@ async function initializeWorkspaceEnvironment(workspace: Workspace, {binFolder,
)
);

return {manifest: workspace.manifest, binFolder, env, cwd: cwd ?? workspace.cwd};
// When operating under PnP, `initializePackageEnvironment`
// yields package location to the linker, which goes into
// the PnP hook, which resolves paths relative to dirname,
// which is realpath'd (because of Node). The realpath that
// follows ensures that workspaces are realpath'd in a
// similar way.
//
// I'm not entirely comfortable with this, especially because
// there are no tests pertaining to this behaviour and the use
// case is still a bit fuzzy to me (something about Flow not
// handling well the case where a project was 1:1 symlinked
// into another place, I think?). I also don't like the idea
// of realpathing thing in general, since it means losing
// information...
//
// It's fine for now because it preserves a behaviour in 3.x
// that was already there in 2.x, but it should be considered
// for removal or standardization if it ever becomes a problem.
//
if (typeof cwd === `undefined`)
cwd = ppath.dirname(await xfs.realpathPromise(ppath.join(workspace.cwd, `package.json` as Filename)));

return {manifest: workspace.manifest, binFolder, env, cwd};
}

async function initializePackageEnvironment(locator: Locator, {project, binFolder, cwd, lifecycleScript}: {project: Project, binFolder: PortablePath, cwd?: PortablePath | undefined, lifecycleScript?: string}) {
Expand Down