Skip to content

Commit b4d5b45

Browse files
aerialist7Space Team
authored and
Space Team
committed
MPP / KJS: Fix incorrect source maps generating for ESM target
(cherry picked from commit 0553a2b) (cherry picked from commit ddd7185) Co-authored-by: Alexander Popoff <[email protected]> ^KT-59523 fixed
1 parent c9f7d7e commit b4d5b45

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt

+39
Original file line numberDiff line numberDiff line change
@@ -1626,4 +1626,43 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
16261626
}
16271627
}
16281628
}
1629+
1630+
@DisplayName("Check source map config of webpack")
1631+
@GradleTest
1632+
fun testWebpackSourceMapConfig(gradleVersion: GradleVersion) {
1633+
project("kotlin-js-browser-project", gradleVersion) {
1634+
build("assemble") {
1635+
assertTasksExecuted(":app:browserProductionWebpack")
1636+
1637+
val sourceMapConfig = """
1638+
|config.module.rules.push({
1639+
|test: /\.m?js${'$'}/,
1640+
|use: ["source-map-loader"],
1641+
|enforce: "pre"
1642+
|});
1643+
""".trimMargin()
1644+
1645+
val webpackConfig = projectPath.resolve("build/js/packages/kotlin-js-browser-app/webpack.config.js")
1646+
.readLines()
1647+
1648+
var startIndex = 0
1649+
for ((index, line) in webpackConfig.withIndex()) {
1650+
if (line.contains("// source maps")) {
1651+
startIndex = index + 1
1652+
break
1653+
}
1654+
}
1655+
1656+
val expectedLinesCount = sourceMapConfig.lines().count()
1657+
1658+
val actual = webpackConfig.subList(startIndex, startIndex + expectedLinesCount)
1659+
.joinToString("\n") { it.trim() }
1660+
1661+
assertEquals(
1662+
sourceMapConfig,
1663+
actual
1664+
)
1665+
}
1666+
}
1667+
}
16291668
}

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackConfig.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ data class KotlinWebpackConfig(
211211
"""
212212
// source maps
213213
config.module.rules.push({
214-
test: /\.js${'$'}/,
214+
test: /\.m?js${'$'}/,
215215
use: ["source-map-loader"],
216216
enforce: "pre"
217217
});

0 commit comments

Comments
 (0)