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

feat(dsl)!: support other JS runtimes #3355

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ObserverOfTime
Copy link
Member

@ObserverOfTime ObserverOfTime commented May 8, 2024

Problem

The generate command currently only supports Node out of the box and Bun via a shim that calls bun -.

Solution

  • Replace the Node-specific global with the universal globalThis.
  • Replace the Node-specific require() with the universal await import().
    • This also adds support for ES modules but no longer works in Node out of the box.
  • Adapt the environment & stdout functions depending on the runtime.
  • Set the required arguments for known runtimes (Node, Bun, Deno).
    • The user can still specify a different command or the full path for custom runtimes.

Notes

  • In Deno, the DSL only needs --allow-env --allow-read but we use --allow-all since grammars may need more.
    • The other runtimes are not restrictive anyway.
  • QuickJS does not support reading input from stdin at the moment.
  • MozJS does not support reading input from stdin as a module at the moment.

@ObserverOfTime ObserverOfTime added this to the 0.23 milestone May 8, 2024
@ObserverOfTime
Copy link
Member Author

We could also support QuickJS & MozJS by writing a temporary file, but loading node modules (if needed) would be tricky.

@ObserverOfTime
Copy link
Member Author

Cross does not seem to support --input-type. Is it using a version of Node older than 12.0?

Windows is, as usual, weird:

 TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "\\?\D:\a\tree-sitter\tree-sitter\test\fixtures\test_grammars\uses_current_column\grammar.js" is not a valid package name imported from D:\a\tree-sitter\tree-sitter\cli\[eval1]

@ObserverOfTime
Copy link
Member Author

ObserverOfTime commented May 8, 2024

Is it using a version of Node older than 12.0?

Right, of course it is… Surely cross-rs/cross#973 will be merged soon…

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

Successfully merging this pull request may close these issues.

None yet

1 participant