diff --git a/src/cli/commands/_execute-lifecycle-script.js b/src/cli/commands/_execute-lifecycle-script.js index 49febbac02..427d79a949 100644 --- a/src/cli/commands/_execute-lifecycle-script.js +++ b/src/cli/commands/_execute-lifecycle-script.js @@ -15,11 +15,21 @@ export async function execFromManifest(config: Config, commandName: string, pkg: } const cmd: ?string = pkg.scripts[commandName]; - if (cmd) { + if (cmd && isValidCommand(commandName, cmd)) { await execCommand(commandName, config, cmd, cwd); } } +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)) { + return false; + } + + return true; +} + export async function execCommand(stage: string, config: Config, cmd: string, cwd: string): Promise { const {reporter} = config; try {