Skip to content

Commit

Permalink
Change npmSetup to install npm into the cache directory rather than n…
Browse files Browse the repository at this point in the history
…ode_modles directory so that it's not deleted by yarn.

By this change, the npmSetup-installed npm is not deleted by npm with
shrinkwrap.
  • Loading branch information
kaitoy committed Nov 23, 2016
1 parent 3c68e19 commit 00cc0c8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 595 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ You can configure the plugin using the "node" extension block, like this:
// Set the work directory for unpacking node
workDir = file("${project.buildDir}/nodejs")

// Set the work directory for NPM
npmWorkDir = file("${project.buildDir}/npm")

// Set the work directory for Yarn
yarnWorkDir = file("${project.buildDir}/yarn")

Expand All @@ -203,13 +206,13 @@ You can configure the plugin using the "node" extension block, like this:
Using a Custom (project-local) Version of `npm`
-----------------------------------------------

The plugin will use a locally-installed `npm` if it exists, regardless of the
method of installation.
If `npmVersion` is specified, the plugin installs that version of `npm` into `npmWorkDir`
by the `npmSetup` task and use it.

If `npmVersion` is not specified and a locally-installed `npm` exists, The plugin will
use it.

If you would like the plugin to install use a custom version of npm rather than
the one bundled with the version of node installation, you can set `npmVersion`
in the `node` extension block. The plugin will install the npm to the project's
`node_modules` directory by configuring the `npmSetup` task.
Otherwise, the plugin will use the `npm` bundled with the version of node installation.

Using a Custom (project-local) Version of `yarn`
-----------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,11 @@ class NpmRule_integTest
copyResources( 'fixtures/npm-missing/package.json', 'package.json' )

when:
def result = runTasksSuccessfully( 'npm_run_parent' )
def result = runTasksSuccessfully( 'npm_run_echoTest' )

then:
result.success
fileExists( 'child1.txt' )
fileExists( 'child2.txt' )
fileExists( 'parent1.txt' )
fileExists( 'parent2.txt' )
}

def 'fails to run npm module using npm_run_ when shrinkwrap removes local npm'()
{
given:
writeBuild( '''
apply plugin: 'com.moowork.node'
node {
version = "5.9.0"
npmVersion = "3.8.3"
download = true
}
''' )

copyResources( 'fixtures/npm-missing/package.json', 'package.json' )
copyResources( 'fixtures/npm-missing/npm-shrinkwrap.json', 'npm-shrinkwrap.json' )

when:
def result = runTasksWithFailure( 'npm_run_parent' )

then:
result.failure != null
result.standardError.contains( 'Could not run npm command - local npm not found but requested in gradle node' )
result.standardError.contains( '3.8.3' )
fileExists( 'test.txt' )
}

def 'succeeds to run npm module using npm_run_ when shrinkwrap contains local npm'()
Expand Down
Loading

0 comments on commit 00cc0c8

Please sign in to comment.