diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-11-21 09:48:45 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-11-21 10:50:52 -0800 |
commit | b488be127a8cf1e59eb257db3f8eaf6efdb0f275 (patch) | |
tree | 83436f4f84b9651ea66c3a0d304050252916c149 /deps/npm/lib/utils/completion/file-completion.js | |
parent | 05de01d707cd9a80f34da23445f507f5f2e2c277 (diff) | |
download | node-new-b488be127a8cf1e59eb257db3f8eaf6efdb0f275.tar.gz |
Include NPM, update .pkg to install it.
.msi update coming soon.
Diffstat (limited to 'deps/npm/lib/utils/completion/file-completion.js')
-rw-r--r-- | deps/npm/lib/utils/completion/file-completion.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/deps/npm/lib/utils/completion/file-completion.js b/deps/npm/lib/utils/completion/file-completion.js new file mode 100644 index 0000000000..427efefb44 --- /dev/null +++ b/deps/npm/lib/utils/completion/file-completion.js @@ -0,0 +1,29 @@ +module.exports = fileCompletion + +var find = require("../find.js") + , mkdir = require("../mkdir-p.js") + , path = require("path") + +function fileCompletion (root, req, depth, cb) { + if (typeof cb !== "function") cb = depth, depth = Infinity + mkdir(root, function (er) { + if (er) return cb(er) + function dirFilter (f, type) { + // return anything that is a file, + // or not exactly the req. + return type !== "dir" || + ( f && f !== path.join(root, req) + && f !== path.join(root, req) + "/" ) + } + find(path.join(root, req), dirFilter, depth, function (er, files) { + if (er) return cb(er) + return cb(null, (files || []).map(function (f) { + return path.join(req, f.substr(root.length + 1) + .substr((f === req ? path.dirname(req) + : req).length) + .replace(/^\//, "")) + })) + }) + }) +} + |