aboutsummaryrefslogtreecommitdiff
path: root/src/compiler.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-09-30 10:24:53 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-09-30 10:24:53 -0700
commitb614f2bc5d9fc421565824b1ceb9a3384f26f35f (patch)
tree243c47baa4c6ce4273a5743d79f3c0dbc78789e5 /src/compiler.js
parentc70758e3b49beb016a3d9db7b609c499d55de48b (diff)
parent7eaa78060c34489c7e56193c725641303d520f31 (diff)
Merge branch 'incoming'
Diffstat (limited to 'src/compiler.js')
-rw-r--r--src/compiler.js31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 89da32d5..2863afda 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -31,15 +31,30 @@ if (ENVIRONMENT_IS_NODE) {
var nodeFS = require('fs');
var nodePath = require('path');
- read = function(filename) {
- filename = nodePath['normalize'](filename);
- var ret = nodeFS['readFileSync'](filename).toString();
- // The path is absolute if the normalized version is the same as the resolved.
- if (!ret && filename != nodePath['resolve'](filename)) {
- filename = path.join(__dirname, '..', 'src', filename);
- ret = nodeFS['readFileSync'](filename).toString();
+ if (!nodeFS.existsSync) {
+ nodeFS.existsSync = function(path) {
+ try {
+ return !!nodeFS.readFileSync(path);
+ } catch(e) {
+ return false;
+ }
+ }
+ }
+
+ function find(filename) {
+ var prefixes = [__dirname, process.cwd()];
+ for (var i = 0; i < prefixes.length; ++i) {
+ var combined = nodePath.join(prefixes[i], filename);
+ if (nodeFS.existsSync(combined)) {
+ return combined;
+ }
}
- return ret;
+ return filename;
+ }
+
+ read = function(filename) {
+ var absolute = find(filename);
+ return nodeFS['readFileSync'](absolute).toString();
};
load = function(f) {