Skip to content

Commit

Permalink
Replace Options with dynamic JsObject (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm authored Feb 12, 2024
1 parent 364d2d8 commit db51783
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal actual external fun fs_exists(path: String): Boolean

/** [docs](https://nodejs.org/api/fs.html#fsmkdirsyncpath-options) */
@JsName("mkdirSync")
internal external fun fs_mkdirSync(path: String, options: Options.Mkdir): String?
internal external fun fs_mkdirSync(path: String, options: dynamic): String?

/** [docs](https://nodejs.org/api/fs.html#fsreadfilesyncpath-options) */
@JsName("readFileSync")
Expand All @@ -41,11 +41,11 @@ internal external fun fs_realpathSync(path: String): String

/** [docs](https://nodejs.org/api/fs.html#fsrmsyncpath-options) */
@JsName("rmSync")
internal external fun fs_rmSync(path: String, options: Options.Remove)
internal external fun fs_rmSync(path: String, options: dynamic)

/** [docs](https://nodejs.org/api/fs.html#fsrmdirsyncpath-options) */
@JsName("rmdirSync")
internal external fun fs_rmdirSync(path: String, options: Options.Remove)
internal external fun fs_rmdirSync(path: String, options: dynamic)

/** [docs](https://nodejs.org/api/fs.html#fsunlinksyncpath) */
@JsName("unlinkSync")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,16 @@ internal actual fun fs_remove(path: String): Boolean {
if (t.errorCode == "ENOENT") return false
}

val options = js("{}")
options["force"] = true
options["recursive"] = false

return try {
fs_rmSync(path, Options.Remove(force = true, recursive = false))
fs_rmSync(path, options)
true
} catch (_: Throwable) {
try {
fs_rmdirSync(path, Options.Remove(force = true, recursive = false))
fs_rmdirSync(path, options)
true
} catch (t: Throwable) {
throw t.toIOException()
Expand All @@ -148,7 +152,11 @@ internal actual fun fs_remove(path: String): Boolean {

internal actual fun fs_mkdir(path: String): Boolean {
return try {
fs_mkdirSync(path, Options.Mkdir())
val options = js("{}")
options["recursive"] = false
options["mode"] = "775"

fs_mkdirSync(path, options)
true
} catch (_: Throwable) {
false
Expand Down

This file was deleted.

0 comments on commit db51783

Please sign in to comment.