Skip to content

Conversation

@jdalton
Copy link
Contributor

@jdalton jdalton commented Nov 6, 2025

Summary

Convert lazy require() calls to static ES module imports in lib-internal package for better bundling and tree-shaking.

Changes

package-extensions.ts

// Before
const yarnPkgExtensions = require('@yarnpkg/extensions')

// After
import yarnPkgExtensions from '@yarnpkg/extensions'

prompts.ts

// Before
const confirmExport = /*@__PURE__*/ require('@inquirer/confirm')
const confirmRaw = confirmExport.default ?? confirmExport
// ... similar for input, password, search, select

// After
import confirm from '@inquirer/confirm'
import input from '@inquirer/input'
// ... etc
const confirmRaw = confirm

Benefits

✅ Better bundling - static imports enable tree-shaking
✅ Cleaner code - no more default ?? fallback patterns
✅ Consistent style - aligns with ES module best practices
✅ Improved performance - eliminates runtime require() resolution

Test Plan

  • Type check passes
  • Security checks pass
  • Verify prompt functionality in interactive commands
  • Verify package extensions work correctly

Impact

Low risk - Simple import conversion with no logic changes. The same modules are loaded, just with static imports instead of dynamic require().

Convert lazy require() calls to static ES module imports for better
bundling and tree-shaking. Aligns with broader effort to eliminate
dynamic require() usage across the codebase.

Changes:
- package-extensions.ts: Import @yarnpkg/extensions as ES module
- prompts.ts: Replace require() with static imports for @inquirer/* modules
- Simplify raw variable assignments (no more default ?? fallback)
@jdalton jdalton closed this Nov 8, 2025
@jdalton jdalton deleted the jdalton/refactor-lib-internal-imports branch November 8, 2025 15:59
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.

2 participants