effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
334 stars 24 forks source link

Use a relative path for loading the JS main #566

Closed marzipankaiser closed 2 months ago

marzipankaiser commented 2 months ago

Currently, the generated script for loading the compiled JavaScript uses an absolute path. This prevents moving the generated files.

This makes it so a relative path is used instead.

jiribenes commented 2 months ago

Motivation: If you compile some Effekt file like main.effekt on the JS backend using effekt --build --backend js main.effekt, the resulting file out/main is just a thin wrapper containing the following:

#!/usr/bin/env node
require('/a/long/path/to/./out/main.js').main()

Unfortunately, this prevents any attempts at packaging the resulting application in a reasonable way since the path is absolute. Instead, it should perhaps be a relative path like require('./main.js').main() and we then trust the packager to bundle the runner script together with the JS file.

jiribenes commented 2 months ago

Currently errors out on Windows with:

Error: Cannot find module './D:\a\effekt\effekt\out\tests\effekt.javascripttests\sideeffects.js'
Require stack:
- D:\a\effekt\effekt\out\tests\effekt.javascripttests\sideeffects__main.js
  [...]
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\a\\effekt\\effekt\\out\\tests\\effekt.javascripttests\\sideeffects__main.js'
  ]
}
jiribenes commented 2 months ago

We also might want to check what happens on the Chez backends wrt this issue 👀

jiribenes commented 2 months ago

https://github.com/effekt-lang/effekt/blob/8c1c05780108664095cf0b2147edd67e121d9e49/effekt/jvm/src/main/scala/effekt/Runner.scala#L217-L226