Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed #112 (path.exists -> fs.exists)

  • Loading branch information...
commit 7ddb9e768a0ad8cd557d33120caae2250101f34c 1 parent b438550
@bjouhier bjouhier authored
View
8 FAQ.md
@@ -68,21 +68,21 @@ f(_); // throws the exception
console.log("after f(_)"); // you won't see this one
```
-### I'm calling `path.exists(fname, _)` and it does not work. What am I doing wrong?
+### I'm calling `fs.exists(fname, _)` and it does not work. What am I doing wrong?
Streamline is designed to work with functions that take standard node callbacks, i.e. callbacks that have the standard `cb(err[, result])` signature.
-Unfortunately some libraries use a different callback signature, and node itself has a few exceptions, the most notable one being `path.exists` which does not have any `err` parameter in its callback.
+Unfortunately some libraries use a different callback signature, and node itself has a few exceptions, the most notable one being `fs.exists` which does not have any `err` parameter in its callback.
The workaround is to write a small wrapper that re-aligns the callback parameters on the standard:
``` javascript
function exists(fname, cb) {
- path.exists(fname, function(result) { cb(null, result); });
+ fs.exists(fname, function(result) { cb(null, result); });
}
console.log(__filename + ': ' + exists(__filename, _)); // works
-console.log(__filename + ': ' + path.exists(__filename, _)); // does not work
+console.log(__filename + ': ' + fs.exists(__filename, _)); // does not work
```
### I'm calling an async function without `_` and I'm not getting a future back. What's wrong?
View
4 lib/compiler/compile._js
@@ -10,7 +10,7 @@ var fs = require("fs");
var fspath = require("path");
function _exists(callback, fname) {
- fspath.exists(fname, function(result) {
+ (fs.exists || fspath.exists)(fname, function(result) {
callback(null, result);
})
}
@@ -323,7 +323,7 @@ function mkdirsSync(path) {
i = 0;
path.split('/').slice(0, -1).forEach(function(seg) {
p += (i++ ? '/' : '') + seg;
- if (i > 1 && !fspath.existsSync(p)) fs.mkdirSync(p, dirMode);
+ if (i > 1 && !(fs.existsSync || fspath.existsSync)(p)) fs.mkdirSync(p, dirMode);
});
}
View
4 lib/compiler/compile.js
@@ -10,7 +10,7 @@
var fspath = require("path");
function _exists(callback, fname) {
- fspath.exists(fname, function(result) {
+ ((fs.exists || fspath.exists))(fname, function(result) {
callback(null, result); });};
@@ -323,7 +323,7 @@ function mkdirsSync(path) {
path.split("/").slice(0, -1).forEach(function(seg) {
p += (((i++ ? "/" : "")) + seg);
- if (((i > 1) && !fspath.existsSync(p))) { fs.mkdirSync(p, dirMode); }; });};
+ if (((i > 1) && !((fs.existsSync || fspath.existsSync))(p))) { fs.mkdirSync(p, dirMode); }; });};
View
2  lib/tools/docTool._js
@@ -30,7 +30,7 @@ var fs = require('fs');
var fsp = require('path');
function exists(cb, p) {
- fsp.exists(p, function(result) {
+ (fs.exists || fsp.exists)(p, function(result) {
cb(null, result)
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.