@atlaspack/utils 2.14.5-canary.36 → 2.14.5-canary.360

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 (197) hide show
  1. package/CHANGELOG.md +462 -0
  2. package/benchmark.js +23 -0
  3. package/dist/DefaultMap.js +41 -0
  4. package/dist/Deferred.js +16 -0
  5. package/dist/PromiseQueue.js +107 -0
  6. package/dist/TapStream.js +23 -0
  7. package/dist/alternatives.js +97 -0
  8. package/dist/ansi-html.js +12 -0
  9. package/dist/blob.js +29 -0
  10. package/dist/bundle-url.js +32 -0
  11. package/dist/collection.js +106 -0
  12. package/dist/config.js +138 -0
  13. package/dist/countLines.js +12 -0
  14. package/dist/debounce.js +15 -0
  15. package/dist/debug-tools.js +39 -0
  16. package/dist/dependency-location.js +22 -0
  17. package/dist/escape-html.js +19 -0
  18. package/dist/generateBuildMetrics.js +111 -0
  19. package/dist/generateCertificate.js +124 -0
  20. package/dist/getCertificate.js +13 -0
  21. package/dist/getExisting.js +20 -0
  22. package/dist/getModuleParts.js +27 -0
  23. package/dist/getRootDir.js +46 -0
  24. package/dist/getTimeId.js +13 -0
  25. package/dist/glob.js +129 -0
  26. package/dist/hash.js +45 -0
  27. package/dist/http-server.js +55 -0
  28. package/dist/index.js +148 -0
  29. package/dist/is-url.js +15 -0
  30. package/dist/isDirectoryInside.js +11 -0
  31. package/dist/objectHash.js +20 -0
  32. package/dist/openInBrowser.js +61 -0
  33. package/dist/parseCSSImport.js +14 -0
  34. package/dist/path.js +36 -0
  35. package/dist/prettifyTime.js +6 -0
  36. package/dist/prettyDiagnostic.js +108 -0
  37. package/dist/progress-message.js +31 -0
  38. package/dist/relativeBundlePath.js +13 -0
  39. package/dist/relativeUrl.js +11 -0
  40. package/dist/replaceBundleReferences.js +131 -0
  41. package/dist/schema.js +404 -0
  42. package/dist/shared-buffer.js +24 -0
  43. package/dist/sourcemap.js +121 -0
  44. package/dist/stream.js +69 -0
  45. package/dist/throttle.js +12 -0
  46. package/dist/urlJoin.js +22 -0
  47. package/lib/DefaultMap.js +42 -0
  48. package/lib/Deferred.js +30 -0
  49. package/lib/PromiseQueue.js +112 -0
  50. package/lib/TapStream.js +34 -0
  51. package/lib/alternatives.js +116 -0
  52. package/lib/ansi-html.js +20 -0
  53. package/lib/blob.js +40 -0
  54. package/lib/bundle-url.js +34 -0
  55. package/lib/collection.js +111 -0
  56. package/lib/config.js +174 -0
  57. package/lib/countLines.js +15 -0
  58. package/lib/debounce.js +18 -0
  59. package/lib/debug-tools.js +40 -0
  60. package/lib/dependency-location.js +21 -0
  61. package/lib/escape-html.js +22 -0
  62. package/lib/generateBuildMetrics.js +121 -0
  63. package/lib/generateCertificate.js +129 -0
  64. package/lib/getCertificate.js +18 -0
  65. package/lib/getExisting.js +25 -0
  66. package/lib/getModuleParts.js +30 -0
  67. package/lib/getRootDir.js +52 -0
  68. package/lib/getTimeId.js +10 -0
  69. package/lib/glob.js +110 -0
  70. package/lib/hash.js +50 -0
  71. package/lib/http-server.js +85 -0
  72. package/lib/index.js +643 -37310
  73. package/lib/is-url.js +24 -0
  74. package/lib/isDirectoryInside.js +18 -0
  75. package/lib/objectHash.js +26 -0
  76. package/lib/openInBrowser.js +74 -0
  77. package/lib/parseCSSImport.js +15 -0
  78. package/lib/path.js +39 -0
  79. package/lib/prettifyTime.js +9 -0
  80. package/lib/prettyDiagnostic.js +154 -0
  81. package/lib/progress-message.js +39 -0
  82. package/lib/relativeBundlePath.js +22 -0
  83. package/lib/relativeUrl.js +24 -0
  84. package/lib/replaceBundleReferences.js +182 -0
  85. package/lib/schema.js +353 -0
  86. package/lib/shared-buffer.js +31 -0
  87. package/lib/sourcemap.js +138 -0
  88. package/lib/stream.js +76 -0
  89. package/lib/throttle.js +15 -0
  90. package/lib/types/DefaultMap.d.ts +13 -0
  91. package/lib/types/Deferred.d.ts +8 -0
  92. package/lib/types/PromiseQueue.d.ts +25 -0
  93. package/lib/types/TapStream.d.ts +6 -0
  94. package/lib/types/alternatives.d.ts +3 -0
  95. package/lib/types/ansi-html.d.ts +1 -0
  96. package/lib/types/blob.d.ts +4 -0
  97. package/lib/types/bundle-url.d.ts +4 -0
  98. package/lib/types/collection.d.ts +33 -0
  99. package/lib/types/config.d.ts +17 -0
  100. package/lib/types/countLines.d.ts +1 -0
  101. package/lib/types/debounce.d.ts +1 -0
  102. package/lib/types/debug-tools.d.ts +8 -0
  103. package/lib/types/dependency-location.d.ts +14 -0
  104. package/lib/types/escape-html.d.ts +1 -0
  105. package/lib/types/generateBuildMetrics.d.ts +18 -0
  106. package/lib/types/generateCertificate.d.ts +5 -0
  107. package/lib/types/getCertificate.d.ts +5 -0
  108. package/lib/types/getExisting.d.ts +8 -0
  109. package/lib/types/getModuleParts.d.ts +4 -0
  110. package/lib/types/getRootDir.d.ts +2 -0
  111. package/lib/types/getTimeId.d.ts +1 -0
  112. package/lib/types/glob.d.ts +9 -0
  113. package/lib/types/hash.d.ts +7 -0
  114. package/lib/types/http-server.d.ts +19 -0
  115. package/lib/types/index.d.ts +49 -0
  116. package/lib/types/is-url.d.ts +1 -0
  117. package/lib/types/isDirectoryInside.d.ts +2 -0
  118. package/lib/types/objectHash.d.ts +3 -0
  119. package/lib/types/openInBrowser.d.ts +1 -0
  120. package/lib/types/parseCSSImport.d.ts +1 -0
  121. package/lib/types/path.d.ts +8 -0
  122. package/lib/types/prettifyTime.d.ts +1 -0
  123. package/lib/types/prettyDiagnostic.d.ts +18 -0
  124. package/lib/types/progress-message.d.ts +3 -0
  125. package/lib/types/relativeBundlePath.d.ts +4 -0
  126. package/lib/types/relativeUrl.d.ts +1 -0
  127. package/lib/types/replaceBundleReferences.d.ts +39 -0
  128. package/lib/types/schema.d.ts +107 -0
  129. package/lib/types/shared-buffer.d.ts +2 -0
  130. package/lib/types/sourcemap.d.ts +15 -0
  131. package/lib/types/stream.d.ts +8 -0
  132. package/lib/types/throttle.d.ts +1 -0
  133. package/lib/types/urlJoin.d.ts +5 -0
  134. package/lib/urlJoin.js +35 -0
  135. package/package.json +27 -18
  136. package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
  137. package/src/Deferred.ts +26 -0
  138. package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
  139. package/src/{TapStream.js → TapStream.ts} +8 -7
  140. package/src/{alternatives.js → alternatives.ts} +15 -16
  141. package/src/{ansi-html.js → ansi-html.ts} +1 -1
  142. package/src/{blob.js → blob.ts} +3 -5
  143. package/src/{bundle-url.js → bundle-url.ts} +3 -5
  144. package/src/{collection.js → collection.ts} +23 -20
  145. package/src/{config.js → config.ts} +20 -21
  146. package/src/{countLines.js → countLines.ts} +0 -2
  147. package/src/{debounce.js → debounce.ts} +3 -5
  148. package/src/debug-tools.ts +48 -0
  149. package/src/{dependency-location.js → dependency-location.ts} +15 -11
  150. package/src/{escape-html.js → escape-html.ts} +5 -3
  151. package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +19 -21
  152. package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
  153. package/src/{getCertificate.js → getCertificate.ts} +6 -5
  154. package/src/{getExisting.js → getExisting.ts} +4 -3
  155. package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
  156. package/src/{getRootDir.js → getRootDir.ts} +1 -3
  157. package/src/getTimeId.ts +12 -0
  158. package/src/{glob.js → glob.ts} +13 -14
  159. package/src/{hash.js → hash.ts} +23 -18
  160. package/src/{http-server.js → http-server.ts} +34 -40
  161. package/src/{index.js → index.ts} +14 -10
  162. package/src/{is-url.js → is-url.ts} +1 -2
  163. package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
  164. package/src/{objectHash.js → objectHash.ts} +1 -4
  165. package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
  166. package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
  167. package/src/{path.js → path.ts} +2 -4
  168. package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
  169. package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +47 -24
  170. package/src/progress-message.ts +43 -0
  171. package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
  172. package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
  173. package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +67 -51
  174. package/src/schema.ts +552 -0
  175. package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
  176. package/src/{sourcemap.js → sourcemap.ts} +28 -10
  177. package/src/{stream.js → stream.ts} +30 -22
  178. package/src/throttle.ts +13 -0
  179. package/src/{urlJoin.js → urlJoin.ts} +1 -3
  180. package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
  181. package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
  182. package/test/{collection.test.js → collection.test.ts} +0 -2
  183. package/test/{config.test.js → config.test.ts} +0 -3
  184. package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
  185. package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
  186. package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
  187. package/test/schema.test.ts +748 -0
  188. package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
  189. package/test/{throttle.test.js → throttle.test.ts} +1 -3
  190. package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
  191. package/tsconfig.json +36 -0
  192. package/tsconfig.tsbuildinfo +1 -0
  193. package/lib/index.js.map +0 -1
  194. package/src/Deferred.js +0 -23
  195. package/src/progress-message.js +0 -22
  196. package/src/schema.js +0 -504
  197. package/src/throttle.js +0 -15
@@ -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,35 +1,33 @@
1
- // @flow
2
-
3
- import type {FilePath, PackagedBundle} from '@atlaspack/types';
4
- import type {FileSystem} from '@atlaspack/fs';
5
- import SourceMap from '@parcel/source-map';
1
+ import type {FilePath, PackagedBundle} from '@atlaspack/types-internal';
2
+ import type {FileSystem} from '@atlaspack/types-internal';
3
+ import SourceMap from '@atlaspack/source-map';
6
4
  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,4 @@
1
- // @flow
2
- import type {FileSystem} from '@atlaspack/fs';
1
+ import type {FileSystem} from '@atlaspack/types-internal';
3
2
  import forge from 'node-forge';
4
3
  import path from 'path';
5
4
  import logger from '@atlaspack/logger';
@@ -7,8 +6,11 @@ import logger from '@atlaspack/logger';
7
6
  export default async function generateCertificate(
8
7
  fs: FileSystem,
9
8
  cacheDir: string,
10
- host: ?string,
11
- ): Promise<{|cert: Buffer, key: Buffer|}> {
9
+ host?: string | null,
10
+ ): Promise<{
11
+ cert: Buffer;
12
+ key: Buffer;
13
+ }> {
12
14
  let certDirectory = cacheDir;
13
15
 
14
16
  const privateKeyPath = path.join(certDirectory, 'private.pem');
@@ -134,7 +136,7 @@ export default async function generateCertificate(
134
136
  await fs.writeFile(certPath, certPem);
135
137
 
136
138
  return {
137
- key: privPem,
138
- cert: certPem,
139
+ key: privPem as unknown as Buffer,
140
+ cert: certPem as unknown as Buffer,
139
141
  };
140
142
  }
@@ -1,17 +1,18 @@
1
- // @flow
2
- import type {HTTPSOptions} from '@atlaspack/types';
3
- import type {FileSystem} from '@atlaspack/fs';
1
+ import type {HTTPSOptions, FileSystem} from '@atlaspack/types-internal';
4
2
 
5
3
  export default async function getCertificate(
6
4
  fs: FileSystem,
7
5
  options: HTTPSOptions,
8
- ): Promise<{|cert: Buffer, key: Buffer|}> {
6
+ ): Promise<{
7
+ cert: Buffer;
8
+ key: Buffer;
9
+ }> {
9
10
  try {
10
11
  let cert = await fs.readFile(options.cert);
11
12
  let key = await fs.readFile(options.key);
12
13
 
13
14
  return {key, cert};
14
- } catch (err) {
15
+ } catch (err: any) {
15
16
  throw new Error('Certificate and/or key not found');
16
17
  }
17
18
  }
@@ -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,6 +1,4 @@
1
- // @flow strict-local
2
-
3
- import type {FilePath} from '@atlaspack/types';
1
+ import type {FilePath} from '@atlaspack/types-internal';
4
2
  import {isGlob} from './glob';
5
3
  import path from 'path';
6
4
 
@@ -0,0 +1,12 @@
1
+ export default function getTimeId(): string {
2
+ let now = new Date();
3
+ return (
4
+ String(now.getFullYear()) +
5
+ String(now.getMonth() + 1).padStart(2, '0') +
6
+ String(now.getDate()).padStart(2, '0') +
7
+ '-' +
8
+ String(now.getHours()).padStart(2, '0') +
9
+ String(now.getMinutes()).padStart(2, '0') +
10
+ String(now.getSeconds()).padStart(2, '0')
11
+ );
12
+ }
@@ -1,10 +1,7 @@
1
- // @flow
2
-
3
- import type {FilePath, Glob} from '@atlaspack/types';
4
- import type {FileSystem} from '@atlaspack/fs';
1
+ import type {FilePath, FileSystem, Glob} from '@atlaspack/types-internal';
5
2
 
6
3
  import _isGlob from 'is-glob';
7
- import fastGlob, {type FastGlobOptions} from 'fast-glob';
4
+ import fastGlob, {Options as FastGlobOptions} from 'fast-glob';
8
5
  import micromatch, {isMatch, makeRe, type Options} from 'micromatch';
9
6
  import {normalizeSeparators} from './path';
10
7
 
@@ -42,9 +39,8 @@ export function globToRegex(glob: Glob, opts?: Options): RegExp {
42
39
  export function globSync(
43
40
  p: FilePath,
44
41
  fs: FileSystem,
45
- options?: FastGlobOptions<FilePath>,
42
+ options?: FastGlobOptions,
46
43
  ): Array<FilePath> {
47
- // $FlowFixMe
48
44
  options = {
49
45
  ...options,
50
46
  fs: {
@@ -56,29 +52,29 @@ export function globSync(
56
52
  // but this is fine for our purposes since we follow symlinks by default.
57
53
  return fs.statSync(p);
58
54
  },
55
+ // @ts-expect-error TS7006
59
56
  readdirSync: (p, opts) => {
60
57
  return fs.readdirSync(p, opts);
61
58
  },
62
59
  },
63
60
  };
64
61
 
65
- // $FlowFixMe
66
62
  return fastGlob.sync(normalizeSeparators(p), options);
67
63
  }
68
64
 
69
65
  export function glob(
70
66
  p: FilePath,
71
67
  fs: FileSystem,
72
- options: FastGlobOptions<FilePath>,
68
+ options: FastGlobOptions,
73
69
  ): Promise<Array<FilePath>> {
74
- // $FlowFixMe
75
70
  options = {
76
71
  ...options,
77
72
  fs: {
78
73
  stat: async (p, cb) => {
79
74
  try {
80
75
  cb(null, await fs.stat(p));
81
- } catch (err) {
76
+ } catch (err: any) {
77
+ // @ts-expect-error TS2345
82
78
  cb(err);
83
79
  }
84
80
  },
@@ -87,25 +83,28 @@ export function glob(
87
83
  // but this is fine for our purposes since we follow symlinks by default.
88
84
  try {
89
85
  cb(null, await fs.stat(p));
90
- } catch (err) {
86
+ } catch (err: any) {
87
+ // @ts-expect-error TS2345
91
88
  cb(err);
92
89
  }
93
90
  },
91
+ // @ts-expect-error TS7006
94
92
  readdir: async (p, opts, cb) => {
95
93
  if (typeof opts === 'function') {
96
94
  cb = opts;
95
+ // @ts-expect-error TS2322
97
96
  opts = null;
98
97
  }
99
98
 
100
99
  try {
101
100
  cb(null, await fs.readdir(p, opts));
102
- } catch (err) {
101
+ } catch (err: any) {
102
+ // @ts-expect-error TS2345
103
103
  cb(err);
104
104
  }
105
105
  },
106
106
  },
107
107
  };
108
108
 
109
- // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
110
109
  return fastGlob(normalizeSeparators(p), options);
111
110
  }
@@ -1,35 +1,40 @@
1
- // @flow strict-local
2
-
3
1
  import type {Readable} from 'stream';
4
- import type {FileSystem} from '@atlaspack/fs';
2
+ import type {FileSystem} from '@atlaspack/types-internal';
5
3
 
6
4
  import {objectSortedEntriesDeep} from './collection';
7
5
  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> {
@@ -1,47 +1,39 @@
1
- // @flow strict-local
2
-
3
1
  import type {
4
2
  Server as HTTPOnlyServer,
5
3
  IncomingMessage as HTTPRequest,
6
4
  ServerResponse as HTTPResponse,
7
5
  } from 'http';
8
- import type {
9
- Server as HTTPSServer,
10
- IncomingMessage as HTTPSRequest,
11
- ServerResponse as HTTPSResponse,
12
- } from 'https';
6
+ import type {Server as HTTPSServer} from 'https';
13
7
  import type {Socket} from 'net';
14
- import type {FilePath, HTTPSOptions} from '@atlaspack/types';
15
- import type {FileSystem} from '@atlaspack/fs';
8
+ import type {FilePath, HTTPSOptions} from '@atlaspack/types-internal';
9
+ import type {FileSystem} from '@atlaspack/types-internal';
16
10
 
17
11
  import http from 'http';
18
12
  import https from 'https';
19
13
  import nullthrows from 'nullthrows';
20
14
  import {getCertificate, generateCertificate} from './';
21
15
 
22
- type CreateHTTPServerOpts = {|
23
- listener?: (HTTPRequest | HTTPSRequest, HTTPResponse | HTTPSResponse) => void,
24
- host?: string,
25
- ...
26
- | {|
27
- https: ?(HTTPSOptions | boolean),
28
- inputFS: FileSystem,
29
- outputFS: FileSystem,
30
- cacheDir: FilePath,
31
- |}
32
- | {||},
33
- |};
16
+ type CreateHTTPServerOpts = {
17
+ listener?: (arg1: HTTPRequest, arg2: HTTPResponse) => void;
18
+ host?: string;
19
+ } & (
20
+ | {
21
+ https: HTTPSOptions | boolean | null | undefined;
22
+ inputFS: FileSystem;
23
+ outputFS: FileSystem;
24
+ cacheDir: FilePath;
25
+ }
26
+ | Record<any, any>
27
+ );
34
28
 
35
29
  export type HTTPServer = HTTPOnlyServer | HTTPSServer;
36
30
 
37
31
  // Creates either an http or https server with an awaitable dispose
38
32
  // that closes any connections
39
- export async function createHTTPServer(
40
- options: CreateHTTPServerOpts,
41
- ): Promise<{|
42
- stop: () => Promise<void>,
43
- server: HTTPServer,
44
- |}> {
33
+ export async function createHTTPServer(options: CreateHTTPServerOpts): Promise<{
34
+ stop: () => Promise<void>;
35
+ server: HTTPServer;
36
+ }> {
45
37
  let server;
46
38
  if (!options.https) {
47
39
  server = http.createServer(options.listener);
@@ -73,21 +65,23 @@ export async function createHTTPServer(
73
65
  return {
74
66
  server,
75
67
  stop() {
76
- return new Promise((resolve, reject) => {
77
- for (let socket of nullthrows(sockets)) {
78
- socket.destroy();
79
- }
80
- sockets = new Set();
81
-
82
- server.close((err) => {
83
- if (err != null) {
84
- reject(err);
85
- return;
68
+ return new Promise(
69
+ (resolve: () => void, reject: (error?: any) => void) => {
70
+ for (let socket of nullthrows(sockets)) {
71
+ socket.destroy();
86
72
  }
73
+ sockets = new Set();
74
+
75
+ server.close((err) => {
76
+ if (err != null) {
77
+ reject(err);
78
+ return;
79
+ }
87
80
 
88
- resolve();
89
- });
90
- });
81
+ resolve();
82
+ });
83
+ },
84
+ );
91
85
  },
92
86
  };
93
87
  }
@@ -1,11 +1,10 @@
1
- // @flow strict-local
2
- export type * from './config';
3
- export type * from './Deferred';
4
- export type * from './generateBuildMetrics';
5
- export type * from './http-server';
6
- export type * from './path';
7
- export type * from './prettyDiagnostic';
8
- export type * from './schema';
1
+ export * from './config';
2
+ export * from './Deferred';
3
+ export * from './generateBuildMetrics';
4
+ export * from './http-server';
5
+ export * from './path';
6
+ export * from './prettyDiagnostic';
7
+ export * from './schema';
9
8
 
10
9
  export {default as countLines} from './countLines';
11
10
  export {default as generateBuildMetrics} from './generateBuildMetrics';
@@ -27,7 +26,7 @@ export {default as createDependencyLocation} from './dependency-location';
27
26
  export {default as debounce} from './debounce';
28
27
  export {default as throttle} from './throttle';
29
28
  export {default as openInBrowser} from './openInBrowser';
30
-
29
+ export {default as getTimeId} from './getTimeId';
31
30
  // Explicit re-exports instead of export * for lazy require performance
32
31
  export {findAlternativeNodeModules, findAlternativeFiles} from './alternatives';
33
32
  export {blobToBuffer, blobToString} from './blob';
@@ -39,6 +38,7 @@ export {
39
38
  setSymmetricDifference,
40
39
  setEqual,
41
40
  setIntersect,
41
+ setIntersectStatic,
42
42
  setUnion,
43
43
  } from './collection';
44
44
  export {
@@ -47,9 +47,13 @@ export {
47
47
  loadConfig,
48
48
  readConfig,
49
49
  } from './config';
50
+ export {debugTools} from './debug-tools';
50
51
  export {DefaultMap, DefaultWeakMap} from './DefaultMap';
51
52
  export {makeDeferredWithPromise} from './Deferred';
52
- export {getProgressMessage} from './progress-message';
53
+ export {
54
+ getProgressMessage,
55
+ getPackageProgressMessage,
56
+ } from './progress-message';
53
57
  export {
54
58
  isGlob,
55
59
  isGlobMatch,
@@ -1,5 +1,4 @@
1
- // @flow
2
-
1
+ // @ts-expect-error TS7016
3
2
  import _isURL from 'is-url';
4
3
 
5
4
  // Matches anchor (ie: #raptors)
@@ -1,5 +1,4 @@
1
- // @flow strict-local
2
- import type {FilePath} from '@atlaspack/types';
1
+ import type {FilePath} from '@atlaspack/types-internal';
3
2
  import path from 'path';
4
3
 
5
4
  export default function isDirectoryInside(
@@ -1,9 +1,6 @@
1
- // @flow strict-local
2
-
3
1
  import crypto from 'crypto';
4
2
 
5
- // $FlowFixMe
6
- type Hashable = Object;
3
+ type Hashable = any;
7
4
 
8
5
  export default function objectHash(object: Hashable): string {
9
6
  let hash = crypto.createHash('md5');
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import open from 'open';
4
2
  import {execSync} from 'child_process';
5
3
  import logger from '@atlaspack/logger';
@@ -33,7 +31,7 @@ function commandExistsUnixSync(commandName: string) {
33
31
  ` && { echo >&1 '${commandName} found'; exit 0; }`,
34
32
  );
35
33
  return !!stdout;
36
- } catch (error) {
34
+ } catch (error: any) {
37
35
  return false;
38
36
  }
39
37
  }
@@ -54,7 +52,7 @@ export default async function openInBrowser(url: string, browser: string) {
54
52
  : undefined;
55
53
 
56
54
  await open(url, options);
57
- } catch (err) {
55
+ } catch (err: any) {
58
56
  logger.error(
59
57
  `Unexpected error while opening in browser: ${browser}`,
60
58
  '@atlaspack/utils',
@@ -1,5 +1,3 @@
1
- // @flow strict
2
-
3
1
  export default function parseCSSImport(url: string): string {
4
2
  if (!/^(~|\.\/|\/)/.test(url)) {
5
3
  return './' + url;
@@ -1,5 +1,4 @@
1
- // @flow strict-local
2
- import type {FilePath} from '@atlaspack/types';
1
+ import type {FilePath} from '@atlaspack/types-internal';
3
2
  import path from 'path';
4
3
 
5
4
  const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/;
@@ -14,8 +13,7 @@ export function normalizeSeparators(filePath: FilePath): FilePath {
14
13
  }
15
14
 
16
15
  export type PathOptions = {
17
- noLeadingDotSlash?: boolean,
18
- ...
16
+ noLeadingDotSlash?: boolean;
19
17
  };
20
18
 
21
19
  export function normalizePath(
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  export default function prettifyTime(timeInMs: number): string {
4
2
  return timeInMs < 1000 ? `${timeInMs}ms` : `${(timeInMs / 1000).toFixed(2)}s`;
5
3
  }