From 9a0b90989e5872b28a6ba76b3d1f841731e77d86 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sun, 3 Jul 2022 16:32:35 -0600 Subject: [PATCH 1/3] Remove scalajs-bundler --- build.sbt | 17 ++++++++--------- project/plugins.sbt | 1 - .../src/main/scala/com/alexitc/Chrome.scala | 12 +++--------- .../scala/com/alexitc/ChromeSbtPlugin.scala | 6 +----- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/build.sbt b/build.sbt index c0d4b49..d26992d 100644 --- a/build.sbt +++ b/build.sbt @@ -16,8 +16,6 @@ inThisBuild( ThisBuild / versionScheme := Some("early-semver") -publish / skip := true - lazy val commonSettings = Seq( scalacOptions ++= { Seq( @@ -45,8 +43,6 @@ lazy val commonSettings = Seq( ) ) -lazy val commonPlugins = Seq() - lazy val bindings = project .in(file("bindings")) .settings(commonSettings: _*) @@ -59,9 +55,7 @@ lazy val bindings = project ), scalaJSUseMainModuleInitializer := true ) - .enablePlugins(commonPlugins: _*) .enablePlugins(ScalaJSPlugin) - .enablePlugins(ScalaJSBundlerPlugin) lazy val plugin = project .in(file("sbt-plugin")) @@ -77,7 +71,12 @@ lazy val plugin = project "org.scalatest" %% "scalatest" % "3.2.11" % "test" ) }, - addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.0"), - addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.20.0") + addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.0") + ) + +val root = project + .in(file(".")) + .aggregate(bindings, plugin) + .settings( + publish / skip := true ) - .enablePlugins(commonPlugins: _*) diff --git a/project/plugins.sbt b/project/plugins.sbt index 0d6663e..e842b21 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,3 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.0") -addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.20.0") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") diff --git a/sbt-plugin/src/main/scala/com/alexitc/Chrome.scala b/sbt-plugin/src/main/scala/com/alexitc/Chrome.scala index c9afada..cf0b6bd 100644 --- a/sbt-plugin/src/main/scala/com/alexitc/Chrome.scala +++ b/sbt-plugin/src/main/scala/com/alexitc/Chrome.scala @@ -15,16 +15,10 @@ object Chrome { }.toMap } - // TODO: I'm not sure if the jsDeps are actually useful but I'm keeping those just because - // the original plugin had them, now that we use scalajs-bundler, it can be that we need - // to re-work the source maps strategy for js dependencies - def buildUnpackedDirectory( - unpacked: File - )(manifest: File, jsLib: File, jsDeps: Seq[File], resources: Seq[File]): File = { - val libsAndDependencies = - List(jsLib -> unpacked / jsLib.getName) ++ jsDeps.map(file => file -> unpacked / file.getName) + def buildUnpackedDirectory(unpacked: File)(manifest: File, jsLib: File, resources: Seq[File]): File = { + val libsAndDependencies = List(jsLib -> unpacked / jsLib.getName) - val sourceMaps = (List(jsLib) ++ jsDeps) + val sourceMaps = List(jsLib) .map { sourceFile => val fileName = sourceFile.getName + ".map" val originalSourceMap = sourceFile.getParentFile / fileName diff --git a/sbt-plugin/src/main/scala/com/alexitc/ChromeSbtPlugin.scala b/sbt-plugin/src/main/scala/com/alexitc/ChromeSbtPlugin.scala index e42bb1c..a1d6f60 100644 --- a/sbt-plugin/src/main/scala/com/alexitc/ChromeSbtPlugin.scala +++ b/sbt-plugin/src/main/scala/com/alexitc/ChromeSbtPlugin.scala @@ -5,12 +5,10 @@ import org.scalajs.sbtplugin.ScalaJSPlugin import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.* import sbt.* import sbt.Keys.* -import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin -import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport.* object ChromeSbtPlugin extends AutoPlugin { - override def requires: Plugins = ScalaJSPlugin && ScalaJSBundlerPlugin + override def requires: Plugins = ScalaJSPlugin object autoImport { @@ -30,7 +28,6 @@ object ChromeSbtPlugin extends AutoPlugin { Chrome.buildUnpackedDirectory(target.value / chromeDir / "unpacked-fast")( (Compile / chromeGenerateManifest).value, fastOptJsLib.value.data, - (Compile / fastOptJS / webpack).value.map(_.data), (Compile / resourceDirectories).value ) }, @@ -39,7 +36,6 @@ object ChromeSbtPlugin extends AutoPlugin { Chrome.buildUnpackedDirectory(target.value / chromeDir / "unpacked-opt")( (Compile / chromeGenerateManifest).value, fullOptJsLib.value.data, - (Compile / fullOptJS / webpack).value.map(_.data), (Compile / resourceDirectories).value ) }, From 31bfc42ea3cc752ea171642d774e435d1de458e0 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sun, 3 Jul 2022 18:33:11 -0600 Subject: [PATCH 2/3] Update examples --- .github/workflows/pull_request.yml | 13 +++++++++++++ .gitignore | 1 + examples/README.md | 5 +++++ examples/build.sbt | 26 ++++++-------------------- examples/project/plugins.sbt | 6 +++--- 5 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 examples/README.md diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 11b2df3..ebfec6c 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -25,3 +25,16 @@ jobs: - name: Run tests run: sbt test + + - name: Publish local + run: sbt +publishLocal + + # Examples + - name: Compile examples - check library version + run: sbt version | tail -n 1 | awk -F " " '{print $2}' > .version + + - name: Compile examples - set library version + run: sed -i -e "s#SCALAJS_CHROME_VERSION#$(cat .version)#" examples/project/plugins.sbt && sed -i -e "s#SCALAJS_CHROME_VERSION#$(cat .version)#" examples/build.sbt + + - name: Compile examples + run: cd examples && sbt compile diff --git a/.gitignore b/.gitignore index a3e09e7..8394ae2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target/ .DS_Store .bsp/ *.iml +.version diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..42cc1c4 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,5 @@ +# Examples + +These are simple application examples. + +NOTE: Update `project/plugins.sbt` and `build.sbt` to set the library version. diff --git a/examples/build.sbt b/examples/build.sbt index 93a65f7..a20c23f 100644 --- a/examples/build.sbt +++ b/examples/build.sbt @@ -3,13 +3,12 @@ import chrome.permissions.Permission import chrome.permissions.Permission.{API, Host} import com.alexitc.{Chrome, ChromeSbtPlugin} -lazy val examples = project.in(file(".")).aggregate(exampleApp, extension) +lazy val scalajsChromeV = "SCALAJS_CHROME_VERSION" -lazy val scalaJsChrome = ProjectRef(file("../."), "bindings") +lazy val examples = project.in(file(".")).aggregate(exampleApp, extension) lazy val exampleApp = project .in(file("app")) - .dependsOn(scalaJsChrome) .enablePlugins(ChromeSbtPlugin) .settings( name := "Example App", @@ -23,12 +22,12 @@ lazy val exampleApp = project "-Xfatal-warnings", "-feature" ), + libraryDependencies += "com.alexitc" %%% "scala-js-chrome" % scalajsChromeV, scalaJSUseMainModuleInitializer := true, Test / scalaJSUseMainModuleInitializer := false, scalaJSLinkerConfig := scalaJSLinkerConfig.value.withRelativizeSourceMapBase( Some((Compile / fastOptJS / artifactPath).value.toURI) ), - packageJSDependencies / skip := false, // you can customize and have a static output name for lib and dependencies // instead of having the default files names like app-fastopt.js, ... (Compile / fastOptJS / artifactPath) := { @@ -37,19 +36,13 @@ lazy val exampleApp = project (Compile / fullOptJS / artifactPath) := { (fullOptJS / crossTarget).value / "main.js" }, - (Compile / packageJSDependencies / artifactPath) := { - (packageJSDependencies / crossTarget).value / "dependencies.js" - }, - (Compile / packageMinifiedJSDependencies / artifactPath) := { - (packageMinifiedJSDependencies / crossTarget).value / "dependencies.js" - }, chromeManifest := new AppManifest { val name = Keys.name.value val version = Keys.version.value val app = App( background = Background( - scripts = List("main.js", "dependencies.js") + scripts = List("main.js", "main-bundle.js") ) ) override val defaultLocale = Some("en") @@ -72,7 +65,6 @@ lazy val exampleApp = project lazy val extension = project .in(file("extension")) - .dependsOn(scalaJsChrome) .enablePlugins(ChromeSbtPlugin) .settings( name := "Example Extension", @@ -86,12 +78,12 @@ lazy val extension = project "-Xfatal-warnings", "-feature" ), + libraryDependencies += "com.alexitc" %%% "scala-js-chrome" % scalajsChromeV, scalaJSUseMainModuleInitializer := true, Test / scalaJSUseMainModuleInitializer := false, scalaJSLinkerConfig := scalaJSLinkerConfig.value.withRelativizeSourceMapBase( Some((Compile / fastOptJS / artifactPath).value.toURI) ), - packageJSDependencies / skip := false, // you can customize and have a static output name for lib and dependencies // instead of having the default files names like extension-fastopt.js, ... (Compile / fastOptJS / artifactPath) := { @@ -100,16 +92,10 @@ lazy val extension = project (Compile / fullOptJS / artifactPath) := { (fullOptJS / crossTarget).value / "main.js" }, - (Compile / packageJSDependencies / artifactPath) := { - (packageJSDependencies / crossTarget).value / "dependencies.js" - }, - (Compile / packageMinifiedJSDependencies / artifactPath) := { - (packageMinifiedJSDependencies / crossTarget).value / "dependencies.js" - }, chromeManifest := new ExtensionManifest { val background = Background( - scripts = List("main.js", "dependencies.js") + scripts = List("main.js", "main-bundle.js") ) val name = Keys.name.value val version = Keys.version.value diff --git a/examples/project/plugins.sbt b/examples/project/plugins.sbt index 79c4d6d..c93b84a 100644 --- a/examples/project/plugins.sbt +++ b/examples/project/plugins.sbt @@ -1,3 +1,3 @@ -import sbt._ -lazy val sbtPlugin = ProjectRef(file("../../."), "plugin") -lazy val root = project.in(file(".")).dependsOn(sbtPlugin) +lazy val scalajsChromeV = "SCALAJS_CHROME_VERSION" + +addSbtPlugin("com.alexitc" % "sbt-chrome-plugin" % scalajsChromeV) From 25b1b8fee8ebc5cf6e933abeac45c0571e8bbb7f Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Mon, 4 Jul 2022 07:58:10 -0600 Subject: [PATCH 3/3] Sample --- .github/workflows/pull_request.yml | 10 +++++----- build.sbt | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ebfec6c..49b20e3 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -30,11 +30,11 @@ jobs: run: sbt +publishLocal # Examples - - name: Compile examples - check library version - run: sbt version | tail -n 1 | awk -F " " '{print $2}' > .version + - name: Update examples/build.sbt + run: sbt printVersion && sed -i -e "s#SCALAJS_CHROME_VERSION#$(cat .version)#" examples/build.sbt - - name: Compile examples - set library version - run: sed -i -e "s#SCALAJS_CHROME_VERSION#$(cat .version)#" examples/project/plugins.sbt && sed -i -e "s#SCALAJS_CHROME_VERSION#$(cat .version)#" examples/build.sbt + - name: Update examples/project/plugins.sbt + run: sbt printVersion && sed -i -e "s#SCALAJS_CHROME_VERSION#$(cat .version)#" examples/project/plugins.sbt - name: Compile examples - run: cd examples && sbt compile + run: cd examples && cat build.sbt && sbt chromePackage diff --git a/build.sbt b/build.sbt index d26992d..f5b435b 100644 --- a/build.sbt +++ b/build.sbt @@ -1,3 +1,5 @@ +import java.nio.file.Files + inThisBuild( List( organization := "com.alexitc", @@ -16,6 +18,8 @@ inThisBuild( ThisBuild / versionScheme := Some("early-semver") +lazy val printVersion = TaskKey[Unit]("printVersion") + lazy val commonSettings = Seq( scalacOptions ++= { Seq( @@ -78,5 +82,9 @@ val root = project .in(file(".")) .aggregate(bindings, plugin) .settings( - publish / skip := true + publish / skip := true, + printVersion := { + val targetFile = baseDirectory.value / ".version" + Files.write(targetFile.toPath, version.value.getBytes(IO.utf8)) + } )