Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove scalajs bundler #132

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ jobs:

- name: Run tests
run: sbt test

- name: Publish local
run: sbt +publishLocal

# Examples
- name: Update examples/build.sbt
run: sbt printVersion && 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 && cat build.sbt && sbt chromePackage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ target/
.DS_Store
.bsp/
*.iml
.version
23 changes: 15 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.nio.file.Files

inThisBuild(
List(
organization := "com.alexitc",
Expand All @@ -16,7 +18,7 @@ inThisBuild(

ThisBuild / versionScheme := Some("early-semver")

publish / skip := true
lazy val printVersion = TaskKey[Unit]("printVersion")

lazy val commonSettings = Seq(
scalacOptions ++= {
Expand Down Expand Up @@ -45,8 +47,6 @@ lazy val commonSettings = Seq(
)
)

lazy val commonPlugins = Seq()

lazy val bindings = project
.in(file("bindings"))
.settings(commonSettings: _*)
Expand All @@ -59,9 +59,7 @@ lazy val bindings = project
),
scalaJSUseMainModuleInitializer := true
)
.enablePlugins(commonPlugins: _*)
.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalaJSBundlerPlugin)

lazy val plugin = project
.in(file("sbt-plugin"))
Expand All @@ -77,7 +75,16 @@ 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,
printVersion := {
val targetFile = baseDirectory.value / ".version"
Files.write(targetFile.toPath, version.value.getBytes(IO.utf8))
}
)
.enablePlugins(commonPlugins: _*)
5 changes: 5 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Examples

These are simple application examples.

NOTE: Update `project/plugins.sbt` and `build.sbt` to set the library version.
26 changes: 6 additions & 20 deletions examples/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) := {
Expand All @@ -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")
Expand All @@ -72,7 +65,6 @@ lazy val exampleApp = project

lazy val extension = project
.in(file("extension"))
.dependsOn(scalaJsChrome)
.enablePlugins(ChromeSbtPlugin)
.settings(
name := "Example Extension",
Expand All @@ -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) := {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 3 additions & 9 deletions sbt-plugin/src/main/scala/com/alexitc/Chrome.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions sbt-plugin/src/main/scala/com/alexitc/ChromeSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
)
},
Expand All @@ -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
)
},
Expand Down