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: use original tough-cookie v5 #2356

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SamMousa
Copy link

@SamMousa SamMousa commented Nov 14, 2024

This PR aims to drop the wrapper of tough-cookie: https://github.com/bundled-es-modules/tough-cookie
It also upgrades the dep to v5.

The original PR: #2206 used the es-bundled version.
In september with the release of v5 tough-cookie was rewritten in typescript and (I'm assuming here) is probably compatible with ES without this wrapper package.

@kettanaito
Copy link
Member

Hi, @SamMousa. This looks exciting! The change requires a rewrite of our cookie store because the new tough-cookie exposes breaking changes in its methods (mostly in types). I will look into this once I have a minute.

@SamMousa
Copy link
Author

I was hoping tests in ci would give me pointers, since running tests locally in the js / ts ecosystem is always a nightmare

@kettanaito
Copy link
Member

@SamMousa, give this repo a try, the tests should be running without issues. Install dependencies, and you have three levels of tests to run:

  • pnpm test:unit
  • pnpm test:node
  • pnpm test:browser

The cookie store changes affect both Node.js and the browser, so start from running Node.js tests locally.

You can spot the mismatch in types if you open the module you modified.

@SamMousa
Copy link
Author

I've simplified the implementation a lot and also reduced coupling with tough-cookie:

  • Instead of exposing the whole cookiejar, expose only the methods that we need
  • Remove a full implementation of a custom store that uses local storage
  • Replaced the full implementation with a simple wrapper that updates local storage after calling setCookie

@SamMousa SamMousa marked this pull request as draft November 18, 2024 10:46
@SamMousa
Copy link
Author

Pff, it took me a while to realize that I have to run node 18. Tests are really still brittle; running pnpm test:browser leads to enormous amounts of failed tests.

This PR is almost done.

I've simplified the code even further; no code depends on tough-cookie, except cookieStore.ts, cookieStore exposes only the minimum functionality MSW uses, this reduces coupling and if we want to we can more easily swap to other cookie libraries in the future.

I'm not familiar with pnpm and therefore not sure how to resolve the pnpm-lock.yaml conflicts. I just redid the changes in dependencies directly from main by running these commands:

> pnpm remove @bundled-es-modules/tough-cookie
> pnpm add tough-cookie

This is ready for review, please run the tests in CI to see what's wrong, locally, as expected, browser tests have high failure rates (on main as well).

@SamMousa SamMousa marked this pull request as ready for review November 18, 2024 14:02
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.

2 participants