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

Prevent yarn install from getting in an infinite loop #1374

Closed
wants to merge 1 commit into from
Closed

Prevent yarn install from getting in an infinite loop #1374

wants to merge 1 commit into from

Conversation

wyze
Copy link
Member

@wyze wyze commented Oct 22, 2016

Summary

This fixes #1227. It adds a check before executing the (pre/post)install lifecycle methods to make sure it won't get into an infinite loop. Not sure if this is the best way to handle it, so feedback is welcome.

Test plan

The lifecycle methods (pre/post)install can no longer get in a yarn install infinite loop.

function isValidCommand(commandName: string, cmd: string): boolean {
// prevent infinite loop (see: https://github.com/yarnpkg/yarn/issues/1227)
// blocks `yarn`, `yarn i`, `yarn install`, with any flags as well
if (commandName.endsWith('install') && /^yarn(\si(nstall)?)?(\s\-.*)?$/.test(cmd)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can just return the opposite of this

if (boolean) {
    return false;
}

return true;

is a bit of an anti-pattern.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understand that. I was leaving it more open in case there are future exceptions that need to be made. I can always change it now to just return the opposite of the conditional and could revisit this pattern in the future when another condition is needed.

@sebmck
Copy link
Contributor

sebmck commented Oct 24, 2016

See my comment in #1227.

@sebmck sebmck closed this Oct 24, 2016
@wyze wyze deleted the lifecycle-infinite-loop branch October 24, 2016 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding a script to package.json called "install" creates an infinite loop
5 participants