Skip to content

Added knip#1701

Open
nico-martin wants to merge 7 commits into
mainfrom
nico/knip
Open

Added knip#1701
nico-martin wants to merge 7 commits into
mainfrom
nico/knip

Conversation

@nico-martin

@nico-martin nico-martin commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

At React Norway I listened to a talk by @TkDodo about knip.

With this I added a knip command to npm that checks fo unused dependencies and unused code in Transformers.js. It already found a couple of lines. @xenova, do you think it makes sense to keep it in the project?

Summary

  • Add Knip to the monorepo with a workspace-aware configuration for root scripts and packages/transformers.
  • Add a dedicated knip CI job in the unit test workflow using Node.js 24.10.0.
  • Fix dependency issues surfaced by Knip by declaring direct imports and removing unused Jest environment dependency.
  • Resolve unused and duplicate export findings by making internal helpers local, removing dead helpers/constants, and preserving compatibility exports without duplicate aliases.
  • Fix a stale JSDoc import path in tokenizer tests.

@nico-martin nico-martin requested a review from xenova June 6, 2026 16:20
@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 left a comment

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.

Very cool! It definitely caught some old/dead code and other code smells (unused exports, etc.)

I think I need to start using knip for a currently-unreleased library I'm working on 🤫

My one minor gripe with the library is that it introduces quite a few dev dependencies, but since it's quite a well-used library across the ecosystem, I don't see this as a blocker. We also so happen to be removing many other dev dependencies in #1665, so we can consider it a fair swap haha.

PS: Big fan of @TkDodo ❤️ -- would love to see the talk if it's available online?

Comment thread package.json Outdated
Comment on lines +66 to 72
"@jest/globals": "30.2.0",
"@types/jest": "^30.0.0",
"@types/node": "^24.1.0",
"@webgpu/types": "^0.1.69",
"esbuild": "^0.27.2",
"jest": "^30.2.0",
"jest-environment-node": "^30.2.0",
"jsdoc-to-markdown": "^9.1.3",

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.

can you explain the jest-environment-node -> jest/globals package change?

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.

This was one of the suggestions from knip since we don't use it.

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.

Oh and about the "@jest/globals": knip found that we import @jest/globals in two places in the project but we don't have it in the dependencies. It never caused an issue because I think its still somewhere in the dependency tree, but as I said in the "onnxruntime-common", whenever we import a package directly, we should also have it in our dependencies.

"dependencies": {
"@huggingface/jinja": "^0.5.6",
"@huggingface/tokenizers": "^0.1.3",
"onnxruntime-common": "1.24.3",

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 remember someone mentioned this before, but since onnxruntime-node and onnxruntime-web depend on it, I don't think it's necessary to define here.

but I suppose if there is a mismatch one day between e.g., Tensor from onnxruntime-node and onnxruntime-web, it may cause some issues.

Lmk what you think!

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.

I think we should keep this as a direct dependency because @huggingface/transformers imports onnxruntime-common directly. And in my opinion as soon as we have a direct import, we should have it as a direct dependency and not rely on being provided by sub-dependencies.

The version mismatch concern is valid, but declaring it directly makes the resolved version explicit instead of depending on hoisting. If ORT node/web diverge further, we should probably revisit the ORT versions together rather than rely on a transitive copy.

Comment thread .github/workflows/tests.yml
Comment thread packages/transformers/src/utils/core.js
Comment thread knip.json Outdated
@nico-martin

Copy link
Copy Markdown
Collaborator Author

@xenova, btw, the talk is online 😊:
https://www.youtube.com/live/Ge0DbLf-2R0?si=omYvDPwNaD9_k5DV&t=10975

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