@atlaspack/fs 2.15.15 → 2.15.16-typescript-80839fbd5.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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2024 Atlassian US., Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
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 = _interopRequireWildcard(require("@atlaspack/workers"));
38
+ const data = _interopRequireDefault(require("@atlaspack/workers"));
39
39
  _workers = function () {
40
40
  return data;
41
41
  };
@@ -56,12 +56,14 @@ 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; }
61
59
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
62
60
  const instances = new Map();
63
61
  let id = 0;
64
62
  class MemoryFS {
63
+ // @ts-expect-error TS2564
64
+
65
+ // @ts-expect-error TS2564
66
+
65
67
  _numWorkerInstances = 0;
66
68
  _workerRegisterResolves = [];
67
69
  _emitter = new (_events().default)();
@@ -100,7 +102,7 @@ class MemoryFS {
100
102
  serialize() {
101
103
  if (!this.handle) {
102
104
  this.handle = this.farm.createReverseHandle((fn, args) => {
103
- // $FlowFixMe
105
+ // @ts-expect-error TS7053
104
106
  return this[fn](...args);
105
107
  });
106
108
  }
@@ -108,6 +110,7 @@ class MemoryFS {
108
110
  // If a worker instance already exists, it will decrement this number
109
111
  this._numWorkerInstances++;
110
112
  return {
113
+ // @ts-expect-error TS2353
111
114
  $$raw: false,
112
115
  id: this.id,
113
116
  handle: this.handle,
@@ -471,6 +474,8 @@ class MemoryFS {
471
474
  // Batch events
472
475
  this._eventQueue.push(event);
473
476
  clearTimeout(this._watcherTimer);
477
+
478
+ // @ts-expect-error TS2322
474
479
  this._watcherTimer = setTimeout(() => {
475
480
  let events = this._eventQueue;
476
481
  this._eventQueue = [];
@@ -496,7 +501,9 @@ class MemoryFS {
496
501
  async _sendWorkerEvent(event) {
497
502
  // Wait for worker instances to register their handles
498
503
  while (this._workerHandles.length < this._numWorkerInstances) {
499
- await new Promise(resolve => this._workerRegisterResolves.push(resolve));
504
+ await new Promise(resolve =>
505
+ // @ts-expect-error TS2345
506
+ this._workerRegisterResolves.push(resolve));
500
507
  }
501
508
  await Promise.all(this._workerHandles.map(workerHandle => this.farm.workerApi.runHandle(workerHandle, [event])));
502
509
  }
@@ -610,7 +617,9 @@ class WriteStream extends _stream().Writable {
610
617
  callback();
611
618
  }
612
619
  _final(callback) {
613
- this.fs.writeFile(this.filePath, this.buffer, this.options).then(callback).catch(callback);
620
+ this.fs.writeFile(this.filePath, this.buffer, this.options)
621
+ // @ts-expect-error TS2345
622
+ .then(callback).catch(callback);
614
623
  }
615
624
  }
616
625
  const S_IFREG = 0o100000;
@@ -743,7 +752,7 @@ function makeShared(contents) {
743
752
  return contents;
744
753
  }
745
754
  let contentsBuffer = contents;
746
- // $FlowFixMe
755
+ // @ts-expect-error TS2339
747
756
  if (process.browser) {
748
757
  // For the polyfilled buffer module, it's faster to always convert once so that the subsequent
749
758
  // operations are fast (.byteLength and using .set instead of .write)
@@ -764,7 +773,7 @@ function makeShared(contents) {
764
773
  class WorkerFS extends MemoryFS {
765
774
  constructor(id, handle) {
766
775
  // TODO Make this not a subclass
767
- // $FlowFixMe
776
+ // @ts-expect-error TS2554
768
777
  super();
769
778
  this.id = id;
770
779
  this.handleFn = (methodName, args) => _workers().default.getWorkerApi().runHandle(handle, [methodName, args]);
@@ -791,7 +800,7 @@ class WorkerFS extends MemoryFS {
791
800
  return (0, _nullthrows().default)(instances.get(opts.id));
792
801
  }
793
802
  serialize() {
794
- // $FlowFixMe
803
+ // @ts-expect-error TS2739
795
804
  return {
796
805
  id: this.id
797
806
  };
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.NodeFS = void 0;
7
- // $FlowFixMe[prop-missing] handled by the throwing constructor
7
+ // @ts-expect-error TS2420
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,6 +86,10 @@ 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
+
89
93
  // Most of this can go away once we only support Node 10+, which includes
90
94
  // require('fs').promises
91
95
  const realpath = (0, _util().promisify)(process.platform === 'win32' ? _gracefulFs().default.realpath : _gracefulFs().default.realpath.native);
@@ -93,8 +97,6 @@ const isPnP = process.versions.pnp != null;
93
97
  function getWatchmanWatcher() {
94
98
  // This is here to trick atlaspack into ignoring this require...
95
99
  const packageName = ['@atlaspack', 'watcher-watchman-js'].join('/');
96
-
97
- // $FlowFixMe
98
100
  return require(packageName);
99
101
  }
100
102
  class NodeFS {
@@ -113,9 +115,15 @@ class NodeFS {
113
115
  realpathSync = process.platform === 'win32' ? _gracefulFs().default.realpathSync : _gracefulFs().default.realpathSync.native;
114
116
  existsSync = _gracefulFs().default.existsSync;
115
117
  readdirSync = _gracefulFs().default.readdirSync;
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;
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;
119
127
  watcher() {
120
128
  return (0, _featureFlags().getFeatureFlag)('useWatchmanWatcher') ? getWatchmanWatcher() : _watcher().default;
121
129
  }
@@ -144,7 +152,9 @@ class NodeFS {
144
152
  ...options,
145
153
  fs: {
146
154
  ..._gracefulFs().default,
155
+ // @ts-expect-error TS7006
147
156
  close: (fd, cb) => {
157
+ // @ts-expect-error TS7006
148
158
  _gracefulFs().default.close(fd, err => {
149
159
  if (err) {
150
160
  cb(err);
@@ -227,7 +237,6 @@ class NodeFS {
227
237
  return;
228
238
  }
229
239
  if (stat.isDirectory()) {
230
- // $FlowFixMe
231
240
  await _fs().default.promises.rmdir(filePath, {
232
241
  recursive: true
233
242
  });
@@ -239,6 +248,8 @@ class NodeFS {
239
248
  exports.NodeFS = NodeFS;
240
249
  (0, _buildCache().registerSerializableClass)(`${_package.default.version}:NodeFS`, NodeFS);
241
250
  let writeStreamCalls = 0;
251
+
252
+ // @ts-expect-error TS7034
242
253
  let threadId;
243
254
  try {
244
255
  ({
@@ -247,9 +258,13 @@ try {
247
258
  } catch {
248
259
  //
249
260
  }
261
+
262
+ // @ts-expect-error TS7034
250
263
  let useOsTmpDir;
251
264
  function shouldUseOsTmpDir(filePath) {
265
+ // @ts-expect-error TS7005
252
266
  if (useOsTmpDir != null) {
267
+ // @ts-expect-error TS7005
253
268
  return useOsTmpDir;
254
269
  }
255
270
  try {
@@ -277,5 +292,7 @@ function getTempFilePath(filePath) {
277
292
  if (shouldUseOsTmpDir(filePath)) {
278
293
  tmpFilePath = _path().default.join((0, _os().tmpdir)(), _path().default.basename(filePath));
279
294
  }
280
- return tmpFilePath + '.' + process.pid + (threadId != null ? '.' + threadId : '') + '.' + (writeStreamCalls++).toString(36);
295
+ return tmpFilePath + '.' + process.pid + (
296
+ // @ts-expect-error TS7005
297
+ threadId != null ? '.' + threadId : '') + '.' + (writeStreamCalls++).toString(36);
281
298
  }
@@ -44,7 +44,6 @@ 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
48
47
  class NodeVCSAwareFS extends _NodeFS.NodeFS {
49
48
  /**
50
49
  * These files are excluded from 'dirty file' tracking even if they are
@@ -66,8 +65,6 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
66
65
  this.#logEventDiff = options.logEventDiff;
67
66
  this.#gitRepoPath = options.gitRepoPath;
68
67
  }
69
-
70
- // $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
71
68
  static deserialize(data) {
72
69
  const fs = new NodeVCSAwareFS({
73
70
  excludePatterns: data.excludePatterns,
@@ -77,7 +74,7 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
77
74
  return fs;
78
75
  }
79
76
 
80
- // $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
77
+ // @ts-expect-error TS2416
81
78
  serialize() {
82
79
  return {
83
80
  excludePatterns: this.#excludePatterns,
@@ -103,7 +100,14 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
103
100
  return JSON.parse(snapshotFileContent);
104
101
  });
105
102
  let watcherEventsSince = [];
106
- const vcsEventsSince = vcsState != null ? (await (0, _logger().instrumentAsync)('NodeVCSAwareFS::rust.getEventsSince', () => (0, _rust().getEventsSince)(gitRepoPath, vcsState, null))).map(e => ({
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 => ({
107
111
  path: e.path,
108
112
  type: e.changeType
109
113
  })) : null;
@@ -112,6 +116,8 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
112
116
  watcherEventsSince = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::watchman.getEventsSince', () => this.watcher().getEventsSince(dir, nativeSnapshotPath, opts));
113
117
  (_this$logEventDiff = this.#logEventDiff) === null || _this$logEventDiff === void 0 || _this$logEventDiff.call(this, watcherEventsSince, vcsEventsSince);
114
118
  }
119
+
120
+ // @ts-expect-error TS2345
115
121
  if (['NEW_AND_CHECK', 'NEW'].includes((0, _featureFlags().getFeatureFlagValue)('vcsMode'))) {
116
122
  if (vcsEventsSince == null) {
117
123
  _logger().default.error({
@@ -145,13 +151,17 @@ class NodeVCSAwareFS extends _NodeFS.NodeFS {
145
151
  let vcsState = null;
146
152
  try {
147
153
  var _vcsState, _vcsState2;
148
- vcsState = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::getVcsStateSnapshot', () => (0, _rust().getVcsStateSnapshot)(gitRepoPath, this.#excludePatterns));
154
+ vcsState = await (0, _logger().instrumentAsync)('NodeVCSAwareFS::getVcsStateSnapshot',
155
+ // @ts-expect-error TS2322
156
+ () => (0, _rust().getVcsStateSnapshot)(gitRepoPath, this.#excludePatterns));
149
157
  _logger().default.verbose({
150
158
  origin: '@atlaspack/fs',
151
159
  message: 'Expose VCS timing metrics',
152
160
  meta: {
153
161
  trackableEvent: 'vcs_timing_metrics',
162
+ // @ts-expect-error TS2339
154
163
  dirtyFilesExecutionTime: (_vcsState = vcsState) === null || _vcsState === void 0 ? void 0 : _vcsState.dirtyFilesExecutionTime,
164
+ // @ts-expect-error TS2339
155
165
  yarnStatesExecutionTime: (_vcsState2 = vcsState) === null || _vcsState2 === void 0 ? void 0 : _vcsState2.yarnStatesExecutionTime
156
166
  }
157
167
  });
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
- // $FlowFixMe[incompatible-call]
255
+ // @ts-expect-error TS2345
256
256
  return this.writable.readFileSync(filePath, encoding);
257
257
  } catch (err) {
258
- // $FlowFixMe[incompatible-call]
258
+ // @ts-expect-error TS2345
259
259
  return this.readable.readFileSync(filePath, encoding);
260
260
  }
261
261
  }
@@ -304,6 +304,7 @@ 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
307
308
  for (let entry of this.writable.readdirSync(dir, opts)) {
308
309
  let filePath = _path().default.join(dir, entry.name ?? entry);
309
310
  if (this.deleted.has(filePath)) continue;
@@ -313,6 +314,7 @@ class OverlayFS {
313
314
  // noop
314
315
  }
315
316
  try {
317
+ // @ts-expect-error TS2769
316
318
  for (let entry of this.readable.readdirSync(dir, opts)) {
317
319
  let filePath = _path().default.join(dir, entry.name ?? entry);
318
320
  if (this.deleted.has(filePath)) continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/fs",
3
- "version": "2.15.15",
3
+ "version": "2.15.16-typescript-80839fbd5.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -11,8 +11,8 @@
11
11
  "url": "https://github.com/atlassian-labs/atlaspack.git"
12
12
  },
13
13
  "main": "lib/index.js",
14
- "source": "src/index.js",
15
- "types": "index.d.ts",
14
+ "source": "src/index.ts",
15
+ "types": "src/index.ts",
16
16
  "engines": {
17
17
  "node": ">= 16.0.0"
18
18
  },
@@ -48,19 +48,18 @@
48
48
  }
49
49
  },
50
50
  "scripts": {
51
- "build-ts": "mkdir -p lib && flow-to-ts src/types.js > lib/types.d.ts",
52
- "check-ts": "tsc --noEmit index.d.ts"
51
+ "check-ts": "tsc --noEmit"
53
52
  },
54
53
  "dependencies": {
55
- "@atlaspack/build-cache": "2.13.3",
56
- "@atlaspack/feature-flags": "2.19.2",
57
- "@atlaspack/logger": "2.14.13",
58
- "@atlaspack/rust": "3.4.1",
59
- "@atlaspack/types-internal": "2.15.2",
60
- "@atlaspack/utils": "2.17.2",
54
+ "@atlaspack/build-cache": "2.13.4-typescript-80839fbd5.0",
55
+ "@atlaspack/feature-flags": "2.19.3-typescript-80839fbd5.0",
56
+ "@atlaspack/logger": "2.14.14-typescript-80839fbd5.0",
57
+ "@atlaspack/rust": "3.4.2-typescript-80839fbd5.0",
58
+ "@atlaspack/types-internal": "2.15.3-typescript-80839fbd5.0",
59
+ "@atlaspack/utils": "2.17.3-typescript-80839fbd5.0",
60
+ "@atlaspack/watcher-watchman-js": "2.14.21-typescript-80839fbd5.0",
61
+ "@atlaspack/workers": "2.14.21-typescript-80839fbd5.0",
61
62
  "@parcel/watcher": "^2.0.7",
62
- "@atlaspack/workers": "2.14.20",
63
- "@atlaspack/watcher-watchman-js": "2.14.20",
64
63
  "graceful-fs": "^4.2.4",
65
64
  "ncp": "^2.0.0",
66
65
  "nullthrows": "^1.1.1",
@@ -70,5 +69,6 @@
70
69
  "@atlaspack/fs": "./lib/browser.js",
71
70
  "./src/NodeFS.js": "./src/NodeFS.browser.js"
72
71
  },
73
- "type": "commonjs"
72
+ "type": "commonjs",
73
+ "gitHead": "80839fbd5c6d6668c2622849856a4b25601354a8"
74
74
  }
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import type {
4
2
  FilePath,
5
3
  FileSystem,
@@ -28,22 +26,21 @@ let id = 0;
28
26
 
29
27
  type HandleFunction = (...args: Array<any>) => any;
30
28
  type SerializedMemoryFS = {
31
- id: number,
32
- handle: any,
33
- dirs: Map<FilePath, Directory>,
34
- files: Map<FilePath, File>,
35
- symlinks: Map<FilePath, FilePath>,
36
- ...
29
+ id: number;
30
+ handle: any;
31
+ dirs: Map<FilePath, Directory>;
32
+ files: Map<FilePath, File>;
33
+ symlinks: Map<FilePath, FilePath>;
37
34
  };
38
35
 
39
- type WorkerEvent = {|
40
- type: 'writeFile' | 'unlink' | 'mkdir' | 'symlink',
41
- path: FilePath,
42
- entry?: Entry,
43
- target?: FilePath,
44
- |};
36
+ type WorkerEvent = {
37
+ type: 'writeFile' | 'unlink' | 'mkdir' | 'symlink';
38
+ path: FilePath;
39
+ entry?: Entry;
40
+ target?: FilePath;
41
+ };
45
42
 
46
- type ResolveFunction = () => mixed;
43
+ type ResolveFunction = () => unknown;
47
44
 
48
45
  export class MemoryFS implements FileSystem {
49
46
  dirs: Map<FilePath, Directory>;
@@ -52,11 +49,13 @@ export class MemoryFS implements FileSystem {
52
49
  watchers: Map<FilePath, Set<Watcher>>;
53
50
  events: Array<Event>;
54
51
  id: number;
52
+ // @ts-expect-error TS2564
55
53
  handle: Handle;
56
54
  farm: WorkerFarm;
57
55
  _cwd: FilePath;
58
56
  _eventQueue: Array<Event>;
59
- _watcherTimer: TimeoutID;
57
+ // @ts-expect-error TS2564
58
+ _watcherTimer: number;
60
59
  _numWorkerInstances: number = 0;
61
60
  _workerHandles: Array<Handle>;
62
61
  _workerRegisterResolves: Array<ResolveFunction> = [];
@@ -103,8 +102,8 @@ export class MemoryFS implements FileSystem {
103
102
  serialize(): SerializedMemoryFS {
104
103
  if (!this.handle) {
105
104
  this.handle = this.farm.createReverseHandle(
106
- (fn: string, args: Array<mixed>) => {
107
- // $FlowFixMe
105
+ (fn: string, args: Array<unknown>) => {
106
+ // @ts-expect-error TS7053
108
107
  return this[fn](...args);
109
108
  },
110
109
  );
@@ -114,6 +113,7 @@ export class MemoryFS implements FileSystem {
114
113
  this._numWorkerInstances++;
115
114
 
116
115
  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,
169
+ options?: FileOptions | null,
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 = [];
259
+ let res: Array<Dirent | any | string> = [];
260
260
  for (let [filePath, entry] of this.dirs) {
261
261
  if (filePath === dir) {
262
262
  continue;
@@ -496,7 +496,10 @@ export class MemoryFS implements FileSystem {
496
496
  return new ReadStream(this, filePath);
497
497
  }
498
498
 
499
- createWriteStream(filePath: FilePath, options: ?FileOptions): WriteStream {
499
+ createWriteStream(
500
+ filePath: FilePath,
501
+ options?: FileOptions | null,
502
+ ): WriteStream {
500
503
  this.mkdirp(path.dirname(filePath));
501
504
  return new WriteStream(this, filePath, options);
502
505
  }
@@ -541,6 +544,7 @@ export class MemoryFS implements FileSystem {
541
544
  this._eventQueue.push(event);
542
545
  clearTimeout(this._watcherTimer);
543
546
 
547
+ // @ts-expect-error TS2322
544
548
  this._watcherTimer = setTimeout(() => {
545
549
  let events = this._eventQueue;
546
550
  this._eventQueue = [];
@@ -572,8 +576,10 @@ export class MemoryFS implements FileSystem {
572
576
  async _sendWorkerEvent(event: WorkerEvent) {
573
577
  // Wait for worker instances to register their handles
574
578
  while (this._workerHandles.length < this._numWorkerInstances) {
575
- await new Promise((resolve) =>
576
- this._workerRegisterResolves.push(resolve),
579
+ await new Promise(
580
+ (resolve: (result: Promise<undefined> | undefined) => void) =>
581
+ // @ts-expect-error TS2345
582
+ this._workerRegisterResolves.push(resolve),
577
583
  );
578
584
  }
579
585
 
@@ -586,7 +592,7 @@ export class MemoryFS implements FileSystem {
586
592
 
587
593
  watch(
588
594
  dir: FilePath,
589
- fn: (err: ?Error, events: Array<Event>) => mixed,
595
+ fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
590
596
  opts: WatcherOptions,
591
597
  ): Promise<AsyncSubscription> {
592
598
  dir = this._normalizePath(dir);
@@ -640,25 +646,28 @@ export class MemoryFS implements FileSystem {
640
646
  fileNames: Array<string>,
641
647
  fromDir: FilePath,
642
648
  root: FilePath,
643
- ): ?FilePath {
649
+ ): FilePath | null | undefined {
644
650
  return findAncestorFile(this, fileNames, fromDir, root);
645
651
  }
646
652
 
647
- findNodeModule(moduleName: string, fromDir: FilePath): ?FilePath {
653
+ findNodeModule(
654
+ moduleName: string,
655
+ fromDir: FilePath,
656
+ ): FilePath | null | undefined {
648
657
  return findNodeModule(this, moduleName, fromDir);
649
658
  }
650
659
 
651
- findFirstFile(filePaths: Array<FilePath>): ?FilePath {
660
+ findFirstFile(filePaths: Array<FilePath>): FilePath | null | undefined {
652
661
  return findFirstFile(this, filePaths);
653
662
  }
654
663
  }
655
664
 
656
665
  class Watcher {
657
- fn: (err: ?Error, events: Array<Event>) => mixed;
666
+ fn: (err: Error | null | undefined, events: Array<Event>) => unknown;
658
667
  options: WatcherOptions;
659
668
 
660
669
  constructor(
661
- fn: (err: ?Error, events: Array<Event>) => mixed,
670
+ fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
662
671
  options: WatcherOptions,
663
672
  ) {
664
673
  this.fn = fn;
@@ -726,10 +735,14 @@ class ReadStream extends Readable {
726
735
  class WriteStream extends Writable {
727
736
  fs: FileSystem;
728
737
  filePath: FilePath;
729
- options: ?FileOptions;
738
+ options: FileOptions | null | undefined;
730
739
  buffer: Buffer;
731
740
 
732
- constructor(fs: FileSystem, filePath: FilePath, options: ?FileOptions) {
741
+ constructor(
742
+ fs: FileSystem,
743
+ filePath: FilePath,
744
+ options?: FileOptions | null,
745
+ ) {
733
746
  super({emitClose: true, autoDestroy: true});
734
747
  this.fs = fs;
735
748
  this.filePath = filePath;
@@ -750,6 +763,7 @@ class WriteStream extends Writable {
750
763
  _final(callback: (error?: Error) => void) {
751
764
  this.fs
752
765
  .writeFile(this.filePath, this.buffer, this.options)
766
+ // @ts-expect-error TS2345
753
767
  .then(callback)
754
768
  .catch(callback);
755
769
  }
@@ -935,7 +949,7 @@ export function makeShared(contents: Buffer | string): Buffer {
935
949
  }
936
950
 
937
951
  let contentsBuffer: Buffer | string = contents;
938
- // $FlowFixMe
952
+ // @ts-expect-error TS2339
939
953
  if (process.browser) {
940
954
  // For the polyfilled buffer module, it's faster to always convert once so that the subsequent
941
955
  // operations are fast (.byteLength and using .set instead of .write)
@@ -965,10 +979,10 @@ class WorkerFS extends MemoryFS {
965
979
 
966
980
  constructor(id: number, handle: Handle) {
967
981
  // TODO Make this not a subclass
968
- // $FlowFixMe
982
+ // @ts-expect-error TS2554
969
983
  super();
970
984
  this.id = id;
971
- this.handleFn = (methodName, args) =>
985
+ this.handleFn = (methodName: any, args: any) =>
972
986
  WorkerFarm.getWorkerApi().runHandle(handle, [methodName, args]);
973
987
 
974
988
  this.handleFn('_registerWorker', [
@@ -998,7 +1012,7 @@ class WorkerFS extends MemoryFS {
998
1012
  }
999
1013
 
1000
1014
  serialize(): SerializedMemoryFS {
1001
- // $FlowFixMe
1015
+ // @ts-expect-error TS2739
1002
1016
  return {
1003
1017
  id: this.id,
1004
1018
  };
@@ -1007,7 +1021,7 @@ class WorkerFS extends MemoryFS {
1007
1021
  writeFile(
1008
1022
  filePath: FilePath,
1009
1023
  contents: Buffer | string,
1010
- options: ?FileOptions,
1024
+ options?: FileOptions | null,
1011
1025
  ): Promise<void> {
1012
1026
  super.writeFile(filePath, contents, options);
1013
1027
  let buffer = makeShared(contents);
@@ -1,7 +1,6 @@
1
- // @flow
2
1
  import type {FileSystem} from '@atlaspack/types-internal';
3
2
 
4
- // $FlowFixMe[prop-missing] handled by the throwing constructor
3
+ // @ts-expect-error TS2420
5
4
  export class NodeFS implements FileSystem {
6
5
  constructor() {
7
6
  throw new Error("NodeFS isn't available in the browser");
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {ReadStream, Stats} from 'fs';
3
2
  import type {Writable} from 'stream';
4
3
  import type {
@@ -13,8 +12,10 @@ import type {
13
12
  AsyncSubscription,
14
13
  } from '@parcel/watcher';
15
14
 
15
+ // @ts-expect-error TS7016
16
16
  import fs from 'graceful-fs';
17
17
  import nativeFS from 'fs';
18
+ // @ts-expect-error TS7016
18
19
  import ncp from 'ncp';
19
20
  import path from 'path';
20
21
  import {tmpdir} from 'os';
@@ -40,7 +41,6 @@ function getWatchmanWatcher(): typeof watcher {
40
41
  // This is here to trick atlaspack into ignoring this require...
41
42
  const packageName = ['@atlaspack', 'watcher-watchman-js'].join('/');
42
43
 
43
- // $FlowFixMe
44
44
  return require(packageName);
45
45
  }
46
46
 
@@ -62,15 +62,18 @@ export class NodeFS implements FileSystem {
62
62
  realpathSync: (path: string, cache?: any) => string =
63
63
  process.platform === 'win32' ? fs.realpathSync : fs.realpathSync.native;
64
64
  existsSync: (path: string) => boolean = fs.existsSync;
65
- readdirSync: any = (fs.readdirSync: any);
65
+ readdirSync: any = fs.readdirSync as any;
66
66
  findAncestorFile: any = isPnP
67
- ? (...args) => searchJS.findAncestorFile(this, ...args)
67
+ ? // @ts-expect-error TS7019
68
+ (...args) => searchJS.findAncestorFile(this, ...args)
68
69
  : searchNative.findAncestorFile;
69
70
  findNodeModule: any = isPnP
70
- ? (...args) => searchJS.findNodeModule(this, ...args)
71
+ ? // @ts-expect-error TS7019
72
+ (...args) => searchJS.findNodeModule(this, ...args)
71
73
  : searchNative.findNodeModule;
72
74
  findFirstFile: any = isPnP
73
- ? (...args) => searchJS.findFirstFile(this, ...args)
75
+ ? // @ts-expect-error TS7019
76
+ (...args) => searchJS.findFirstFile(this, ...args)
74
77
  : searchNative.findFirstFile;
75
78
 
76
79
  watcher(): typeof watcher {
@@ -88,7 +91,7 @@ export class NodeFS implements FileSystem {
88
91
  if (!failed) {
89
92
  try {
90
93
  await fs.promises.rename(tmpFilePath, filePath);
91
- } catch (e) {
94
+ } catch (e: any) {
92
95
  // This is adapted from fs-write-stream-atomic. Apparently
93
96
  // Windows doesn't like renaming when the target already exists.
94
97
  if (
@@ -117,7 +120,9 @@ export class NodeFS implements FileSystem {
117
120
  ...options,
118
121
  fs: {
119
122
  ...fs,
123
+ // @ts-expect-error TS7006
120
124
  close: (fd, cb) => {
125
+ // @ts-expect-error TS7006
121
126
  fs.close(fd, (err) => {
122
127
  if (err) {
123
128
  cb(err);
@@ -136,7 +141,7 @@ export class NodeFS implements FileSystem {
136
141
  failed = true;
137
142
  try {
138
143
  fs.unlinkSync(tmpFilePath);
139
- } catch (_err) {
144
+ } catch (_err: any) {
140
145
  // ignore
141
146
  }
142
147
  });
@@ -147,7 +152,7 @@ export class NodeFS implements FileSystem {
147
152
  async writeFile(
148
153
  filePath: FilePath,
149
154
  contents: Buffer | string,
150
- options: ?FileOptions,
155
+ options?: FileOptions | null,
151
156
  ): Promise<void> {
152
157
  let tmpFilePath = getTempFilePath(filePath);
153
158
  await fs.promises.writeFile(tmpFilePath, contents, options);
@@ -164,7 +169,7 @@ export class NodeFS implements FileSystem {
164
169
  async realpath(originalPath: string): Promise<string> {
165
170
  try {
166
171
  return await realpath(originalPath, 'utf8');
167
- } catch (e) {
172
+ } catch (e: any) {
168
173
  // do nothing
169
174
  }
170
175
 
@@ -172,14 +177,14 @@ export class NodeFS implements FileSystem {
172
177
  }
173
178
 
174
179
  exists(filePath: FilePath): Promise<boolean> {
175
- return new Promise((resolve) => {
180
+ return new Promise((resolve: (result: Promise<never>) => void) => {
176
181
  fs.exists(filePath, resolve);
177
182
  });
178
183
  }
179
184
 
180
185
  watch(
181
186
  dir: FilePath,
182
- fn: (err: ?Error, events: Array<Event>) => mixed,
187
+ fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
183
188
  opts: WatcherOptions,
184
189
  ): Promise<AsyncSubscription> {
185
190
  return this.watcher().subscribe(dir, fn, opts);
@@ -224,12 +229,11 @@ export class NodeFS implements FileSystem {
224
229
  let stat;
225
230
  try {
226
231
  stat = await this.stat(filePath);
227
- } catch (err) {
232
+ } catch (err: any) {
228
233
  return;
229
234
  }
230
235
 
231
236
  if (stat.isDirectory()) {
232
- // $FlowFixMe
233
237
  await nativeFS.promises.rmdir(filePath, {recursive: true});
234
238
  } else {
235
239
  await nativeFS.promises.unlink(filePath);
@@ -241,6 +245,7 @@ registerSerializableClass(`${packageJSON.version}:NodeFS`, NodeFS);
241
245
 
242
246
  let writeStreamCalls = 0;
243
247
 
248
+ // @ts-expect-error TS7034
244
249
  let threadId;
245
250
  try {
246
251
  ({threadId} = require('worker_threads'));
@@ -248,10 +253,13 @@ try {
248
253
  //
249
254
  }
250
255
 
256
+ // @ts-expect-error TS7034
251
257
  let useOsTmpDir;
252
258
 
253
- function shouldUseOsTmpDir(filePath) {
259
+ function shouldUseOsTmpDir(filePath: FilePath) {
260
+ // @ts-expect-error TS7005
254
261
  if (useOsTmpDir != null) {
262
+ // @ts-expect-error TS7005
255
263
  return useOsTmpDir;
256
264
  }
257
265
  try {
@@ -265,7 +273,7 @@ function shouldUseOsTmpDir(filePath) {
265
273
  // Check the tmpdir is on the same partition as the target directory.
266
274
  // This is required to ensure renaming is an atomic operation.
267
275
  useOsTmpDir = tmpDirStats.dev === filePathStats.dev;
268
- } catch (e) {
276
+ } catch (e: any) {
269
277
  // We don't have read/write access to the OS tmp directory
270
278
  useOsTmpDir = false;
271
279
  }
@@ -288,6 +296,7 @@ function getTempFilePath(filePath: FilePath) {
288
296
  tmpFilePath +
289
297
  '.' +
290
298
  process.pid +
299
+ // @ts-expect-error TS7005
291
300
  (threadId != null ? '.' + threadId : '') +
292
301
  '.' +
293
302
  (writeStreamCalls++).toString(36)
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import path from 'path';
4
2
  import {NodeFS} from './NodeFS';
5
3
  import {getVcsStateSnapshot, getEventsSince} from '@atlaspack/rust';
@@ -9,7 +7,6 @@ import {registerSerializableClass} from '@atlaspack/build-cache';
9
7
  import logger, {instrumentAsync} from '@atlaspack/logger';
10
8
  import {getFeatureFlagValue} from '@atlaspack/feature-flags';
11
9
 
12
- // $FlowFixMe
13
10
  import packageJSON from '../package.json';
14
11
 
15
12
  export interface NodeVCSAwareFSOptions {
@@ -43,7 +40,6 @@ export class NodeVCSAwareFS extends NodeFS {
43
40
  this.#gitRepoPath = options.gitRepoPath;
44
41
  }
45
42
 
46
- // $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
47
43
  static deserialize(data: SerializedNodeVCSAwareFS): NodeVCSAwareFS {
48
44
  const fs = new NodeVCSAwareFS({
49
45
  excludePatterns: data.excludePatterns,
@@ -53,7 +49,7 @@ export class NodeVCSAwareFS extends NodeFS {
53
49
  return fs;
54
50
  }
55
51
 
56
- // $FlowFixMe[incompatible-extend] the serialization API is not happy with inheritance
52
+ // @ts-expect-error TS2416
57
53
  serialize(): SerializedNodeVCSAwareFS {
58
54
  return {
59
55
  excludePatterns: this.#excludePatterns,
@@ -85,18 +81,22 @@ export class NodeVCSAwareFS extends NodeFS {
85
81
  return JSON.parse(snapshotFileContent);
86
82
  },
87
83
  );
88
- let watcherEventsSince = [];
84
+ let watcherEventsSince: Array<Event> = [];
89
85
 
90
86
  const vcsEventsSince =
91
87
  vcsState != null
92
- ? (
88
+ ? // @ts-expect-error TS2571
89
+ (
93
90
  await instrumentAsync('NodeVCSAwareFS::rust.getEventsSince', () =>
91
+ // @ts-expect-error TS2739
94
92
  getEventsSince(gitRepoPath, vcsState, null),
95
93
  )
96
- ).map((e) => ({
97
- path: e.path,
98
- type: e.changeType,
99
- }))
94
+ )
95
+ // @ts-expect-error TS7006
96
+ .map((e) => ({
97
+ path: e.path,
98
+ type: e.changeType,
99
+ }))
100
100
  : null;
101
101
 
102
102
  if (getFeatureFlagValue('vcsMode') !== 'NEW' && vcsEventsSince != null) {
@@ -107,6 +107,7 @@ export class NodeVCSAwareFS extends NodeFS {
107
107
  this.#logEventDiff?.(watcherEventsSince, vcsEventsSince);
108
108
  }
109
109
 
110
+ // @ts-expect-error TS2345
110
111
  if (['NEW_AND_CHECK', 'NEW'].includes(getFeatureFlagValue('vcsMode'))) {
111
112
  if (vcsEventsSince == null) {
112
113
  logger.error({
@@ -159,6 +160,7 @@ export class NodeVCSAwareFS extends NodeFS {
159
160
  try {
160
161
  vcsState = await instrumentAsync(
161
162
  'NodeVCSAwareFS::getVcsStateSnapshot',
163
+ // @ts-expect-error TS2322
162
164
  () => getVcsStateSnapshot(gitRepoPath, this.#excludePatterns),
163
165
  );
164
166
 
@@ -167,11 +169,13 @@ export class NodeVCSAwareFS extends NodeFS {
167
169
  message: 'Expose VCS timing metrics',
168
170
  meta: {
169
171
  trackableEvent: 'vcs_timing_metrics',
172
+ // @ts-expect-error TS2339
170
173
  dirtyFilesExecutionTime: vcsState?.dirtyFilesExecutionTime,
174
+ // @ts-expect-error TS2339
171
175
  yarnStatesExecutionTime: vcsState?.yarnStatesExecutionTime,
172
176
  },
173
177
  });
174
- } catch (err) {
178
+ } catch (err: any) {
175
179
  logger.error({
176
180
  origin: '@atlaspack/fs',
177
181
  message: `Failed to get VCS state snapshot: ${err.message}`,
@@ -185,7 +189,7 @@ export class NodeVCSAwareFS extends NodeFS {
185
189
  const snapshotContents = {
186
190
  vcsState,
187
191
  nativeSnapshotPath,
188
- };
192
+ } as const;
189
193
  await this.writeFile(snapshot, JSON.stringify(snapshotContents));
190
194
  }
191
195
  }
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import type {Readable, Writable} from 'stream';
4
2
  import type {
5
3
  FilePath,
@@ -46,12 +44,12 @@ export class OverlayFS implements FileSystem {
46
44
  return fs;
47
45
  }
48
46
 
49
- serialize(): {|
50
- $$raw: boolean,
51
- readable: FileSystem,
52
- writable: FileSystem,
53
- deleted: Set<FilePath>,
54
- |} {
47
+ serialize(): {
48
+ $$raw: boolean;
49
+ readable: FileSystem;
50
+ writable: FileSystem;
51
+ deleted: Set<FilePath>;
52
+ } {
55
53
  return {
56
54
  $$raw: false,
57
55
  writable: this.writable,
@@ -108,7 +106,7 @@ export class OverlayFS implements FileSystem {
108
106
  }
109
107
  }
110
108
  }
111
- } catch (e) {
109
+ } catch (e: any) {
112
110
  if (e.code === 'ENOENT') {
113
111
  return false;
114
112
  }
@@ -141,7 +139,7 @@ export class OverlayFS implements FileSystem {
141
139
  async writeFile(
142
140
  filePath: FilePath,
143
141
  contents: string | Buffer,
144
- options: ?FileOptions,
142
+ options?: FileOptions | null,
145
143
  ): Promise<void> {
146
144
  filePath = await this._copyPathForWrite(filePath);
147
145
  await this.writable.writeFile(filePath, contents, options);
@@ -212,7 +210,7 @@ export class OverlayFS implements FileSystem {
212
210
 
213
211
  try {
214
212
  await this.writable.unlink(filePath);
215
- } catch (e) {
213
+ } catch (e: any) {
216
214
  if (e.code === 'ENOENT' && !this.readable.existsSync(filePath)) {
217
215
  throw e;
218
216
  }
@@ -239,7 +237,7 @@ export class OverlayFS implements FileSystem {
239
237
  async rimraf(filePath: FilePath): Promise<void> {
240
238
  try {
241
239
  await this.unlink(filePath);
242
- } catch (e) {
240
+ } catch (e: any) {
243
241
  // noop
244
242
  }
245
243
  }
@@ -250,7 +248,7 @@ export class OverlayFS implements FileSystem {
250
248
  return this.writable.ncp(source, destination);
251
249
  }
252
250
 
253
- createReadStream(filePath: FilePath, opts?: ?FileOptions): Readable {
251
+ createReadStream(filePath: FilePath, opts?: FileOptions | null): Readable {
254
252
  filePath = this._deletedThrows(filePath);
255
253
  if (this.writable.existsSync(filePath)) {
256
254
  return this.writable.createReadStream(filePath, opts);
@@ -259,7 +257,7 @@ export class OverlayFS implements FileSystem {
259
257
  return this.readable.createReadStream(filePath, opts);
260
258
  }
261
259
 
262
- createWriteStream(path: FilePath, opts?: ?FileOptions): Writable {
260
+ createWriteStream(path: FilePath, opts?: FileOptions | null): Writable {
263
261
  path = this._normalizePath(path);
264
262
  this.deleted.delete(path);
265
263
  return this.writable.createWriteStream(path, opts);
@@ -281,10 +279,10 @@ export class OverlayFS implements FileSystem {
281
279
  readFileSync(filePath: FilePath, encoding?: Encoding): any {
282
280
  filePath = this.realpathSync(filePath);
283
281
  try {
284
- // $FlowFixMe[incompatible-call]
282
+ // @ts-expect-error TS2345
285
283
  return this.writable.readFileSync(filePath, encoding);
286
- } catch (err) {
287
- // $FlowFixMe[incompatible-call]
284
+ } catch (err: any) {
285
+ // @ts-expect-error TS2345
288
286
  return this.readable.readFileSync(filePath, encoding);
289
287
  }
290
288
  }
@@ -293,7 +291,7 @@ export class OverlayFS implements FileSystem {
293
291
  filePath = this._normalizePath(filePath);
294
292
  try {
295
293
  return this.writable.statSync(filePath);
296
- } catch (e) {
294
+ } catch (e: any) {
297
295
  if (e.code === 'ENOENT' && this.existsSync(filePath)) {
298
296
  return this.readable.statSync(filePath);
299
297
  }
@@ -321,7 +319,7 @@ export class OverlayFS implements FileSystem {
321
319
 
322
320
  try {
323
321
  filePath = this.realpathSync(filePath);
324
- } catch (err) {
322
+ } catch (err: any) {
325
323
  if (err.code !== 'ENOENT') throw err;
326
324
  }
327
325
 
@@ -343,7 +341,8 @@ export class OverlayFS implements FileSystem {
343
341
  let entries = new Map();
344
342
 
345
343
  try {
346
- for (let entry: any of this.writable.readdirSync(dir, opts)) {
344
+ // @ts-expect-error TS2769
345
+ for (let entry of this.writable.readdirSync(dir, opts)) {
347
346
  let filePath = path.join(dir, entry.name ?? entry);
348
347
  if (this.deleted.has(filePath)) continue;
349
348
  entries.set(filePath, entry);
@@ -353,7 +352,8 @@ export class OverlayFS implements FileSystem {
353
352
  }
354
353
 
355
354
  try {
356
- for (let entry: any of this.readable.readdirSync(dir, opts)) {
355
+ // @ts-expect-error TS2769
356
+ for (let entry of this.readable.readdirSync(dir, opts)) {
357
357
  let filePath = path.join(dir, entry.name ?? entry);
358
358
  if (this.deleted.has(filePath)) continue;
359
359
  if (entries.has(filePath)) continue;
@@ -368,7 +368,7 @@ export class OverlayFS implements FileSystem {
368
368
 
369
369
  async watch(
370
370
  dir: FilePath,
371
- fn: (err: ?Error, events: Array<Event>) => mixed,
371
+ fn: (err: Error | null | undefined, events: Array<Event>) => unknown,
372
372
  opts: WatcherOptions,
373
373
  ): Promise<AsyncSubscription> {
374
374
  let writableSubscription = await this.writable.watch(dir, fn, opts);
@@ -411,15 +411,18 @@ export class OverlayFS implements FileSystem {
411
411
  fileNames: Array<string>,
412
412
  fromDir: FilePath,
413
413
  root: FilePath,
414
- ): ?FilePath {
414
+ ): FilePath | null | undefined {
415
415
  return findAncestorFile(this, fileNames, fromDir, root);
416
416
  }
417
417
 
418
- findNodeModule(moduleName: string, fromDir: FilePath): ?FilePath {
418
+ findNodeModule(
419
+ moduleName: string,
420
+ fromDir: FilePath,
421
+ ): FilePath | null | undefined {
419
422
  return findNodeModule(this, moduleName, fromDir);
420
423
  }
421
424
 
422
- findFirstFile(filePaths: Array<FilePath>): ?FilePath {
425
+ findFirstFile(filePaths: Array<FilePath>): FilePath | null | undefined {
423
426
  return findFirstFile(this, filePaths);
424
427
  }
425
428
  }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {FilePath, FileSystem} from '@atlaspack/types-internal';
3
2
  import path from 'path';
4
3
 
@@ -6,7 +5,7 @@ export function findNodeModule(
6
5
  fs: FileSystem,
7
6
  moduleName: string,
8
7
  dir: FilePath,
9
- ): ?FilePath {
8
+ ): FilePath | null | undefined {
10
9
  let {root} = path.parse(dir);
11
10
  while (dir !== root) {
12
11
  // Skip node_modules directories
@@ -20,7 +19,7 @@ export function findNodeModule(
20
19
  if (stats.isDirectory()) {
21
20
  return moduleDir;
22
21
  }
23
- } catch (err) {
22
+ } catch (err: any) {
24
23
  // ignore
25
24
  }
26
25
 
@@ -36,7 +35,7 @@ export function findAncestorFile(
36
35
  fileNames: Array<string>,
37
36
  dir: FilePath,
38
37
  root: FilePath,
39
- ): ?FilePath {
38
+ ): FilePath | null | undefined {
40
39
  let {root: pathRoot} = path.parse(dir);
41
40
  // eslint-disable-next-line no-constant-condition
42
41
  while (true) {
@@ -50,7 +49,7 @@ export function findAncestorFile(
50
49
  if (fs.statSync(filePath).isFile()) {
51
50
  return filePath;
52
51
  }
53
- } catch (err) {
52
+ } catch (err: any) {
54
53
  // ignore
55
54
  }
56
55
  }
@@ -68,13 +67,13 @@ export function findAncestorFile(
68
67
  export function findFirstFile(
69
68
  fs: FileSystem,
70
69
  filePaths: Array<FilePath>,
71
- ): ?FilePath {
70
+ ): FilePath | null | undefined {
72
71
  for (let filePath of filePaths) {
73
72
  try {
74
73
  if (fs.statSync(filePath).isFile()) {
75
74
  return filePath;
76
75
  }
77
- } catch (err) {
76
+ } catch (err: any) {
78
77
  // ignore
79
78
  }
80
79
  }
@@ -1,4 +1,3 @@
1
- // @flow strict-local
2
1
  import type {
3
2
  FilePath,
4
3
  FileSystem,
@@ -17,7 +16,7 @@ export * from './NodeVCSAwareFS';
17
16
 
18
17
  export type {FileSystem, FileOptions};
19
18
 
20
- const pipeline: (Readable, Writable) => Promise<void> = promisify(
19
+ const pipeline: (arg1: Readable, arg2: Writable) => Promise<void> = promisify(
21
20
  stream.pipeline,
22
21
  );
23
22
 
@@ -1,7 +1,5 @@
1
- // @flow
2
-
3
1
  import {OverlayFS} from '../src/OverlayFS';
4
- import {fsFixture} from '@atlaspack/test-utils/src/fsFixture';
2
+ import {fsFixture} from '@atlaspack/test-utils';
5
3
  import {MemoryFS} from '../src/MemoryFS';
6
4
  import WorkerFarm from '@atlaspack/workers';
7
5
  import {WORKER_PATH} from '@atlaspack/core';
@@ -10,9 +8,9 @@ import assert from 'assert';
10
8
  import path from 'path';
11
9
 
12
10
  describe('OverlayFS', () => {
13
- let underlayFS;
14
- let fs;
15
- let workerFarm;
11
+ let underlayFS: any;
12
+ let fs: any;
13
+ let workerFarm: any;
16
14
 
17
15
  beforeEach(() => {
18
16
  workerFarm = new WorkerFarm({
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }
package/lib/types.d.ts DELETED
File without changes