@ranimontagna/agent-toolkit 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/package.json +1 -1
- package/skills/backend/api/api-design/LICENSE +21 -0
- package/skills/backend/api/api-design/NOTICE.md +7 -0
- package/skills/backend/api/api-design/SKILL.md +523 -0
- package/skills/frontend/astro/astro-developer/LICENSE +59 -0
- package/skills/frontend/astro/astro-developer/NOTICE.md +7 -0
- package/skills/frontend/astro/astro-developer/SKILL.md +132 -0
- package/skills/frontend/astro/astro-developer/architecture.md +435 -0
- package/skills/frontend/astro/astro-developer/constraints.md +559 -0
- package/skills/frontend/astro/astro-developer/debugging.md +513 -0
- package/skills/frontend/astro/astro-developer/testing.md +973 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: astro-developer
|
|
3
|
+
description: Use when developing Astro framework internals, integrations, features, fixes, tests, debugging, or understanding the official Astro monorepo architecture and constraints.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Astro Developer Skill
|
|
7
|
+
|
|
8
|
+
Context-loading skill for AI agents and developers working in the Astro monorepo. Loads relevant documentation based on your task.
|
|
9
|
+
|
|
10
|
+
## Quick Decision Matrix
|
|
11
|
+
|
|
12
|
+
**What are you doing?** → **Read these files:**
|
|
13
|
+
|
|
14
|
+
| Task | Primary Docs | Supporting Docs |
|
|
15
|
+
| -------------------------- | -------------------------------------------------------------------- | ---------------------------------- |
|
|
16
|
+
| Adding a core feature | [architecture.md](architecture.md), [constraints.md](constraints.md) | [testing.md](testing.md) |
|
|
17
|
+
| Fixing a bug | [debugging.md](debugging.md) | [architecture.md](architecture.md) |
|
|
18
|
+
| Writing/fixing tests | [testing.md](testing.md) | [constraints.md](constraints.md) |
|
|
19
|
+
| Creating an integration | Explore `packages/integrations/` for examples | [testing.md](testing.md) |
|
|
20
|
+
| Understanding architecture | [architecture.md](architecture.md) | - |
|
|
21
|
+
| Dealing with errors | [debugging.md](debugging.md), [constraints.md](constraints.md) | [testing.md](testing.md) |
|
|
22
|
+
| Understanding constraints | [constraints.md](constraints.md) | [architecture.md](architecture.md) |
|
|
23
|
+
|
|
24
|
+
## Critical Warnings
|
|
25
|
+
|
|
26
|
+
**Before you start, be aware of these common pitfalls:**
|
|
27
|
+
|
|
28
|
+
1. **Prefer Unit Tests**: Write unit-testable code by default. Use integration tests only when necessary → [testing.md](testing.md)
|
|
29
|
+
2. **Node.js API Restrictions**: Cannot use Node.js APIs in `runtime/` code → [constraints.md](constraints.md)
|
|
30
|
+
3. **Test Isolation**: Must set unique `outDir` for each integration test → [testing.md](testing.md)
|
|
31
|
+
4. **Runtime Boundaries**: Core vs Vite vs Browser execution contexts → [architecture.md](architecture.md)
|
|
32
|
+
5. **Prerelease Mode**: Changesets target `origin/next` branch (check `.changeset/config.json`)
|
|
33
|
+
|
|
34
|
+
## Quick Command Reference
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Development
|
|
38
|
+
pnpm install # Install (root only)
|
|
39
|
+
pnpm run build # Build all packages
|
|
40
|
+
pnpm run dev # Watch mode
|
|
41
|
+
pnpm run lint # Lint codebase
|
|
42
|
+
|
|
43
|
+
# Testing
|
|
44
|
+
pnpm -C packages/astro exec astro-scripts test "test/**/*.test.js" # All tests
|
|
45
|
+
pnpm -C packages/astro exec astro-scripts test -m "pattern" # Filter tests
|
|
46
|
+
pnpm run test:e2e # E2E tests
|
|
47
|
+
node --test test/file.test.js # Single test
|
|
48
|
+
|
|
49
|
+
# Examples
|
|
50
|
+
pnpm --filter @example/minimal run dev # Run example
|
|
51
|
+
|
|
52
|
+
# Changesets
|
|
53
|
+
pnpm exec changeset --empty # Create changeset, no interactive mode
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Key File Paths
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
packages/astro/src/
|
|
60
|
+
├── core/ # Node.js execution context (build/dev commands)
|
|
61
|
+
├── runtime/
|
|
62
|
+
│ ├── server/ # Vite SSR execution context
|
|
63
|
+
│ └── client/ # Browser execution context
|
|
64
|
+
├── virtual-modules/ # Virtual module entry points
|
|
65
|
+
├── content/ # Content layer system
|
|
66
|
+
├── vite-plugin-*/ # Vite plugins
|
|
67
|
+
└── types/ # Centralized TypeScript types
|
|
68
|
+
|
|
69
|
+
packages/integrations/ # Official integrations
|
|
70
|
+
examples/ # Test your changes here
|
|
71
|
+
test/fixtures/ # Test fixtures
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Note**: Error stack traces in `node_modules/` map to source in `packages/`. See [architecture.md](architecture.md) for details.
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
This skill loads relevant context—it doesn't orchestrate workflows. After loading appropriate docs:
|
|
79
|
+
|
|
80
|
+
1. Read the recommended files for your task
|
|
81
|
+
2. Apply the patterns and constraints described
|
|
82
|
+
3. Use the commands and file paths provided
|
|
83
|
+
4. Search docs for error messages if you encounter issues
|
|
84
|
+
|
|
85
|
+
## Architecture Quick Summary
|
|
86
|
+
|
|
87
|
+
**Three Execution Contexts:**
|
|
88
|
+
|
|
89
|
+
- **core/** → Node.js, build/dev commands, avoid Node APIs except in Vite plugins
|
|
90
|
+
- **runtime/server/** → Vite SSR, CANNOT use Node APIs
|
|
91
|
+
- **runtime/client/** → Browser, CANNOT use Node APIs at all
|
|
92
|
+
|
|
93
|
+
**Five Pipeline Types:**
|
|
94
|
+
|
|
95
|
+
- **RunnablePipeline** → `astro dev` with Vite loader system
|
|
96
|
+
- **NonRunnablePipeline** → `astro dev` without runtime module loading (Cloudflare adapter)
|
|
97
|
+
- **BuildPipeline** → `astro build` + prerendering
|
|
98
|
+
- **AppPipeline** → Production serverless/SSR
|
|
99
|
+
- **ContainerPipeline** → Container API
|
|
100
|
+
|
|
101
|
+
See [architecture.md](architecture.md) for complete details.
|
|
102
|
+
|
|
103
|
+
## Testing Quick Summary
|
|
104
|
+
|
|
105
|
+
**Philosophy**: Prefer unit tests over integration tests. Write unit-testable code by default.
|
|
106
|
+
|
|
107
|
+
**Unit tests** (fast, preferred):
|
|
108
|
+
|
|
109
|
+
- Test pure functions and business logic
|
|
110
|
+
- Extract business logic from infrastructure
|
|
111
|
+
- Use dependency injection
|
|
112
|
+
|
|
113
|
+
**Integration tests** (slow, use sparingly):
|
|
114
|
+
|
|
115
|
+
- Only for features that cannot be unit tested (virtual modules, full build pipeline)
|
|
116
|
+
- Always set unique `outDir` to avoid cache pollution
|
|
117
|
+
|
|
118
|
+
See [testing.md](testing.md) for complete patterns and examples.
|
|
119
|
+
|
|
120
|
+
## When NOT to Use This Skill
|
|
121
|
+
|
|
122
|
+
- **Bug triage**: Use the `triage` skill instead
|
|
123
|
+
- **GitHub Actions analysis**: Use the `analyze-github-action-logs` skill
|
|
124
|
+
- **Simple questions**: Just ask directly, don't load this skill
|
|
125
|
+
|
|
126
|
+
## Related Documentation
|
|
127
|
+
|
|
128
|
+
- Root: [/AGENTS.md](https://github.com/withastro/astro/blob/main/AGENTS.md)
|
|
129
|
+
- Root: [/CONTRIBUTING.md](https://github.com/withastro/astro/blob/main/CONTRIBUTING.md)
|
|
130
|
+
- Astro docs: https://docs.astro.build/llms.txt
|
|
131
|
+
- Package: packages/astro/src/core/README.md
|
|
132
|
+
- Build plugins: packages/astro/src/core/build/plugins/README.md
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
# Architecture Guide
|
|
2
|
+
|
|
3
|
+
Understanding Astro's internal architecture is critical for effective development. This guide covers execution contexts, pipelines, virtual modules, and content layer architecture.
|
|
4
|
+
|
|
5
|
+
## Three Execution Contexts
|
|
6
|
+
|
|
7
|
+
Astro code runs in three distinct environments. Understanding which context your code executes in determines what APIs you can use and how to debug it.
|
|
8
|
+
|
|
9
|
+
### Context 1: Node.js (Core)
|
|
10
|
+
|
|
11
|
+
**Location**: `packages/astro/src/core/`
|
|
12
|
+
|
|
13
|
+
**When it runs**: During `astro dev`, `astro build`, and CLI commands
|
|
14
|
+
|
|
15
|
+
**Characteristics**:
|
|
16
|
+
|
|
17
|
+
- Node.js environment (but contains mixed code)
|
|
18
|
+
- Contains both build-time AND runtime code
|
|
19
|
+
- Node.js API usage should be avoided except in Vite plugins
|
|
20
|
+
- Powers build orchestration and dev server setup
|
|
21
|
+
|
|
22
|
+
**Note**: `core/` is not purely build-time - avoid Node.js APIs unless in Vite plugin implementations
|
|
23
|
+
|
|
24
|
+
**Examples**:
|
|
25
|
+
|
|
26
|
+
- `packages/astro/src/core/build/` → Build orchestration (mixed)
|
|
27
|
+
- `packages/astro/src/core/dev/` → Dev server setup (mixed)
|
|
28
|
+
- `packages/astro/src/cli/` → CLI commands (pure Node.js)
|
|
29
|
+
|
|
30
|
+
**Debug with**: Standard Node debugging, console.log, `node --inspect`
|
|
31
|
+
|
|
32
|
+
### Context 2: Vite SSR (Runtime Server)
|
|
33
|
+
|
|
34
|
+
**Location**: `packages/astro/src/runtime/server/`
|
|
35
|
+
|
|
36
|
+
**When it runs**: Inside Vite's SSR environment during rendering
|
|
37
|
+
|
|
38
|
+
**Characteristics**:
|
|
39
|
+
|
|
40
|
+
- Node environment BUT isolated from core
|
|
41
|
+
- **CANNOT use Node.js APIs** (`node:fs`, `node:path`, etc.)
|
|
42
|
+
- Must work in non-Node runtimes (Cloudflare Workers, Deno)
|
|
43
|
+
- Use `@astrojs/internal-helpers` for cross-platform utilities
|
|
44
|
+
|
|
45
|
+
**Rule**: If the file path contains `/runtime/`, absolutely NO Node.js APIs
|
|
46
|
+
|
|
47
|
+
**Examples**:
|
|
48
|
+
|
|
49
|
+
- `packages/astro/src/runtime/server/render/` → Page rendering
|
|
50
|
+
- Virtual modules loaded during SSR
|
|
51
|
+
|
|
52
|
+
**Debug with**: `DEBUG=astro:*` environment variable
|
|
53
|
+
|
|
54
|
+
### Context 3: Browser (Runtime Client)
|
|
55
|
+
|
|
56
|
+
**Location**: `packages/astro/src/runtime/client/`
|
|
57
|
+
|
|
58
|
+
**When it runs**: In the browser after page load
|
|
59
|
+
|
|
60
|
+
**Characteristics**:
|
|
61
|
+
|
|
62
|
+
- Browser-only environment
|
|
63
|
+
- CANNOT use any Node.js APIs
|
|
64
|
+
- Only browser-compatible code allowed
|
|
65
|
+
- Handles partial hydration, client-side routing
|
|
66
|
+
|
|
67
|
+
**Examples**:
|
|
68
|
+
|
|
69
|
+
- `packages/astro/src/runtime/client/idle.ts` → Idle hydration
|
|
70
|
+
- `packages/astro/src/runtime/client/visible.ts` → Visible hydration
|
|
71
|
+
|
|
72
|
+
**Debug with**: Browser DevTools, console.log in browser
|
|
73
|
+
|
|
74
|
+
## Pipeline Architecture
|
|
75
|
+
|
|
76
|
+
Astro uses a base `Pipeline` class with multiple implementations for different environments.
|
|
77
|
+
|
|
78
|
+
### Pipeline Hierarchy
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
Pipeline (abstract base class)
|
|
82
|
+
├── RunnablePipeline → Dev with RunnableDevEnvironment
|
|
83
|
+
├── NonRunnablePipeline → Dev with NonRunnableDevEnvironment
|
|
84
|
+
├── BuildPipeline → Build and prerendering
|
|
85
|
+
├── AppPipeline → Production SSR/serverless
|
|
86
|
+
└── ContainerPipeline → Container API
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Location**: `packages/astro/src/core/base-pipeline.ts`
|
|
90
|
+
|
|
91
|
+
### Pipeline Types
|
|
92
|
+
|
|
93
|
+
#### 1. RunnablePipeline
|
|
94
|
+
|
|
95
|
+
**When**: During `astro dev` with Vite RunnableDevEnvironment
|
|
96
|
+
**Purpose**: Handle dev server requests with runtime module loading
|
|
97
|
+
**Location**: `packages/astro/src/vite-plugin-app/pipeline.ts`
|
|
98
|
+
**Characteristics**:
|
|
99
|
+
|
|
100
|
+
- Contains reference to Vite loader system
|
|
101
|
+
- Can import modules at runtime via Vite environment APIs
|
|
102
|
+
- Hot module reloading support
|
|
103
|
+
- Standard dev workflow
|
|
104
|
+
|
|
105
|
+
**Best practice**: Avoid runtime module imports when possible. Prefer Vite plugins and virtual modules instead.
|
|
106
|
+
|
|
107
|
+
#### 2. NonRunnablePipeline
|
|
108
|
+
|
|
109
|
+
**When**: During `astro dev` with Vite NonRunnableDevEnvironment
|
|
110
|
+
**Purpose**: Handle dev server requests without runtime module loading
|
|
111
|
+
**Location**: `packages/astro/src/core/app/dev/pipeline.ts`
|
|
112
|
+
**Characteristics**:
|
|
113
|
+
|
|
114
|
+
- Used by adapters like Cloudflare
|
|
115
|
+
- No reference to Vite loader system
|
|
116
|
+
- Cannot import modules at runtime
|
|
117
|
+
- Must rely entirely on Vite plugins and virtual modules
|
|
118
|
+
|
|
119
|
+
**Critical**: This is why code must avoid runtime module imports and use plugins/virtual modules instead
|
|
120
|
+
|
|
121
|
+
#### 3. BuildPipeline
|
|
122
|
+
|
|
123
|
+
**When**: During `astro build` and prerendering
|
|
124
|
+
**Purpose**: Generate static HTML and handle prerendering
|
|
125
|
+
**Location**: `packages/astro/src/core/build/pipeline.ts`
|
|
126
|
+
**Characteristics**:
|
|
127
|
+
|
|
128
|
+
- Optimized output
|
|
129
|
+
- Static generation
|
|
130
|
+
- Asset processing
|
|
131
|
+
- Prerendering logic
|
|
132
|
+
|
|
133
|
+
#### 4. AppPipeline
|
|
134
|
+
|
|
135
|
+
**When**: Production runtime (serverless/SSR)
|
|
136
|
+
**Purpose**: Serve dynamic requests in production
|
|
137
|
+
**Location**: `packages/astro/src/core/app/pipeline.ts`
|
|
138
|
+
**Characteristics**:
|
|
139
|
+
|
|
140
|
+
- No build-time dependencies
|
|
141
|
+
- Optimized for cold starts
|
|
142
|
+
- Adapter integration
|
|
143
|
+
- Production error handling
|
|
144
|
+
|
|
145
|
+
#### 5. ContainerPipeline
|
|
146
|
+
|
|
147
|
+
**When**: Using the Container API
|
|
148
|
+
**Purpose**: Programmatic rendering outside of normal Astro contexts
|
|
149
|
+
**Location**: `packages/astro/src/container/pipeline.ts`
|
|
150
|
+
**Characteristics**:
|
|
151
|
+
|
|
152
|
+
- Standalone rendering
|
|
153
|
+
- Component interning cache
|
|
154
|
+
- Used for testing and programmatic access
|
|
155
|
+
|
|
156
|
+
### Base Pipeline
|
|
157
|
+
|
|
158
|
+
**Pipeline** (abstract base class): Static parts that don't change between requests
|
|
159
|
+
|
|
160
|
+
From `packages/astro/src/core/base-pipeline.ts`:
|
|
161
|
+
|
|
162
|
+
- Configuration
|
|
163
|
+
- Logger
|
|
164
|
+
- Manifest
|
|
165
|
+
- Runtime mode (development/production)
|
|
166
|
+
- Middleware
|
|
167
|
+
- Actions
|
|
168
|
+
- Internal caches
|
|
169
|
+
|
|
170
|
+
**All pipeline implementations extend this base class**
|
|
171
|
+
|
|
172
|
+
### RenderContext vs Pipeline
|
|
173
|
+
|
|
174
|
+
**Pipeline**: Constant per server/build session (static)
|
|
175
|
+
|
|
176
|
+
- Created once at process start
|
|
177
|
+
- Reused for every request
|
|
178
|
+
- Contains configuration and settings
|
|
179
|
+
|
|
180
|
+
**RenderContext**: Per-request data (dynamic)
|
|
181
|
+
|
|
182
|
+
- Created for each request
|
|
183
|
+
- Current URL
|
|
184
|
+
- Matched route
|
|
185
|
+
- Request locals
|
|
186
|
+
- i18n context
|
|
187
|
+
- Middleware execution
|
|
188
|
+
|
|
189
|
+
## Virtual Modules System
|
|
190
|
+
|
|
191
|
+
Virtual modules are a core pattern in Astro. They're "files" that don't exist on disk but are generated at build/dev time.
|
|
192
|
+
|
|
193
|
+
### Virtual Module Conventions
|
|
194
|
+
|
|
195
|
+
**Prefix**: `virtual:astro:*` for Astro-internal, `\0` prefix for Rollup-internal (Rollup convention)
|
|
196
|
+
|
|
197
|
+
**Pattern**:
|
|
198
|
+
|
|
199
|
+
1. Internal code imports `virtual:astro:something`
|
|
200
|
+
2. Vite plugin `resolveId` hook returns `\0virtual:astro:something`
|
|
201
|
+
3. Vite plugin `load` hook returns generated code
|
|
202
|
+
|
|
203
|
+
### Core Virtual Modules Registry
|
|
204
|
+
|
|
205
|
+
**File**: `packages/astro/src/virtual-modules/`
|
|
206
|
+
|
|
207
|
+
| Module | Purpose | Source |
|
|
208
|
+
| -------------------------- | -------------------------------------------- | --------------------- |
|
|
209
|
+
| `virtual:astro:routes` | Route definitions | Generated from pages/ |
|
|
210
|
+
| `virtual:astro:manifest` | Serialized manifest (single source of truth) | Build output |
|
|
211
|
+
| `virtual:astro:pages` | Page collections | Generated from pages/ |
|
|
212
|
+
| `virtual:astro:renderers` | Framework renderers | Integration config |
|
|
213
|
+
| `virtual:astro:middleware` | Middleware module | src/middleware.ts |
|
|
214
|
+
| `virtual:astro:dev-css` | Dev-mode CSS modules | Vite dev |
|
|
215
|
+
| `virtual:astro:app` | App pipeline | Production runtime |
|
|
216
|
+
| `virtual:image-service` | Image service config | Config + integrations |
|
|
217
|
+
|
|
218
|
+
**Actions Virtual Modules**:
|
|
219
|
+
|
|
220
|
+
- `virtual:astro:actions/entrypoint` → Actions entry
|
|
221
|
+
- `virtual:astro:actions/options` → Actions configuration
|
|
222
|
+
|
|
223
|
+
**Adapter Virtual Modules**:
|
|
224
|
+
|
|
225
|
+
- `virtual:astro:adapter-config` → Adapter configuration
|
|
226
|
+
- `virtual:astro:adapter-entrypoint` → Adapter entry point
|
|
227
|
+
|
|
228
|
+
### Internal Page Virtual Modules
|
|
229
|
+
|
|
230
|
+
**Prefix**: `@astro-page:*` (legacy pattern, specific to pages)
|
|
231
|
+
|
|
232
|
+
**Note**: This is an older pattern used specifically for page modules. New virtual modules should use `virtual:astro:*` instead unless there's a specific reason to deviate.
|
|
233
|
+
|
|
234
|
+
**Example**: `@astro-page:src/pages/index.astro` → Virtual module for index page
|
|
235
|
+
|
|
236
|
+
**Standard pattern for new plugins**: Use `virtual:astro:*` prefix
|
|
237
|
+
|
|
238
|
+
### Virtual Module Implementation Pattern
|
|
239
|
+
|
|
240
|
+
**Current pattern** (see `packages/astro/src/core/build/plugins/plugin-ssr.ts`):
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const VIRTUAL_MODULE_ID = 'virtual:astro:my-module';
|
|
244
|
+
const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
|
|
245
|
+
|
|
246
|
+
// In Vite plugin
|
|
247
|
+
{
|
|
248
|
+
name: '@astrojs/vite-plugin-my-module',
|
|
249
|
+
resolveId: {
|
|
250
|
+
filter: {
|
|
251
|
+
id: new RegExp(`^${VIRTUAL_MODULE_ID}$`),
|
|
252
|
+
},
|
|
253
|
+
handler() {
|
|
254
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
load: {
|
|
258
|
+
filter: {
|
|
259
|
+
id: new RegExp(`^${RESOLVED_VIRTUAL_MODULE_ID}$`),
|
|
260
|
+
},
|
|
261
|
+
handler() {
|
|
262
|
+
return {
|
|
263
|
+
code: `export default ${JSON.stringify(data)}`,
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Pattern**: Use `filter/id/handler` structure for both `resolveId` and `load` hooks.
|
|
271
|
+
|
|
272
|
+
## Content Layer Architecture
|
|
273
|
+
|
|
274
|
+
The content layer handles content collections at build time and runtime.
|
|
275
|
+
|
|
276
|
+
### Key Components
|
|
277
|
+
|
|
278
|
+
**Location**: `packages/astro/src/content/`
|
|
279
|
+
|
|
280
|
+
| Component | File | Purpose |
|
|
281
|
+
| ------------------ | ------------------------------ | ------------------------------- |
|
|
282
|
+
| Content Layer | `content-layer.ts` (479 lines) | Main orchestration |
|
|
283
|
+
| Data Store | `data-store.ts` | Read-only runtime store |
|
|
284
|
+
| Mutable Data Store | `mutable-data-store.ts` | Build-time mutable store |
|
|
285
|
+
| Runtime API | `runtime.ts` | `getCollection()`, `getEntry()` |
|
|
286
|
+
| Types Generator | `types-generator.ts` | TypeScript type generation |
|
|
287
|
+
| Watcher | `watcher.ts` | File system watching |
|
|
288
|
+
|
|
289
|
+
### Content Layer Flow
|
|
290
|
+
|
|
291
|
+
```
|
|
292
|
+
Build Time:
|
|
293
|
+
┌─────────────┐ ┌──────────────┐ ┌────────────────┐
|
|
294
|
+
│ Loaders │───▶│MutableStore │───▶│.astro/data- │
|
|
295
|
+
│(load data) │ │(collect data)│ │store.json │
|
|
296
|
+
└─────────────┘ └──────────────┘ └────────────────┘
|
|
297
|
+
│
|
|
298
|
+
▼
|
|
299
|
+
┌──────────────┐
|
|
300
|
+
│Types Generator│
|
|
301
|
+
└──────────────┘
|
|
302
|
+
|
|
303
|
+
Runtime:
|
|
304
|
+
┌────────────────┐ ┌──────────┐ ┌─────────────┐
|
|
305
|
+
│.astro/data- │───▶│DataStore │───▶│Runtime API │
|
|
306
|
+
│store.json │ │(read-only)│ │(getCollection)│
|
|
307
|
+
└────────────────┘ └──────────┘ └─────────────┘
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Content Constants
|
|
311
|
+
|
|
312
|
+
**File**: `packages/astro/src/content/consts.ts`
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
DATA_STORE_FILE = '.astro/data-store.json';
|
|
316
|
+
COLLECTIONS_MANIFEST_FILE = 'collections-manifest.json';
|
|
317
|
+
MODULES_IMPORTS_FILE = 'modules-imports.json';
|
|
318
|
+
ASSET_IMPORTS_FILE = 'asset-imports.json';
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Live Collections (Astro 5+)
|
|
322
|
+
|
|
323
|
+
**New pattern**: Fetch data at runtime rather than build time
|
|
324
|
+
|
|
325
|
+
**Configuration**: Separate from build-time collections
|
|
326
|
+
|
|
327
|
+
- Build-time: `src/content/config.ts`
|
|
328
|
+
- Runtime: `src/live.config.ts`
|
|
329
|
+
|
|
330
|
+
**Loader Protocol**: Loaders must implement standard interface
|
|
331
|
+
|
|
332
|
+
## Vite Plugin Architecture
|
|
333
|
+
|
|
334
|
+
**Location**: `packages/astro/src/vite-plugin-*/`
|
|
335
|
+
|
|
336
|
+
Vite plugins execute within Vite's context (similar to runtime/server).
|
|
337
|
+
|
|
338
|
+
### Build Plugins
|
|
339
|
+
|
|
340
|
+
**Location**: `packages/astro/src/core/build/plugins/`
|
|
341
|
+
|
|
342
|
+
**Documentation**: `packages/astro/src/core/build/plugins/README.md`
|
|
343
|
+
|
|
344
|
+
**Plugin Responsibilities**:
|
|
345
|
+
|
|
346
|
+
1. **plugin-middleware**: Emits `middleware.mjs` if present
|
|
347
|
+
2. **plugin-renderers**: Collects renderers → `renderers.mjs`
|
|
348
|
+
3. **plugin-pages**: Virtual modules for each page (static builds)
|
|
349
|
+
4. **plugin-ssr**: Creates SSR entry points
|
|
350
|
+
5. **plugin-manifest**: Creates `manifest.mjs` (single source of truth)
|
|
351
|
+
|
|
352
|
+
### Plugin Execution Order
|
|
353
|
+
|
|
354
|
+
Plugins work together in sequence:
|
|
355
|
+
|
|
356
|
+
1. Middleware plugin runs first
|
|
357
|
+
2. Renderers collected
|
|
358
|
+
3. Pages processed
|
|
359
|
+
4. SSR entries created
|
|
360
|
+
5. Manifest generated (final step)
|
|
361
|
+
|
|
362
|
+
## Package Structure
|
|
363
|
+
|
|
364
|
+
### Monorepo Organization
|
|
365
|
+
|
|
366
|
+
```
|
|
367
|
+
packages/
|
|
368
|
+
├── astro/ # Core package
|
|
369
|
+
│ ├── src/
|
|
370
|
+
│ │ ├── core/ # Node.js build/dev
|
|
371
|
+
│ │ ├── runtime/ # Vite SSR + browser
|
|
372
|
+
│ │ ├── virtual-modules/ # Virtual module sources
|
|
373
|
+
│ │ ├── content/ # Content layer
|
|
374
|
+
│ │ ├── vite-plugin-*/ # Vite plugins
|
|
375
|
+
│ │ └── types/ # Centralized types
|
|
376
|
+
│ └── test/
|
|
377
|
+
│ ├── fixtures/ # Test fixtures
|
|
378
|
+
│ └── *.test.js # Unit tests
|
|
379
|
+
├── integrations/
|
|
380
|
+
│ ├── react/
|
|
381
|
+
│ ├── vue/
|
|
382
|
+
│ ├── svelte/
|
|
383
|
+
│ └── ...
|
|
384
|
+
└── create-astro/ # CLI scaffolding tool
|
|
385
|
+
|
|
386
|
+
examples/ # Example projects
|
|
387
|
+
├── blog/
|
|
388
|
+
├── minimal/
|
|
389
|
+
└── ...
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Node Modules Mapping
|
|
393
|
+
|
|
394
|
+
When you see errors in `node_modules/`, map back to source:
|
|
395
|
+
|
|
396
|
+
```
|
|
397
|
+
ERROR in node_modules/astro/dist/core/build/index.js
|
|
398
|
+
↓
|
|
399
|
+
FIX in packages/astro/src/core/build/index.ts
|
|
400
|
+
|
|
401
|
+
ERROR in node_modules/@astrojs/react/index.js
|
|
402
|
+
↓
|
|
403
|
+
FIX in packages/integrations/react/src/index.ts
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
**Rebuild required**: Edits to source files take effect after `pnpm run build`
|
|
407
|
+
|
|
408
|
+
## Critical Constraints
|
|
409
|
+
|
|
410
|
+
For detailed constraints including Node.js API restrictions, test isolation, virtual module conventions, and more, see [constraints.md](constraints.md).
|
|
411
|
+
|
|
412
|
+
**Key points:**
|
|
413
|
+
|
|
414
|
+
- Node.js APIs forbidden in `runtime/` folders
|
|
415
|
+
- Tests must use unique `outDir`
|
|
416
|
+
- Types centralized in `src/types/`
|
|
417
|
+
- Virtual modules use `virtual:astro:*` prefix
|
|
418
|
+
|
|
419
|
+
## Debugging
|
|
420
|
+
|
|
421
|
+
For comprehensive debugging strategies, see [debugging.md](debugging.md).
|
|
422
|
+
|
|
423
|
+
**Quick reference by context:**
|
|
424
|
+
|
|
425
|
+
- **Core (Node.js)**: Use `DEBUG=astro:*` or `node --inspect`
|
|
426
|
+
- **Runtime Server**: Check `DEBUG=astro:render,astro:server`
|
|
427
|
+
- **Runtime Client**: Use browser DevTools
|
|
428
|
+
- **Content Layer**: Inspect `.astro/data-store.json`
|
|
429
|
+
|
|
430
|
+
## Further Reading
|
|
431
|
+
|
|
432
|
+
- Core README: `packages/astro/src/core/README.md`
|
|
433
|
+
- Build Plugins: `packages/astro/src/core/build/plugins/README.md`
|
|
434
|
+
- Virtual Modules: `packages/astro/src/virtual-modules/README.md`
|
|
435
|
+
- CONTRIBUTING.md sections on code structure
|