Skip to content

refactor: update package manager detection and improve type handling #9067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 4, 2025

Conversation

beyondkmp
Copy link
Collaborator

@beyondkmp beyondkmp commented Apr 29, 2025

fix #8970 (comment)

  • Replaced the detect and getPackageManagerVersion functions with a new detectPackageManager function for better clarity and type safety.
  • Updated the PM type to an enum for improved maintainability.
  • Adjusted the logic in getCollectorByPackageManager and installDependencies to utilize the new detection method.
  • Cleaned up unused code and comments in packageManager.ts and yarn.ts files.

- Replaced the `detect` and `getPackageManagerVersion` functions with a new `detectPackageManager` function for better clarity and type safety.
- Updated the `PM` type to an enum for improved maintainability.
- Adjusted the logic in `getCollectorByPackageManager` and `installDependencies` to utilize the new detection method.
- Cleaned up unused code and comments in `packageManager.ts` and `yarn.ts` files.
Copy link

changeset-bot bot commented Apr 29, 2025

🦋 Changeset detected

Latest commit: 210f3cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
app-builder-lib Patch
dmg-builder Patch
electron-builder-squirrel-windows Patch
electron-builder Patch
electron-forge-maker-appimage Patch
electron-forge-maker-nsis-web Patch
electron-forge-maker-nsis Patch
electron-forge-maker-snap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@beyondkmp beyondkmp marked this pull request as draft April 29, 2025 07:31
- Renamed `detectPackageManager` to `detectPackageManagerByEnv` for clarity.
- Improved the logic in `detectPackageManager` to handle multiple lock files and prioritize detection based on existing files.
- Updated the `installDependencies` function to correctly handle Yarn Berry cases.
- Cleaned up code for better readability and maintainability.
@beyondkmp beyondkmp marked this pull request as ready for review April 30, 2025 09:46
@beyondkmp beyondkmp requested a review from mmaietta April 30, 2025 10:02
@beyondkmp
Copy link
Collaborator Author

@mmaietta

Should we directly determine the package manager based on the env, and completely remove the logic that determines it based on the lock file? Could you check if this might cause any other issues?

@mmaietta
Copy link
Collaborator

mmaietta commented May 1, 2025

Hmmm, I think we should emulate the approach that electron-builder took prior to the PM refactor. IIRC, it only accepted npm/yarn though, so we are technically expanding the featureset of detecting of the package manager. I'm not sure what errors could occur if we only used env, but envs can differ across local dev vs. build machine, not sure if we want to only take into account env. If multiple lockfiles are detected, then we should use env, otherwise fall back to lockfile logic?

@beyondkmp
Copy link
Collaborator Author

@mmaietta The current logic has been changed: if there is only one lock file, the lock file will be used to determine the package manager (PM). If there are multiple lock files or no lock file, the environment variables (env) will be used instead.

- Introduced `getPackageManagerCommand` to standardize command retrieval for package managers.
- Updated imports in `index.ts` and `yarn.ts` to include the new function.
- Removed the deprecated `getPackageToolPath` function for cleaner code.
@beyondkmp beyondkmp requested a review from mmaietta May 4, 2025 01:29
@mmaietta mmaietta merged commit 312938d into electron-userland:master May 4, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Cannot find module 'sharp'" on Windows only after upgrading to 26.0.11
2 participants