|
1 | 1 | import { ResolvableFile } from '../classes/resolvable-file.ts' |
| 2 | +import { uninstallSetImmediatePolyfill } from './set-immediate-polyfill.ts' |
2 | 3 | import { vendors } from './vendors.ts' |
3 | 4 |
|
| 5 | +export { installSetImmediatePolyfill, uninstallSetImmediatePolyfill } from './set-immediate-polyfill.ts' |
| 6 | + |
4 | 7 | const { path } = vendors |
5 | 8 |
|
6 | 9 | export const textEncoder = new TextEncoder() |
@@ -238,49 +241,3 @@ export function isZip(uint8Array: Uint8Array) { |
238 | 241 | (uint8Array[3] === 0x04 || uint8Array[3] === 0x06 || uint8Array[3] === 0x08) |
239 | 242 | ) |
240 | 243 | } |
241 | | - |
242 | | -const originalSetImmediate = globalThis.setImmediate |
243 | | -let __nostalgist_setImmediate_channel: MessageChannel | null = null |
244 | | -const __nostalgist_setImmediate_queue: Array<() => void> = [] |
245 | | - |
246 | | -function setImmediatePolyfill(callback: any) { |
247 | | - if (typeof originalSetImmediate === 'function') { |
248 | | - return originalSetImmediate(callback) |
249 | | - } |
250 | | - |
251 | | - if (typeof MessageChannel !== 'undefined') { |
252 | | - if (!__nostalgist_setImmediate_channel) { |
253 | | - __nostalgist_setImmediate_channel = new MessageChannel() |
254 | | - __nostalgist_setImmediate_channel.port1.onmessage = () => { |
255 | | - const fn = __nostalgist_setImmediate_queue.shift() |
256 | | - if (fn) { |
257 | | - try { |
258 | | - fn() |
259 | | - } catch {} |
260 | | - } |
261 | | - } |
262 | | - } |
263 | | - __nostalgist_setImmediate_queue.push(callback) |
264 | | - __nostalgist_setImmediate_channel.port2.postMessage(0) |
265 | | - return 0 |
266 | | - } |
267 | | - |
268 | | - // fallback to setTimeout |
269 | | - // eslint-disable-next-line @typescript-eslint/no-implied-eval |
270 | | - return setTimeout(callback, 0) |
271 | | -} |
272 | | - |
273 | | -export function installSetImmediatePolyfill() { |
274 | | - if (typeof globalThis.setImmediate === 'function') { |
275 | | - return |
276 | | - } |
277 | | - // @ts-expect-error polyfill |
278 | | - globalThis.setImmediate = setImmediatePolyfill |
279 | | -} |
280 | | - |
281 | | -export function uninstallSetImmediatePolyfill() { |
282 | | - if (globalThis.setImmediate === setImmediatePolyfill) { |
283 | | - // @ts-expect-error remove polyfill |
284 | | - delete globalThis.setImmediate |
285 | | - } |
286 | | -} |
0 commit comments