From a6bec57dadad972f4fe66696fa60de967a617c01 Mon Sep 17 00:00:00 2001 From: Victor Hiairrassary Date: Mon, 19 Aug 2019 13:18:06 +0200 Subject: [PATCH] Add ES modules support --- .../scalajsbundler/sbtplugin/Settings.scala | 4 ++-- .../scalajsbundler/util/ScalaJSOutputAnalyzer.scala | 4 ++-- .../scalajsbundler/sbtplugin/Settings.scala | 4 ++-- .../scalajsbundler/util/ScalaJSOutputAnalyzer.scala | 4 ++-- .../scalajsbundler/sbtplugin/LibraryTasks.scala | 6 +++--- .../sbtplugin/ScalaJSBundlerPlugin.scala | 12 ++++++------ .../scalajsbundler/sbtplugin/WebpackTasks.scala | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sbt-scalajs-bundler/src/main/scala-sjs-0.6/scalajsbundler/sbtplugin/Settings.scala b/sbt-scalajs-bundler/src/main/scala-sjs-0.6/scalajsbundler/sbtplugin/Settings.scala index 82f8afc7..ac7b973f 100644 --- a/sbt-scalajs-bundler/src/main/scala-sjs-0.6/scalajsbundler/sbtplugin/Settings.scala +++ b/sbt-scalajs-bundler/src/main/scala-sjs-0.6/scalajsbundler/sbtplugin/Settings.scala @@ -11,7 +11,7 @@ import org.scalajs.sbtplugin.ScalaJSPluginInternal.{scalaJSEnsureUnforked, scala import sbt.Keys.{loadedTestFrameworks, streams, testFrameworks, version} import sbt._ import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport.{installJsdom, npmUpdate, requireJsDomEnv, webpack, webpackConfigFile, webpackNodeArgs, webpackResources} -import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.{createdTestAdapters, ensureModuleKindIsCommonJSModule} +import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.{createdTestAdapters, ensureModuleKindIsNotNoModule} import scalajsbundler.scalajs.compat.testing.TestAdapter import scalajsbundler.{JSDOMNodeJSEnv, JsDomTestEntries, NpmPackage, Webpack} @@ -40,7 +40,7 @@ private[sbtplugin] object Settings { case other => sys.error(s"You need a ComJSEnv to test (found ${other.name})") }.getOrElse { Def.taskDyn[ComJSEnv] { - assert(ensureModuleKindIsCommonJSModule.value) + assert(ensureModuleKindIsNotNoModule.value) val sjsOutput = fastOptJS.value.data // If jsdom is going to be used, then we should bundle the test module into a file that exports the tests to the global namespace if (requireJsDomEnv.value) Def.task { diff --git a/sbt-scalajs-bundler/src/main/scala-sjs-0.6/scalajsbundler/util/ScalaJSOutputAnalyzer.scala b/sbt-scalajs-bundler/src/main/scala-sjs-0.6/scalajsbundler/util/ScalaJSOutputAnalyzer.scala index c53a0d78..eed076ac 100644 --- a/sbt-scalajs-bundler/src/main/scala-sjs-0.6/scalajsbundler/util/ScalaJSOutputAnalyzer.scala +++ b/sbt-scalajs-bundler/src/main/scala-sjs-0.6/scalajsbundler/util/ScalaJSOutputAnalyzer.scala @@ -44,8 +44,8 @@ object ScalaJSOutputAnalyzer { moduleInitializers: Seq[ModuleInitializer], logger: Logger ): LinkingUnit = { - require(linkerConfig.moduleKind == ModuleKind.CommonJSModule, - s"linkerConfig.moduleKind was ${linkerConfig.moduleKind}") + require(linkerConfig.moduleKind != ModuleKind.NoModule, + s"linkerConfig.moduleKind was ModuleKind.NoModule") val symbolRequirements = { val backend = new BasicLinkerBackend(linkerConfig.semantics, linkerConfig.esFeatures, diff --git a/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/sbtplugin/Settings.scala b/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/sbtplugin/Settings.scala index c972f2ff..49eeb19c 100644 --- a/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/sbtplugin/Settings.scala +++ b/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/sbtplugin/Settings.scala @@ -12,7 +12,7 @@ import sbt._ import sbt.testing.Framework import scalajsbundler.{JSDOMNodeJSEnv, Webpack, JsDomTestEntries, NpmPackage} import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport.{installJsdom, npmUpdate, requireJsDomEnv, webpackConfigFile, webpackNodeArgs, webpackResources, webpack} -import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.{createdTestAdapters, ensureModuleKindIsCommonJSModule} +import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.{createdTestAdapters, ensureModuleKindIsNotNoModule} import scalajsbundler.scalajs.compat.io.FileVirtualBinaryFile import scalajsbundler.scalajs.compat.testing.TestAdapter @@ -27,7 +27,7 @@ private[sbtplugin] object Settings { loadedTestFrameworks := Def.task { val (env, input) = { Def.taskDyn[(JSEnv, org.scalajs.jsenv.Input)] { - assert(ensureModuleKindIsCommonJSModule.value) + assert(ensureModuleKindIsNotNoModule.value) val sjsOutput = fastOptJS.value.data // If jsdom is going to be used, then we should bundle the test module into a file that exports the tests to the global namespace if (requireJsDomEnv.value) Def.task { diff --git a/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/util/ScalaJSOutputAnalyzer.scala b/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/util/ScalaJSOutputAnalyzer.scala index 2240f4aa..38c48c40 100644 --- a/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/util/ScalaJSOutputAnalyzer.scala +++ b/sbt-scalajs-bundler/src/main/scala-sjs-1.x/scalajsbundler/util/ScalaJSOutputAnalyzer.scala @@ -50,8 +50,8 @@ object ScalaJSOutputAnalyzer { ): LinkingUnit = { import scala.concurrent.ExecutionContext.Implicits.global - require(linkerConfig.moduleKind == ModuleKind.CommonJSModule, - s"linkerConfig.moduleKind was ${linkerConfig.moduleKind}") + require(linkerConfig.moduleKind != ModuleKind.NoModule, + s"linkerConfig.moduleKind was ModuleKind.NoModule") val frontend = StandardLinkerFrontend(linkerConfig) val backend = new StoreLinkingUnitLinkerBackend(linkerConfig) val linker = StandardLinkerImpl(frontend, backend) diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/LibraryTasks.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/LibraryTasks.scala index 606b7c0d..6cf46492 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/LibraryTasks.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/LibraryTasks.scala @@ -62,7 +62,7 @@ object LibraryTasks { stage: TaskKey[Attributed[File]], mode: BundlingMode.Library): Def.Initialize[Task[BundlerFile.Library]] = Def.task { - assert(ensureModuleKindIsCommonJSModule.value) + assert(ensureModuleKindIsNotNoModule.value) val log = streams.value.log val emitSourceMaps = (finallyEmitSourceMaps in stage).value val customWebpackConfigFile = (webpackConfigFile in stage).value @@ -107,7 +107,7 @@ object LibraryTasks { stage: TaskKey[Attributed[File]], mode: BundlingMode.Library): Def.Initialize[Task[BundlerFile.Loader]] = Def.task { - assert(ensureModuleKindIsCommonJSModule.value) + assert(ensureModuleKindIsNotNoModule.value) val entry = WebpackTasks.entry(stage).value val loaderFile = entry.asLoader @@ -122,7 +122,7 @@ object LibraryTasks { mode: BundlingMode.LibraryAndApplication) : Def.Initialize[Task[Seq[BundlerFile.Public]]] = Def.task { - assert(ensureModuleKindIsCommonJSModule.value) + assert(ensureModuleKindIsNotNoModule.value) val cacheLocation = streams.value.cacheDirectory / s"${stage.key.label}-webpack-bundle-all" val targetDir = npmUpdate.value val entry = WebpackTasks.entry(stage).value diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala index ace7f711..f0b8bed9 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala @@ -537,10 +537,10 @@ object ScalaJSBundlerPlugin extends AutoPlugin { KeyRanks.Invisible ) - private[scalajsbundler] val ensureModuleKindIsCommonJSModule = + private[scalajsbundler] val ensureModuleKindIsNotNoModule = SettingKey[Boolean]( - "ensureModuleKindIsCommonJSModule", - "Checks that scalaJSModuleKind is set to CommonJSModule", + "ensureModuleKindIsNotNoModule", + "Checks that scalaJSModuleKind is not set to NoModule", KeyRanks.Invisible ) @@ -567,9 +567,9 @@ object ScalaJSBundlerPlugin extends AutoPlugin { useYarn := false, - ensureModuleKindIsCommonJSModule := { - if (scalaJSLinkerConfig.value.moduleKind == ModuleKind.CommonJSModule) true - else sys.error(s"scalaJSModuleKind must be set to ModuleKind.CommonJSModule in projects where ScalaJSBundler plugin is enabled") + ensureModuleKindIsNotNoModule := { + if (scalaJSLinkerConfig.value.moduleKind != ModuleKind.NoModule) true + else sys.error(s"scalaJSModuleKind must not be set to ModuleKind.NoModule in projects where ScalaJSBundler plugin is enabled") }, webpackBundlingMode := BundlingMode.Default, diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/WebpackTasks.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/WebpackTasks.scala index 8997d4e1..e3d523ca 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/WebpackTasks.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/WebpackTasks.scala @@ -18,7 +18,7 @@ object WebpackTasks { private[sbtplugin] def webpack( stage: TaskKey[Attributed[File]]): Def.Initialize[Task[Seq[Attributed[File]]]] = Def.task { - assert(ensureModuleKindIsCommonJSModule.value) + assert(ensureModuleKindIsNotNoModule.value) val cacheLocation = streams.value.cacheDirectory / s"${stage.key.label}-webpack" val generatedWebpackConfigFile = (scalaJSBundlerWebpackConfig in stage).value