-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
community onboarding: codebase documentation around runtime (#10612)
* document runtime * apply suggestions from code review
- Loading branch information
Showing
8 changed files
with
150 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,51 @@ | ||
# `core/` | ||
|
||
Code that executes within the top-level Node context. Contains the main Astro logic for the `build`, `dev`, `preview`, and `sync` commands, and also manages the Vite server and SSR. | ||
Code that executes directly on Node (not processed by vite). Contains the main Astro logic for the `build`, `dev`, `preview`, and `sync` commands, and also manages the lifecycle of the Vite server. | ||
|
||
The `core/index.ts` file is the main entry point for the `astro` package. | ||
The `core/index.ts` module exports the CLI commands as functions and is the main entrypoint of the `astro` package. | ||
```ts | ||
import { dev, build, preview, sync } from 'astro'; | ||
``` | ||
|
||
[See CONTRIBUTING.md](../../../../CONTRIBUTING.md) for a code overview. | ||
|
||
## Pipeline | ||
``` | ||
Pages | ||
used by / | ||
/ | ||
creates / | ||
App --------- AppPipeline AstroGlobal | ||
\ implements / | ||
\ creates / | ||
creates impl.\ provided to / | ||
vite-plugin-astro-server --------- DevPipeline ------ Pipeline ------------- RenderContext Middleware | ||
/ \ used by / | ||
/ creates \ / | ||
creates / implements \ / | ||
AstroBuilder --------- BuildPipeline APIContext | ||
\ | ||
\ | ||
used by \ | ||
Endpoints | ||
``` | ||
|
||
The pipeline is an internal concept that describes how Astro pages are eventually created and rendered to the user. | ||
## `App` | ||
|
||
Each pipeline has different requirements, criteria and quirks. Although, each pipeline must use the same underline functions, because | ||
the core of the pipeline is the same. | ||
## `vite-plugin-astro-server` (see `../vite-plugin-astro-server/`) | ||
|
||
The core of the pipeline is rendering a generic route (page, endpoint or redirect) and returning a `Response`. | ||
When rendering a route, a pipeline must pass a `RenderContext` and `ComponentInstance`. The way these two information are | ||
computed doesn't concern the core of a pipeline. In fact, these types will be computed in different manner based on the type of pipeline. | ||
## `AstroBuilder` | ||
|
||
Each consumer will decide how to handle a `Response`. | ||
## `Pipeline` | ||
|
||
The pipeline is an interface representing data that stays unchanged throughout the duration of the server or build. For example: the user configuration, the list of pages and endpoints in the project, and environment-specific way of gathering scripts and styles. | ||
|
||
There are 3 implementations of the pipeline: | ||
- `DevPipeline`: in-use during the `astro dev` CLI command. Created and used by `vite-plugin-astro-server`, and then forwarded to other internals. | ||
- `BuildPipeline`: in-use during the `astro build` command in `"static"` mode, and for prerendering in `"server"` and `"hybrid"` output modes. See `core/build/`. | ||
- `AppPipeline`: in-use during production server(less) deployments. Created and used by `App` (see `core/app/`), and then forwarded to other internals. | ||
|
||
All 3 expose a common, environment-agnostic interface which is used by the rest of the internals, most notably by `RenderContext`. | ||
|
||
## `RenderContext` | ||
|
||
Each request is rendered using a `RenderContext`. It manages data unique to each request. For example: the parsed `URL`, internationalization data, the `locals` object, and the route that matched the request. It is responsible for executing middleware, calling endpoints, and rendering pages by gathering necessary data from a `Pipeline`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters