@@ -11,26 +11,25 @@ import mill.testrunner.TestResult
1111import mill .util .Jvm
1212import mill .{Args , T }
1313import sbt .testing .Status
14- import upickle .default .{macroRW , ReadWriter => RW }
15-
14+ import upickle .default .{macroRW , ReadWriter as RW }
1615import java .io .{File , FileNotFoundException }
1716import java .util .zip .ZipFile
17+
1818import scala .xml .XML
1919
2020/**
2121 * This module is very experimental. Don't use it, it is still under the development, APIs can change.
2222 */
23+ @ mill.api.experimental
2324trait KotlinJsModule extends KotlinModule { outer =>
2425
2526 // region Kotlin/JS configuration
2627
2728 /** The kind of JS module generated by the compiler */
28- // FIXME: Rename to kotlinKsModuleKind
29- def moduleKind : T [ModuleKind ] = ModuleKind .PlainModule
29+ def kotlinJsModuleKind : T [ModuleKind ] = ModuleKind .PlainModule
3030
3131 /** Call main function upon execution. */
32- // FIXME: Rename to kotlinJsCallMain
33- def callMain : T [Boolean ] = true
32+ def kotlinJsCallMain : T [Boolean ] = true
3433
3534 /** Binary type (if any) to produce. If [[BinaryKind.Executable ]] is selected, then .js file(s) will be produced. */
3635 def kotlinJsBinaryKind : T [Option [BinaryKind ]] = Some (BinaryKind .Executable )
@@ -51,8 +50,7 @@ trait KotlinJsModule extends KotlinModule { outer =>
5150 def kotlinJsSourceMapNamesPolicy : T [SourceMapNamesPolicy ] = SourceMapNamesPolicy .No
5251
5352 /** Split generated .js per-module. Effective only if [[BinaryKind.Executable ]] is selected. */
54- // FIXME: rename to kotlinJsSplitPerModule
55- def splitPerModule : T [Boolean ] = true
53+ def kotlinJsSplitPerModule : T [Boolean ] = true
5654
5755 /** Run target for the executable (if [[BinaryKind.Executable ]] is set). */
5856 def kotlinJsRunTarget : T [Option [RunTarget ]] = None
@@ -66,21 +64,26 @@ trait KotlinJsModule extends KotlinModule { outer =>
6664 }
6765
6866 override def mandatoryIvyDeps : T [Seq [Dep ]] = Task {
69- Seq (
70- ivy " org.jetbrains.kotlin:kotlin-stdlib-js: ${kotlinVersion()}"
71- )
67+ super .mandatoryIvyDeps()
68+ // TODO: find source or docs, why this is the correct behavior
69+ // Filter out the non-js kotlin-stdlib
70+ .filterNot(d => d.organization == " org.jetbrains.kotlin" && d.name == " kotlin-stdlib" ) ++
71+ Seq (
72+ ivy " org.jetbrains.kotlin:kotlin-stdlib-js: ${kotlinVersion()}"
73+ )
7274 }
7375
7476 override def transitiveCompileClasspath : T [Seq [PathRef ]] = Task {
75- Task .traverse(transitiveModuleCompileModuleDeps)(m =>
76- Task .Anon {
77- val transitiveModuleArtifactPath =
78- if (m.isInstanceOf [KotlinJsModule ] && m != friendModule.orNull) {
79- m.asInstanceOf [KotlinJsModule ].klib()
80- } else m.compile().classes
81- m.localCompileClasspath() ++ Seq (transitiveModuleArtifactPath)
82- }
83- )().flatten
77+ Task .traverse(transitiveModuleCompileModuleDeps) {
78+ case js : KotlinJsModule if js != kotlinJsFriendModule.orNull =>
79+ Task .Anon {
80+ js.localCompileClasspath() ++ Seq (js.klib())
81+ }
82+ case m => Task .Anon {
83+ // this is the super-implementation
84+ m.localCompileClasspath() ++ Seq (m.compile().classes)
85+ }
86+ }().flatten
8487 }
8588
8689 /**
@@ -92,12 +95,12 @@ trait KotlinJsModule extends KotlinModule { outer =>
9295 irClasspath = None ,
9396 allKotlinSourceFiles = allKotlinSourceFiles(),
9497 librariesClasspath = compileClasspath(),
95- callMain = callMain (),
96- moduleKind = moduleKind (),
98+ callMain = kotlinJsCallMain (),
99+ moduleKind = kotlinJsModuleKind (),
97100 produceSourceMaps = kotlinJsSourceMap(),
98101 sourceMapEmbedSourcesKind = kotlinJsSourceMapEmbedSources(),
99102 sourceMapNamesPolicy = kotlinJsSourceMapNamesPolicy(),
100- splitPerModule = splitPerModule (),
103+ splitPerModule = kotlinJsSplitPerModule (),
101104 esTarget = kotlinJsESTarget(),
102105 kotlinVersion = kotlinVersion(),
103106 destinationRoot = Task .dest,
@@ -112,10 +115,10 @@ trait KotlinJsModule extends KotlinModule { outer =>
112115 Task .Command { run(args)() }
113116
114117 override def run (args : Task [Args ] = Task .Anon (Args ())): Command [Unit ] = Task .Command {
115- runJsBinary (
118+ kotlinJsRunBinary (
116119 args = args(),
117120 binaryKind = kotlinJsBinaryKind(),
118- moduleKind = moduleKind (),
121+ moduleKind = kotlinJsModuleKind (),
119122 binaryDir = linkBinary().classes.path,
120123 runTarget = kotlinJsRunTarget(),
121124 artifactId = artifactId(),
@@ -136,9 +139,9 @@ trait KotlinJsModule extends KotlinModule { outer =>
136139 mill.api.Result .Failure (" runMain is not supported in Kotlin/JS." )
137140 }
138141
139- protected [js] def friendModule : Option [KotlinJsModule ] = None
142+ protected [js] def kotlinJsFriendModule : Option [KotlinJsModule ] = None
140143
141- protected [js] def runJsBinary (
144+ protected [js] def kotlinJsRunBinary (
142145 args : Args = Args (),
143146 binaryKind : Option [BinaryKind ],
144147 moduleKind : ModuleKind ,
@@ -192,12 +195,12 @@ trait KotlinJsModule extends KotlinModule { outer =>
192195 allKotlinSourceFiles = allKotlinSourceFiles(),
193196 irClasspath = None ,
194197 librariesClasspath = compileClasspath(),
195- callMain = callMain (),
196- moduleKind = moduleKind (),
198+ callMain = kotlinJsCallMain (),
199+ moduleKind = kotlinJsModuleKind (),
197200 produceSourceMaps = kotlinJsSourceMap(),
198201 sourceMapEmbedSourcesKind = kotlinJsSourceMapEmbedSources(),
199202 sourceMapNamesPolicy = kotlinJsSourceMapNamesPolicy(),
200- splitPerModule = splitPerModule (),
203+ splitPerModule = kotlinJsSplitPerModule (),
201204 esTarget = kotlinJsESTarget(),
202205 kotlinVersion = kotlinVersion(),
203206 destinationRoot = Task .dest,
@@ -219,12 +222,12 @@ trait KotlinJsModule extends KotlinModule { outer =>
219222 allKotlinSourceFiles = Seq .empty,
220223 // classpath of libraries to be used to run this module's code
221224 librariesClasspath = upstreamAssemblyClasspath(),
222- callMain = callMain (),
223- moduleKind = moduleKind (),
225+ callMain = kotlinJsCallMain (),
226+ moduleKind = kotlinJsModuleKind (),
224227 produceSourceMaps = kotlinJsSourceMap(),
225228 sourceMapEmbedSourcesKind = kotlinJsSourceMapEmbedSources(),
226229 sourceMapNamesPolicy = kotlinJsSourceMapNamesPolicy(),
227- splitPerModule = splitPerModule (),
230+ splitPerModule = kotlinJsSplitPerModule (),
228231 esTarget = kotlinJsESTarget(),
229232 kotlinVersion = kotlinVersion(),
230233 destinationRoot = Task .dest,
@@ -513,16 +516,16 @@ trait KotlinJsModule extends KotlinModule { outer =>
513516
514517 override def kotlinJsRunTarget : T [Option [RunTarget ]] = outer.kotlinJsRunTarget()
515518
516- override def moduleKind : T [ModuleKind ] = ModuleKind .PlainModule
519+ override def kotlinJsModuleKind : T [ModuleKind ] = ModuleKind .PlainModule
517520
518- override def splitPerModule = false
521+ override def kotlinJsSplitPerModule = false
519522
520523 override def testLocal (args : String * ): Command [(String , Seq [TestResult ])] =
521524 Task .Command {
522525 this .testForked(args* )()
523526 }
524527
525- override protected [js] def friendModule : Option [KotlinJsModule ] = Some (outer)
528+ override protected [js] def kotlinJsFriendModule : Option [KotlinJsModule ] = Some (outer)
526529
527530 override protected def testTask (
528531 args : Task [Seq [String ]],
@@ -534,7 +537,7 @@ trait KotlinJsModule extends KotlinModule { outer =>
534537 " Cannot run Kotlin/JS tests, because run target is not specified."
535538 )
536539 }
537- runJsBinary (
540+ kotlinJsRunBinary (
538541 // TODO add runner to be able to use test selector
539542 args = Args (args() ++ Seq (
540543 // TODO this is valid only for the NodeJS target. Once browser support is
@@ -550,7 +553,7 @@ trait KotlinJsModule extends KotlinModule { outer =>
550553 s " output= ${testReportXml().getOrElse(defaultXmlReportName)}"
551554 )),
552555 binaryKind = Some (BinaryKind .Executable ),
553- moduleKind = moduleKind (),
556+ moduleKind = kotlinJsModuleKind (),
554557 binaryDir = linkBinary().classes.path,
555558 runTarget = runTarget,
556559 artifactId = artifactId(),
0 commit comments