[PR #1] [MERGED] Replace sharp dependency with jimp 1.6.0 #2

Closed
opened 2026-10-15 18:08:50 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/SillyTavern/transformers.js/pull/1
Author: @Copilot
Created: 3/13/2026
Status: ✅ Merged
Merged: 3/15/2026
Merged by: @Cohee1207

Base: main ← Head: copilot/replace-sharp-with-jimp


📝 Commits (3)

  • bb4e49c Initial plan
  • 550597f Replace sharp dependency with jimp 1.6.0
  • 68f29bf Address code review comments with clarifying comments

📊 Changes

8 files changed (+680 additions, -369 deletions)

View changed files

📝 packages/transformers/docs/source/tutorials/next-ai-sdk.md (+1 -1)
📝 packages/transformers/docs/source/tutorials/next.md (+2 -2)
📝 packages/transformers/package.json (+1 -1)
📝 packages/transformers/scripts/build/constants.mjs (+2 -2)
📝 packages/transformers/scripts/build/plugins/ignoreModulesPlugin.mjs (+4 -1)
📝 packages/transformers/src/utils/image.js (+67 -84)
📝 pnpm-lock.yaml (+603 -277)
📝 pnpm-workspace.yaml (+0 -1)

📄 Description

Replaces the native sharp image processing library with jimp@1.6.0, a pure JavaScript alternative that requires no native compilation.

src/utils/image.js

  • import sharp → import { Jimp, ResizeStrategy } from 'jimp'
  • loadImageFunction returns RGBA (4 channels, same as browser path); callers .convert() back to original channel count
  • fromBlob: Jimp.fromBuffer() replaces sharp(buffer)
  • resize: img.resize({w, h, mode}) with ResizeStrategy enum replaces .affine() / .resize(). Lanczos falls back to bicubic (jimp has no lanczos kernel).
  • pad: composite onto a new larger Jimp instance replaces .extend()
  • crop / center_crop: img.crop() replaces .extract(); padding cases use composite() + crop()
  • save: img.write(path) replaces .toFile(path)
  • toSharp() → toJimp(): converts to RGBA via .clone().rgba() then Jimp.fromBitmap()

Build config

  • constants.mjs: sharp → jimp in NODE_EXTERNAL_MODULES and WEB_IGNORE_MODULES
  • ignoreModulesPlugin.mjs: stub exports Jimp and ResizeStrategy named exports for web builds

Docs & workspace

  • Next.js tutorial webpack aliases and serverComponentsExternalPackages updated
  • pnpm-workspace.yaml: removed sharp from onlyBuiltDependencies

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • huggingface.co
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node --experimental-vm-modules --expose-gc node_modules/jest/bin/jest.js --verbose --logHeapUsage tests/utils/image.test.js _TOKEN"; }; f (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node --experimental-vm-modules --expose-gc node_modules/jest/bin/jest.js --verbose tests/utils/image.test.js (dns block)
  • www.npmjs.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/SillyTavern/transformers.js/pull/1 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 3/15/2026 **Merged by:** [@Cohee1207](https://github.com/Cohee1207) **Base:** `main` ← **Head:** `copilot/replace-sharp-with-jimp` --- ### 📝 Commits (3) - [`bb4e49c`](https://github.com/SillyTavern/transformers.js/commit/bb4e49c786c5a4705c6ab589c30c8ecb95c014c5) Initial plan - [`550597f`](https://github.com/SillyTavern/transformers.js/commit/550597f0fbf14f71fb16e447b8abd040d83c470d) Replace sharp dependency with jimp 1.6.0 - [`68f29bf`](https://github.com/SillyTavern/transformers.js/commit/68f29bf5a01f82113cdeaffbe613b57a29497e47) Address code review comments with clarifying comments ### 📊 Changes **8 files changed** (+680 additions, -369 deletions) <details> <summary>View changed files</summary> 📝 `packages/transformers/docs/source/tutorials/next-ai-sdk.md` (+1 -1) 📝 `packages/transformers/docs/source/tutorials/next.md` (+2 -2) 📝 `packages/transformers/package.json` (+1 -1) 📝 `packages/transformers/scripts/build/constants.mjs` (+2 -2) 📝 `packages/transformers/scripts/build/plugins/ignoreModulesPlugin.mjs` (+4 -1) 📝 `packages/transformers/src/utils/image.js` (+67 -84) 📝 `pnpm-lock.yaml` (+603 -277) 📝 `pnpm-workspace.yaml` (+0 -1) </details> ### 📄 Description Replaces the native `sharp` image processing library with `jimp@1.6.0`, a pure JavaScript alternative that requires no native compilation. ### `src/utils/image.js` - `import sharp` → `import { Jimp, ResizeStrategy } from 'jimp'` - `loadImageFunction` returns RGBA (4 channels, same as browser path); callers `.convert()` back to original channel count - `fromBlob`: `Jimp.fromBuffer()` replaces `sharp(buffer)` - `resize`: `img.resize({w, h, mode})` with `ResizeStrategy` enum replaces `.affine()` / `.resize()`. Lanczos falls back to bicubic (jimp has no lanczos kernel). - `pad`: composite onto a new larger `Jimp` instance replaces `.extend()` - `crop` / `center_crop`: `img.crop()` replaces `.extract()`; padding cases use `composite()` + `crop()` - `save`: `img.write(path)` replaces `.toFile(path)` - `toSharp()` → `toJimp()`: converts to RGBA via `.clone().rgba()` then `Jimp.fromBitmap()` ### Build config - `constants.mjs`: `sharp` → `jimp` in `NODE_EXTERNAL_MODULES` and `WEB_IGNORE_MODULES` - `ignoreModulesPlugin.mjs`: stub exports `Jimp` and `ResizeStrategy` named exports for web builds ### Docs & workspace - Next.js tutorial webpack aliases and `serverComponentsExternalPackages` updated - `pnpm-workspace.yaml`: removed `sharp` from `onlyBuiltDependencies` > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `huggingface.co` > - Triggering command: `/home/REDACTED/work/_temp/ghcca-node/node/bin/node node --experimental-vm-modules --expose-gc node_modules/jest/bin/jest.js --verbose --logHeapUsage tests/utils/image.test.js _TOKEN&#34;; }; f` (dns block) > - Triggering command: `/home/REDACTED/work/_temp/ghcca-node/node/bin/node node --experimental-vm-modules --expose-gc node_modules/jest/bin/jest.js --verbose tests/utils/image.test.js` (dns block) > - `www.npmjs.com` > - Triggering command: `/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/SillyTavern/transformers.js/settings/copilot/coding_agent) (admins only) > > </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Send tasks to Copilot coding agent from [Slack](https://gh.io/cca-slack-docs) and [Teams](https://gh.io/cca-teams-docs) to turn conversations into code. Copilot posts an update in your thread when it's finished. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-15 18:08:50 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
SillyTavern/transformers.js#2
No description provided.