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

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaspack/fs
2
2
 
3
+ ## 2.15.16
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
8
+ - @atlaspack/types-internal@2.16.0
9
+ - @atlaspack/feature-flags@2.20.0
10
+ - @atlaspack/workers@2.14.21
11
+ - @atlaspack/utils@2.17.3
12
+ - @atlaspack/watcher-watchman-js@2.14.21
13
+
3
14
  ## 2.15.15
4
15
 
5
16
  ### Patch Changes
package/index.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type {FileSystem, FilePath} from '@atlaspack/types-internal';
2
+ import type {Event} from '@parcel/watcher';
3
+ import type WorkerFarm from '@atlaspack/workers';
4
+
5
+ export type {
6
+ FileSystem,
7
+ FileOptions,
8
+ ReaddirOptions,
9
+ Stats,
10
+ Encoding,
11
+ Dirent,
12
+ } from '@atlaspack/types-internal';
13
+
14
+ export const NodeFS: {
15
+ new (): FileSystem;
16
+ };
17
+
18
+ export const MemoryFS: {
19
+ new (farm: WorkerFarm): FileSystem;
20
+ };
21
+
22
+ export const OverlayFS: {
23
+ new (writable: FileSystem, readable: FileSystem): FileSystem;
24
+ };
25
+
26
+ interface NodeVCSAwareFSOptions {
27
+ gitRepoPath: null | FilePath;
28
+ excludePatterns: Array<string>;
29
+ logEventDiff: null | ((watcherEvents: Event[], vcsEvents: Event[]) => void);
30
+ }
31
+
32
+ export const NodeVCSAwareFS: {
33
+ new (options: NodeVCSAwareFSOptions): FileSystem;
34
+ };
package/lib/MemoryFS.js CHANGED
@@ -35,7 +35,7 @@ function _utils() {
35
35
  }
36
36
  var _package = _interopRequireDefault(require("../package.json"));
