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.
|
@license Apache License 2.0 - See file 'LICENSE.md' in this project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var path = require('jsdoc/path');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@constructor
|
@constructor
|
||||||
@param {object} opts
|
@param {object} opts
|
||||||
@ -13,7 +15,13 @@
|
|||||||
@param {string|RegExp} opts.excludePattern
|
@param {string|RegExp} opts.excludePattern
|
||||||
*/
|
*/
|
||||||
exports.Filter = function(opts) {
|
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?
|
this.includePattern = opts.includePattern?
|
||||||
typeof opts.includePattern === 'string'? new RegExp(opts.includePattern) : opts.includePattern
|
typeof opts.includePattern === 'string'? new RegExp(opts.includePattern) : opts.includePattern
|
||||||
: null;
|
: null;
|
||||||
@ -27,6 +35,8 @@ exports.Filter = function(opts) {
|
|||||||
@returns {boolean} Should the given file be included?
|
@returns {boolean} Should the given file be included?
|
||||||
*/
|
*/
|
||||||
exports.Filter.prototype.isIncluded = function(filepath) {
|
exports.Filter.prototype.isIncluded = function(filepath) {
|
||||||
|
filepath = path.resolve(process.cwd(), filepath);
|
||||||
|
|
||||||
if ( this.includePattern && !this.includePattern.test(filepath) ) {
|
if ( this.includePattern && !this.includePattern.test(filepath) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
var fs = require('jsdoc/fs');
|
var fs = require('jsdoc/fs');
|
||||||
|
var path = require('jsdoc/path');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@constructor
|
@constructor
|
||||||
@ -23,7 +24,8 @@ exports.Scanner.prototype = Object.create( require('events').EventEmitter.protot
|
|||||||
@fires sourceFileFound
|
@fires sourceFileFound
|
||||||
*/
|
*/
|
||||||
exports.Scanner.prototype.scan = function(searchPaths, depth, filter) {
|
exports.Scanner.prototype.scan = function(searchPaths, depth, filter) {
|
||||||
var filePaths = [],
|
var cwd = process.cwd(),
|
||||||
|
filePaths = [],
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
searchPaths = searchPaths || [];
|
searchPaths = searchPaths || [];
|
||||||
@ -32,10 +34,12 @@ exports.Scanner.prototype.scan = function(searchPaths, depth, filter) {
|
|||||||
searchPaths.forEach(function($) {
|
searchPaths.forEach(function($) {
|
||||||
var filepath = decodeURIComponent($);
|
var filepath = decodeURIComponent($);
|
||||||
if ( fs.statSync(filepath).isFile() ) {
|
if ( fs.statSync(filepath).isFile() ) {
|
||||||
filePaths.push(filepath);
|
filePaths.push( path.resolve(cwd, filepath) );
|
||||||
}
|
}
|
||||||
else {
|
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() {
|
describe("jsdoc/src/filter", function() {
|
||||||
var filter = new (require('jsdoc/src/filter').Filter)({
|
var filter = new (require('jsdoc/src/filter').Filter)({
|
||||||
includePattern: new RegExp(".+\\.js(doc)?$"),
|
includePattern: new RegExp(".+\\.js(doc)?$"),
|
||||||
@ -5,7 +6,7 @@ describe("jsdoc/src/filter", function() {
|
|||||||
exclude: ['.ignore', 'scratch/conf.js']
|
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($) {
|
files = files.filter(function($) {
|
||||||
return filter.isIncluded($);
|
return filter.isIncluded($);
|
||||||
@ -16,4 +17,4 @@ describe("jsdoc/src/filter", function() {
|
|||||||
expect(files.indexOf("yes.js")).toBeGreaterThan(-1);
|
expect(files.indexOf("yes.js")).toBeGreaterThan(-1);
|
||||||
expect(files.indexOf("/yes.jsdoc")).toBeGreaterThan(-1);
|
expect(files.indexOf("/yes.jsdoc")).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user