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

use yarn instead of npm #7

Closed
wants to merge 14 commits into from
Closed

use yarn instead of npm #7

wants to merge 14 commits into from

Conversation

undefined-moe
Copy link
Member

No description provided.

@ilharp ilharp self-requested a review April 20, 2022 19:03
@ilharp
Copy link
Member

ilharp commented Apr 22, 2022

@undefined-moe

经过调查,yarn.yarnrc 文件似乎无法实现现有 .npmrc 的全部功能。

现在的 .npmrc 内容为:

registry=https://registry.npmmirror.com/ # 设置镜像
prefix=${HOME}/../node                   # 设置 Global 文件夹
cache=${HOME}/../tmp/npm-cache           # 设置 Cache
tmp=${HOME}/../tmp                       # 设置临时文件夹

后三条配置均为了避免泄漏而设计。yarn 是否可以实现上述功能?如果不能的话,那我们将无法迁移到 yarn,因为包管理器会与用户环境产生可能的冲突和泄漏。

@MaikoTan
Copy link
Member

yarn v1 can also set them by

yarn config set prefix <global-folder>
yarn config set cache-folder <cache-folder>

to achieve this.

Although I have no idea what is tmp and how is it working.

And if using yarn berry (v2 / v3), packages would be installed in .yarn/ by default.

@ilharp
Copy link
Member

ilharp commented Apr 22, 2022

经过验证,.yarnrc 不可采用。

  1. .yarnrc 不支持环境变量插值。该特性现在正在被使用,以避免泄漏。

  2. .yarnrc 在使用相对路径时 yarn 会将其变为绝对路径,使得 Koi 无法满足便携性需求。

  3. .yarnrc 各配置的行为不一致。cache-folder 相对于 $HOME 判定路径,而 prefix 基于 pwd

回滚到 .npmrc,但 yarnnpm 行为仍然不一致,不遵循 .npmrc 设置。

最后,查看 yarn config current。其中有多项 folder 相关字段无法修改。判断使用 yarn 将不可避免地导致包和缓存泄漏到用户环境中,且这些安装的包将无法被 Koi 调用。

鉴于上述原因,现判定 yarn@1 无法实现 npm 的全部功能,故不予采用。

此 PR 保留几天后关闭。有其他建议可随时提出。

@ilharp
Copy link
Member

ilharp commented Apr 22, 2022

需注意「包管理器支持 Global 环境」并非 Koi 的必需功能,现阶段也无任何需求使用到了该功能。现阶段 yarn 最主要的问题是不可控的 prefixcachetmp 导致的包和缓存的泄漏。此情况极有可能导致用户提供的破损的环境(如破损的 yarn 缓存)导致 Koi 的功能出现异常。如果有其他意见,请随时提出。

@undefined-moe
Copy link
Member Author

yarn2 可以通过 .yarnrc.yaml 指定 cacheFolder 或是禁用 enableGlobalCache
同时,在 yarn2 中禁用了 yarn global 功能。
详见 https://yarnpkg.com/configuration/yarnrc

@undefined-moe
Copy link
Member Author

yarn2 默认会将缓存存储于 ./.yarn/cache 目录下。

@MaikoTan
Copy link
Member

MaikoTan commented Apr 22, 2022

if you want to use yarn 2 (in fact current version is already 3), then I think it is better to "bundle" the yarn itself and its plugins in the shipped release, instead of installing it at the runtime. yarn will install the latest berry version from GitHub, which is not much stable that every user could connect.
also, koishi now is not support yarn berry's pnp feature very well, although this can be improved in the future.

@MaikoTan
Copy link
Member

MaikoTan commented Apr 22, 2022

需注意「包管理器支持 Global 环境」并非 Koi 的必需功能,现阶段也无任何需求使用到了该功能。现阶段 yarn 最主要的问题是不可控的 prefixcachetmp 导致的包和缓存的泄漏。此情况极有可能导致用户提供的破损的环境(如破损的 yarn 缓存)导致 Koi 的功能出现异常。如果有其他意见,请随时提出。

Agreed.
Even the yarn is more convenient in development, if we cannot consist its behaviour, it is better to screw it and just use npm instead.
Koi, as a "koishi one-click initialisator", should always maintain its dependencies into itself.

EDIT: But looks like yarn berry works well in this case.

@undefined-moe
Copy link
Member Author

Works on Linux. Windows and MacOS not tested.

@MaikoTan
Copy link
Member

As koishijs/koishi#633 merged, it should be allowed to use yarn berry to perform create / install completely.

@ilharp
Copy link
Member

ilharp commented May 1, 2022

已在 84b6c5c 使用 Co-authored-by 签署提交。将关闭本 PR。

@ilharp ilharp closed this May 1, 2022
@ilharp ilharp deleted the undefined branch July 31, 2022 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants