Skip to content

Commit

Permalink
Add npmRegistry as first class citizen node config parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nowheresly committed Sep 21, 2019
1 parent 3052d9b commit 6952df9
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cache:
- $HOME/.gradle

jdk:
- oraclejdk8
- openjdk8

script:
- ./gradlew ci --stacktrace
Expand Down
14 changes: 0 additions & 14 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,3 @@ This can be done adding some arguments to the already defined `npmInstall`-task.
```gradle
npmInstall.args = ['--loglevel', 'silly']
```

# How do I specify a registry for the NPM setup task?

This can be done by adding to the arguments for the already defined `npmSetup` task.

```gradle
tasks.npmSetup {
doFirst {
args = args + ['--registry', 'http://myregistry.npm.com']
}
}
```

You can also add any other arguments to this list that work with `npm install` i.e. more verbose modes.
3 changes: 3 additions & 0 deletions docs/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ node {
// Base URL for fetching node distributions (change if you have a mirror).
distBaseUrl = 'https://nodejs.org/dist'
// Registry to use for yarn or npm
npmRegistry = 'http://myregistry.npm.com'
// If true, it will download node using above parameters.
// If false, it will try to use globally installed node.
download = true
Expand Down
1 change: 1 addition & 0 deletions examples/simple-yarn/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.moowork.node'

node {
download = true
npmRegistry = 'https://registry.npmjs.org/'
}

task helloWorld( type: NodeTask, dependsOn: 'yarn' ) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/groovy/com/moowork/gradle/node/NodeExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class NodeExtension

File npmWorkDir

String npmRegistry = 'https://registry.npmjs.org'

File yarnWorkDir

File nodeModulesDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class NpmSetupTask
set.add( getConfig().download )
set.add( getConfig().npmVersion )
set.add( getConfig().npmWorkDir )
set.add( getConfig().npmRegistry )
return set
}

Expand Down Expand Up @@ -109,7 +110,7 @@ class NpmSetupTask
if ( !npmVersion.isEmpty() )
{
logger.debug( "Setting npmVersion to ${npmVersion}" )
setArgs( ['install', '--global', '--no-save', '--prefix', getVariant().npmDir, "npm@${npmVersion}"] )
setArgs( ['install', '--global', '--no-save', '--registry', getVariant().npmRegistry, '--prefix', getVariant().npmDir, "npm@${npmVersion}"] )
enabled = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Variant

def String npmExec

def String npmRegistry

def File npmDir

def File npmBinDir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class VariantBuilder

variant.nodeDir = getNodeDir( osName, osArch )
variant.npmDir = ext.npmVersion ? getNpmDir() : variant.nodeDir
variant.npmRegistry = ext.npmRegistry
variant.yarnDir = getYarnDir()

variant.nodeBinDir = variant.nodeDir
Expand Down Expand Up @@ -118,7 +119,7 @@ class VariantBuilder
}
}

//https://github.com/nodejs/node/pull/5995
//https://github.com/nodejs/node/pull/5995
private boolean hasWindowsZip()
{
def version = this.ext.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class YarnSetupTask
def set = new HashSet<>()
set.add( this.getConfig().download )
set.add( this.getConfig().yarnVersion )
set.add( this.getConfig().npmRegistry )
return set
}

Expand All @@ -45,7 +46,7 @@ class YarnSetupTask
pkg += "@${yarnVersion}"
}

this.setArgs( ['install', '--global', '--no-save', '--prefix', this.getVariant().yarnDir, pkg] )
this.setArgs( ['install', '--global', '--no-save', '--registry', getVariant().npmRegistry, '--prefix', this.getVariant().yarnDir, pkg] )
enabled = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class NodeExtensionTest
ext.workDir != null
ext.nodeModulesDir != null
ext.version == '10.15.3'
ext.npmRegistry == 'https://registry.npmjs.org'
!ext.download
ext.npmVersion == ''
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class VariantBuilderTest
def ext = new NodeExtension(project)
ext.download = true
ext.version = '0.11.1'
ext.npmRegistry = 'http://myregistry.npm.com'
ext.workDir = new File('.gradle/node').absoluteFile

def builder = new VariantBuilder(ext)
Expand All @@ -47,6 +48,7 @@ class VariantBuilderTest
variant.windows
variant.exeDependency == exeDependency
variant.archiveDependency == 'org.nodejs:node:0.11.1:[email protected]'
variant.npmRegistry == 'http://myregistry.npm.com'

variant.nodeDir.toString().endsWith(NODE_BASE_PATH + nodeDir)
variant.nodeBinDir.toString().endsWith(NODE_BASE_PATH + nodeDir)
Expand Down Expand Up @@ -92,7 +94,7 @@ class VariantBuilderTest
'x86' | 'node-v4.0.0-win-x86' | 'org.nodejs:win-x86/node:4.0.0@exe'
'x86_64' | 'node-v4.0.0-win-x64' | 'org.nodejs:win-x64/node:4.0.0@exe'
}
@Unroll
def "test variant on windows without exe (#osArch)"()
{
Expand Down

0 comments on commit 6952df9

Please sign in to comment.