-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Adds the directory that contains Node to the PATH #5743
Conversation
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.
I'd love to see a unit test for this too.
@@ -173,3 +173,15 @@ exports.readJson = async function readJson(source: string): Promise<any> { | |||
throw new Error(`Invalid json file (${source})`); | |||
} | |||
}; | |||
|
|||
exports.chmod = function chmod(target: string, mod: number): Promise<void> { | |||
return fs.chmod(target, mod); |
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.
Why is the return type for this, is a promise?
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.
const fs = require('fs-extra');
fs-extra exposes the fs functions but make them promise-ready.
target: string, | ||
{output = `Fake binary`, exitCode = 1}: {|output: string, exitCode: number|} = {}, | ||
): Promise<void> { | ||
await exports.writeFile(target, `#!/bin/sh\necho "${output}"\nexit ${exitCode}\n`); |
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.
You should probably escape output
properly.
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.
I think it's fine. These utilities aren't used with user input or anything really complex, so I prefer to keep them simple.
@@ -142,6 +142,10 @@ export async function makeEnv( | |||
const envPath = env[constants.ENV_PATH_KEY]; | |||
const pathParts = envPath ? envPath.split(path.delimiter) : []; | |||
|
|||
// Include the directory that contains node so that we can guarantee that the scripts | |||
// will always run with the exact same Node release than the one use to run Yarn | |||
pathParts.unshift(path.dirname(process.execPath)); |
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.
We should probably assign path.dirname(process.execPath)
to a variable at this point since it is calculated over and over below.
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.
Yep, but I already plan to refactor this part in a followup!
Summary
This diff orders Yarn to run the lifecycle scripts with a PATH configured to offer in priority the same
node
binary used to run Yarn itself. This change makes Yarn more coherent since we were previously doing this for node-gyp.Test plan
Added a test to pkg-tests