Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

youaresoyoung
Copy link

@youaresoyoung youaresoyoung commented Sep 12, 2025

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • The changes are appropriately documented (if applicable).
  • The changes have sufficient test coverage (if applicable).
  • The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:

ref

Summary

This PR improves support for alternative package managers (pnpm, Yarn Berry) during project initialization.
Previously, npx create-electron-app resolved to npm at init time (because lockfiles don’t exist yet and npx sets the npm user agent). As a result, templates depending on pnpm/yarn–specific setup were silently misconfigured.

This change allows users to explicitly choose a package manager via CLI prompt or --package-manager flag, and ensures that decision is consistently propagated through the init pipeline.

Problem

  • Init-time mismatch: New projects were bootstrapped with npm, even if the user intended to use pnpm or Yarn Berry.
  • Silent divergence: Switching to another PM afterward (e.g. running pnpm install) did not re-run template logic (e.g. .npmrc, pnpm.onlyBuiltDependencies).
  • Root cause:
    • resolvePackageManager() relied on user-agent or existing lockfile. Neither works at init time.
    • Templates redundantly re-called resolvePackageManager(), diverging from the CLI’s decision.
    • Some setup depended on postinstall, which doesn’t run if the PM changes later.
  • ref: feat(core): pnpm support #3822, feat: improve Yarn Berry support #3997

Solution

  • Added explicit package manager selection during init:
    • CLI prompt (interactive)
    • --package-manager flag (non-interactive / CI)
  • Modified resolvePackageManager() to accept and cache an explicit argument.
  • Propagated the selected PM through init → template, avoiding re-detection.
  • Added test coverage for explicit PM caching and fallback behavior.

Alternatives Considered

  • Environment variable (FORGE_PACKAGE_MANAGER): simple, but too implicit.
  • Lockfile bundling: brittle and introduces drift.
  • Postinstall-driven setup: fragile and increasingly restricted in PM policies.
    Explicit selection + propagation was chosen for clarity and determinism.

Impact

  • Deterministic init-time package manager choice.
  • Consistent behavior between CLI and template layers.
  • Improved pnpm and Yarn Berry compatibility without breaking default npm flow.

Result / Outcome

  • When pnpm is selected, Forge now automatically adds:
    • npmrc file
    • pnpm.onlyBuiltDependencies configuration
  • When yarn is selected (running with Yarn Berry), Forge now automatically adds:
    • .yarnrc file

This allows users to run Electron Forge out-of-the-box with their chosen package manager, without requiring any manual configuration.

Document

@youaresoyoung youaresoyoung requested a review from a team as a code owner September 12, 2025 22:37
@erickzhao erickzhao self-requested a review September 19, 2025 16:07
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.