expo 58.0.0 → 58.0.2
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 +76 -76
- package/ios/Expo/ExpoReactNativeFactory.swift +2 -2
- package/ios/ExpoObjC/AppDelegates/EXReactRootViewFactory.mm +16 -2
- package/ios/ExpoObjC/include/Expo/EXReactRootViewFactory.h +2 -1
- package/package.json +13 -13
- package/scripts/spm/README.md +0 -3
- package/scripts/spm/__tests__/app-target.test.js +105 -1
- package/scripts/spm/__tests__/autolink-gate.test.js +188 -0
- package/scripts/spm/__tests__/classify.test.js +17 -19
- package/scripts/spm/__tests__/cli.test.js +57 -1
- package/scripts/spm/__tests__/diagnostics.test.js +806 -183
- 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 +1330 -104
- package/scripts/spm/__tests__/metadata.test.js +120 -0
- package/scripts/spm/__tests__/plugin.test.js +3304 -111
- package/scripts/spm/__tests__/podspec.test.js +27 -138
- package/scripts/spm/__tests__/spm-dependencies.test.js +344 -0
- package/scripts/spm/app-target.js +42 -1
- package/scripts/spm/autolink-gate.js +40 -0
- package/scripts/spm/classify.js +78 -79
- package/scripts/spm/cli.js +23 -9
- package/scripts/spm/diagnostics.js +605 -192
- package/scripts/spm/flavored-frameworks.js +231 -64
- package/scripts/spm/manifests.js +565 -196
- package/scripts/spm/metadata.js +152 -0
- package/scripts/spm/plugin.js +679 -205
- package/scripts/spm/podspec.js +57 -170
- 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,13 @@
|
|
|
12
11
|
const fs = require('fs');
|
|
13
12
|
const path = require('path');
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
constructor({ file, line, snippet, reason }) {
|
|
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 });
|
|
14
|
+
const { APPLE_SOURCE_DIRS } = require('./classify');
|
|
28
15
|
|
|
16
|
+
// CRLF-safe.
|
|
29
17
|
const sourceLines = (text) => text.replace(/\r\n/g, '\n').split('\n');
|
|
30
18
|
|
|
31
19
|
// ---------------------------------------------------------------------------
|
|
32
|
-
//
|
|
20
|
+
// Line reading: the podspec body outside `test_spec` blocks, comments stripped
|
|
33
21
|
// ---------------------------------------------------------------------------
|
|
34
22
|
|
|
35
23
|
/**
|
|
@@ -134,141 +122,40 @@ function xcconfigLinkerFlags(text) {
|
|
|
134
122
|
return null;
|
|
135
123
|
}
|
|
136
124
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
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);
|
|
125
|
+
/** Pod names a podspec depends on, ignoring `test_spec` blocks. Text-only. */
|
|
126
|
+
function podspecDependencies(text) {
|
|
127
|
+
const deps = [];
|
|
128
|
+
for (const { text: line } of podspecBodyLines(text)) {
|
|
129
|
+
const match = line.match(/\.dependency\s+['"]([^'"]+)['"]/);
|
|
130
|
+
if (match) deps.push(match[1]);
|
|
181
131
|
}
|
|
182
|
-
return
|
|
132
|
+
return deps;
|
|
183
133
|
}
|
|
184
134
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
return value;
|
|
190
|
-
}
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
// I/O
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
191
138
|
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (delta !== 0) return delta;
|
|
139
|
+
function readText(file) {
|
|
140
|
+
try {
|
|
141
|
+
return fs.readFileSync(file, 'utf8');
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
198
144
|
}
|
|
199
|
-
return 0;
|
|
200
145
|
}
|
|
201
146
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
}
|
|
147
|
+
function podspecsIn(dir) {
|
|
148
|
+
try {
|
|
149
|
+
return fs
|
|
150
|
+
.readdirSync(dir)
|
|
151
|
+
.filter((name) => name.endsWith('.podspec'))
|
|
152
|
+
.sort()
|
|
153
|
+
.map((name) => path.join(dir, name));
|
|
154
|
+
} catch {
|
|
155
|
+
return [];
|
|
263
156
|
}
|
|
264
|
-
// Both forms may appear; the higher one is the floor that actually holds.
|
|
265
|
-
return versions.sort(compareVersions).pop() ?? null;
|
|
266
157
|
}
|
|
267
158
|
|
|
268
|
-
// ---------------------------------------------------------------------------
|
|
269
|
-
// I/O
|
|
270
|
-
// ---------------------------------------------------------------------------
|
|
271
|
-
|
|
272
159
|
/**
|
|
273
160
|
* The podspecs describing `podName`: its own file when one carries its name, else
|
|
274
161
|
* every podspec in the directories — a module may name its podspec anything.
|
|
@@ -278,39 +165,25 @@ function podspecFiles(podName, dirs) {
|
|
|
278
165
|
const own = path.join(dir, `${podName}.podspec`);
|
|
279
166
|
if (fs.existsSync(own)) return [own];
|
|
280
167
|
}
|
|
281
|
-
return dirs.flatMap(
|
|
282
|
-
try {
|
|
283
|
-
return fs
|
|
284
|
-
.readdirSync(dir)
|
|
285
|
-
.filter((name) => name.endsWith('.podspec'))
|
|
286
|
-
.sort()
|
|
287
|
-
.map((name) => path.join(dir, name));
|
|
288
|
-
} catch {
|
|
289
|
-
return [];
|
|
290
|
-
}
|
|
291
|
-
});
|
|
168
|
+
return dirs.flatMap(podspecsIn);
|
|
292
169
|
}
|
|
293
170
|
|
|
294
171
|
/**
|
|
295
172
|
* 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
|
|
173
|
+
* module unbuildable without a Package.swift, and the xcconfig linker flags worth a
|
|
174
|
+
* warning. A module with linkage is not emitted at all, so nothing else is reported
|
|
175
|
+
* for it — one diagnostic at a time.
|
|
298
176
|
*/
|
|
299
177
|
function readPodspecs(podName, dirs) {
|
|
300
178
|
const texts = [];
|
|
301
179
|
for (const file of podspecFiles(podName, dirs)) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
text = fs.readFileSync(file, 'utf8');
|
|
305
|
-
} catch {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
180
|
+
const text = readText(file);
|
|
181
|
+
if (text == null) continue;
|
|
308
182
|
const declaration = linkageDeclaration(text);
|
|
309
183
|
if (declaration != null) {
|
|
310
184
|
return {
|
|
311
185
|
linkage: { file, line: declaration.number, snippet: declaration.text },
|
|
312
186
|
linkerFlags: null,
|
|
313
|
-
iosDeploymentTarget: null,
|
|
314
187
|
};
|
|
315
188
|
}
|
|
316
189
|
texts.push({ file, text });
|
|
@@ -322,21 +195,35 @@ function readPodspecs(podName, dirs) {
|
|
|
322
195
|
return found == null ? null : { file, line: found.number, snippet: found.text };
|
|
323
196
|
})
|
|
324
197
|
.find((found) => found != null) ?? null;
|
|
325
|
-
const versions = texts
|
|
326
|
-
.map(({ file, text }) => readIosFloor(text, file))
|
|
327
|
-
.filter((version) => version != null);
|
|
328
198
|
return {
|
|
329
199
|
linkage: null,
|
|
330
200
|
linkerFlags: located(xcconfigLinkerFlags),
|
|
331
|
-
iosDeploymentTarget: versions.sort(compareVersions).pop() ?? null,
|
|
332
201
|
};
|
|
333
202
|
}
|
|
334
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Everything the plugin reads from a pod's podspecs, read once per pod. Linkage is
|
|
206
|
+
* looked for beside the pod and in the module's source directories and root;
|
|
207
|
+
* dependencies are read from every podspec in the pod's own directory, so a pod
|
|
208
|
+
* sharing it with siblings reports theirs too.
|
|
209
|
+
*/
|
|
210
|
+
function readPodspecFacts({ podName, podspecDir, moduleRoot }) {
|
|
211
|
+
const dirs = [
|
|
212
|
+
podspecDir,
|
|
213
|
+
...APPLE_SOURCE_DIRS.map((dir) => path.join(moduleRoot, dir)),
|
|
214
|
+
moduleRoot,
|
|
215
|
+
].filter(Boolean);
|
|
216
|
+
const dependencies = new Set(
|
|
217
|
+
podspecsIn(podspecDir).flatMap((file) => podspecDependencies(readText(file) ?? ''))
|
|
218
|
+
);
|
|
219
|
+
return { ...readPodspecs(podName, dirs), dependencies: [...dependencies] };
|
|
220
|
+
}
|
|
221
|
+
|
|
335
222
|
module.exports = {
|
|
336
|
-
PodspecSyntaxError,
|
|
337
223
|
podspecBodyLines,
|
|
224
|
+
podspecDependencies,
|
|
338
225
|
linkageDeclaration,
|
|
339
226
|
xcconfigLinkerFlags,
|
|
340
|
-
readIosFloor,
|
|
341
227
|
readPodspecs,
|
|
228
|
+
readPodspecFacts,
|
|
342
229
|
};
|
|
@@ -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
|
-
}
|