Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f238179

Browse files
3flextschuchortdev
authored andcommitted
Add kotlin-dom-api-compat dependency
JetBrains/kotlin@688894a
1 parent 748e681 commit f238179

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

‎core/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//file:noinspection GroovyAssignabilityCheck
2+
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
23

34
plugins {
45
id "com.github.gmazzo.buildconfig" version "3.1.0"
@@ -16,6 +17,18 @@ buildConfig {
1617
}
1718
}
1819

20+
configurations.all {
21+
resolutionStrategy.dependencySubstitution {
22+
substitute(module("org.jetbrains.kotlin:kotlin-dom-api-compat"))
23+
.using variant(module("org.jetbrains.kotlin:kotlin-dom-api-compat:$embedded_kotlin_version")) {
24+
attributes {
25+
attribute(KotlinPlatformType.attribute, KotlinPlatformType.js)
26+
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, "kotlin-runtime"))
27+
}
28+
}
29+
}
30+
}
31+
1932
dependencies {
2033
compileOnly 'com.google.auto.service:auto-service:1.1.1'
2134
kapt "com.google.auto.service:auto-service:1.1.1"
@@ -31,7 +44,9 @@ dependencies {
3144
// running compiler plugins passed via the pluginClasspath CLI option works
3245
testRuntimeOnly "org.jetbrains.kotlin:kotlin-scripting-compiler:$embedded_kotlin_version"
3346

34-
//testRuntimeOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$embedded_kotlin_version"
47+
// Include Kotlin/JS standard library in test classpath for auto loading
48+
testRuntimeOnly "org.jetbrains.kotlin:kotlin-stdlib-js"
49+
testRuntimeOnly "org.jetbrains.kotlin:kotlin-dom-api-compat"
3550

3651
// The Kotlin compiler should be near the end of the list because its .jar file includes
3752
// an obsolete version of Guava

‎core/src/main/kotlin/com/tschuchort/compiletesting/HostEnvironment.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ internal object HostEnvironment {
2727
findInClasspath(kotlinDependencyRegex("kotlin-stdlib-js"))
2828
}
2929

30+
val kotlinDomApiCompatKlib: File? by lazy {
31+
findInClasspath(kotlinDependencyRegex("kotlin-dom-api-compat"))
32+
}
33+
3034
val kotlinReflectJar: File? by lazy {
3135
findInClasspath(kotlinDependencyRegex("kotlin-reflect"))
3236
}
@@ -40,7 +44,7 @@ internal object HostEnvironment {
4044
}
4145

4246
private fun kotlinDependencyRegex(prefix: String): Regex {
43-
return Regex("$prefix(-[0-9]+\\.[0-9]+(\\.[0-9]+)?)([-0-9a-zA-Z]+)?\\.jar")
47+
return Regex("$prefix(-[0-9]+\\.[0-9]+(\\.[0-9]+)?)([-0-9a-zA-Z]+)?(\\.jar|\\.klib)")
4448
}
4549

4650
/** Tries to find a file matching the given [regex] in the host process' classpath */
@@ -60,7 +64,11 @@ internal object HostEnvironment {
6064

6165
val classpaths = classGraph.classpathFiles
6266
val modules = classGraph.modules.mapNotNull { it.locationFile }
67+
val klibs = System.getProperty("java.class.path")
68+
.split(File.pathSeparator)
69+
.filter { it.endsWith(".klib") }
70+
.map(::File)
6371

64-
return (classpaths + modules).distinctBy(File::getAbsolutePath)
72+
return (classpaths + modules+ klibs).distinctBy(File::getAbsolutePath)
6573
}
6674
}

‎core/src/main/kotlin/com/tschuchort/compiletesting/KotlinJsCompilation.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
5252
HostEnvironment.kotlinStdLibJsJar
5353
}
5454

55+
/**
56+
* Path to the kotlin-dom-api-compat.klib
57+
* If none is given, it will be searched for in the host
58+
* process' classpaths
59+
*/
60+
var kotlinStdLibDomApi: File? by default {
61+
HostEnvironment.kotlinDomApiCompatKlib
62+
}
63+
5564
/**
5665
* Generate TypeScript declarations .d.ts file alongside JS file. Available in IR backend only
5766
*/
@@ -90,7 +99,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
9099
args.moduleName = moduleName // -ir-output-name
91100
args.outputFile = File(outputDir, outputFileName).absolutePath
92101
args.sourceMapBaseDirs = jsClasspath().joinToString(separator = File.pathSeparator)
93-
args.libraries = listOfNotNull(kotlinStdLibJsJar).joinToString(separator = ":")
102+
args.libraries = listOfNotNull(kotlinStdLibJsJar, kotlinStdLibDomApi).joinToString(separator = File.pathSeparator)
94103

95104
args.irProduceKlibDir = irProduceKlibDir
96105
args.irProduceKlibFile = irProduceKlibFile

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /