@atlaspack/fs 2.14.5-dev.14 → 2.14.5-dev.55

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