|
1 | 1 | import { ReadableStream } from 'web-streams-polyfill'; |
2 | | -// eslint-disable-next-line no-undef |
3 | | -global.ReadableStream = ReadableStream; |
| 2 | +import { Blob } from 'buffer'; |
| 3 | +import { MessageChannel, MessagePort } from 'worker_threads'; |
| 4 | + |
| 5 | +// File class polyfill for Node.js environments |
| 6 | +class File extends Blob { |
| 7 | + name: string; |
| 8 | + lastModified: number; |
| 9 | + |
| 10 | + constructor( |
| 11 | + chunks: Array<ArrayBuffer | ArrayBufferView | Blob | string>, |
| 12 | + name: string, |
| 13 | + options?: { type?: string; lastModified?: number }, |
| 14 | + ) { |
| 15 | + super(chunks as unknown as Array<ArrayBuffer | Blob>, options); |
| 16 | + this.name = name; |
| 17 | + this.lastModified = options?.lastModified ?? Date.now(); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +// DOMException polyfill |
| 22 | +class DOMException extends Error { |
| 23 | + code: number; |
| 24 | + constructor(message?: string, name?: string) { |
| 25 | + super(message); |
| 26 | + this.name = name || 'Error'; |
| 27 | + this.code = 0; |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// eslint-disable-next-line no-undef, @typescript-eslint/no-explicit-any |
| 32 | +(global as any).ReadableStream = ReadableStream; |
| 33 | +// eslint-disable-next-line no-undef, @typescript-eslint/no-explicit-any |
| 34 | +(global as any).Blob = Blob; |
| 35 | +// eslint-disable-next-line no-undef, @typescript-eslint/no-explicit-any |
| 36 | +(global as any).File = File; |
| 37 | +// eslint-disable-next-line no-undef, @typescript-eslint/no-explicit-any |
| 38 | +(global as any).MessagePort = MessagePort; |
| 39 | +// eslint-disable-next-line no-undef, @typescript-eslint/no-explicit-any |
| 40 | +(global as any).MessageChannel = MessageChannel; |
| 41 | +// eslint-disable-next-line no-undef, @typescript-eslint/no-explicit-any |
| 42 | +(global as any).DOMException = DOMException; |
0 commit comments