Skip to content

Conversation

@slimbuck
Copy link
Member

@slimbuck slimbuck commented Sep 9, 2025

This PR:

  • swap sharp for libwebp compiled to wasm
  • add a stub for global window, document and canvas to replace jsdom and node-canvas

This results in no functionality change, but means we have a smaller dependency footprint resulting in (hopefully) fewer issues across the various platforms.

Also might help with bundling to binary.

@slimbuck slimbuck requested review from a team and Copilot September 9, 2025 13:22
@slimbuck slimbuck self-assigned this Sep 9, 2025
@slimbuck slimbuck added the enhancement New feature or request label Sep 9, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes dependencies on sharp, jsdom, and node-canvas by replacing them with custom implementations to reduce the dependency footprint and improve cross-platform compatibility.

  • Replaces sharp image processing with a custom WebP encoder compiled to WASM
  • Replaces jsdom and node-canvas with minimal stubs for browser APIs
  • Updates build configuration to exclude the removed dependencies

Reviewed Changes

Copilot reviewed 10 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/writers/write-sog.ts Replaces sharp WebP encoding with custom WebpEncoder and adds file writing utility
src/utils/webp.ts Implements new WebpEncoder class using WASM-compiled libwebp
src/process.ts Renames process function to processDataTable to avoid naming conflicts
src/index.ts Updates imports to use renamed processDataTable function
src/gpu/gpu-device.ts Replaces jsdom with minimal stubs for window, document, and canvas APIs
rollup.config.mjs Removes sharp and jsdom from external dependencies
package.json Removes canvas, jsdom, and sharp dependencies; adds lib/ to files
lib/webp_encode.mjs Adds WASM-compiled WebP encoder module
lib/webp_encode.c Adds C source code for WebP encoding functions
lib/BUILD.md Adds build instructions for the WebP WASM module

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool indeed!

@slimbuck slimbuck merged commit b51a35b into playcanvas:main Sep 9, 2025
2 checks passed
@slimbuck slimbuck deleted the canvas-dev branch September 9, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants