From 28a8ad866f7010c26f8930425bed92778f5c1669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carbon=20=E7=A2=B3=E8=8B=AF?= <79406469+CoderSerio@users.noreply.github.com> Date: Mon, 26 Jun 2023 13:37:59 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feat:=20=E9=99=90=E5=88=B6=20pnpm=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=BA8+=20(#10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: readme提示限定node版本 * feat: 限制node版本为18+ * feat: 限制pnpm版本为8+ * feat: check the version of pnpm before install dependencies * feat: 调整启动脚本 --------- Co-authored-by: CoderSerio --- .npmrc | 2 +- README.md | 1 + package.json | 2 ++ scripts/preinstall.js | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 scripts/preinstall.js diff --git a/.npmrc b/.npmrc index 38f11c6..0453efc 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1 @@ -registry=https://registry.npmjs.org +registry=https://registry.npmjs.org \ No newline at end of file diff --git a/README.md b/README.md index 3673304..098e14a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ 进入项目仓库
```sh +# 请使用pnpm 8进行安装,避免依赖结构问题导致后续命令无法执行 pnpm i npm run build:all ``` diff --git a/package.json b/package.json index 5c24fe8..2506b44 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/preinstall.js b/scripts/preinstall.js new file mode 100644 index 0000000..1c1c6bc --- /dev/null +++ b/scripts/preinstall.js @@ -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); +}