Permalink
Browse files

computes paths is all for now

  • Loading branch information...
substack committed Sep 22, 2010
0 parents commit b0363ae3d5749b3f7e722b21c65484fdf634acf3
Showing with 46 additions and 0 deletions.
  1. +9 −0 README.md
  2. +37 −0 browserify.js
@@ -0,0 +1,9 @@
Browserify
==========
Turn node modules into browser-compliant javascript.
Note
====
This module is just a stub for now. Stay tuned.
@@ -0,0 +1,37 @@
var path = require('path');
var fs = require('fs');
var Step = require('step');
module.exports = function Browserify (name, nodeSource) {
if (!(this instanceof Browserify)) return new Browserify(name, nodeSource);
if (nodeSource === undefined) nodeSource = process.env.NODE_SOURCE;
var requirePaths = nodeSource
? [ nodeSource + '/lib' ].concat(require.paths)
: require.paths
;
this.path = function (cb) {
Step();
};
this.pathSync = function () {
return firstMap(requirePaths, function (dir) {
if (!path.existsSync(dir)) return undefined;
return firstMap(
[ '.js', '.node', '/index.js', '/index.node' ]
.map(function (suf) { return dir + '/' + name + suf }),
function (file) { if (path.existsSync(file)) return file }
);
});
};
};
function firstMap (xs, f) {
for (var i = 0; i < xs.length; i++) {
var x = f(xs[i], i);
if (x !== undefined) return x;
}
return undefined;
}

0 comments on commit b0363ae

Please sign in to comment.