Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blueprints: add support for NodeJS #576

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/php-wasm/progress/src/lib/progress-tracker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/**
* CustomEvent class for NodeJS
* @see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
*/
class CustomEventNode<T = any> extends Event {
detail: T;

constructor(type: string, customEventInit?: CustomEventInit<T>) {
super(type, customEventInit);
this.detail = customEventInit?.detail
? customEventInit.detail
: ({} as T);
}
}

if (typeof CustomEvent === 'undefined') {
// @ts-expect-error
globalThis.CustomEvent = CustomEventNode;
}

/**
* Options for customizing the progress tracker.
*/
Expand Down
12 changes: 12 additions & 0 deletions packages/playground/blueprints/src/lib/steps/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ export async function updateFile(
export async function fileToUint8Array(file: File) {
return new Uint8Array(await file.arrayBuffer());
}
/**
* File class for NodeJS
* @see https://developer.mozilla.org/en-US/docs/Web/API/File
*/
class FileNode {
// NodeJS has no File class
}

if (typeof File === 'undefined') {
// @ts-expect-error
globalThis.File = FileNode;
}

/**
* Polyfill the File class in JSDOM which lacks arrayBuffer() method
Expand Down