Skip to content

perf(load): load typescript configs with jiti directly - #5052

Merged
escapedcat merged 2 commits into
masterfrom
fix/load-drop-typescript-peer
Oct 13, 2026
Merged

escapedcat merged 2 commits into
masterfrom
fix/load-drop-typescript-peer

Conversation

@escapedcat

@escapedcat escapedcat commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Description

Replaces cosmiconfig-typescript-loader in @commitlint/load with a direct jiti dependency and an inlined loader.

cosmiconfig-typescript-loader is about 15 lines around jiti, but it declares typescript >=5 and @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: jiti does the transpiling itself.

jiti is 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):

Size Packages
Before 42.6 MB 73
After 10.1 MB 51

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, .mts and .cts configs load as before:

// commitlint.config.ts
import type { UserConfig } from "@commitlint/types";

const config: UserConfig = { extends: ["@commitlint/config-conventional"] };
export default config;
echo "feat: add thing" | commitlint # passes

How Has This Been Tested?

  • New test @commitlint/load/src/dependencies.test.ts fails if any runtime dependency of @commitlint/load requires typescript or @types/node as a non-optional peer. First commit is red, second is green.
  • pnpm build, pnpm format, pnpm lint and pnpm test pass locally (92 files, 1261 tests).
  • Installed the published 21.2.3 CLI with the patched @commitlint/load overridden in: no typescript or @types/node in the tree, and a commitlint.config.ts still lints.
  • On a published 21.2.3 install with typescript and @types/node deleted by hand, .ts, .mts and .cts configs (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's TypeScriptCompileError class.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have verified that any documentation examples I added/changed actually work.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • For a feature/bug fix, my commits follow the test-driven flow: a failing-test commit, then the implementation.

🤖 Generated with Claude Code

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>
@escapedcat
escapedcat requested a balanced review from Copilot October 13, 2026 14:19
@escapedcat escapedcat changed the title fix(load): load typescript configs with jiti directly perf(load): load typescript configs with jiti directly Oct 13, 2026
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>
@escapedcat
escapedcat force-pushed the fix/load-drop-typescript-peer branch from 9c5cdba to 30a79c6 Compare October 13, 2026 14:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[High impact] Replaces TypeScript config loader dependency.

The PR appears safe to merge, with a non-blocking gap in the new dependency test.

Findings

  1. P2 Child packages escape the check ▶

Reviews (1) · Last reviewed commit: "perf(load): load typescript configs with..." · Reviewed by Greptile

Comment on lines +22 to +23
const requiring = Object.keys(dependencies).filter((name) => {
const manifest = readManifest(path.join(packageDir, "node_modules", name));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 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.

@escapedcat
escapedcat added this pull request to the merge queue Oct 13, 2026
Merged via the queue into master with commit 3103b86 Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants