-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
Give mill the ability to re-write ESModule imports at link time #3109
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
599afd6
Tidy up some deprecation warninga
Quafadas 9ea5bea
.
Quafadas d19c56b
.
Quafadas 1e12f19
.
Quafadas ff2f434
add node
Quafadas 5b191f4
Add ability to remap ES module imports at link time
Quafadas c2aa0e0
Merge branch 'main' into jsimportRemap
Quafadas 96addd7
reformat
Quafadas e524bc3
Let's see if this fixes classpath issues.
Quafadas fccc715
formatting
Quafadas 666fade
Remove this unncessary default as per conversation
Quafadas c41b15f
Update junixsocket from 2.9.0 to 2.9.1 (#3113)
lefou e4a672e
Update mainargs from 0.6.2 to 0.6.3 (#3114)
lefou 247bee6
Update asm from 9.6 to 9.7 (#3112)
lefou c28fd8a
Update requests from 0.8.0 to 0.8.2 (#3115)
lefou b2d8f10
Update semanticdb-scalac from 4.9.2 to 4.9.3 (#3116)
lefou 927e410
Update transitive commons-io from 2.15.1 to 2.16.1 (#3117)
lefou 5023c65
Update Scala Native to 0.5.0 (#3120)
lolgab a68c09b
Isolate scoverage modules from their parent modules (#3118)
romain-gilles-ultra 5e65027
.
Quafadas b307fe0
Propogate Module remapping from build.sc to ScalaJsModule
Quafadas d84925a
Merge branch 'main' into jsimportRemap
Quafadas e096503
dev container
Quafadas 77903ea
Remove whitespace - reformat
Quafadas f8bba2b
See if this passes tests
Quafadas 5eae119
No need to change this
Quafadas 68b814b
reformat
Quafadas d44de38
Apply review suggestions
lolgab 849afc9
Merge branch 'main' into jsimportRemap
lolgab 87657d7
Merge pull request #1 from lolgab/jsimportRemap
Quafadas cdbfb80
Fix test for error message
lolgab 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 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 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 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 |
---|---|---|
|
@@ -270,3 +270,11 @@ object OutputPatterns { | |
|
||
implicit val rw: RW[OutputPatterns] = macroRW[OutputPatterns] | ||
} | ||
|
||
sealed trait ESModuleImportMapping | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
object ESModuleImportMapping { | ||
case class Prefix(prefix: String, replacement: String) extends ESModuleImportMapping | ||
|
||
implicit def rwPrefix: RW[Prefix] = macroRW | ||
implicit def rw: RW[ESModuleImportMapping] = macroRW | ||
} |
This file contains 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 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,16 @@ | ||
package app | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation._ | ||
|
||
object App { | ||
def main(args: Array[String]): Unit = { | ||
println(linspace(-10.0, 10.0, 10)) | ||
} | ||
} | ||
|
||
@js.native | ||
@JSImport("@stdlib/linspace", JSImport.Default) | ||
object linspace extends js.Object { | ||
def apply(start: Double, stop: Double, num: Int): Any = js.native | ||
} |
78 changes: 78 additions & 0 deletions
78
scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala
This file contains 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,78 @@ | ||
package mill.scalajslib | ||
|
||
import mill.api.Result | ||
import mill.define.Discover | ||
import mill.util.{TestEvaluator, TestUtil} | ||
import utest._ | ||
import mill.define.Target | ||
import mill.scalajslib.api._ | ||
|
||
object EsModuleRemapTests extends TestSuite { | ||
val workspacePath = TestUtil.getOutPathStatic() / "esModuleRemap" | ||
|
||
val remapTo = "https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs" | ||
|
||
object EsModuleRemap extends TestUtil.BaseModule { | ||
|
||
object sourceMapModule extends ScalaJSModule { | ||
override def millSourcePath = workspacePath | ||
override def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) | ||
override def scalaJSVersion = "1.16.0" | ||
override def scalaJSSourceMap = false | ||
override def moduleKind = ModuleKind.ESModule | ||
|
||
override def scalaJSImportMap: Target[Seq[ESModuleImportMapping]] = Seq( | ||
ESModuleImportMapping.Prefix("@stdlib/linspace", remapTo) | ||
) | ||
} | ||
|
||
object OldJsModule extends ScalaJSModule { | ||
override def millSourcePath = workspacePath | ||
override def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) | ||
override def scalaJSVersion = "1.15.0" | ||
override def scalaJSSourceMap = false | ||
override def moduleKind = ModuleKind.ESModule | ||
|
||
override def scalaJSImportMap: Target[Seq[ESModuleImportMapping]] = Seq( | ||
ESModuleImportMapping.Prefix("@stdlib/linspace", remapTo) | ||
) | ||
} | ||
|
||
override lazy val millDiscover = Discover[this.type] | ||
} | ||
|
||
val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "esModuleRemap" | ||
|
||
val evaluator = TestEvaluator.static(EsModuleRemap) | ||
|
||
val tests: Tests = Tests { | ||
prepareWorkspace() | ||
|
||
test("should remap the esmodule") { | ||
val Right((report, _)) = | ||
evaluator(EsModuleRemap.sourceMapModule.fastLinkJS) | ||
val publicModules = report.publicModules.toSeq | ||
assert(publicModules.length == 1) | ||
val main = publicModules.head | ||
assert(main.jsFileName == "main.js") | ||
val mainPath = report.dest.path / "main.js" | ||
assert(os.exists(mainPath)) | ||
val rawJs = os.read.lines(mainPath) | ||
assert(rawJs(1).contains(remapTo)) | ||
} | ||
|
||
test("should throw for older scalaJS versions") { | ||
val Left(Result.Exception(ex, _)) = evaluator(EsModuleRemap.OldJsModule.fastLinkJS) | ||
val error = ex.getMessage | ||
assert(error == "scalaJSImportMap is not supported with Scala.js < 1.16.") | ||
} | ||
|
||
} | ||
|
||
def prepareWorkspace(): Unit = { | ||
os.remove.all(workspacePath) | ||
os.makeDir.all(workspacePath / os.up) | ||
os.copy(millSourcePath, workspacePath) | ||
} | ||
|
||
} |
This file contains 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 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
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.
@lefou @lihaoyi
Suggestions for this name?
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.
What's wrong with the current name? What's the name of the underlying concept?