site-config-stack 4.2.2 → 5.0.0

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
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const ufo = require('ufo');
4
- const vue = require('vue');
5
4
 
6
5
  const SiteConfigPriority = {
7
6
  system: -15,
@@ -13,10 +12,38 @@ const SiteConfigPriority = {
13
12
  runtime: 0
14
13
  };
15
14
 
15
+ function toValue(source) {
16
+ if (typeof source === "function")
17
+ return source();
18
+ if (source && source.__v_isRef === true)
19
+ return source.value;
20
+ return source;
21
+ }
22
+ const NUXT_SITE_PREFIX = "NUXT_SITE_";
23
+ const NUXT_PUBLIC_SITE_PREFIX = "NUXT_PUBLIC_SITE_";
24
+ function envSiteConfig(env = {}) {
25
+ const config = {};
26
+ for (const key of Object.keys(env)) {
27
+ const prefixLength = key.startsWith(NUXT_SITE_PREFIX) ? NUXT_SITE_PREFIX.length : key.startsWith(NUXT_PUBLIC_SITE_PREFIX) ? NUXT_PUBLIC_SITE_PREFIX.length : 0;
28
+ if (!prefixLength)
29
+ continue;
30
+ const segments = key.slice(prefixLength).split("_");
31
+ let configKey = segments[0].toLowerCase();
32
+ for (let i = 1; i < segments.length; i++) {
33
+ const segment = segments[i];
34
+ configKey += segment[0]?.toUpperCase() + segment.slice(1).toLowerCase();
35
+ }
36
+ config[configKey] = env[key];
37
+ }
38
+ return config;
39
+ }
40
+
16
41
  function normalizeSiteConfig(config) {
17
42
  if (typeof config.indexable !== "undefined")
18
43
  config.indexable = String(config.indexable) !== "false";
19
- if (typeof config.trailingSlash !== "undefined" && !config.trailingSlash)
44
+ else if (typeof config.env !== "undefined")
45
+ config.indexable = config.env === "production";
46
+ if (typeof config.trailingSlash !== "undefined")
20
47
  config.trailingSlash = String(config.trailingSlash) !== "false";
21
48
  if (config.url && !ufo.hasProtocol(String(config.url), { acceptRelative: true, strict: false }))
22
49
  config.url = ufo.withHttps(String(config.url));
@@ -47,6 +74,8 @@ function validateSiteConfigStack(stack, options) {
47
74
  errors.push(`url "${val}" from ${context} should not contain a query`);
48
75
  else if (hostname === "localhost" && !options?.dev && resolved.env !== "development")
49
76
  errors.push(`url "${val}" from ${context} should not be localhost`);
77
+ } else if (options?.prerender) {
78
+ errors.push("url is not set, so prerendered pages render absolute URLs as relative paths. Set site.url or NUXT_SITE_URL");
50
79
  }
51
80
  return errors;
52
81
  }
@@ -89,7 +118,7 @@ function createSiteConfigStack(options) {
89
118
  for (const o in stack.sort((a, b) => (a._priority || 0) - (b._priority || 0))) {
90
119
  for (const k in stack[o]) {
91
120
  const key = k;
92
- const val = options2?.resolveRefs ? vue.toValue(stack[o][k]) : stack[o][k];
121
+ const val = options2?.resolveRefs ? toValue(stack[o][k]) : stack[o][k];
93
122
  if (!k.startsWith("_") && typeof val !== "undefined" && val !== "") {
94
123
  siteConfig[k] = val;
95
124
  if (typeof stack[o]._priority !== "undefined" && stack[o]._priority !== -1) {
@@ -109,27 +138,9 @@ function createSiteConfigStack(options) {
109
138
  };
110
139
  }
111
140
 
112
- const NUXT_SITE_PREFIX = "NUXT_SITE_";
113
- const NUXT_PUBLIC_SITE_PREFIX = "NUXT_PUBLIC_SITE_";
114
- function envSiteConfig(env = {}) {
115
- const config = {};
116
- for (const key of Object.keys(env)) {
117
- const prefixLength = key.startsWith(NUXT_SITE_PREFIX) ? NUXT_SITE_PREFIX.length : key.startsWith(NUXT_PUBLIC_SITE_PREFIX) ? NUXT_PUBLIC_SITE_PREFIX.length : 0;
118
- if (!prefixLength)
119
- continue;
120
- const segments = key.slice(prefixLength).split("_");
121
- let configKey = segments[0].toLowerCase();
122
- for (let i = 1; i < segments.length; i++) {
123
- const segment = segments[i];
124
- configKey += segment[0]?.toUpperCase() + segment.slice(1).toLowerCase();
125
- }
126
- config[configKey] = env[key];
127
- }
128
- return config;
129
- }
130
-
131
141
  exports.SiteConfigPriority = SiteConfigPriority;
132
142
  exports.createSiteConfigStack = createSiteConfigStack;
133
143
  exports.envSiteConfig = envSiteConfig;
134
144
  exports.normalizeSiteConfig = normalizeSiteConfig;
145
+ exports.toValue = toValue;
135
146
  exports.validateSiteConfigStack = validateSiteConfigStack;
package/dist/index.d.cts CHANGED
@@ -87,6 +87,7 @@ interface SiteConfigStack {
87
87
  declare function normalizeSiteConfig(config: SiteConfigResolved): SiteConfigResolved;
88
88
  declare function validateSiteConfigStack(stack: SiteConfigStack, options?: {
89
89
  dev?: boolean;
90
+ prerender?: boolean;
90
91
  }): string[];
91
92
  declare function createSiteConfigStack(options?: {
92
93
  debug: boolean;
@@ -96,7 +97,32 @@ declare function createSiteConfigStack(options?: {
96
97
  get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
97
98
  };
98
99
 
100
+ /**
101
+ * `toValue` without importing `vue`.
102
+ *
103
+ * Site config values are refs, computeds, getters or plain values, so resolving
104
+ * one needs `toValue` — but importing it from `vue` costs the whole framework.
105
+ * `vue` re-exports it from `@vue/runtime-dom`, so a single named import pulls
106
+ * `@vue/runtime-dom` + `@vue/runtime-core` (~246 KB) into whatever graph asks
107
+ * for it. On the server that graph is a Nitro plugin, which on a Cloudflare
108
+ * Worker is evaluated at cold start, before the isolate can answer any request:
109
+ * the renderer, the scheduler and the component system all initialise so that
110
+ * one pure function can unwrap a value.
111
+ *
112
+ * `@vue/reactivity` is where `toValue` actually lives and is a tenth the size,
113
+ * but `vue` reaches it through `@vue/runtime-dom` rather than depending on it
114
+ * directly, so importing it here would make every consumer install a peer.
115
+ * Nine lines is a better trade than that.
116
+ *
117
+ * `__v_isRef` is the same marker Vue's own `isRef` reads, and it is how every
118
+ * other library in the ecosystem (VueUse's `unref`, for one) recognises a ref
119
+ * without a hard dependency on Vue.
120
+ */
121
+ declare function toValue<T>(source: T | (() => T) | {
122
+ __v_isRef?: true;
123
+ value: T;
124
+ }): T;
99
125
  declare function envSiteConfig(env?: Record<string, any>): Record<string, any>;
100
126
 
101
- export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
127
+ export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, toValue, validateSiteConfigStack };
102
128
  export type { GetSiteConfigOptions, MaybeComputedRef, MaybeComputedRefEntries, SiteConfig, SiteConfigInput, SiteConfigResolved, SiteConfigStack };
package/dist/index.d.mts CHANGED
@@ -87,6 +87,7 @@ interface SiteConfigStack {
87
87
  declare function normalizeSiteConfig(config: SiteConfigResolved): SiteConfigResolved;
88
88
  declare function validateSiteConfigStack(stack: SiteConfigStack, options?: {
89
89
  dev?: boolean;
90
+ prerender?: boolean;
90
91
  }): string[];
91
92
  declare function createSiteConfigStack(options?: {
92
93
  debug: boolean;
@@ -96,7 +97,32 @@ declare function createSiteConfigStack(options?: {
96
97
  get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
97
98
  };
98
99
 
100
+ /**
101
+ * `toValue` without importing `vue`.
102
+ *
103
+ * Site config values are refs, computeds, getters or plain values, so resolving
104
+ * one needs `toValue` — but importing it from `vue` costs the whole framework.
105
+ * `vue` re-exports it from `@vue/runtime-dom`, so a single named import pulls
106
+ * `@vue/runtime-dom` + `@vue/runtime-core` (~246 KB) into whatever graph asks
107
+ * for it. On the server that graph is a Nitro plugin, which on a Cloudflare
108
+ * Worker is evaluated at cold start, before the isolate can answer any request:
109
+ * the renderer, the scheduler and the component system all initialise so that
110
+ * one pure function can unwrap a value.
111
+ *
112
+ * `@vue/reactivity` is where `toValue` actually lives and is a tenth the size,
113
+ * but `vue` reaches it through `@vue/runtime-dom` rather than depending on it
114
+ * directly, so importing it here would make every consumer install a peer.
115
+ * Nine lines is a better trade than that.
116
+ *
117
+ * `__v_isRef` is the same marker Vue's own `isRef` reads, and it is how every
118
+ * other library in the ecosystem (VueUse's `unref`, for one) recognises a ref
119
+ * without a hard dependency on Vue.
120
+ */
121
+ declare function toValue<T>(source: T | (() => T) | {
122
+ __v_isRef?: true;
123
+ value: T;
124
+ }): T;
99
125
  declare function envSiteConfig(env?: Record<string, any>): Record<string, any>;
100
126
 
101
- export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
127
+ export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, toValue, validateSiteConfigStack };
102
128
  export type { GetSiteConfigOptions, MaybeComputedRef, MaybeComputedRefEntries, SiteConfig, SiteConfigInput, SiteConfigResolved, SiteConfigStack };
package/dist/index.d.ts CHANGED
@@ -87,6 +87,7 @@ interface SiteConfigStack {
87
87
  declare function normalizeSiteConfig(config: SiteConfigResolved): SiteConfigResolved;
88
88
  declare function validateSiteConfigStack(stack: SiteConfigStack, options?: {
89
89
  dev?: boolean;
90
+ prerender?: boolean;
90
91
  }): string[];
91
92
  declare function createSiteConfigStack(options?: {
92
93
  debug: boolean;
@@ -96,7 +97,32 @@ declare function createSiteConfigStack(options?: {
96
97
  get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
97
98
  };
98
99
 
100
+ /**
101
+ * `toValue` without importing `vue`.
102
+ *
103
+ * Site config values are refs, computeds, getters or plain values, so resolving
104
+ * one needs `toValue` — but importing it from `vue` costs the whole framework.
105
+ * `vue` re-exports it from `@vue/runtime-dom`, so a single named import pulls
106
+ * `@vue/runtime-dom` + `@vue/runtime-core` (~246 KB) into whatever graph asks
107
+ * for it. On the server that graph is a Nitro plugin, which on a Cloudflare
108
+ * Worker is evaluated at cold start, before the isolate can answer any request:
109
+ * the renderer, the scheduler and the component system all initialise so that
110
+ * one pure function can unwrap a value.
111
+ *
112
+ * `@vue/reactivity` is where `toValue` actually lives and is a tenth the size,
113
+ * but `vue` reaches it through `@vue/runtime-dom` rather than depending on it
114
+ * directly, so importing it here would make every consumer install a peer.
115
+ * Nine lines is a better trade than that.
116
+ *
117
+ * `__v_isRef` is the same marker Vue's own `isRef` reads, and it is how every
118
+ * other library in the ecosystem (VueUse's `unref`, for one) recognises a ref
119
+ * without a hard dependency on Vue.
120
+ */
121
+ declare function toValue<T>(source: T | (() => T) | {
122
+ __v_isRef?: true;
123
+ value: T;
124
+ }): T;
99
125
  declare function envSiteConfig(env?: Record<string, any>): Record<string, any>;
100
126
 
101
- export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
127
+ export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, toValue, validateSiteConfigStack };
102
128
  export type { GetSiteConfigOptions, MaybeComputedRef, MaybeComputedRefEntries, SiteConfig, SiteConfigInput, SiteConfigResolved, SiteConfigStack };
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { hasProtocol, withHttps, parseURL, parseHost, getQuery } from 'ufo';
2
- import { toValue } from 'vue';
3
2
 
4
3
  const SiteConfigPriority = {
5
4
  system: -15,
@@ -11,10 +10,38 @@ const SiteConfigPriority = {
11
10
  runtime: 0
12
11
  };
13
12
 
13
+ function toValue(source) {
14
+ if (typeof source === "function")
15
+ return source();
16
+ if (source && source.__v_isRef === true)
17
+ return source.value;
18
+ return source;
19
+ }
20
+ const NUXT_SITE_PREFIX = "NUXT_SITE_";
21
+ const NUXT_PUBLIC_SITE_PREFIX = "NUXT_PUBLIC_SITE_";
22
+ function envSiteConfig(env = {}) {
23
+ const config = {};
24
+ for (const key of Object.keys(env)) {
25
+ const prefixLength = key.startsWith(NUXT_SITE_PREFIX) ? NUXT_SITE_PREFIX.length : key.startsWith(NUXT_PUBLIC_SITE_PREFIX) ? NUXT_PUBLIC_SITE_PREFIX.length : 0;
26
+ if (!prefixLength)
27
+ continue;
28
+ const segments = key.slice(prefixLength).split("_");
29
+ let configKey = segments[0].toLowerCase();
30
+ for (let i = 1; i < segments.length; i++) {
31
+ const segment = segments[i];
32
+ configKey += segment[0]?.toUpperCase() + segment.slice(1).toLowerCase();
33
+ }
34
+ config[configKey] = env[key];
35
+ }
36
+ return config;
37
+ }
38
+
14
39
  function normalizeSiteConfig(config) {
15
40
  if (typeof config.indexable !== "undefined")
16
41
  config.indexable = String(config.indexable) !== "false";
17
- if (typeof config.trailingSlash !== "undefined" && !config.trailingSlash)
42
+ else if (typeof config.env !== "undefined")
43
+ config.indexable = config.env === "production";
44
+ if (typeof config.trailingSlash !== "undefined")
18
45
  config.trailingSlash = String(config.trailingSlash) !== "false";
19
46
  if (config.url && !hasProtocol(String(config.url), { acceptRelative: true, strict: false }))
20
47
  config.url = withHttps(String(config.url));
@@ -45,6 +72,8 @@ function validateSiteConfigStack(stack, options) {
45
72
  errors.push(`url "${val}" from ${context} should not contain a query`);
46
73
  else if (hostname === "localhost" && !options?.dev && resolved.env !== "development")
47
74
  errors.push(`url "${val}" from ${context} should not be localhost`);
75
+ } else if (options?.prerender) {
76
+ errors.push("url is not set, so prerendered pages render absolute URLs as relative paths. Set site.url or NUXT_SITE_URL");
48
77
  }
49
78
  return errors;
50
79
  }
@@ -107,23 +136,4 @@ function createSiteConfigStack(options) {
107
136
  };
108
137
  }
109
138
 
110
- const NUXT_SITE_PREFIX = "NUXT_SITE_";
111
- const NUXT_PUBLIC_SITE_PREFIX = "NUXT_PUBLIC_SITE_";
112
- function envSiteConfig(env = {}) {
113
- const config = {};
114
- for (const key of Object.keys(env)) {
115
- const prefixLength = key.startsWith(NUXT_SITE_PREFIX) ? NUXT_SITE_PREFIX.length : key.startsWith(NUXT_PUBLIC_SITE_PREFIX) ? NUXT_PUBLIC_SITE_PREFIX.length : 0;
116
- if (!prefixLength)
117
- continue;
118
- const segments = key.slice(prefixLength).split("_");
119
- let configKey = segments[0].toLowerCase();
120
- for (let i = 1; i < segments.length; i++) {
121
- const segment = segments[i];
122
- configKey += segment[0]?.toUpperCase() + segment.slice(1).toLowerCase();
123
- }
124
- config[configKey] = env[key];
125
- }
126
- return config;
127
- }
128
-
129
- export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
139
+ export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, toValue, validateSiteConfigStack };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "site-config-stack",
3
3
  "type": "module",
4
- "version": "4.2.2",
4
+ "version": "5.0.0",
5
5
  "description": "Shared site configuration utilities.",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -36,15 +36,18 @@
36
36
  "dist",
37
37
  "urls.d.ts"
38
38
  ],
39
+ "engines": {
40
+ "node": "^22.22.3 || ^24.15.0 || >=26.0.0"
41
+ },
39
42
  "peerDependencies": {
40
- "vue": "^3.5.30"
43
+ "vue": "^3.5.43"
41
44
  },
42
45
  "dependencies": {
43
46
  "ufo": "^1.6.4"
44
47
  },
45
48
  "devDependencies": {
46
49
  "unbuild": "^3.6.1",
47
- "vue": "^3.5.41"
50
+ "vue": "^3.5.43"
48
51
  },
49
52
  "scripts": {
50
53
  "lint": "eslint . --fix",