From 6952df9b9bb8da5b311002d658e30201683c0566 Mon Sep 17 00:00:00 2001 From: Sylvere Richard Date: Tue, 17 Sep 2019 23:25:39 +0200 Subject: [PATCH] Add npmRegistry as first class citizen node config parameter --- .travis.yml | 2 +- docs/faq.md | 14 -------------- docs/node.md | 3 +++ examples/simple-yarn/build.gradle | 1 + .../com/moowork/gradle/node/NodeExtension.groovy | 2 ++ .../moowork/gradle/node/npm/NpmSetupTask.groovy | 3 ++- .../com/moowork/gradle/node/variant/Variant.groovy | 2 ++ .../gradle/node/variant/VariantBuilder.groovy | 3 ++- .../moowork/gradle/node/yarn/YarnSetupTask.groovy | 3 ++- .../moowork/gradle/node/NodeExtensionTest.groovy | 1 + .../gradle/node/variant/VariantBuilderTest.groovy | 4 +++- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index b78de49..ad784ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ cache: - $HOME/.gradle jdk: -- oraclejdk8 +- openjdk8 script: - ./gradlew ci --stacktrace diff --git a/docs/faq.md b/docs/faq.md index f186512..ef39422 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -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. \ No newline at end of file diff --git a/docs/node.md b/docs/node.md index eaf5763..969df30 100644 --- a/docs/node.md +++ b/docs/node.md @@ -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 diff --git a/examples/simple-yarn/build.gradle b/examples/simple-yarn/build.gradle index 0cd918f..f97d5df 100644 --- a/examples/simple-yarn/build.gradle +++ b/examples/simple-yarn/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.moowork.node' node { download = true + npmRegistry = 'https://registry.npmjs.org/' } task helloWorld( type: NodeTask, dependsOn: 'yarn' ) { diff --git a/src/main/groovy/com/moowork/gradle/node/NodeExtension.groovy b/src/main/groovy/com/moowork/gradle/node/NodeExtension.groovy index 6319079..a64f0ae 100644 --- a/src/main/groovy/com/moowork/gradle/node/NodeExtension.groovy +++ b/src/main/groovy/com/moowork/gradle/node/NodeExtension.groovy @@ -11,6 +11,8 @@ class NodeExtension File npmWorkDir + String npmRegistry = 'https://registry.npmjs.org' + File yarnWorkDir File nodeModulesDir diff --git a/src/main/groovy/com/moowork/gradle/node/npm/NpmSetupTask.groovy b/src/main/groovy/com/moowork/gradle/node/npm/NpmSetupTask.groovy index 1e1d5ac..dcaebc1 100644 --- a/src/main/groovy/com/moowork/gradle/node/npm/NpmSetupTask.groovy +++ b/src/main/groovy/com/moowork/gradle/node/npm/NpmSetupTask.groovy @@ -43,6 +43,7 @@ class NpmSetupTask set.add( getConfig().download ) set.add( getConfig().npmVersion ) set.add( getConfig().npmWorkDir ) + set.add( getConfig().npmRegistry ) return set } @@ -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 } } diff --git a/src/main/groovy/com/moowork/gradle/node/variant/Variant.groovy b/src/main/groovy/com/moowork/gradle/node/variant/Variant.groovy index ffc5c4a..4488bfa 100644 --- a/src/main/groovy/com/moowork/gradle/node/variant/Variant.groovy +++ b/src/main/groovy/com/moowork/gradle/node/variant/Variant.groovy @@ -18,6 +18,8 @@ class Variant def String npmExec + def String npmRegistry + def File npmDir def File npmBinDir diff --git a/src/main/groovy/com/moowork/gradle/node/variant/VariantBuilder.groovy b/src/main/groovy/com/moowork/gradle/node/variant/VariantBuilder.groovy index ba074d6..dc7a321 100644 --- a/src/main/groovy/com/moowork/gradle/node/variant/VariantBuilder.groovy +++ b/src/main/groovy/com/moowork/gradle/node/variant/VariantBuilder.groovy @@ -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 @@ -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 diff --git a/src/main/groovy/com/moowork/gradle/node/yarn/YarnSetupTask.groovy b/src/main/groovy/com/moowork/gradle/node/yarn/YarnSetupTask.groovy index e41e956..e82b3a5 100644 --- a/src/main/groovy/com/moowork/gradle/node/yarn/YarnSetupTask.groovy +++ b/src/main/groovy/com/moowork/gradle/node/yarn/YarnSetupTask.groovy @@ -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 } @@ -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 } } diff --git a/src/test/groovy/com/moowork/gradle/node/NodeExtensionTest.groovy b/src/test/groovy/com/moowork/gradle/node/NodeExtensionTest.groovy index dfadeb8..0e87b42 100644 --- a/src/test/groovy/com/moowork/gradle/node/NodeExtensionTest.groovy +++ b/src/test/groovy/com/moowork/gradle/node/NodeExtensionTest.groovy @@ -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 == '' } diff --git a/src/test/groovy/com/moowork/gradle/node/variant/VariantBuilderTest.groovy b/src/test/groovy/com/moowork/gradle/node/variant/VariantBuilderTest.groovy index 7dc1b7a..f75d260 100644 --- a/src/test/groovy/com/moowork/gradle/node/variant/VariantBuilderTest.groovy +++ b/src/test/groovy/com/moowork/gradle/node/variant/VariantBuilderTest.groovy @@ -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) @@ -47,6 +48,7 @@ class VariantBuilderTest variant.windows variant.exeDependency == exeDependency variant.archiveDependency == 'org.nodejs:node:0.11.1:linux-x86@tar.gz' + variant.npmRegistry == 'http://myregistry.npm.com' variant.nodeDir.toString().endsWith(NODE_BASE_PATH + nodeDir) variant.nodeBinDir.toString().endsWith(NODE_BASE_PATH + nodeDir) @@ -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)"() {