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

Switch JS package manager to pnpm #44167

Merged
merged 23 commits into from
Jul 19, 2024
Merged

Switch JS package manager to pnpm #44167

merged 23 commits into from
Jul 19, 2024

Conversation

gzdunek
Copy link
Contributor

@gzdunek gzdunek commented Jul 12, 2024

Implements RFD 177 - Upgrade JS package manager.
Closes #33356
e counterpart https://github.com/gravitational/teleport.e/pull/4652

Best to review commit-by-commit.

I quickly tested Connect (Windows, macOS and Linux builds) and Web UI (macOS), I didn't see any problems.
Test builds: 17.0.0-dev.gzdunek.14 (17.0.0-dev.gzdunek.13 for macOS artifacts).

I will backport it to v16, on v15 and v14 we will stay with yarn. I will add "packageManager": "[email protected]" to them.

Note

To use pnpm, enable Corepack (if you haven't already done it) with corepack enable.
All commands stayed the same, you only need to change yarn to pnpm, e.g. pnpm start-teleport.
The only important difference is dependencies installation, previously you could type yarn now it's pnpm install (or pnpm i).

Warning

After switching back to a branch that uses Yarn, I recommend running make clean-ui before yarn install, otherwise the dependency installation will fail.

It also removes resolutions that are no longer relevant.
`jest-styled-components` package is no longer global, so `toHaveStyleRule` matchers is not recognized by TS.
We use them only in three places, so it's simpler to convert them to `toHaveStyle`.
I don't think anyone uses the debug configuration for electron (and we don't have `start-electron` script for a long time).
.pnpmfile.cjs Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Today I realized that pnpm adds an entry for each workspace to the lockfile, including e/web/teleport 😢 (so we will get a different lockfile when e is not cloned).
The only workaround I've found is to manually modify the lockfile using pnpm hooks. I know it's ugly, but I can't think of anything better.
To simplify this hook, I removed all dependencies from the e/web/teleport/package.json.

Copy link
Member

@ravicious ravicious Jul 16, 2024

Choose a reason for hiding this comment

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

I think it's a pretty elegant solution actually.

@@ -1643,15 +1643,15 @@ backport:
.PHONY: ensure-js-deps
ensure-js-deps:
@if [[ "${WEBASSETS_SKIP_BUILD}" -eq 1 ]]; then mkdir -p webassets/teleport && touch webassets/teleport/index.html; \
else yarn install --ignore-scripts; fi
Copy link
Contributor Author

Choose a reason for hiding this comment

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

