gradle-node-plugin
gradle-node-plugin copied to clipboard
Custom .npmrc for npmSetup task
Hi!
If custom npm version is chosen, e.g. 5.7.1, then plugin installs it with
npm install --global [email protected] ...other flags
it works well in dev environment, however fails on CI environment if remote registry requires authentication, and there is no way to update agent's global settings.
The question - is there a way to use custom .npmrc file for this scenario?
If not, could you extend existing configuration with custom npmrc file location?
Thank you!
I've checked this issue, however I think .npmrc from project dir will be ignored in case of installing with --global
flag.
I think I've found a workaround. Plugin uses --prefix
attribute to set custom global location for installed npm, pointing to "$projectDir/.gradle/npm/npm-v$npmVersion". So we can copy custom config to this location before the npmSetup task.
def customNpmVersion = '5.7.1'
node {
npmVersion = customNpmVersion
}
// generate/copy custom config to 'global' folder
task customNpmrc() {
doLast {
def customConfig = """
# custom .npmrc content goes here
"""
def configFolder = "$projectDir/.gradle/npm/npm-v$customNpmVersion/etc"
file(configFolder).mkdirs()
file("$configFolder/npmrc").text = customConfig;
}
}
// add new task as a dependency to npmSetup
tasks.npmSetup.dependsOn customNpmrc
It depends on plugin's internal logic, so I'll keep this open to get more opinions on correct solution.
npm has a --userconfig=/path/to/.npmrc flag you can pass, is there an option to add additional paramaters to the npm install command or npm build?
My workaround:
npmSetup {
doFirst {
copy {
from '.npmrc'
into "${node.npmWorkDir}/npm-v${node.npmVersion}/etc"
rename '.npmrc', 'npmrc'
}
}
}
Hi guys,
I'm trying to use a custom .npmrc to be able to authenticate on azure pipelines.
I've noticed that npm is being installed on "build/npm/npm-v6.9.0/lib/node_modules/npm/npmrc" I've tried to changed the content of this file with the authentication value and then run the nodesetup but it doesn't seems to be working.
any new ideas?
@lopesdasilva , npm will try to load the ~/.npmrc file, if you want a more specific path then you would do --userconfig=/path/to/your/.npmrc
Is there some way to have the registry for the yarn install/npm install? I.e. I got the package installation AFTER the yarn/npm is installed already but I need the yarn/npm installation to come from a specific artifactory as well.
I tried using the workaround above but it'll still grab the package from https://registry.npmjs.org/yarn