@atlaspack/utils 2.17.3 → 2.17.4-typescript-17c3d1dec.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 (113) hide show
  1. package/LICENSE +201 -0
  2. package/lib/DefaultMap.d.ts +13 -0
  3. package/lib/DefaultMap.js +0 -4
  4. package/lib/Deferred.d.ts +8 -0
  5. package/lib/PromiseQueue.d.ts +25 -0
  6. package/lib/TapStream.d.ts +6 -0
  7. package/lib/alternatives.d.ts +3 -0
  8. package/lib/ansi-html.d.ts +1 -0
  9. package/lib/ansi-html.js +2 -0
  10. package/lib/blob.d.ts +4 -0
  11. package/lib/bundle-url.d.ts +4 -0
  12. package/lib/collection.d.ts +33 -0
  13. package/lib/config.d.ts +17 -0
  14. package/lib/config.js +3 -1
  15. package/lib/countLines.d.ts +1 -0
  16. package/lib/debounce.d.ts +1 -0
  17. package/lib/debug-tools.d.ts +6 -0
  18. package/lib/debug-tools.js +1 -0
  19. package/lib/dependency-location.d.ts +14 -0
  20. package/lib/escape-html.d.ts +1 -0
  21. package/lib/generateBuildMetrics.d.ts +18 -0
  22. package/lib/generateCertificate.d.ts +5 -0
  23. package/lib/getCertificate.d.ts +6 -0
  24. package/lib/getExisting.d.ts +8 -0
  25. package/lib/getModuleParts.d.ts +4 -0
  26. package/lib/getRootDir.d.ts +2 -0
  27. package/lib/glob.d.ts +10 -0
  28. package/lib/glob.js +12 -4
  29. package/lib/hash.d.ts +7 -0
  30. package/lib/http-server.d.ts +19 -0
  31. package/lib/index.d.ts +48 -0
  32. package/lib/index.js +164 -9
  33. package/lib/is-url.d.ts +1 -0
  34. package/lib/is-url.js +2 -0
  35. package/lib/isDirectoryInside.d.ts +2 -0
  36. package/lib/objectHash.d.ts +3 -0
  37. package/lib/objectHash.js +0 -1
  38. package/lib/openInBrowser.d.ts +1 -0
  39. package/lib/parseCSSImport.d.ts +1 -0
  40. package/lib/path.d.ts +8 -0
  41. package/lib/prettifyTime.d.ts +1 -0
  42. package/lib/prettyDiagnostic.d.ts +17 -0
  43. package/lib/prettyDiagnostic.js +3 -5
  44. package/lib/progress-message.d.ts +3 -0
  45. package/lib/relativeBundlePath.d.ts +4 -0
  46. package/lib/relativeUrl.d.ts +1 -0
  47. package/lib/replaceBundleReferences.d.ts +39 -0
  48. package/lib/schema.d.ts +107 -0
  49. package/lib/schema.js +38 -19
  50. package/lib/shared-buffer.d.ts +2 -0
  51. package/lib/shared-buffer.js +5 -1
  52. package/lib/sourcemap.d.ts +16 -0
  53. package/lib/stream.d.ts +8 -0
  54. package/lib/throttle.d.ts +1 -0
  55. package/lib/urlJoin.d.ts +5 -0
  56. package/lib/urlJoin.js +1 -1
  57. package/package.json +22 -15
  58. package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
  59. package/src/Deferred.ts +26 -0
  60. package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
  61. package/src/{TapStream.js → TapStream.ts} +8 -7
  62. package/src/{alternatives.js → alternatives.ts} +14 -15
  63. package/src/{ansi-html.js → ansi-html.ts} +1 -1
  64. package/src/{blob.js → blob.ts} +2 -4
  65. package/src/{bundle-url.js → bundle-url.ts} +3 -5
  66. package/src/{collection.js → collection.ts} +14 -21
  67. package/src/{config.js → config.ts} +18 -19
  68. package/src/{countLines.js → countLines.ts} +0 -2
  69. package/src/{debounce.js → debounce.ts} +3 -5
  70. package/src/{debug-tools.js → debug-tools.ts} +6 -8
  71. package/src/{dependency-location.js → dependency-location.ts} +15 -11
  72. package/src/{escape-html.js → escape-html.ts} +5 -3
  73. package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +16 -18
  74. package/src/{generateCertificate.js → generateCertificate.ts} +7 -5
  75. package/src/{getCertificate.js → getCertificate.ts} +5 -3
  76. package/src/{getExisting.js → getExisting.ts} +4 -3
  77. package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
  78. package/src/{getRootDir.js → getRootDir.ts} +0 -2
  79. package/src/{glob.js → glob.ts} +14 -10
  80. package/src/{hash.js → hash.ts} +22 -17
  81. package/src/{http-server.js → http-server.ts} +32 -38
  82. package/src/{index.js → index.ts} +7 -8
  83. package/src/{is-url.js → is-url.ts} +1 -2
  84. package/src/{isDirectoryInside.js → isDirectoryInside.ts} +0 -1
  85. package/src/{objectHash.js → objectHash.ts} +1 -4
  86. package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
  87. package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
  88. package/src/{path.js → path.ts} +1 -3
  89. package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
  90. package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +22 -20
  91. package/src/{progress-message.js → progress-message.ts} +3 -2
  92. package/src/{relativeBundlePath.js → relativeBundlePath.ts} +3 -3
  93. package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
  94. package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +54 -36
  95. package/src/{schema.js → schema.ts} +158 -141
  96. package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
  97. package/src/{sourcemap.js → sourcemap.ts} +16 -6
  98. package/src/{stream.js → stream.ts} +29 -21
  99. package/src/throttle.ts +13 -0
  100. package/src/{urlJoin.js → urlJoin.ts} +1 -3
  101. package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
  102. package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
  103. package/test/{collection.test.js → collection.test.ts} +0 -2
  104. package/test/{config.test.js → config.test.ts} +0 -3
  105. package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
  106. package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
  107. package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
  108. package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
  109. package/test/{throttle.test.js → throttle.test.ts} +1 -3
  110. package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
  111. package/tsconfig.json +4 -0
  112. package/src/Deferred.js +0 -23
  113. package/src/throttle.js +0 -15
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import assert from 'assert';
3
2
  import randomInt from 'random-int';
4
3
 
@@ -25,7 +24,7 @@ describe('PromiseQueue', () => {
25
24
  let queue = new PromiseQueue();
26
25
  queue.add(() => Promise.reject(error));
27
26
  await queue.run();
28
- } catch (e) {
27
+ } catch (e: any) {
29
28
  assert.equal(e, error);
30
29
  }
31
30
  });
@@ -38,7 +37,7 @@ describe('PromiseQueue', () => {
38
37
  throw error;
39
38
  });
40
39
  await queue.run();
41
- } catch (e) {
40
+ } catch (e: any) {
42
41
  assert.equal(e, error);
43
42
  }
44
43
  });
@@ -92,17 +91,17 @@ describe('PromiseQueue', () => {
92
91
 
93
92
  const fn1 = sinon
94
93
  .stub()
95
- .returns(new Promise((resolve) => setTimeout(resolve, 5000)));
94
+ .returns(new Promise((resolve: any) => setTimeout(resolve, 5000)));
96
95
 
97
96
  queue.add(fn1); // queue does not work if nothing is running, this is broken behaviour
98
97
  queue.run();
99
98
 
100
99
  const fn2 = sinon
101
100
  .stub()
102
- .returns(new Promise((resolve) => setTimeout(resolve, 5000)));
101
+ .returns(new Promise((resolve: any) => setTimeout(resolve, 5000)));
103
102
  const fn3 = sinon
104
103
  .stub()
105
- .returns(new Promise((resolve) => setTimeout(resolve, 5000)));
104
+ .returns(new Promise((resolve: any) => setTimeout(resolve, 5000)));
106
105
 
107
106
  queue.add(fn2);
108
107
  queue.add(fn3);
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import assert from 'assert';
4
2
  import {
5
3
  objectSortedEntries,
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import {loadConfig} from '../src/config';
5
3
  import {inputFS as fs} from '@atlaspack/test-utils';
@@ -23,7 +21,6 @@ describe('loadConfig', () => {
23
21
  });
24
22
 
25
23
  it('should throw error with empty string json', async () => {
26
- // $FlowFixMe[prop-missing]
27
24
  await assert.rejects(async () => {
28
25
  await loadConfig(
29
26
  fs,
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import assert from 'assert';
3
2
  import objectHash from '../src/objectHash';
4
3
 
@@ -8,12 +7,12 @@ describe('objectHash', () => {
8
7
  foo: {foo: 'foo', baz: ['foo', 'baz', 'bar'], bar: 'bar'},
9
8
  baz: 'baz',
10
9
  bar: 'bar',
11
- };
10
+ } as const;
12
11
  const obj2 = {
13
12
  foo: {foo: 'foo', baz: ['foo', 'baz', 'bar'], bar: 'bar'},
14
13
  baz: 'baz',
15
14
  bar: 'bar',
16
- };
15
+ } as const;
17
16
 
18
17
  assert.equal(objectHash(obj1), objectHash(obj2));
19
18
  });
@@ -22,11 +21,11 @@ describe('objectHash', () => {
22
21
  const obj1 = {
23
22
  baz: 'baz',
24
23
  bar: 'ba',
25
- };
24
+ } as const;
26
25
  const obj2 = {
27
26
  baz: 'baz',
28
27
  bar: 'bar',
29
- };
28
+ } as const;
30
29
 
31
30
  assert.notEqual(objectHash(obj1), objectHash(obj2));
32
31
  });
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import assert from 'assert';
3
2
  import prettifyTime from '../src/prettifyTime';
4
3
 
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import type {NamedBundle, Dependency} from '@atlaspack/types';
4
2
 
5
3
  import assert from 'assert';
@@ -7,30 +5,25 @@ import {getURLReplacement} from '../src/replaceBundleReferences';
7
5
 
8
6
  describe('replace bundle references', () => {
9
7
  it('Query params and named pipeline, relative', () => {
10
- // $FlowFixMe
11
8
  let fromBundle: NamedBundle = {
12
9
  filePath: '/user/dist/reformat.html',
13
10
  name: 'reformat.html',
14
- // $FlowFixMe
15
11
  target: {
16
12
  distDir: '/user/dist',
17
13
  publicUrl: '/',
18
14
  },
19
15
  };
20
16
 
21
- // $FlowFixMe
22
17
  let toBundle: NamedBundle = {
23
18
  filePath:
24
19
  '/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
25
20
  name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
26
- // $FlowFixMe
27
21
  target: {
28
22
  distDir: '/user/dist',
29
23
  publicUrl: '/',
30
24
  },
31
25
  };
32
26
 
33
- // $FlowFixMe
34
27
  let dependency: Dependency = {
35
28
  id: '074b36596e3147e900a8ad17ceb5c90b',
36
29
  specifier: 'url:./image.jpg?as=webp',
@@ -52,30 +45,25 @@ describe('replace bundle references', () => {
52
45
  });
53
46
 
54
47
  it('Query params and named pipeline, absolute', () => {
55
- // $FlowFixMe
56
48
  let fromBundle: NamedBundle = {
57
49
  filePath: '/user/dist/reformat.html',
58
50
  name: 'reformat.html',
59
- // $FlowFixMe
60
51
  target: {
61
52
  distDir: '/user/dist',
62
53
  publicUrl: '/',
63
54
  },
64
55
  };
65
56
 
66
- // $FlowFixMe
67
57
  let toBundle: NamedBundle = {
68
58
  filePath:
69
59
  '/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
70
60
  name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
71
- // $FlowFixMe
72
61
  target: {
73
62
  distDir: '/user/dist',
74
63
  publicUrl: '/',
75
64
  },
76
65
  };
77
66
 
78
- // $FlowFixMe
79
67
  let dependency: Dependency = {
80
68
  id: '074b36596e3147e900a8ad17ceb5c90b',
81
69
  specifier: 'url:./image.jpg?as=webp',
@@ -97,30 +85,25 @@ describe('replace bundle references', () => {
97
85
  });
98
86
 
99
87
  it('Custom Public URL', () => {
100
- // $FlowFixMe
101
88
  let fromBundle: NamedBundle = {
102
89
  filePath: '/user/dist/reformat.html',
103
90
  name: 'reformat.html',
104
- // $FlowFixMe
105
91
  target: {
106
92
  distDir: '/user/dist',
107
93
  publicUrl: 'https://test.com/static',
108
94
  },
109
95
  };
110
96
 
111
- // $FlowFixMe
112
97
  let toBundle: NamedBundle = {
113
98
  filePath:
114
99
  '/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
115
100
  name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
116
- // $FlowFixMe
117
101
  target: {
118
102
  distDir: '/user/dist',
119
103
  publicUrl: 'https://test.com/static',
120
104
  },
121
105
  };
122
106
 
123
- // $FlowFixMe
124
107
  let dependency: Dependency = {
125
108
  id: '074b36596e314797845a8ad17ceb5c9b',
126
109
  specifier: './image.jpg',
@@ -142,30 +125,25 @@ describe('replace bundle references', () => {
142
125
  });
143
126
 
144
127
  it('Relative with folders in between', () => {
145
- // $FlowFixMe
146
128
  let fromBundle: NamedBundle = {
147
129
  filePath: '/user/dist/reformat.html',
148
130
  name: 'reformat.html',
149
- // $FlowFixMe
150
131
  target: {
151
132
  distDir: '/user/dist',
152
133
  publicUrl: 'https://test.com/static',
153
134
  },
154
135
  };
155
136
 
156
- // $FlowFixMe
157
137
  let toBundle: NamedBundle = {
158
138
  filePath:
159
139
  '/user/dist/assets/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
160
140
  name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
161
- // $FlowFixMe
162
141
  target: {
163
142
  distDir: '/user/dist/assets',
164
143
  publicUrl: 'https://test.com/static',
165
144
  },
166
145
  };
167
146
 
168
- // $FlowFixMe
169
147
  let dependency: Dependency = {
170
148
  id: '074b36596e3147e900a8ad17ceb5c90b',
171
149
  specifier: 'url:./image.jpg?as=webp',
@@ -187,29 +165,24 @@ describe('replace bundle references', () => {
187
165
  });
188
166
 
189
167
  it('should work with bundle names with colons, relative', () => {
190
- // $FlowFixMe
191
168
  let fromBundle: NamedBundle = {
192
169
  filePath: '/user/dist/reformat.html',
193
170
  name: 'reformat.html',
194
- // $FlowFixMe
195
171
  target: {
196
172
  distDir: '/user/dist',
197
173
  publicUrl: '/',
198
174
  },
199
175
  };
200
176
 
201
- // $FlowFixMe
202
177
  let toBundle: NamedBundle = {
203
178
  filePath: '/user/dist/a:b:c.html',
204
179
  name: 'a:b:c.html',
205
- // $FlowFixMe
206
180
  target: {
207
181
  distDir: '/user/dist',
208
182
  publicUrl: '/',
209
183
  },
210
184
  };
211
185
 
212
- // $FlowFixMe
213
186
  let dependency: Dependency = {
214
187
  id: '074b36596e3147e900a8ad17ceb5c90b',
215
188
  specifier: './a:b:c.html',
@@ -227,29 +200,24 @@ describe('replace bundle references', () => {
227
200
  });
228
201
 
229
202
  it('should work with bundle names with colons, absolute', () => {
230
- // $FlowFixMe
231
203
  let fromBundle: NamedBundle = {
232
204
  filePath: '/user/dist/reformat.html',
233
205
  name: 'reformat.html',
234
- // $FlowFixMe
235
206
  target: {
236
207
  distDir: '/user/dist',
237
208
  publicUrl: '/',
238
209
  },
239
210
  };
240
211
 
241
- // $FlowFixMe
242
212
  let toBundle: NamedBundle = {
243
213
  filePath: '/user/dist/a:b:c.html',
244
214
  name: 'a:b:c.html',
245
- // $FlowFixMe
246
215
  target: {
247
216
  distDir: '/user/dist',
248
217
  publicUrl: '/',
249
218
  },
250
219
  };
251
220
 
252
- // $FlowFixMe
253
221
  let dependency: Dependency = {
254
222
  id: '074b36596e3147e900a8ad17ceb5c90b',
255
223
  specifier: './a:b:c.html',
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import assert from 'assert';
3
2
  import {
4
3
  matchSourceMappingURL,
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import sinon from 'sinon';
5
3
  import throttle from '../src/throttle';
@@ -33,7 +31,7 @@ describe('throttle', () => {
33
31
  });
34
32
 
35
33
  it('preserves the `this` when throttled functions are invoked', () => {
36
- let result;
34
+ let result: any;
37
35
  let throttled = throttle(function () {
38
36
  result = this.bar;
39
37
  }, 100);
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import urlJoin from '../src/urlJoin';
5
3
 
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }
package/src/Deferred.js DELETED
@@ -1,23 +0,0 @@
1
- // @flow strict-local
2
-
3
- import invariant from 'assert';
4
-
5
- export type Deferred<T> = {|
6
- resolve(T): void,
7
- reject(mixed): void,
8
- |};
9
-
10
- export function makeDeferredWithPromise<T>(): {|
11
- deferred: Deferred<T>,
12
- promise: Promise<T>,
13
- |} {
14
- let deferred: ?Deferred<T>;
15
- let promise = new Promise<T>((resolve, reject) => {
16
- deferred = {resolve, reject};
17
- });
18
-
19
- // Promise constructor callback executes synchronously, so this is defined
20
- invariant(deferred != null);
21
-
22
- return {deferred, promise};
23
- }
package/src/throttle.js DELETED
@@ -1,15 +0,0 @@
1
- // @flow strict-local
2
-
3
- export default function throttle<TArgs: Iterable<mixed>>(
4
- fn: (...args: TArgs) => mixed,
5
- delay: number,
6
- ): (...args: TArgs) => void {
7
- let lastCalled: ?number;
8
-
9
- return function throttled(...args: TArgs) {
10
- if (lastCalled == null || lastCalled + delay <= Date.now()) {
11
- fn.call(this, ...args);
12
- lastCalled = Date.now();
13
- }
14
- };
15
- }