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

feat: 使用corepack管理PNM版本,锁定为[email protected],增加ci脚本支持快速下载依赖 #4237

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
version: 9.6.0
Copy link
Member

Choose a reason for hiding this comment

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

为什么是这个版本呢,pnpm 应该没有出现过 minor 版本不兼容的情况吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

因为我本地使用的是9.6.0 那我改成9吧

Copy link
Member

@czy88840616 czy88840616 Dec 19, 2024

Choose a reason for hiding this comment

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

我理解 9 的 latest 就行了。如果 pnpm 有问题,由 CI + lock 来保证,我们最终确保的是框架 ci 没有问题,这个 lock 仅服务于框架本身,不会提供给用户的项目。

run_install: false

- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -110,7 +110,7 @@ jobs:
container-name: 'mqtt'

- name: Install dependencies
run: pnpm install
run: ./scripts/ci

- name: Install codecov
run: pnpm add -g codecov
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/precheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
version: 9.6.0
run_install: false

- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -35,7 +35,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- run: pnpm install
- run: ./scripts/ci
- run: pnpm build --if-present
- run: pnpm lint
- run: pnpm lint:cycle
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
"type": "git",
"url": "https://github.com/midwayjs/midway.git"
},
"packageManager": "[email protected]",
"engines": {
"node": ">= 16.0.0"
"node": ">= 16.0.0",
"pnpm": "9.6.0"
},
"license": "MIT",
"collective": {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
packages:
- 'packages/*'
- 'packages-serverless/*'
- 'packages-resource/*'
- 'packages-resource/*'
18 changes: 18 additions & 0 deletions scripts/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
##
## 依赖安装脚本
## 使用:
## ./scripts/ci
##

# NPM源
NPM_REGISTRY="https://mirrors.tencent.com/npm/"
Copy link
Member

Choose a reason for hiding this comment

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

不允许使用三方源,避免同步问题

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我改成淘宝源可以嘛? 得考虑国内开发者下载速度吧,或者不指定我就删了吧

Copy link
Member

@czy88840616 czy88840616 Dec 19, 2024

Choose a reason for hiding this comment

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

不需要的,这里仅考虑 CI 标准环境,本地的可以自行配置 registry,或者 nrm 修改,方式有很多,也没法限制,不需要提交的。


## 获取所有参数
echo "运行命令: export COREPACK_NPM_REGISTRY=$NPM_REGISTRY && corepack enable pnpm && pnpm i --registry $NPM_REGISTRY --frozen-lockfile $*"

# 导出corepack环境变量,安装pnpm版本
export COREPACK_NPM_REGISTRY=$NPM_REGISTRY && corepack enable pnpm

# 安装项目依赖
pnpm i --registry $NPM_REGISTRY --frozen-lockfile "$@"
Copy link
Member

Choose a reason for hiding this comment

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

这里其实不需要 --frozen-lockfile,因为 pnpm 在 github action ci 环境默认就是这个

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个脚本,可以直接用,免得在本地pnpm i 。 直接pnpm i,pnpm-lock不就会更新嘛?

Copy link
Member

@czy88840616 czy88840616 Dec 19, 2024

Choose a reason for hiding this comment

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

如果 lock 里没有,那 i 的时候更新也没问题的,pr 的时候会看的。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

我是习惯于把环境配置好,争取做到开发者不因为环境导致问题,专注与业务上。 我经常在pnpm i时出现pnpm-lock变动,PR提交上来了。就得反复改。

如果觉得不太合适,我明天把这个PR 关掉

Copy link
Member

Choose a reason for hiding this comment

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

恩,这个 pr 更多的是一些开发者习惯,目前看起来还不足以变成框架的规约。

pnpm i 在新增依赖,更新了 package.json 和 lock 文件,这是合理的,如果没有更新,纯粹只是安装,应该不会更新 pkg 和 lock。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pnpm i直接安装会更新pnpm-lock,但不更新pkg, 因为pkg里面的版本,很多有 "@types/node": "^2.10.2", 这种。 目前midway好像是写死版本号

Copy link
Member

Choose a reason for hiding this comment

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

是的,每个三方包都会经由renovate 机器人提 pr 后人工 review + CI 完后合入。

Loading