From a3d3384293d1318c3dfc64d04d85a05d2dd84677 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Mon, 4 Nov 2013 07:12:23 -0800 Subject: [PATCH] resolve paths relative to the user's working directory --- jsdoc.cmd | 3 +++ lib/jsdoc/src/filter.js | 8 ++++---- lib/jsdoc/src/scanner.js | 6 +++--- test/specs/jsdoc/src/filter.js | 2 +- test/specs/jsdoc/src/scanner.js | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/jsdoc.cmd b/jsdoc.cmd index 9bd2a562..f81212d1 100644 --- a/jsdoc.cmd +++ b/jsdoc.cmd @@ -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:* =% diff --git a/lib/jsdoc/src/filter.js b/lib/jsdoc/src/filter.js index 4bd18055..c9e18464 100644 --- a/lib/jsdoc/src/filter.js +++ b/lib/jsdoc/src/filter.js @@ -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; diff --git a/lib/jsdoc/src/scanner.js b/lib/jsdoc/src/scanner.js index 914cf7fe..94d02af2 100644 --- a/lib/jsdoc/src/scanner.js +++ b/lib/jsdoc/src/scanner.js @@ -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); }) ); } }); diff --git a/test/specs/jsdoc/src/filter.js b/test/specs/jsdoc/src/filter.js index 98593378..6a983bbc 100644 --- a/test/specs/jsdoc/src/filter.js +++ b/test/specs/jsdoc/src/filter.js @@ -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($); diff --git a/test/specs/jsdoc/src/scanner.js b/test/specs/jsdoc/src/scanner.js index 3203c2aa..a36b9a8c 100644 --- a/test/specs/jsdoc/src/scanner.js +++ b/test/specs/jsdoc/src/scanner.js @@ -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() {