Skip to content

Commit ed451e2

Browse files
authored
Add Nitro and Nuxt integration entries (#15)
1 parent 770a957 commit ed451e2

24 files changed

Lines changed: 1594 additions & 2346 deletions

.agents/CONTEXT.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Safe Runtime Config
2+
3+
This context defines the project language for validating Nuxt and Nitro runtime configuration.
4+
5+
## Language
6+
7+
**Runtime validation**:
8+
Validation of the resolved server runtime config when Nitro starts.
9+
_Avoid_: startup validation, server validation
10+
11+
**Build validation**:
12+
Validation of configured runtime config during Nuxt or Nitro build hooks.
13+
_Avoid_: compile-time validation, static validation
14+
15+
## Relationships
16+
17+
- **Runtime validation** happens after runtime environment values have been resolved.
18+
- **Build validation** happens before the server starts.
19+
20+
## Example dialogue
21+
22+
> **Dev:** "Should this failure be handled by **Build validation**?"
23+
> **Domain expert:** "No, it depends on the server's resolved environment, so it belongs to **Runtime validation**."
24+
25+
## Flagged ambiguities
26+
27+
- "runtime validation" means validation when Nitro starts, not validation inside the Vue app runtime.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dist
1818
*.tgz
1919

2020
# Nuxt
21+
.nitro
2122
.nuxt
2223
.output
2324
.nuxtrc

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ Runtime validation uses [@cfworker/json-schema](https://github.com/cfworker/cfwo
286286
- Missing required environment variables in production
287287
- Invalid values that pass build-time checks but fail at runtime
288288

289+
Shelve runtime fetching is separate from validation ownership. If `shelve.fetchAtRuntime` is enabled, the Shelve runtime plugin runs before validation so fetched secrets are included in the validated config.
290+
289291
## ESLint Integration
290292

291293
The module includes an ESLint plugin that warns when using `useRuntimeConfig()` instead of `useSafeRuntimeConfig()`.

build.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { defineBuildConfig } from 'unbuild'
22

33
export default defineBuildConfig({
4-
entries: [{ input: 'src/eslint/index', name: 'eslint' }],
4+
entries: [
5+
{ input: 'src/nitro', name: 'nitro' },
6+
{ input: 'src/eslint/index', name: 'eslint' },
7+
],
58
declaration: true,
69
clean: false,
710
rollup: { emitCJS: false },
8-
externals: ['@typescript-eslint/utils', '@typescript-eslint/types', 'eslint'],
11+
externals: ['@nuxt/kit', '@typescript-eslint/utils', '@typescript-eslint/types', 'eslint'],
912
})

docs/content/1.guide/4.validation.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ icon: ph:seal-check
55

66
The module validates your runtime config to catch configuration errors early. By default, validation runs at build time only.
77

8+
Validation is handled by the package's Nitro module. In Nuxt apps, the Nuxt module exposes the user-facing API, types, and imports, then passes validation options into Nitro. Generated validation files are internal implementation details and their paths are not part of the public API.
9+
810
## Build-time Validation (Default)
911

10-
With default settings, validation runs at:
12+
With default settings, build validation runs through Nitro during:
1113

1214
- **Dev start** - when running `nuxt dev`
13-
- **Build completion** - when running `nuxt build`
15+
- **Build** - when running `nuxt build`
1416

1517
```ts [nuxt.config.ts]
1618
export default defineNuxtConfig({
@@ -54,6 +56,8 @@ When enabled:
5456
2. A Nitro plugin validates `useRuntimeConfig()` on cold start
5557
3. Uses [@cfworker/json-schema](https://github.com/cfworker/cfworker/tree/main/packages/json-schema) (~8KB, edge-compatible)
5658

59+
Shelve runtime fetching remains a separate integration. When `shelve.fetchAtRuntime` is enabled, that runtime fetch plugin runs before validation so fetched secrets can be validated.
60+
5761
What it catches:
5862

5963
- Missing env vars in production (`DATABASE_URL` not set)

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ export default antfu({
1313
'playground/shelve.json',
1414
'src/runtime/**/*.d.ts',
1515
'src/runtime/**/*.js',
16+
'test/fixtures/**/.nitro/**',
17+
'test/fixtures/**/.nuxt/**',
18+
'test/fixtures/**/.output/**',
1619
],
1720
})

package.json

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,38 @@
2424
],
2525
"sideEffects": false,
2626
"exports": {
27-
".": { "types": "./dist/types.d.mts", "import": "./dist/module.mjs" },
28-
"./eslint": { "types": "./dist/eslint.d.mts", "import": "./dist/eslint.mjs" }
27+
".": {
28+
"types": "./dist/types.d.mts",
29+
"import": "./dist/module.mjs"
30+
},
31+
"./nuxt": {
32+
"types": "./dist/types.d.mts",
33+
"import": "./dist/module.mjs"
34+
},
35+
"./nitro": {
36+
"types": "./dist/nitro.d.mts",
37+
"import": "./dist/nitro.mjs"
38+
},
39+
"./eslint": {
40+
"types": "./dist/eslint.d.mts",
41+
"import": "./dist/eslint.mjs"
42+
}
2943
},
3044
"main": "./dist/module.mjs",
3145
"typesVersions": {
3246
"*": {
33-
".": ["./dist/types.d.mts"],
34-
"eslint": ["./dist/eslint.d.mts"]
47+
".": [
48+
"./dist/types.d.mts"
49+
],
50+
"nuxt": [
51+
"./dist/types.d.mts"
52+
],
53+
"nitro": [
54+
"./dist/nitro.d.mts"
55+
],
56+
"eslint": [
57+
"./dist/eslint.d.mts"
58+
]
3559
}
3660
},
3761
"files": [
@@ -56,10 +80,19 @@
5680
},
5781
"peerDependencies": {
5882
"@nuxt/kit": "^3.0.0 || ^4.0.0 || ^5.0.0-0",
59-
"eslint": ">=9.0.0"
83+
"eslint": ">=9.0.0",
84+
"nitro": "^3.0.0-beta"
6085
},
6186
"peerDependenciesMeta": {
62-
"eslint": { "optional": true }
87+
"@nuxt/kit": {
88+
"optional": true
89+
},
90+
"eslint": {
91+
"optional": true
92+
},
93+
"nitro": {
94+
"optional": true
95+
}
6396
},
6497
"dependencies": {
6598
"@cfworker/json-schema": "catalog:",
@@ -93,6 +126,7 @@
93126
"eslint": "catalog:",
94127
"eslint-plugin-format": "catalog:",
95128
"lint-staged": "catalog:",
129+
"nitro": "catalog:",
96130
"nuxt": "catalog:",
97131
"simple-git-hooks": "catalog:",
98132
"typescript": "catalog:",

0 commit comments

Comments
 (0)