jrburke/r.js — pull request #630 by jroper (2014-02-19 05:30:57+00:00)
Title: Don't detect Trireme as Rhino

Trireme is an emulation of node.js that runs on Rhino:

https://github.com/apigee/trireme

It provides the node API, and should be treated by r.js as node. However, r.js detects Rhino by checking for the existence of Packages before checking for node. This then promptly fails a few lines of code later, here:

```javascript
fileName = args[0];

if (fileName && fileName.indexOf('-') === 0) {
commandOption = fileName.substring(1);
fileName = args[1];
}
```

Because for some reason (possibly a bug in Trireme?), although args[0] returned an object, that object doesn't have an indexOf method. At any rate, the correct way to get the command line arguments in trireme is to use the node api, process.argv.

Presumably this can be solved by trying to detect node before trying to detect rhino, and I assume that should be fine because I don't think anyone's going to ever try to emulate Rhino on node. If someone confirms that changing the detection order is an appropriate solution, I'll happily submit a pull request. I've tested, if you swap them around, r.js does detect node, and it works.