-
Notifications
You must be signed in to change notification settings - Fork 995
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
Leverage PROJECT_CWD to set cwd in yarn 3 bin "proxies" #6199
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit c1478a7. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 14 targets
Sent with 💌 from NxCloud. |
✅ Deploy Preview for redwoodjs-docs canceled.
|
Yarn master Dom at it again, nice one! |
@@ -79,7 +79,7 @@ const loadDotEnvDefaultsMiddleware = () => { | |||
config({ | |||
path: path.join(getPaths().base, '.env'), | |||
defaults: path.join(getPaths().base, '.env.defaults'), | |||
encoding: 'utf8', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the default value
@@ -79,7 +79,7 @@ const loadDotEnvDefaultsMiddleware = () => { | |||
config({ | |||
path: path.join(getPaths().base, '.env'), | |||
defaults: path.join(getPaths().base, '.env.defaults'), | |||
encoding: 'utf8', | |||
multiline: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partly fixes #5657
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I didn't see this comment; I'll revisit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries! 👍👍👍
// Ensure we run all commands from the base of the RW project | ||
// even if you invoke from ./web or ./api | ||
const rwProjectRoot = requireFromCli('./dist/lib/index.js').getPaths().base | ||
process.chdir(rwProjectRoot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one (core) is already at the root, so no need to change to it
I've tested this locally and it works so far, so I'm going to merge once checks past and test again in canary. |
…9/redwood into fix/cell-prerender-graphql-fallback * 'fix/cell-prerender-graphql-fallback' of github.com:dac09/redwood: Stylistic suggestions Leverage PROJECT_CWD to set cwd in yarn 3 bin "proxies" (redwoodjs#6199) chore(cli): Add additional tests for sdl generator (redwoodjs#6200)
To upgrade RW projects to yarn 3, we had to make bin "proxy" files so that we could still access the bins of our dependencies. See #4444 for the full break down.
When you run a bin, yarn 3 sets the cwd to the workspace calling it. This revealed a hidden dependency in many of our CLI commands that expect the cwd to be the root, so we imported
getPaths
from@redwoodjs/cli
(an export of the one in@redwoodjs/internal
) in many of the bin proxy files to find the root and change to it.This works and has worked for a long time, but turns out to be a not-so-great idea because it means pulling in a massive amount of
@redwoodjs/internal
for any CLI command, and possibly introducing some indeterminacy around the way env vars are loaded.Instead of importing
getPaths
, this PR leverages thePROJECT_CWD
env var provided by yarn 3. It's value is what you expect. See https://yarnpkg.com/advanced/lifecycle-scripts/#environment-variables.Next step is to confirm whether or not this change fixes #5657.
Here's a visualization of the change using
0x
to generate a flamegraph:The exact command for reproduction is