@atlaspack/fs 2.15.16-typescript-e99c742e9.0 → 2.15.16-typescript-bc4459c37.0

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.
@@ -0,0 +1,368 @@
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
+ // @ts-expect-error TS2345
256
+ return this.writable.readFileSync(filePath, encoding);
257
+ } catch (err) {
258
+ // @ts-expect-error TS2345
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
+ // @ts-expect-error TS2769
308
+ for (let entry of this.writable.readdirSync(dir, opts)) {
309
+ let filePath = _path().default.join(dir, entry.name ?? entry);
310
+ if (this.deleted.has(filePath)) continue;
311
+ entries.set(filePath, entry);
312
+ }
313
+ } catch {
314
+ // noop
315
+ }
316
+ try {
317
+ // @ts-expect-error TS2769
318
+ for (let entry of this.readable.readdirSync(dir, opts)) {
319
+ let filePath = _path().default.join(dir, entry.name ?? entry);
320
+ if (this.deleted.has(filePath)) continue;
321
+ if (entries.has(filePath)) continue;
322
+ entries.set(filePath, entry);
323
+ }
324
+ } catch {
325
+ // noop
326
+ }
327
+ return Array.from(entries.values());
328
+ }
329
+ async watch(dir, fn, opts) {
330
+ let writableSubscription = await this.writable.watch(dir, fn, opts);
331
+ let readableSubscription = await this.readable.watch(dir, fn, opts);
332
+ return {
333
+ unsubscribe: async () => {
334
+ await writableSubscription.unsubscribe();
335
+ await readableSubscription.unsubscribe();
336
+ }
337
+ };
338
+ }
339
+ async getEventsSince(dir, snapshot, opts) {
340
+ let writableEvents = await this.writable.getEventsSince(dir, snapshot, opts);
341
+ let readableEvents = await this.readable.getEventsSince(dir, snapshot, opts);
342
+ return [...writableEvents, ...readableEvents];
343
+ }
344
+ async writeSnapshot(dir, snapshot, opts) {
345
+ await this.writable.writeSnapshot(dir, snapshot, opts);
346
+ }
347
+ findAncestorFile(fileNames, fromDir, root) {
348
+ return (0, _find.findAncestorFile)(this, fileNames, fromDir, root);
349
+ }
350
+ findNodeModule(moduleName, fromDir) {
351
+ return (0, _find.findNodeModule)(this, moduleName, fromDir);
352
+ }
353
+ findFirstFile(filePaths) {
354
+ return (0, _find.findFirstFile)(this, filePaths);
355
+ }
356
+ }
357
+ exports.OverlayFS = OverlayFS;
358
+ class FSError extends Error {
359
+ constructor(code, path, message) {
360
+ var _Error$captureStackTr;
361
+ super(`${code}: ${path} ${message}`);
362
+ this.name = 'FSError';
363
+ this.code = code;
364
+ this.path = path;
365
+ (_Error$captureStackTr = Error.captureStackTrace) === null || _Error$captureStackTr === void 0 || _Error$captureStackTr.call(Error, this, this.constructor);
366
+ }
367
+ }
368
+ (0, _buildCache().registerSerializableClass)(`${_package.default.version}:OverlayFS`, OverlayFS);
package/lib/find.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { FilePath, FileSystem } from '@atlaspack/types-internal';
2
+ export declare function findNodeModule(fs: FileSystem, moduleName: string, dir: FilePath): FilePath | null | undefined;
3
+ export declare function findAncestorFile(fs: FileSystem, fileNames: Array<string>, dir: FilePath, root: FilePath): FilePath | null | undefined;
4
+ export declare function findFirstFile(fs: FileSystem, filePaths: Array<FilePath>): FilePath | null | undefined;
package/lib/find.js ADDED
@@ -0,0 +1,77 @@
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
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { FilePath, FileSystem, FileOptions } from '@atlaspack/types-internal';
2
+ export * from './NodeFS';
3
+ export * from './MemoryFS';
4
+ export * from './OverlayFS';
5
+ export * from './NodeVCSAwareFS';
6
+ export type { FileSystem, FileOptions };
7
+ export declare function ncp(sourceFS: FileSystem, source: FilePath, destinationFS: FileSystem, destination: FilePath, filter?: (filePath: FilePath) => boolean): Promise<void>;
package/lib/index.js ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ ncp: true
8
+ };
9
+ exports.ncp = ncp;
10
+ function _path() {
11
+ const data = _interopRequireDefault(require("path"));
12
+ _path = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _stream() {
18
+ const data = _interopRequireDefault(require("stream"));
19
+ _stream = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _util() {
25
+ const data = require("util");
26
+ _util = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ var _NodeFS = require("./NodeFS");
32
+ Object.keys(_NodeFS).forEach(function (key) {
33
+ if (key === "default" || key === "__esModule") return;
34
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
35
+ if (key in exports && exports[key] === _NodeFS[key]) return;
36
+ Object.defineProperty(exports, key, {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _NodeFS[key];
40
+ }
41
+ });
42
+ });
43
+ var _MemoryFS = require("./MemoryFS");
44
+ Object.keys(_MemoryFS).forEach(function (key) {
45
+ if (key === "default" || key === "__esModule") return;
46
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
47
+ if (key in exports && exports[key] === _MemoryFS[key]) return;
48
+ Object.defineProperty(exports, key, {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _MemoryFS[key];
52
+ }
53
+ });
54
+ });
55
+ var _OverlayFS = require("./OverlayFS");
56
+ Object.keys(_OverlayFS).forEach(function (key) {
57
+ if (key === "default" || key === "__esModule") return;
58
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
59
+ if (key in exports && exports[key] === _OverlayFS[key]) return;
60
+ Object.defineProperty(exports, key, {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _OverlayFS[key];
64
+ }
65
+ });
66
+ });
67
+ var _NodeVCSAwareFS = require("./NodeVCSAwareFS");
68
+ Object.keys(_NodeVCSAwareFS).forEach(function (key) {
69
+ if (key === "default" || key === "__esModule") return;
70
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
71
+ if (key in exports && exports[key] === _NodeVCSAwareFS[key]) return;
72
+ Object.defineProperty(exports, key, {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _NodeVCSAwareFS[key];
76
+ }
77
+ });
78
+ });
79
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
80
+ const pipeline = (0, _util().promisify)(_stream().default.pipeline);
81
+
82
+ // Recursively copies a directory from the sourceFS to the destinationFS
83
+ async function ncp(sourceFS, source, destinationFS, destination, filter) {
84
+ await destinationFS.mkdirp(destination);
85
+ let files = await sourceFS.readdir(source);
86
+ for (let file of files) {
87
+ if (filter && !filter(file)) {
88
+ continue;
89
+ }
90
+ let sourcePath = _path().default.join(source, file);
91
+ let destPath = _path().default.join(destination, file);
92
+ let stats = await sourceFS.stat(sourcePath);
93
+ if (stats.isFile()) {
94
+ await pipeline(sourceFS.createReadStream(sourcePath), destinationFS.createWriteStream(destPath));
95
+ } else if (stats.isDirectory()) {
96
+ await ncp(sourceFS, sourcePath, destinationFS, destPath, filter);
97
+ }
98
+ }
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/fs",
3
- "version": "2.15.16-typescript-e99c742e9.0",
3
+ "version": "2.15.16-typescript-bc4459c37.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -51,14 +51,14 @@
51
51
  "check-ts": "tsc --emitDeclarationOnly --rootDir src"
52
52
  },
53
53
  "dependencies": {
54
- "@atlaspack/build-cache": "2.13.4-typescript-e99c742e9.0",
55
- "@atlaspack/feature-flags": "2.19.3-typescript-e99c742e9.0",
56
- "@atlaspack/logger": "2.14.14-typescript-e99c742e9.0",
57
- "@atlaspack/rust": "3.4.2-typescript-e99c742e9.0",
58
- "@atlaspack/types-internal": "2.15.3-typescript-e99c742e9.0",
59
- "@atlaspack/utils": "2.17.3-typescript-e99c742e9.0",
60
- "@atlaspack/watcher-watchman-js": "2.14.21-typescript-e99c742e9.0",
61
- "@atlaspack/workers": "2.14.21-typescript-e99c742e9.0",
54
+ "@atlaspack/build-cache": "2.13.4-typescript-bc4459c37.0",
55
+ "@atlaspack/feature-flags": "2.19.3-typescript-bc4459c37.0",
56
+ "@atlaspack/logger": "2.14.14-typescript-bc4459c37.0",
57
+ "@atlaspack/rust": "3.4.2-typescript-bc4459c37.0",
58
+ "@atlaspack/types-internal": "2.15.3-typescript-bc4459c37.0",
59
+ "@atlaspack/utils": "2.17.3-typescript-bc4459c37.0",
60
+ "@atlaspack/watcher-watchman-js": "2.14.21-typescript-bc4459c37.0",
61
+ "@atlaspack/workers": "2.14.21-typescript-bc4459c37.0",
62
62
  "@parcel/watcher": "^2.0.7",
63
63
  "graceful-fs": "^4.2.4",
64
64
  "ncp": "^2.0.0",
@@ -70,5 +70,5 @@
70
70
  "./src/NodeFS.js": "./src/NodeFS.browser.js"
71
71
  },
72
72
  "type": "commonjs",
73
- "gitHead": "e99c742e92175ac411d807daf2ba45d5bacebb58"
73
+ "gitHead": "bc4459c37a38ef1f74772126637e1d8841d1fcb0"
74
74
  }