Closed
Description
Inside the snapshot-lib
project you will see these folders:
commonMain
- compiles for all platformsjvmMain
- compiles only on the JVMjsMain
- compiles only to JScommonTest
- these tests run on all platformsjvmTest
- these tests only run on JVM- etc.
Good example
We want as much code as possible to live in common
. A good example of multiplatform is this:
- a simple
internal expect fun
to wrap a platform-specific API - all the logic of
ArrayMap
lives incommon
Then we implement the "expect" for both jvm and js with "actual"
- https://github.com/diffplug/spotless-snapshot/blob/f63192a84390901a3d3543066d095ea23bf81d21/snapshot-lib/src/jvmMain/kotlin/com/diffplug/snapshot/FastMap.jvm.kt#L25-L26
- https://github.com/diffplug/spotless-snapshot/blob/f63192a84390901a3d3543066d095ea23bf81d21/snapshot-lib/src/jsMain/kotlin/com/diffplug/snapshot/FastMap.js.kt#L20-L31
Work to be done.
In this case, we have JVM-only code. It should be pretty easy to move it into common, but there are a few tricky parts, which I don't want to deal with right now. So I move only the public API into common
.
Leave the implementation as jvm only, and the js just throws TODO exceptions for now
- https://github.com/diffplug/spotless-snapshot/blob/f63192a84390901a3d3543066d095ea23bf81d21/snapshot-lib/src/jvmMain/kotlin/com/diffplug/snapshot/PerCharacterEscaper.jvm.kt#L18-L171
- https://github.com/diffplug/spotless-snapshot/blob/f63192a84390901a3d3543066d095ea23bf81d21/snapshot-lib/src/jsMain/kotlin/com/diffplug/snapshot/PerCharacterEscaper.js.kt#L18-L21
To implement this I would
- move
PerCharacterEscaperTest
out ofjvmTest
and intocommonTest
gradlew jvmTest
will still be passing, butgradlew jsTest
will now be failing
- remove the
expect actual
stuff and just put the whole JVM implementation into common - fix compile errors with as little platform-specific code as possible