Consider the following trivial clojurescript program:
(ns node-test.core
(:require [cljs.nodejs :as node]))
(defn -main [& args]
(println "args: " args)
(let [one (first args) two (second args)]
(println "one: " one)
(println "two: " two)))
(set! *main-cli-fn* -main)
Problem: If I compile this with no optimizations, this program works as expected. Example:
$ node program.js 1 2
=> args: (1, 2)
one: 1
two: 2
If I compile the program with advanced optimizations, then my program doesn't recognize arguments:
$ node program.js 1 2
=> args: nil
one: nil
two: nil
What could be causing this?
EDIT: Adding the following externs seems to fix the issue:
var node = {};
node.process = {};
node.process.argv = {};
In addition, taking out the node parent object and just using process also fixes it:
var process = {};
process.argv = {};
I'm not really sure I even understand my own solution though. I guess behind the scenes clojurescript is passing node.process.argv to -main?