From 146d6ac538ba3ee5985b330b5ac079f2c556f24a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Cruz?= Date: Sat, 10 Aug 2013 21:48:26 +0100 Subject: [PATCH] Normalise windows paths, closes #279. --- lib/commands/list.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/commands/list.js b/lib/commands/list.js index 10cf3d85..57c81256 100644 --- a/lib/commands/list.js +++ b/lib/commands/list.js @@ -17,20 +17,25 @@ function list(options, config) { project.getTree() .spread(function (tree, flattened) { - var baseDir; + var baseDir = path.dirname(path.join(config.cwd, config.directory)); - // Relativize? - if (options.relative) { - baseDir = path.dirname(path.join(config.cwd, config.directory)); - - project.walkTree(tree, function (node) { + // Relativize paths + // Also normalize paths on windows + project.walkTree(tree, function (node) { + if (options.relative) { node.canonicalDir = path.relative(baseDir, node.canonicalDir); - }, true); + } + node.canonicalDir = normalize(node.canonicalDir); + }, true); - mout.object.forOwn(flattened, function (node) { + // Note that we need to to parse the flattened tree because it might + // contain additional packages + mout.object.forOwn(flattened, function (node) { + if (options.relative) { node.canonicalDir = path.relative(baseDir, node.canonicalDir); - }); - } + } + node.canonicalDir = normalize(node.canonicalDir); + }); // Render paths? if (options.paths) { @@ -119,7 +124,7 @@ function paths(flattened) { // Concatenate each main entry with the canonical dir main = main.map(function (part) { - return path.join(pkg.canonicalDir, part).trim(); + return normalize(path.join(pkg.canonicalDir, part).trim()); }).join(','); ret[name] = main; @@ -128,6 +133,10 @@ function paths(flattened) { return ret; } +function normalize(src) { + return src.replace(/\\/g, '/'); +} + // ------------------- list.line = function (argv) {