/
index.js
49 lines (43 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const fs = require('fs');
const path = require('path');
const globby = require('globby');
const pTry = require('p-try');
const macos = require('./lib/macos');
const linux = require('./lib/linux');
const windows = require('./lib/windows');
module.exports = (iterable, options) => pTry(() => {
iterable = [...(typeof iterable === 'string' ? [iterable] : iterable)].map(String);
options = {
glob: true,
...options
};
// TOOD: Upgrading to latest `globby` version is blocked by https://github.com/mrmlnc/fast-glob/issues/110
const paths = (options.glob === false ? iterable : globby.sync(iterable, {
expandDirectories: false,
nodir: false,
nonull: true
}))
.map(filePath => path.resolve(filePath))
.filter(filePath => {
try {
return fs.lstatSync(filePath);
} catch (error) {
if (error.code === 'ENOENT') {
return false;
}
throw error;
}
});
if (paths.length === 0) {
return;
}
switch (process.platform) {
case 'darwin':
return macos(paths);
case 'win32':
return windows(paths);
default:
return linux(paths);
}
});