Skip to content
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

Use corepack to define the current packageManager #44

Merged
merged 4 commits into from
Nov 20, 2024

Conversation

cesarlightit
Copy link
Contributor

@cesarlightit cesarlightit commented Nov 12, 2024

Define packageManager in package.json

Purpose

Setting the packageManager field in the package.json file of a project ensures consistent dependency management across all environments where the project is run. This field explicitly specifies the package manager (e.g., npm, yarn, pnpm) and version to be used, which helps prevent issues caused by differences in package managers and versions that could otherwise lead to conflicts, inconsistencies, or unexpected behavior in the project.

Importance

  • Environment Consistency: When collaborators or CI/CD pipelines install dependencies, they will use the exact same package manager and version, minimizing “works on my machine” issues.
  • Dependency Resolution: Different package managers and versions can handle dependency resolution differently, impacting the structure of the node_modules folder. By defining the package manager, you ensure predictable and reproducible dependency installations.
  • Compatibility with Lock Files: Specifying the package manager aligns with lock files (e.g., package-lock.json for npm, yarn.lock for Yarn), ensuring they are used with the appropriate package manager, which can avoid errors in dependency integrity checks.

Setup for a new project

Each new project should define the package manager in the package.json file. To configure the package.json with the latest stable version of pnpm run the following command in the root of the project.

corepack use pnpm@latest

Working with a corepack defined project

Clone a fresh copy of the project from a repository

git clone repo

Ensure you have corepack enabled

corepack enable

Install NodeJS, the defined package manager and the project dependencies

cd repo
nvm install
pnpm install

Once corepack is enabled, it will function as a yarn or pnpm proxy. When trying to run any of these package managers, NodeJS will attempt to download the defined version before running it. Global installations of these tools will not be taken into account while corepack is enabled.

@github-actions github-actions bot added the WIP Work in progress or draft label Nov 12, 2024
@github-actions github-actions bot added To Review and removed WIP Work in progress or draft labels Nov 12, 2024
@walt-it
Copy link
Contributor

walt-it commented Nov 13, 2024

Great initiative! Only thing I would that note is that if we move forward, we should remember to add the instructions to the boilerplate README.

@cesarlightit
Copy link
Contributor Author

Great initiative! Only thing I would that note is that if we move forward, we should remember to add the instructions to the boilerplate README.

I made some changes to the documentation.

Copy link
Collaborator

@ThunderNaka ThunderNaka left a comment

Choose a reason for hiding this comment

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

Looks great!

@ThunderNaka ThunderNaka merged commit df808cc into main Nov 20, 2024
2 checks passed
@ThunderNaka ThunderNaka deleted the improvement/corepack branch November 20, 2024 13:40
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.

3 participants