File tree Expand file tree Collapse file tree 7 files changed +41
-90
lines changed
nodeFilesystemShared/src/node Expand file tree Collapse file tree 7 files changed +41
-90
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 55
66package kotlinx.io.node
77
8+ import kotlinx.io.withCaughtException
9+
810internal external interface BufferModule {
911 val Buffer : BufferObj
1012}
@@ -22,4 +24,8 @@ internal external interface Buffer {
2224 fun writeInt8 (value : Byte , offset : Int )
2325}
2426
25- internal expect val buffer: BufferModule
27+ internal val buffer: BufferModule by lazy {
28+ loadModule(" buffer" , ::bufferInitializer)
29+ }
30+
31+ private fun bufferInitializer (): BufferModule ? = js(" eval('require')('buffer')" )
Original file line number Diff line number Diff line change @@ -86,4 +86,8 @@ internal external interface realpathSync {
8686 fun native (path : String ): String
8787}
8888
89- internal expect val fs: Fs
89+ internal val fs: Fs by lazy {
90+ loadModule(" fs" , ::fsInitializer)
91+ }
92+
93+ private fun fsInitializer (): Fs ? = js(" eval('require')('fs')" )
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+ */
5+
6+ package kotlinx.io.node
7+
8+ import kotlinx.io.withCaughtException
9+
10+ internal fun <T > loadModule (name : String , initializer : () -> T ? ): T {
11+ var mod: T ? = null
12+ val ex = withCaughtException {
13+ mod = initializer()
14+ }
15+ if (mod == null ) {
16+ throw UnsupportedOperationException (" Module '$name ' could not be loaded" , ex)
17+ }
18+ return mod!!
19+ }
Original file line number Diff line number Diff line change @@ -18,4 +18,8 @@ internal external interface Os {
1818 fun platform (): String
1919}
2020
21- internal expect val os: Os
21+ internal val os: Os by lazy {
22+ loadModule(" os" , ::osInitializer)
23+ }
24+
25+ private fun osInitializer (): Os ? = js(" eval('require')('os')" )
Original file line number Diff line number Diff line change @@ -14,4 +14,8 @@ internal external interface Path {
1414 val sep: String
1515}
1616
17- internal expect val path: Path
17+ internal val path: Path by lazy {
18+ loadModule(" path" , ::pathInitializer)
19+ }
20+
21+ private fun pathInitializer (): Path ? = js(" eval('require')('path')" )
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments