Skip to content

Move to monorepo #2732

Open
Open

Description

@ronag

This would solve...

Currently the undici package is quite heavy with a lot of stuff that you might not need, e.g. web api. Would be good to separate undici "core" into its own package.

The implementation should look like...

Use pnpm

Activity

  1. metcoder95 commented on Feb 12, 2024

    @metcoder95
    Member

    I think @Ethan-Arrowood was managing this idea for a while, after the split of undici-types

  2. Ethan-Arrowood commented on Feb 12, 2024

    @Ethan-Arrowood
    Collaborator

    There's some old threads about monorepo ideas. Happy to revisit

  3. mcollina commented on Feb 12, 2024

    @mcollina
    SponsorMember

    I think it's inevitable that we adopt a monorepo at this point, this project has grown too big, and there are separate subsystems that could be used separately.

  4. Ethan-Arrowood commented on Feb 12, 2024

    @Ethan-Arrowood
    Collaborator

    Use pnpm

    This is also my preference. Does anyone feel extra-strongly about using npm?

    pnpm is now included in corepack so it should be very easy for everyone to use it without any additional install or set up (minus a corepack enable call).

  5. Ethan-Arrowood commented on Feb 12, 2024

    @Ethan-Arrowood
    Collaborator

    I will also start by experimenting with npm workspaces to start. They've supposedly come along way so maybe its worth trying again.

  6. mcollina commented on Feb 12, 2024

    @mcollina
    SponsorMember

    I've not been able to make npm workspace work in any reasonable way for OSS development

    I think the most useful part would be if somebody could figure out how to set it up with changesets so that we could ship independent versions of the packages. Alternatively, they will all have the same version.

  7. Ethan-Arrowood commented on Feb 12, 2024

    @Ethan-Arrowood
    Collaborator

    I have experience with changesets. Do you want me to try npm+changesets or go straight to pnpm+changesets?

  8. Ethan-Arrowood commented on Feb 13, 2024

    @Ethan-Arrowood
    Collaborator

    Rough plan:

    1. Create PR that moves everything into packages/undici and documentation
      • No code will split up just yet
      • CI should run as normal
      • Docs site should work as normal
      • Other tooling should continue to work (build, commit hooks, etc.), and run from root as normal
      • This should only introduce npm workspaces. Changesets should not be required.
      • Even though the code will exist in packages/undici directory, the package should still be named and published as undici (for now).
      • (In nodejs/node) Update Node.js -> Undici vendor process

    Step 1 is simply the first step in migrating to a monorepo. This will reduce impact on contributors and should not disrupt development.

    1. Code split (incremental)
      • Create new packages packages/core, packages/fetch, and packages/types
      • Start publishing packages as @undici/core, @undici/fetch, and @undici/types
      • Retain packages/undici as undici and make it roll-up and export all of the other packages
      • Introduce changesets for version and publishing management.
      • (Optional) Move linting and formatting to root

    Step 2 serves as an incremental step to a true monorepo organization. By retaining undici package we don't have to affect Node.js or users. Everything will appear as normal.

    1. Migrate Node.js from undici to @undici/fetch

      • Make necessary change in nodejs/node to vendor @undici/fetch instead of undici
    2. More code splitting!

      • Intentionally not-well-defined at this time, consider other parts of Undici that we can split out into its own separate packages.
  9. mcollina commented on Feb 13, 2024

    @mcollina
    SponsorMember

    I'm +1

  10. metcoder95 commented on Feb 13, 2024

    @metcoder95
    Member

    LGTM 🚀

  11. Ethan-Arrowood commented on Feb 19, 2024

    @Ethan-Arrowood
    Collaborator

    I'll have a PR up for step 1 very soon. I'd like to land #2766 first as that will help simplify things.

  12. mcollina commented on Feb 20, 2024

    @mcollina
    SponsorMember

    My experience with npm workspaces is that they are not fit for purpose. Specifically, they are missing the workspace protocol, https://pnpm.io/workspaces#referencing-workspace-packages-through-aliases, which makes it impossible to maintain an OSS library without it. (Or I couldn’t figure out how to handle versioning).


    @KhafraDev wdyt?

  13. Ethan-Arrowood commented on Feb 20, 2024

    @Ethan-Arrowood
    Collaborator

    I've found more success where versions are updated by a tool such as changesets. That said, switching to pnpm has other great benefits -- and everyone can do it since it's supported in corepack. Ill make sure to present options for us to consider

  14. Uzlopak commented on Feb 20, 2024

    @Uzlopak
    Contributor

    I dont like monorepos. They make managing code complicated. I would rather have one package released on npm with everything than having to manage many packages where each package has different versions.

  15. 20 remaining items

  16. KhafraDev commented on Feb 21, 2024

    @KhafraDev
    Member

    Then I would suggest to split it into two different repos. undici core and undici web.

    I'd prefer this over a monorepo.

    Sure the code lives in separate folders, but yet we still have a lot of it. It is difficult to know where to make changes, how to add new apis, etc.

    @Uzlopak was able to add EventSource without any help from me or anyone else on how to organize code. If we're talking about the lower leveled dispatcher api/mocks/ProxyAgent/etc., that simply isn't an issue with the web stuff and wouldn't be solved by moving it. Moving the web code to their own folder (in the PR linked here) will let people use tooling to ignore those files.

    Not only that, others have made breaking changes relatively quickly lately (such as the removal of some dispatcher handler options and interceptors).

    possibly axios, got etc...

    axios and got both use node:http and axios will use XMLHttpRequest in browsers. If axios ever moved to fetch then they likely use undici's fetch instead of undici core (or just global fetch). I know this is very shitty proof but I looked at the most downloaded dependents of undici on npm and every single one of them used fetch. I would go so far as to say that undici.fetch is just as fundamentally important as undici.request, etc., as they both serve two entirely separate use cases in a similar api.

    I haven't thought too much about what a minimal @undici/core would contain. I find the current Dispatcher implementation to be confusing. The indirection in particular is the worst part (such as the makeDispatcher piece in index.js). This obviously was done for good reason (such as extending/implementing the interface in an easy way across the repo). But if for example these pieces lived in their own module, it could force us to come up with a better API for other pieces like the Mock interfaces or custom Handlers.

    I'm very confused as to how you came to the conclusion that the core api being confusing can be solved by moving the web stuff. The web stuff doesn't need docs, and this seems like a documentation issue w.r.t. core.

    I can't speak on information density because I've never had issues with it honestly. Of course we could move MockAgent or ProxyAgent to their own packages, and I wouldn't have an issue with that, because they are higher leveled than even fetch, and do not rely on core.

    Fetch relies on core internals and core relies on fetch internals (specifically undici.request w/ a FormData body). There is no easy way of decoupling fetch from core with a benefit that seems to boil down to '[core/web] is too [confusing/big]' ("big" in a more abstract way than package size). From what I've seen @Ethan-Arrowood mostly has an issue with documentation in core, because the web stuff simply has enough documentation on MDN or a million other places.

    So I would like to leave a few questions:

  17. Ethan-Arrowood commented on Feb 21, 2024

    @Ethan-Arrowood
    Collaborator

    In short, yes many of these issues can be solved with better/more documentation AND improved code organization (not necessarily meaning monorepo). Let's start there and iterate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions