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

Vhiairrassary/es modules support #336

Open
wants to merge 2 commits into
base: main
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import sbt.Keys._
import sbt._
import scalajsbundler.{JSDOMNodeJSEnv, Webpack, JsDomTestEntries, NpmPackage}
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport.{installJsdom, npmUpdate, requireJsDomEnv, webpackConfigFile, webpackNodeArgs, webpackResources, webpack}
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.{ensureModuleKindIsCommonJSModule, scalaJSBundlerImportedModules}
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.{ensureModuleKindIsNotNoModule, scalaJSBundlerImportedModules}
import scalajsbundler.sbtplugin.internal.BuildInfo

private[sbtplugin] object Settings {
Expand Down Expand Up @@ -131,7 +131,7 @@ private[sbtplugin] object Settings {
jsEnvInput := Def.task {
import org.scalajs.jsenv.Input._

assert(ensureModuleKindIsCommonJSModule.value)
assert(ensureModuleKindIsNotNoModule.value)
val prev = jsEnvInput.value
val sjsOutput = scalaJSLinkedFile.value.data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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
Expand Down Expand Up @@ -82,7 +82,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

Expand All @@ -97,7 +97,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,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
)

Expand All @@ -570,9 +570,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down