Skip to content

perf: import the types only by import type, and load the conflicter, execa and which-package-manager when used - #875

Merged
mshima merged 1 commit into
yeoman:mainfrom
mshima:lazy-imports
Oct 21, 2026
Merged

mshima merged 1 commit into
yeoman:mainfrom
mshima:lazy-imports

Conversation

@mshima

@mshima mshima commented Oct 21, 2026

Copy link
Copy Markdown
Member

Summary

  • import type: five imports of types only were written import { type A } from '…'. With verbatimModuleSyntax, TypeScript keeps an import {} from '…' of their module in the JavaScript: the whole mem-fs-editor (for MemFsEditorFile) and the conflicter (for ConflicterOptions) were loaded for a type. They are import type, and @typescript-eslint/no-import-type-side-effects forbids the inline form.
  • The conflicter is imported by commitSharedFsTask, at the commit only.
  • execa and which-package-manager are imported by packageManagerInstallTask, at an install only.
  • test/generator-features.ts resets the module mocks once for the file: reset after the first version of the generator, the later ones ran the actual execa, which the install now imports when it runs.

Benchmark

Importing yeoman-environment:

modules import time
before 405 133–134 ms
after 190 95–97 ms

Test plan

  • npm test (eslint, prettier, tsc, the tests), and the tests with 2 and 4 workers
  • No import {} from left in dist

🤖 Generated with Claude Code

…execa and which-package-manager when used

- The imports of types only written `import { type A }` kept an import of
  their module in the JavaScript emitted by verbatimModuleSyntax: the whole
  mem-fs-editor and the conflicter were loaded for a type. They are
  `import type`, and @typescript-eslint/no-import-type-side-effects forbids
  them.
- The conflicter is imported by the commit, execa and which-package-manager
  by an install.

Importing the environment loads 190 modules, 405 before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mshima
mshima merged commit 37e7a80 into yeoman:main Oct 21, 2026
15 of 16 checks passed
@mshima
mshima deleted the lazy-imports branch October 21, 2026 13:57
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.

1 participant