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

node:process not available on browser #55

Open
ghivert opened this issue Aug 17, 2024 · 3 comments
Open

node:process not available on browser #55

ghivert opened this issue Aug 17, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ghivert
Copy link

ghivert commented Aug 17, 2024

Hi! Thanks for glint, the package is really nice!

I'm wondering about embedding of a gleam runtime in frontend. Currently, when targeting JS, the compiler will output a import * as process from 'node:process' in glint. This means that even if you don't use any functions from glint, the code will crash in browser. Do you think there's a way to avoid this? 🙂

To give a little more context, my idea would be to present only one package, that could be used as a CLI or programmatically, whether in Node/Deno/Bun or in browser. I.e. a universal package, able to be used everywhere.


For example, I'm wondering if we could modify the exit function (which is the only one that requires node:process) to something like:

export function exit(code) {
  import('node:process').then(process => process.exit(code))
  return new gleam.Error('process.exit')
}

In Node & other runtimes, it would not change anything (because process.exit would be called everytime), while in browser it will return an Error in Gleam.

@TanklesXL
Copy link
Owner

Oh that's interesting, thanks for bringing this up!

I have been thinking about the exit behaviours and I wonder if I should have glint return a result or exit code rather than exiting on its own, that would let the user determine what behaviour best fits for them and then removes any target-specific code from glint

@TanklesXL
Copy link
Owner

How does the typing of that new exit function work? I would need to modify it so that glint returns a result I think?

@ghivert
Copy link
Author

ghivert commented Aug 17, 2024

After more thoughts, I think the best would be to simply return a Result(a, Error) and let the user handle the value as you suggest.

In the CLI, we can probably just use the exit function I wrote and return null instead of gleam.Error. So the typing will be the same. Node always make sure that running Promise finishes before shutting down the process. So it will ensures process.exit will be called.

@TanklesXL TanklesXL added the bug Something isn't working label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants