2 Copyright (c) 2012, Yahoo! Inc. All rights reserved.
3 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
6 var async = require('async'),
7 fileset = require('fileset'),
9 path = require('path'),
12 function filesFor(options, callback) {
13 if (!callback && typeof options === 'function') {
17 options = options || {};
19 var root = options.root,
20 includes = options.includes,
21 excludes = options.excludes,
22 realpath = options.realpath,
23 relative = options.relative,
26 root = root || process.cwd();
27 includes = includes && Array.isArray(includes) ? includes : [ '**/*.js' ];
28 excludes = excludes && Array.isArray(excludes) ? excludes : [ '**/node_modules/**' ];
30 opts = { cwd: root, nodir: true };
32 opts['x' + seq + new Date().getTime()] = true; //cache buster for minimatch cache bug
33 fileset(includes.join(' '), excludes.join(' '), opts, function (err, files) {
34 if (err) { return callback(err); }
35 if (relative) { return callback(err, files); }
38 files = files.map(function (file) { return path.resolve(root, file); });
39 return callback(err, files);
42 var realPathCache = module.constructor._realpathCache || {};
44 async.map(files, function (file, done) {
45 fs.realpath(path.resolve(root, file), realPathCache, done);
50 function matcherFor(options, callback) {
52 if (!callback && typeof options === 'function') {
56 options = options || {};
57 options.relative = false; //force absolute paths
58 options.realpath = true; //force real paths (to match Node.js module paths)
60 filesFor(options, function (err, files) {
63 if (err) { return callback(err); }
64 files.forEach(function (file) { fileMap[file] = true; });
66 matchFn = function (file) { return fileMap[file]; };
67 matchFn.files = Object.keys(fileMap);
68 return callback(null, matchFn);
74 matcherFor: matcherFor