--ignore-scripts was causing Connect on Linux not to have pty-node (I don't know why it worked with yarn).

@public-teleport-github-review-bot

@gzdunek - this PR will require admin approval to merge due to its size. Consider breaking it up into a series smaller changes.

Copy link

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

Copy link
Contributor

@ryanclark ryanclark left a comment

Choose a reason for hiding this comment

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

👏

README.md Outdated Show resolved Hide resolved
@ryanclark
Copy link
Contributor

Should we add yarn.lock to the .gitignore?

# Conflicts:
#	build.assets/Dockerfile
#	web/packages/design/package.json
#	yarn.lock
Makefile Outdated Show resolved Hide resolved
@gzdunek
Copy link
Contributor Author

gzdunek commented Jul 16, 2024

Should we add yarn.lock to the .gitignore?

I think it's a good idea to prevent it from being reintroduced by accident, added.

jest.config.js Show resolved Hide resolved
web/.storybook/main.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
BUILD_macos.md Outdated
* `brew install node yarn`
* Currently, [`yarn`](https://classic.yarnpkg.com/en/docs/install) (< 2.0.0) is required
* `brew install node`
* `corepack enable`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `corepack enable`
* `corepack enable pnpm`

Copy link
Member

Choose a reason for hiding this comment

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

Though pnpm docs say this:

If you installed Node.js using Homebrew, you'll need to install corepack separately:

brew install corepack

This will automatically install pnpm on your system.

Should it just say brew install node corepack then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uh that's correct, I just tried a fresh installation :/
I suppose it didn't work that way in the past, because I didn't install corepack with brew.

Changed to brew install node corepack.

web/README.md Outdated Show resolved Hide resolved
web/packages/design/src/Icon/README.md Outdated Show resolved Hide resolved
BUILD_macos.md Outdated
* `brew install node yarn`
* Currently, [`yarn`](https://classic.yarnpkg.com/en/docs/install) (< 2.0.0) is required
* `brew install node`
* `corepack enable`
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the corepack enable pnpm thread (#44167 (comment)), do you have any opinions/advice on using pnpm to manage the node install?

Ie:

brew install pnpm
export PNPM_HOME=~/Library/pnpm
pnpm env use --global 20 # or whatever version

@ravicious @gzdunek

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have never tried this before, but it seems really convenient.
We could even provide a specific version in .npmrc, which would be installed automatically for our project when we run any pnpm command:

#.npmrc
use-node-version=20.15.0
grzegorz@mbp teleport % pnpm node -v
Fetching Node.js 20.15.0 ...
v20.15.0

But I believe this change should also done for CI to have a single way of installing Node.js and the package manager. However, I think it would be too much for this PR, but we can go back to this idea in the future.
What do you think?

@gzdunek
Copy link
Contributor Author

gzdunek commented Jul 19, 2024

Okay, let's merge this!

@gzdunek gzdunek added this pull request to the merge queue Jul 19, 2024
Merged via the queue into master with commit 620c0a0 Jul 19, 2024
41 checks passed
@gzdunek gzdunek deleted the gzdunek/pnpm branch July 19, 2024 10:10
@public-teleport-github-review-bot

@gzdunek See the table below for backport results.

Branch Result
branch/v16 Failed

gzdunek added a commit that referenced this pull request Jul 19, 2024
* Adjust `package.json`s to pnpm

* Convert resolutions (pnpm doesn't support `**/` syntax)

It also removes resolutions that are no longer relevant.

* Convert `yarn.lock` to `pnpm-lock.yaml` with `pnpm import`

* Always add `e/web/teleport` workspace to the lockfile

* Adjust `jest` to new node_modules structure

* Adjust `storybook` to new node_modules structure

* Replace `toHaveStyleRule` with `toHaveStyle`

`jest-styled-components` package is no longer global, so `toHaveStyleRule` matchers is not recognized by TS.
We use them only in three places, so it's simpler to convert them to `toHaveStyle`.

* Adjust README files

* Adjust GHA workflows

* Adjust build assets

* Remove remaining `yarn` mentions

I don't think anyone uses the debug configuration for electron (and we don't have `start-electron` script for a long time).

* `corepack enable` -> `corepack enable pnpm`

* Automatically enable pnpm when running `make build/teleport`

* Run `pnpm import` again

* Run `pnpm dedupe`

* Add `yarn.lock` to .gitignore

* Link to pnpm installation docs

* Add a better comment for `transformIgnorePatterns`

* Make pattern for `shared` stories more specific

* Change `corepack enable pnpm` in readmes

* Run `pnpm import && pnpm dedupe` again

(cherry picked from commit 620c0a0)
github-merge-queue bot pushed a commit that referenced this pull request Jul 19, 2024
* Switch JS package manager to pnpm (#44167)

* Adjust `package.json`s to pnpm

* Convert resolutions (pnpm doesn't support `**/` syntax)

It also removes resolutions that are no longer relevant.

* Convert `yarn.lock` to `pnpm-lock.yaml` with `pnpm import`

* Always add `e/web/teleport` workspace to the lockfile

* Adjust `jest` to new node_modules structure

* Adjust `storybook` to new node_modules structure

* Replace `toHaveStyleRule` with `toHaveStyle`

`jest-styled-components` package is no longer global, so `toHaveStyleRule` matchers is not recognized by TS.
We use them only in three places, so it's simpler to convert them to `toHaveStyle`.

* Adjust README files

* Adjust GHA workflows

* Adjust build assets

* Remove remaining `yarn` mentions

I don't think anyone uses the debug configuration for electron (and we don't have `start-electron` script for a long time).

* `corepack enable` -> `corepack enable pnpm`

* Automatically enable pnpm when running `make build/teleport`

* Run `pnpm import` again

* Run `pnpm dedupe`

* Add `yarn.lock` to .gitignore

* Link to pnpm installation docs

* Add a better comment for `transformIgnorePatterns`

* Make pattern for `shared` stories more specific

* Change `corepack enable pnpm` in readmes

* Run `pnpm import && pnpm dedupe` again

(cherry picked from commit 620c0a0)

* Run `pnpm import && pnpm dedupe`

* Remove `yarn.lock`

* make ensure-js-package-manager: Do not prompt before installing pnpm

---------

Co-authored-by: Rafał Cieślak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v16 no-changelog Indicates that a PR does not require a changelog entry size/xl ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix incorrectly hoisted JS dependencies
6 participants