nuxt-safe-runtime-config 0.0.7 → 0.0.10

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 CHANGED
@@ -137,13 +137,13 @@ export default defineNuxtConfig({
137
137
  })
138
138
  ```
139
139
 
140
- The module will validate your runtime config against the schema during:
140
+ The module validates your runtime config **after environment variables are merged** during:
141
141
 
142
142
  - `nuxi dev` (development mode)
143
143
  - `nuxi build`
144
144
  - `nuxi generate`
145
145
 
146
- If validation fails, the build process will stop with detailed error messages.
146
+ This means validation happens at **runtime initialization**, after all `NUXT_*` environment variables from `.env` files have been merged into your runtime config. If validation fails, the build process will stop with detailed error messages.
147
147
 
148
148
  ## Important Notes
149
149
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-safe-runtime-config",
3
3
  "configKey": "safeRuntimeConfig",
4
- "version": "0.0.7",
4
+ "version": "0.0.10",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/dist/module.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { defineNuxtModule } from '@nuxt/kit';
2
- import { consola } from 'consola';
3
2
 
4
3
  const module = defineNuxtModule({
5
4
  meta: {
@@ -8,43 +7,35 @@ const module = defineNuxtModule({
8
7
  },
9
8
  defaults: {
10
9
  $schema: void 0
11
- // No default schema, users must provide their own
12
10
  },
13
11
  setup(options, nuxt) {
14
- if (nuxt.options.dev) {
15
- nuxt.hook("ready", async () => {
16
- await validateRuntimeConfig(nuxt, options);
17
- });
12
+ if (!options.$schema)
18
13
  return;
19
- }
14
+ const schema = options.$schema;
15
+ nuxt.hook("ready", async () => {
16
+ if (nuxt.options._prepare)
17
+ return;
18
+ await validateRuntimeConfig(nuxt.options.nitro.runtimeConfig, schema);
19
+ });
20
20
  nuxt.hook("build:done", async () => {
21
- await validateRuntimeConfig(nuxt, options);
21
+ await validateRuntimeConfig(nuxt.options.nitro.runtimeConfig, schema);
22
22
  });
23
23
  }
24
24
  });
25
- async function validateRuntimeConfig(nuxt, options) {
26
- const schemaConfig = options.$schema;
27
- if (!schemaConfig)
28
- return;
29
- try {
30
- const runtimeConfig = nuxt.options.runtimeConfig || {};
31
- if (!isStandardSchema(schemaConfig)) {
32
- consola.error("Safe Runtime Config: Schema is not Standard Schema compatible");
33
- return;
34
- }
35
- const result = await schemaConfig["~standard"].validate(runtimeConfig);
36
- if ("issues" in result && result.issues && result.issues.length > 0) {
37
- consola.error("Safe Runtime Config: Validation failed!");
38
- result.issues.forEach((issue, index) => {
39
- consola.error(` ${index + 1}. ${formatIssue(issue)}`);
40
- });
41
- throw new Error("Runtime config validation failed");
42
- }
43
- consola.success("Validated Runtime Config");
44
- } catch (error) {
45
- consola.error("Safe Runtime Config: Validation error:", error);
46
- throw error;
25
+ async function validateRuntimeConfig(config, schema) {
26
+ if (!isStandardSchema(schema)) {
27
+ console.error("Safe Runtime Config: Schema is not Standard Schema compatible");
28
+ throw new Error("Invalid schema format");
29
+ }
30
+ const result = await schema["~standard"].validate(config);
31
+ if ("issues" in result && result.issues && result.issues.length > 0) {
32
+ console.error("Safe Runtime Config: Validation failed!");
33
+ result.issues.forEach((issue, index) => {
34
+ console.error(` ${index + 1}. ${formatIssue(issue)}`);
35
+ });
36
+ throw new Error("Runtime config validation failed");
47
37
  }
38
+ console.log("\u2713 Validated Runtime Config");
48
39
  }
49
40
  function isStandardSchema(schema) {
50
41
  return schema && typeof schema === "object" && "~standard" in schema && typeof schema["~standard"] === "object" && typeof schema["~standard"].validate === "function";
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "nuxt-safe-runtime-config",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.10",
5
+ "packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
5
6
  "description": "Validate Nuxt runtime config with Standard Schema at build time",
6
7
  "author": {
7
8
  "name": "onmax"
@@ -36,41 +37,8 @@
36
37
  "files": [
37
38
  "dist"
38
39
  ],
39
- "dependencies": {
40
- "@nuxt/kit": "^3.17.4",
41
- "@standard-schema/spec": "^1.0.0",
42
- "consola": "^3.4.2",
43
- "dotenv": "^17.2.3"
44
- },
45
- "devDependencies": {
46
- "@antfu/eslint-config": "^4.13.3",
47
- "@antfu/ni": "^25.0.0",
48
- "@nuxt/devtools": "^2.4.1",
49
- "@nuxt/eslint": "^1.4.1",
50
- "@nuxt/eslint-config": "^1.4.1",
51
- "@nuxt/module-builder": "^1.0.1",
52
- "@nuxt/schema": "^3.17.4",
53
- "@nuxt/test-utils": "^3.19.1",
54
- "@types/node": "latest",
55
- "bumpp": "^10.1.1",
56
- "changelogen": "^0.6.1",
57
- "eslint": "^9.28.0",
58
- "eslint-plugin-format": "^1.0.1",
59
- "lint-staged": "^16.1.0",
60
- "nuxt": "^3.17.4",
61
- "simple-git-hooks": "^2.13.0",
62
- "typescript": "~5.8.3",
63
- "valibot": "^1.1.0",
64
- "vitest": "^3.2.0",
65
- "vue-tsc": "^2.2.10"
66
- },
67
- "simple-git-hooks": {
68
- "pre-commit": "pnpm lint-staged"
69
- },
70
- "lint-staged": {
71
- "*": "eslint --fix"
72
- },
73
40
  "scripts": {
41
+ "prepack": "nuxt-module-build build",
74
42
  "dev": "nuxi dev playground",
75
43
  "dev:build": "nuxi build playground",
76
44
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground && pnpm -C test/fixtures/validation-failure prepare && pnpm -C test/fixtures/validation-success prepare",
@@ -81,5 +49,37 @@
81
49
  "test": "vitest run",
82
50
  "test:watch": "vitest watch",
83
51
  "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
52
+ },
53
+ "dependencies": {
54
+ "@nuxt/kit": "catalog:",
55
+ "@standard-schema/spec": "catalog:"
56
+ },
57
+ "devDependencies": {
58
+ "@antfu/eslint-config": "catalog:",
59
+ "@antfu/ni": "catalog:",
60
+ "@nuxt/devtools": "catalog:",
61
+ "@nuxt/eslint": "catalog:",
62
+ "@nuxt/eslint-config": "catalog:",
63
+ "@nuxt/module-builder": "catalog:",
64
+ "@nuxt/schema": "catalog:",
65
+ "@nuxt/test-utils": "catalog:",
66
+ "@types/node": "catalog:",
67
+ "bumpp": "catalog:",
68
+ "changelogen": "catalog:",
69
+ "eslint": "catalog:",
70
+ "eslint-plugin-format": "catalog:",
71
+ "lint-staged": "catalog:",
72
+ "nuxt": "catalog:",
73
+ "simple-git-hooks": "catalog:",
74
+ "typescript": "catalog:",
75
+ "valibot": "catalog:",
76
+ "vitest": "catalog:",
77
+ "vue-tsc": "catalog:"
78
+ },
79
+ "simple-git-hooks": {
80
+ "pre-commit": "pnpm lint-staged"
81
+ },
82
+ "lint-staged": {
83
+ "*": "eslint --fix"
84
84
  }
85
- }
85
+ }
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -1,8 +0,0 @@
1
- export default defineNitroPlugin((nitroApp) => {
2
- const config = useRuntimeConfig();
3
- const schema = nitroApp.__safeRuntimeConfigSchema;
4
- if (!schema) return;
5
- validateConfig(config, schema);
6
- });
7
- function validateConfig(config, schema) {
8
- }
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -1,3 +0,0 @@
1
- import { defineNuxtPlugin } from "#app";
2
- export default defineNuxtPlugin((_nuxtApp) => {
3
- });