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

Allow the user env variable of CYPRESS_INSTALL_BINARY='' (an empty string) to take precedence over npm config #8488

Closed
weareoutman opened this issue Sep 3, 2020 · 5 comments · Fixed by #8596
Labels
topic: installation Issue during installation or downloading Cypress

Comments

@weareoutman
Copy link
Contributor

weareoutman commented Sep 3, 2020

Current behavior:

A user env variable of CYPRESS_INSTALL_BINARY='' (an empty string) cannot override the npm config.

We want to run cypress only in CI, so we put a CYPRESS_INSTALL_BINARY=0 in PROJECT/.npmrc to avoid all our developers to download the cypress binary, which is a big cost considering our poor network. And then add a user env variable in CI to let it do download. Since cypress releases frequently, a fixed version like CYPRESS_INSTALL_BINARY=5.1.0 is not a good approach. But CYPRESS_INSTALL_BINARY='' is not working too.

Desired behavior:

Allow the user env variable of CYPRESS_INSTALL_BINARY='' to take precedence over npm config. Or add a new keyword of CYPRESS_INSTALL_BINARY=auto or something like that.

Test code to reproduce

  1. Add CYPRESS_INSTALL_BINARY=0 in a project's .npmrc (or ~/.npmrc)
  2. Add export CYPRESS_INSTALL_BINARY='' in shell profile (e.g. ~/.bash_profile)
  3. Run npm install cypress

Possible fix

In https://github.com/cypress-io/cypress/blob/develop/cli/lib/util.js#L473

const envVar = process.env[varName]
// Instead of `if (envVar)`, prefer:
if (varName in process.env) {
  result = envVar
}

Or we can add an extra option of allowEmptyVar for getEnv to avoid potential breaking for all other env variables.

Versions

Cypress: 5.1.0
Operation systems: Mac OS 10.15, CentOS 7

@bahmutov bahmutov added the topic: installation Issue during installation or downloading Cypress label Sep 15, 2020
@bahmutov
Copy link
Contributor

Hi @weareoutman

Can you clarify what you mean by "so we put a CYPRESS_INSTALL_BINARY=0 in PROJECT/.npmrc" - you specify the environment variables in the .npmrc file? How does that look?

@weareoutman
Copy link
Contributor Author

@bahmutov Yes, we disable Cypress installation of our project by default by setting PROJECT/.npmrc to like this:

CYPRESS_INSTALL_BINARY=0

This works since at https://github.com/cypress-io/cypress/blob/develop/cli/lib/util.js#L467-L485 :

    const envVar = process.env[varName]
    const configVar = process.env[`npm_config_${varName}`]
    const packageConfigVar = process.env[`npm_package_config_${varName}`]

    let result

    if (envVar) {
      debug(`Using ${varName} from environment variable`)

      result = envVar
    } else if (configVar) {
      debug(`Using ${varName} from npm config`)

      result = configVar
    } else if (packageConfigVar) {
      debug(`Using ${varName} from package.json config`)

      result = packageConfigVar
    }

process.env[`npm_config_${varName}`] will be the var defined in .npmrc, which could be overridden if process.env[varName] exists.

So we disable Cypress installation in the PROJECT/.npmrc, which disable all developers from installing Cypress. And we also want the CI server to enable it by set global ENV which take precedence over project settings. But export CYPRESS_INSTALL_BINARY='' in global ENV will be ignored since it checks if (envVar), while empty string is considered as falsy.

@bahmutov
Copy link
Contributor

bahmutov commented Sep 19, 2020 via email

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 22, 2020

The code for this is done in cypress-io/cypress#8596, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 29, 2020

Released in 5.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.3.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: installation Issue during installation or downloading Cypress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants