@atlaspack/utils 2.17.2 → 2.17.3-typescript-08dcc1c9b.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.
Files changed (70) hide show
  1. package/LICENSE +201 -0
  2. package/lib/DefaultMap.js +0 -4
  3. package/lib/config.js +3 -1
  4. package/lib/debug-tools.js +1 -0
  5. package/lib/generateCertificate.js +2 -0
  6. package/lib/glob.js +14 -4
  7. package/lib/index.js +164 -9
  8. package/lib/is-url.js +2 -0
  9. package/lib/objectHash.js +0 -1
  10. package/lib/prettyDiagnostic.js +3 -5
  11. package/lib/schema.js +38 -19
  12. package/lib/shared-buffer.js +1 -1
  13. package/lib/urlJoin.js +1 -1
  14. package/package.json +18 -13
  15. package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
  16. package/src/Deferred.ts +26 -0
  17. package/src/{PromiseQueue.js → PromiseQueue.ts} +41 -36
  18. package/src/{TapStream.js → TapStream.ts} +8 -7
  19. package/src/{alternatives.js → alternatives.ts} +14 -15
  20. package/src/{ansi-html.js → ansi-html.ts} +0 -1
  21. package/src/{blob.js → blob.ts} +2 -4
  22. package/src/{bundle-url.js → bundle-url.ts} +3 -5
  23. package/src/{collection.js → collection.ts} +14 -21
  24. package/src/{config.js → config.ts} +18 -19
  25. package/src/{countLines.js → countLines.ts} +0 -2
  26. package/src/{debounce.js → debounce.ts} +3 -5
  27. package/src/{debug-tools.js → debug-tools.ts} +6 -8
  28. package/src/{dependency-location.js → dependency-location.ts} +15 -11
  29. package/src/{escape-html.js → escape-html.ts} +5 -3
  30. package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +16 -18
  31. package/src/{generateCertificate.js → generateCertificate.ts} +8 -5
  32. package/src/{getCertificate.js → getCertificate.ts} +5 -3
  33. package/src/{getExisting.js → getExisting.ts} +4 -3
  34. package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
  35. package/src/{getRootDir.js → getRootDir.ts} +0 -2
  36. package/src/{glob.js → glob.ts} +16 -11
  37. package/src/{hash.js → hash.ts} +22 -17
  38. package/src/{http-server.js → http-server.ts} +32 -38
  39. package/src/{index.js → index.ts} +7 -8
  40. package/src/{is-url.js → is-url.ts} +1 -2
  41. package/src/{isDirectoryInside.js → isDirectoryInside.ts} +0 -1
  42. package/src/{objectHash.js → objectHash.ts} +1 -4
  43. package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
  44. package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
  45. package/src/{path.js → path.ts} +1 -3
  46. package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
  47. package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +22 -20
  48. package/src/{progress-message.js → progress-message.ts} +3 -2
  49. package/src/{relativeBundlePath.js → relativeBundlePath.ts} +3 -3
  50. package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
  51. package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +54 -36
  52. package/src/{schema.js → schema.ts} +158 -141
  53. package/src/{shared-buffer.js → shared-buffer.ts} +6 -4
  54. package/src/{sourcemap.js → sourcemap.ts} +16 -6
  55. package/src/{stream.js → stream.ts} +29 -21
  56. package/src/throttle.ts +13 -0
  57. package/src/{urlJoin.js → urlJoin.ts} +1 -3
  58. package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
  59. package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
  60. package/test/{collection.test.js → collection.test.ts} +0 -2
  61. package/test/{config.test.js → config.test.ts} +0 -3
  62. package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
  63. package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
  64. package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
  65. package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
  66. package/test/{throttle.test.js → throttle.test.ts} +1 -3
  67. package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
  68. package/tsconfig.json +4 -0
  69. package/src/Deferred.js +0 -23
  70. package/src/throttle.js +0 -15
@@ -1,20 +1,16 @@
1
- // @flow strict-local
2
-
3
1
  export function unique<T>(array: Array<T>): Array<T> {
4
2
  return [...new Set(array)];
5
3
  }
6
4
 
7
5
  export function objectSortedEntries(obj: {
8
- +[string]: mixed,
9
- ...
10
- }): Array<[string, mixed]> {
6
+ readonly [key: string]: unknown;
7
+ }): Array<[string, unknown]> {
11
8
  return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
12
9
  }
13
10
 
14
11
  export function objectSortedEntriesDeep(object: {
15
- +[string]: mixed,
16
- ...
17
- }): Array<[string, mixed]> {
12
+ readonly [key: string]: unknown;
13
+ }): Array<[string, unknown]> {
18
14
  let sortedEntries = objectSortedEntries(object);
19
15
  for (let i = 0; i < sortedEntries.length; i++) {
20
16
  sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
@@ -22,13 +18,13 @@ export function objectSortedEntriesDeep(object: {
22
18
  return sortedEntries;
23
19
  }
24
20
 
25
- function sortEntry(entry: mixed) {
21
+ function sortEntry(entry: unknown): unknown {
26
22
  if (Array.isArray(entry)) {
27
23
  return entry.map(sortEntry);
28
24
  }
29
25
 
30
26
  if (typeof entry === 'object' && entry != null) {
31
- return objectSortedEntriesDeep(entry);
27
+ return objectSortedEntriesDeep(entry as {readonly [key: string]: unknown});
32
28
  }
33
29
 
34
30
  return entry;
@@ -44,11 +40,8 @@ function sortEntry(entry: mixed) {
44
40
  * @param {*} b Set B
45
41
  * @returns A \ B
46
42
  */
47
- export function setDifference<T>(
48
- a: $ReadOnlySet<T>,
49
- b: $ReadOnlySet<T>,
50
- ): Set<T> {
51
- let difference = new Set();
43
+ export function setDifference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T> {
44
+ let difference = new Set<T>();
52
45
  for (let e of a) {
53
46
  if (!b.has(e)) {
54
47
  difference.add(e);
@@ -69,10 +62,10 @@ export function setDifference<T>(
69
62
  * @returns A Δ B
70
63
  */
71
64
  export function setSymmetricDifference<T>(
72
- a: $ReadOnlySet<T>,
73
- b: $ReadOnlySet<T>,
65
+ a: ReadonlySet<T>,
66
+ b: ReadonlySet<T>,
74
67
  ): Set<T> {
75
- let difference = new Set();
68
+ let difference = new Set<T>();
76
69
  for (let e of a) {
77
70
  if (!b.has(e)) {
78
71
  difference.add(e);
@@ -86,7 +79,7 @@ export function setSymmetricDifference<T>(
86
79
  return difference;
87
80
  }
88
81
 
89
- export function setIntersect<T>(a: Set<T>, b: $ReadOnlySet<T>): void {
82
+ export function setIntersect<T>(a: Set<T>, b: ReadonlySet<T>): void {
90
83
  for (let entry of a) {
91
84
  if (!b.has(entry)) {
92
85
  a.delete(entry);
@@ -95,7 +88,7 @@ export function setIntersect<T>(a: Set<T>, b: $ReadOnlySet<T>): void {
95
88
  }
96
89
 
97
90
  export function setIntersectStatic<T>(a: Set<T>, b: Set<T>): Set<T> {
98
- let intersection = new Set();
91
+ let intersection = new Set<T>();
99
92
  for (let entry of a) {
100
93
  if (b.has(entry)) {
101
94
  intersection.add(entry);
@@ -108,7 +101,7 @@ export function setUnion<T>(a: Iterable<T>, b: Iterable<T>): Set<T> {
108
101
  return new Set([...a, ...b]);
109
102
  }
110
103
 
111
- export function setEqual<T>(a: $ReadOnlySet<T>, b: $ReadOnlySet<T>): boolean {
104
+ export function setEqual<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean {
112
105
  if (a.size != b.size) {
113
106
  return false;
114
107
  }
@@ -1,24 +1,24 @@
1
- // @flow
2
-
3
1
  import type {ConfigResult, File, FilePath} from '@atlaspack/types';
4
2
  import type {FileSystem} from '@atlaspack/fs';
5
3
  import ThrowableDiagnostic from '@atlaspack/diagnostic';
6
4
  import path from 'path';
5
+ // @ts-expect-error TS7016
7
6
  import clone from 'clone';
8
7
  import json5 from 'json5';
9
8
  import {parse as toml} from '@iarna/toml';
10
9
  import LRU from 'lru-cache';
11
10
 
12
- export type ConfigOutput = {|
13
- config: ConfigResult,
14
- files: Array<File>,
15
- |};
11
+ export type ConfigOutput = {
12
+ config: ConfigResult;
13
+ files: Array<File>;
14
+ };
16
15
 
17
- export type ConfigOptions = {|
18
- parse?: boolean,
19
- parser?: (string) => any,
20
- |};
16
+ export type ConfigOptions = {
17
+ parse?: boolean;
18
+ parser?: (arg1: string) => any;
19
+ };
21
20
 
21
+ // @ts-expect-error TS2351
22
22
  const configCache = new LRU<FilePath, ConfigOutput>({max: 500});
23
23
  const resolveCache = new Map();
24
24
 
@@ -27,7 +27,7 @@ export function resolveConfig(
27
27
  filepath: FilePath,
28
28
  filenames: Array<FilePath>,
29
29
  projectRoot: FilePath,
30
- ): Promise<?FilePath> {
30
+ ): Promise<FilePath | null | undefined> {
31
31
  // Cache the result of resolving config for this directory.
32
32
  // This is automatically invalidated at the end of the current build.
33
33
  let key = path.dirname(filepath) + filenames.join(',');
@@ -50,7 +50,7 @@ export function resolveConfigSync(
50
50
  filepath: FilePath,
51
51
  filenames: Array<FilePath>,
52
52
  projectRoot: FilePath,
53
- ): ?FilePath {
53
+ ): FilePath | null | undefined {
54
54
  return fs.findAncestorFile(filenames, path.dirname(filepath), projectRoot);
55
55
  }
56
56
 
@@ -59,7 +59,7 @@ export async function loadConfig(
59
59
  filepath: FilePath,
60
60
  filenames: Array<FilePath>,
61
61
  projectRoot: FilePath,
62
- opts: ?ConfigOptions,
62
+ opts?: ConfigOptions | null,
63
63
  ): Promise<ConfigOutput | null> {
64
64
  let parse = opts?.parse ?? true;
65
65
  let configFile = await resolveConfig(fs, filepath, filenames, projectRoot);
@@ -73,7 +73,6 @@ export async function loadConfig(
73
73
  let extname = path.extname(configFile).slice(1);
74
74
  if (extname === 'js' || extname === 'cjs') {
75
75
  let output = {
76
- // $FlowFixMe
77
76
  config: clone(module.require(configFile)),
78
77
  files: [{filePath: configFile}],
79
78
  };
@@ -83,7 +82,7 @@ export async function loadConfig(
83
82
  }
84
83
 
85
84
  return readConfig(fs, configFile, opts);
86
- } catch (err) {
85
+ } catch (err: any) {
87
86
  if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
88
87
  return null;
89
88
  }
@@ -103,7 +102,7 @@ loadConfig.clear = () => {
103
102
  export async function readConfig(
104
103
  fs: FileSystem,
105
104
  configFile: FilePath,
106
- opts: ?ConfigOptions,
105
+ opts?: ConfigOptions | null,
107
106
  ): Promise<ConfigOutput | null> {
108
107
  let parse = opts?.parse ?? true;
109
108
  let cachedOutput = configCache.get(String(parse) + configFile);
@@ -121,7 +120,7 @@ export async function readConfig(
121
120
  let parse = opts?.parser ?? getParser(extname);
122
121
  try {
123
122
  config = parse(configContent);
124
- } catch (e) {
123
+ } catch (e: any) {
125
124
  if (extname !== '' && extname !== 'json') {
126
125
  throw e;
127
126
  }
@@ -161,7 +160,7 @@ export async function readConfig(
161
160
 
162
161
  configCache.set(String(parse) + configFile, output);
163
162
  return output;
164
- } catch (err) {
163
+ } catch (err: any) {
165
164
  if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
166
165
  return null;
167
166
  }
@@ -170,7 +169,7 @@ export async function readConfig(
170
169
  }
171
170
  }
172
171
 
173
- function getParser(extname) {
172
+ function getParser(extname: string) {
174
173
  switch (extname) {
175
174
  case 'toml':
176
175
  return toml;
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  export default function countLines(
4
2
  string: string,
5
3
  startIndex: number = 0,
@@ -1,10 +1,8 @@
1
- // @flow strict-local
2
-
3
- export default function debounce<TArgs: Array<mixed>>(
4
- fn: (...args: TArgs) => mixed,
1
+ export default function debounce<TArgs extends Array<unknown>>(
2
+ fn: (...args: TArgs) => unknown,
5
3
  delay: number,
6
4
  ): (...args: TArgs) => void {
7
- let timeout;
5
+ let timeout: NodeJS.Timeout | undefined | null;
8
6
 
9
7
  return function (...args: TArgs) {
10
8
  if (timeout) {
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  /*
4
2
  * These tools are intended for Atlaspack developers, to provide extra utilities
5
3
  * to make debugging Atlaspack issues more straightforward.
@@ -11,10 +9,10 @@
11
9
  * You can enable all tools by setting `ATLASPACK_DEBUG_TOOLS=all`.
12
10
  */
13
11
 
14
- type DebugTools = {|
15
- 'asset-file-names-in-output': boolean,
16
- 'simple-cli-reporter': boolean,
17
- |};
12
+ type DebugTools = {
13
+ ['asset-file-names-in-output']: boolean;
14
+ ['simple-cli-reporter']: boolean;
15
+ };
18
16
 
19
17
  export let debugTools: DebugTools = {
20
18
  'asset-file-names-in-output': false,
@@ -28,11 +26,11 @@ for (let tool of envVarValue.split(',')) {
28
26
 
29
27
  if (tool === 'all') {
30
28
  for (let key in debugTools) {
31
- debugTools[key] = true;
29
+ debugTools[key as keyof DebugTools] = true;
32
30
  }
33
31
  break;
34
32
  } else if (debugTools.hasOwnProperty(tool)) {
35
- debugTools[tool] = true;
33
+ debugTools[tool as keyof DebugTools] = true;
36
34
  } else if (tool === '') {
37
35
  continue;
38
36
  } else {
@@ -1,20 +1,24 @@
1
- // @flow
2
-
3
1
  export default function createDependencyLocation(
4
- start: {|
5
- line: number,
6
- column: number,
7
- |},
2
+ start: {
3
+ line: number;
4
+ column: number;
5
+ },
8
6
  specifier: string,
9
7
  lineOffset: number = 0,
10
8
  columnOffset: number = 0,
11
9
  // Imports are usually wrapped in quotes
12
10
  importWrapperLength: number = 2,
13
- ): {|
14
- end: {|column: number, line: number|},
15
- filePath: string,
16
- start: {|column: number, line: number|},
17
- |} {
11
+ ): {
12
+ end: {
13
+ column: number;
14
+ line: number;
15
+ };
16
+ filePath: string;
17
+ start: {
18
+ column: number;
19
+ line: number;
20
+ };
21
+ } {
18
22
  return {
19
23
  filePath: specifier,
20
24
  start: {
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  // Based on _.escape https://github.com/lodash/lodash/blob/master/escape.js
3
2
  const reUnescapedHtml = /[&<>"']/g;
4
3
  const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
@@ -9,11 +8,14 @@ const htmlEscapes = {
9
8
  '>': '&gt;',
10
9
  '"': '&quot;',
11
10
  "'": '&#39;',
12
- };
11
+ } as const;
13
12
 
14
13
  export function escapeHTML(s: string): string {
15
14
  if (reHasUnescapedHtml.test(s)) {
16
- return s.replace(reUnescapedHtml, (c) => htmlEscapes[c]);
15
+ return s.replace(
16
+ reUnescapedHtml,
17
+ (c) => htmlEscapes[c as keyof typeof htmlEscapes],
18
+ );
17
19
  }
18
20
 
19
21
  return s;
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import type {FilePath, PackagedBundle} from '@atlaspack/types';
4
2
  import type {FileSystem} from '@atlaspack/fs';
5
3
  import SourceMap from '@parcel/source-map';
@@ -7,29 +5,29 @@ import nullthrows from 'nullthrows';
7
5
  import path from 'path';
8
6
  import {loadSourceMapUrl} from './';
9
7
 
10
- export type AssetStats = {|
11
- filePath: string,
12
- size: number,
13
- originalSize: number,
14
- time: number,
15
- |};
8
+ export type AssetStats = {
9
+ filePath: string;
10
+ size: number;
11
+ originalSize: number;
12
+ time: number;
13
+ };
16
14
 
17
- export type BundleStats = {|
18
- filePath: string,
19
- size: number,
20
- time: number,
21
- assets: Array<AssetStats>,
22
- |};
15
+ export type BundleStats = {
16
+ filePath: string;
17
+ size: number;
18
+ time: number;
19
+ assets: Array<AssetStats>;
20
+ };
23
21
 
24
- export type BuildMetrics = {|
25
- bundles: Array<BundleStats>,
26
- |};
22
+ export type BuildMetrics = {
23
+ bundles: Array<BundleStats>;
24
+ };
27
25
 
28
26
  async function getSourcemapSizes(
29
27
  filePath: FilePath,
30
28
  fs: FileSystem,
31
29
  projectRoot: FilePath,
32
- ): Promise<?Map<string, number>> {
30
+ ): Promise<Map<string, number> | null | undefined> {
33
31
  let bundleContents = await fs.readFile(filePath, 'utf-8');
34
32
  let mapUrlData = await loadSourceMapUrl(fs, filePath, bundleContents);
35
33
  if (!mapUrlData) {
@@ -1,5 +1,5 @@
1
- // @flow
2
1
  import type {FileSystem} from '@atlaspack/fs';
2
+ // @ts-expect-error TS7016
3
3
  import forge from 'node-forge';
4
4
  import path from 'path';
5
5
  import logger from '@atlaspack/logger';
@@ -7,8 +7,11 @@ import logger from '@atlaspack/logger';
7
7
  export default async function generateCertificate(
8
8
  fs: FileSystem,
9
9
  cacheDir: string,
10
- host: ?string,
11
- ): Promise<{|cert: Buffer, key: Buffer|}> {
10
+ host?: string | null,
11
+ ): Promise<{
12
+ cert: Buffer;
13
+ key: Buffer;
14
+ }> {
12
15
  let certDirectory = cacheDir;
13
16
 
14
17
  const privateKeyPath = path.join(certDirectory, 'private.pem');
@@ -134,7 +137,7 @@ export default async function generateCertificate(
134
137
  await fs.writeFile(certPath, certPem);
135
138
 
136
139
  return {
137
- key: privPem,
138
- cert: certPem,
140
+ key: privPem as unknown as Buffer,
141
+ cert: certPem as unknown as Buffer,
139
142
  };
140
143
  }
@@ -1,17 +1,19 @@
1
- // @flow
2
1
  import type {HTTPSOptions} from '@atlaspack/types';
3
2
  import type {FileSystem} from '@atlaspack/fs';
4
3
 
5
4
  export default async function getCertificate(
6
5
  fs: FileSystem,
7
6
  options: HTTPSOptions,
8
- ): Promise<{|cert: Buffer, key: Buffer|}> {
7
+ ): Promise<{
8
+ cert: Buffer;
9
+ key: Buffer;
10
+ }> {
9
11
  try {
10
12
  let cert = await fs.readFile(options.cert);
11
13
  let key = await fs.readFile(options.key);
12
14
 
13
15
  return {key, cert};
14
- } catch (err) {
16
+ } catch (err: any) {
15
17
  throw new Error('Certificate and/or key not found');
16
18
  }
17
19
  }
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import fs from 'fs';
4
2
 
5
3
  /**
@@ -9,7 +7,10 @@ import fs from 'fs';
9
7
  export default function getExisting(
10
8
  minifiedPath: string,
11
9
  sourcePath: string,
12
- ): {|minified: string, source: string|} {
10
+ ): {
11
+ minified: string;
12
+ source: string;
13
+ } {
13
14
  let source = fs.readFileSync(sourcePath, 'utf8').trim();
14
15
  return {
15
16
  source,
@@ -1,4 +1,3 @@
1
- // @flow strict-local
2
1
  import path from 'path';
3
2
 
4
3
  import {normalizeSeparators} from './path';
@@ -6,7 +5,9 @@ import {normalizeSeparators} from './path';
6
5
  /**
7
6
  * Returns the package name and the optional subpath
8
7
  */
9
- export default function getModuleParts(_name: string): [string, ?string] {
8
+ export default function getModuleParts(
9
+ _name: string,
10
+ ): [string, string | null | undefined] {
10
11
  let name = path.normalize(_name);
11
12
  let splitOn = name.indexOf(path.sep);
12
13
  if (name.charAt(0) === '@') {
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import type {FilePath} from '@atlaspack/types';
4
2
  import {isGlob} from './glob';
5
3
  import path from 'path';
@@ -1,11 +1,12 @@
1
- // @flow
2
-
3
1
  import type {FilePath, Glob} from '@atlaspack/types';
4
2
  import type {FileSystem} from '@atlaspack/fs';
5
3
 
4
+ // @ts-expect-error TS7016
6
5
  import _isGlob from 'is-glob';
7
- import fastGlob, {type FastGlobOptions} from 'fast-glob';
8
- import micromatch, {isMatch, makeRe, type Options} from 'micromatch';
6
+ // @ts-expect-error TS2305
7
+ import fastGlob, {FastGlobOptions} from 'fast-glob';
8
+ // @ts-expect-error TS7016
9
+ import micromatch, {isMatch, makeRe, Options} from 'micromatch';
9
10
  import {normalizeSeparators} from './path';
10
11
 
11
12
  export function isGlob(p: FilePath): any {
@@ -44,25 +45,27 @@ export function globSync(
44
45
  fs: FileSystem,
45
46
  options?: FastGlobOptions<FilePath>,
46
47
  ): Array<FilePath> {
47
- // $FlowFixMe
48
48
  options = {
49
49
  ...options,
50
50
  fs: {
51
+ // @ts-expect-error TS7006
51
52
  statSync: (p) => {
52
53
  return fs.statSync(p);
53
54
  },
55
+ // @ts-expect-error TS7006
54
56
  lstatSync: (p) => {
55
57
  // Our FileSystem interface doesn't have lstat support at the moment,
56
58
  // but this is fine for our purposes since we follow symlinks by default.
57
59
  return fs.statSync(p);
58
60
  },
61
+ // @ts-expect-error TS7006
59
62
  readdirSync: (p, opts) => {
60
63
  return fs.readdirSync(p, opts);
61
64
  },
62
65
  },
63
66
  };
64
67
 
65
- // $FlowFixMe
68
+ // @ts-expect-error TS2322
66
69
  return fastGlob.sync(normalizeSeparators(p), options);
67
70
  }
68
71
 
@@ -71,26 +74,28 @@ export function glob(
71
74
  fs: FileSystem,
72
75
  options: FastGlobOptions<FilePath>,
73
76
  ): Promise<Array<FilePath>> {
74
- // $FlowFixMe
75
77
  options = {
76
78
  ...options,
77
79
  fs: {
80
+ // @ts-expect-error TS7006
78
81
  stat: async (p, cb) => {
79
82
  try {
80
83
  cb(null, await fs.stat(p));
81
- } catch (err) {
84
+ } catch (err: any) {
82
85
  cb(err);
83
86
  }
84
87
  },
88
+ // @ts-expect-error TS7006
85
89
  lstat: async (p, cb) => {
86
90
  // Our FileSystem interface doesn't have lstat support at the moment,
87
91
  // but this is fine for our purposes since we follow symlinks by default.
88
92
  try {
89
93
  cb(null, await fs.stat(p));
90
- } catch (err) {
94
+ } catch (err: any) {
91
95
  cb(err);
92
96
  }
93
97
  },
98
+ // @ts-expect-error TS7006
94
99
  readdir: async (p, opts, cb) => {
95
100
  if (typeof opts === 'function') {
96
101
  cb = opts;
@@ -99,13 +104,13 @@ export function glob(
99
104
 
100
105
  try {
101
106
  cb(null, await fs.readdir(p, opts));
102
- } catch (err) {
107
+ } catch (err: any) {
103
108
  cb(err);
104
109
  }
105
110
  },
106
111
  },
107
112
  };
108
113
 
109
- // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
114
+ // @ts-expect-error TS2322
110
115
  return fastGlob(normalizeSeparators(p), options);
111
116
  }
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import type {Readable} from 'stream';
4
2
  import type {FileSystem} from '@atlaspack/fs';
5
3
 
@@ -8,28 +6,35 @@ import {hashString, Hash} from '@atlaspack/rust';
8
6
 
9
7
  export function hashStream(stream: Readable): Promise<string> {
10
8
  let hash = new Hash();
11
- return new Promise((resolve, reject) => {
12
- stream.on('error', (err) => {
13
- reject(err);
14
- });
15
- stream
16
- .on('data', (chunk) => {
17
- hash.writeBuffer(chunk);
18
- })
19
- .on('end', function () {
20
- resolve(hash.finish());
21
- })
22
- .on('error', (err) => {
9
+ return new Promise(
10
+ (
11
+ resolve: (result: Promise<string> | string) => void,
12
+ reject: (error?: any) => void,
13
+ ) => {
14
+ stream.on('error', (err) => {
23
15
  reject(err);
24
16
  });
25
- });
17
+ stream
18
+ .on('data', (chunk) => {
19
+ hash.writeBuffer(chunk);
20
+ })
21
+ .on('end', function () {
22
+ resolve(hash.finish());
23
+ })
24
+ .on('error', (err) => {
25
+ reject(err);
26
+ });
27
+ },
28
+ );
26
29
  }
27
30
 
28
- export function hashObject(obj: {+[string]: mixed, ...}): string {
31
+ export function hashObject(obj: {readonly [key: string]: unknown}): string {
29
32
  return hashString(JSON.stringify(objectSortedEntriesDeep(obj)));
30
33
  }
31
34
 
32
- let testCache: {|[string]: Promise<string>|} = {
35
+ let testCache: {
36
+ [key: string]: Promise<string>;
37
+ } = {
33
38
  /*:: ...null */
34
39
  };
35
40
  export function hashFile(fs: FileSystem, filePath: string): Promise<string> {