diff --git a/core/js/src/node/initializers.kt b/core/js/src/node/initializers.kt new file mode 100644 index 000000000..40e5ff070 --- /dev/null +++ b/core/js/src/node/initializers.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. + */ + +package kotlinx.io.node + +internal actual fun bufferInitializer(): BufferModule? = js("eval('require')('buffer')") +internal actual fun osInitializer(): Os? = js("eval('require')('os')") +internal actual fun fsInitializer(): Fs? = js("eval('require')('fs')") +internal actual fun pathInitializer(): Path? = js("eval('require')('path')") diff --git a/core/nodeFilesystemShared/src/node/buffer.kt b/core/nodeFilesystemShared/src/node/buffer.kt index a9e9029f5..dc79eaf9f 100644 --- a/core/nodeFilesystemShared/src/node/buffer.kt +++ b/core/nodeFilesystemShared/src/node/buffer.kt @@ -5,8 +5,6 @@ package kotlinx.io.node -import kotlinx.io.withCaughtException - internal external interface BufferModule { val Buffer: BufferObj } @@ -28,4 +26,4 @@ internal val buffer: BufferModule by lazy { loadModule("buffer", ::bufferInitializer) } -private fun bufferInitializer(): BufferModule? = js("eval('require')('buffer')") +internal expect fun bufferInitializer(): BufferModule? diff --git a/core/nodeFilesystemShared/src/node/fs.kt b/core/nodeFilesystemShared/src/node/fs.kt index 8a9718f0b..6ca09c872 100644 --- a/core/nodeFilesystemShared/src/node/fs.kt +++ b/core/nodeFilesystemShared/src/node/fs.kt @@ -90,4 +90,4 @@ internal val fs: Fs by lazy { loadModule("fs", ::fsInitializer) } -private fun fsInitializer(): Fs? = js("eval('require')('fs')") +internal expect fun fsInitializer(): Fs? diff --git a/core/nodeFilesystemShared/src/node/os.kt b/core/nodeFilesystemShared/src/node/os.kt index d197da091..38b60dff4 100644 --- a/core/nodeFilesystemShared/src/node/os.kt +++ b/core/nodeFilesystemShared/src/node/os.kt @@ -22,4 +22,4 @@ internal val os: Os by lazy { loadModule("os", ::osInitializer) } -private fun osInitializer(): Os? = js("eval('require')('os')") +internal expect fun osInitializer(): Os? diff --git a/core/nodeFilesystemShared/src/node/path.kt b/core/nodeFilesystemShared/src/node/path.kt index 918b7afbf..3babaeb66 100644 --- a/core/nodeFilesystemShared/src/node/path.kt +++ b/core/nodeFilesystemShared/src/node/path.kt @@ -18,4 +18,4 @@ internal val path: Path by lazy { loadModule("path", ::pathInitializer) } -private fun pathInitializer(): Path? = js("eval('require')('path')") +internal expect fun pathInitializer(): Path? diff --git a/core/wasmJs/src/node/initializers.kt b/core/wasmJs/src/node/initializers.kt new file mode 100644 index 000000000..40e5ff070 --- /dev/null +++ b/core/wasmJs/src/node/initializers.kt @@ -0,0 +1,11 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. + */ + +package kotlinx.io.node + +internal actual fun bufferInitializer(): BufferModule? = js("eval('require')('buffer')") +internal actual fun osInitializer(): Os? = js("eval('require')('os')") +internal actual fun fsInitializer(): Fs? = js("eval('require')('fs')") +internal actual fun pathInitializer(): Path? = js("eval('require')('path')")