Skip to content

Commit ac2f3ae

Browse files
committed
Renamed and refactored some tasks in KotlinJsModule
1 parent 4fa94ce commit ac2f3ae

File tree

3 files changed

+44
-41
lines changed

3 files changed

+44
-41
lines changed

kotlinlib/src/mill/kotlinlib/js/KotlinJsModule.scala

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,25 @@ import mill.testrunner.TestResult
1111
import mill.util.Jvm
1212
import mill.{Args, T}
1313
import sbt.testing.Status
14-
import upickle.default.{macroRW, ReadWriter => RW}
15-
14+
import upickle.default.{macroRW, ReadWriter as RW}
1615
import java.io.{File, FileNotFoundException}
1716
import java.util.zip.ZipFile
17+
1818
import 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
2324
trait 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(),

kotlinlib/test/src/mill/kotlinlib/js/KotlinJsLinkTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object KotlinJsLinkTests extends TestSuite {
1313

1414
trait KotlinJsCrossModule extends KotlinJsModule with Cross.Module[Boolean] {
1515
override def kotlinVersion = KotlinJsLinkTests.kotlinVersion
16-
override def splitPerModule: T[Boolean] = crossValue
16+
override def kotlinJsSplitPerModule: T[Boolean] = crossValue
1717
override def kotlinJsBinaryKind: T[Option[BinaryKind]] = Some(BinaryKind.Executable)
1818
override def moduleDeps = Seq(module.bar)
1919
// drop cross-value

kotlinlib/test/src/mill/kotlinlib/js/KotlinJsNodeRunTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object KotlinJsNodeRunTests extends TestSuite {
2424

2525
def kotlinVersion = KotlinJsNodeRunTests.kotlinVersion
2626

27-
override def moduleKind = crossValue2 match {
27+
override def kotlinJsModuleKind = crossValue2 match {
2828
case "no" => ModuleKind.NoModule
2929
case "plain" => ModuleKind.PlainModule
3030
case "es" => ModuleKind.ESModule
@@ -34,7 +34,7 @@ object KotlinJsNodeRunTests extends TestSuite {
3434
}
3535

3636
override def moduleDeps = Seq(module.bar)
37-
override def splitPerModule = crossValue
37+
override def kotlinJsSplitPerModule = crossValue
3838
override def kotlinJsRunTarget = Some(RunTarget.Node)
3939
}
4040

0 commit comments

Comments
 (0)