From 40128d6c6343e153eb09bf29a67d58ccc4c57582 Mon Sep 17 00:00:00 2001 From: Brian Woodward Date: Fri, 26 Aug 2016 14:19:52 -0400 Subject: [PATCH] Fix: Handle Windows path separators when calculating base path on Windows (fixes #68) (#69) --- appveyor.yml | 27 +++++++++++++++++++++++++++ index.js | 15 ++++++++++++++- package.json | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..05ff977 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,27 @@ +# Test against these versions of Node.js +environment: + matrix: + # node.js + - nodejs_version: "6.0" + - nodejs_version: "5.0" + - nodejs_version: "4.0" + - nodejs_version: "0.12" + - nodejs_version: "0.10" + +# Install scripts. (runs after repo cloning) +install: + # Get the latest stable version of Node.js or io.js + - ps: Install-Product node $env:nodejs_version + # install modules + - npm install + +# Post-install test scripts. +test_script: + # Output useful info for debugging. + - node --version + - npm --version + # run tests + - npm test + +# Don't actually build. +build: off diff --git a/index.js b/index.js index f795959..363a29d 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ var resolveGlob = require('to-absolute-glob'); var globParent = require('glob-parent'); var path = require('path'); var extend = require('extend'); +var sepRe = (process.platform === 'win32' ? /[\/\\]/ : /\/+/); var gs = { // Creates a stream for a single glob or filter @@ -190,7 +191,19 @@ function globIsSingular(glob) { } function getBasePath(ourGlob, opt) { - return resolveGlob(globParent(ourGlob) + path.sep, opt); + var basePath; + var parent = globParent(ourGlob); + + if (parent === '/' && opt && opt.root) { + basePath = path.normalize(opt.root); + } else { + basePath = resolveGlob(parent, opt); + } + + if (!sepRe.test(basePath.charAt(basePath.length - 1))) { + basePath += path.sep; + } + return basePath; } module.exports = gs; diff --git a/package.json b/package.json index 23c3b00..b782289 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "index.js" ], "scripts": { - "lint": "eslint . && jscs *.js test/", + "lint": "eslint . && jscs . test/", "pretest": "npm run lint", "test": "mocha", "coveralls": "istanbul cover _mocha --report lcovonly && istanbul-coveralls"