-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: extract DottyJSPlugin from Build #23597
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package dotty.tools.sbtplugin | ||
|
||
import sbt.* | ||
import sbt.Keys.* | ||
|
||
import org.scalajs.sbtplugin.ScalaJSPlugin | ||
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ | ||
|
||
import org.scalajs.linker.interface.StandardConfig | ||
|
||
object DottyJSPlugin extends AutoPlugin { | ||
|
||
object autoImport { | ||
val switchToESModules: StandardConfig => StandardConfig = | ||
config => config.withModuleKind(ModuleKind.ESModule) | ||
} | ||
|
||
val writePackageJSON = taskKey[Unit]( | ||
"Write package.json to configure module type for Node.js") | ||
|
||
override def requires: Plugins = ScalaJSPlugin | ||
|
||
override def projectSettings: Seq[Setting[_]] = Def.settings( | ||
|
||
/* #11709 Remove the dependency on scala3-library that ScalaJSPlugin adds. | ||
* Instead, in this build, we use `.dependsOn` relationships to depend on | ||
* the appropriate, locally-defined, scala3-library-bootstrappedJS. | ||
*/ | ||
libraryDependencies ~= { | ||
_.filter(!_.name.startsWith("scala3-library_sjs1")) | ||
}, | ||
|
||
// Replace the JVM JUnit dependency by the Scala.js one | ||
libraryDependencies ~= { | ||
_.filter(!_.name.startsWith("junit-interface")) | ||
}, | ||
libraryDependencies += | ||
("org.scala-js" %% "scalajs-junit-test-runtime" % scalaJSVersion % "test").cross(CrossVersion.for3Use2_13), | ||
|
||
// Typecheck the Scala.js IR found on the classpath | ||
scalaJSLinkerConfig ~= (_.withCheckIR(true)), | ||
|
||
Compile / jsEnvInput := (Compile / jsEnvInput).dependsOn(writePackageJSON).value, | ||
Test / jsEnvInput := (Test / jsEnvInput).dependsOn(writePackageJSON).value, | ||
|
||
writePackageJSON := { | ||
val packageType = scalaJSLinkerConfig.value.moduleKind match { | ||
case ModuleKind.NoModule => "commonjs" | ||
case ModuleKind.CommonJSModule => "commonjs" | ||
case ModuleKind.ESModule => "module" | ||
} | ||
|
||
val path = target.value / "package.json" | ||
|
||
IO.write(path, s"""{"type": "$packageType"}\n""") | ||
}, | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was extracted from the plugin's
projectSettings
sincecommonBootstrappedSettings
is defined inBuild
. This duplication will be removed with the upcomingBootstrappedProject
plugin that is used in the new build.