Discourse 코어가 JS 패키지 관리용으로 pnpm으로 전환

Discourse 코어의 JS 패키지 매니저를 'yarn classic’에서 pnpm으로 전환합니다. 이를 통해 설치 속도 및 저장 공간 요구 사항이 크게 개선될 것입니다.

프로덕션

호스팅 관리 서비스나 표준 설치를 사용 중이라면 별도로 할 일이 없습니다. 다음 업데이트 시 변경 사항이 자동으로 적용됩니다.

커스텀 프로덕션 환경을 사용 중이라면 yarn ... 명령어를 pnpm ...으로 변경해야 합니다.

개발

Discourse 코어의 최신 버전을 가져온 후 서버를 시작할 때 다음과 같은 오류를 볼 수 있습니다:

pnpm is not installed

또는 yarn install과 같은 명령어를 실행하면 다음과 같은 오류가 표시됩니다.

error discourse@: The engine "yarn" is incompatible with this module. Expected version "please-use-pnpm". Got "..."

이 문제를 해결하려면 다음을 수행해야 합니다:

  1. npm install -g pnpm 실행

  2. pnpm install 실행

  3. 개발 환경에서 yarn ... 사용처를 모두 pnpm ...으로 교체

플러그인 / 테마

공식 플러그인/테마의 린팅 의존성에 pnpm을 사용하도록 전환했습니다.

discourse_theme CLI의 경우, gem update discourse_theme을 실행하여 로컬 버전을 업데이트해야 합니다.

yarn으로 되돌리기

yarn 기반의 Discourse 버전(예: stable 브랜치에서 개발 중)으로 되돌아가야 한다면, 코어의 모든 node_modules 디렉토리를 수동으로 삭제해야 합니다:

rm -rf node_modules app/assets/javascripts/*/node_modules

Can report a faultless smooth experience on dev, working first time, thanks very much! :rocket:

If your self hosted. Will we need to do anything if not using custom components & plugins?

Ie some plugins & components are not official.

Assuming you’re using our standard install, you don’t need to do anything. No changes are required to plugins or themes

Should we change this expected version to, perhaps:

please-use-pnpm-see-https://meta.discourse.org/t/324521

:smiley:

I am contributing to another FOSS project where I was recently introduced for the first time to PNPM. The transition was a complete no-brainer, smooth, effective, and a real pleasure.

I wrote up very brief notes in the documentation for that project for What PNPM Is, and how to use it. While the tiny details are different for every project, I hope what’s there might provide a quick intro to anyone here, who like me didn’t have a clue before an announcement was made.

Good resource, thanks @TonyG

It’s worth noting though - none of the “configuration notes” there are required for Discourse. Not sure why they need it… maybe because it’s a windows-based application?

Also, their note about “In an existing project, just delete the ‘node_modules’ folder” is handled automatically in Discourse by this script :sunglasses:

So for us, it really should be as simple as:

npm install -g pnpm
pnpm install

One question here, David:

How to run linting locally?

ie what replaces, e.g.: yarn prettier --write plugins/discourse-events

I’ve tried to run

pnpm pprettier --write plugins/discourse-events

but it throws an error:

Error: File not found with singular glob: /Users/blah/dev/disc/discourse/plugins/discourse-events (if this was purposeful, use allowEmpty option)

I think you have too many p there?

So you want:

pnpm prettier --write plugins/discourse-events

pprettier is a tool for running prettier in parallel, but I guess it doesn’t support running on a single directory like that.

Thanks for your contribution to FOSS docs @david :lol_: It does look like the page is oriented toward Windows, and that the info there might be required knowledge for using pnpm. I will edit and clarify that neither is the case for that utility.

To be clear, the info about how pnpm works is only there for the comfort of the user/developer, including those here who might like to understand this new tool that replaces a significant, often used tool in our kit.

For Discourse devs, that info explains where things are located and how to change default locations. This is intended to answer a question like “if all of my node_modules are now in one location, where are they?” In the Discourse container, you devs might not want packages in the default location. If, for whatever reason, a plugin developer is directly referencing the node_modules folder and they find links to another location rather than files, the info on that page concisely explains how that location is determined.

So much for trying to be brief. :facepalm: :lolsob:

Anyway, good move to pnpm, and thanks.

Yes, pprettier was not appropriate, thanks.

Worked out my ultimate problem too.

You apparently need to run pnpm install in the plugin directory before you can run linting checks (even from the discourse directory).

Hmm intersting :thinking:

With our standard plugin skeleton, each plugin has its own package.json file with its linting dependencies. And for now, the skeleton still uses yarn.

So to lint a specific plugin, you would go into the plugin directory and run

yarn install
yarn prettier --write

Using core’s linting config on plugins can work sometimes. But if the version/config diverges, it can get painful because the version of eslint/prettier in core won’t match the version running in your plugin’s CI.

Would we consider using pnpm from the plugin directory too?

I believe it is still using the local package.json, no?

Yes we definitely will! Just letting the dust settle on the core change before we start that adventure

(fun fact: CDCK maintain almost 600 theme/plugin repositories which will all need updating :sweat_smile:)

Sure, no issues!

This seems to have worked correctly, but was confused by notice that seems to state this needs to be done manually and is not automatic for standard install site:

Thanks @Architect. These PRs will suppress the upgrade messages:

Ran into an issue upgrading via the web tool — the upgrade page said the upgrade failed, with the Expected version "please-use-pnpm" error, but when I subsequently visited the Versions page again it appeared that the upgrade succeeded:

…however none of the Admin pages are working now:

Update:
I did a rebuild on the command line and that’s fixed things.

Thanks for reporting @alxndr.

I just pushed this fix which should stop this happening to others.

Maybe it’s our Communiteq environment, but TBH I don’t see any significant speed improvements during installation? Our stable test install even installs 23 seconds quicker than the tests-passed one.