@atlaspack/fs 2.15.16 → 2.15.17-typescript-5ad950d33.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.
@@ -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/index.d.ts DELETED
@@ -1,34 +0,0 @@
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/types.d.ts DELETED
File without changes