Kotlin / kotlinx-nodejs

Kotlin external declarations for using the Node.js API from Kotlin code targeting JavaScript
https://kotl.in/js
Apache License 2.0
215 stars 19 forks source link

fs.promises API does not seem to work #5

Open vlsi opened 4 years ago

vlsi commented 4 years ago

See https://nodejs.org/api/fs.html#fs_fs_promises_api

The fs.promises API provides an alternative set of asynchronous file system methods that return Promise objects rather than using callbacks. The API is accessible via require('fs').promises or require('fs/promises')

It looks like fs.promises is not right here: https://github.com/Kotlin/kotlinx-nodejs/blob/85512009c3b8f14449a7dbd8305a9fef797d6afb/kotlinx-nodejs/src/fs.fs.promises.module_node.kt#L1

I'm not sure what declare module "fs/promises" means in TypeScript, however, the following Kotlin declaration works:

@file:JsModule("fs")
@file:JsQualifier("promises")
package ...

import kotlin.js.Promise

external fun unlink(paths: String): Promise<Unit>
vlsi commented 4 years ago

@file:JsModule("fs/promises") produces

Caused by: java.lang.IllegalStateException: Module 'fs/promises' not found
        at org.jetbrains.kotlin.gradle.internal.ExecKt$execWithErrorLogger$1.invoke(exec.kt:91)
        at org.jetbrains.kotlin.gradle.internal.ExecKt$execWithErrorLogger$1.invoke(exec.kt)
        at org.jetbrains.kotlin.gradle.internal.ProgressKt.operation(progress.kt:23)
        at org.jetbrains.kotlin.gradle.internal.ProgressKt.operation$default(progress.kt:15)
        at org.jetbrains.kotlin.gradle.internal.ExecKt.execWithErrorLogger(exec.kt:75)
        at org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackRunner.execute(KotlinWebpackRunner.kt:24)
        at org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack.doExecute(KotlinWebpack.kt:229)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:104)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:49)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:42)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:726)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:693)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.run(ExecuteActionsTaskExecuter.java:569)
vlsi commented 4 years ago

The following works (I'm not sure if it should work or if it should not):

@file:JsModule("fs")
@file:JsQualifier("promises")
package ...

import kotlin.js.Promise

external fun unlink(paths: String): Promise<Unit>
turansky commented 4 years ago

cc @ilgonmic