UNPKG

1.76 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isGlob = isGlob;
7exports.isGlobMatch = isGlobMatch;
8exports.globSync = globSync;
9exports.glob = glob;
10
11var _isGlob2 = _interopRequireDefault(require("is-glob"));
12
13var _fastGlob = _interopRequireDefault(require("fast-glob"));
14
15var _micromatch = require("micromatch");
16
17var _path = require("./path");
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21function isGlob(p) {
22 return (0, _isGlob2.default)((0, _path.normalizeSeparators)(p));
23}
24
25function isGlobMatch(filePath, glob) {
26 return (0, _micromatch.isMatch)(filePath, (0, _path.normalizeSeparators)(glob));
27}
28
29function globSync(p, options) {
30 return _fastGlob.default.sync((0, _path.normalizeSeparators)(p), options);
31}
32
33function glob(p, fs, options) {
34 // $FlowFixMe
35 options = { ...options,
36 fs: {
37 stat: async (p, cb) => {
38 try {
39 cb(null, (await fs.stat(p)));
40 } catch (err) {
41 cb(err);
42 }
43 },
44 lstat: async (p, cb) => {
45 // Our FileSystem interface doesn't have lstat support at the moment,
46 // but this is fine for our purposes since we follow symlinks by default.
47 try {
48 cb(null, (await fs.stat(p)));
49 } catch (err) {
50 cb(err);
51 }
52 },
53 readdir: async (p, opts, cb) => {
54 if (typeof opts === 'function') {
55 cb = opts;
56 opts = null;
57 }
58
59 try {
60 cb(null, (await fs.readdir(p, opts)));
61 } catch (err) {
62 cb(err);
63 }
64 }
65 }
66 }; // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
67
68 return (0, _fastGlob.default)((0, _path.normalizeSeparators)(p), options);
69}
\No newline at end of file