Skip to content

Commit a8c60b7

Browse files
committed
build: enforce pnpm and node.js version requirements
Add configuration files (.nvmrc, .npmrc, .pnpmrc) and update package.json to enforce specific Node.js and pnpm versions. Update CI workflow to use pnpm and Corepack. Add documentation in PACKAGE-MANAGER.md explaining the requirements and setup process.
1 parent a1e0740 commit a8c60b7

File tree

10 files changed

+216
-26
lines changed

10 files changed

+216
-26
lines changed

.gitattributes

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Set default behavior to automatically normalize line endings
2+
* text=auto eol=lf
3+
4+
# Denote all files that are truly binary and should not be modified
5+
*.png binary
6+
*.jpg binary
7+
*.jpeg binary
8+
*.gif binary
9+
*.ico binary
10+
*.webp binary
11+
*.woff binary
12+
*.woff2 binary
13+
*.eot binary
14+
*.ttf binary
15+
*.otf binary
16+
*.mp4 binary
17+
*.webm binary
18+
*.mp3 binary
19+
*.zip binary
20+
*.gz binary
21+
*.tar binary

.github/workflows/lint.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ jobs:
1717
- name: Setup Node.js
1818
uses: actions/setup-node@v4
1919
with:
20-
node-version: '20'
21-
cache: 'npm'
20+
node-version: '20.3.0'
21+
cache: 'pnpm'
2222

23-
- name: Install dependencies
24-
run: npm ci
23+
- name: Enable Corepack
24+
run: corepack enable
25+
26+
- name: Setup pnpm
27+
run: corepack prepare pnpm@latest --activate
2528

26-
- name: Install Biome
27-
run: npm install -g @biomejs/biome
29+
- name: Install dependencies
30+
run: pnpm install --frozen-lockfile
2831

2932
- name: Check formatting
3033
run: biome format --write=false .

.husky/pre-commit

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
pnpm lint-staged
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
# Run lint-staged with available pnpm
5+
pnpm lint-staged || (
6+
echo "Error: Failed to run lint-staged. Make sure pnpm is installed."
7+
echo "You can install pnpm globally with: npm install -g [email protected]"
8+
exit 1
9+
)

.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
engine-strict=true
2+
use-node-version=20.3.0
3+
strict-peer-dependencies=false
4+
auto-install-peers=true

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.3.0

.pnpmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
strict-peer-dependencies=false
2+
auto-install-peers=true
3+
engine-strict=true
4+
node-version=>=20.3.0

