mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
resolve paths relative to the user's working directory
This commit is contained in:
parent
b81de7863d
commit
a3d3384293
@ -10,6 +10,9 @@ SET _BASEPATH=%_BASEPATH:~0,-1%
|
||||
REM for whatever reason, Rhino requires module paths to be valid URIs
|
||||
SET _URLPATH=file:/%_BASEPATH%
|
||||
|
||||
REM we need the ability to resolve paths relative to the user's pwd
|
||||
SET PWD=%cd%
|
||||
|
||||
IF "%_URLPATH%"=="%_URLPATH: =%" GOTO NO_SPACES
|
||||
:ESCAPE_SPACE
|
||||
SET _TRAILING=%_URLPATH:* =%
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
|
||||
var path = require('jsdoc/path');
|
||||
|
||||
var pwd = process.env.PWD;
|
||||
|
||||
/**
|
||||
@constructor
|
||||
@param {object} opts
|
||||
@ -15,11 +17,9 @@ var path = require('jsdoc/path');
|
||||
@param {string|RegExp} opts.excludePattern
|
||||
*/
|
||||
exports.Filter = function(opts) {
|
||||
var cwd = process.cwd();
|
||||
|
||||
this.exclude = opts.exclude && Array.isArray(opts.exclude) ?
|
||||
opts.exclude.map(function($) {
|
||||
return path.resolve(cwd, $);
|
||||
return path.resolve(pwd, $);
|
||||
}) :
|
||||
null;
|
||||
this.includePattern = opts.includePattern?
|
||||
@ -35,7 +35,7 @@ exports.Filter = function(opts) {
|
||||
@returns {boolean} Should the given file be included?
|
||||
*/
|
||||
exports.Filter.prototype.isIncluded = function(filepath) {
|
||||
filepath = path.resolve(process.cwd(), filepath);
|
||||
filepath = path.resolve(pwd, filepath);
|
||||
|
||||
if ( this.includePattern && !this.includePattern.test(filepath) ) {
|
||||
return false;
|
||||
|
||||
@ -24,7 +24,7 @@ exports.Scanner.prototype = Object.create( require('events').EventEmitter.protot
|
||||
@fires sourceFileFound
|
||||
*/
|
||||
exports.Scanner.prototype.scan = function(searchPaths, depth, filter) {
|
||||
var cwd = process.cwd(),
|
||||
var pwd = process.env.PWD,
|
||||
filePaths = [],
|
||||
self = this;
|
||||
|
||||
@ -34,11 +34,11 @@ exports.Scanner.prototype.scan = function(searchPaths, depth, filter) {
|
||||
searchPaths.forEach(function($) {
|
||||
var filepath = decodeURIComponent($);
|
||||
if ( fs.statSync(filepath).isFile() ) {
|
||||
filePaths.push( path.resolve(cwd, filepath) );
|
||||
filePaths.push( path.resolve(pwd, filepath) );
|
||||
}
|
||||
else {
|
||||
filePaths = filePaths.concat( fs.ls(filepath, depth).map(function(item) {
|
||||
return path.resolve(cwd, item);
|
||||
return path.resolve(pwd, item);
|
||||
}) );
|
||||
}
|
||||
});
|
||||
|
||||
@ -6,7 +6,7 @@ describe("jsdoc/src/filter", function() {
|
||||
exclude: ['.ignore', 'scratch/conf.js']
|
||||
});
|
||||
|
||||
var files = ['yes.js', '/yes.jsdoc', '/_nope.js', '.ignore', process.cwd() + '/scratch/conf.js'];
|
||||
var files = ['yes.js', '/yes.jsdoc', '/_nope.js', '.ignore', process.env.PWD + '/scratch/conf.js'];
|
||||
|
||||
files = files.filter(function($) {
|
||||
return filter.isIncluded($);
|
||||
|
||||
@ -6,10 +6,10 @@ describe("jsdoc/src/scanner", function() {
|
||||
excludePattern: new RegExp("(^|\\/|\\\\)_")
|
||||
}),
|
||||
path = require('path'),
|
||||
sourceFiles = scanner.scan([path.join(__dirname, 'test', 'fixtures', 'src')], 3, filter);
|
||||
sourceFiles = scanner.scan([path.join(process.env.PWD, 'test', 'fixtures', 'src')], 3, filter);
|
||||
|
||||
sourceFiles = sourceFiles.map(function($) {
|
||||
return path.relative(__dirname, $);
|
||||
return path.relative(process.env.PWD, $);
|
||||
});
|
||||
|
||||
it("should return the correct source files", function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user