expo 58.0.0 → 58.0.1
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/android/build.gradle +2 -2
- package/android/proguard-rules.pro +4 -0
- package/android/src/main/java/expo/modules/fetch/NativeResponse.kt +5 -1
- package/android/src/main/java/expo/modules/fetch/OkHttpFileUrlInterceptor.kt +5 -1
- package/build/winter/runtime.native.js +0 -2
- package/build/winter/runtime.native.js.map +1 -1
- package/bundledNativeModules.json +21 -21
- package/package.json +7 -7
- package/scripts/spm/README.md +0 -3
- package/scripts/spm/__tests__/cli.test.js +57 -1
- package/scripts/spm/__tests__/diagnostics.test.js +181 -131
- package/scripts/spm/__tests__/flavored-frameworks.test.js +9 -0
- package/scripts/spm/__tests__/helpers.js +88 -0
- package/scripts/spm/__tests__/manifests.test.js +289 -74
- package/scripts/spm/__tests__/plugin.test.js +1101 -111
- package/scripts/spm/__tests__/podspec.test.js +27 -138
- package/scripts/spm/__tests__/spm-dependencies.test.js +344 -0
- package/scripts/spm/classify.js +28 -6
- package/scripts/spm/cli.js +23 -9
- package/scripts/spm/diagnostics.js +111 -91
- package/scripts/spm/flavored-frameworks.js +233 -21
- package/scripts/spm/manifests.js +85 -34
- package/scripts/spm/plugin.js +214 -55
- package/scripts/spm/podspec.js +10 -160
- package/src/winter/runtime.native.ts +0 -2
- package/template.tgz +0 -0
- package/build/winter/AbortSignal.d.ts +0 -3
- package/build/winter/AbortSignal.js +0 -96
- package/build/winter/AbortSignal.js.map +0 -1
- package/src/winter/AbortSignal.ts +0 -132
- package/src/winter/__tests__/AbortSignal.test.native.ts +0 -163
package/scripts/spm/podspec.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The little the SwiftPM plugin reads from a podspec. A podspec is Ruby, and Ruby
|
|
3
|
-
* cannot be read safely without running it, so the plugin
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* exact literal — anything else is refused with a `PodspecSyntaxError`.
|
|
3
|
+
* cannot be read safely without running it, so the plugin never extracts values from
|
|
4
|
+
* one: a misparsed `frameworks` list would ship a wrong link line silently. It only
|
|
5
|
+
* DETECTS that a podspec declares linkage — the module is then asked for a
|
|
6
|
+
* Package.swift — and that its xcconfig passes linker flags, which is worth a warning.
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
'use strict';
|
|
@@ -12,24 +11,12 @@
|
|
|
12
11
|
const fs = require('fs');
|
|
13
12
|
const path = require('path');
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
super(`${file}:${line}: ${reason}`);
|
|
18
|
-
this.name = 'PodspecSyntaxError';
|
|
19
|
-
this.file = file;
|
|
20
|
-
this.line = line;
|
|
21
|
-
this.snippet = snippet;
|
|
22
|
-
this.reason = reason;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const syntaxError = (file, line, reason) =>
|
|
27
|
-
new PodspecSyntaxError({ file, line: line.number, snippet: line.text.trim(), reason });
|
|
28
|
-
|
|
14
|
+
// No reader below is sensitive to a trailing `\r` today; the normalisation is here so
|
|
15
|
+
// that one anchoring a pattern at line end does not quietly fail on a CRLF checkout.
|
|
29
16
|
const sourceLines = (text) => text.replace(/\r\n/g, '\n').split('\n');
|
|
30
17
|
|
|
31
18
|
// ---------------------------------------------------------------------------
|
|
32
|
-
//
|
|
19
|
+
// Line reading: the podspec body outside `test_spec` blocks, comments stripped
|
|
33
20
|
// ---------------------------------------------------------------------------
|
|
34
21
|
|
|
35
22
|
/**
|
|
@@ -134,137 +121,6 @@ function xcconfigLinkerFlags(text) {
|
|
|
134
121
|
return null;
|
|
135
122
|
}
|
|
136
123
|
|
|
137
|
-
// ---------------------------------------------------------------------------
|
|
138
|
-
// iOS deployment floor: exact literals or an error
|
|
139
|
-
// ---------------------------------------------------------------------------
|
|
140
|
-
|
|
141
|
-
const PLATFORMS_RX = /^\s*\w+\.platforms\s*=\s*(.*)$/;
|
|
142
|
-
const DEPLOYMENT_TARGET_RX = /^\s*\w+\.ios\.deployment_target\s*=\s*(.*)$/;
|
|
143
|
-
const HASH_PAIR_RX = /^:(\w+)\s*=>\s*(['"])([^'"]*)\2$/;
|
|
144
|
-
const LITERAL_RX = /^(['"])([^'"]*)\1$/;
|
|
145
|
-
const VERSION_RX = /^\d+(?:\.\d+)*$/;
|
|
146
|
-
|
|
147
|
-
/** The hash body between the braces, joined across lines. Trailing code is refused. */
|
|
148
|
-
function readHashBody(lines, index, file) {
|
|
149
|
-
const line = lines[index];
|
|
150
|
-
let body = line.text.slice(line.text.indexOf('{') + 1);
|
|
151
|
-
let last = index;
|
|
152
|
-
while (!body.includes('}')) {
|
|
153
|
-
last += 1;
|
|
154
|
-
if (last >= lines.length) {
|
|
155
|
-
throw syntaxError(file, line, 'a `platforms` hash that is never closed');
|
|
156
|
-
}
|
|
157
|
-
body += ` ${lines[last].text.trim()}`;
|
|
158
|
-
}
|
|
159
|
-
const close = body.indexOf('}');
|
|
160
|
-
const trailing = body.slice(close + 1).trim();
|
|
161
|
-
if (trailing.length) {
|
|
162
|
-
throw syntaxError(file, line, `\`${trailing}\` after the platforms hash`);
|
|
163
|
-
}
|
|
164
|
-
return { body: body.slice(0, close), last };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function iosVersionFromHash(body, line, file) {
|
|
168
|
-
let version = null;
|
|
169
|
-
for (const entry of body.split(',').map((pair) => pair.trim())) {
|
|
170
|
-
if (entry.length === 0) continue;
|
|
171
|
-
const pair = entry.match(HASH_PAIR_RX);
|
|
172
|
-
if (pair == null) {
|
|
173
|
-
throw syntaxError(file, line, `\`${entry}\` where a \`:ios => '16.4'\` pair belongs`);
|
|
174
|
-
}
|
|
175
|
-
const [, platform, , value] = pair;
|
|
176
|
-
if (platform !== 'ios') continue;
|
|
177
|
-
if (version != null) {
|
|
178
|
-
throw syntaxError(file, line, 'two `:ios` keys in one platforms hash');
|
|
179
|
-
}
|
|
180
|
-
version = requireVersion(value, line, file);
|
|
181
|
-
}
|
|
182
|
-
return version;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function requireVersion(value, line, file) {
|
|
186
|
-
if (!VERSION_RX.test(value)) {
|
|
187
|
-
throw syntaxError(file, line, `the iOS floor \`${value}\`, which is not a version literal`);
|
|
188
|
-
}
|
|
189
|
-
return value;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function compareVersions(one, other) {
|
|
193
|
-
const parts = (version) => version.split('.').map(Number);
|
|
194
|
-
const [left, right] = [parts(one), parts(other)];
|
|
195
|
-
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
196
|
-
const delta = (left[i] ?? 0) - (right[i] ?? 0);
|
|
197
|
-
if (delta !== 0) return delta;
|
|
198
|
-
}
|
|
199
|
-
return 0;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* The iOS floor the podspec declares, or null when it declares none. Only exact
|
|
204
|
-
* literals are read; anything computed is refused rather than guessed at.
|
|
205
|
-
*
|
|
206
|
-
* A `platforms` hash written inside a heredoc would be read as if it were code. That
|
|
207
|
-
* costs a wrong deployment floor — a compile-time error in the module being built —
|
|
208
|
-
* where a heredoc-driven linkage guess would have shipped a wrong link line.
|
|
209
|
-
*/
|
|
210
|
-
function readIosFloor(text, file) {
|
|
211
|
-
const lines = [...podspecBodyLines(text)];
|
|
212
|
-
const versions = [];
|
|
213
|
-
let platformsLine = null;
|
|
214
|
-
for (let i = 0; i < lines.length; i++) {
|
|
215
|
-
const line = lines[i];
|
|
216
|
-
const interpolated = () => {
|
|
217
|
-
if (line.text.includes('#{')) {
|
|
218
|
-
throw syntaxError(
|
|
219
|
-
file,
|
|
220
|
-
line,
|
|
221
|
-
'string interpolation, which the reader cannot resolve without running the podspec'
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
const platforms = line.text.match(PLATFORMS_RX);
|
|
226
|
-
if (platforms != null) {
|
|
227
|
-
interpolated();
|
|
228
|
-
if (!platforms[1].trimStart().startsWith('{')) {
|
|
229
|
-
throw syntaxError(
|
|
230
|
-
file,
|
|
231
|
-
line,
|
|
232
|
-
`\`${platforms[1].trim()}\` where a \`{ :ios => '16.4' }\` hash belongs`
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
if (platformsLine != null) {
|
|
236
|
-
throw syntaxError(
|
|
237
|
-
file,
|
|
238
|
-
line,
|
|
239
|
-
`a second \`platforms\` assignment (the first is on line ${platformsLine}), so which ` +
|
|
240
|
-
'floor wins depends on Ruby evaluation order'
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
platformsLine = line.number;
|
|
244
|
-
const { body, last } = readHashBody(lines, i, file);
|
|
245
|
-
const version = iosVersionFromHash(body, line, file);
|
|
246
|
-
if (version != null) versions.push(version);
|
|
247
|
-
i = last;
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
const deploymentTarget = line.text.match(DEPLOYMENT_TARGET_RX);
|
|
251
|
-
if (deploymentTarget != null) {
|
|
252
|
-
interpolated();
|
|
253
|
-
const literal = deploymentTarget[1].trim().match(LITERAL_RX);
|
|
254
|
-
if (literal == null) {
|
|
255
|
-
throw syntaxError(
|
|
256
|
-
file,
|
|
257
|
-
line,
|
|
258
|
-
`\`${deploymentTarget[1].trim()}\` where a version literal like '16.4' belongs`
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
versions.push(requireVersion(literal[2], line, file));
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
// Both forms may appear; the higher one is the floor that actually holds.
|
|
265
|
-
return versions.sort(compareVersions).pop() ?? null;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
124
|
// ---------------------------------------------------------------------------
|
|
269
125
|
// I/O
|
|
270
126
|
// ---------------------------------------------------------------------------
|
|
@@ -293,8 +149,9 @@ function podspecFiles(podName, dirs) {
|
|
|
293
149
|
|
|
294
150
|
/**
|
|
295
151
|
* What the plugin needs from a pod's podspecs: the linkage declaration that makes the
|
|
296
|
-
* module unbuildable without a Package.swift, and the
|
|
297
|
-
* is not emitted at all, so
|
|
152
|
+
* module unbuildable without a Package.swift, and the xcconfig linker flags worth a
|
|
153
|
+
* warning. A module with linkage is not emitted at all, so nothing else is reported
|
|
154
|
+
* for it — one diagnostic at a time.
|
|
298
155
|
*/
|
|
299
156
|
function readPodspecs(podName, dirs) {
|
|
300
157
|
const texts = [];
|
|
@@ -310,7 +167,6 @@ function readPodspecs(podName, dirs) {
|
|
|
310
167
|
return {
|
|
311
168
|
linkage: { file, line: declaration.number, snippet: declaration.text },
|
|
312
169
|
linkerFlags: null,
|
|
313
|
-
iosDeploymentTarget: null,
|
|
314
170
|
};
|
|
315
171
|
}
|
|
316
172
|
texts.push({ file, text });
|
|
@@ -322,21 +178,15 @@ function readPodspecs(podName, dirs) {
|
|
|
322
178
|
return found == null ? null : { file, line: found.number, snippet: found.text };
|
|
323
179
|
})
|
|
324
180
|
.find((found) => found != null) ?? null;
|
|
325
|
-
const versions = texts
|
|
326
|
-
.map(({ file, text }) => readIosFloor(text, file))
|
|
327
|
-
.filter((version) => version != null);
|
|
328
181
|
return {
|
|
329
182
|
linkage: null,
|
|
330
183
|
linkerFlags: located(xcconfigLinkerFlags),
|
|
331
|
-
iosDeploymentTarget: versions.sort(compareVersions).pop() ?? null,
|
|
332
184
|
};
|
|
333
185
|
}
|
|
334
186
|
|
|
335
187
|
module.exports = {
|
|
336
|
-
PodspecSyntaxError,
|
|
337
188
|
podspecBodyLines,
|
|
338
189
|
linkageDeclaration,
|
|
339
190
|
xcconfigLinkerFlags,
|
|
340
|
-
readIosFloor,
|
|
341
191
|
readPodspecs,
|
|
342
192
|
};
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
// Otherwise we're relying on `getModulesRunBeforeMainModule` which is unstable or can be missing
|
|
6
6
|
import './setupReactNativeEnvironment';
|
|
7
7
|
import '../../types';
|
|
8
|
-
import { installAbortSignalPatch } from './AbortSignal';
|
|
9
8
|
import { installFormDataPatch } from './FormData';
|
|
10
9
|
import { installGlobal as install } from './installGlobal';
|
|
11
10
|
|
|
@@ -30,7 +29,6 @@ install('__ExpoImportMetaRegistry', () => require('./ImportMetaRegistry').Import
|
|
|
30
29
|
install('structuredClone', () => require('@ungap/structured-clone').default);
|
|
31
30
|
|
|
32
31
|
installFormDataPatch(FormData);
|
|
33
|
-
installAbortSignalPatch(AbortSignal);
|
|
34
32
|
|
|
35
33
|
// Polyfill async iterator symbol for Hermes.
|
|
36
34
|
// @ts-expect-error: readonly property only applies when the engine supports it
|
package/template.tgz
CHANGED
|
Binary file
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
const MAX_TIMEOUT = Number.MAX_SAFE_INTEGER;
|
|
2
|
-
const MAX_TIMER_DELAY = 2 ** 31 - 1;
|
|
3
|
-
export function installAbortSignalPatch(abortSignal) {
|
|
4
|
-
if (abortSignal.timeout == null) {
|
|
5
|
-
defineAbortSignalStatic(abortSignal, 'timeout', timeout);
|
|
6
|
-
}
|
|
7
|
-
if (abortSignal.any == null) {
|
|
8
|
-
defineAbortSignalStatic(abortSignal, 'any', any);
|
|
9
|
-
}
|
|
10
|
-
return abortSignal;
|
|
11
|
-
}
|
|
12
|
-
function timeout(milliseconds) {
|
|
13
|
-
validateTimeout(milliseconds);
|
|
14
|
-
const controller = new AbortController();
|
|
15
|
-
const reason = new DOMException('The signal timed out.', 'TimeoutError');
|
|
16
|
-
let remaining = milliseconds;
|
|
17
|
-
const schedule = ()=>{
|
|
18
|
-
const delay = Math.min(remaining, MAX_TIMER_DELAY);
|
|
19
|
-
remaining -= delay;
|
|
20
|
-
setTimeout(()=>{
|
|
21
|
-
if (remaining > 0) {
|
|
22
|
-
schedule();
|
|
23
|
-
} else {
|
|
24
|
-
abortWithReason(controller, reason);
|
|
25
|
-
}
|
|
26
|
-
}, delay);
|
|
27
|
-
};
|
|
28
|
-
schedule();
|
|
29
|
-
return controller.signal;
|
|
30
|
-
}
|
|
31
|
-
function any(signals) {
|
|
32
|
-
if (signals == null || typeof signals[Symbol.iterator] !== 'function') {
|
|
33
|
-
throw new TypeError('AbortSignal.any requires an iterable.');
|
|
34
|
-
}
|
|
35
|
-
const signalList = Array.from(signals);
|
|
36
|
-
const controller = new AbortController();
|
|
37
|
-
const cleanupFunctions = [];
|
|
38
|
-
for (const signal of signalList){
|
|
39
|
-
validateAbortSignal(signal);
|
|
40
|
-
if (signal.aborted) {
|
|
41
|
-
abortWithReason(controller, getAbortReason(signal));
|
|
42
|
-
return controller.signal;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const abort = (signal)=>{
|
|
46
|
-
cleanupFunctions.forEach((cleanup)=>cleanup());
|
|
47
|
-
abortWithReason(controller, getAbortReason(signal));
|
|
48
|
-
};
|
|
49
|
-
for (const signal of signalList){
|
|
50
|
-
const listener = ()=>{
|
|
51
|
-
abort(signal);
|
|
52
|
-
};
|
|
53
|
-
signal.addEventListener('abort', listener);
|
|
54
|
-
cleanupFunctions.push(()=>{
|
|
55
|
-
signal.removeEventListener('abort', listener);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return controller.signal;
|
|
59
|
-
}
|
|
60
|
-
function validateTimeout(milliseconds) {
|
|
61
|
-
if (typeof milliseconds !== 'number') {
|
|
62
|
-
throw new TypeError('AbortSignal.timeout requires a number.');
|
|
63
|
-
}
|
|
64
|
-
if (!Number.isInteger(milliseconds) || milliseconds < 0 || milliseconds > MAX_TIMEOUT) {
|
|
65
|
-
throw new RangeError(`AbortSignal.timeout requires a timeout between 0 and ${MAX_TIMEOUT} milliseconds.`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function validateAbortSignal(signal) {
|
|
69
|
-
if (signal == null || typeof signal !== 'object' || typeof signal.aborted !== 'boolean' || typeof signal.addEventListener !== 'function' || typeof signal.removeEventListener !== 'function') {
|
|
70
|
-
throw new TypeError('AbortSignal.any requires every item to be an AbortSignal.');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function getAbortReason(signal) {
|
|
74
|
-
return 'reason' in signal ? signal.reason : new DOMException('The operation was aborted.', 'AbortError');
|
|
75
|
-
}
|
|
76
|
-
function abortWithReason(controller, reason) {
|
|
77
|
-
controller.abort(reason);
|
|
78
|
-
if (controller.signal.reason !== reason) {
|
|
79
|
-
try {
|
|
80
|
-
Object.defineProperty(controller.signal, 'reason', {
|
|
81
|
-
value: reason,
|
|
82
|
-
configurable: true
|
|
83
|
-
});
|
|
84
|
-
} catch {}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function defineAbortSignalStatic(abortSignal, name, value) {
|
|
88
|
-
Object.defineProperty(abortSignal, name, {
|
|
89
|
-
value,
|
|
90
|
-
configurable: true,
|
|
91
|
-
enumerable: false,
|
|
92
|
-
writable: true
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
//# sourceMappingURL=AbortSignal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["winter/AbortSignal.ts"],"sourcesContent":[null],"names":["MAX_TIMEOUT","Number","MAX_SAFE_INTEGER","MAX_TIMER_DELAY","installAbortSignalPatch","abortSignal","timeout","defineAbortSignalStatic","any","milliseconds","validateTimeout","controller","AbortController","reason","DOMException","remaining","schedule","delay","Math","min","setTimeout","abortWithReason","signal","signals","Symbol","iterator","TypeError","signalList","Array","from","cleanupFunctions","validateAbortSignal","aborted","getAbortReason","abort","forEach","cleanup","listener","addEventListener","push","removeEventListener","isInteger","RangeError","Object","defineProperty","value","configurable","name","enumerable","writable"],"mappings":"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"}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
type AbortSignalConstructor = typeof AbortSignal;
|
|
2
|
-
|
|
3
|
-
const MAX_TIMEOUT = Number.MAX_SAFE_INTEGER;
|
|
4
|
-
const MAX_TIMER_DELAY = 2 ** 31 - 1;
|
|
5
|
-
|
|
6
|
-
export function installAbortSignalPatch(
|
|
7
|
-
abortSignal: AbortSignalConstructor
|
|
8
|
-
): AbortSignalConstructor {
|
|
9
|
-
if (abortSignal.timeout == null) {
|
|
10
|
-
defineAbortSignalStatic(abortSignal, 'timeout', timeout);
|
|
11
|
-
}
|
|
12
|
-
if (abortSignal.any == null) {
|
|
13
|
-
defineAbortSignalStatic(abortSignal, 'any', any);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return abortSignal;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function timeout(milliseconds: number): AbortSignal {
|
|
20
|
-
validateTimeout(milliseconds);
|
|
21
|
-
|
|
22
|
-
const controller = new AbortController();
|
|
23
|
-
const reason = new DOMException('The signal timed out.', 'TimeoutError');
|
|
24
|
-
let remaining = milliseconds;
|
|
25
|
-
|
|
26
|
-
const schedule = () => {
|
|
27
|
-
const delay = Math.min(remaining, MAX_TIMER_DELAY);
|
|
28
|
-
remaining -= delay;
|
|
29
|
-
setTimeout(() => {
|
|
30
|
-
if (remaining > 0) {
|
|
31
|
-
schedule();
|
|
32
|
-
} else {
|
|
33
|
-
abortWithReason(controller, reason);
|
|
34
|
-
}
|
|
35
|
-
}, delay);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
schedule();
|
|
39
|
-
|
|
40
|
-
return controller.signal;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function any(signals: Iterable<AbortSignal>): AbortSignal {
|
|
44
|
-
if (signals == null || typeof signals[Symbol.iterator] !== 'function') {
|
|
45
|
-
throw new TypeError('AbortSignal.any requires an iterable.');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const signalList = Array.from(signals);
|
|
49
|
-
const controller = new AbortController();
|
|
50
|
-
const cleanupFunctions: (() => void)[] = [];
|
|
51
|
-
|
|
52
|
-
for (const signal of signalList) {
|
|
53
|
-
validateAbortSignal(signal);
|
|
54
|
-
|
|
55
|
-
if (signal.aborted) {
|
|
56
|
-
abortWithReason(controller, getAbortReason(signal));
|
|
57
|
-
return controller.signal;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const abort = (signal: AbortSignal) => {
|
|
62
|
-
cleanupFunctions.forEach((cleanup) => cleanup());
|
|
63
|
-
abortWithReason(controller, getAbortReason(signal));
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
for (const signal of signalList) {
|
|
67
|
-
const listener = () => {
|
|
68
|
-
abort(signal);
|
|
69
|
-
};
|
|
70
|
-
signal.addEventListener('abort', listener);
|
|
71
|
-
cleanupFunctions.push(() => {
|
|
72
|
-
signal.removeEventListener('abort', listener);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return controller.signal;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function validateTimeout(milliseconds: number): void {
|
|
80
|
-
if (typeof milliseconds !== 'number') {
|
|
81
|
-
throw new TypeError('AbortSignal.timeout requires a number.');
|
|
82
|
-
}
|
|
83
|
-
if (!Number.isInteger(milliseconds) || milliseconds < 0 || milliseconds > MAX_TIMEOUT) {
|
|
84
|
-
throw new RangeError(
|
|
85
|
-
`AbortSignal.timeout requires a timeout between 0 and ${MAX_TIMEOUT} milliseconds.`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function validateAbortSignal(signal: AbortSignal): void {
|
|
91
|
-
if (
|
|
92
|
-
signal == null ||
|
|
93
|
-
typeof signal !== 'object' ||
|
|
94
|
-
typeof signal.aborted !== 'boolean' ||
|
|
95
|
-
typeof signal.addEventListener !== 'function' ||
|
|
96
|
-
typeof signal.removeEventListener !== 'function'
|
|
97
|
-
) {
|
|
98
|
-
throw new TypeError('AbortSignal.any requires every item to be an AbortSignal.');
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function getAbortReason(signal: AbortSignal): unknown {
|
|
103
|
-
return 'reason' in signal
|
|
104
|
-
? signal.reason
|
|
105
|
-
: new DOMException('The operation was aborted.', 'AbortError');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function abortWithReason(controller: AbortController, reason: unknown): void {
|
|
109
|
-
controller.abort(reason);
|
|
110
|
-
|
|
111
|
-
if (controller.signal.reason !== reason) {
|
|
112
|
-
try {
|
|
113
|
-
Object.defineProperty(controller.signal, 'reason', {
|
|
114
|
-
value: reason,
|
|
115
|
-
configurable: true,
|
|
116
|
-
});
|
|
117
|
-
} catch {}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function defineAbortSignalStatic(
|
|
122
|
-
abortSignal: AbortSignalConstructor,
|
|
123
|
-
name: 'timeout' | 'any',
|
|
124
|
-
value: AbortSignalConstructor[typeof name]
|
|
125
|
-
): void {
|
|
126
|
-
Object.defineProperty(abortSignal, name, {
|
|
127
|
-
value,
|
|
128
|
-
configurable: true,
|
|
129
|
-
enumerable: false,
|
|
130
|
-
writable: true,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { installAbortSignalPatch } from '../AbortSignal';
|
|
2
|
-
|
|
3
|
-
const originalTimeout = AbortSignal.timeout;
|
|
4
|
-
const originalAny = AbortSignal.any;
|
|
5
|
-
|
|
6
|
-
function resetAbortSignalStatics() {
|
|
7
|
-
Object.defineProperty(AbortSignal, 'timeout', {
|
|
8
|
-
value: undefined,
|
|
9
|
-
configurable: true,
|
|
10
|
-
enumerable: false,
|
|
11
|
-
writable: true,
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(AbortSignal, 'any', {
|
|
14
|
-
value: undefined,
|
|
15
|
-
configurable: true,
|
|
16
|
-
enumerable: false,
|
|
17
|
-
writable: true,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function restoreAbortSignalStatics() {
|
|
22
|
-
Object.defineProperty(AbortSignal, 'timeout', {
|
|
23
|
-
value: originalTimeout,
|
|
24
|
-
configurable: true,
|
|
25
|
-
enumerable: false,
|
|
26
|
-
writable: true,
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(AbortSignal, 'any', {
|
|
29
|
-
value: originalAny,
|
|
30
|
-
configurable: true,
|
|
31
|
-
enumerable: false,
|
|
32
|
-
writable: true,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
describe('AbortSignal patch', () => {
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
jest.useFakeTimers();
|
|
39
|
-
resetAbortSignalStatics();
|
|
40
|
-
installAbortSignalPatch(AbortSignal);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
jest.useRealTimers();
|
|
45
|
-
restoreAbortSignalStatics();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should install timeout and any when missing', () => {
|
|
49
|
-
expect(AbortSignal.timeout).toEqual(expect.any(Function));
|
|
50
|
-
expect(AbortSignal.any).toEqual(expect.any(Function));
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should not override native timeout or any implementations', () => {
|
|
54
|
-
const timeout = jest.fn();
|
|
55
|
-
const any = jest.fn();
|
|
56
|
-
|
|
57
|
-
Object.defineProperty(AbortSignal, 'timeout', {
|
|
58
|
-
value: timeout,
|
|
59
|
-
configurable: true,
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(AbortSignal, 'any', {
|
|
62
|
-
value: any,
|
|
63
|
-
configurable: true,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
installAbortSignalPatch(AbortSignal);
|
|
67
|
-
|
|
68
|
-
expect(AbortSignal.timeout).toBe(timeout);
|
|
69
|
-
expect(AbortSignal.any).toBe(any);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should abort timeout signal after delay with TimeoutError reason', () => {
|
|
73
|
-
const signal = AbortSignal.timeout(10);
|
|
74
|
-
const listener = jest.fn();
|
|
75
|
-
|
|
76
|
-
signal.addEventListener('abort', listener);
|
|
77
|
-
jest.advanceTimersByTime(9);
|
|
78
|
-
|
|
79
|
-
expect(signal.aborted).toBe(false);
|
|
80
|
-
expect(listener).not.toHaveBeenCalled();
|
|
81
|
-
|
|
82
|
-
jest.advanceTimersByTime(1);
|
|
83
|
-
|
|
84
|
-
expect(signal.aborted).toBe(true);
|
|
85
|
-
expect(listener).toHaveBeenCalledTimes(1);
|
|
86
|
-
expect(signal.reason).toBeInstanceOf(DOMException);
|
|
87
|
-
expect(signal.reason.name).toBe('TimeoutError');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should reject invalid timeout values', () => {
|
|
91
|
-
expect(() => AbortSignal.timeout(-1)).toThrow(RangeError);
|
|
92
|
-
expect(() => AbortSignal.timeout(1.5)).toThrow(RangeError);
|
|
93
|
-
expect(() => AbortSignal.timeout(Number.MAX_SAFE_INTEGER + 1)).toThrow(RangeError);
|
|
94
|
-
// @ts-expect-error: Testing invalid usage
|
|
95
|
-
expect(() => AbortSignal.timeout('1')).toThrow(TypeError);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should return non-aborted signal for empty any iterable', () => {
|
|
99
|
-
const signal = AbortSignal.any([]);
|
|
100
|
-
|
|
101
|
-
expect(signal.aborted).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should abort any signal when source is already aborted', () => {
|
|
105
|
-
const reason = new Error('cancelled');
|
|
106
|
-
const controller = new AbortController();
|
|
107
|
-
|
|
108
|
-
controller.abort(reason);
|
|
109
|
-
const signal = AbortSignal.any([controller.signal]);
|
|
110
|
-
|
|
111
|
-
expect(signal.aborted).toBe(true);
|
|
112
|
-
expect(signal.reason).toBe(reason);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should abort any signal when any source aborts', () => {
|
|
116
|
-
const reason = new Error('second');
|
|
117
|
-
const firstController = new AbortController();
|
|
118
|
-
const secondController = new AbortController();
|
|
119
|
-
const signal = AbortSignal.any([firstController.signal, secondController.signal]);
|
|
120
|
-
const listener = jest.fn();
|
|
121
|
-
|
|
122
|
-
signal.addEventListener('abort', listener);
|
|
123
|
-
secondController.abort(reason);
|
|
124
|
-
|
|
125
|
-
expect(signal.aborted).toBe(true);
|
|
126
|
-
expect(signal.reason).toBe(reason);
|
|
127
|
-
expect(listener).toHaveBeenCalledTimes(1);
|
|
128
|
-
expect(firstController.signal.aborted).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should preserve first abort reason for any signal', () => {
|
|
132
|
-
const firstReason = new Error('first');
|
|
133
|
-
const secondReason = new Error('second');
|
|
134
|
-
const firstController = new AbortController();
|
|
135
|
-
const secondController = new AbortController();
|
|
136
|
-
const signal = AbortSignal.any([firstController.signal, secondController.signal]);
|
|
137
|
-
|
|
138
|
-
secondController.abort(secondReason);
|
|
139
|
-
firstController.abort(firstReason);
|
|
140
|
-
|
|
141
|
-
expect(signal.reason).toBe(secondReason);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should remove source listeners after any signal aborts', () => {
|
|
145
|
-
const firstController = new AbortController();
|
|
146
|
-
const secondController = new AbortController();
|
|
147
|
-
const removeFirstListener = jest.spyOn(firstController.signal, 'removeEventListener');
|
|
148
|
-
const removeSecondListener = jest.spyOn(secondController.signal, 'removeEventListener');
|
|
149
|
-
|
|
150
|
-
AbortSignal.any([firstController.signal, secondController.signal]);
|
|
151
|
-
firstController.abort();
|
|
152
|
-
|
|
153
|
-
expect(removeFirstListener).toHaveBeenCalledWith('abort', expect.any(Function));
|
|
154
|
-
expect(removeSecondListener).toHaveBeenCalledWith('abort', expect.any(Function));
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should reject invalid any iterable values', () => {
|
|
158
|
-
// @ts-expect-error: Testing invalid usage
|
|
159
|
-
expect(() => AbortSignal.any(null)).toThrow(TypeError);
|
|
160
|
-
// @ts-expect-error: Testing invalid usage
|
|
161
|
-
expect(() => AbortSignal.any([{}])).toThrow(TypeError);
|
|
162
|
-
});
|
|
163
|
-
});
|