unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.89k stars 496 forks source link

refactor: structure overhaul #2473

Closed pi0 closed 3 months ago

pi0 commented 4 months ago

This PR splits the Nitro codebase into logical scopes separated by subpath exports.

[!NOTE] This PR introduces lots of changes to the current 2.x codebase in order to make sure we can keep supporting Nitro 2.x for a longer term in parallel to Nitro 3.x. A lot of thoughts have been put in to make sure we don't intentionally break any common or documented usage. There is still a chance that some changes introduce regressions. We will keep investigating to find and resolve them as much as possible via Nitro nightly channel. If you spotted any, please feel free to open an issue and describe the case 🙏🏼

What happened to types?

Currently, types are split in several places from core, bundler, and runtime and exported from several places. Now they are unified and accessible from (type-only) nitropack/types subpath.

[!NOTE] This change is likely break-in usages augmenting Nitro types from "nitropack" subpath. This will be addressed in a subsequent PR after better testing via a backward-compatible polyfill.

What happened to the core?

Externally, almost nothing. Exactly the same exports are preserved for compatibility. Internally, some important major refactors happened:

What happened to runtime?

One of the messy parts of the current code structure was runtime. It was:

To add to the complexity, the virtual files were ALSO exposed in the same #internal/nitro/virtual namespace.

The new structure makes it much cleaner:

Since this PR is landing for Nitro 2.x, to avoid breaking changes in projects and frameworks that for any reason had to use #internal/nitro, there is a compatibility layer with minimal known usages (mainly from Nuxt codebase), they are maintained in src/runtime/_compat.

What is the new kit?

The new nitropack/kit exports common but shared utils + define helpers. More will be added in the next steps

pi0 commented 3 months ago

(this PR is likely making unsen regrssions as mentioned above and merge is intended to identify them end-to-end and fix in nightly channel progressively)