@atlaspack/utils 2.17.2 → 2.17.3-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 +201 -0
- package/lib/DefaultMap.js +0 -4
- package/lib/config.js +3 -1
- package/lib/debug-tools.js +1 -0
- package/lib/generateCertificate.js +2 -0
- package/lib/glob.js +14 -4
- package/lib/index.js +164 -9
- package/lib/is-url.js +2 -0
- package/lib/objectHash.js +0 -1
- package/lib/prettyDiagnostic.js +3 -5
- package/lib/schema.js +38 -19
- package/lib/shared-buffer.js +1 -1
- package/lib/urlJoin.js +1 -1
- package/package.json +18 -13
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +41 -36
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +14 -15
- package/src/{ansi-html.js → ansi-html.ts} +0 -1
- package/src/{blob.js → blob.ts} +2 -4
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +14 -21
- package/src/{config.js → config.ts} +18 -19
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/{debug-tools.js → debug-tools.ts} +6 -8
- package/src/{dependency-location.js → dependency-location.ts} +15 -11
- package/src/{escape-html.js → escape-html.ts} +5 -3
- package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +16 -18
- package/src/{generateCertificate.js → generateCertificate.ts} +8 -5
- package/src/{getCertificate.js → getCertificate.ts} +5 -3
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +0 -2
- package/src/{glob.js → glob.ts} +16 -11
- package/src/{hash.js → hash.ts} +22 -17
- package/src/{http-server.js → http-server.ts} +32 -38
- package/src/{index.js → index.ts} +7 -8
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +0 -1
- package/src/{objectHash.js → objectHash.ts} +1 -4
- package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
- package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
- package/src/{path.js → path.ts} +1 -3
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +22 -20
- package/src/{progress-message.js → progress-message.ts} +3 -2
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +3 -3
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +54 -36
- package/src/{schema.js → schema.ts} +158 -141
- package/src/{shared-buffer.js → shared-buffer.ts} +6 -4
- package/src/{sourcemap.js → sourcemap.ts} +16 -6
- package/src/{stream.js → stream.ts} +29 -21
- package/src/throttle.ts +13 -0
- package/src/{urlJoin.js → urlJoin.ts} +1 -3
- package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
- package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
- package/test/{collection.test.js → collection.test.ts} +0 -2
- package/test/{config.test.js → config.test.ts} +0 -3
- package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
- package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
- package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
- package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
- package/test/{throttle.test.js → throttle.test.ts} +1 -3
- package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
- package/tsconfig.json +4 -0
- package/src/Deferred.js +0 -23
- 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 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,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,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);
|
package/tsconfig.json
ADDED
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
|
-
}
|