Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 6564bb8

Browse files
authored
Merge pull request #355 from exoego/fs
[fs] Overhaul fsPromise: new methods and correction
2 parents 87349b8 + a674f50 commit 6564bb8

File tree

2 files changed

+105
-49
lines changed

2 files changed

+105
-49
lines changed

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/fs/Fs.scala

Lines changed: 104 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,63 +1082,113 @@ object Fs extends Fs {
10821082
@js.native
10831083
trait FsPromises extends js.Object {
10841084
def access(path: Path, mode: FileMode): js.Promise[Unit] = js.native
1085+
def access(path: Path): js.Promise[Unit] = js.native
1086+
1087+
def appendFile(file: Path, data: Buffer, options: FileAppendOptions): js.Promise[Unit] = js.native
1088+
def appendFile(file: FileHandle, data: Buffer, options: FileAppendOptions): js.Promise[Unit] = js.native
1089+
1090+
def appendFile(file: Path, data: String, options: FileAppendOptions): js.Promise[Unit] = js.native
1091+
def appendFile(file: FileHandle, data: String, options: FileAppendOptions): js.Promise[Unit] = js.native
1092+
1093+
def appendFile(file: Path, data: String, encoding: String): js.Promise[Unit] = js.native
1094+
def appendFile(file: FileHandle, data: String, encoding: String): js.Promise[Unit] = js.native
1095+
1096+
def appendFile(file: Path, data: String): js.Promise[Unit] = js.native
1097+
def appendFile(file: FileHandle, data: String): js.Promise[Unit] = js.native
1098+
1099+
def appendFile(file: Path, data: Buffer): js.Promise[Unit] = js.native
1100+
def appendFile(file: FileHandle, data: Buffer): js.Promise[Unit] = js.native
1101+
1102+
def chmod(path: Path, mode: FileMode): js.Promise[Unit] = js.native
1103+
1104+
def chown(path: Path, uid: UID, gid: GID): js.Promise[Unit] = js.native
1105+
1106+
def copyFile(src: Path, target: Path, mode: FileMode): js.Promise[Unit] = js.native
1107+
def copyFile(src: Path, target: Path): js.Promise[Unit] = js.native
1108+
1109+
def lchmod(path: Path, mode: FileMode): js.Promise[Unit] = js.native
1110+
1111+
def lchown(path: Path, uid: UID, gid: GID): js.Promise[Unit] = js.native
1112+
1113+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
1114+
def lutimes(path: Path, atime: Time, mtime: Time): js.Promise[Unit] = js.native
1115+
1116+
def link(existingPath: Path, newPath: Path): js.Promise[Unit] = js.native
1117+
1118+
def lstat(path: Path, options: StatOptions): js.Promise[StatsVariant] = js.native
1119+
def lstat(path: Path): js.Promise[StatsVariant] = js.native
1120+
1121+
def mkdir(path: Path, options: MkdirOptions): js.Promise[Unit] = js.native
1122+
def mkdir(path: Path, mode: FileMode): js.Promise[Unit] = js.native
1123+
def mkdir(path: Path): js.Promise[Unit] = js.native
10851124

1086-
def appendFile(file: Path, data: String, options: FileAppendOptions): js.Promise[Unit] = js.native
1087-
def appendFile(file: FileDescriptor, data: Buffer, options: FileAppendOptions): js.Promise[Unit] = js.native
1088-
def appendFile(file: Path, data: String, encoding: String): js.Promise[Unit] = js.native
1089-
def appendFile(file: FileDescriptor, data: Buffer, encoding: String): js.Promise[Unit] = js.native
1090-
def appendFile(file: Path, data: String): js.Promise[Unit] = js.native
1091-
def appendFile(file: Path, data: Buffer): js.Promise[Unit] = js.native
1092-
def appendFile(file: FileDescriptor, data: String): js.Promise[Unit] = js.native
1093-
def appendFile(file: FileDescriptor, data: Buffer): js.Promise[Unit] = js.native
1094-
1095-
def chmod(path: Path, mode: FileMode): js.Promise[Unit] = js.native
1096-
def chown(path: Path, uid: UID, gid: GID): js.Promise[Unit] = js.native
1097-
def copyFile(src: Path, target: Path, flag: Int): js.Promise[Unit] = js.native
1098-
def lchmod(path: Path, mode: FileMode): js.Promise[Unit] = js.native
1099-
def lchown(path: Path, uid: UID, gid: GID): js.Promise[Unit] = js.native
1100-
def link(existingPath: Path, newPath: Path): js.Promise[Unit] = js.native
1101-
def lstat(path: Path, options: StatOptions): js.Promise[StatsVariant] = js.native
1102-
def mkdir(path: Path, options: MkdirOptions): js.Promise[Unit] = js.native
1103-
def mkdir(path: Path): js.Promise[Unit] = js.native
1104-
def mkdir(path: Path, mode: FileMode): js.Promise[Unit] = js.native
11051125
def mkdtemp(prefix: String, options: FileEncodingOptions): js.Promise[String] = js.native
11061126
def mkdtemp(prefix: String, encoding: String): js.Promise[String] = js.native
11071127
def mkdtemp(prefix: String): js.Promise[String] = js.native
1108-
def open(path: Path, flags: Flags, mode: FileMode): js.Promise[FileHandle] = js.native
1109-
def open(path: Path, flags: Flags): js.Promise[FileHandle] = js.native
1128+
1129+
def open(path: Path, flags: Flags, mode: FileMode): js.Promise[FileHandle] = js.native
1130+
def open(path: Path, flags: Flags, mode: String): js.Promise[FileHandle] = js.native
1131+
def open(path: Path, flags: Flags): js.Promise[FileHandle] = js.native
11101132
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
11111133
def open(path: Path): js.Promise[FileHandle] = js.native
1112-
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) def opendir(path: Path,
1113-
options: OpendirOptions
1114-
): js.Promise[Dir[String] | Dir[Buffer]] = js.native
1115-
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12) def opendir(
1116-
path: Path
1117-
): js.Promise[Dir[String]] =
1118-
js.native
1134+
1135+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
1136+
def opendir(path: Path, options: OpendirOptions): js.Promise[Dir[String] | Dir[Buffer]] = js.native
1137+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
1138+
def opendir(path: Path): js.Promise[Dir[String]] = js.native
1139+
11191140
def readdir(path: Path, options: ReaddirOptions): js.Promise[ReaddirArrays2] = js.native
11201141
def readdir(path: Path, encoding: String): js.Promise[ReaddirArrays] = js.native
11211142
def readdir(path: Path, options: FileEncodingOptions): js.Promise[ReaddirArrays] = js.native
11221143
def readdir(path: Path): js.Promise[js.Array[String]] = js.native
1123-
def readlink(path: Path): js.Promise[String] = js.native
1124-
def readlink(path: Path, options: String): js.Promise[Output] = js.native
1125-
def readlink(path: Path, options: FileEncodingOptions): js.Promise[Output] = js.native
1126-
def rename(oldPath: Path, newPath: Path): js.Promise[Unit] = js.native
1127-
def rmdir(path: Path): js.Promise[Unit] = js.native
1144+
1145+
def readFile(path: Path, options: String): js.Promise[Output] = js.native
1146+
def readFile(path: Path, options: ReadFileOptions): js.Promise[Output] = js.native
1147+
def readFile(path: Path): js.Promise[String] = js.native
1148+
def readFile(path: FileHandle, options: String): js.Promise[Output] = js.native
1149+
def readFile(path: FileHandle, options: ReadFileOptions): js.Promise[Output] = js.native
1150+
def readFile(path: FileHandle): js.Promise[String] = js.native
1151+
1152+
def readlink(path: Path): js.Promise[String] = js.native
1153+
def readlink(path: Path, options: String): js.Promise[Output] = js.native
1154+
def readlink(path: Path, options: FileEncodingOptions): js.Promise[Output] = js.native
1155+
1156+
def realpath(path: Path, options: ReadFileOptions): js.Promise[Output] = js.native
1157+
def realpath(path: Path, options: String): js.Promise[Output] = js.native
1158+
def realpath(path: Path): js.Promise[String] = js.native
1159+
1160+
def rename(oldPath: Path, newPath: Path): js.Promise[Unit] = js.native
1161+
1162+
def rmdir(path: Path): js.Promise[Unit] = js.native
11281163
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
1129-
def rmdir(path: Path, options: RmdirOptions): js.Promise[Unit] = js.native
1130-
def stat(path: Path, options: StatOptions): js.Promise[StatsVariant] = js.native
1131-
def stat(path: Path): js.Promise[StatsVariant] = js.native
1132-
def symlink(target: Path, path: Path, `type`: String): js.Promise[Unit] = js.native
1133-
def symlink(target: Path, path: Path): js.Promise[Unit] = js.native
1134-
def truncate(path: Path, length: Int): js.Promise[Unit] = js.native
1135-
def truncate(path: Path): js.Promise[Unit] = js.native
1136-
def unlink(path: Path): js.Promise[Unit] = js.native
1137-
def utimes(path: Path, atime: Time, mtime: Time): js.Promise[Unit] = js.native
1164+
def rmdir(path: Path, options: RmdirOptions): js.Promise[Unit] = js.native
1165+
1166+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
1167+
def rm(path: Path, options: RmOptions): js.Promise[Unit] = js.native
1168+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
1169+
def rm(path: Path): js.Promise[Unit] = js.native
1170+
1171+
def stat(path: Path, options: StatOptions): js.Promise[StatsVariant] = js.native
1172+
def stat(path: Path): js.Promise[Stats] = js.native
1173+
1174+
def symlink(target: Path, path: Path, `type`: String): js.Promise[Unit] = js.native
1175+
def symlink(target: Path, path: Path): js.Promise[Unit] = js.native
1176+
1177+
def truncate(path: Path, length: Int): js.Promise[Unit] = js.native
1178+
def truncate(path: Path): js.Promise[Unit] = js.native
1179+
1180+
def unlink(path: Path): js.Promise[Unit] = js.native
1181+
1182+
def utimes(path: Path, atime: Time, mtime: Time): js.Promise[Unit] = js.native
1183+
11381184
def writeFile(file: Path, data: String, options: FileWriteOptions): js.Promise[Unit] = js.native
11391185
def writeFile(file: Path, data: BufferLike, options: FileWriteOptions): js.Promise[Unit] = js.native
1186+
def writeFile(file: Path, data: String): js.Promise[Unit] = js.native
1187+
def writeFile(file: Path, data: BufferLike): js.Promise[Unit] = js.native
11401188
def writeFile(file: FileHandle, data: String, options: FileWriteOptions): js.Promise[Unit] = js.native
11411189
def writeFile(file: FileHandle, data: BufferLike, options: FileWriteOptions): js.Promise[Unit] = js.native
1190+
def writeFile(file: FileHandle, data: String): js.Promise[Unit] = js.native
1191+
def writeFile(file: FileHandle, data: BufferLike): js.Promise[Unit] = js.native
11421192
}
11431193

