From fc2b4ad3d2f77c33285a3e9854cfa5ec45d57c12 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Thu, 30 Oct 2014 12:06:26 -0700 Subject: [PATCH] fix Windows path issues and static-file copying (#785) - In the default template, look for the list of static file paths in the config property `templates.default.staticFiles.include`. (You can still use `paths` instead of `include`.) - Handle path-normalization issues that prevented the default template from copying user-specified static files on Windows. - Normalize paths in `fs.toDir` so that callers get the correct path separator on Windows. --- lib/jsdoc/tag/dictionary/definitions.js | 2 ++ node/fs.js | 4 +++- rhino/fs.js | 5 ++++- templates/default/publish.js | 12 ++++++++---- test/specs/tags/overviewtag.js | 7 +++++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/jsdoc/tag/dictionary/definitions.js b/lib/jsdoc/tag/dictionary/definitions.js index 498de112..d862fca9 100644 --- a/lib/jsdoc/tag/dictionary/definitions.js +++ b/lib/jsdoc/tag/dictionary/definitions.js @@ -58,6 +58,8 @@ function filepathMinusPrefix(filepath) { var commonPrefix = path.commonPrefix(sourcePaths); var result = ''; + filepath = path.normalize(filepath); + if (filepath) { // always use forward slashes result = (filepath + path.sep).replace(commonPrefix, '') diff --git a/node/fs.js b/node/fs.js index c9b59321..bf652f27 100644 --- a/node/fs.js +++ b/node/fs.js @@ -8,6 +8,8 @@ var wrench = require('wrench'); var toDir = exports.toDir = function(_path) { var isDirectory; + _path = path.normalize(_path); + try { isDirectory = fs.statSync(_path).isDirectory(); } @@ -15,7 +17,7 @@ var toDir = exports.toDir = function(_path) { isDirectory = false; } - if (isDirectory){ + if (isDirectory) { return _path; } else { return path.dirname(_path); diff --git a/rhino/fs.js b/rhino/fs.js index 40bfd38d..8261e319 100644 --- a/rhino/fs.js +++ b/rhino/fs.js @@ -85,7 +85,10 @@ exports.readdir = asyncify(readdirSync); // JSDoc extension to `fs` module var toDir = exports.toDir = function toDir(_path) { - var f = new java.io.File( path.resolve(global.env.pwd, _path) ); + var f; + + _path = path.normalize(_path); + f = new java.io.File( path.resolve(global.env.pwd, _path) ); if ( f.isDirectory() ){ return _path; diff --git a/templates/default/publish.js b/templates/default/publish.js index cc81c1e4..05dfe1a5 100644 --- a/templates/default/publish.js +++ b/templates/default/publish.js @@ -19,7 +19,7 @@ var hasOwnProp = Object.prototype.hasOwnProperty; var data; var view; -var outdir = env.opts.destination; +var outdir = path.normalize(env.opts.destination); function find(spec) { return helper.find(data, spec); @@ -426,8 +426,8 @@ exports.publish = function(taffyData, opts, tutorials) { var conf = env.conf.templates || {}; conf['default'] = conf['default'] || {}; - var templatePath = opts.template; - view = new template.Template(templatePath + '/tmpl'); + var templatePath = path.normalize(opts.template); + view = new template.Template( path.join(templatePath, 'tmpl') ); // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness // doesn't try to hand them out later @@ -512,7 +512,11 @@ exports.publish = function(taffyData, opts, tutorials) { var staticFileFilter; var staticFileScanner; if (conf['default'].staticFiles) { - staticFilePaths = conf['default'].staticFiles.paths || []; + // The canonical property name is `include`. We accept `paths` for backwards compatibility + // with a bug in JSDoc 3.2.x. + staticFilePaths = conf['default'].staticFiles.include || + conf['default'].staticFiles.paths || + []; staticFileFilter = new (require('jsdoc/src/filter')).Filter(conf['default'].staticFiles); staticFileScanner = new (require('jsdoc/src/scanner')).Scanner(); diff --git a/test/specs/tags/overviewtag.js b/test/specs/tags/overviewtag.js index 5208df5e..1d3568a8 100644 --- a/test/specs/tags/overviewtag.js +++ b/test/specs/tags/overviewtag.js @@ -48,6 +48,7 @@ describe("@overview tag", function() { it('The name should not include the entire filepath when the source file is outside the ' + 'JSDoc directory', function() { var Doclet = require('jsdoc/doclet').Doclet; + var os = require('os'); var doclet; var docletMeta; @@ -60,6 +61,12 @@ describe("@overview tag", function() { env.sourceFiles = []; env.opts._ = [fakePath]; + // ensure that paths are resolved consistently on Windows + if (os.platform().indexOf('win') === 0) { + fakePath = 'c:' + fakePath; + env.pwd = 'c:' + env.pwd; + } + // create a doclet with a fake filepath, then add a `@file` tag docletSrc = '/** @class */'; docletMeta = {