37
37
  function _workers() {
38
- const data = _interopRequireDefault(require("@atlaspack/workers"));
38
+ const data = _interopRequireWildcard(require("@atlaspack/workers"));
39
39
  _workers = function () {
40
40
  return data;
41
41
  };
@@ -56,14 +56,12 @@ function _events() {
56
56
  return data;
57
57
  }
58
58
  var _find = require("./find");
59
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
60
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
59
61
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
60
62
  const instances = new Map();
61
63
  let id = 0;
62
64
  class MemoryFS {
63
- // @ts-expect-error TS2564
64
-
65
- // @ts-expect-error TS2564
66
-
67
65
  _numWorkerInstances = 0;
68
66
  _workerRegisterResolves = [];
69
67
  _emitter = new (_events().default)();
@@ -102,7 +100,7 @@ class MemoryFS {
102
100
  serialize() {
103
101
  if (!this.handle) {
104
102
  this.handle = this.farm.createReverseHandle((fn, args) => {
105
- // @ts-expect-error TS7053
103
+ // $FlowFixMe
106
104
  return this[fn](...args);
107
105
  });
108
106
  }
@@ -110,7 +108,6 @@ class MemoryFS {
110
108
  // If a worker instance already exists, it will decrement this number
111
109
  this._numWorkerInstances++;
112
110
  return {
113
- // @ts-expect-error TS2353
114
111
  $$raw: false,
115
112
  id: this.id,
116
113
  handle: this.handle,
@@ -474,8 +471,6 @@ class MemoryFS {
474
471
  // Batch events
475
472
  this._eventQueue.push(event);
476
473
  clearTimeout(this._watcherTimer);
477
-
478
- // @ts-expect-error TS2322
479
474
  this._watcherTimer = setTimeout(() => {
480
475
  let events = this._eventQueue;
481
476
  this._eventQueue = [];
@@ -501,9 +496,7 @@ class MemoryFS {
501
496
  async _sendWorkerEvent(event) {
502
497
  // Wait for worker instances to register their handles
503
498
  while (this._workerHandles.length < this._numWorkerInstances) {
504
- await new Promise(resolve =>
505
- // @ts-expect-error TS2345
506
- this._workerRegisterResolves.push(resolve));
499
+ await new Promise(resolve => this._workerRegisterResolves.push(resolve));
507
500
  }
508
501
  await Promise.all(this._workerHandles.map(workerHandle => this.farm.workerApi.runHandle(workerHandle, [event])));
509
502
  }
@@ -617,9 +610,7 @@ class WriteStream extends _stream().Writable {
617
610
  callback();
618
611
  }
619
612
  _final(callback) {
620
- this.fs.writeFile(this.filePath, this.buffer, this.options)
621
- // @ts-expect-error TS2345
622
- .then(callback).catch(callback);
613
+ this.fs.writeFile(this.filePath, this.buffer, this.options).then(callback).catch(callback);
623
614
  }
624
615
  }
625
616
  const S_IFREG = 0o100000;
@@ -752,7 +743,7 @@ function makeShared(contents) {
752
743
  return contents;
753
744
  }
754
745
  let contentsBuffer = contents;
755
- // @ts-expect-error TS2339
746
+ // $FlowFixMe
756
747
  if (process.browser) {
757
748
  // For the polyfilled buffer module, it's faster to always convert once so that the subsequent
758
749
  // operations are fast (.byteLength and using .set instead of .write)
@@ -773,7 +764,7 @@ function makeShared(contents) {
773
764
  class WorkerFS extends MemoryFS {
774
765
  constructor(id, handle) {
775
766
  // TODO Make this not a subclass
776
- // @ts-expect-error TS2554
767
+ // $FlowFixMe
777
768
  super();
778
769
  this.id = id;
779
770
  this.handleFn = (methodName, args) => _workers().default.getWorkerApi().runHandle(handle, [methodName, args]);
@@ -800,7 +791,7 @@ class WorkerFS extends MemoryFS {
800
791
  return (0, _nullthrows().default)(instances.get(opts.id));
801
792
  }
802
793
  serialize() {
803
- // @ts-expect-error TS2739
794
+ // $FlowFixMe
804
795
  return {
805
796
  id: this.id
806
797
  };
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.NodeFS = void 0;
7
- // @ts-expect-error TS2420
7
+ // $FlowFixMe[prop-missing] handled by the throwing constructor
8
8
  class NodeFS {
9
9
  constructor() {
10
10
  throw new Error("NodeFS isn't available in the browser");
package/lib/NodeFS.js CHANGED
@@ -86,10 +86,6 @@ var searchJS = _interopRequireWildcard(require("./find"));
86
86
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
87
87
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
88
88
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
89
- // @ts-expect-error TS7016
90
-
91
- // @ts-expect-error TS7016
92
-
93
89
  // Most of this can go away once we only support Node 10+, which includes
94
90
  // require('fs').promises
95
91
  const realpath = (0, _util().promisify)(process.platform === 'win32' ? _gracefulFs().default.realpath : _gracefulFs().default.realpath.native);
@@ -97,6 +93,8 @@ const isPnP = process.versions.pnp != null;
97
93
  function getWatchmanWatcher() {
98
94
  // This is here to trick atlaspack into ignoring this require...
99
95
  const packageName = ['@atlaspack', 'watcher-watchman-js'].join('/');
96
+
97
+ // $FlowFixMe
100
98
  return require(packageName);
101
99
  }
102
100
  class NodeFS {
@@ -115,15 +113,9 @@ class NodeFS {
115
113
  realpathSync = process.platform === 'win32' ? _gracefulFs().default.realpathSync : _gracefulFs().default.realpathSync.native;
116
114
  existsSync = _gracefulFs().default.existsSync;
117
115
  readdirSync = _gracefulFs().default.readdirSync;
118
- findAncestorFile = isPnP ?
119
- // @ts-expect-error TS7019
120
- (...args) => searchJS.findAncestorFile(this, ...args) : searchNative().findAncestorFile;
121
- findNodeModule = isPnP ?
122
- // @ts-expect-error TS7019
123
- (...args) => searchJS.findNodeModule(this, ...args) : searchNative().findNodeModule;
124
- findFirstFile = isPnP ?
125
- // @ts-expect-error TS7019
126
- (...args) => searchJS.findFirstFile(this, ...args) : searchNative().findFirstFile;
116
+ findAncestorFile = isPnP ? (...args) => searchJS.findAncestorFile(this, ...args) : searchNative().findAncestorFile;
117
+ findNodeModule = isPnP ? (...args) => searchJS.findNodeModule(this, ...args) : searchNative().findNodeModule;
118
+ findFirstFile = isPnP ? (...args) => searchJS.findFirstFile(this, ...args) : searchNative().findFirstFile;
127
119
  watcher() {
128
120
  return (0, _featureFlags().getFeatureFlag)('useWatchmanWatcher') ? getWatchmanWatcher() : _watcher().default;
129
121
  }
@@ -152,9 +144,7 @@ class NodeFS {
152
144
  ...options,
153
145
  fs: {
154
146
  ..._gracefulFs().default,
155
- // @ts-expect-error TS7006
156
147
  close: (fd, cb) => {
157
- // @ts-expect-error TS7006
158
148
  _gracefulFs().default.close(fd, err => {
159
149
  if (err) {
160
150
  cb(err);
@@ -237,6 +227,7 @@ class NodeFS {
237
227
  return;
238
228
  }
239
229
  if (stat.isDirectory()) {
230
+ // $FlowFixMe
240
231
  await _fs().default.promises.rmdir(filePath, {
241
232
  recursive: true
242
233
  });
@@ -248,8 +239,6 @@ class NodeFS {
248
239
  exports.NodeFS = NodeFS;
249
240
  (0, _buildCache().registerSerializableClass)(`${_package.default.version}:NodeFS`, NodeFS);
250
241
  let writeStreamCalls = 0;
251
-
252
- // @ts-expect-error TS7034
253
242
  let threadId;
254
243
  try {
255
244
  ({
@@ -258,13 +247,9 @@ try {
258
247
  } catch {
259
248
  //
260
249
  }
261
-
262
- // @ts-expect-error TS7034
263
250
  let useOsTmpDir;
264
251
  function shouldUseOsTmpDir(filePath) {
265
- // @ts-expect-error TS7005
266
252
  if (useOsTmpDir != null) {
267
- // @ts-expect-error TS7005
268
253
  return useOsTmpDir;
269
254
  }
270
255
  try {
@@ -292,7 +277,5 @@ function getTempFilePath(filePath) {
292
277
  if (shouldUseOsTmpDir(filePath)) {
293
278
  tmpFilePath = _path().default.join((0, _os().tmpdir)(), _path().default.basename(filePath));
294
279
  }
295
- return tmpFilePath + '.' + process.pid + (
296
- // @ts-expect-error TS7005
297
- threadId != null ? '.' + threadId : '') + '.' + (writeStreamCalls++).toString(36);
280
+ return tmpFilePath + '.' + process.pid + (threadId != null ? '.' + threadId : '') + '.' + (writeStreamCalls++).toString(36);
298
281
  }
@@ -44,6 +44,7 @@ var _package = _interopRequireDefault(require("../package.json"));
44
44
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
45
45
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
46
46
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
+ // $FlowFixMe
47
48
  class NodeVCSAwareFS extends _NodeFS.NodeFS {
48
49
  /**
49
50
  * These files are excluded from 'dirty file' tracking even if they are
@@ -65,6 +66,8 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
65
66
  this.#logEventDiff = options.logEventDiff;
66
67
  this.#gitRepoPath = options.gitRepoPath;
67
68
  }
69
+
70
+ // $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
68
71
  static deserialize(data) {
69
72
  const fs = new NodeVCSAwareFS({
70
73
  excludePatterns: data.excludePatterns,
@@ -74,7 +77,7 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
74
77
  return fs;
75
78
  }
76
79
 
77
- // @ts-expect-error TS2416
80
+ // $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
78
81
  serialize() {
79
82
  return {
80
83
  excludePatterns: this.#excludePatterns,
@@ -100,14 +103,7 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
100
103
  return JSON.parse(snapshotFileContent);
101
104
  });
102
105
  let watcherEventsSince = [];
103
- const vcsEventsSince = vcsState != null ?
104
- // @ts-expect-error TS2571
105
- (await (0, _logger().instrumentAsync)('NodeVCSAwareFS::rust.getEventsSince', () =>
106
- // @ts-expect-error TS2739
107
- (0, _rust().getEventsSince)(gitRepoPath, vcsState, null))
108
-
109
- // @ts-expect-error TS7006
110
- ).map(e => ({
106
+ const vcsEventsSince = vcsState != null ? (await (0, _logger().instrumentAsync)('NodeVCSAwareFS::rust.getEventsSince', () => (0, _rust().getEventsSince)(gitRepoPath, vcsState, null))).map(e => ({
111
107
  path: e.path,
112
108
  type: e.changeType
113
109
  })) : null;
@@ -116,8 +112,6 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
116
112
  watcherEventsSince = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::watchman.getEventsSince', () => this.watcher().getEventsSince(dir, nativeSnapshotPath, opts));
117
113
  (_this$logEventDiff = this.#logEventDiff) === null || _this$logEventDiff === void 0 || _this$logEventDiff.call(this, watcherEventsSince, vcsEventsSince);
118
114
  }
119
-
120
- // @ts-expect-error TS2345
121
115
  if (['NEW_AND_CHECK', 'NEW'].includes((0, _featureFlags().getFeatureFlagValue)('vcsMode'))) {
122
116
  if (vcsEventsSince == null) {
123
117
  _logger().default.error({
@@ -151,17 +145,13 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
151
145
  let vcsState = null;
152
146
  try {
153
147
  var _vcsState, _vcsState2;
154
- vcsState = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::getVcsStateSnapshot',
155
- // @ts-expect-error TS2322
156
- () => (0, _rust().getVcsStateSnapshot)(gitRepoPath, this.#excludePatterns));
148
+ vcsState = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::getVcsStateSnapshot', () => (0, _rust().getVcsStateSnapshot)(gitRepoPath, this.#excludePatterns));
157
149
  _logger().default.verbose({
158
150
  origin: '@atlaspack/fs',
159
151
  message: 'Expose VCS timing metrics',
160
152
  meta: {
161
153
  trackableEvent: 'vcs_timing_metrics',
162
- // @ts-expect-error TS2339
163
154
  dirtyFilesExecutionTime: (_vcsState = vcsState) === null || _vcsState === void 0 ? void 0 : _vcsState.dirtyFilesExecutionTime,
164
- // @ts-expect-error TS2339
165
155
  yarnStatesExecutionTime: (_vcsState2 = vcsState) === null || _vcsState2 === void 0 ? void 0 : _vcsState2.yarnStatesExecutionTime
166
156
  }
167
157
  });
package/lib/OverlayFS.js CHANGED
@@ -252,10 +252,10 @@ class OverlayFS {
252
252
  readFileSync(filePath, encoding) {
253
253
  filePath = this.realpathSync(filePath);
254
254
  try {
255
- // @ts-expect-error TS2345
255
+ // $FlowFixMe[incompatible-call]
256
256
  return this.writable.readFileSync(filePath, encoding);
257
257
  } catch (err) {
258
- // @ts-expect-error TS2345
258
+ // $FlowFixMe[incompatible-call]
259
259
  return this.readable.readFileSync(filePath, encoding);
260
260
  }
261
261
  }
@@ -304,7 +304,6 @@ class OverlayFS {
304
304
  // Read from both filesystems and merge the results
305
305
  let entries = new Map();
306
306
  try {
307
- // @ts-expect-error TS2769
308
307
  for (let entry of this.writable.readdirSync(dir, opts)) {
309
308
  let filePath = _path().default.join(dir, entry.name ?? entry);
310
309
  if (this.deleted.has(filePath)) continue;
@@ -314,7 +313,6 @@ class OverlayFS {
314
313
  // noop
315
314
  }
316
315
  try {
317
- // @ts-expect-error TS2769
318
316
  for (let entry of this.readable.readdirSync(dir, opts)) {
319
317
  let filePath = _path().default.join(dir, entry.name ?? entry);
320
318
  if (this.deleted.has(filePath)) continue;
package/lib/types.d.ts ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/fs",
3
- "version": "2.15.16-typescript-bc4459c37.0",
3
+ "version": "2.15.16",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -10,9 +10,9 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/atlassian-labs/atlaspack.git"
12
12
  },
13
- "main": "./lib/index.js",
14
- "source": "./src/index.ts",
15
- "types": "./lib/index.d.ts",
13
+ "main": "lib/index.js",
14
+ "source": "src/index.js",
15
+ "types": "index.d.ts",
16
16
  "engines": {
17
17
  "node": ">= 16.0.0"
18
18
  },
@@ -48,18 +48,19 @@
48
48
  }
49
49
  },
50
50
  "scripts": {
51
- "check-ts": "tsc --emitDeclarationOnly --rootDir src"
51
+ "build-ts": "mkdir -p lib && flow-to-ts src/types.js > lib/types.d.ts",
52
+ "check-ts": "tsc --noEmit index.d.ts"
52
53
  },
53
54
  "dependencies": {
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",
55
+ "@atlaspack/build-cache": "2.13.3",
56
+ "@atlaspack/feature-flags": "2.20.0",
57
+ "@atlaspack/logger": "2.14.13",
58
+ "@atlaspack/rust": "3.4.1",
59
+ "@atlaspack/types-internal": "2.16.0",
60
+ "@atlaspack/utils": "2.17.3",
62
61
  "@parcel/watcher": "^2.0.7",
62
+ "@atlaspack/workers": "2.14.21",
63
+ "@atlaspack/watcher-watchman-js": "2.14.21",
63
64
  "graceful-fs": "^4.2.4",
64
65
  "ncp": "^2.0.0",
65
66
  "nullthrows": "^1.1.1",
@@ -69,6 +70,5 @@
69
70
  "@atlaspack/fs": "./lib/browser.js",
70
71
  "./src/NodeFS.js": "./src/NodeFS.browser.js"
71
72
  },
72
- "type": "commonjs",
73
- "gitHead": "bc4459c37a38ef1f74772126637e1d8841d1fcb0"
74
- }
73
+ "type": "commonjs"
74
+ }
@@ -1,3 +1,5 @@
1
+ // @flow
2
+
1
3
  import type {
2
4
  FilePath,
3
5
  FileSystem,
@@ -26,21 +28,22 @@ let id = 0;
26
28
 
27
29
  type HandleFunction = (...args: Array<any>) => any;
28
30
  type SerializedMemoryFS = {
29
- id: number;
30
- handle: any;
31
- dirs: Map<FilePath, Directory>;
32
- files: Map<FilePath, File>;
33
- symlinks: Map<FilePath, FilePath>;
31
+ id: number,
32
+ handle: any,
33
+ dirs: Map<FilePath, Directory>,
34
+ files: Map<FilePath, File>,
35
+ symlinks: Map<FilePath, FilePath>,
36
+ ...
34
37
  };
35
38
 
36
- type WorkerEvent = {
37
- type: 'writeFile' | 'unlink' | 'mkdir' | 'symlink';
38
- path: FilePath;
39
- entry?: Entry;
40
- target?: FilePath;
41
- };
39
+ type WorkerEvent = {|
40
+ type: 'writeFile' | 'unlink' | 'mkdir' | 'symlink',
41
+ path: FilePath,
42
+ entry?: Entry,
43
+ target?: FilePath,
44
+ |};
42
45
 
43
- type ResolveFunction = () => unknown;
46
+ type ResolveFunction = () => mixed;
44
47
 
45
48
  export class MemoryFS implements FileSystem {
46
49
  dirs: Map<FilePath, Directory>;
@@ -49,13 +52,11 @@ export class MemoryFS implements FileSystem {
49
52
  watchers: Map<FilePath, Set<Watcher>>;
50
53
  events: Array<Event>;
51
54
  id: number;
52
- // @ts-expect-error TS2564
53
55
  handle: Handle;
54
56
  farm: WorkerFarm;
55
57
  _cwd: FilePath;
56
58
  _eventQueue: Array<Event>;
57
- // @ts-expect-error TS2564
58
- _watcherTimer: number;
59
+ _watcherTimer: TimeoutID;
59
60
  _numWorkerInstances: number = 0;
60
61
  _workerHandles: Array<Handle>;
61
62
  _workerRegisterResolves: Array<ResolveFunction> = [];
@@ -102,8 +103,8 @@ export class MemoryFS implements FileSystem {
102
103
  serialize(): SerializedMemoryFS {
103
104
  if (!this.handle) {
104
105
  this.handle = this.farm.createReverseHandle(
105
- (fn: string, args: Array<unknown>) => {
106
- // @ts-expect-error TS7053
106
+ (fn: string, args: Array<mixed>) => {
107
+ // $FlowFixMe
107
108
  return this[fn](...args);
108
109
  },
109
110
  );
@@ -113,7 +114,6 @@ export class MemoryFS implements FileSystem {
113
114
  this._numWorkerInstances++;
114
115
 
115
116
  return {
116
- // @ts-expect-error TS2353
117
117
  $$raw: false,
118
118
  id: this.id,
119
119
  handle: this.handle,
@@ -166,7 +166,7 @@ export class MemoryFS implements FileSystem {
166
166
  async writeFile(
167
167
  filePath: FilePath,
168
168
  contents: Buffer | string,
169
- options?: FileOptions | null,
169
+ options?: ?FileOptions,
170
170
  ) {
171
171
  filePath = this._normalizePath(filePath);
172
172
  if (this.dirs.has(filePath)) {
@@ -256,7 +256,7 @@ export class MemoryFS implements FileSystem {
256
256
  dir += path.sep;
257
257
  }
258
258
 
259
- let res: Array<Dirent | any | string> = [];
259
+ let res = [];
260
260
  for (let [filePath, entry] of this.dirs) {
261
261
  if (filePath === dir) {
262
262
  continue;
@@ -496,10 +496,7 @@ export class MemoryFS implements FileSystem {
496
496
  return new ReadStream(this, filePath);
497
497
  }
498
498
 
499
- createWriteStream(
500
- filePath: FilePath,
501
- options?: FileOptions | null,
502
- ): WriteStream {
499
+ createWriteStream(filePath: FilePath, options: ?FileOptions): WriteStream {
503
500
  this.mkdirp(path.dirname(filePath));
504
501
  return new WriteStream(this, filePath, options);
505
502
  }
@@ -544,7 +541,6 @@ export class MemoryFS implements FileSystem {
544
541
  this._eventQueue.push(event);
545
542
  clearTimeout(this._watcherTimer);
546
543
 
547
- // @ts-expect-error TS2322
548
544
  this._watcherTimer = setTimeout(() => {
549
545
  let events = this._eventQueue;
550
546
  this._eventQueue = [];
@@ -576,10 +572,8 @@ export class MemoryFS implements FileSystem {
576
572
  async _sendWorkerEvent(event: WorkerEvent) {
577
573
  // Wait for worker instances to register their handles
578
574
  while (this._workerHandles.length < this._numWorkerInstances) {
579
- await new Promise(
580
- (resolve: (result: Promise<undefined> | undefined) => void) =>
581
- // @ts-expect-error TS2345
582
- this._workerRegisterResolves.push(resolve),
575
+ await new Promise((resolve) =>
576
+ this._workerRegisterResolves.push(resolve),
583
577
  );
584
578
  }
585
579
 
@@ -592,7 +586,7 @@ export class MemoryFS implements FileSystem {
592
586
 
593
587
  watch(
594
588
  dir: FilePath,
595
- fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
589
+ fn: (err: ?Error, events: Array<Event>) => mixed,
596
590
  opts: WatcherOptions,
597
591
  ): Promise<AsyncSubscription> {
598
592
  dir = this._normalizePath(dir);
@@ -646,28 +640,25 @@ export class MemoryFS implements FileSystem {
646
640
  fileNames: Array<string>,
647
641
  fromDir: FilePath,
648
642
  root: FilePath,
649
- ): FilePath | null | undefined {
643
+ ): ?FilePath {
650
644
  return findAncestorFile(this, fileNames, fromDir, root);
651
645
  }
652
646
 
653
- findNodeModule(
654
- moduleName: string,
655
- fromDir: FilePath,
656
- ): FilePath | null | undefined {
647
+ findNodeModule(moduleName: string, fromDir: FilePath): ?FilePath {
657
648
  return findNodeModule(this, moduleName, fromDir);
658
649
  }
659
650
 
660
- findFirstFile(filePaths: Array<FilePath>): FilePath | null | undefined {
651
+ findFirstFile(filePaths: Array<FilePath>): ?FilePath {
661
652
  return findFirstFile(this, filePaths);
662
653
  }
663
654
  }
664
655
 
665
656
  class Watcher {
666
- fn: (err: Error | null | undefined, events: Array<Event>) => unknown;
657
+ fn: (err: ?Error, events: Array<Event>) => mixed;
667
658
  options: WatcherOptions;
668
659
 
669
660
  constructor(
670
- fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
661
+ fn: (err: ?Error, events: Array<Event>) => mixed,
671
662
  options: WatcherOptions,
672
663
  ) {
673
664
  this.fn = fn;
@@ -735,14 +726,10 @@ class ReadStream extends Readable {
735
726
  class WriteStream extends Writable {
736
727
  fs: FileSystem;
737
728
  filePath: FilePath;
738
- options: FileOptions | null | undefined;
729
+ options: ?FileOptions;
739
730
  buffer: Buffer;
740
731
 
741
- constructor(
742
- fs: FileSystem,
743
- filePath: FilePath,
744
- options?: FileOptions | null,
745
- ) {
732
+ constructor(fs: FileSystem, filePath: FilePath, options: ?FileOptions) {
746
733
  super({emitClose: true, autoDestroy: true});
747
734
  this.fs = fs;
748
735
  this.filePath = filePath;
@@ -763,7 +750,6 @@ class WriteStream extends Writable {
763
750
  _final(callback: (error?: Error) => void) {
764
751
  this.fs
765
752
  .writeFile(this.filePath, this.buffer, this.options)
766
- // @ts-expect-error TS2345
767
753
  .then(callback)
768
754
  .catch(callback);
769
755
  }
@@ -949,7 +935,7 @@ export function makeShared(contents: Buffer | string): Buffer {
949
935
  }
950
936
 
951
937
  let contentsBuffer: Buffer | string = contents;
952
- // @ts-expect-error TS2339
938
+ // $FlowFixMe
953
939
  if (process.browser) {
954
940
  // For the polyfilled buffer module, it's faster to always convert once so that the subsequent
955
941
  // operations are fast (.byteLength and using .set instead of .write)
@@ -979,10 +965,10 @@ class WorkerFS extends MemoryFS {
979
965
 
980
966
  constructor(id: number, handle: Handle) {
981
967
  // TODO Make this not a subclass
982
- // @ts-expect-error TS2554
968
+ // $FlowFixMe
983
969
  super();
984
970
  this.id = id;
985
- this.handleFn = (methodName: any, args: any) =>
971
+ this.handleFn = (methodName, args) =>
986
972
  WorkerFarm.getWorkerApi().runHandle(handle, [methodName, args]);
987
973
 
988
974
  this.handleFn('_registerWorker', [
@@ -1012,7 +998,7 @@ class WorkerFS extends MemoryFS {
1012
998
  }
1013
999
 
1014
1000
  serialize(): SerializedMemoryFS {
1015
- // @ts-expect-error TS2739
1001
+ // $FlowFixMe
1016
1002
  return {
1017
1003
  id: this.id,
1018
1004
  };
@@ -1021,7 +1007,7 @@ class WorkerFS extends MemoryFS {
1021
1007
  writeFile(
1022
1008
  filePath: FilePath,
1023
1009
  contents: Buffer | string,
1024
- options?: FileOptions | null,
1010
+ options: ?FileOptions,
1025
1011
  ): Promise<void> {
1026
1012
  super.writeFile(filePath, contents, options);
1027
1013
  let buffer = makeShared(contents);
@@ -1,6 +1,7 @@
1
+ // @flow
1
2
  import type {FileSystem} from '@atlaspack/types-internal';
2
3
 
3
- // @ts-expect-error TS2420
4
+ // $FlowFixMe[prop-missing] handled by the throwing constructor
4
5
  export class NodeFS implements FileSystem {
5
6
  constructor() {
6
7
  throw new Error("NodeFS isn't available in the browser");