Skip to content

Commit 0495e75

Browse files
rivysindresorhus
andcommitted
Fix Windows issues (#8)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent fffe855 commit 0495e75

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
os:
2+
- linux
3+
- osx
4+
- windows
15
language: node_js
26
node_js:
37
- '12'

api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const {promisify} = require('util');
33
const path = require('path');
44
const fs = require('fs');
5+
const normalizePath = process.platform === 'win32' ? require('normalize-path') : x => x;
56
const writeFileAtomic = require('write-file-atomic');
67
const escapeStringRegexp = require('escape-string-regexp');
78
const arrify = require('arrify');
@@ -33,7 +34,8 @@ module.exports = async (filePaths, {find, replacement, ignoreCase, glob} = {}) =
3334
.replace(/\\r/g, '\r')
3435
.replace(/\\t/g, '\t');
3536

36-
filePaths = glob ? await globby(filePaths) : [...new Set(filePaths.map(filePath => path.resolve(filePath)))];
37+
// TODO: Drop the `normalizePath` call when https://github.com/mrmlnc/fast-glob/issues/240 is fixed.
38+
filePaths = glob ? await globby(filePaths.map(filePath => normalizePath(filePath))) : [...new Set(filePaths.map(filePath => normalizePath(path.resolve(filePath))))];
3739

3840
find = find.map(element => {
3941
const iFlag = ignoreCase ? 'i' : '';

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"escape-string-regexp": "^2.0.0",
4646
"globby": "^10.0.1",
4747
"meow": "^5.0.0",
48+
"normalize-path": "^3.0.0",
4849
"write-file-atomic": "^3.0.0"
4950
},
5051
"devDependencies": {

test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fs from 'fs';
2-
import os from 'os';
32
import path from 'path';
43
import test from 'ava';
54
import execa from 'execa';
@@ -39,15 +38,15 @@ test('multiple newlines and tabs', async t => {
3938

4039
test('globs', async t => {
4140
const filePaths = [await tempWrite('foo bar foo', 'a.glob'), await tempWrite('foo bar foo', 'b.glob')];
42-
const tmpdir = os.tmpdir();
41+
const dirnames = filePaths.map(filePath => path.dirname(filePath));
4342

44-
await execa('./cli.js', ['--string=bar', '--replacement=foo', path.join(tmpdir, '*', '*.glob')]);
43+
await execa('./cli.js', ['--string=bar', '--replacement=foo', path.join(dirnames[0], '*.glob'), path.join(dirnames[1], '*.glob')]);
4544
t.is(fs.readFileSync(filePaths[0], 'utf8'), 'foo foo foo');
4645
t.is(fs.readFileSync(filePaths[1], 'utf8'), 'foo foo foo');
4746
});
4847

4948
test('no globs', async t => {
50-
const filePaths = [await tempWrite('foo bar foo', '*.glob'), await tempWrite('foo bar foo', 'foo.glob')];
49+
const filePaths = [await tempWrite('foo bar foo', process.platform === 'win32' ? 'STAR.glob' : '*.glob'), await tempWrite('foo bar foo', 'foo.glob')];
5150
const dirnames = filePaths.map(filePath => path.dirname(filePath));
5251

5352
await t.throwsAsync(

0 commit comments

Comments
 (0)