Repository navigation
perf(load): load typescript configs with jiti directly - #5052
Conversation
Failing test: cosmiconfig-typescript-loader declares typescript and @types/node as required peers, so npm and pnpm install both for every commitlint user. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cosmiconfig-typescript-loader is a thin wrapper around jiti that declares typescript and @types/node as required peers. npm and pnpm auto-install those, so users without their own TypeScript downloaded ~32 MB that nothing imports at runtime. Call jiti from the loader instead. A fresh install of @commitlint/cli and @commitlint/config-conventional goes from 42.6 MB to 10.1 MB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9c5cdba to
30a79c6
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The inline loader preserves existing behavior while removing unnecessary required peer dependencies.
0 open findings
What changed in this PR
Replaces the TypeScript config loader wrapper with direct jiti usage, reducing installation size without changing supported config formats.
Changes:
- Adds an inline lazy TypeScript loader using
jiti. - Replaces the wrapper dependency and adds a peer-dependency regression test.
- Updates dependency resolution metadata.
| File | Description |
|---|---|
@commitlint/load/src/utils/load-config.ts |
Implements TypeScript config loading directly with jiti. |
@commitlint/load/src/dependencies.test.ts |
Guards against required TypeScript-related peers. |
@commitlint/load/package.json |
Replaces the wrapper dependency with jiti. |
pnpm-lock.yaml |
Updates resolved dependencies. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
| const requiring = Object.keys(dependencies).filter((name) => { | ||
| const manifest = readManifest(path.join(packageDir, "node_modules", name)); |
There was a problem hiding this comment.
Child packages escape the check
The new test checks required peers only on direct dependencies. If one of those packages adds a child package that requires typescript or @types/node as a peer, users will download it while this test still passes. Walk the runtime dependency tree, resolving each child from its parent, so the guard also catches required peers further down.
Description
Replaces
cosmiconfig-typescript-loaderin@commitlint/loadwith a directjitidependency and an inlined loader.cosmiconfig-typescript-loaderis about 15 lines aroundjiti, but it declarestypescript >=5and@types/node *as required peer dependencies. npm and pnpm auto-install required peers, so every user without their own TypeScript gets both. Nothing imports them at runtime:jitidoes the transpiling itself.jitiis already in every commitlint install through the loader, so no new package enters the tree.Motivation and Context
Install size. Fresh
npm install @commitlint/cli @commitlint/config-conventional(macOS arm64, 21.2.3):TypeScript 7's native binary alone is 27.5 MB of the "before" number. Projects that already have TypeScript installed see no difference.
Came out of reviewing #5051, where
es-toolkit(4.2 MB) was the target.Usage examples
No change in usage.
.ts,.mtsand.ctsconfigs load as before:How Has This Been Tested?
@commitlint/load/src/dependencies.test.tsfails if any runtime dependency of@commitlint/loadrequirestypescriptor@types/nodeas a non-optional peer. First commit is red, second is green.pnpm build,pnpm format,pnpm lintandpnpm testpass locally (92 files, 1261 tests).@commitlint/loadoverridden in: notypescriptor@types/nodein the tree, and acommitlint.config.tsstill lints.typescriptand@types/nodedeleted by hand,.ts,.mtsand.ctsconfigs (type imports, an enum,satisfies) still load. A config with a type error loads the same with and without TypeScript, so no type-checking is lost.One behaviour note: load failures keep the
TypeScriptLoader failed to compile TypeScript:message prefix, but the error is no longer an instance of the loader'sTypeScriptCompileErrorclass.Types of changes
Checklist:
🤖 Generated with Claude Code