Skip to content

Commit

Permalink
✨feat: 限制 pnpm 版本为8+ (#10)
Browse files Browse the repository at this point in the history
* chore: readme提示限定node版本

* feat: 限制node版本为18+

* feat: 限制pnpm版本为8+

* feat: check the version of pnpm before install dependencies

* feat: 调整启动脚本

---------

Co-authored-by: CoderSerio <CoderSerio@[email protected]>
  • Loading branch information
CoderSerio and CoderSerio authored Jun 26, 2023
1 parent 197bb61 commit 28a8ad8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
registry=https://registry.npmjs.org
registry=https://registry.npmjs.org
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
进入项目仓库<br>

```sh
# 请使用pnpm 8进行安装,避免依赖结构问题导致后续命令无法执行
pnpm i
npm run build:all
```
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"preinstall": "npx only-allow pnpm",
"pnpm:devPreinstall": "node ./scripts/preinstall.js",
"dev": "father dev",
"build:all": "pnpm run -r build",
"test:all": "pnpm run -r test",
Expand Down
17 changes: 17 additions & 0 deletions scripts/preinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const childProcess = require("child_process");

let version;
try {
version = childProcess.execSync("pnpm -v").toString();
} catch (err) {
console.error(`Error: can't find module 'pnpm'.`);
process.exit(1);
}

const majorVersion = version?.split(".")?.[0];
if (!majorVersion || +majorVersion < 8) {
console.error(
`Error: required pnpm version is not less than 8.0.0, but got ${version}.`
);
process.exit(1);
}

0 comments on commit 28a8ad8

Please sign in to comment.