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

chore: use pnpm to manage dependencies #12635

Closed
wants to merge 16 commits into from
Closed

Conversation

jacobwgillespie
Copy link
Contributor

Problem

Followup from #12520 (see there for more context), this PR replaces Yarn 1 with pnpm. Yarn 1 is semi-unmaintained and has caused issues in docker build.

Changes

This PR switches to use pnpm instead of yarn. The highlights are:

  • All yarn commands are updated to their pnpm equivalents
  • GitHub Actions workflows and the Dockerfile use pnpm now
  • Some additional dependencies have been added to package.json if they previously were only available due to hoisting.

How did you test this code?

Installed locally + ran docker build. Will need CI to run the tests.

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Looks good to me, but TypeScript is acting up, and I don't see why since nothing should be different with regard to typing. 🤔 Also something fishy going on with plugin server tests.

addFilterDefaultOptions,
})
const { reportFunnelStepReordered } = useActions(eventUsageLogic)
export const ActionFilter = React.forwardRef<HTMLDivElement, ActionFilterProps>(function ActionFilter(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this addition of function needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's for the ESLint rule react/display-name - with the arrow function inside forwardRef, the wrapped component is unnamed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh interesting, I thought we were already compliant with this rule. Looks like it's just been a while since this file was last edited and only now did ESLint catch this.

@jacobwgillespie
Copy link
Contributor Author

TypeScript is acting up, and I don't see why since nothing should be different with regard to typing

Yeah... So this is the fun of migrating from Yarn 1 to pnpm (or a more strict Yarn) - Yarn 1 hoisted all modules to the root of node_modules, so you could potentially import a sub-dependency in your app without specifying it in package.json, and the behavior of tools that inspect node_modules can change. For instance, @types/* packages would be hoisted to the top, ESLint plugins would be hoisted, etc.

With pnpm or a more correct Yarn version, you can only import packages specified in package.json. This is way safer and more predictable, but when migrating you discover all the places that previously were accidentally working due to hoisting. 🙂

I'll keep watching the build, I think I'm getting closer to fixing all the TS issues.

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

This is looking fantastic, well done! Ran this locally (bin/start) and everything's working.
The only remaining issue it those few failing Cypress tests – though I ran them on a clean setup locally with fully green results, so this might be some flakiness. Also not sure why Jest tests haven't ran in CI. Once the checks are green, we can merge this.

@@ -0,0 +1,37 @@
diff --git a/lib/types.d.ts b/lib/types.d.ts
Copy link
Collaborator

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.

Ah, cool, yeah an upstream fix would be even better. 🙂

The issue here is that kea in 3.0.0-alpha accepted just two generic arguments for SelectorDefinition, but in the 3.x.x released version requires three. Looks like kea-forms assumes the alpha version's types.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for finding this! I released version 3.0.2 of kea-forms with the fix.

addFilterDefaultOptions,
})
const { reportFunnelStepReordered } = useActions(eventUsageLogic)
export const ActionFilter = React.forwardRef<HTMLDivElement, ActionFilterProps>(function ActionFilter(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh interesting, I thought we were already compliant with this rule. Looks like it's just been a while since this file was last edited and only now did ESLint catch this.

@jacobwgillespie
Copy link
Contributor Author

this might be some flakiness. Also not sure why Jest tests haven't ran in CI. Once the checks are green, we can merge this.

Yeah, having done this before, the flakiness may very well be related to some module reshuffling, and after merge / deploy it's quite possible that there might be a followup issue to fix for the release. 🙂 Whenever this is merged, it would be good to watch for any errors, etc.

# Split the test into 3 parts. To increase the number split change the denominator in `length / 3`
run: echo "test-chunks=$(yarn test --listTests --json | sed -n 3p | jq -cM '[_nwise(length / 3 | ceil)]')" >> $GITHUB_OUTPUT
run: echo "test-chunks=$(pnpm test -- --listTests --json | sed -n 3p | jq -cM '[_nwise(length / 3 | ceil)]')" >> $GITHUB_OUTPUT
Copy link
Collaborator

Choose a reason for hiding this comment

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

Jest tests aren't running in CI. Looks like this should be sed -n 5p with pnpm + we might need to update ts-node, as I'm getting a "Non-string value passed to ts.resolveTypeReferenceDirective" error.
I would push this myself, but "Allow edits and access to secrets by maintainers" is unchecked on this 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.

Updated 👍

Allow edits and access to secrets by maintainers

Apparently GitHub doesn't support this if the repo and the fork are both located in organization accounts rather than personal accounts. 🤷 https://github.com/orgs/community/discussions/5634

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, that's very annoying. Now there are some "Jest encountered an unexpected token" problems in Frontend CI checks, and unfortunately I'm not able to push a fix either.

Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

This looks good to me! The last changes I think we need are:

  • kea-forms can now be upgraded to a version that fixes the bug
  • multiple RUN commands in production.Dockerfile should be combined to one, in two places

Other than that, if there's no easy way to get CI working, we're just going to merge it in, and quickly fix things if any remaining issues arise. I think the stakes are low enough that we could get away with it.

@jacobwgillespie
Copy link
Contributor Author

Okay, I've updated with changes from master and cleaned up the Dockerfile. I still need to fix Jest, which is currently not transpiling tests correctly (it still has import / export).

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@mariusandra
Copy link
Collaborator

We recently upgraded Jest and are running it now through esbuild, so that problem might have solved itself.

I'd be happy to merge it in, though we decided to wait until next week as we're just about to release a new version of PostHog... and just in case it's best to wait for after that :).

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@jacobwgillespie
Copy link
Contributor Author

Closing in favor of #13190 🚀

thmsobrmlr added a commit that referenced this pull request Dec 12, 2022
* chore: use pnpm to manage dependencies

* Fix CI errors

* Don't report Docker image size for external PRs

* Fix pnpm-lock.yaml formatting

* Fix module versions

* Ignore pnpm-lock.yaml

* Upgrade Cypress action for pnpm support

* Set up node and pnpm before Cypress

* Fix typescript issues

* Include patches directory in Dockerfile

* Fix Jest tests in CI

* Update lockfile

* Update lockfile

* Clean up Dockerfile

* Update pnpm-lock.yaml to reflect current package.json files

* remove yarn-error.log from .gitignore

* formatting

* update data exploration readme

* type jest.config.ts

* fix @react-hook issues for jest

* fix react-syntax-highlighter issues for jest

* fix jest issues from query-selector-shadow-dom

* fix transform ignore patterns and undo previous fixes

* add missing storybook peer dependencies

* fix nullish coalescing operator for storybook

* reorder storybook plugins

* update editor-update-tsd warning to new npm script

* use legacy ssl for chromatic / node 18 compatibility

* use pnpm for visual regression testing workflow

* use node 16 for chromatic

* add @babel/plugin-proposal-nullish-coalescing-operator as direct dependency

* try fix for plugin-server

* cleanup

* fix comment and warning

* update more comments

* update playwright dockerfile

* update plugin source types

* conditional image size reporting

* revert react-native instructions

* less restrictive pnpm verions

* use ref component name in line with style guide

Co-authored-by: Jacob Gillespie <jacobwgillespie@gmail.com>
@charlescook-ph
Copy link
Contributor

Thank you so much @jacobwgillespie! Check your email for a small gift from us :)

@jacobwgillespie
Copy link
Contributor Author

Hey, thank you! 🙌

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.

5 participants