hopp.js 901 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env node
  2. // * The entry point of the CLI
  3. // @ts-check
  4. import { cli } from "../dist/index.js";
  5. import { spawnSync } from "child_process";
  6. import { cloneDeep } from "lodash-es";
  7. const nodeVersion = parseInt(process.versions.node.split(".")[0]);
  8. // As per isolated-vm documentation, we need to supply `--no-node-snapshot` for node >= 20
  9. // src: https://github.com/laverdet/isolated-vm?tab=readme-ov-file#requirements
  10. if (nodeVersion >= 20 && !process.execArgv.includes("--no-node-snapshot")) {
  11. const argCopy = cloneDeep(process.argv);
  12. // Replace first argument with --no-node-snapshot
  13. // We can get argv[0] from process.argv0
  14. argCopy[0] = "--no-node-snapshot";
  15. const result = spawnSync(
  16. process.argv0,
  17. argCopy,
  18. { stdio: "inherit" }
  19. );
  20. // Exit with the same status code as the spawned process
  21. process.exit(result.status ?? 0);
  22. } else {
  23. cli(process.argv);
  24. }