Comparing version 0.1.2 to 0.1.3
24
main.js
@@ -16,1 +16,25 @@ var fs = require("fs"); | ||
}; | ||
// Not perfect, but we need to match the behavior of install.js. | ||
var requireExp = /\brequire\(['"]([^'"]+)['"]\)/g; | ||
// This function should match the behavior of `ready` and `absolutize` in | ||
// install.js, but the implementations are not worth unifying because we have | ||
// access to the "path" module here. | ||
exports.getRequiredIDs = function(id, source) { | ||
var match, seen = {}, ids = []; | ||
requireExp.lastIndex = 0; | ||
while ((match = requireExp.exec(source))) { | ||
var rid = match[1]; | ||
if (rid.charAt(0) === ".") | ||
rid = path.normalize(path.join(id, "..", match[1])); | ||
if (!seen.hasOwnProperty(rid)) { | ||
seen[rid] = true; | ||
ids.push(rid); | ||
} | ||
} | ||
return ids; | ||
}; |
@@ -18,3 +18,3 @@ { | ||
], | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"homepage": "http://github.com/benjamn/install", | ||
@@ -21,0 +21,0 @@ "repository": { |
@@ -208,3 +208,3 @@ var main = require("../main"); | ||
install("path/to/n", function(require, exports) { | ||
function n(require, exports) { | ||
assert.strictEqual(require("./o").value, value); | ||
@@ -221,5 +221,11 @@ assert.strictEqual(require("../to/o").value, value); | ||
assert.deepEqual( | ||
main.getRequiredIDs("path/to/n", n.toString()), | ||
["path/to/o"]); | ||
finish(t); | ||
}); | ||
} | ||
install("path/to/n", n); | ||
install("path/to/o", function(require, exports) { | ||
@@ -226,0 +232,0 @@ exports.value = value; |
59145
615