@atlaspack/fs 2.14.5-dev.55 → 2.14.5-dev.69
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/CHANGELOG.md +13 -0
- package/lib/browser.js +1271 -0
- package/lib/browser.js.map +1 -0
- package/lib/index.js +2411 -92
- package/lib/index.js.map +1 -0
- package/package.json +11 -11
- package/src/NodeVCSAwareFS.js +1 -1
- package/lib/MemoryFS.js +0 -829
- package/lib/NodeFS.browser.js +0 -13
- package/lib/NodeFS.js +0 -281
- package/lib/NodeVCSAwareFS.js +0 -176
- package/lib/OverlayFS.js +0 -366
- package/lib/find.js +0 -77
package/lib/OverlayFS.js
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.OverlayFS = void 0;
|
|
7
|
-
function _buildCache() {
|
|
8
|
-
const data = require("@atlaspack/build-cache");
|
|
9
|
-
_buildCache = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _workers() {
|
|
15
|
-
const data = _interopRequireDefault(require("@atlaspack/workers"));
|
|
16
|
-
_workers = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
var _package = _interopRequireDefault(require("../package.json"));
|
|
22
|
-
var _find = require("./find");
|
|
23
|
-
var _MemoryFS = require("./MemoryFS");
|
|
24
|
-
function _nullthrows() {
|
|
25
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
26
|
-
_nullthrows = function () {
|
|
27
|
-
return data;
|
|
28
|
-
};
|
|
29
|
-
return data;
|
|
30
|
-
}
|
|
31
|
-
function _path() {
|
|
32
|
-
const data = _interopRequireDefault(require("path"));
|
|
33
|
-
_path = function () {
|
|
34
|
-
return data;
|
|
35
|
-
};
|
|
36
|
-
return data;
|
|
37
|
-
}
|
|
38
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
-
class OverlayFS {
|
|
40
|
-
deleted = new Set();
|
|
41
|
-
constructor(workerFarmOrFS, readable) {
|
|
42
|
-
if (workerFarmOrFS instanceof _workers().default) {
|
|
43
|
-
this.writable = new _MemoryFS.MemoryFS(workerFarmOrFS);
|
|
44
|
-
} else {
|
|
45
|
-
this.writable = workerFarmOrFS;
|
|
46
|
-
}
|
|
47
|
-
this.readable = readable;
|
|
48
|
-
this._cwd = readable.cwd();
|
|
49
|
-
}
|
|
50
|
-
static deserialize(opts) {
|
|
51
|
-
let fs = new OverlayFS(opts.writable, opts.readable);
|
|
52
|
-
if (opts.deleted != null) fs.deleted = opts.deleted;
|
|
53
|
-
return fs;
|
|
54
|
-
}
|
|
55
|
-
serialize() {
|
|
56
|
-
return {
|
|
57
|
-
$$raw: false,
|
|
58
|
-
writable: this.writable,
|
|
59
|
-
readable: this.readable,
|
|
60
|
-
deleted: this.deleted
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
_deletedThrows(filePath) {
|
|
64
|
-
filePath = this._normalizePath(filePath);
|
|
65
|
-
if (this.deleted.has(filePath)) {
|
|
66
|
-
throw new FSError('ENOENT', filePath, 'does not exist');
|
|
67
|
-
}
|
|
68
|
-
return filePath;
|
|
69
|
-
}
|
|
70
|
-
_checkExists(filePath) {
|
|
71
|
-
filePath = this._deletedThrows(filePath);
|
|
72
|
-
if (!this.existsSync(filePath)) {
|
|
73
|
-
throw new FSError('ENOENT', filePath, 'does not exist');
|
|
74
|
-
}
|
|
75
|
-
return filePath;
|
|
76
|
-
}
|
|
77
|
-
_isSymlink(filePath) {
|
|
78
|
-
filePath = this._normalizePath(filePath);
|
|
79
|
-
// Check the parts of the path to see if any are symlinks.
|
|
80
|
-
let {
|
|
81
|
-
root,
|
|
82
|
-
dir,
|
|
83
|
-
base
|
|
84
|
-
} = _path().default.parse(filePath);
|
|
85
|
-
let segments = dir.slice(root.length).split(_path().default.sep).concat(base);
|
|
86
|
-
while (segments.length) {
|
|
87
|
-
filePath = _path().default.join(root, ...segments);
|
|
88
|
-
let name = segments.pop();
|
|
89
|
-
if (this.deleted.has(filePath)) {
|
|
90
|
-
return false;
|
|
91
|
-
} else if (this.writable instanceof _MemoryFS.MemoryFS && this.writable.symlinks.has(filePath)) {
|
|
92
|
-
return true;
|
|
93
|
-
} else {
|
|
94
|
-
// HACK: Atlaspack fs does not provide `lstatSync`,
|
|
95
|
-
// so we use `readdirSync` to check if the path is a symlink.
|
|
96
|
-
let parent = _path().default.resolve(filePath, '..');
|
|
97
|
-
if (parent === filePath) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
for (let dirent of this.readdirSync(parent, {
|
|
102
|
-
withFileTypes: true
|
|
103
|
-
})) {
|
|
104
|
-
if (typeof dirent === 'string') {
|
|
105
|
-
break; // {withFileTypes: true} not supported
|
|
106
|
-
} else if (dirent.name === name) {
|
|
107
|
-
if (dirent.isSymbolicLink()) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
} catch (e) {
|
|
113
|
-
if (e.code === 'ENOENT') {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
throw e;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
async _copyPathForWrite(filePath) {
|
|
123
|
-
filePath = await this._normalizePath(filePath);
|
|
124
|
-
let dirPath = _path().default.dirname(filePath);
|
|
125
|
-
if (this.existsSync(dirPath) && !this.writable.existsSync(dirPath)) {
|
|
126
|
-
await this.writable.mkdirp(dirPath);
|
|
127
|
-
}
|
|
128
|
-
return filePath;
|
|
129
|
-
}
|
|
130
|
-
_normalizePath(filePath) {
|
|
131
|
-
return _path().default.resolve(this.cwd(), filePath);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// eslint-disable-next-line require-await
|
|
135
|
-
async readFile(filePath, encoding) {
|
|
136
|
-
return this.readFileSync(filePath, encoding);
|
|
137
|
-
}
|
|
138
|
-
async writeFile(filePath, contents, options) {
|
|
139
|
-
filePath = await this._copyPathForWrite(filePath);
|
|
140
|
-
await this.writable.writeFile(filePath, contents, options);
|
|
141
|
-
this.deleted.delete(filePath);
|
|
142
|
-
}
|
|
143
|
-
async copyFile(source, destination) {
|
|
144
|
-
source = this._normalizePath(source);
|
|
145
|
-
destination = await this._copyPathForWrite(destination);
|
|
146
|
-
if (await this.writable.exists(source)) {
|
|
147
|
-
await this.writable.writeFile(destination, await this.writable.readFile(source));
|
|
148
|
-
} else {
|
|
149
|
-
await this.writable.writeFile(destination, await this.readable.readFile(source));
|
|
150
|
-
}
|
|
151
|
-
this.deleted.delete(destination);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// eslint-disable-next-line require-await
|
|
155
|
-
async stat(filePath) {
|
|
156
|
-
return this.statSync(filePath);
|
|
157
|
-
}
|
|
158
|
-
async symlink(target, filePath) {
|
|
159
|
-
target = this._normalizePath(target);
|
|
160
|
-
filePath = this._normalizePath(filePath);
|
|
161
|
-
await this.writable.symlink(target, filePath);
|
|
162
|
-
this.deleted.delete(filePath);
|
|
163
|
-
}
|
|
164
|
-
async unlink(filePath) {
|
|
165
|
-
filePath = this._normalizePath(filePath);
|
|
166
|
-
let toDelete = [filePath];
|
|
167
|
-
if (this.writable instanceof _MemoryFS.MemoryFS && this._isSymlink(filePath)) {
|
|
168
|
-
this.writable.symlinks.delete(filePath);
|
|
169
|
-
} else if (this.statSync(filePath).isDirectory()) {
|
|
170
|
-
let stack = [filePath];
|
|
171
|
-
|
|
172
|
-
// Recursively add every descendant path to deleted.
|
|
173
|
-
while (stack.length) {
|
|
174
|
-
let root = (0, _nullthrows().default)(stack.pop());
|
|
175
|
-
for (let ent of this.readdirSync(root, {
|
|
176
|
-
withFileTypes: true
|
|
177
|
-
})) {
|
|
178
|
-
if (typeof ent === 'string') {
|
|
179
|
-
let childPath = _path().default.join(root, ent);
|
|
180
|
-
toDelete.push(childPath);
|
|
181
|
-
if (this.statSync(childPath).isDirectory()) {
|
|
182
|
-
stack.push(childPath);
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
let childPath = _path().default.join(root, ent.name);
|
|
186
|
-
toDelete.push(childPath);
|
|
187
|
-
if (ent.isDirectory()) {
|
|
188
|
-
stack.push(childPath);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
try {
|
|
195
|
-
await this.writable.unlink(filePath);
|
|
196
|
-
} catch (e) {
|
|
197
|
-
if (e.code === 'ENOENT' && !this.readable.existsSync(filePath)) {
|
|
198
|
-
throw e;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
for (let pathToDelete of toDelete) {
|
|
202
|
-
this.deleted.add(pathToDelete);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
async mkdirp(dir) {
|
|
206
|
-
dir = this._normalizePath(dir);
|
|
207
|
-
await this.writable.mkdirp(dir);
|
|
208
|
-
if (this.deleted != null) {
|
|
209
|
-
let root = _path().default.parse(dir).root;
|
|
210
|
-
while (dir !== root) {
|
|
211
|
-
this.deleted.delete(dir);
|
|
212
|
-
dir = _path().default.dirname(dir);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
async rimraf(filePath) {
|
|
217
|
-
try {
|
|
218
|
-
await this.unlink(filePath);
|
|
219
|
-
} catch (e) {
|
|
220
|
-
// noop
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// eslint-disable-next-line require-await
|
|
225
|
-
async ncp(source, destination) {
|
|
226
|
-
// TODO: Implement this correctly.
|
|
227
|
-
return this.writable.ncp(source, destination);
|
|
228
|
-
}
|
|
229
|
-
createReadStream(filePath, opts) {
|
|
230
|
-
filePath = this._deletedThrows(filePath);
|
|
231
|
-
if (this.writable.existsSync(filePath)) {
|
|
232
|
-
return this.writable.createReadStream(filePath, opts);
|
|
233
|
-
}
|
|
234
|
-
return this.readable.createReadStream(filePath, opts);
|
|
235
|
-
}
|
|
236
|
-
createWriteStream(path, opts) {
|
|
237
|
-
path = this._normalizePath(path);
|
|
238
|
-
this.deleted.delete(path);
|
|
239
|
-
return this.writable.createWriteStream(path, opts);
|
|
240
|
-
}
|
|
241
|
-
cwd() {
|
|
242
|
-
return this._cwd;
|
|
243
|
-
}
|
|
244
|
-
chdir(path) {
|
|
245
|
-
this._cwd = this._checkExists(path);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// eslint-disable-next-line require-await
|
|
249
|
-
async realpath(filePath) {
|
|
250
|
-
return this.realpathSync(filePath);
|
|
251
|
-
}
|
|
252
|
-
readFileSync(filePath, encoding) {
|
|
253
|
-
filePath = this.realpathSync(filePath);
|
|
254
|
-
try {
|
|
255
|
-
// $FlowFixMe[incompatible-call]
|
|
256
|
-
return this.writable.readFileSync(filePath, encoding);
|
|
257
|
-
} catch (err) {
|
|
258
|
-
// $FlowFixMe[incompatible-call]
|
|
259
|
-
return this.readable.readFileSync(filePath, encoding);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
statSync(filePath) {
|
|
263
|
-
filePath = this._normalizePath(filePath);
|
|
264
|
-
try {
|
|
265
|
-
return this.writable.statSync(filePath);
|
|
266
|
-
} catch (e) {
|
|
267
|
-
if (e.code === 'ENOENT' && this.existsSync(filePath)) {
|
|
268
|
-
return this.readable.statSync(filePath);
|
|
269
|
-
}
|
|
270
|
-
throw e;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
realpathSync(filePath) {
|
|
274
|
-
filePath = this._deletedThrows(filePath);
|
|
275
|
-
filePath = this._deletedThrows(this.writable.realpathSync(filePath));
|
|
276
|
-
if (!this.writable.existsSync(filePath)) {
|
|
277
|
-
return this.readable.realpathSync(filePath);
|
|
278
|
-
}
|
|
279
|
-
return filePath;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// eslint-disable-next-line require-await
|
|
283
|
-
async exists(filePath) {
|
|
284
|
-
return this.existsSync(filePath);
|
|
285
|
-
}
|
|
286
|
-
existsSync(filePath) {
|
|
287
|
-
filePath = this._normalizePath(filePath);
|
|
288
|
-
if (this.deleted.has(filePath)) return false;
|
|
289
|
-
try {
|
|
290
|
-
filePath = this.realpathSync(filePath);
|
|
291
|
-
} catch (err) {
|
|
292
|
-
if (err.code !== 'ENOENT') throw err;
|
|
293
|
-
}
|
|
294
|
-
if (this.deleted.has(filePath)) return false;
|
|
295
|
-
return this.writable.existsSync(filePath) || this.readable.existsSync(filePath);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// eslint-disable-next-line require-await
|
|
299
|
-
async readdir(path, opts) {
|
|
300
|
-
return this.readdirSync(path, opts);
|
|
301
|
-
}
|
|
302
|
-
readdirSync(dir, opts) {
|
|
303
|
-
dir = this.realpathSync(dir);
|
|
304
|
-
// Read from both filesystems and merge the results
|
|
305
|
-
let entries = new Map();
|
|
306
|
-
try {
|
|
307
|
-
for (let entry of this.writable.readdirSync(dir, opts)) {
|
|
308
|
-
let filePath = _path().default.join(dir, entry.name ?? entry);
|
|
309
|
-
if (this.deleted.has(filePath)) continue;
|
|
310
|
-
entries.set(filePath, entry);
|
|
311
|
-
}
|
|
312
|
-
} catch {
|
|
313
|
-
// noop
|
|
314
|
-
}
|
|
315
|
-
try {
|
|
316
|
-
for (let entry of this.readable.readdirSync(dir, opts)) {
|
|
317
|
-
let filePath = _path().default.join(dir, entry.name ?? entry);
|
|
318
|
-
if (this.deleted.has(filePath)) continue;
|
|
319
|
-
if (entries.has(filePath)) continue;
|
|
320
|
-
entries.set(filePath, entry);
|
|
321
|
-
}
|
|
322
|
-
} catch {
|
|
323
|
-
// noop
|
|
324
|
-
}
|
|
325
|
-
return Array.from(entries.values());
|
|
326
|
-
}
|
|
327
|
-
async watch(dir, fn, opts) {
|
|
328
|
-
let writableSubscription = await this.writable.watch(dir, fn, opts);
|
|
329
|
-
let readableSubscription = await this.readable.watch(dir, fn, opts);
|
|
330
|
-
return {
|
|
331
|
-
unsubscribe: async () => {
|
|
332
|
-
await writableSubscription.unsubscribe();
|
|
333
|
-
await readableSubscription.unsubscribe();
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
async getEventsSince(dir, snapshot, opts) {
|
|
338
|
-
let writableEvents = await this.writable.getEventsSince(dir, snapshot, opts);
|
|
339
|
-
let readableEvents = await this.readable.getEventsSince(dir, snapshot, opts);
|
|
340
|
-
return [...writableEvents, ...readableEvents];
|
|
341
|
-
}
|
|
342
|
-
async writeSnapshot(dir, snapshot, opts) {
|
|
343
|
-
await this.writable.writeSnapshot(dir, snapshot, opts);
|
|
344
|
-
}
|
|
345
|
-
findAncestorFile(fileNames, fromDir, root) {
|
|
346
|
-
return (0, _find.findAncestorFile)(this, fileNames, fromDir, root);
|
|
347
|
-
}
|
|
348
|
-
findNodeModule(moduleName, fromDir) {
|
|
349
|
-
return (0, _find.findNodeModule)(this, moduleName, fromDir);
|
|
350
|
-
}
|
|
351
|
-
findFirstFile(filePaths) {
|
|
352
|
-
return (0, _find.findFirstFile)(this, filePaths);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
exports.OverlayFS = OverlayFS;
|
|
356
|
-
class FSError extends Error {
|
|
357
|
-
constructor(code, path, message) {
|
|
358
|
-
var _Error$captureStackTr;
|
|
359
|
-
super(`${code}: ${path} ${message}`);
|
|
360
|
-
this.name = 'FSError';
|
|
361
|
-
this.code = code;
|
|
362
|
-
this.path = path;
|
|
363
|
-
(_Error$captureStackTr = Error.captureStackTrace) === null || _Error$captureStackTr === void 0 || _Error$captureStackTr.call(Error, this, this.constructor);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
(0, _buildCache().registerSerializableClass)(`${_package.default.version}:OverlayFS`, OverlayFS);
|
package/lib/find.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findAncestorFile = findAncestorFile;
|
|
7
|
-
exports.findFirstFile = findFirstFile;
|
|
8
|
-
exports.findNodeModule = findNodeModule;
|
|
9
|
-
function _path() {
|
|
10
|
-
const data = _interopRequireDefault(require("path"));
|
|
11
|
-
_path = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
function findNodeModule(fs, moduleName, dir) {
|
|
18
|
-
let {
|
|
19
|
-
root
|
|
20
|
-
} = _path().default.parse(dir);
|
|
21
|
-
while (dir !== root) {
|
|
22
|
-
// Skip node_modules directories
|
|
23
|
-
if (_path().default.basename(dir) === 'node_modules') {
|
|
24
|
-
dir = _path().default.dirname(dir);
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
let moduleDir = _path().default.join(dir, 'node_modules', moduleName);
|
|
28
|
-
let stats = fs.statSync(moduleDir);
|
|
29
|
-
if (stats.isDirectory()) {
|
|
30
|
-
return moduleDir;
|
|
31
|
-
}
|
|
32
|
-
} catch (err) {
|
|
33
|
-
// ignore
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Move up a directory
|
|
37
|
-
dir = _path().default.dirname(dir);
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
function findAncestorFile(fs, fileNames, dir, root) {
|
|
42
|
-
let {
|
|
43
|
-
root: pathRoot
|
|
44
|
-
} = _path().default.parse(dir);
|
|
45
|
-
// eslint-disable-next-line no-constant-condition
|
|
46
|
-
while (true) {
|
|
47
|
-
if (_path().default.basename(dir) === 'node_modules') {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
for (const fileName of fileNames) {
|
|
51
|
-
let filePath = _path().default.join(dir, fileName);
|
|
52
|
-
try {
|
|
53
|
-
if (fs.statSync(filePath).isFile()) {
|
|
54
|
-
return filePath;
|
|
55
|
-
}
|
|
56
|
-
} catch (err) {
|
|
57
|
-
// ignore
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (dir === root || dir === pathRoot) {
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
dir = _path().default.dirname(dir);
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
function findFirstFile(fs, filePaths) {
|
|
68
|
-
for (let filePath of filePaths) {
|
|
69
|
-
try {
|
|
70
|
-
if (fs.statSync(filePath).isFile()) {
|
|
71
|
-
return filePath;
|
|
72
|
-
}
|
|
73
|
-
} catch (err) {
|
|
74
|
-
// ignore
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|