mziyut / articles

mziyut's articles
1 stars 0 forks source link

execjs が実行する Node.js の path #15

Open mziyut opened 1 year ago

mziyut commented 1 year ago

https://github.com/rails/execjs

GitHub
GitHub - rails/execjs: Run JavaScript code from Ruby
Run JavaScript code from Ruby. Contribute to rails/execjs development by creating an account on GitHub.
mziyut commented 1 year ago

https://github.com/rails/execjs/blob/d19a51d43a4dfb20b0f539d0c81d16ab69904e21/lib/execjs/runtimes.rb#L18-L23

    Node = ExternalRuntime.new(
      name:        "Node.js (V8)",
      command:     ["node", "nodejs"],
      runner_path: ExecJS.root + "/support/node_runner.js",
      encoding:    'UTF-8'
    )

https://github.com/rails/execjs/blob/f49db2167accbc1b8ec117e12dd397ed8a5a2534/lib/execjs/module.rb#L30-L32

    def root
      @root ||= File.expand_path("..", __FILE__)
    end

https://github.com/rails/execjs/blob/d19a51d43a4dfb20b0f539d0c81d16ab69904e21/lib/execjs/support/node_runner.js#L1-L34

(function(program, execJS) { execJS(program) })(function(global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
}, function(program) {
  var __process__ = process;

  var printFinal = function(string) {
    process.stdout.write('' + string, function() {
      __process__.exit(0);
    });
  };
  try {
    delete this.process;
    delete this.console;
    delete this.setTimeout;
    delete this.setInterval;
    delete this.clearTimeout;
    delete this.clearInterval;
    delete this.setImmediate;
    delete this.clearImmediate;
    result = program();
    this.process = __process__;
    if (typeof result == 'undefined' && result !== null) {
      printFinal('["ok"]');
    } else {
      try {
        printFinal(JSON.stringify(['ok', result]));
      } catch (err) {
        printFinal(JSON.stringify(['err', '' + err, err.stack]));
      }
    }
  } catch (err) {
    this.process = __process__;
    printFinal(JSON.stringify(['err', '' + err, err.stack]));
  }
});
GitHub
execjs/lib/execjs/runtimes.rb at d19a51d43a4dfb20b0f539d0c81d16ab69904e21 · rails/execjs
Run JavaScript code from Ruby. Contribute to rails/execjs development by creating an account on GitHub.
GitHub
execjs/lib/execjs/module.rb at f49db2167accbc1b8ec117e12dd397ed8a5a2534 · rails/execjs
Run JavaScript code from Ruby. Contribute to rails/execjs development by creating an account on GitHub.
GitHub
execjs/lib/execjs/support/node_runner.js at d19a51d43a4dfb20b0f539d0c81d16ab69904e21 · rails/execjs
Run JavaScript code from Ruby. Contribute to rails/execjs development by creating an account on GitHub.