Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wasmJs target for kotlin-node wrappers #2170

Open
vdshb opened this issue Nov 12, 2023 · 9 comments
Open

Add wasmJs target for kotlin-node wrappers #2170

vdshb opened this issue Nov 12, 2023 · 9 comments

Comments

@vdshb
Copy link

vdshb commented Nov 12, 2023

wasmJs KMP target became available in NodeJs. This is a proposal to make kotlin-node wrappers available on this new target.

@turansky
Copy link
Collaborator

What is your use case?
Which types you need in wasmJs?

@vdshb
Copy link
Author

vdshb commented Jan 28, 2024

@turansky I'm creating a KMP class which starts child process in different targets. It supports kotlin/js and uses

node.childProcess.ChildProcess
node.events.Event

from kotlin-wrappers.

@lppedd
Copy link
Contributor

lppedd commented Feb 1, 2024

I'm also looking for WASM interop with Node.js modules.
An example of what I'd like to replace with proper types is:

@Suppress("UNUSED_PARAMETER")
private fun readFileSync(name: String): String =
  js(
    """
    {
      const fs = require('fs');
      return fs.readFileSync(name, {
        encoding: 'utf8'
      });
    }
    """
  )

public actual fun readBenchmarkFile(name: String): String =
  readFileSync("$basePath$name")

@turansky
Copy link
Collaborator

turansky commented Feb 1, 2024

Why readFileSync isn't declared as external?

@lppedd
Copy link
Contributor

lppedd commented Feb 1, 2024

@turansky because I'm waiting for kotlin-wrappers to offer external types 😆

@turansky
Copy link
Collaborator

turansky commented Feb 1, 2024

I personally use following scripts

Script "I don't need fine externals"
  1. Don't test external on own use cases
    • js calls are fine/
    • No knowledge sharing with community
Script "I need fine externals"
  1. Write fine externals for yourself
  2. Test externals in custom projects
  3. Share detected problems in issue about externals
  4. Share externals, which I wrote, with community
    ...

@lppedd
Copy link
Contributor

lppedd commented Feb 1, 2024

I think the main point here is kotlin-wrappers already have those externals, so why rewrite them?

We should find a way to share them between the js and wasmJs source sets.

@turansky
Copy link
Collaborator

turansky commented Feb 1, 2024

already have those externals, so why rewrite them?

Because they aren't compatible with wasmJs as I know

We should find a way to share them between the js and wasmJs source sets.

If you need all Node.js declarations probably Kotlin/JS is what you need? :)

@lppedd
Copy link
Contributor

lppedd commented Feb 2, 2024

If you need all Node.js declarations probably Kotlin/JS is what you need? :)

I don't need all of them, but I guess being WASM is interoperable with JS, people will adopt it by moving incrementally, only some bits, while still calling JS-first APIs.

Because they aren't compatible with wasmJs as I know

That's true. Looks like on WASM, external JS types must derive from JsAny.
So I think the best approach would be to wait for the K/WASM team to relax the externals requirements.
Maybe you can let them know about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants