Skip to content

V4 move to pnpm workspaces#1504

Merged
xenova merged 54 commits intov4from
v4-pnpm-workspaces
Jan 29, 2026
Merged

V4 move to pnpm workspaces#1504
xenova merged 54 commits intov4from
v4-pnpm-workspaces

Conversation

@nico-martin
Copy link
Copy Markdown
Collaborator

@nico-martin nico-martin commented Jan 22, 2026

This PR is a proposal to move to pnpm workspaces.

why workspaces?
Right we have only one package: @huggingface/transformers
So everything we ship can be used from this one package. In the future we also want to be able to ship small, domain specific packages. For example a framework specific package @huggingface/transformers-reactor maybe abstractions like a text-generation package that is compatible with the Responses API @huggingface/transformers-responses.
Using workspaces will allow us to ship those small packages that depend on @huggingface/transformers without the overhead of individual repos.

why pnpm?
Pnpm is a package manager for NodeJS that brings a lot of benefits especially in how it handles disk space.
pnpm stores each package version once in a global store and hard-links it to all workspaces that need it, which avoids the disk space waste of npm duplicating packages everywhere. The symlink-based node_modules structure means packages can only import what they explicitly declare as dependencies, preventing the "works on my machine" issues where code accidentally relies on hoisted packages.
The workspace:* protocol links local packages during development and converts to real versions when you publish, and installs are faster because pnpm fetches packages in parallel and reuses everything from the global store. You just need a pnpm-workspace.yaml file to set it up.
Also pnpm seems to be the standard for workspaces in the npm ecosystem, since big repos like Vercel AI SDK, langchainjs and others are using it.

@nico-martin nico-martin requested a review from xenova January 22, 2026 14:47
@nico-martin nico-martin changed the title V4 mover to pnpm workspaces V4 move to pnpm workspaces Jan 22, 2026
Copy link
Copy Markdown
Collaborator

@xenova xenova left a comment

Choose a reason for hiding this comment

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

Very nice! I think we should add some docs (either a new CONTRIBUTING.md or in README.md), which explains the new repo structure and how things tie together. When we add react-transformers, we can document how the multi-dev-server works.

Some other comments:

Comment thread package.json Outdated
Comment thread packages/transformers/package.json Outdated
Comment thread .github/workflows/publish.yml
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should define per-package github workflow tests. Kind of like https://github.com/huggingface/huggingface.js/tree/main/.github/workflows. WDYT?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You mean publish workflows per package? Definitely makes sense.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yep exactly. This can be a follow-up PR.

Comment thread packages/transformers/scripts/esbuild/build/plugins/postBuildPlugin.mjs Outdated
Comment thread packages/transformers/scripts/esbuild/build/constants.mjs Outdated
Comment thread packages/transformers/src/models/vits/tokenization_vits.js
Comment thread packages/transformers/tsconfig.json Outdated
Comment thread .gitignore Outdated
Copy link
Copy Markdown
Collaborator

@xenova xenova left a comment

Choose a reason for hiding this comment

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

PR's looking pretty good imo! 🙌 I made a couple of fixes for documentation generation, and I've now tested it with hf-doc-builder, and everything seems to be correct. In case you want to run it locally, you can:

  1. install https://github.com/huggingface/doc-builder from source (pip install --upgrade git+https://github.com/huggingface/doc-builder)
  2. in packages/transformers, run pnpm docs-api, then doc-builder build transformers.js ./docs/source/ --not_python_module --build_dir ./docs/build/, then doc-builder preview transformers.js ./docs/source/ --not_python_module.
You should then see something like this Image

Some things you may be able to check out:

  1. Our root directory is filled with lots of config files. Can we find a way to reduce this count? e.g., are both tsconfig files necessary (do we need one in the root, if we have on a per-project level)?
  2. We should add a solid CONTRIBUTING.md, probably following from your work in #1433, including how the project is structured, the build process, opening PRs, etc.
  3. We dynamically build the Transformers.js README.md, (pnpm readme), but we don't want to commit duplicates of this file. On the other hand, when publishing, we would need the README.md inside of the packages/transformers folder. On that note, we would probably eventually need to make the monorepo README different from the transformers.js README (where the monorepo README explains the project structure).
  4. Some pages (e.g., api/tokenizers) contain many unnecessary sections (because these are exported by the module). Perhaps we can find a way with https://www.npmjs.com/package/jsdoc-to-markdown to filter definitions to only be visible when this is a global export of transformers.js
  5. Documentation improvements, as a whole, would be most welcomed (in a separate PR), and the doc builder would then be able to include code snippets inside the generated docs.

@nico-martin
Copy link
Copy Markdown
Collaborator Author

@xenova, I added a CONTRIBUTING.md and did some changes to the config files. Unfortunately I dont think we can remove more files.
For the readme/documentation stuff I think we should open another PR.

Copy link
Copy Markdown
Collaborator

@xenova xenova left a comment

Choose a reason for hiding this comment

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

LGTM ✅

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@xenova xenova merged commit 4e1b4b6 into v4 Jan 29, 2026
1 check passed
@xenova xenova deleted the v4-pnpm-workspaces branch January 29, 2026 03:34
AaronRohrbacher pushed a commit to AaronRohrbacher/transformers.js that referenced this pull request Apr 16, 2026
* switched to pnpm workspaces

* updated github actions

* added comments

* Update tensor.js

* Formatting

* Update tsconfig.json

* Update tsconfig.json

* fixed circular reference error in pipelines/zero-shot-audio-classification.js

* Post-tsconfig updates

* Move transformers.js docs to package folder

* Move additional tests

* JSDoc update

* Version bumps

* Update incorrect test

* Update test_modeling_musicgen.js

* Update test_modeling_musicgen.js

* Update test_modeling_musicgen.js

* fixed broken symlink

* fixes after review

* Remove old conversion scripts

Users should use onnxruntime-genai or optimum directly

* Update .prettierrc

* Formatting

* Update readme/docs

* Move build scripts to parent folder

* Remove unused tests

* Remove old compare function

* Fix JSDoc

* Update generate.js

* Update inline descriptions

* Bump versions

* Update node imports

* Add module header to FileCache.js

* JSDoc updates

* Update tensor.js

* Move prettier config to package.json key

* Update FileCache.js

* Remove unused import

* Remove non-existent file include

* Prefer non-default exports

* Update doc module exports

* Update docs generation script

* merged tsconfigs and added contributing.md

* Update path_to_docs

* Formatting

* Formatting

* Formatting

* Update prettier usage

* Remove <code> tags from headers

* Swap docs-preview and docs-build commands

* ONNXRUNTIME_NODE_INSTALL=skip for doc-builder

* Update buildAll.mjs

* Update index

---------

Co-authored-by: Joshua Lochner <26504141+xenova@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants