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

Adds the directory that contains Node to the PATH #5743

Merged
merged 3 commits into from
Apr 26, 2018
Merged

Adds the directory that contains Node to the PATH #5743

merged 3 commits into from
Apr 26, 2018

Conversation

arcanis
Copy link
Member

@arcanis arcanis commented Apr 26, 2018

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

@arcanis arcanis requested a review from BYK April 26, 2018 14:44
Copy link
Member

@BYK BYK left a 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);
Copy link
Member

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?

Copy link
Member Author

@arcanis arcanis Apr 26, 2018

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`);
Copy link
Member

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.

Copy link
Member Author

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));
Copy link
Member

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.

Copy link
Member Author

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!

@arcanis arcanis merged commit 7312d9d into master Apr 26, 2018
@arcanis arcanis deleted the node-bin branch August 13, 2018 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants