@atlaspack/utils 2.17.1 → 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.
- package/CHANGELOG.md +7 -0
- 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
package/lib/schema.js
CHANGED
|
@@ -30,7 +30,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
30
30
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
31
31
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
32
32
|
function validateSchema(schema, data) {
|
|
33
|
-
function walk(
|
|
33
|
+
function walk(
|
|
34
|
+
// @ts-expect-error TS7006
|
|
35
|
+
schemaAncestors, dataNode, dataPath) {
|
|
34
36
|
let [schemaNode] = schemaAncestors;
|
|
35
37
|
if (schemaNode.type) {
|
|
36
38
|
let type = Array.isArray(dataNode) ? 'array' : typeof dataNode;
|
|
@@ -49,10 +51,10 @@ function validateSchema(schema, data) {
|
|
|
49
51
|
{
|
|
50
52
|
if (schemaNode.items) {
|
|
51
53
|
let results = [];
|
|
52
|
-
//
|
|
54
|
+
// @ts-expect-error TS18046
|
|
53
55
|
for (let i = 0; i < dataNode.length; i++) {
|
|
54
56
|
let result = walk([schemaNode.items].concat(schemaAncestors),
|
|
55
|
-
//
|
|
57
|
+
// @ts-expect-error TS18046
|
|
56
58
|
dataNode[i], dataPath + '/' + i);
|
|
57
59
|
if (result) results.push(result);
|
|
58
60
|
}
|
|
@@ -62,7 +64,7 @@ function validateSchema(schema, data) {
|
|
|
62
64
|
}
|
|
63
65
|
case 'string':
|
|
64
66
|
{
|
|
65
|
-
//
|
|
67
|
+
// @ts-expect-error TS2322
|
|
66
68
|
let value = dataNode;
|
|
67
69
|
if (schemaNode.enum) {
|
|
68
70
|
if (!schemaNode.enum.includes(value)) {
|
|
@@ -92,7 +94,7 @@ function validateSchema(schema, data) {
|
|
|
92
94
|
}
|
|
93
95
|
case 'number':
|
|
94
96
|
{
|
|
95
|
-
//
|
|
97
|
+
// @ts-expect-error TS2322
|
|
96
98
|
let value = dataNode;
|
|
97
99
|
if (schemaNode.enum) {
|
|
98
100
|
if (!schemaNode.enum.includes(value)) {
|
|
@@ -113,10 +115,13 @@ function validateSchema(schema, data) {
|
|
|
113
115
|
let results = [];
|
|
114
116
|
let invalidProps;
|
|
115
117
|
if (schemaNode.__forbiddenProperties) {
|
|
116
|
-
//
|
|
118
|
+
// @ts-expect-error TS2769
|
|
117
119
|
let keys = Object.keys(dataNode);
|
|
120
|
+
// @ts-expect-error TS7006
|
|
118
121
|
invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
|
|
119
|
-
results.push(...invalidProps.map(
|
|
122
|
+
results.push(...invalidProps.map(
|
|
123
|
+
// @ts-expect-error TS7006
|
|
124
|
+
k => ({
|
|
120
125
|
type: 'forbidden-prop',
|
|
121
126
|
dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
|
|
122
127
|
dataType: 'key',
|
|
@@ -127,10 +132,14 @@ function validateSchema(schema, data) {
|
|
|
127
132
|
})));
|
|
128
133
|
}
|
|
129
134
|
if (schemaNode.required) {
|
|
130
|
-
//
|
|
135
|
+
// @ts-expect-error TS2769
|
|
131
136
|
let keys = Object.keys(dataNode);
|
|
132
|
-
let missingKeys = schemaNode.required.filter(
|
|
133
|
-
|
|
137
|
+
let missingKeys = schemaNode.required.filter(
|
|
138
|
+
// @ts-expect-error TS7006
|
|
139
|
+
val => !keys.includes(val));
|
|
140
|
+
results.push(...missingKeys.map(
|
|
141
|
+
// @ts-expect-error TS7006
|
|
142
|
+
k => ({
|
|
134
143
|
type: 'missing-prop',
|
|
135
144
|
dataPath,
|
|
136
145
|
dataType: 'value',
|
|
@@ -144,14 +153,14 @@ function validateSchema(schema, data) {
|
|
|
144
153
|
let {
|
|
145
154
|
additionalProperties = true
|
|
146
155
|
} = schemaNode;
|
|
147
|
-
//
|
|
156
|
+
// @ts-expect-error TS2407
|
|
148
157
|
for (let k in dataNode) {
|
|
149
158
|
if (invalidProps && invalidProps.includes(k)) {
|
|
150
159
|
// Don't check type on forbidden props
|
|
151
160
|
continue;
|
|
152
161
|
} else if (k in schemaNode.properties) {
|
|
153
162
|
let result = walk([schemaNode.properties[k]].concat(schemaAncestors),
|
|
154
|
-
//
|
|
163
|
+
// @ts-expect-error TS18046
|
|
155
164
|
dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
|
|
156
165
|
if (result) results.push(result);
|
|
157
166
|
} else {
|
|
@@ -161,9 +170,9 @@ function validateSchema(schema, data) {
|
|
|
161
170
|
type: 'enum',
|
|
162
171
|
dataType: 'key',
|
|
163
172
|
dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
|
|
164
|
-
expectedValues: Object.keys(schemaNode.properties
|
|
165
|
-
//
|
|
166
|
-
p => !(p in dataNode)),
|
|
173
|
+
expectedValues: Object.keys(schemaNode.properties
|
|
174
|
+
// @ts-expect-error TS18046
|
|
175
|
+
).filter(p => !(p in dataNode)),
|
|
167
176
|
actualValue: k,
|
|
168
177
|
ancestors: schemaAncestors,
|
|
169
178
|
prettyType: schemaNode.__type
|
|
@@ -171,7 +180,7 @@ function validateSchema(schema, data) {
|
|
|
171
180
|
}
|
|
172
181
|
} else {
|
|
173
182
|
let result = walk([additionalProperties].concat(schemaAncestors),
|
|
174
|
-
//
|
|
183
|
+
// @ts-expect-error TS18046
|
|
175
184
|
dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
|
|
176
185
|
if (result) results.push(result);
|
|
177
186
|
}
|
|
@@ -213,6 +222,7 @@ function validateSchema(schema, data) {
|
|
|
213
222
|
}
|
|
214
223
|
} else if (schemaNode.not) {
|
|
215
224
|
let result = walk([schemaNode.not].concat(schemaAncestors), dataNode, dataPath);
|
|
225
|
+
// @ts-expect-error TS2339
|
|
216
226
|
if (!result || result.length == 0) {
|
|
217
227
|
return {
|
|
218
228
|
type: 'other',
|
|
@@ -234,16 +244,22 @@ var _default = exports.default = validateSchema;
|
|
|
234
244
|
function fuzzySearch(expectedValues, actualValue) {
|
|
235
245
|
let result = expectedValues.map(exp => [exp, levenshtein().distance(exp, actualValue)]).filter(
|
|
236
246
|
// Remove if more than half of the string would need to be changed
|
|
247
|
+
// @ts-expect-error TS2769
|
|
237
248
|
([, d]) => d * 2 < actualValue.length);
|
|
249
|
+
// @ts-expect-error TS2345
|
|
238
250
|
result.sort(([, a], [, b]) => a - b);
|
|
251
|
+
// @ts-expect-error TS2345
|
|
239
252
|
return result.map(([v]) => v);
|
|
240
253
|
}
|
|
241
254
|
validateSchema.diagnostic = function (schema, data, origin, message) {
|
|
242
255
|
if ('source' in data && 'data' in data && typeof data.source !== 'string' && !data) {
|
|
243
256
|
throw new Error('At least one of data.source and data.data must be defined!');
|
|
244
257
|
}
|
|
245
|
-
|
|
246
|
-
|
|
258
|
+
// @ts-expect-error TS2339
|
|
259
|
+
let object = data.map ?
|
|
260
|
+
// @ts-expect-error TS2339
|
|
261
|
+
data.map.data :
|
|
262
|
+
// @ts-expect-error TS2339
|
|
247
263
|
data.data ?? JSON.parse(data.source);
|
|
248
264
|
let errors = validateSchema(schema, object);
|
|
249
265
|
if (errors.length) {
|
|
@@ -303,11 +319,13 @@ validateSchema.diagnostic = function (schema, data, origin, message) {
|
|
|
303
319
|
};
|
|
304
320
|
});
|
|
305
321
|
let map, code;
|
|
322
|
+
// @ts-expect-error TS2339
|
|
306
323
|
if (data.map) {
|
|
324
|
+
// @ts-expect-error TS2339
|
|
307
325
|
map = data.map;
|
|
308
326
|
code = data.source;
|
|
309
327
|
} else {
|
|
310
|
-
//
|
|
328
|
+
// @ts-expect-error TS2339
|
|
311
329
|
map = data.source ?? JSON.stringify((0, _nullthrows().default)(data.data), 0, '\t');
|
|
312
330
|
code = map;
|
|
313
331
|
}
|
|
@@ -329,6 +347,7 @@ validateSchema.diagnostic = function (schema, data, origin, message) {
|
|
|
329
347
|
diagnostic: {
|
|
330
348
|
message: message,
|
|
331
349
|
origin,
|
|
350
|
+
// @ts-expect-error TS2322
|
|
332
351
|
codeFrames
|
|
333
352
|
}
|
|
334
353
|
});
|
package/lib/shared-buffer.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.SharedBuffer = void 0;
|
|
7
7
|
let SharedBuffer = exports.SharedBuffer = void 0;
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// @ts-expect-error process.browser is a browser-specific property
|
|
10
10
|
if (process.browser) {
|
|
11
11
|
exports.SharedBuffer = SharedBuffer = ArrayBuffer;
|
|
12
12
|
// Safari has removed the constructor
|
package/lib/urlJoin.js
CHANGED
|
@@ -28,7 +28,7 @@ function urlJoin(publicURL, assetPath) {
|
|
|
28
28
|
// Leading / ensures that paths with colons are not parsed as a protocol.
|
|
29
29
|
let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
|
|
30
30
|
const assetUrl = _url().default.parse(p);
|
|
31
|
-
url.pathname = _path().default.posix.join(url.pathname, assetUrl.pathname);
|
|
31
|
+
url.pathname = _path().default.posix.join(url.pathname ?? '', assetUrl.pathname ?? '');
|
|
32
32
|
url.search = assetUrl.search;
|
|
33
33
|
url.hash = assetUrl.hash;
|
|
34
34
|
return _url().default.format(url);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/utils",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.3-typescript-08dcc1c9b.0",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
13
|
"main": "lib/index.js",
|
|
14
|
-
"source": "src/index.
|
|
14
|
+
"source": "src/index.ts",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
@@ -30,17 +30,16 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@atlaspack/codeframe": "2.13.
|
|
34
|
-
"@atlaspack/diagnostic": "2.14.
|
|
35
|
-
"@atlaspack/feature-flags": "2.19.
|
|
36
|
-
"@atlaspack/logger": "2.14.
|
|
37
|
-
"@atlaspack/markdown-ansi": "2.14.
|
|
38
|
-
"@atlaspack/rust": "3.4.
|
|
39
|
-
"@parcel/source-map": "^2.1.1",
|
|
40
|
-
"chalk": "^4.1.0",
|
|
41
|
-
"nullthrows": "^1.1.1",
|
|
33
|
+
"@atlaspack/codeframe": "2.13.5-typescript-08dcc1c9b.0",
|
|
34
|
+
"@atlaspack/diagnostic": "2.14.2-typescript-08dcc1c9b.0",
|
|
35
|
+
"@atlaspack/feature-flags": "2.19.3-typescript-08dcc1c9b.0",
|
|
36
|
+
"@atlaspack/logger": "2.14.14-typescript-08dcc1c9b.0",
|
|
37
|
+
"@atlaspack/markdown-ansi": "2.14.2-typescript-08dcc1c9b.0",
|
|
38
|
+
"@atlaspack/rust": "3.4.2-typescript-08dcc1c9b.0",
|
|
42
39
|
"@iarna/toml": "^2.2.0",
|
|
40
|
+
"@parcel/source-map": "^2.1.1",
|
|
43
41
|
"ansi-html-community": "0.0.8",
|
|
42
|
+
"chalk": "^4.1.0",
|
|
44
43
|
"clone": "^2.1.1",
|
|
45
44
|
"fast-glob": "^3.2.12",
|
|
46
45
|
"fastest-levenshtein": "^1.0.16",
|
|
@@ -50,13 +49,14 @@
|
|
|
50
49
|
"lru-cache": "^6.0.0",
|
|
51
50
|
"micromatch": "^4.0.4",
|
|
52
51
|
"node-forge": "^1.2.1",
|
|
52
|
+
"nullthrows": "^1.1.1",
|
|
53
53
|
"open": "^7.0.3",
|
|
54
54
|
"snarkdown": "^2.0.0",
|
|
55
55
|
"strip-ansi": "^6.0.0",
|
|
56
56
|
"terminal-link": "^2.1.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@atlaspack/babel-register": "2.14.
|
|
59
|
+
"@atlaspack/babel-register": "2.14.2-typescript-08dcc1c9b.0",
|
|
60
60
|
"benny": "^3.7.1",
|
|
61
61
|
"random-int": "^1.0.0"
|
|
62
62
|
},
|
|
@@ -66,5 +66,10 @@
|
|
|
66
66
|
"./src/openInBrowser.js": false,
|
|
67
67
|
"@atlaspack/markdown-ansi": false
|
|
68
68
|
},
|
|
69
|
-
"type": "commonjs"
|
|
69
|
+
"type": "commonjs",
|
|
70
|
+
"scripts": {
|
|
71
|
+
"check-ts": "tsc --noEmit"
|
|
72
|
+
},
|
|
73
|
+
"types": "src/index.ts",
|
|
74
|
+
"gitHead": "08dcc1c9bcdc6ab931d55e05ccc0f45669de2f22"
|
|
70
75
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
export class DefaultMap<K, V> extends Map<K, V> {
|
|
4
|
-
_getDefault: (K) => V;
|
|
2
|
+
_getDefault: (arg1: K) => V;
|
|
5
3
|
|
|
6
|
-
constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
|
|
4
|
+
constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>) {
|
|
7
5
|
super(entries);
|
|
8
6
|
this._getDefault = getDefault;
|
|
9
7
|
}
|
|
@@ -17,8 +15,7 @@ export class DefaultMap<K, V> extends Map<K, V> {
|
|
|
17
15
|
this.set(key, ret);
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
return ret;
|
|
18
|
+
return ret as V;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
|
|
@@ -26,11 +23,11 @@ interface Key {}
|
|
|
26
23
|
|
|
27
24
|
// Duplicated from DefaultMap implementation for Flow
|
|
28
25
|
// Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
|
|
29
|
-
export class DefaultWeakMap<K
|
|
30
|
-
_getDefault: (K) => V;
|
|
26
|
+
export class DefaultWeakMap<K extends Key, V> extends WeakMap<K, V> {
|
|
27
|
+
_getDefault: (arg1: K) => V;
|
|
31
28
|
|
|
32
|
-
constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
|
|
33
|
-
super(entries);
|
|
29
|
+
constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>) {
|
|
30
|
+
super(entries as Iterable<readonly [K, V]>);
|
|
34
31
|
this._getDefault = getDefault;
|
|
35
32
|
}
|
|
36
33
|
|
|
@@ -43,7 +40,6 @@ export class DefaultWeakMap<K: Key, V> extends WeakMap<K, V> {
|
|
|
43
40
|
this.set(key, ret);
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
return ret;
|
|
43
|
+
return ret as V;
|
|
48
44
|
}
|
|
49
45
|
}
|
package/src/Deferred.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import invariant from 'assert';
|
|
2
|
+
|
|
3
|
+
export type Deferred<T> = {
|
|
4
|
+
resolve(arg1: T): void;
|
|
5
|
+
reject(arg1: unknown): void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function makeDeferredWithPromise<T>(): {
|
|
9
|
+
deferred: Deferred<T>;
|
|
10
|
+
promise: Promise<T>;
|
|
11
|
+
} {
|
|
12
|
+
let deferred: Deferred<T> | null | undefined;
|
|
13
|
+
let promise = new Promise<T>(
|
|
14
|
+
(
|
|
15
|
+
resolve: (result: Promise<T> | T) => void,
|
|
16
|
+
reject: (error?: any) => void,
|
|
17
|
+
) => {
|
|
18
|
+
deferred = {resolve, reject};
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Promise constructor callback executes synchronously, so this is defined
|
|
23
|
+
invariant(deferred != null);
|
|
24
|
+
|
|
25
|
+
return {deferred, promise};
|
|
26
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import {makeDeferredWithPromise, Deferred} from './Deferred';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
type PromiseQueueOpts = {
|
|
4
|
+
maxConcurrent: number;
|
|
5
|
+
};
|
|
6
6
|
|
|
7
7
|
export default class PromiseQueue<T> {
|
|
8
|
-
_deferred:
|
|
8
|
+
_deferred: Deferred<Array<T>> | null | undefined;
|
|
9
9
|
_maxConcurrent: number;
|
|
10
10
|
_numRunning: number = 0;
|
|
11
11
|
_queue: Array<() => Promise<void>> = [];
|
|
12
|
-
_runPromise:
|
|
13
|
-
_error:
|
|
12
|
+
_runPromise: Promise<Array<T>> | null | undefined = null;
|
|
13
|
+
_error: unknown;
|
|
14
14
|
_count: number = 0;
|
|
15
15
|
_results: Array<T> = [];
|
|
16
16
|
_addSubscriptions: Set<() => void> = new Set();
|
|
@@ -28,30 +28,35 @@ export default class PromiseQueue<T> {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
add(fn: () => Promise<T>): void {
|
|
31
|
-
new Promise(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
31
|
+
new Promise(
|
|
32
|
+
(
|
|
33
|
+
resolve: (result: Promise<T> | T) => void,
|
|
34
|
+
reject: (error?: any) => void,
|
|
35
|
+
) => {
|
|
36
|
+
let i = this._count++;
|
|
37
|
+
let wrapped = () =>
|
|
38
|
+
fn().then(
|
|
39
|
+
(result) => {
|
|
40
|
+
this._results[i] = result;
|
|
41
|
+
resolve(result);
|
|
42
|
+
},
|
|
43
|
+
(err) => {
|
|
44
|
+
reject(err);
|
|
45
|
+
throw err;
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
this._queue.push(wrapped);
|
|
50
|
+
|
|
51
|
+
for (const addFn of this._addSubscriptions) {
|
|
52
|
+
addFn();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
|
|
56
|
+
this._next();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
).catch(() => {});
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
subscribeToAdd(fn: () => void): () => void {
|
|
@@ -71,9 +76,9 @@ export default class PromiseQueue<T> {
|
|
|
71
76
|
return Promise.resolve([]);
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
let {deferred, promise} = makeDeferredWithPromise();
|
|
79
|
+
let {deferred, promise} = makeDeferredWithPromise<Array<T>>();
|
|
75
80
|
this._deferred = deferred;
|
|
76
|
-
this._runPromise = promise
|
|
81
|
+
this._runPromise = promise as Promise<Array<T>>;
|
|
77
82
|
|
|
78
83
|
while (this._queue.length && this._numRunning < this._maxConcurrent) {
|
|
79
84
|
this._next();
|
|
@@ -84,7 +89,7 @@ export default class PromiseQueue<T> {
|
|
|
84
89
|
|
|
85
90
|
async _next(): Promise<void> {
|
|
86
91
|
let fn = this._queue.shift();
|
|
87
|
-
await this._runFn(fn);
|
|
92
|
+
await this._runFn(fn as () => unknown);
|
|
88
93
|
if (this._queue.length) {
|
|
89
94
|
this._next();
|
|
90
95
|
} else if (this._numRunning === 0) {
|
|
@@ -92,11 +97,11 @@ export default class PromiseQueue<T> {
|
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
async _runFn(fn: () =>
|
|
100
|
+
async _runFn(fn: () => unknown): Promise<void> {
|
|
96
101
|
this._numRunning++;
|
|
97
102
|
try {
|
|
98
103
|
await fn();
|
|
99
|
-
} catch (e) {
|
|
104
|
+
} catch (e: any) {
|
|
100
105
|
// Only store the first error that occurs.
|
|
101
106
|
// We don't reject immediately so that any other concurrent
|
|
102
107
|
// requests have time to complete.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {Transform} from 'stream';
|
|
4
2
|
|
|
5
3
|
/*
|
|
@@ -7,21 +5,24 @@ import {Transform} from 'stream';
|
|
|
7
5
|
* callback. Continues to pass data chunks down the stream.
|
|
8
6
|
*/
|
|
9
7
|
export default class TapStream extends Transform {
|
|
10
|
-
_tap: (Buffer) =>
|
|
11
|
-
constructor(tap: (Buffer) =>
|
|
12
|
-
super({...options});
|
|
8
|
+
_tap: (arg1: Buffer) => unknown;
|
|
9
|
+
constructor(tap: (arg1: Buffer) => unknown, options: unknown) {
|
|
10
|
+
super({...(options as any)});
|
|
13
11
|
this._tap = tap;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
_transform(
|
|
17
15
|
chunk: Buffer | string,
|
|
18
16
|
encoding: string,
|
|
19
|
-
callback: (
|
|
17
|
+
callback: (
|
|
18
|
+
err?: Error | null | undefined,
|
|
19
|
+
chunk?: Buffer | string,
|
|
20
|
+
) => unknown,
|
|
20
21
|
) {
|
|
21
22
|
try {
|
|
22
23
|
this._tap(Buffer.from(chunk));
|
|
23
24
|
callback(null, chunk);
|
|
24
|
-
} catch (err) {
|
|
25
|
+
} catch (err: any) {
|
|
25
26
|
callback(err);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import type {FileSystem} from '@atlaspack/types';
|
|
4
3
|
import {fuzzySearch} from './schema';
|
|
@@ -48,7 +47,7 @@ export async function findAlternativeNodeModules(
|
|
|
48
47
|
potentialModules.push(...modules);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
} catch (err) {
|
|
50
|
+
} catch (err: any) {
|
|
52
51
|
// ignore
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -68,16 +67,16 @@ async function findAllFilesUp({
|
|
|
68
67
|
collected,
|
|
69
68
|
leadingDotSlash = true,
|
|
70
69
|
includeDirectories = true,
|
|
71
|
-
}: {
|
|
72
|
-
fs: FileSystem
|
|
73
|
-
dir: string
|
|
74
|
-
root: string
|
|
75
|
-
basedir: string
|
|
76
|
-
maxlength: number
|
|
77
|
-
collected: Array<string
|
|
78
|
-
leadingDotSlash?: boolean
|
|
79
|
-
includeDirectories?: boolean
|
|
80
|
-
|
|
70
|
+
}: {
|
|
71
|
+
fs: FileSystem;
|
|
72
|
+
dir: string;
|
|
73
|
+
root: string;
|
|
74
|
+
basedir: string;
|
|
75
|
+
maxlength: number;
|
|
76
|
+
collected: Array<string>;
|
|
77
|
+
leadingDotSlash?: boolean;
|
|
78
|
+
includeDirectories?: boolean;
|
|
79
|
+
}): Promise<unknown> {
|
|
81
80
|
let dirContent = (await fs.readdir(dir)).sort();
|
|
82
81
|
return Promise.all(
|
|
83
82
|
dirContent.map(async (item) => {
|
|
@@ -111,9 +110,9 @@ export async function findAlternativeFiles(
|
|
|
111
110
|
fileSpecifier: string,
|
|
112
111
|
dir: string,
|
|
113
112
|
projectRoot: string,
|
|
114
|
-
leadingDotSlash
|
|
115
|
-
includeDirectories
|
|
116
|
-
includeExtension
|
|
113
|
+
leadingDotSlash: boolean = true,
|
|
114
|
+
includeDirectories: boolean = true,
|
|
115
|
+
includeExtension: boolean = false,
|
|
117
116
|
): Promise<Array<string>> {
|
|
118
117
|
let potentialFiles: Array<string> = [];
|
|
119
118
|
// Find our root, we won't recommend files above the package root as that's bad practise
|
package/src/{blob.js → blob.ts}
RENAMED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import type {Blob} from '@atlaspack/types';
|
|
4
2
|
|
|
5
3
|
import {Buffer} from 'buffer';
|
|
@@ -12,7 +10,7 @@ export function blobToBuffer(blob: Blob): Promise<Buffer> {
|
|
|
12
10
|
} else if (blob instanceof Buffer) {
|
|
13
11
|
return Promise.resolve(Buffer.from(blob));
|
|
14
12
|
} else {
|
|
15
|
-
return Promise.resolve(Buffer.from(blob, 'utf8'));
|
|
13
|
+
return Promise.resolve(Buffer.from(blob as string, 'utf8'));
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
|
|
@@ -22,6 +20,6 @@ export async function blobToString(blob: Blob): Promise<string> {
|
|
|
22
20
|
} else if (blob instanceof Buffer) {
|
|
23
21
|
return blob.toString();
|
|
24
22
|
} else {
|
|
25
|
-
return blob;
|
|
23
|
+
return blob as string;
|
|
26
24
|
}
|
|
27
25
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let bundleURL: ?string = null;
|
|
1
|
+
let bundleURL: string | null | undefined = null;
|
|
4
2
|
function getBundleURLCached(): string {
|
|
5
3
|
if (bundleURL == null) {
|
|
6
4
|
bundleURL = _getBundleURL();
|
|
@@ -13,7 +11,7 @@ function _getBundleURL(): string {
|
|
|
13
11
|
// Attempt to find the URL of the current script and use that as the base URL
|
|
14
12
|
try {
|
|
15
13
|
throw new Error();
|
|
16
|
-
} catch (err) {
|
|
14
|
+
} catch (err: any) {
|
|
17
15
|
let stack: string = typeof err.stack === 'string' ? err.stack : '';
|
|
18
16
|
let matches = stack.match(/(https?|file|ftp):\/\/[^)\n]+/g);
|
|
19
17
|
if (matches) {
|
|
@@ -24,7 +22,7 @@ function _getBundleURL(): string {
|
|
|
24
22
|
return '/';
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
export function getBaseURL(url
|
|
25
|
+
export function getBaseURL(url?: string | null): string {
|
|
28
26
|
if (url == null) {
|
|
29
27
|
return '/';
|
|
30
28
|
}
|