@atlaspack/fs 2.12.1-canary.3354

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/browser.js ADDED
@@ -0,0 +1,1134 @@
1
+ var $eHCLO$path = require("path");
2
+ var $eHCLO$stream = require("stream");
3
+ var $eHCLO$util = require("util");
4
+ var $eHCLO$buffer = require("buffer");
5
+ var $eHCLO$atlaspackcore = require("@atlaspack/core");
6
+ var $eHCLO$atlaspackutils = require("@atlaspack/utils");
7
+ var $eHCLO$atlaspackworkers = require("@atlaspack/workers");
8
+ var $eHCLO$events = require("events");
9
+
10
+
11
+ function $atlaspack$interopDefault(a) {
12
+ return a && a.__esModule ? a.default : a;
13
+ }
14
+
15
+ function $atlaspack$exportWildcard(dest, source) {
16
+ Object.keys(source).forEach(function(key) {
17
+ if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
18
+ return;
19
+ }
20
+
21
+ Object.defineProperty(dest, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return source[key];
25
+ }
26
+ });
27
+ });
28
+
29
+ return dest;
30
+ }
31
+
32
+ function $atlaspack$export(e, n, v, s) {
33
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
34
+ }
35
+
36
+ $atlaspack$export(module.exports, "ncp", () => $416aba2172cbc610$export$d3a8044e3fef7335);
37
+
38
+
39
+
40
+ var $4d6ec4a7ba8784a9$exports = {};
41
+
42
+ $atlaspack$export($4d6ec4a7ba8784a9$exports, "NodeFS", () => $4d6ec4a7ba8784a9$export$c4e0ef2ab73c21e7);
43
+ // $FlowFixMe[prop-missing] handled by the throwing constructor
44
+ class $4d6ec4a7ba8784a9$export$c4e0ef2ab73c21e7 {
45
+ constructor(){
46
+ throw new Error("NodeFS isn't available in the browser");
47
+ }
48
+ }
49
+
50
+
51
+ var $995ba0f44994569b$exports = {};
52
+
53
+ $atlaspack$export($995ba0f44994569b$exports, "MemoryFS", () => $995ba0f44994569b$export$3048eb7ec07c2c4e);
54
+ $atlaspack$export($995ba0f44994569b$exports, "FSError", () => $995ba0f44994569b$export$d414276624ebf134);
55
+ $atlaspack$export($995ba0f44994569b$exports, "makeShared", () => $995ba0f44994569b$export$df9eb3e75aa27a22);
56
+ $atlaspack$export($995ba0f44994569b$exports, "File", () => $995ba0f44994569b$export$b6afa8811b7e644e);
57
+
58
+
59
+
60
+
61
+ var $b6ff243d7d5008ac$exports = {};
62
+ $b6ff243d7d5008ac$exports = JSON.parse("{\"name\":\"@atlaspack/fs\",\"version\":\"2.12.1-canary.3354+7bb54d46a\",\"description\":\"Blazing fast, zero configuration web application bundler\",\"license\":\"MIT\",\"publishConfig\":{\"access\":\"public\"},\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/atlassian-labs/atlaspack.git\"},\"main\":\"lib/index.js\",\"source\":\"src/index.js\",\"types\":\"index.d.ts\",\"engines\":{\"node\":\">= 16.0.0\"},\"targets\":{\"types\":false,\"main\":{\"includeNodeModules\":{\"@atlaspack/core\":false,\"@atlaspack/feature-flags\":false,\"@atlaspack/rust\":false,\"@atlaspack/types-internal\":false,\"@atlaspack/utils\":false,\"@atlaspack/watcher-watchman-js\":false,\"@parcel/watcher\":false,\"@atlaspack/workers\":false}},\"browser\":{\"includeNodeModules\":{\"@atlaspack/core\":false,\"@atlaspack/feature-flags\":false,\"@atlaspack/rust\":false,\"@atlaspack/types-internal\":false,\"@atlaspack/utils\":false,\"@atlaspack/watcher-watchman-js\":false,\"@parcel/watcher\":false,\"@atlaspack/workers\":false}}},\"scripts\":{\"build-ts\":\"mkdir -p lib && flow-to-ts src/types.js > lib/types.d.ts\",\"check-ts\":\"tsc --noEmit index.d.ts\"},\"dependencies\":{\"@atlaspack/feature-flags\":\"2.12.1-canary.3354+7bb54d46a\",\"@atlaspack/rust\":\"2.12.1-canary.3354+7bb54d46a\",\"@atlaspack/types-internal\":\"2.12.1-canary.3354+7bb54d46a\",\"@atlaspack/utils\":\"2.12.1-canary.3354+7bb54d46a\",\"@atlaspack/workers\":\"2.12.1-canary.3354+7bb54d46a\",\"@parcel/watcher\":\"^2.0.7\"},\"devDependencies\":{\"@atlaspack/watcher-watchman-js\":\"2.12.1-canary.3354+7bb54d46a\",\"graceful-fs\":\"^4.2.4\",\"ncp\":\"^2.0.0\",\"nullthrows\":\"^1.1.1\",\"utility-types\":\"^3.10.0\"},\"peerDependencies\":{\"@atlaspack/core\":\"2.12.1-canary.3354+7bb54d46a\"},\"browser\":{\"@atlaspack/fs\":\"./lib/browser.js\",\"./src/NodeFS.js\":\"./src/NodeFS.browser.js\"},\"gitHead\":\"7bb54d46a00c5ba9cdbc2ee426dcbe82c8d79a3e\"}");
63
+
64
+
65
+
66
+ var $023b8d639760db5c$exports = {};
67
+ 'use strict';
68
+ function $023b8d639760db5c$var$nullthrows(x, message) {
69
+ if (x != null) return x;
70
+ var error = new Error(message !== undefined ? message : 'Got unexpected ' + x);
71
+ error.framesToPop = 1; // Skip nullthrows's own stack frame.
72
+ throw error;
73
+ }
74
+ $023b8d639760db5c$exports = $023b8d639760db5c$var$nullthrows;
75
+ $023b8d639760db5c$exports.default = $023b8d639760db5c$var$nullthrows;
76
+ Object.defineProperty($023b8d639760db5c$exports, '__esModule', {
77
+ value: true
78
+ });
79
+
80
+
81
+
82
+
83
+ function $a9ed96e57e8d2cf3$export$4c6d088a7d7f9947(fs, moduleName, dir) {
84
+ let { root: root } = (0, ($atlaspack$interopDefault($eHCLO$path))).parse(dir);
85
+ while(dir !== root){
86
+ // Skip node_modules directories
87
+ if ((0, ($atlaspack$interopDefault($eHCLO$path))).basename(dir) === 'node_modules') dir = (0, ($atlaspack$interopDefault($eHCLO$path))).dirname(dir);
88
+ try {
89
+ let moduleDir = (0, ($atlaspack$interopDefault($eHCLO$path))).join(dir, 'node_modules', moduleName);
90
+ let stats = fs.statSync(moduleDir);
91
+ if (stats.isDirectory()) return moduleDir;
92
+ } catch (err) {
93
+ // ignore
94
+ }
95
+ // Move up a directory
96
+ dir = (0, ($atlaspack$interopDefault($eHCLO$path))).dirname(dir);
97
+ }
98
+ return null;
99
+ }
100
+ function $a9ed96e57e8d2cf3$export$d51a93c758976388(fs, fileNames, dir, root) {
101
+ let { root: pathRoot } = (0, ($atlaspack$interopDefault($eHCLO$path))).parse(dir);
102
+ // eslint-disable-next-line no-constant-condition
103
+ while(true){
104
+ if ((0, ($atlaspack$interopDefault($eHCLO$path))).basename(dir) === 'node_modules') return null;
105
+ for (const fileName of fileNames){
106
+ let filePath = (0, ($atlaspack$interopDefault($eHCLO$path))).join(dir, fileName);
107
+ try {
108
+ if (fs.statSync(filePath).isFile()) return filePath;
109
+ } catch (err) {
110
+ // ignore
111
+ }
112
+ }
113
+ if (dir === root || dir === pathRoot) break;
114
+ dir = (0, ($atlaspack$interopDefault($eHCLO$path))).dirname(dir);
115
+ }
116
+ return null;
117
+ }
118
+ function $a9ed96e57e8d2cf3$export$64df6e3182fd5b2d(fs, filePaths) {
119
+ for (let filePath of filePaths)try {
120
+ if (fs.statSync(filePath).isFile()) return filePath;
121
+ } catch (err) {
122
+ // ignore
123
+ }
124
+ }
125
+
126
+
127
+
128
+ var $995ba0f44994569b$require$Buffer = $eHCLO$buffer.Buffer;
129
+ const $995ba0f44994569b$var$instances = new Map();
130
+ let $995ba0f44994569b$var$id = 0;
131
+ class $995ba0f44994569b$export$3048eb7ec07c2c4e {
132
+ _numWorkerInstances = 0;
133
+ _workerRegisterResolves = [];
134
+ _emitter = new (0, ($atlaspack$interopDefault($eHCLO$events)))();
135
+ constructor(workerFarm){
136
+ this.farm = workerFarm;
137
+ this._cwd = (0, ($atlaspack$interopDefault($eHCLO$path))).resolve((0, ($atlaspack$interopDefault($eHCLO$path))).sep);
138
+ this.dirs = new Map([
139
+ [
140
+ this._cwd,
141
+ new $995ba0f44994569b$var$Directory()
142
+ ]
143
+ ]);
144
+ this.files = new Map();
145
+ this.symlinks = new Map();
146
+ this.watchers = new Map();
147
+ this.events = [];
148
+ this.id = $995ba0f44994569b$var$id++;
149
+ this._workerHandles = [];
150
+ this._eventQueue = [];
151
+ $995ba0f44994569b$var$instances.set(this.id, this);
152
+ this._emitter.on('allWorkersRegistered', ()=>{
153
+ for (let resolve of this._workerRegisterResolves)resolve();
154
+ this._workerRegisterResolves = [];
155
+ });
156
+ }
157
+ static deserialize(opts) {
158
+ let existing = $995ba0f44994569b$var$instances.get(opts.id);
159
+ if (existing != null) {
160
+ // Correct the count of worker instances since serialization assumes a new instance is created
161
+ (0, ($atlaspack$interopDefault($eHCLO$atlaspackworkers))).getWorkerApi().runHandle(opts.handle, [
162
+ 'decrementWorkerInstance',
163
+ []
164
+ ]);
165
+ return existing;
166
+ }
167
+ let fs = new $995ba0f44994569b$var$WorkerFS(opts.id, (0, (/*@__PURE__*/$atlaspack$interopDefault($023b8d639760db5c$exports)))(opts.handle));
168
+ fs.dirs = opts.dirs;
169
+ fs.files = opts.files;
170
+ fs.symlinks = opts.symlinks;
171
+ return fs;
172
+ }
173
+ serialize() {
174
+ if (!this.handle) this.handle = this.farm.createReverseHandle((fn, args)=>{
175
+ // $FlowFixMe
176
+ return this[fn](...args);
177
+ });
178
+ // If a worker instance already exists, it will decrement this number
179
+ this._numWorkerInstances++;
180
+ return {
181
+ $$raw: false,
182
+ id: this.id,
183
+ handle: this.handle,
184
+ dirs: this.dirs,
185
+ files: this.files,
186
+ symlinks: this.symlinks
187
+ };
188
+ }
189
+ decrementWorkerInstance() {
190
+ this._numWorkerInstances--;
191
+ if (this._numWorkerInstances === this._workerHandles.length) this._emitter.emit('allWorkersRegistered');
192
+ }
193
+ cwd() {
194
+ return this._cwd;
195
+ }
196
+ chdir(dir) {
197
+ this._cwd = dir;
198
+ }
199
+ _normalizePath(filePath, realpath = true) {
200
+ filePath = (0, ($atlaspack$interopDefault($eHCLO$path))).normalize(filePath);
201
+ if (!filePath.startsWith(this.cwd())) filePath = (0, ($atlaspack$interopDefault($eHCLO$path))).resolve(this.cwd(), filePath);
202
+ // get realpath by following symlinks
203
+ if (realpath) {
204
+ let { root: root, dir: dir, base: base } = (0, ($atlaspack$interopDefault($eHCLO$path))).parse(filePath);
205
+ let parts = dir.slice(root.length).split((0, ($atlaspack$interopDefault($eHCLO$path))).sep).concat(base);
206
+ let res = root;
207
+ for (let part of parts){
208
+ res = (0, ($atlaspack$interopDefault($eHCLO$path))).join(res, part);
209
+ let symlink = this.symlinks.get(res);
210
+ if (symlink) res = symlink;
211
+ }
212
+ return res;
213
+ }
214
+ return filePath;
215
+ }
216
+ async writeFile(filePath, contents, options) {
217
+ filePath = this._normalizePath(filePath);
218
+ if (this.dirs.has(filePath)) throw new $995ba0f44994569b$export$d414276624ebf134('EISDIR', filePath, 'is a directory');
219
+ let dir = (0, ($atlaspack$interopDefault($eHCLO$path))).dirname(filePath);
220
+ if (!this.dirs.has(dir)) throw new $995ba0f44994569b$export$d414276624ebf134('ENOENT', dir, 'does not exist');
221
+ let buffer = $995ba0f44994569b$export$df9eb3e75aa27a22(contents);
222
+ let file = this.files.get(filePath);
223
+ let mode = options && options.mode || 438;
224
+ if (file) {
225
+ file.write(buffer, mode);
226
+ this.files.set(filePath, file);
227
+ } else this.files.set(filePath, new $995ba0f44994569b$export$b6afa8811b7e644e(buffer, mode));
228
+ await this._sendWorkerEvent({
229
+ type: 'writeFile',
230
+ path: filePath,
231
+ entry: this.files.get(filePath)
232
+ });
233
+ this._triggerEvent({
234
+ type: file ? 'update' : 'create',
235
+ path: filePath
236
+ });
237
+ }
238
+ // eslint-disable-next-line require-await
239
+ async readFile(filePath, encoding) {
240
+ return this.readFileSync(filePath, encoding);
241
+ }
242
+ readFileSync(filePath, encoding) {
243
+ filePath = this._normalizePath(filePath);
244
+ let file = this.files.get(filePath);
245
+ if (file == null) throw new $995ba0f44994569b$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
246
+ let buffer = file.read();
247
+ if (encoding) return buffer.toString(encoding);
248
+ return buffer;
249
+ }
250
+ async copyFile(source, destination) {
251
+ let contents = await this.readFile(source);
252
+ await this.writeFile(destination, contents);
253
+ }
254
+ statSync(filePath) {
255
+ filePath = this._normalizePath(filePath);
256
+ let dir = this.dirs.get(filePath);
257
+ if (dir) return dir.stat();
258
+ let file = this.files.get(filePath);
259
+ if (file == null) throw new $995ba0f44994569b$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
260
+ return file.stat();
261
+ }
262
+ // eslint-disable-next-line require-await
263
+ async stat(filePath) {
264
+ return this.statSync(filePath);
265
+ }
266
+ readdirSync(dir, opts) {
267
+ dir = this._normalizePath(dir);
268
+ if (!this.dirs.has(dir)) throw new $995ba0f44994569b$export$d414276624ebf134('ENOENT', dir, 'does not exist');
269
+ if (!dir.endsWith((0, ($atlaspack$interopDefault($eHCLO$path))).sep)) dir += (0, ($atlaspack$interopDefault($eHCLO$path))).sep;
270
+ let res = [];
271
+ for (let [filePath, entry] of this.dirs){
272
+ if (filePath === dir) continue;
273
+ if (filePath.startsWith(dir) && filePath.indexOf((0, ($atlaspack$interopDefault($eHCLO$path))).sep, dir.length) === -1) {
274
+ let name = filePath.slice(dir.length);
275
+ if (opts?.withFileTypes) res.push(new $995ba0f44994569b$var$Dirent(name, entry));
276
+ else res.push(name);
277
+ }
278
+ }
279
+ for (let [filePath, entry] of this.files)if (filePath.startsWith(dir) && filePath.indexOf((0, ($atlaspack$interopDefault($eHCLO$path))).sep, dir.length) === -1) {
280
+ let name = filePath.slice(dir.length);
281
+ if (opts?.withFileTypes) res.push(new $995ba0f44994569b$var$Dirent(name, entry));
282
+ else res.push(name);
283
+ }
284
+ for (let [from] of this.symlinks)if (from.startsWith(dir) && from.indexOf((0, ($atlaspack$interopDefault($eHCLO$path))).sep, dir.length) === -1) {
285
+ let name = from.slice(dir.length);
286
+ if (opts?.withFileTypes) res.push(new $995ba0f44994569b$var$Dirent(name, {
287
+ mode: $995ba0f44994569b$var$S_IFLNK
288
+ }));
289
+ else res.push(name);
290
+ }
291
+ return res;
292
+ }
293
+ // eslint-disable-next-line require-await
294
+ async readdir(dir, opts) {
295
+ return this.readdirSync(dir, opts);
296
+ }
297
+ async unlink(filePath) {
298
+ filePath = this._normalizePath(filePath);
299
+ if (!this.files.has(filePath) && !this.dirs.has(filePath)) throw new $995ba0f44994569b$export$d414276624ebf134('ENOENT', filePath, 'does not exist');
300
+ this.files.delete(filePath);
301
+ this.dirs.delete(filePath);
302
+ this.watchers.delete(filePath);
303
+ await this._sendWorkerEvent({
304
+ type: 'unlink',
305
+ path: filePath
306
+ });
307
+ this._triggerEvent({
308
+ type: 'delete',
309
+ path: filePath
310
+ });
311
+ return Promise.resolve();
312
+ }
313
+ async mkdirp(dir) {
314
+ dir = this._normalizePath(dir);
315
+ if (this.dirs.has(dir)) return Promise.resolve();
316
+ if (this.files.has(dir)) throw new $995ba0f44994569b$export$d414276624ebf134('ENOENT', dir, 'is not a directory');
317
+ let root = (0, ($atlaspack$interopDefault($eHCLO$path))).parse(dir).root;
318
+ while(dir !== root){
319
+ if (this.dirs.has(dir)) break;
320
+ this.dirs.set(dir, new $995ba0f44994569b$var$Directory());
321
+ await this._sendWorkerEvent({
322
+ type: 'mkdir',
323
+ path: dir
324
+ });
325
+ this._triggerEvent({
326
+ type: 'create',
327
+ path: dir
328
+ });
329
+ dir = (0, ($atlaspack$interopDefault($eHCLO$path))).dirname(dir);
330
+ }
331
+ return Promise.resolve();
332
+ }
333
+ async rimraf(filePath) {
334
+ filePath = this._normalizePath(filePath);
335
+ if (this.dirs.has(filePath)) {
336
+ let dir = filePath + (0, ($atlaspack$interopDefault($eHCLO$path))).sep;
337
+ for (let filePath of this.files.keys())if (filePath.startsWith(dir)) {
338
+ this.files.delete(filePath);
339
+ await this._sendWorkerEvent({
340
+ type: 'unlink',
341
+ path: filePath
342
+ });
343
+ this._triggerEvent({
344
+ type: 'delete',
345
+ path: filePath
346
+ });
347
+ }
348
+ for (let dirPath of this.dirs.keys())if (dirPath.startsWith(dir)) {
349
+ this.dirs.delete(dirPath);
350
+ this.watchers.delete(dirPath);
351
+ await this._sendWorkerEvent({
352
+ type: 'unlink',
353
+ path: filePath
354
+ });
355
+ this._triggerEvent({
356
+ type: 'delete',
357
+ path: dirPath
358
+ });
359
+ }
360
+ for (let filePath of this.symlinks.keys())if (filePath.startsWith(dir)) {
361
+ this.symlinks.delete(filePath);
362
+ await this._sendWorkerEvent({
363
+ type: 'unlink',
364
+ path: filePath
365
+ });
366
+ }
367
+ this.dirs.delete(filePath);
368
+ await this._sendWorkerEvent({
369
+ type: 'unlink',
370
+ path: filePath
371
+ });
372
+ this._triggerEvent({
373
+ type: 'delete',
374
+ path: filePath
375
+ });
376
+ } else if (this.files.has(filePath)) {
377
+ this.files.delete(filePath);
378
+ await this._sendWorkerEvent({
379
+ type: 'unlink',
380
+ path: filePath
381
+ });
382
+ this._triggerEvent({
383
+ type: 'delete',
384
+ path: filePath
385
+ });
386
+ }
387
+ return Promise.resolve();
388
+ }
389
+ async ncp(source, destination) {
390
+ source = this._normalizePath(source);
391
+ if (this.dirs.has(source)) {
392
+ if (!this.dirs.has(destination)) {
393
+ this.dirs.set(destination, new $995ba0f44994569b$var$Directory());
394
+ await this._sendWorkerEvent({
395
+ type: 'mkdir',
396
+ path: destination
397
+ });
398
+ this._triggerEvent({
399
+ type: 'create',
400
+ path: destination
401
+ });
402
+ }
403
+ let dir = source + (0, ($atlaspack$interopDefault($eHCLO$path))).sep;
404
+ for (let dirPath of this.dirs.keys())if (dirPath.startsWith(dir)) {
405
+ let destName = (0, ($atlaspack$interopDefault($eHCLO$path))).join(destination, dirPath.slice(dir.length));
406
+ if (!this.dirs.has(destName)) {
407
+ this.dirs.set(destName, new $995ba0f44994569b$var$Directory());
408
+ await this._sendWorkerEvent({
409
+ type: 'mkdir',
410
+ path: destination
411
+ });
412
+ this._triggerEvent({
413
+ type: 'create',
414
+ path: destName
415
+ });
416
+ }
417
+ }
418
+ for (let [filePath, file] of this.files)if (filePath.startsWith(dir)) {
419
+ let destName = (0, ($atlaspack$interopDefault($eHCLO$path))).join(destination, filePath.slice(dir.length));
420
+ let exists = this.files.has(destName);
421
+ this.files.set(destName, file);
422
+ await this._sendWorkerEvent({
423
+ type: 'writeFile',
424
+ path: destName,
425
+ entry: file
426
+ });
427
+ this._triggerEvent({
428
+ type: exists ? 'update' : 'create',
429
+ path: destName
430
+ });
431
+ }
432
+ } else await this.copyFile(source, destination);
433
+ }
434
+ createReadStream(filePath) {
435
+ return new $995ba0f44994569b$var$ReadStream(this, filePath);
436
+ }
437
+ createWriteStream(filePath, options) {
438
+ return new $995ba0f44994569b$var$WriteStream(this, filePath, options);
439
+ }
440
+ realpathSync(filePath) {
441
+ return this._normalizePath(filePath);
442
+ }
443
+ // eslint-disable-next-line require-await
444
+ async realpath(filePath) {
445
+ return this.realpathSync(filePath);
446
+ }
447
+ async symlink(target, path) {
448
+ target = this._normalizePath(target);
449
+ path = this._normalizePath(path);
450
+ this.symlinks.set(path, target);
451
+ await this._sendWorkerEvent({
452
+ type: 'symlink',
453
+ path: path,
454
+ target: target
455
+ });
456
+ }
457
+ existsSync(filePath) {
458
+ filePath = this._normalizePath(filePath);
459
+ return this.files.has(filePath) || this.dirs.has(filePath);
460
+ }
461
+ // eslint-disable-next-line require-await
462
+ async exists(filePath) {
463
+ return this.existsSync(filePath);
464
+ }
465
+ _triggerEvent(event) {
466
+ this.events.push(event);
467
+ if (this.watchers.size === 0) return;
468
+ // Batch events
469
+ this._eventQueue.push(event);
470
+ clearTimeout(this._watcherTimer);
471
+ this._watcherTimer = setTimeout(()=>{
472
+ let events = this._eventQueue;
473
+ this._eventQueue = [];
474
+ for (let [dir, watchers] of this.watchers){
475
+ if (!dir.endsWith((0, ($atlaspack$interopDefault($eHCLO$path))).sep)) dir += (0, ($atlaspack$interopDefault($eHCLO$path))).sep;
476
+ if (event.path.startsWith(dir)) for (let watcher of watchers)watcher.trigger(events);
477
+ }
478
+ }, 50);
479
+ }
480
+ _registerWorker(handle) {
481
+ this._workerHandles.push(handle);
482
+ if (this._numWorkerInstances === this._workerHandles.length) this._emitter.emit('allWorkersRegistered');
483
+ }
484
+ async _sendWorkerEvent(event) {
485
+ // Wait for worker instances to register their handles
486
+ while(this._workerHandles.length < this._numWorkerInstances)await new Promise((resolve)=>this._workerRegisterResolves.push(resolve));
487
+ await Promise.all(this._workerHandles.map((workerHandle)=>this.farm.workerApi.runHandle(workerHandle, [
488
+ event
489
+ ])));
490
+ }
491
+ watch(dir, fn, opts) {
492
+ dir = this._normalizePath(dir);
493
+ let watcher = new $995ba0f44994569b$var$Watcher(fn, opts);
494
+ let watchers = this.watchers.get(dir);
495
+ if (!watchers) {
496
+ watchers = new Set();
497
+ this.watchers.set(dir, watchers);
498
+ }
499
+ watchers.add(watcher);
500
+ return Promise.resolve({
501
+ unsubscribe: ()=>{
502
+ watchers = (0, (/*@__PURE__*/$atlaspack$interopDefault($023b8d639760db5c$exports)))(watchers);
503
+ watchers.delete(watcher);
504
+ if (watchers.size === 0) this.watchers.delete(dir);
505
+ return Promise.resolve();
506
+ }
507
+ });
508
+ }
509
+ async getEventsSince(dir, snapshot, opts) {
510
+ let contents = await this.readFile(snapshot, 'utf8');
511
+ let len = Number(contents);
512
+ let events = this.events.slice(len);
513
+ let ignore = opts.ignore;
514
+ if (ignore) events = events.filter((event)=>!ignore.some((i)=>event.path.startsWith(i + (0, ($atlaspack$interopDefault($eHCLO$path))).sep)));
515
+ return events;
516
+ }
517
+ async writeSnapshot(dir, snapshot) {
518
+ await this.writeFile(snapshot, '' + this.events.length);
519
+ }
520
+ findAncestorFile(fileNames, fromDir, root) {
521
+ return (0, $a9ed96e57e8d2cf3$export$d51a93c758976388)(this, fileNames, fromDir, root);
522
+ }
523
+ findNodeModule(moduleName, fromDir) {
524
+ return (0, $a9ed96e57e8d2cf3$export$4c6d088a7d7f9947)(this, moduleName, fromDir);
525
+ }
526
+ findFirstFile(filePaths) {
527
+ return (0, $a9ed96e57e8d2cf3$export$64df6e3182fd5b2d)(this, filePaths);
528
+ }
529
+ }
530
+ class $995ba0f44994569b$var$Watcher {
531
+ constructor(fn, options){
532
+ this.fn = fn;
533
+ this.options = options;
534
+ }
535
+ trigger(events) {
536
+ let ignore = this.options.ignore;
537
+ if (ignore) events = events.filter((event)=>!ignore.some((i)=>event.path.startsWith(i + (0, ($atlaspack$interopDefault($eHCLO$path))).sep)));
538
+ if (events.length > 0) this.fn(null, events);
539
+ }
540
+ }
541
+ class $995ba0f44994569b$export$d414276624ebf134 extends Error {
542
+ constructor(code, path, message){
543
+ super(`${code}: ${path} ${message}`);
544
+ this.name = 'FSError';
545
+ this.code = code;
546
+ this.path = path;
547
+ Error.captureStackTrace?.(this, this.constructor);
548
+ }
549
+ }
550
+ class $995ba0f44994569b$var$ReadStream extends (0, $eHCLO$stream.Readable) {
551
+ constructor(fs, filePath){
552
+ super();
553
+ this.fs = fs;
554
+ this.filePath = filePath;
555
+ this.reading = false;
556
+ this.bytesRead = 0;
557
+ }
558
+ _read() {
559
+ if (this.reading) return;
560
+ this.reading = true;
561
+ this.fs.readFile(this.filePath).then((res)=>{
562
+ this.bytesRead += res.byteLength;
563
+ this.push(res);
564
+ this.push(null);
565
+ }, (err)=>{
566
+ this.emit('error', err);
567
+ });
568
+ }
569
+ }
570
+ class $995ba0f44994569b$var$WriteStream extends (0, $eHCLO$stream.Writable) {
571
+ constructor(fs, filePath, options){
572
+ super({
573
+ emitClose: true,
574
+ autoDestroy: true
575
+ });
576
+ this.fs = fs;
577
+ this.filePath = filePath;
578
+ this.options = options;
579
+ this.buffer = $995ba0f44994569b$require$Buffer.alloc(0);
580
+ }
581
+ _write(chunk, encoding, callback) {
582
+ let c = typeof chunk === 'string' ? $995ba0f44994569b$require$Buffer.from(chunk, encoding) : chunk;
583
+ this.buffer = $995ba0f44994569b$require$Buffer.concat([
584
+ this.buffer,
585
+ c
586
+ ]);
587
+ callback();
588
+ }
589
+ _final(callback) {
590
+ this.fs.writeFile(this.filePath, this.buffer, this.options).then(callback).catch(callback);
591
+ }
592
+ }
593
+ const $995ba0f44994569b$var$S_IFREG = 32768;
594
+ const $995ba0f44994569b$var$S_IFDIR = 16384;
595
+ const $995ba0f44994569b$var$S_IFLNK = 40960;
596
+ const $995ba0f44994569b$var$S_IFMT = 61440;
597
+ class $995ba0f44994569b$var$Entry {
598
+ constructor(mode){
599
+ this.mode = mode;
600
+ let now = Date.now();
601
+ this.atime = now;
602
+ this.mtime = now;
603
+ this.ctime = now;
604
+ this.birthtime = now;
605
+ }
606
+ access() {
607
+ let now = Date.now();
608
+ this.atime = now;
609
+ this.ctime = now;
610
+ }
611
+ modify(mode) {
612
+ let now = Date.now();
613
+ this.mtime = now;
614
+ this.ctime = now;
615
+ this.mode = mode;
616
+ }
617
+ getSize() {
618
+ return 0;
619
+ }
620
+ stat() {
621
+ return new $995ba0f44994569b$var$Stat(this);
622
+ }
623
+ }
624
+ class $995ba0f44994569b$var$Stat {
625
+ dev = 0;
626
+ ino = 0;
627
+ nlink = 0;
628
+ uid = 0;
629
+ gid = 0;
630
+ rdev = 0;
631
+ blksize = 0;
632
+ blocks = 0;
633
+ constructor(entry){
634
+ this.mode = entry.mode;
635
+ this.size = entry.getSize();
636
+ this.atimeMs = entry.atime;
637
+ this.mtimeMs = entry.mtime;
638
+ this.ctimeMs = entry.ctime;
639
+ this.birthtimeMs = entry.birthtime;
640
+ this.atime = new Date(entry.atime);
641
+ this.mtime = new Date(entry.mtime);
642
+ this.ctime = new Date(entry.ctime);
643
+ this.birthtime = new Date(entry.birthtime);
644
+ }
645
+ isFile() {
646
+ return Boolean(this.mode & $995ba0f44994569b$var$S_IFREG);
647
+ }
648
+ isDirectory() {
649
+ return Boolean(this.mode & $995ba0f44994569b$var$S_IFDIR);
650
+ }
651
+ isBlockDevice() {
652
+ return false;
653
+ }
654
+ isCharacterDevice() {
655
+ return false;
656
+ }
657
+ isSymbolicLink() {
658
+ return false;
659
+ }
660
+ isFIFO() {
661
+ return false;
662
+ }
663
+ isSocket() {
664
+ return false;
665
+ }
666
+ }
667
+ class $995ba0f44994569b$var$Dirent {
668
+ #mode;
669
+ constructor(name, entry){
670
+ this.name = name;
671
+ this.#mode = entry.mode;
672
+ }
673
+ isFile() {
674
+ return (this.#mode & $995ba0f44994569b$var$S_IFMT) === $995ba0f44994569b$var$S_IFREG;
675
+ }
676
+ isDirectory() {
677
+ return (this.#mode & $995ba0f44994569b$var$S_IFMT) === $995ba0f44994569b$var$S_IFDIR;
678
+ }
679
+ isBlockDevice() {
680
+ return false;
681
+ }
682
+ isCharacterDevice() {
683
+ return false;
684
+ }
685
+ isSymbolicLink() {
686
+ return (this.#mode & $995ba0f44994569b$var$S_IFMT) === $995ba0f44994569b$var$S_IFLNK;
687
+ }
688
+ isFIFO() {
689
+ return false;
690
+ }
691
+ isSocket() {
692
+ return false;
693
+ }
694
+ }
695
+ class $995ba0f44994569b$export$b6afa8811b7e644e extends $995ba0f44994569b$var$Entry {
696
+ constructor(buffer, mode){
697
+ super($995ba0f44994569b$var$S_IFREG | mode);
698
+ this.buffer = buffer;
699
+ }
700
+ read() {
701
+ super.access();
702
+ return $995ba0f44994569b$require$Buffer.from(this.buffer);
703
+ }
704
+ write(buffer, mode) {
705
+ super.modify($995ba0f44994569b$var$S_IFREG | mode);
706
+ this.buffer = buffer;
707
+ }
708
+ getSize() {
709
+ return this.buffer.byteLength;
710
+ }
711
+ }
712
+ class $995ba0f44994569b$var$Directory extends $995ba0f44994569b$var$Entry {
713
+ constructor(){
714
+ super($995ba0f44994569b$var$S_IFDIR);
715
+ }
716
+ }
717
+ function $995ba0f44994569b$export$df9eb3e75aa27a22(contents) {
718
+ if (typeof contents !== 'string' && contents.buffer instanceof (0, $eHCLO$atlaspackutils.SharedBuffer)) return contents;
719
+ let contentsBuffer = contents;
720
+ // For the polyfilled buffer module, it's faster to always convert once so that the subsequent
721
+ // operations are fast (.byteLength and using .set instead of .write)
722
+ contentsBuffer = contentsBuffer instanceof $995ba0f44994569b$require$Buffer ? contentsBuffer : $995ba0f44994569b$require$Buffer.from(contentsBuffer);
723
+ let length = $995ba0f44994569b$require$Buffer.byteLength(contentsBuffer);
724
+ let shared = new (0, $eHCLO$atlaspackutils.SharedBuffer)(length);
725
+ let buffer = $995ba0f44994569b$require$Buffer.from(shared);
726
+ if (length > 0) {
727
+ if (typeof contentsBuffer === 'string') buffer.write(contentsBuffer);
728
+ else buffer.set(contentsBuffer);
729
+ }
730
+ return buffer;
731
+ }
732
+ class $995ba0f44994569b$var$WorkerFS extends $995ba0f44994569b$export$3048eb7ec07c2c4e {
733
+ constructor(id, handle){
734
+ // TODO Make this not a subclass
735
+ // $FlowFixMe
736
+ super();
737
+ this.id = id;
738
+ this.handleFn = (methodName, args)=>(0, ($atlaspack$interopDefault($eHCLO$atlaspackworkers))).getWorkerApi().runHandle(handle, [
739
+ methodName,
740
+ args
741
+ ]);
742
+ this.handleFn('_registerWorker', [
743
+ (0, ($atlaspack$interopDefault($eHCLO$atlaspackworkers))).getWorkerApi().createReverseHandle((event)=>{
744
+ switch(event.type){
745
+ case 'writeFile':
746
+ this.files.set(event.path, event.entry);
747
+ break;
748
+ case 'unlink':
749
+ this.files.delete(event.path);
750
+ this.dirs.delete(event.path);
751
+ this.symlinks.delete(event.path);
752
+ break;
753
+ case 'mkdir':
754
+ this.dirs.set(event.path, new $995ba0f44994569b$var$Directory());
755
+ break;
756
+ case 'symlink':
757
+ this.symlinks.set(event.path, event.target);
758
+ break;
759
+ }
760
+ })
761
+ ]);
762
+ }
763
+ static deserialize(opts) {
764
+ return (0, (/*@__PURE__*/$atlaspack$interopDefault($023b8d639760db5c$exports)))($995ba0f44994569b$var$instances.get(opts.id));
765
+ }
766
+ serialize() {
767
+ // $FlowFixMe
768
+ return {
769
+ id: this.id
770
+ };
771
+ }
772
+ writeFile(filePath, contents, options) {
773
+ super.writeFile(filePath, contents, options);
774
+ let buffer = $995ba0f44994569b$export$df9eb3e75aa27a22(contents);
775
+ return this.handleFn('writeFile', [
776
+ filePath,
777
+ buffer,
778
+ options
779
+ ]);
780
+ }
781
+ unlink(filePath) {
782
+ super.unlink(filePath);
783
+ return this.handleFn('unlink', [
784
+ filePath
785
+ ]);
786
+ }
787
+ mkdirp(dir) {
788
+ super.mkdirp(dir);
789
+ return this.handleFn('mkdirp', [
790
+ dir
791
+ ]);
792
+ }
793
+ rimraf(filePath) {
794
+ super.rimraf(filePath);
795
+ return this.handleFn('rimraf', [
796
+ filePath
797
+ ]);
798
+ }
799
+ ncp(source, destination) {
800
+ super.ncp(source, destination);
801
+ return this.handleFn('ncp', [
802
+ source,
803
+ destination
804
+ ]);
805
+ }
806
+ symlink(target, path) {
807
+ super.symlink(target, path);
808
+ return this.handleFn('symlink', [
809
+ target,
810
+ path
811
+ ]);
812
+ }
813
+ }
814
+ (0, $eHCLO$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($b6ff243d7d5008ac$exports))).version}:MemoryFS`, $995ba0f44994569b$export$3048eb7ec07c2c4e);
815
+ (0, $eHCLO$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($b6ff243d7d5008ac$exports))).version}:WorkerFS`, $995ba0f44994569b$var$WorkerFS);
816
+ (0, $eHCLO$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($b6ff243d7d5008ac$exports))).version}:Stat`, $995ba0f44994569b$var$Stat);
817
+ (0, $eHCLO$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($b6ff243d7d5008ac$exports))).version}:File`, $995ba0f44994569b$export$b6afa8811b7e644e);
818
+ (0, $eHCLO$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($b6ff243d7d5008ac$exports))).version}:Directory`, $995ba0f44994569b$var$Directory);
819
+
820
+
821
+ var $49e8d7e24153085c$exports = {};
822
+
823
+ $atlaspack$export($49e8d7e24153085c$exports, "OverlayFS", () => $49e8d7e24153085c$export$5963299e2424ca1c);
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+ class $49e8d7e24153085c$export$5963299e2424ca1c {
832
+ deleted = new Set();
833
+ constructor(workerFarmOrFS, readable){
834
+ if (workerFarmOrFS instanceof (0, ($atlaspack$interopDefault($eHCLO$atlaspackworkers)))) this.writable = new (0, $995ba0f44994569b$export$3048eb7ec07c2c4e)(workerFarmOrFS);
835
+ else this.writable = workerFarmOrFS;
836
+ this.readable = readable;
837
+ this._cwd = readable.cwd();
838
+ }
839
+ static deserialize(opts) {
840
+ let fs = new $49e8d7e24153085c$export$5963299e2424ca1c(opts.writable, opts.readable);
841
+ if (opts.deleted != null) fs.deleted = opts.deleted;
842
+ return fs;
843
+ }
844
+ serialize() {
845
+ return {
846
+ $$raw: false,
847
+ writable: this.writable,
848
+ readable: this.readable,
849
+ deleted: this.deleted
850
+ };
851
+ }
852
+ _deletedThrows(filePath) {
853
+ filePath = this._normalizePath(filePath);
854
+ if (this.deleted.has(filePath)) throw new $49e8d7e24153085c$var$FSError('ENOENT', filePath, 'does not exist');
855
+ return filePath;
856
+ }
857
+ _checkExists(filePath) {
858
+ filePath = this._deletedThrows(filePath);
859
+ if (!this.existsSync(filePath)) throw new $49e8d7e24153085c$var$FSError('ENOENT', filePath, 'does not exist');
860
+ return filePath;
861
+ }
862
+ _isSymlink(filePath) {
863
+ filePath = this._normalizePath(filePath);
864
+ // Check the parts of the path to see if any are symlinks.
865
+ let { root: root, dir: dir, base: base } = (0, ($atlaspack$interopDefault($eHCLO$path))).parse(filePath);
866
+ let segments = dir.slice(root.length).split((0, ($atlaspack$interopDefault($eHCLO$path))).sep).concat(base);
867
+ while(segments.length){
868
+ filePath = (0, ($atlaspack$interopDefault($eHCLO$path))).join(root, ...segments);
869
+ let name = segments.pop();
870
+ if (this.deleted.has(filePath)) return false;
871
+ else if (this.writable instanceof (0, $995ba0f44994569b$export$3048eb7ec07c2c4e) && this.writable.symlinks.has(filePath)) return true;
872
+ else {
873
+ // HACK: Atlaspack fs does not provide `lstatSync`,
874
+ // so we use `readdirSync` to check if the path is a symlink.
875
+ let parent = (0, ($atlaspack$interopDefault($eHCLO$path))).resolve(filePath, '..');
876
+ if (parent === filePath) return false;
877
+ try {
878
+ for (let dirent of this.readdirSync(parent, {
879
+ withFileTypes: true
880
+ })){
881
+ if (typeof dirent === 'string') break; // {withFileTypes: true} not supported
882
+ else if (dirent.name === name) {
883
+ if (dirent.isSymbolicLink()) return true;
884
+ }
885
+ }
886
+ } catch (e) {
887
+ if (e.code === 'ENOENT') return false;
888
+ throw e;
889
+ }
890
+ }
891
+ }
892
+ return false;
893
+ }
894
+ async _copyPathForWrite(filePath) {
895
+ filePath = await this._normalizePath(filePath);
896
+ let dirPath = (0, ($atlaspack$interopDefault($eHCLO$path))).dirname(filePath);
897
+ if (this.existsSync(dirPath) && !this.writable.existsSync(dirPath)) await this.writable.mkdirp(dirPath);
898
+ return filePath;
899
+ }
900
+ _normalizePath(filePath) {
901
+ return (0, ($atlaspack$interopDefault($eHCLO$path))).resolve(this.cwd(), filePath);
902
+ }
903
+ // eslint-disable-next-line require-await
904
+ async readFile(filePath, encoding) {
905
+ return this.readFileSync(filePath, encoding);
906
+ }
907
+ async writeFile(filePath, contents, options) {
908
+ filePath = await this._copyPathForWrite(filePath);
909
+ await this.writable.writeFile(filePath, contents, options);
910
+ this.deleted.delete(filePath);
911
+ }
912
+ async copyFile(source, destination) {
913
+ source = this._normalizePath(source);
914
+ destination = await this._copyPathForWrite(destination);
915
+ if (await this.writable.exists(source)) await this.writable.writeFile(destination, await this.writable.readFile(source));
916
+ else await this.writable.writeFile(destination, await this.readable.readFile(source));
917
+ this.deleted.delete(destination);
918
+ }
919
+ // eslint-disable-next-line require-await
920
+ async stat(filePath) {
921
+ return this.statSync(filePath);
922
+ }
923
+ async symlink(target, filePath) {
924
+ target = this._normalizePath(target);
925
+ filePath = this._normalizePath(filePath);
926
+ await this.writable.symlink(target, filePath);
927
+ this.deleted.delete(filePath);
928
+ }
929
+ async unlink(filePath) {
930
+ filePath = this._normalizePath(filePath);
931
+ let toDelete = [
932
+ filePath
933
+ ];
934
+ if (this.writable instanceof (0, $995ba0f44994569b$export$3048eb7ec07c2c4e) && this._isSymlink(filePath)) this.writable.symlinks.delete(filePath);
935
+ else if (this.statSync(filePath).isDirectory()) {
936
+ let stack = [
937
+ filePath
938
+ ];
939
+ // Recursively add every descendant path to deleted.
940
+ while(stack.length){
941
+ let root = (0, (/*@__PURE__*/$atlaspack$interopDefault($023b8d639760db5c$exports)))(stack.pop());
942
+ for (let ent of this.readdirSync(root, {
943
+ withFileTypes: true
944
+ }))if (typeof ent === 'string') {
945
+ let childPath = (0, ($atlaspack$interopDefault($eHCLO$path))).join(root, ent);
946
+ toDelete.push(childPath);
947
+ if (this.statSync(childPath).isDirectory()) stack.push(childPath);
948
+ } else {
949
+ let childPath = (0, ($atlaspack$interopDefault($eHCLO$path))).join(root, ent.name);
950
+ toDelete.push(childPath);
951
+ if (ent.isDirectory()) stack.push(childPath);
952
+ }
953
+ }
954
+ }
955
+ try {
956
+ await this.writable.unlink(filePath);
957
+ } catch (e) {
958
+ if (e.code === 'ENOENT' && !this.readable.existsSync(filePath)) throw e;
959
+ }
960
+ for (let pathToDelete of toDelete)this.deleted.add(pathToDelete);
961
+ }
962
+ async mkdirp(dir) {
963
+ dir = this._normalizePath(dir);
964
+ await this.writable.mkdirp(dir);
965
+ if (this.deleted != null) {
966
+ let root = (0, ($atlaspack$interopDefault($eHCLO$path))).parse(dir).root;
967
+ while(dir !== root){
968
+ this.deleted.delete(dir);
969
+ dir = (0, ($atlaspack$interopDefault($eHCLO$path))).dirname(dir);
970
+ }
971
+ }
972
+ }
973
+ async rimraf(filePath) {
974
+ try {
975
+ await this.unlink(filePath);
976
+ } catch (e) {
977
+ // noop
978
+ }
979
+ }
980
+ // eslint-disable-next-line require-await
981
+ async ncp(source, destination) {
982
+ // TODO: Implement this correctly.
983
+ return this.writable.ncp(source, destination);
984
+ }
985
+ createReadStream(filePath, opts) {
986
+ filePath = this._deletedThrows(filePath);
987
+ if (this.writable.existsSync(filePath)) return this.writable.createReadStream(filePath, opts);
988
+ return this.readable.createReadStream(filePath, opts);
989
+ }
990
+ createWriteStream(path, opts) {
991
+ path = this._normalizePath(path);
992
+ this.deleted.delete(path);
993
+ return this.writable.createWriteStream(path, opts);
994
+ }
995
+ cwd() {
996
+ return this._cwd;
997
+ }
998
+ chdir(path) {
999
+ this._cwd = this._checkExists(path);
1000
+ }
1001
+ // eslint-disable-next-line require-await
1002
+ async realpath(filePath) {
1003
+ return this.realpathSync(filePath);
1004
+ }
1005
+ readFileSync(filePath, encoding) {
1006
+ filePath = this.realpathSync(filePath);
1007
+ try {
1008
+ // $FlowFixMe[incompatible-call]
1009
+ return this.writable.readFileSync(filePath, encoding);
1010
+ } catch (err) {
1011
+ // $FlowFixMe[incompatible-call]
1012
+ return this.readable.readFileSync(filePath, encoding);
1013
+ }
1014
+ }
1015
+ statSync(filePath) {
1016
+ filePath = this._normalizePath(filePath);
1017
+ try {
1018
+ return this.writable.statSync(filePath);
1019
+ } catch (e) {
1020
+ if (e.code === 'ENOENT' && this.existsSync(filePath)) return this.readable.statSync(filePath);
1021
+ throw e;
1022
+ }
1023
+ }
1024
+ realpathSync(filePath) {
1025
+ filePath = this._deletedThrows(filePath);
1026
+ filePath = this._deletedThrows(this.writable.realpathSync(filePath));
1027
+ if (!this.writable.existsSync(filePath)) return this.readable.realpathSync(filePath);
1028
+ return filePath;
1029
+ }
1030
+ // eslint-disable-next-line require-await
1031
+ async exists(filePath) {
1032
+ return this.existsSync(filePath);
1033
+ }
1034
+ existsSync(filePath) {
1035
+ filePath = this._normalizePath(filePath);
1036
+ if (this.deleted.has(filePath)) return false;
1037
+ try {
1038
+ filePath = this.realpathSync(filePath);
1039
+ } catch (err) {
1040
+ if (err.code !== 'ENOENT') throw err;
1041
+ }
1042
+ if (this.deleted.has(filePath)) return false;
1043
+ return this.writable.existsSync(filePath) || this.readable.existsSync(filePath);
1044
+ }
1045
+ // eslint-disable-next-line require-await
1046
+ async readdir(path, opts) {
1047
+ return this.readdirSync(path, opts);
1048
+ }
1049
+ readdirSync(dir, opts) {
1050
+ dir = this.realpathSync(dir);
1051
+ // Read from both filesystems and merge the results
1052
+ let entries = new Map();
1053
+ try {
1054
+ for (let entry of this.writable.readdirSync(dir, opts)){
1055
+ let filePath = (0, ($atlaspack$interopDefault($eHCLO$path))).join(dir, entry.name ?? entry);
1056
+ if (this.deleted.has(filePath)) continue;
1057
+ entries.set(filePath, entry);
1058
+ }
1059
+ } catch {
1060
+ // noop
1061
+ }
1062
+ try {
1063
+ for (let entry of this.readable.readdirSync(dir, opts)){
1064
+ let filePath = (0, ($atlaspack$interopDefault($eHCLO$path))).join(dir, entry.name ?? entry);
1065
+ if (this.deleted.has(filePath)) continue;
1066
+ if (entries.has(filePath)) continue;
1067
+ entries.set(filePath, entry);
1068
+ }
1069
+ } catch {
1070
+ // noop
1071
+ }
1072
+ return Array.from(entries.values());
1073
+ }
1074
+ async watch(dir, fn, opts) {
1075
+ let writableSubscription = await this.writable.watch(dir, fn, opts);
1076
+ let readableSubscription = await this.readable.watch(dir, fn, opts);
1077
+ return {
1078
+ unsubscribe: async ()=>{
1079
+ await writableSubscription.unsubscribe();
1080
+ await readableSubscription.unsubscribe();
1081
+ }
1082
+ };
1083
+ }
1084
+ async getEventsSince(dir, snapshot, opts) {
1085
+ let writableEvents = await this.writable.getEventsSince(dir, snapshot, opts);
1086
+ let readableEvents = await this.readable.getEventsSince(dir, snapshot, opts);
1087
+ return [
1088
+ ...writableEvents,
1089
+ ...readableEvents
1090
+ ];
1091
+ }
1092
+ async writeSnapshot(dir, snapshot, opts) {
1093
+ await this.writable.writeSnapshot(dir, snapshot, opts);
1094
+ }
1095
+ findAncestorFile(fileNames, fromDir, root) {
1096
+ return (0, $a9ed96e57e8d2cf3$export$d51a93c758976388)(this, fileNames, fromDir, root);
1097
+ }
1098
+ findNodeModule(moduleName, fromDir) {
1099
+ return (0, $a9ed96e57e8d2cf3$export$4c6d088a7d7f9947)(this, moduleName, fromDir);
1100
+ }
1101
+ findFirstFile(filePaths) {
1102
+ return (0, $a9ed96e57e8d2cf3$export$64df6e3182fd5b2d)(this, filePaths);
1103
+ }
1104
+ }
1105
+ class $49e8d7e24153085c$var$FSError extends Error {
1106
+ constructor(code, path, message){
1107
+ super(`${code}: ${path} ${message}`);
1108
+ this.name = 'FSError';
1109
+ this.code = code;
1110
+ this.path = path;
1111
+ Error.captureStackTrace?.(this, this.constructor);
1112
+ }
1113
+ }
1114
+ (0, $eHCLO$atlaspackcore.registerSerializableClass)(`${(0, (/*@__PURE__*/$atlaspack$interopDefault($b6ff243d7d5008ac$exports))).version}:OverlayFS`, $49e8d7e24153085c$export$5963299e2424ca1c);
1115
+
1116
+
1117
+ const $416aba2172cbc610$var$pipeline = (0, $eHCLO$util.promisify)((0, ($atlaspack$interopDefault($eHCLO$stream))).pipeline);
1118
+ async function $416aba2172cbc610$export$d3a8044e3fef7335(sourceFS, source, destinationFS, destination) {
1119
+ await destinationFS.mkdirp(destination);
1120
+ let files = await sourceFS.readdir(source);
1121
+ for (let file of files){
1122
+ let sourcePath = (0, ($atlaspack$interopDefault($eHCLO$path))).join(source, file);
1123
+ let destPath = (0, ($atlaspack$interopDefault($eHCLO$path))).join(destination, file);
1124
+ let stats = await sourceFS.stat(sourcePath);
1125
+ if (stats.isFile()) await $416aba2172cbc610$var$pipeline(sourceFS.createReadStream(sourcePath), destinationFS.createWriteStream(destPath));
1126
+ else if (stats.isDirectory()) await $416aba2172cbc610$export$d3a8044e3fef7335(sourceFS, sourcePath, destinationFS, destPath);
1127
+ }
1128
+ }
1129
+ $atlaspack$exportWildcard(module.exports, $4d6ec4a7ba8784a9$exports);
1130
+ $atlaspack$exportWildcard(module.exports, $995ba0f44994569b$exports);
1131
+ $atlaspack$exportWildcard(module.exports, $49e8d7e24153085c$exports);
1132
+
1133
+
1134
+ //# sourceMappingURL=browser.js.map