mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
resolve relative paths before scanning/filtering (#405)
This commit is contained in:
parent
78c0437f79
commit
8a6fe881e8
@ -5,6 +5,8 @@
|
||||
@license Apache License 2.0 - See file 'LICENSE.md' in this project.
|
||||
*/
|
||||
|
||||
var path = require('jsdoc/path');
|
||||
|
||||
/**
|
||||
@constructor
|
||||
@param {object} opts
|
||||
@ -13,7 +15,13 @@
|
||||
@param {string|RegExp} opts.excludePattern
|
||||
*/
|
||||
exports.Filter = function(opts) {
|
||||
this.exclude = opts.exclude || null;
|
||||
var cwd = process.cwd();
|
||||
|
||||
this.exclude = opts.exclude && Array.isArray(opts.exclude) ?
|
||||
opts.exclude.map(function($) {
|
||||
return path.resolve(cwd, $);
|
||||
}) :
|
||||
null;
|
||||
this.includePattern = opts.includePattern?
|
||||
typeof opts.includePattern === 'string'? new RegExp(opts.includePattern) : opts.includePattern
|
||||
: null;
|
||||
@ -27,6 +35,8 @@ exports.Filter = function(opts) {
|
||||
@returns {boolean} Should the given file be included?
|
||||
*/
|
||||
exports.Filter.prototype.isIncluded = function(filepath) {
|
||||
filepath = path.resolve(process.cwd(), filepath);
|
||||
|
||||
if ( this.includePattern && !this.includePattern.test(filepath) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
|
||||
var fs = require('jsdoc/fs');
|
||||
var path = require('jsdoc/path');
|
||||
|
||||
/**
|
||||
@constructor
|
||||
@ -23,7 +24,8 @@ exports.Scanner.prototype = Object.create( require('events').EventEmitter.protot
|
||||
@fires sourceFileFound
|
||||
*/
|
||||
exports.Scanner.prototype.scan = function(searchPaths, depth, filter) {
|
||||
var filePaths = [],
|
||||
var cwd = process.cwd(),
|
||||
filePaths = [],
|
||||
self = this;
|
||||
|
||||
searchPaths = searchPaths || [];
|
||||
@ -32,10 +34,12 @@ exports.Scanner.prototype.scan = function(searchPaths, depth, filter) {
|
||||
searchPaths.forEach(function($) {
|
||||
var filepath = decodeURIComponent($);
|
||||
if ( fs.statSync(filepath).isFile() ) {
|
||||
filePaths.push(filepath);
|
||||
filePaths.push( path.resolve(cwd, filepath) );
|
||||
}
|
||||
else {
|
||||
filePaths = filePaths.concat(fs.ls(filepath, depth));
|
||||
filePaths = filePaths.concat( fs.ls(filepath, depth).map(function(item) {
|
||||
return path.resolve(cwd, item);
|
||||
}) );
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/*global describe: true, expect: true, it: true */
|
||||
describe("jsdoc/src/filter", function() {
|
||||
var filter = new (require('jsdoc/src/filter').Filter)({
|
||||
includePattern: new RegExp(".+\\.js(doc)?$"),
|
||||
@ -5,7 +6,7 @@ describe("jsdoc/src/filter", function() {
|
||||
exclude: ['.ignore', 'scratch/conf.js']
|
||||
});
|
||||
|
||||
var files = ['yes.js', '/yes.jsdoc', '/_nope.js', '.ignore'];
|
||||
var files = ['yes.js', '/yes.jsdoc', '/_nope.js', '.ignore', process.cwd() + '/scratch/conf.js'];
|
||||
|
||||
files = files.filter(function($) {
|
||||
return filter.isIncluded($);
|
||||
@ -16,4 +17,4 @@ describe("jsdoc/src/filter", function() {
|
||||
expect(files.indexOf("yes.js")).toBeGreaterThan(-1);
|
||||
expect(files.indexOf("/yes.jsdoc")).toBeGreaterThan(-1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user