Permalink
Browse files

Moved check for Node.js environment before the check for window.

This will avoid situations where the browser environment does exist (e.g. via jsdom), but fetchText still needs to be using fs not xhr.
  • Loading branch information...
1 parent d04d2f7 commit 311fd27bf1e095f6295be253372cc808d762fe63 @jaysoo jaysoo committed May 8, 2012
Showing with 9 additions and 9 deletions.
  1. +9 −9 cs.js
View
18 cs.js
@@ -17,7 +17,15 @@ define(['CoffeeScript'], function (CoffeeScript) {
},
buildMap = {};
- if ((typeof window !== "undefined" && window.navigator && window.document) || typeof importScripts !== "undefined") {
+ if (typeof process !== "undefined" &&
+ process.versions &&
+ !!process.versions.node) {
+ //Using special require.nodeRequire, something added by r.js.
+ fs = require.nodeRequire('fs');
+ fetchText = function (path, callback) {
+ callback(fs.readFileSync(path, 'utf8'));
+ };
+ } else if ((typeof window !== "undefined" && window.navigator && window.document) || typeof importScripts !== "undefined") {
// Browser action
getXhr = function () {
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
@@ -58,14 +66,6 @@ define(['CoffeeScript'], function (CoffeeScript) {
xhr.send(null);
};
// end browser.js adapters
- } else if (typeof process !== "undefined" &&
- process.versions &&
- !!process.versions.node) {
- //Using special require.nodeRequire, something added by r.js.
- fs = require.nodeRequire('fs');
- fetchText = function (path, callback) {
- callback(fs.readFileSync(path, 'utf8'));
- };
} else if (typeof Packages !== 'undefined') {
//Why Java, why is this so awkward?
fetchText = function (path, callback) {

0 comments on commit 311fd27

Please sign in to comment.