sbt / sbt-web

Library for building sbt plugins for the web
Other
368 stars 64 forks source link

WebKeys.importDirectly is broken in sbt 2.0 #263

Open BillyAutrey opened 4 hours ago

BillyAutrey commented 4 hours ago

Issue

The following test fails under sbt 2.0.

https://github.com/sbt/sbt-web/blob/main/src/sbt-test/sbt-web/multi-module/build.sbt#L16

Short version

sbt 2 changes the default value for exportJars := true. This changes underlying logic to calculate exportable assets.

Deeper Explanation

The corresponding check for e.js at modules/c/target/web/public/main/js/e.js fails:

[info] [error] (fileCheckC) java.lang.AssertionError: assertion failed: Could not find e.js

In SbtWeb.scala, importDirectly works by looking for internalWebModules. This call looks for mapping metadata with the key webModulesLib here. https://github.com/sbt/sbt-web/blob/b92d20e7db95474fd3af8d5c826994555572797a/src/main/scala/com/typesafe/sbt/web/SbtWeb.scala#L464

In sbt 1, here's an example of the corresponding metadata in this same test:

(analysis: Analysis: , artifact: Artifact(e, jar, jar, None, Vector(compile), None, Map(), None, false), moduleID: e:e:0.1.0-SNAPSHOT, configuration: compile)
(webModulesLib: e)
(analysis: Analysis: , artifact: Artifact(x, jar, jar, None, Vector(compile), None, Map(), None, false), moduleID: x:x:0.1.0-SNAPSHOT, configuration: compile)

In sbt 2, the webModulesLib entry doesn't exist at all.

The code that sets this attribute is in exportProducts, which is called when exportedProducts is originally set.

https://github.com/sbt/sbt-web/blob/b92d20e7db95474fd3af8d5c826994555572797a/src/main/scala/com/typesafe/sbt/web/SbtWeb.scala#L434-L441

Compile / exportedProducts is added to via exportAssets https://github.com/sbt/sbt-web/blob/b92d20e7db95474fd3af8d5c826994555572797a/src/main/scala/com/typesafe/sbt/web/SbtWeb.scala#L254

https://github.com/sbt/sbt-web/blob/b92d20e7db95474fd3af8d5c826994555572797a/src/main/scala/com/typesafe/sbt/web/SbtWeb.scala#L414-L432

Note that line 419 checks the state of exportJars. This changes the export of assets, which doesn't break most things. But in this case, if exportJars := false is set for module/c, this particular test passes. Others do not, however.

BillyAutrey commented 4 hours ago

This is also blocking #255