nuxt-site-config-kit 1.1.0 → 1.1.2

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/dist/index.cjs CHANGED
@@ -81,43 +81,27 @@ function useSiteConfig(context, nuxt = kit.tryUseNuxt()) {
81
81
  return container.get();
82
82
  }
83
83
 
84
- function requireSiteConfig(context, requirements, modes) {
85
- const nuxt = kit.tryUseNuxt();
86
- if (!nuxt)
87
- return;
88
- const assertions = nuxt._siteConfigAsserts || {};
89
- Object.keys(modes).forEach((mode) => {
90
- const key = mode;
91
- if (!modes[key])
92
- return;
93
- assertions[key] = assertions[key] || [];
94
- assertions[key].push({ context, requirements });
95
- });
96
- nuxt._siteConfigAsserts = assertions;
84
+ function requireSiteConfig() {
97
85
  }
98
- async function assertSiteConfig(mode, options) {
99
- const siteConfig = await useSiteConfig();
100
- const nuxt = kit.useNuxt();
86
+ function assertSiteConfig(context, requirements, options) {
87
+ const siteConfig = useSiteConfig();
101
88
  let valid = true;
102
89
  const messages = [];
103
90
  const logger = kit.useLogger("nuxt-site-config");
104
- const assertions = nuxt._siteConfigAsserts?.[mode] || false;
105
- if (!assertions)
106
- return { valid, messages };
107
- assertions.forEach(({ context, requirements }) => {
108
- Object.keys(requirements).forEach((k) => {
109
- const key = k;
110
- if (!siteConfig[key]) {
111
- const msg = `\`${context}\` requires \`${key}\` to be set. ${requirements[key]}`;
112
- messages.push(msg);
113
- if (options?.logErrors !== false)
114
- logger.error(msg);
115
- valid = false;
116
- }
117
- });
91
+ Object.keys(requirements).forEach((k) => {
92
+ const key = k;
93
+ if (!siteConfig[key]) {
94
+ const msg = `\`${context}\` requires \`${key}\` to be set. ${requirements[key]}`;
95
+ messages.push(msg);
96
+ valid = false;
97
+ }
118
98
  });
119
- if (!valid && options?.throwError !== false)
120
- throw new Error(`Missing site config for ${mode} mode.`);
99
+ if (!valid) {
100
+ if (options?.logErrors)
101
+ logger.error(messages.join("\n"));
102
+ else if (options?.throwError)
103
+ throw new Error(messages.join("\n"));
104
+ }
121
105
  return {
122
106
  valid,
123
107
  messages
package/dist/index.d.cts CHANGED
@@ -26,14 +26,17 @@ declare function useSiteConfig(context?: {
26
26
  path: string;
27
27
  }, nuxt?: Nuxt | null): SiteConfig;
28
28
 
29
- declare function requireSiteConfig(context: string, requirements: Partial<Record<keyof SiteConfig, string>>, modes: Partial<Record<AssertionModes, boolean>>): void;
30
- declare function assertSiteConfig(mode: AssertionModes, options?: {
29
+ /**
30
+ * @deprecated No longer used
31
+ */
32
+ declare function requireSiteConfig(): void;
33
+ declare function assertSiteConfig(context: string, requirements: Partial<Record<keyof SiteConfig, string>>, options?: {
31
34
  throwError?: boolean;
32
35
  logErrors?: boolean;
33
- }): Promise<{
36
+ }): {
34
37
  valid: boolean;
35
38
  messages: string[];
36
- }>;
39
+ };
37
40
 
38
41
  declare function useNitroOrigin(): string;
39
42
  declare function withSiteUrl(path: string, options?: {
package/dist/index.d.mts CHANGED
@@ -26,14 +26,17 @@ declare function useSiteConfig(context?: {
26
26
  path: string;
27
27
  }, nuxt?: Nuxt | null): SiteConfig;
28
28
 
29
- declare function requireSiteConfig(context: string, requirements: Partial<Record<keyof SiteConfig, string>>, modes: Partial<Record<AssertionModes, boolean>>): void;
30
- declare function assertSiteConfig(mode: AssertionModes, options?: {
29
+ /**
30
+ * @deprecated No longer used
31
+ */
32
+ declare function requireSiteConfig(): void;
33
+ declare function assertSiteConfig(context: string, requirements: Partial<Record<keyof SiteConfig, string>>, options?: {
31
34
  throwError?: boolean;
32
35
  logErrors?: boolean;
33
- }): Promise<{
36
+ }): {
34
37
  valid: boolean;
35
38
  messages: string[];
36
- }>;
39
+ };
37
40
 
38
41
  declare function useNitroOrigin(): string;
39
42
  declare function withSiteUrl(path: string, options?: {
package/dist/index.d.ts CHANGED
@@ -26,14 +26,17 @@ declare function useSiteConfig(context?: {
26
26
  path: string;
27
27
  }, nuxt?: Nuxt | null): SiteConfig;
28
28
 
29
- declare function requireSiteConfig(context: string, requirements: Partial<Record<keyof SiteConfig, string>>, modes: Partial<Record<AssertionModes, boolean>>): void;
30
- declare function assertSiteConfig(mode: AssertionModes, options?: {
29
+ /**
30
+ * @deprecated No longer used
31
+ */
32
+ declare function requireSiteConfig(): void;
33
+ declare function assertSiteConfig(context: string, requirements: Partial<Record<keyof SiteConfig, string>>, options?: {
31
34
  throwError?: boolean;
32
35
  logErrors?: boolean;
33
- }): Promise<{
36
+ }): {
34
37
  valid: boolean;
35
38
  messages: string[];
36
- }>;
39
+ };
37
40
 
38
41
  declare function useNitroOrigin(): string;
39
42
  declare function withSiteUrl(path: string, options?: {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { tryUseNuxt, installModule, resolvePath, useNuxt, useLogger } from '@nuxt/kit';
1
+ import { tryUseNuxt, installModule, resolvePath, useLogger, useNuxt } from '@nuxt/kit';
2
2
  import { readPackageJSON } from 'pkg-types';
3
3
  import { createSiteConfigStack, resolveSitePath, fixSlashes } from 'site-config-stack';
4
4
  import { withoutProtocol } from 'ufo';
@@ -79,43 +79,27 @@ function useSiteConfig(context, nuxt = tryUseNuxt()) {
79
79
  return container.get();
80
80
  }
81
81
 
82
- function requireSiteConfig(context, requirements, modes) {
83
- const nuxt = tryUseNuxt();
84
- if (!nuxt)
85
- return;
86
- const assertions = nuxt._siteConfigAsserts || {};
87
- Object.keys(modes).forEach((mode) => {
88
- const key = mode;
89
- if (!modes[key])
90
- return;
91
- assertions[key] = assertions[key] || [];
92
- assertions[key].push({ context, requirements });
93
- });
94
- nuxt._siteConfigAsserts = assertions;
82
+ function requireSiteConfig() {
95
83
  }
96
- async function assertSiteConfig(mode, options) {
97
- const siteConfig = await useSiteConfig();
98
- const nuxt = useNuxt();
84
+ function assertSiteConfig(context, requirements, options) {
85
+ const siteConfig = useSiteConfig();
99
86
  let valid = true;
100
87
  const messages = [];
101
88
  const logger = useLogger("nuxt-site-config");
102
- const assertions = nuxt._siteConfigAsserts?.[mode] || false;
103
- if (!assertions)
104
- return { valid, messages };
105
- assertions.forEach(({ context, requirements }) => {
106
- Object.keys(requirements).forEach((k) => {
107
- const key = k;
108
- if (!siteConfig[key]) {
109
- const msg = `\`${context}\` requires \`${key}\` to be set. ${requirements[key]}`;
110
- messages.push(msg);
111
- if (options?.logErrors !== false)
112
- logger.error(msg);
113
- valid = false;
114
- }
115
- });
89
+ Object.keys(requirements).forEach((k) => {
90
+ const key = k;
91
+ if (!siteConfig[key]) {
92
+ const msg = `\`${context}\` requires \`${key}\` to be set. ${requirements[key]}`;
93
+ messages.push(msg);
94
+ valid = false;
95
+ }
116
96
  });
117
- if (!valid && options?.throwError !== false)
118
- throw new Error(`Missing site config for ${mode} mode.`);
97
+ if (!valid) {
98
+ if (options?.logErrors)
99
+ logger.error(messages.join("\n"));
100
+ else if (options?.throwError)
101
+ throw new Error(messages.join("\n"));
102
+ }
119
103
  return {
120
104
  valid,
121
105
  messages
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-site-config-kit",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "description": "Shared site configuration build-time utilities for Nuxt 3 modules.",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -31,7 +31,7 @@
31
31
  "@nuxt/schema": "^3.7.1",
32
32
  "pkg-types": "^1.0.3",
33
33
  "ufo": "^1.3.0",
34
- "site-config-stack": "1.1.0"
34
+ "site-config-stack": "1.1.2"
35
35
  },
36
36
  "scripts": {
37
37
  "lint": "eslint . --fix",