Skip to content

Commit

Permalink
Allow execution of the peggy binary on Windows.
Browse files Browse the repository at this point in the history
Handle node runtime flags manually, executing a sub-instance of node to actually run `peggy`.

Fixes #514.
  • Loading branch information
hildjj committed Sep 29, 2024
1 parent 85f1d79 commit c765d60
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Released: TBD

- [#531](https://github.com/peggyjs/peggy/issues/531) Clean up rollup hacks
from CLI code.
- [#514](https://github.com/peggyjs/peggy/issues/514) Allow execution of
the `peggy` binary on Windows by handling node runtime flags manually,
executing a sub-instance of node to actually run `peggy`.

### Documentation

Expand Down
23 changes: 22 additions & 1 deletion bin/peggy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
#!/usr/bin/env -S node --experimental-vm-modules --no-warnings
#!/usr/bin/env node

"use strict";

// Since Windows can't handle `env -S`, exec once to get permission
// to use the vm module in its modern form.
const execArgv = new Set(process.execArgv);
if (!execArgv.has("--experimental-vm-modules")) {
execArgv.add("--experimental-vm-modules");
execArgv.add("--no-warnings");
const { spawnSync } = require("child_process");
// NOTE: Does not replace process. Node can't do that, apparently.
const { status, signal, error } = spawnSync(process.argv[0], [
...execArgv,
...process.argv.slice(1),
], { stdio: "inherit" });
if (error) {
throw error;
}
if (signal) {
process.kill(process.pid, signal);
}
process.exit(status);
}

const {
CommanderError, InvalidArgumentError, PeggyCLI,
} = require("./peggy-cli.js");
Expand Down

0 comments on commit c765d60

Please sign in to comment.