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

refactor: structure overhaul #2473

Merged
merged 32 commits into from
Jun 4, 2024
Merged

refactor: structure overhaul #2473

merged 32 commits into from
Jun 4, 2024

Conversation

pi0
Copy link
Member

@pi0 pi0 commented May 27, 2024

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

  • nitropack/cli: Nitro CLI. Will be used for standalone zero dep CLI package in the future
  • nitropack/core: Main utilities exposed for programmatic usage, dev and build + app (same as nitropack for now)
  • nitropack/runtime: Core server runtime logic (see notes below)
  • nitropack/types: All types unified in a single place (see notes below)
  • nitropack/config: Config type helper (loader, defaults, and normalizers live in core)
  • nitropack/kit: Possibly reusable utilities for module and preset authoring as well as external integrations
  • nitropack/presets: deployment presets (runtime, config, types) (refactor: overhaul presets structure #2446)
  • nitropack/meta: exposing current version (alternative to package.json imports - ca2282b)

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:

  • Config loader and resolvers moved to modular core/config
  • Core logic (nitro.ts) split into scan utils and config resolvers
  • Builder utils split into modular units for better maintenance

What happened to runtime?

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

  • Exposing all internal utils
  • Exposing userland utils (for auto imports)
  • Exposing preset internal utils
  • Available as #internal/nitro or #internal/nitro/* for import

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:

  • nitropack/runtime: Exposing userland utils (same as auto imports)
  • nitropack/runtime/internal/*: Exposing internal utils. Users and frameworks should NEVER EVER use them they will be soon protected as well to prevent wrongly importing from this namespace this is because we need to improve nitro internal implementation without imposing breaking changes
  • New virtual (+internal) imports:
    • #nitro-internal-pollyfills
    • #nitro-internal-virtual/*

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

  • defineNitroPreset and defineNitroModule
  • writeFile, isDirectory, prettyPath, resolveNitroPath

@pi0 pi0 marked this pull request as draft May 27, 2024 10:03
@pi0 pi0 changed the title [wip] refactor: structure overhaul refactor: structure overhaul Jun 4, 2024
@pi0 pi0 marked this pull request as ready for review June 4, 2024 17:52
@pi0
Copy link
Member Author

pi0 commented Jun 4, 2024

(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)

@pi0 pi0 merged commit d20ffcb into main Jun 4, 2024
5 checks passed
@pi0 pi0 deleted the refactor/struct branch June 4, 2024 17:53
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.

1 participant