fork-with-node-options.js 820 B

12345678910111213141516171819202122232425
  1. const { execFileSync } = require('node:child_process');
  2. const path = require('node:path');
  3. const fixtures = path.resolve(__dirname, '..');
  4. const failJs = path.join(fixtures, 'module', 'fail.js');
  5. const env = {
  6. ELECTRON_RUN_AS_NODE: 'true',
  7. // Process will exit with 1 if NODE_OPTIONS is accepted.
  8. NODE_OPTIONS: `--require "${failJs}"`,
  9. // Try bypassing the check with NODE_REPL_EXTERNAL_MODULE.
  10. NODE_REPL_EXTERNAL_MODULE: failJs
  11. };
  12. // Provide a lower cased NODE_OPTIONS in case some code ignores case sensitivity
  13. // when reading NODE_OPTIONS.
  14. env.node_options = env.NODE_OPTIONS;
  15. try {
  16. execFileSync(process.argv[2],
  17. ['--require', path.join(fixtures, 'module', 'noop.js')],
  18. { env, stdio: 'inherit' });
  19. process.exit(0);
  20. } catch {
  21. console.log('NODE_OPTIONS passed to child');
  22. process.exit(1);
  23. }