diff --git a/.travis.yml b/.travis.yml index 4617e8340..0d46c454e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ language: java -install: - - npm install os: - osx script: diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index a8c4eee24..055813062 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -90,14 +90,9 @@ $ sbt ## Run unit tests (JS) -The JS tests require node to be installed, and a few dependencies to have been -fetched with -``` -$ npm install -``` -(run from the root of the coursier sources). +The JS tests require node to be installed. They automatically run `npm install` from the root of the coursier sources if needed. -JS tests can then be run like JVM tests, like +JS tests can be run like JVM tests, like ``` $ sbt > ++2.12.4 @@ -190,4 +185,4 @@ we need to put 2) and 3) into `message`: Typically there needs to be at least 2 minor versions between since-version and to-be-removed-version to help migration. -For example, if since version is 1.1.0, then deprecation can be removed in 1.3.0 \ No newline at end of file +For example, if since version is 1.1.0, then deprecation can be removed in 1.3.0 diff --git a/build.sbt b/build.sbt index 117444581..75ceb061d 100644 --- a/build.sbt +++ b/build.sbt @@ -41,7 +41,8 @@ lazy val tests = crossProject .disablePlugins(ScriptedPlugin) .dependsOn(core, cache % "test", scalaz) .jsSettings( - scalaJSStage.in(Global) := FastOptStage + scalaJSStage.in(Global) := FastOptStage, + testOptions := testOptions.dependsOn(runNpmInstallIfNeeded).value ) .configs(Integration) .settings( diff --git a/project/Settings.scala b/project/Settings.scala index f3bf9985d..be5dfb024 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -1,4 +1,6 @@ +import java.nio.file.Files + import sbt._ import sbt.Keys._ import sbt.ScriptedPlugin.autoImport.{sbtLauncher, scriptedBufferLog, ScriptedLaunchConf, scriptedLaunchOpts} @@ -45,6 +47,28 @@ object Settings { javacOptions.in(Keys.doc) := Seq() ) + val runNpmInstallIfNeeded = Def.task { + val baseDir = baseDirectory.in(ThisBuild).value + val evFile = baseDir / "node_modules" / ".npm_run" + val log = streams.value.log + if (!evFile.exists()) { + val cmd = Seq("npm", "install") + val b = new ProcessBuilder(cmd: _*) + b.directory(baseDir) + b.inheritIO() + log.info(s"Running ${cmd.mkString(" ")}") + val p = b.start() + val retCode = p.waitFor() + if (retCode == 0) + log.info(s"${cmd.mkString(" ")} ran successfully") + else + sys.error(s"${cmd.mkString(" ")} failed (return code $retCode)") + + // Parent dir should have been created by npm install + Files.write(evFile.toPath, Array.emptyByteArray) + } + } + lazy val shared = javaScalaPluginShared ++ Seq( scalaVersion := scala212, libs ++= {