Skip to content

Commit 193b11d

Browse files
committed
Add npmRegistry as first class citizen node config parameter
1 parent 3052d9b commit 193b11d

File tree

10 files changed

+18
-18
lines changed

10 files changed

+18
-18
lines changed

docs/faq.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,3 @@ This can be done adding some arguments to the already defined `npmInstall`-task.
3131
```gradle
3232
npmInstall.args = ['--loglevel', 'silly']
3333
```
34-
35-
# How do I specify a registry for the NPM setup task?
36-
37-
This can be done by adding to the arguments for the already defined `npmSetup` task.
38-
39-
```gradle
40-
tasks.npmSetup {
41-
doFirst {
42-
args = args + ['--registry', 'http://myregistry.npm.com']
43-
}
44-
}
45-
```
46-
47-
You can also add any other arguments to this list that work with `npm install` i.e. more verbose modes.

docs/node.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ node {
179179
// Base URL for fetching node distributions (change if you have a mirror).
180180
distBaseUrl = 'https://nodejs.org/dist'
181181
182+
// Registry to use for yarn or npm
183+
npmRegistry = 'http://myregistry.npm.com'
184+
182185
// If true, it will download node using above parameters.
183186
// If false, it will try to use globally installed node.
184187
download = true

examples/simple-yarn/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apply plugin: 'com.moowork.node'
22

33
node {
44
download = true
5+
npmRegistry = 'https://registry.npmjs.org/'
56
}
67

78
task helloWorld( type: NodeTask, dependsOn: 'yarn' ) {

src/main/groovy/com/moowork/gradle/node/NodeExtension.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class NodeExtension
1111

1212
File npmWorkDir
1313

14+
String npmRegistry = 'https://registry.npmjs.org'
15+
1416
File yarnWorkDir
1517

1618
File nodeModulesDir

src/main/groovy/com/moowork/gradle/node/npm/NpmSetupTask.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class NpmSetupTask
4343
set.add( getConfig().download )
4444
set.add( getConfig().npmVersion )
4545
set.add( getConfig().npmWorkDir )
46+
set.add( getConfig().npmRegistry )
4647
return set
4748
}
4849

@@ -109,7 +110,7 @@ class NpmSetupTask
109110
if ( !npmVersion.isEmpty() )
110111
{
111112
logger.debug( "Setting npmVersion to ${npmVersion}" )
112-
setArgs( ['install', '--global', '--no-save', '--prefix', getVariant().npmDir, "npm@${npmVersion}"] )
113+
setArgs( ['install', '--global', '--no-save', '--registry', getVariant().npmRegistry, '--prefix', getVariant().npmDir, "npm@${npmVersion}"] )
113114
enabled = true
114115
}
115116
}

src/main/groovy/com/moowork/gradle/node/variant/Variant.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class Variant
1818

1919
def String npmExec
2020

21+
def String npmRegistry
22+
2123
def File npmDir
2224

2325
def File npmBinDir

src/main/groovy/com/moowork/gradle/node/variant/VariantBuilder.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class VariantBuilder
3030

3131
variant.nodeDir = getNodeDir( osName, osArch )
3232
variant.npmDir = ext.npmVersion ? getNpmDir() : variant.nodeDir
33+
variant.npmRegistry = ext.npmRegistry
3334
variant.yarnDir = getYarnDir()
3435

3536
variant.nodeBinDir = variant.nodeDir
@@ -118,7 +119,7 @@ class VariantBuilder
118119
}
119120
}
120121

121-
//https://github.com/nodejs/node/pull/5995
122+
//https://github.com/nodejs/node/pull/5995
122123
private boolean hasWindowsZip()
123124
{
124125
def version = this.ext.version

src/main/groovy/com/moowork/gradle/node/yarn/YarnSetupTask.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class YarnSetupTask
2626
def set = new HashSet<>()
2727
set.add( this.getConfig().download )
2828
set.add( this.getConfig().yarnVersion )
29+
set.add( this.getConfig().npmRegistry )
2930
return set
3031
}
3132

@@ -45,7 +46,7 @@ class YarnSetupTask
4546
pkg += "@${yarnVersion}"
4647
}
4748

48-
this.setArgs( ['install', '--global', '--no-save', '--prefix', this.getVariant().yarnDir, pkg] )
49+
this.setArgs( ['install', '--global', '--no-save', '--registry', getVariant().npmRegistry, '--prefix', this.getVariant().yarnDir, pkg] )
4950
enabled = true
5051
}
5152
}

src/test/groovy/com/moowork/gradle/node/NodeExtensionTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class NodeExtensionTest
1818
ext.workDir != null
1919
ext.nodeModulesDir != null
2020
ext.version == '10.15.3'
21+
ext.npmRegistry == 'https://registry.npmjs.org'
2122
!ext.download
2223
ext.npmVersion == ''
2324
}

src/test/groovy/com/moowork/gradle/node/variant/VariantBuilderTest.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class VariantBuilderTest
3737
def ext = new NodeExtension(project)
3838
ext.download = true
3939
ext.version = '0.11.1'
40+
ext.npmRegistry = 'http://myregistry.npm.com'
4041
ext.workDir = new File('.gradle/node').absoluteFile
4142

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

5153
variant.nodeDir.toString().endsWith(NODE_BASE_PATH + nodeDir)
5254
variant.nodeBinDir.toString().endsWith(NODE_BASE_PATH + nodeDir)
@@ -92,7 +94,7 @@ class VariantBuilderTest
9294
'x86' | 'node-v4.0.0-win-x86' | 'org.nodejs:win-x86/node:4.0.0@exe'
9395
'x86_64' | 'node-v4.0.0-win-x64' | 'org.nodejs:win-x64/node:4.0.0@exe'
9496
}
95-
97+
9698
@Unroll
9799
def "test variant on windows without exe (#osArch)"()
98100
{

0 commit comments

Comments
 (0)