resolve paths relative to the user's working directory

This commit is contained in:
Jeff Williams 2013-11-04 07:12:23 -08:00
parent b81de7863d
commit a3d3384293
5 changed files with 13 additions and 10 deletions

View File

@ -10,6 +10,9 @@ SET _BASEPATH=%_BASEPATH:~0,-1%
REM for whatever reason, Rhino requires module paths to be valid URIs REM for whatever reason, Rhino requires module paths to be valid URIs
SET _URLPATH=file:/%_BASEPATH% 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 IF "%_URLPATH%"=="%_URLPATH: =%" GOTO NO_SPACES
:ESCAPE_SPACE :ESCAPE_SPACE
SET _TRAILING=%_URLPATH:* =% SET _TRAILING=%_URLPATH:* =%

View File

@ -7,6 +7,8 @@
var path = require('jsdoc/path'); var path = require('jsdoc/path');
var pwd = process.env.PWD;
/** /**
@constructor @constructor
@param {object} opts @param {object} opts
@ -15,11 +17,9 @@ var path = require('jsdoc/path');
@param {string|RegExp} opts.excludePattern @param {string|RegExp} opts.excludePattern
*/ */
exports.Filter = function(opts) { exports.Filter = function(opts) {
var cwd = process.cwd();
this.exclude = opts.exclude && Array.isArray(opts.exclude) ? this.exclude = opts.exclude && Array.isArray(opts.exclude) ?
opts.exclude.map(function($) { opts.exclude.map(function($) {
return path.resolve(cwd, $); return path.resolve(pwd, $);
}) : }) :
null; null;
this.includePattern = opts.includePattern? this.includePattern = opts.includePattern?
@ -35,7 +35,7 @@ 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); filepath = path.resolve(pwd, filepath);
if ( this.includePattern && !this.includePattern.test(filepath) ) { if ( this.includePattern && !this.includePattern.test(filepath) ) {
return false; return false;

View File

@ -24,7 +24,7 @@ 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 cwd = process.cwd(), var pwd = process.env.PWD,
filePaths = [], filePaths = [],
self = this; self = this;
@ -34,11 +34,11 @@ 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( path.resolve(cwd, filepath) ); filePaths.push( path.resolve(pwd, filepath) );
} }
else { else {
filePaths = filePaths.concat( fs.ls(filepath, depth).map(function(item) { filePaths = filePaths.concat( fs.ls(filepath, depth).map(function(item) {
return path.resolve(cwd, item); return path.resolve(pwd, item);
}) ); }) );
} }
}); });

View File

@ -6,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', process.cwd() + '/scratch/conf.js']; var files = ['yes.js', '/yes.jsdoc', '/_nope.js', '.ignore', process.env.PWD + '/scratch/conf.js'];
files = files.filter(function($) { files = files.filter(function($) {
return filter.isIncluded($); return filter.isIncluded($);

View File

@ -6,10 +6,10 @@ describe("jsdoc/src/scanner", function() {
excludePattern: new RegExp("(^|\\/|\\\\)_") excludePattern: new RegExp("(^|\\/|\\\\)_")
}), }),
path = require('path'), 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($) { sourceFiles = sourceFiles.map(function($) {
return path.relative(__dirname, $); return path.relative(process.env.PWD, $);
}); });
it("should return the correct source files", function() { it("should return the correct source files", function() {