11441194
@js.native
@@ -1313,8 +1363,8 @@ trait StatOptions extends js.Object {
13131363

13141364
@Factory
13151365
trait MkdirOptions extends js.Object {
1316-
var recursive: js.UndefOr[Boolean] = js.undefined
1317-
var mode: js.UndefOr[FileMode] = js.undefined
1366+
var recursive: js.UndefOr[Boolean] = js.undefined
1367+
var mode: js.UndefOr[FileMode | String] = js.undefined
13181368
}
13191369

13201370
@Factory
@@ -1327,10 +1377,16 @@ trait RmdirOptions extends js.Object {
13271377
@deprecated("Use maxRetries", "Node.js v13.3.0, v12.16.0")
13281378
var maxBusyTries: js.UndefOr[Int] = js.undefined
13291379
var maxRetries: js.UndefOr[Int] = js.undefined
1330-
@deprecated(
1331-
"Tha option has been removed, and EMFILE errors use the same retry logic as other errors.",
1332-
"Node.js v13.3.0, v12.16.0"
1333-
)
1380+
var retryDelay: js.UndefOr[Int] = js.undefined
1381+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs12)
1382+
var recursive: js.UndefOr[Boolean] = js.undefined
1383+
}
1384+
1385+
@enableMembersIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
1386+
@Factory
1387+
trait RmOptions extends js.Object {
1388+
var force: js.UndefOr[Boolean] = js.undefined
1389+
var maxRetries: js.UndefOr[Int] = js.undefined
13341390
var retryDelay: js.UndefOr[Int] = js.undefined
13351391
var recursive: js.UndefOr[Boolean] = js.undefined
13361392
}

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/fs/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scala.scalajs.js.{typedarray, |}
1313
*/
1414
package object fs {
1515
type Path = typedarray.Uint8Array | String | URL
16-
type Time = Int | String | js.Date
16+
type Time = Double | String | js.Date
1717
type BufferLike = typedarray.TypedArray[_, _] | typedarray.DataView
1818
type Output = String | Buffer
1919
type FileWriteOptions = FileAppendOptions

0 commit comments

Comments
 (0)