Skip to content

Commit 7ca9987

Browse files
committed
Handle linux paths on windows.
1 parent 5c69804 commit 7ca9987

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

index.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ module.exports = function(glob, options) {
88
// default options
99
var opts = options || {};
1010

11-
// ensure cwd is absolute
12-
var cwd = path.resolve(opts.cwd ? opts.cwd : process.cwd());
13-
cwd = unixify(cwd);
14-
15-
var rootDir = opts.root;
16-
// if `options.root` is defined, ensure it's absolute
17-
if (rootDir) {
18-
rootDir = unixify(rootDir);
19-
if (process.platform === 'win32' || !isAbsolute(rootDir)) {
20-
rootDir = unixify(path.resolve(rootDir));
21-
}
22-
}
11+
// ensure provided paths are absolute
12+
var cwd = ensureAbsolute(opts.cwd ? opts.cwd : process.cwd());
13+
var rootDir = opts.root ? ensureAbsolute(opts.root) : undefined;
2314

2415
// trim starting ./ from glob patterns
2516
if (glob.slice(0, 2) === './') {
@@ -54,6 +45,11 @@ module.exports = function(glob, options) {
5445
return ing.negated ? '!' + glob : glob;
5546
};
5647

48+
function ensureAbsolute(filepath) {
49+
var absoluteFilepath = isAbsolute(filepath) ? filepath : path.resolve(filepath);
50+
return unixify(absoluteFilepath);
51+
}
52+
5753
function unixify(filepath) {
5854
return filepath.replace(/\\/g, '/');
5955
}

test.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,39 @@ describe('resolve', function () {
5656
assert.equal(actual, unixify(path.resolve('.')) + '/\\!(foo)');
5757
});
5858

59-
it('should make a glob absolute from a cwd', function () {
59+
it('should make a glob absolute from a relative cwd', function () {
6060
actual = resolve('a/*.js', {cwd: 'foo'});
6161
assert.equal(actual, unixify(path.resolve('foo/a/*.js')));
6262
});
6363

64-
it('should make a negative glob absolute from a cwd', function () {
64+
it('should make a negative glob absolute from a relative cwd', function () {
6565
actual = resolve('!a/*.js', {cwd: 'foo'});
6666
assert.equal(actual, '!' + unixify(path.resolve('foo/a/*.js')));
6767
});
6868

69-
it('should make a glob absolute from a root path', function () {
69+
it('should make a glob absolute from an absolute cwd', function () {
70+
actual = resolve('a/*.js', {cwd: '/foo'});
71+
assert.equal(actual, unixify('/foo/a/*.js'));
72+
});
73+
74+
it('should make a glob absolute from a relative root path', function () {
7075
actual = resolve('/a/*.js', {root: 'foo'});
7176
assert.equal(actual, unixify(path.resolve('foo/a/*.js')));
7277
});
7378

7479
it('should make a glob absolute from a root slash', function () {
7580
actual = resolve('/a/*.js', {root: '/'});
76-
assert.equal(actual, unixify(path.resolve('/a/*.js')));
81+
assert.equal(actual, unixify('/a/*.js'));
7782
});
7883

79-
it('should make a glob absolute from a negative root path', function () {
84+
it('should make a glob absolute from a negative relative root path', function () {
8085
actual = resolve('!/a/*.js', {root: 'foo'});
8186
assert.equal(actual, '!' + unixify(path.resolve('foo/a/*.js')));
8287
});
8388

8489
it('should make a negative glob absolute from a negative root path', function () {
8590
actual = resolve('!/a/*.js', {root: '/'})
86-
assert.equal(actual, '!' + unixify(path.resolve('/a/*.js')));
91+
assert.equal(actual, '!' + unixify('/a/*.js'));
8792
});
8893
});
8994

@@ -93,14 +98,14 @@ describe('resolve', function () {
9398
assert.equal(actual, unixify(path.resolve('foo/bar')) + '\\!(baz)');
9499
});
95100

96-
it('should make a glob absolute from a root path', function () {
101+
it('should make a glob absolute from a relative root path', function () {
97102
actual = resolve('/a/*.js', {root: 'foo\\bar\\baz'});
98103
assert.equal(actual, unixify(path.resolve('foo/bar/baz/a/*.js')));
99104
});
100105

101106
it('should make a glob absolute from a root slash', function () {
102107
actual = resolve('/a/*.js', {root: '\\'});
103-
assert.equal(actual, unixify(path.resolve('/a/*.js')));
108+
assert.equal(actual, unixify('/a/*.js'));
104109
});
105110
});
106111
});

0 commit comments

Comments
 (0)