Skip to content

Commit

Permalink
Fix scalacenter#99: Relax NPM dependency version conflict resolution (s…
Browse files Browse the repository at this point in the history
…calacenter#215)

* feat: Delegate a version conflict resolution to npm/yarn if npmResolutions not provided.

* doc: Add a description regarding delegation to npm/yarn
  • Loading branch information
TATSUNO Yasuhiro authored and exoego committed Feb 10, 2018
1 parent adcdb6e commit 4f72105
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ object PackageJson {
case Seq(single) =>
name -> single
case _ =>
val resolution =
resolutions.getOrElse(name, sys.error(s"Different versions of '$name' are required: $versions, but no “resolution” has been provided."))
val resolution = resolutions.get(name) match {
case Some(v) => v
case None => versions.mkString(" ")
}
name -> resolution
}
resolvedDependency :: result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ object ScalaJSBundlerPlugin extends AutoPlugin {
* will be picked. But if all the projects depend on the same version of `react`, the version
* given in `npmResolutions` will be ignored.
*
* If different versions of the packages are referred but the package is NOT configured in `npmResolutions`,
* a version conflict resolution is delegated to npm/yarn. This behavior may reduce a need to configure
* `npmResolutions` explicitly. E.g. "14.4.2" can be automatically-picked for ">=14.0.0 14.4.2 ^14.4.1".
*
* Note that this key must be scoped by a `Configuration` (either `Compile` or `Test`).
*
* @group settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ val sub3 =
npmDependencies in Compile += "react" -> "15.3.2"
)

val sub4 =
proj("sub4")
.settings(
npmDependencies in Compile += "react" -> ">=15.3.2"
)

val checkPackageJson = taskKey[Unit]("Check that the package.json file does not contain duplicate entries for the 'react' dependency")

val noConflicts =
Expand All @@ -38,6 +44,10 @@ val resolution =
npmResolutions in Compile := Map("react" -> "15.4.1")
)

val delegatedToPackageManager =
proj("delegatedToPackageManager")
.dependsOn(sub1, sub4)

def proj(id: String): Project =
Project(id, file(id))
.enablePlugins(ScalaJSBundlerPlugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
> no-conflicts/checkPackageJson
-> conflict/npmUpdate
> resolution/npmUpdate
> delegatedToPackageManager/npmUpdate

0 comments on commit 4f72105

Please sign in to comment.