Skip to content

Commit 97e70d0

Browse files
fix(deps): update dependency org.jetbrains.compose:compose-gradle-plugin to v1.9.0 (#3178)
* fix(deps): update dependency org.jetbrains.compose:compose-gradle-plugin to v1.9.0 * Fix compilation. * Fix web sample. * Fix build and add favicon to sample. * Fix build. * Fix import. --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Colin White <colin@colinwhite.me>
1 parent c3e3d6f commit 97e70d0

File tree

13 files changed

+145
-14
lines changed

13 files changed

+145
-14
lines changed

build.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
1313
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.js
1414
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.wasm
1515
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
16+
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
1617

1718
buildscript {
1819
repositories {
@@ -145,6 +146,15 @@ allprojects {
145146
}
146147

147148
applyOkioJsTestWorkaround()
149+
150+
// Skiko's runtime files are ESM-only so preload our shim to let Node require them during tests.
151+
tasks.withType<KotlinJsTest>().configureEach {
152+
nodeJsArgs.add("--require")
153+
val skikoMjsWorkaround = rootProject.layout.projectDirectory
154+
.file("gradle/nodejs/registerSkikoMjsWorkaround.cjs")
155+
.asFile
156+
nodeJsArgs.add(skikoMjsWorkaround.absolutePath)
157+
}
148158
}
149159

150160
private val ktlintRules = buildMap {

buildSrc/src/main/kotlin/coil3/multiplatform.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ fun Project.addAllMultiplatformTargets(skikoVersion: Provider<String>, enableWas
6666
}
6767

6868
applyKotlinJsImplicitDependencyWorkaround(enableWasm)
69-
if (enableWasm) {
70-
createSkikoWasmJsRuntimeDependency(skikoVersion)
71-
}
69+
createSkikoWasmJsRuntimeDependency(skikoVersion)
7270
}
7371
}
7472

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ systemProp.org.gradle.internal.launcher.welcomeMessageEnabled=false
1010

1111
kotlin.code.style=official
1212
kotlin.mpp.androidSourceSetLayoutVersion=2
13+
kotlin.native.jvmArgs=-Xmx8g
1314

1415
kotlinx.atomicfu.enableJsIrTransformation=true
1516
kotlinx.atomicfu.enableJvmIrTransformation=true

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ androidx-tracing-perfetto = "1.0.0"
66
atomicfu = "0.29.0"
77
coroutines = "1.10.2"
88
dokka = "2.0.0"
9-
jetbrains-compose = "1.8.2"
9+
jetbrains-compose = "1.9.0"
1010
kotlin = "2.2.20"
1111
ktlint = "1.6.0"
1212
ktor2 = "2.3.13"
1313
ktor3 = "3.1.0"
1414
okhttp = "4.12.0"
1515
okio = "3.16.0"
16-
paparazzi = "1.3.5"
16+
paparazzi = "2.0.0-alpha02"
1717
roborazzi = "1.50.0"
18-
skiko = "0.9.4.2"
18+
skiko = "0.9.22.2"
1919

2020
[plugins]
2121
baselineProfile = { id = "androidx.baselineprofile", version.ref = "androidx-benchmark" }
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const Module = require('module');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const TARGET_FILES = new Set(['skiko.mjs', 'skikod8.mjs']);
6+
const ORIGINAL_MJS_HANDLER = Module._extensions['.mjs'];
7+
8+
function transformModuleSource(source) {
9+
let prelude = '';
10+
11+
if (source.includes('import.meta.url')) {
12+
prelude += 'const { pathToFileURL } = require("url");\n';
13+
source = source.replace(/import\.meta\.url/g, 'pathToFileURL(__filename).href');
14+
}
15+
16+
const exportedNames = [];
17+
source = source.replace(/export\s+(const|let|var)\s+([\w$]+)\s*=/g, (match, declaration, name) => {
18+
exportedNames.push(name);
19+
return `${declaration} ${name} =`;
20+
});
21+
22+
let defaultExport = null;
23+
source = source.replace(/export\s+default\s+([^;]+);?/g, (match, expression) => {
24+
defaultExport = expression.trim().replace(/;+$/, '');
25+
return '';
26+
});
27+
28+
let transformed = prelude + 'const __exports = {};\n' + source + '\n';
29+
for (const name of exportedNames) {
30+
transformed += `__exports.${name} = ${name};\n`;
31+
}
32+
if (defaultExport !== null) {
33+
transformed += `__exports.default = ${defaultExport};\n`;
34+
}
35+
transformed += 'module.exports = __exports;\n';
36+
return transformed;
37+
}
38+
39+
Module._extensions['.mjs'] = function registerSkikoMjs(module, filename) {
40+
const baseName = path.basename(filename);
41+
if (!TARGET_FILES.has(baseName)) {
42+
if (ORIGINAL_MJS_HANDLER) {
43+
return ORIGINAL_MJS_HANDLER(module, filename);
44+
}
45+
const error = new Error(`Cannot load ES module ${filename}`);
46+
error.code = 'ERR_REQUIRE_ESM';
47+
throw error;
48+
}
49+
50+
const originalSource = fs.readFileSync(filename, 'utf8');
51+
const transformedSource = transformModuleSource(originalSource);
52+
module._compile(transformedSource, filename);
53+
};
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package sample.compose
22

33
import androidx.compose.ui.ExperimentalComposeUiApi
4-
import androidx.compose.ui.window.CanvasBasedWindow
5-
import org.jetbrains.skiko.wasm.onWasmReady
4+
import androidx.compose.ui.window.ComposeViewport
5+
import kotlinx.browser.document
66

77
@OptIn(ExperimentalComposeUiApi::class)
8-
fun main() = onWasmReady {
9-
CanvasBasedWindow(Title) {
8+
fun main() {
9+
document.title = Title
10+
ComposeViewport {
1011
App()
1112
}
1213
}
107 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Loading

samples/compose/src/jsMain/resources/index.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,24 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Coil</title>
6+
<link rel="icon" href="favicon.svg" type="image/svg+xml">
7+
<link rel="alternate icon" href="favicon.ico" type="image/x-icon">
68
<script type="application/javascript" src="skiko.js"></script>
9+
<style>
10+
html,
11+
body {
12+
margin: 0;
13+
height: 100%;
14+
}
15+
16+
#ComposeTarget {
17+
width: 100%;
18+
height: 100%;
19+
}
20+
</style>
721
</head>
822
<body>
9-
<canvas id="ComposeTarget"></canvas>
23+
<div id="ComposeTarget"></div>
1024
<script src="coilSample.js"></script>
1125
</body>
1226
</html>
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package sample.compose
22

33
import androidx.compose.ui.ExperimentalComposeUiApi
4-
import androidx.compose.ui.window.CanvasBasedWindow
4+
import androidx.compose.ui.window.ComposeViewport
5+
import kotlinx.browser.document
56

67
@OptIn(ExperimentalComposeUiApi::class)
78
fun main() {
8-
CanvasBasedWindow(Title) {
9+
document.title = Title
10+
ComposeViewport {
911
App()
1012
}
1113
}

0 commit comments

Comments
 (0)