rescript-bun icon indicating copy to clipboard operation
rescript-bun copied to clipboard

Rational behins Global and Globals

Open nojaf opened this issue 10 months ago • 2 comments

I very much like this project! Use it often, but unfortunately I aways have to look at the source code when I'm working with it.

Why are Globals and Global two modules?

An example which I struggle with:

open RescriptBun

let exportData = Bun.file(Path.join2(Globals.import.meta.dir, "export_data.json"))
if !(await exportData->Bun.BunFile.exists) {
  Console.log("export_data.json not found")
  Process.process->Process.exitWithCode(1)
}

Finding Globals.import.meta.dir is tedious. Adding open RescriptBun.Globals after open RescriptBun leads to

this open statement shadows the value identifier import (which is later used)ReScript(44)

when using import.meta.

Would it not make sense to merge Global and Globals and export importMeta to avoid the duplicate name?

nojaf avatar Feb 21 '25 13:02 nojaf

IIRC I modelled it after how the TypeScript d.ts types was structured. Very much open to suggestions though, and there's plenty of stuff I'd like to change for ergonomics as well. The Error constructor is another thing that conflicts with opening the globals here.

If you want to take a stab at the issue you're talking about here, as well as any other things, please feel free! I'd be happy to see this worked on. I'll eventually get back to it as well, but it might be a little while.

zth avatar Mar 03 '25 06:03 zth

@nojaf looked at this again. Maybe worth doing something about this? Mull on it and make sure the structure makes sense, and if not, change it.

zth avatar Oct 30 '25 10:10 zth