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: specify a particular Node.js version using pnpm #1677

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all 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
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shell-emulator=true
auto-install-peers=true
strict-peer-dependencies=false
enable-pre-post-scripts=true
enable-pre-post-scripts=true
Copy link
Member

@zzcr zzcr Jul 26, 2024

Choose a reason for hiding this comment

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

你好,这个如果配置死了18.19.1,会让版本不匹配的用户重新下载nodejs,这样做不是很好哈吗,在内部下载会超时,但是还是感谢你的贡献哈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这样做相当于以项目级别指定node版本,可以防止不同贡献者因为开发环境的node不同导致贡献仓库时有相关问题。

内部下载超时一般可以通过设置镜像解决,类似在 .npmrc 中添加指定淘宝镜像
node-mirror:release=https://npmmirror.com/mirrors/node/

我看华为云也有相关node生态的镜像,类似 cypress 的镜像

Copy link
Member

Choose a reason for hiding this comment

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

我的理解是给用户相应的提示即可,不能迫使用户区下载nodejs,可以在package.json中指定下nodejs的最低版本的

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. 这里的用户指的是开发 tiny-vue 的开发者 —— 面对源码
  2. 在 package.json 下指定 node.js 最低版本对应的作用域是 开发 tiny-vue 的开发者 U 使用 tiny-vue 组件库的用户(面对产物)

也就是说,这两者的作用域可以不同,比如说开发 tiny-vue 组件库统一使用 latest 版本,只要打出来的包兼容 node 12,使用 tiny-vue 组件库的用户使用 node 12 也可以正常运行。

相对应的,如果开发 tiny-vue 的开发者使用的是 node 12 而不是 latest,那么在运行 tiny-vue 源码时,自动下载源码所需的 node 版本理论上更合适,省去主动切换 node 版本。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

也就是说对于 tiny-vue 的开发者,把 node 环境也当做了依赖的一环,做到像安装 package.json 声明的依赖一样。

类似像 https://github.com/antfu/eslint-config/blob/c22689f8fc38f7c7a0e53b9fed7f359f36e5c7e4/package.json#L5
使用 corepack 并且指定 packageManager,还可以把包管理器当做依赖的一环,这样当 pnpm 和 node 版本都不同时,通过 corepack 自动安装项目所需 pnpm,通过 pnpm 自动安装项目所需 node,达到基本跟环境隔离的效果~

Copy link
Member

Choose a reason for hiding this comment

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

@gweesin 有可能会出现一个问题,就是开发者没有搭梯子的话,执行 pnpm i 会报错。
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个是的,国内的话需要配置一次环境变量 COREPACK_NPM_REGISTRY=https://registry.npmmirror.com 指定淘宝镜像

use-node-version=18.19.1
Loading