mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-25 07:42:11 +00:00
refactor(shim): Move node CustomEvent polyfill to Platform.shim (#357)
This commit is contained in:
@@ -105,7 +105,8 @@ Platform.load({
|
||||
Headers: globalThis.Headers,
|
||||
FormData: globalThis.FormData,
|
||||
File: globalThis.File,
|
||||
ReadableStream: globalThis.ReadableStream
|
||||
ReadableStream: globalThis.ReadableStream,
|
||||
CustomEvent: globalThis.CustomEvent
|
||||
});
|
||||
|
||||
export * from './lib.js';
|
||||
|
||||
@@ -17,6 +17,7 @@ import os from 'os';
|
||||
import fs from 'fs/promises';
|
||||
import { readFileSync } from 'fs';
|
||||
import DOMParser from './polyfills/server-dom.js';
|
||||
import CustomEvent from './polyfills/node-custom-event.js';
|
||||
import { fileURLToPath } from 'url';
|
||||
import evaluate from './jsruntime/jinter.js';
|
||||
|
||||
@@ -123,7 +124,8 @@ Platform.load({
|
||||
Headers: Headers as unknown as typeof globalThis.Headers,
|
||||
FormData: FormData as unknown as typeof globalThis.FormData,
|
||||
File: File as unknown as typeof globalThis.File,
|
||||
ReadableStream: ReadableStream as unknown as typeof globalThis.ReadableStream
|
||||
ReadableStream: ReadableStream as unknown as typeof globalThis.ReadableStream,
|
||||
CustomEvent: CustomEvent as unknown as typeof globalThis.CustomEvent
|
||||
});
|
||||
|
||||
export * from './lib.js';
|
||||
|
||||
13
src/platform/polyfills/node-custom-event.ts
Normal file
13
src/platform/polyfills/node-custom-event.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
// See https://github.com/nodejs/node/issues/40678#issuecomment-1126944677
|
||||
export default class CustomEvent extends Event {
|
||||
#detail;
|
||||
|
||||
constructor(type: string, options?: CustomEventInit<any[]>) {
|
||||
super(type, options);
|
||||
this.#detail = options?.detail ?? null;
|
||||
}
|
||||
|
||||
get detail() {
|
||||
return this.#detail;
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,8 @@ Platform.load({
|
||||
Headers: globalThis.Headers,
|
||||
FormData: globalThis.FormData,
|
||||
File: globalThis.File,
|
||||
ReadableStream: globalThis.ReadableStream
|
||||
ReadableStream: globalThis.ReadableStream,
|
||||
CustomEvent: globalThis.CustomEvent
|
||||
});
|
||||
|
||||
export * from './lib.js';
|
||||
|
||||
Reference in New Issue
Block a user