CONTRIBUTING.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ export const toolName: Tool = {
6262

6363
## Development Setup
6464

65+
### Prerequisites
66+
67+
- Node.js (v20.3.0 or newer)
68+
- pnpm (v8.0.0 or newer)
69+
70+
> **Note:** This project requires pnpm as the package manager. We recommend using Corepack (built into Node.js 20+) to manage pnpm:
71+
> ```sh
72+
> # Enable Corepack
73+
> corepack enable
74+
>
75+
> # Activate pnpm
76+
> corepack prepare pnpm@latest --activate
77+
> ```
78+
>
79+
> For more details on our package manager and Node.js requirements, see [PACKAGE-MANAGER.md](./PACKAGE-MANAGER.md).
80+
81+
### Setup Steps
82+
6583
1. Clone the repository
6684
```sh
6785
git clone https://github.com/wilsonwangdev/frontend-tools-explorer.git
@@ -70,20 +88,21 @@ export const toolName: Tool = {
7088
7189
2. Install dependencies
7290
```sh
73-
npm install
74-
# or
91+
# Using Corepack (recommended)
92+
corepack enable
93+
corepack prepare pnpm@latest --activate
94+
pnpm install
95+
96+
# Alternative: If you have network issues with Corepack
97+
npm install -g [email protected]
7598
pnpm install
76-
# or
77-
yarn install
7899
```
100+
101+
> If you encounter network issues with Corepack during git operations, see the [Troubleshooting section in PACKAGE-MANAGER.md](./PACKAGE-MANAGER.md#troubleshooting).
79102
80103
3. Start the development server
81104
```sh
82-
npm run dev
83-
# or
84105
pnpm dev
85-
# or
86-
yarn dev
87106
```
88107

89108
4. Open your browser and visit `http://localhost:4321`

PACKAGE-MANAGER.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Package Manager and Node.js Requirements
2+
3+
## Overview
4+
5+
This project enforces specific requirements for the development environment to ensure consistency across all contributors and deployments.
6+
7+
## Requirements
8+
9+
### Node.js Version
10+
11+
- **Minimum required version**: v20.3.0
12+
- **Recommended version**: v22.x (LTS)
13+
14+
This requirement is based on Astro's compatibility with Node.js versions. Astro 5.x requires Node.js v20.3.0 or higher.
15+
16+
### Package Manager
17+
18+
- **Required package manager**: pnpm v8.0.0 or higher
19+
- **Current version used**: pnpm v8.15.4
20+
21+
## Why pnpm?
22+
23+
We've chosen pnpm as the required package manager for this project for several reasons:
24+
25+
1. **Disk space efficiency**: pnpm uses a content-addressable store which saves disk space and speeds up installation.
26+
2. **Strict dependency resolution**: pnpm creates a non-flat `node_modules` structure that prevents access to packages that aren't explicitly declared as dependencies.
27+
3. **Performance**: pnpm is generally faster than npm and Yarn Classic for installation operations.
28+
4. **Consistency**: Using a single package manager ensures consistent dependency resolution across all development environments.
29+
30+
## Configuration Files
31+
32+
The following files enforce these requirements:
33+
34+
- `.nvmrc`: Specifies the Node.js version for tools like nvm
35+
- `.npmrc`: Contains npm-related configurations
36+
- `.pnpmrc`: Contains pnpm-specific configurations
37+
- `package.json`: Contains the `engines` and `packageManager` fields
38+
39+
## Enforcement
40+
41+
These requirements are enforced through:
42+
43+
1. The `engines` field in `package.json`
44+
2. The `packageManager` field in `package.json`
45+
3. A simple preinstall script that prevents npm/yarn usage
46+
4. Configuration in `.npmrc` and `.pnpmrc`
47+
48+
## Installation
49+
50+
Since we require Node.js 20.3.0 or higher, we recommend using Corepack to manage pnpm. Corepack is included with Node.js 20+ and provides native package manager version management.
51+
52+
### Using Corepack (Recommended)
53+
54+
```bash
55+
# Enable Corepack (only needed once)
56+
corepack enable
57+
58+
# Use the latest pnpm version
59+
corepack prepare pnpm@latest --activate
60+
```
61+
62+
This approach has several advantages:
63+
1. No need to install pnpm globally
64+
2. Automatically uses the correct version specified in package.json
65+
3. Built into Node.js 20+
66+
4. Ensures consistent package manager versions across all developers
67+
68+
### Alternative Installation
69+
70+
If you prefer not to use Corepack, you can install pnpm globally:
71+
72+
```bash
73+
npm install -g pnpm
74+
```
75+
76+
## Troubleshooting
77+
78+
### Common Issues
79+
80+
If you encounter issues related to Node.js version or package manager:
81+
82+
1. Check your Node.js version with `node -v`
83+
2. Install the required Node.js version
84+
3. Enable Corepack with `corepack enable`
85+
4. Prepare pnpm with `corepack prepare pnpm@latest --activate`
86+
5. Use `pnpm install` to install dependencies
87+
88+
### Network Issues with Corepack
89+
90+
If you encounter network errors when Corepack tries to download pnpm (especially during git commits with Husky):
91+
92+
```
93+
Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-8.15.4.tgz.
94+
Internal Error: Error when performing the request...
95+
```
96+
97+
Try these solutions:
98+
99+
1. **Install pnpm globally** as a fallback:
100+
```bash
101+
npm install -g [email protected]
102+
```
103+
This is the simplest solution and recommended for most users.
104+
105+
2. **Configure npm registry** if you're behind a proxy or firewall:
106+
```bash
107+
npm config set registry https://registry.npmjs.org/
108+
```
109+
110+
3. **Disable Husky temporarily** if needed for commits:
111+
```bash
112+
git commit --no-verify -m "Your commit message"
113+
```
114+
115+
4. **Check network connectivity** to registry.npmjs.org
116+
117+
For more information on pnpm, visit [the official pnpm documentation](https://pnpm.io/).
118+
119+
For more information on Corepack, visit [the Node.js Corepack documentation](https://nodejs.org/api/corepack.html) and [Corepack Troubleshooting](https://github.com/nodejs/corepack#troubleshooting).

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ Frontend Tools Explorer is a curated collection of essential tools, libraries, a
4545

4646
### Prerequisites
4747

48-
- Node.js (v18 or newer)
49-
- npm, pnpm, or Yarn
48+
- Node.js (v20.3.0 or newer)
49+
- pnpm (v8.0.0 or newer)
50+
51+
> **Note:** This project requires specific Node.js and package manager versions. For more details, see [PACKAGE-MANAGER.md](./PACKAGE-MANAGER.md).
5052
5153
### Installation
5254

@@ -60,21 +62,22 @@ Frontend Tools Explorer is a curated collection of essential tools, libraries, a
6062
2. Install dependencies
6163

6264
```sh
63-
npm install
64-
# or
65+
# Using Corepack (recommended)
66+
corepack enable
67+
corepack prepare pnpm@latest --activate
68+
pnpm install
69+
70+
# Alternative: If you have network issues with Corepack
71+
npm install -g [email protected]
6572
pnpm install
66-
# or
67-
yarn install
6873
```
6974

75+
> **Note:** This project requires pnpm as the package manager. We recommend using Corepack (built into Node.js 20+) to manage pnpm. See [PACKAGE-MANAGER.md](./PACKAGE-MANAGER.md) for more details and troubleshooting.
76+
7077
3. Start the development server
7178

7279
```sh
73-
npm run dev
74-
# or
7580
pnpm dev
76-
# or
77-
yarn dev
7881
```
7982

8083
4. Open your browser and visit `http://localhost:4321`

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
"name": "frontend-tools-explorer",
33
"type": "module",
44
"version": "0.0.1",
5+
"engines": {
6+
"node": ">=20.3.0",
7+
"pnpm": ">=8.0.0"
8+
},
9+
"packageManager": "[email protected]",
510
"scripts": {
611
"dev": "astro dev",
712
"build": "astro build",
@@ -11,7 +16,9 @@
1116
"format": "biome format . --write",
1217
"check": "biome check . --write",
1318
"prepare": "husky",
14-
"lint-staged": "lint-staged"
19+
"lint-staged": "lint-staged",
20+
"preinstall": "node -e \"process.env.npm_config_user_agent && !process.env.npm_config_user_agent.includes('pnpm') && (console.error('Please use pnpm instead of npm or yarn'), process.exit(1))\"",
21+
"install-pnpm-fallback": "npm install -g [email protected]"
1522
},
1623
"dependencies": {
1724
"@astrojs/vercel": "^8.2.0",
@@ -24,6 +31,7 @@
2431
"husky": "^9.1.7",
2532
"lint-staged": "^16.1.2",
2633
"postcss": "^8.5.6",
34+
"semver": "^7.5.4",
2735
"tailwindcss": "^3.4.17"
2836
}
2937
}

0 commit comments

Comments
 (0)