@gjsify/fs 0.3.12 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/_virtual/_rolldown/runtime.js +18 -0
- package/lib/esm/callback.js +301 -302
- package/lib/esm/cp.js +207 -227
- package/lib/esm/dir.js +140 -148
- package/lib/esm/dirent.js +137 -128
- package/lib/esm/encoding.js +30 -27
- package/lib/esm/errors.js +15 -11
- package/lib/esm/fd-ops.js +105 -122
- package/lib/esm/file-handle.js +648 -653
- package/lib/esm/fs-watcher.js +153 -161
- package/lib/esm/glob.js +148 -149
- package/lib/esm/index.js +158 -351
- package/lib/esm/promises.js +413 -386
- package/lib/esm/read-stream.js +104 -108
- package/lib/esm/stat-watcher.js +113 -114
- package/lib/esm/statfs.js +56 -43
- package/lib/esm/stats.js +166 -159
- package/lib/esm/sync.js +366 -341
- package/lib/esm/types/index.js +6 -6
- package/lib/esm/utils.js +15 -17
- package/lib/esm/utimes.js +26 -37
- package/lib/esm/write-stream.js +96 -108
- package/package.json +10 -10
package/lib/esm/fs-watcher.js
CHANGED
|
@@ -1,171 +1,163 @@
|
|
|
1
|
+
import { normalizePath } from "./utils.js";
|
|
1
2
|
import GLib from "@girs/glib-2.0";
|
|
2
3
|
import Gio from "@girs/gio-2.0";
|
|
3
4
|
import { EventEmitter } from "node:events";
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const priv = privates.get(this);
|
|
68
|
-
if (priv.persistent) {
|
|
69
|
-
priv.persistent = false;
|
|
70
|
-
if (priv.sourceId !== null) {
|
|
71
|
-
GLib.source_remove(priv.sourceId);
|
|
72
|
-
priv.sourceId = null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
5
|
+
|
|
6
|
+
//#region src/fs-watcher.ts
|
|
7
|
+
const privates = new WeakMap();
|
|
8
|
+
var FSWatcher = class extends EventEmitter {
|
|
9
|
+
constructor(filename, options, listener) {
|
|
10
|
+
super();
|
|
11
|
+
if (!options || typeof options !== "object") options = { persistent: true };
|
|
12
|
+
const persistent = options.persistent !== false;
|
|
13
|
+
const cancellable = Gio.Cancellable.new();
|
|
14
|
+
const pathStr = normalizePath(filename);
|
|
15
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
16
|
+
const watcher = file.monitor(Gio.FileMonitorFlags.NONE, cancellable);
|
|
17
|
+
watcher.connect("changed", changed.bind(this));
|
|
18
|
+
let sourceId = null;
|
|
19
|
+
if (persistent) {
|
|
20
|
+
sourceId = GLib.timeout_add(GLib.PRIORITY_LOW, 2147483647, () => GLib.SOURCE_CONTINUE);
|
|
21
|
+
}
|
|
22
|
+
privates.set(this, {
|
|
23
|
+
persistent,
|
|
24
|
+
cancellable,
|
|
25
|
+
sourceId,
|
|
26
|
+
watcher
|
|
27
|
+
});
|
|
28
|
+
if (listener) this.on("change", listener);
|
|
29
|
+
}
|
|
30
|
+
close() {
|
|
31
|
+
const priv = privates.get(this);
|
|
32
|
+
if (!priv.cancellable.is_cancelled()) {
|
|
33
|
+
priv.cancellable.cancel();
|
|
34
|
+
if (priv.sourceId !== null) {
|
|
35
|
+
GLib.source_remove(priv.sourceId);
|
|
36
|
+
priv.sourceId = null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* When called, requests that the Node.js event loop not exit so long as the
|
|
42
|
+
* FSWatcher is active. Calling ref() multiple times has no effect.
|
|
43
|
+
*/
|
|
44
|
+
ref() {
|
|
45
|
+
const priv = privates.get(this);
|
|
46
|
+
if (!priv.persistent && !priv.cancellable.is_cancelled()) {
|
|
47
|
+
priv.persistent = true;
|
|
48
|
+
priv.sourceId = GLib.timeout_add(GLib.PRIORITY_LOW, 2147483647, () => GLib.SOURCE_CONTINUE);
|
|
49
|
+
}
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* When called, the active FSWatcher will not require the Node.js event loop
|
|
54
|
+
* to remain active. Calling unref() multiple times has no effect.
|
|
55
|
+
*/
|
|
56
|
+
unref() {
|
|
57
|
+
const priv = privates.get(this);
|
|
58
|
+
if (priv.persistent) {
|
|
59
|
+
priv.persistent = false;
|
|
60
|
+
if (priv.sourceId !== null) {
|
|
61
|
+
GLib.source_remove(priv.sourceId);
|
|
62
|
+
priv.sourceId = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
78
68
|
;
|
|
79
69
|
function changed(watcher, file, otherFile, eventType) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
70
|
+
switch (eventType) {
|
|
71
|
+
case Gio.FileMonitorEvent.CHANGES_DONE_HINT:
|
|
72
|
+
this.emit("change", "change", file.get_basename());
|
|
73
|
+
break;
|
|
74
|
+
case Gio.FileMonitorEvent.DELETED:
|
|
75
|
+
case Gio.FileMonitorEvent.CREATED:
|
|
76
|
+
case Gio.FileMonitorEvent.RENAMED:
|
|
77
|
+
case Gio.FileMonitorEvent.MOVED_IN:
|
|
78
|
+
case Gio.FileMonitorEvent.MOVED_OUT:
|
|
79
|
+
this.emit("rename", "rename", file.get_basename());
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
92
82
|
}
|
|
93
|
-
var fs_watcher_default = FSWatcher;
|
|
94
83
|
function gioEventToNodeType(eventType) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
default:
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
84
|
+
switch (eventType) {
|
|
85
|
+
case Gio.FileMonitorEvent.CHANGES_DONE_HINT: return "change";
|
|
86
|
+
case Gio.FileMonitorEvent.DELETED:
|
|
87
|
+
case Gio.FileMonitorEvent.CREATED:
|
|
88
|
+
case Gio.FileMonitorEvent.RENAMED:
|
|
89
|
+
case Gio.FileMonitorEvent.MOVED_IN:
|
|
90
|
+
case Gio.FileMonitorEvent.MOVED_OUT: return "rename";
|
|
91
|
+
default: return null;
|
|
92
|
+
}
|
|
107
93
|
}
|
|
108
94
|
async function* watchAsync(filename, options) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
95
|
+
const signal = options?.signal;
|
|
96
|
+
if (signal?.aborted) return;
|
|
97
|
+
const pathStr = normalizePath(filename);
|
|
98
|
+
const file = Gio.File.new_for_path(pathStr);
|
|
99
|
+
const cancellable = Gio.Cancellable.new();
|
|
100
|
+
let watcher;
|
|
101
|
+
try {
|
|
102
|
+
watcher = file.monitor(Gio.FileMonitorFlags.NONE, cancellable);
|
|
103
|
+
} catch {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const eventQueue = [];
|
|
107
|
+
const waiterQueue = [];
|
|
108
|
+
let finished = false;
|
|
109
|
+
function enqueue(event) {
|
|
110
|
+
if (finished) return;
|
|
111
|
+
if (waiterQueue.length > 0) {
|
|
112
|
+
waiterQueue.shift().resolve({
|
|
113
|
+
value: event,
|
|
114
|
+
done: false
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
eventQueue.push(event);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function terminate() {
|
|
121
|
+
if (finished) return;
|
|
122
|
+
finished = true;
|
|
123
|
+
if (!cancellable.is_cancelled()) cancellable.cancel();
|
|
124
|
+
while (waiterQueue.length > 0) {
|
|
125
|
+
waiterQueue.shift().resolve({
|
|
126
|
+
value: undefined,
|
|
127
|
+
done: true
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const signalId = watcher.connect("changed", (_mon, changedFile, _otherFile, eventType) => {
|
|
132
|
+
const type = gioEventToNodeType(eventType);
|
|
133
|
+
if (type === null) return;
|
|
134
|
+
enqueue({
|
|
135
|
+
eventType: type,
|
|
136
|
+
filename: changedFile?.get_basename() ?? null
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
const abortHandler = () => terminate();
|
|
140
|
+
signal?.addEventListener("abort", abortHandler);
|
|
141
|
+
try {
|
|
142
|
+
while (!finished) {
|
|
143
|
+
if (eventQueue.length > 0) {
|
|
144
|
+
yield eventQueue.shift();
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const result = await new Promise((resolve) => {
|
|
148
|
+
waiterQueue.push({ resolve });
|
|
149
|
+
});
|
|
150
|
+
if (result.done) break;
|
|
151
|
+
yield result.value;
|
|
152
|
+
}
|
|
153
|
+
} finally {
|
|
154
|
+
signal?.removeEventListener("abort", abortHandler);
|
|
155
|
+
try {
|
|
156
|
+
watcher.disconnect(signalId);
|
|
157
|
+
} catch {}
|
|
158
|
+
if (!cancellable.is_cancelled()) cancellable.cancel();
|
|
159
|
+
}
|
|
166
160
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
watchAsync
|
|
171
|
-
};
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
export { FSWatcher, FSWatcher as default, watchAsync };
|
package/lib/esm/glob.js
CHANGED
|
@@ -1,164 +1,163 @@
|
|
|
1
|
-
import { readdirSync } from "./sync.js";
|
|
2
1
|
import { normalizePath } from "./utils.js";
|
|
2
|
+
import { readdirSync } from "./sync.js";
|
|
3
|
+
|
|
4
|
+
//#region src/glob.ts
|
|
5
|
+
/** Convert a single glob segment (no `/`) to a regex source string */
|
|
3
6
|
function segmentToRegexSrc(seg) {
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
result += c;
|
|
63
|
-
}
|
|
64
|
-
i++;
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
7
|
+
const extglob = /^([!*+?@])\((.+)\)$/.exec(seg);
|
|
8
|
+
if (extglob) {
|
|
9
|
+
const [, type, inner] = extglob;
|
|
10
|
+
const parts = inner.split("|").map((p) => segmentToRegexSrc(p));
|
|
11
|
+
const group = "(?:" + parts.join("|") + ")";
|
|
12
|
+
switch (type) {
|
|
13
|
+
case "!": return "(?!(?:" + parts.join("|") + "))[^/]*";
|
|
14
|
+
case "*": return group + "*";
|
|
15
|
+
case "+": return group + "+";
|
|
16
|
+
case "?": return group + "?";
|
|
17
|
+
case "@": return group;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
let result = "";
|
|
21
|
+
let i = 0;
|
|
22
|
+
while (i < seg.length) {
|
|
23
|
+
const c = seg[i];
|
|
24
|
+
if (c === "*") {
|
|
25
|
+
result += "[^/]*";
|
|
26
|
+
i++;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (c === "?") {
|
|
30
|
+
result += "[^/]";
|
|
31
|
+
i++;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (c === "[") {
|
|
35
|
+
const end = seg.indexOf("]", i + 1);
|
|
36
|
+
if (end === -1) {
|
|
37
|
+
result += "\\[";
|
|
38
|
+
i++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
result += seg.slice(i, end + 1);
|
|
42
|
+
i = end + 1;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (c === "{") {
|
|
46
|
+
const end = seg.indexOf("}", i + 1);
|
|
47
|
+
if (end === -1) {
|
|
48
|
+
result += "\\{";
|
|
49
|
+
i++;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const alts = seg.slice(i + 1, end).split(",").map((a) => segmentToRegexSrc(a.trim()));
|
|
53
|
+
result += "(?:" + alts.join("|") + ")";
|
|
54
|
+
i = end + 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (".+^$|()[]{}".includes(c)) {
|
|
58
|
+
result += "\\" + c;
|
|
59
|
+
} else {
|
|
60
|
+
result += c;
|
|
61
|
+
}
|
|
62
|
+
i++;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
67
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Convert a glob pattern to a RegExp that matches relative POSIX paths.
|
|
68
|
+
*/
|
|
68
69
|
function globToRegex(pattern) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
70
|
+
pattern = pattern.replace(/\/+/g, "/").replace(/^\.\//, "");
|
|
71
|
+
const segments = pattern.split("/");
|
|
72
|
+
const parts = [];
|
|
73
|
+
for (let si = 0; si < segments.length; si++) {
|
|
74
|
+
const seg = segments[si];
|
|
75
|
+
const isLast = si === segments.length - 1;
|
|
76
|
+
if (seg === "**") {
|
|
77
|
+
if (isLast) {
|
|
78
|
+
if (parts.length > 0 && parts[parts.length - 1] === "/") {
|
|
79
|
+
parts.pop();
|
|
80
|
+
parts.push("(?:/.+)?");
|
|
81
|
+
} else {
|
|
82
|
+
parts.push("(?:.+)?");
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
parts.push("(?:[^/]+/)*");
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
parts.push(segmentToRegexSrc(seg));
|
|
89
|
+
if (!isLast) parts.push("/");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return new RegExp("^(?:" + parts.join("") + ")$");
|
|
92
93
|
}
|
|
93
94
|
function buildExcludePredicate(exclude) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
if (!exclude) return null;
|
|
96
|
+
if (typeof exclude === "function") return exclude;
|
|
97
|
+
const patterns = Array.isArray(exclude) ? exclude : [exclude];
|
|
98
|
+
const regexes = patterns.map((p) => globToRegex(p));
|
|
99
|
+
return (path) => regexes.some((rx) => rx.test(path));
|
|
99
100
|
}
|
|
100
101
|
function matchAll(pattern, cwd, exclude) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
102
|
+
const regex = globToRegex(pattern);
|
|
103
|
+
const isExcluded = buildExcludePredicate(exclude);
|
|
104
|
+
let allEntries;
|
|
105
|
+
try {
|
|
106
|
+
allEntries = readdirSync(cwd, { recursive: true });
|
|
107
|
+
} catch {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const candidates = [".", ...allEntries];
|
|
111
|
+
const results = [];
|
|
112
|
+
for (const entry of candidates) {
|
|
113
|
+
const normalized = entry.replace(/\\/g, "/");
|
|
114
|
+
if (!regex.test(normalized)) continue;
|
|
115
|
+
if (isExcluded && isExcluded(normalized)) continue;
|
|
116
|
+
results.push(entry);
|
|
117
|
+
}
|
|
118
|
+
return results;
|
|
118
119
|
}
|
|
119
120
|
function globSync(pattern, options) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
122
|
+
const cwd = options?.cwd ? normalizePath(options.cwd) : globalThis.process?.cwd?.() ?? "/";
|
|
123
|
+
const exclude = options?.exclude;
|
|
124
|
+
const seen = new Set();
|
|
125
|
+
const results = [];
|
|
126
|
+
for (const p of patterns) {
|
|
127
|
+
for (const match of matchAll(p, cwd, exclude)) {
|
|
128
|
+
if (!seen.has(match)) {
|
|
129
|
+
seen.add(match);
|
|
130
|
+
results.push(match);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return results;
|
|
134
135
|
}
|
|
135
136
|
function glob(pattern, options, callback) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
137
|
+
let opts;
|
|
138
|
+
let cb;
|
|
139
|
+
if (typeof options === "function") {
|
|
140
|
+
cb = options;
|
|
141
|
+
opts = {};
|
|
142
|
+
} else {
|
|
143
|
+
cb = callback;
|
|
144
|
+
opts = options || {};
|
|
145
|
+
}
|
|
146
|
+
Promise.resolve().then(() => {
|
|
147
|
+
try {
|
|
148
|
+
const matches = globSync(pattern, opts);
|
|
149
|
+
cb(null, matches);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
cb(err, []);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
153
154
|
}
|
|
154
155
|
async function* globAsync(pattern, options) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
const matches = globSync(pattern, options);
|
|
157
|
+
for (const m of matches) {
|
|
158
|
+
yield m;
|
|
159
|
+
}
|
|
159
160
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
globSync
|
|
164
|
-
};
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
163
|
+
export { glob, globAsync, globSync };
|