-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
We could also support QuickJS & MozJS by writing a temporary file, but loading node modules (if needed) would be tricky. |
Cross does not seem to support Windows is, as usual, weird:
|
Right, of course it is… Surely cross-rs/cross#973 will be merged soon… |
50fa2e6
to
31838dc
Compare
Note to self: add these back if QuickJS and MozJS are ever supported. --- a/cli/src/generate/dsl.js
+++ b/cli/src/generate/dsl.js
@@ -459,6 +459,8 @@ function checkPrecedence(value) {
function getEnv(name) {
if (globalThis.process) return process.env[name]; // Node/Bun
if (globalThis.Deno) return Deno.env.get(name); // Deno
+ if (globalThis.std) return std.getenv(name); // QuickJS
+ if (globalThis.os?.getenv) return os.getenv(name); // MozJS
throw Error("Unsupported JS runtime");
}
@@ -482,6 +484,10 @@ if (globalThis.process) { // Node/Bun
process.stdout.write(output);
} else if (globalThis.Deno) { // Deno
Deno.stdout.writeSync(new TextEncoder().encode(output));
+} else if (globalThis.std) { // QuickJS
+ std.out.puts(output);
+} else if (globalThis.putstr) { // MozJS
+ putstr(output);
} else {
throw Error("Unsupported JS runtime");
}
|
This also adds support for ES modules
ES module import does not support absolute Windows paths
Problem
The
generate
command currently only supports Node out of the box and Bun via a shim that callsbun -
.Solution
global
with the universalglobalThis
.require()
with the universalawait import()
.Notes
--allow-env --allow-read
but we use--allow-all
since grammars may need more.