Skip to content

Commit 40128d6

Browse files
doowbphated
authored andcommitted
Fix: Handle Windows path separators when calculating base path on Windows (fixes #68) (#69)
1 parent 353a810 commit 40128d6

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

appveyor.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Test against these versions of Node.js
2+
environment:
3+
matrix:
4+
# node.js
5+
- nodejs_version: "6.0"
6+
- nodejs_version: "5.0"
7+
- nodejs_version: "4.0"
8+
- nodejs_version: "0.12"
9+
- nodejs_version: "0.10"
10+
11+
# Install scripts. (runs after repo cloning)
12+
install:
13+
# Get the latest stable version of Node.js or io.js
14+
- ps: Install-Product node $env:nodejs_version
15+
# install modules
16+
- npm install
17+
18+
# Post-install test scripts.
19+
test_script:
20+
# Output useful info for debugging.
21+
- node --version
22+
- npm --version
23+
# run tests
24+
- npm test
25+
26+
# Don't actually build.
27+
build: off

index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var resolveGlob = require('to-absolute-glob');
1010
var globParent = require('glob-parent');
1111
var path = require('path');
1212
var extend = require('extend');
13+
var sepRe = (process.platform === 'win32' ? /[\/\\]/ : /\/+/);
1314

1415
var gs = {
1516
// Creates a stream for a single glob or filter
@@ -190,7 +191,19 @@ function globIsSingular(glob) {
190191
}
191192

192193
function getBasePath(ourGlob, opt) {
193-
return resolveGlob(globParent(ourGlob) + path.sep, opt);
194+
var basePath;
195+
var parent = globParent(ourGlob);
196+
197+
if (parent === '/' && opt && opt.root) {
198+
basePath = path.normalize(opt.root);
199+
} else {
200+
basePath = resolveGlob(parent, opt);
201+
}
202+
203+
if (!sepRe.test(basePath.charAt(basePath.length - 1))) {
204+
basePath += path.sep;
205+
}
206+
return basePath;
194207
}
195208

196209
module.exports = gs;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"index.js"
1616
],
1717
"scripts": {
18-
"lint": "eslint . && jscs *.js test/",
18+
"lint": "eslint . && jscs . test/",
1919
"pretest": "npm run lint",
2020
"test": "mocha",
2121
"coveralls": "istanbul cover _mocha --report lcovonly && istanbul-coveralls"

0 commit comments

Comments
 (0)