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

build: mirror nitro and nitropack npm packages #2497

Merged
merged 13 commits into from
Jun 13, 2024
Merged

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Jun 7, 2024

TLDR

This PR allows a way to use nitro or nitropack as a dependency and import the same.

Context

With access to nitro npm package (thanks to @jgermade and @danielroe) we can adopt using a shorter name across.

I had some doubts about this from #1362 mainly because we cannot use @nitro/ namespace in npm but with structure overhaul (#2473) and adoption of subpath exports, this is no longer a concern + usage of subpaths gives much more reasons that more end-users would benefit from explicit imports in their codebase rather than usages of a zero-dep CLI utility.

Approach

Adoption is tricky. We have a lot of current users that depend on nitropack as canonical and nitro can be only versioned for >3 to avoid conflict with the previous state.

This PR:

  • Add builder configuration to have interchangeable import from nitro or nitropack
  • Adds an automated script to generate a virtual mirror package

The virtual mirror package does not copy but reexports subpaths. This is to ensure in mixed scenarios, we don't duplicate bundle and install sizes.

Mirror dependency

The mirror package needs to have a dependency on the main package. Using peerDependencies is ideal because can help to dedup, but it turns out in cases like using npm: alias package managers show strange behavior and won't install! So it main package is in the dependencies of the mirror package.

Nitro 2.x (current)

Nitro 2.x, will use nitropack as canonical as before to avoid any changes but only supports nitro/ subpath import aliases that will redirect to nitropack/ for forward compatibility.

We release nitro@2.x.y-nitropack-mirror (with 2.x tag) and nitro-nightly@2-compat for forward compatibility.

Nitro 3.x (next)

Nitro 3.x, will use nitro as canonical and redirect nitropack/ subpath imports.

We release nitropack@3.x.y-nitro-mirror (with the latest tag) and nitropack-nightly@3.x.y-nitro-mirror for backward compatibility.

TODO

  • (postponed) type augmentations should work via nitro/nitropack/nitro/types and nitropack/types regardless of canonical (nitro{pack}/types)

@pi0 pi0 changed the title [draft] feat: interchangeable usage of nitro and nitropack [wip] feat: interchangeable usage of nitro and nitropack Jun 7, 2024
@pi0 pi0 requested a review from danielroe June 7, 2024 11:40
@pi0 pi0 force-pushed the refactor/nitro-nitropack branch from 0b5e86a to 3190477 Compare June 13, 2024 11:36
@pi0 pi0 changed the title [wip] feat: interchangeable usage of nitro and nitropack build: mirror nitro and nitropack npm packages Jun 13, 2024
@pi0 pi0 marked this pull request as ready for review June 13, 2024 12:39
@pi0 pi0 merged commit 4842312 into main Jun 13, 2024
5 checks passed
@pi0 pi0 deleted the refactor/nitro-nitropack branch June 13, 2024 13:54
This was referenced Jun 13, 2024
@pi0 pi0 mentioned this pull request Sep 15, 2024
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