Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

NPM/Yarn is downloaded from the default registry if npmVersion or yarnVersion is set #226

Closed
rkrisztian opened this issue Jun 8, 2017 · 3 comments
Labels
Milestone

Comments

@rkrisztian
Copy link

If you have this in your Gradle script:

node {
    npmVersion = '5.0.1'
    download = true
}

Or this:

node {
    yarnVersion = '0.23.4'
    download = true
}

Then NPM/Yarn will be downloaded from registry.npmjs.org, rather than from the mirror site I set in <PROJECT_DIR>/.npmrc.

The reason is, when installing a global package (npm install -g --prefix=<PROJECT_DIR>/.gradle/npm/... npm@<VERSION>), the registry setting in <PROJECT_DIR>/.npmrc is not used.

So far I know the followings:

  • What works:
    ** Set registry=http://my-registry.com:1234/repository/ in ~/.npmrc. (A project-level setting would be more ideal for my company though.)
  • What does not work:
    ** npmSetup.args += ['--registry=http://my-registry.com:1234/repository/'] yarnSetup.args += ['--registry=http://my-registry.com:1234/repository/'] (In those tasks, args is write-only, according to Gradle.
@srs
Copy link
Owner

srs commented Jun 14, 2017

Ah, right. The args should be modified to allow to be added too. Will mark this as a bug.

@srs srs added the bug label Jun 14, 2017
@srs srs added this to the 1.2.0 milestone Jun 14, 2017
@srs srs closed this as completed in ec89c78 Jun 14, 2017
@mconner
Copy link

mconner commented Aug 1, 2017

How is this supposed to be used? (Not a Gradle expert, so bear with me). The plugin apply() does:

        this.project.afterEvaluate {
            this.config.variant = new VariantBuilder( this.config ).build()
            configureSetupTask()
            configureNpmSetupTask()
            configureYarnSetupTask()
        }

and configureNpmSetupTask calls npmSetupTask.configureVersion, which set the args:

    void configureVersion( String npmVersion )
    {
        if ( !npmVersion.isEmpty() )
        {
            logger.debug( "Setting npmVersion to ${npmVersion}" )
            setArgs( ['install', '--global', '--no-save', '--prefix', getVariant().npmDir, "npm@${npmVersion}"] )
            enabled = true
        }
    }

This apparently overwrites them if I try do do npmSetup.arg += ..., as indicated by @rkrisztian:
It does seem to work if I do this in an afterEvaluate, but that seems an odd way to define that, and I'm not sure if its guaranteed who comes first, project or plugin.

@rkrisztian
Copy link
Author

rkrisztian commented Aug 2, 2017

@mconner, I use it like this:

afterEvaluate() {
    npmSetup.args += ['--registry=https://some.url/here/']
}

But I agree that the plugin shouldn't be using afterEvaluate to initialize the arguments, as that is a bad design that also forces us to have to use afterEvaluate as well.

(This ticket is closed though, so IMO I should ask you to open a new one with your info.)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants