site-config-stack 4.2.2 → 4.2.3
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 +28 -21
- package/dist/index.d.cts +26 -1
- package/dist/index.d.mts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.mjs +27 -21
- package/package.json +1 -1
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,6 +12,32 @@ 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";
|
|
@@ -89,7 +114,7 @@ function createSiteConfigStack(options) {
|
|
|
89
114
|
for (const o in stack.sort((a, b) => (a._priority || 0) - (b._priority || 0))) {
|
|
90
115
|
for (const k in stack[o]) {
|
|
91
116
|
const key = k;
|
|
92
|
-
const val = options2?.resolveRefs ?
|
|
117
|
+
const val = options2?.resolveRefs ? toValue(stack[o][k]) : stack[o][k];
|
|
93
118
|
if (!k.startsWith("_") && typeof val !== "undefined" && val !== "") {
|
|
94
119
|
siteConfig[k] = val;
|
|
95
120
|
if (typeof stack[o]._priority !== "undefined" && stack[o]._priority !== -1) {
|
|
@@ -109,27 +134,9 @@ function createSiteConfigStack(options) {
|
|
|
109
134
|
};
|
|
110
135
|
}
|
|
111
136
|
|
|
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
137
|
exports.SiteConfigPriority = SiteConfigPriority;
|
|
132
138
|
exports.createSiteConfigStack = createSiteConfigStack;
|
|
133
139
|
exports.envSiteConfig = envSiteConfig;
|
|
134
140
|
exports.normalizeSiteConfig = normalizeSiteConfig;
|
|
141
|
+
exports.toValue = toValue;
|
|
135
142
|
exports.validateSiteConfigStack = validateSiteConfigStack;
|
package/dist/index.d.cts
CHANGED
|
@@ -96,7 +96,32 @@ declare function createSiteConfigStack(options?: {
|
|
|
96
96
|
get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* `toValue` without importing `vue`.
|
|
101
|
+
*
|
|
102
|
+
* Site config values are refs, computeds, getters or plain values, so resolving
|
|
103
|
+
* one needs `toValue` — but importing it from `vue` costs the whole framework.
|
|
104
|
+
* `vue` re-exports it from `@vue/runtime-dom`, so a single named import pulls
|
|
105
|
+
* `@vue/runtime-dom` + `@vue/runtime-core` (~246 KB) into whatever graph asks
|
|
106
|
+
* for it. On the server that graph is a Nitro plugin, which on a Cloudflare
|
|
107
|
+
* Worker is evaluated at cold start, before the isolate can answer any request:
|
|
108
|
+
* the renderer, the scheduler and the component system all initialise so that
|
|
109
|
+
* one pure function can unwrap a value.
|
|
110
|
+
*
|
|
111
|
+
* `@vue/reactivity` is where `toValue` actually lives and is a tenth the size,
|
|
112
|
+
* but `vue` reaches it through `@vue/runtime-dom` rather than depending on it
|
|
113
|
+
* directly, so importing it here would make every consumer install a peer.
|
|
114
|
+
* Nine lines is a better trade than that.
|
|
115
|
+
*
|
|
116
|
+
* `__v_isRef` is the same marker Vue's own `isRef` reads, and it is how every
|
|
117
|
+
* other library in the ecosystem (VueUse's `unref`, for one) recognises a ref
|
|
118
|
+
* without a hard dependency on Vue.
|
|
119
|
+
*/
|
|
120
|
+
declare function toValue<T>(source: T | (() => T) | {
|
|
121
|
+
__v_isRef?: true;
|
|
122
|
+
value: T;
|
|
123
|
+
}): T;
|
|
99
124
|
declare function envSiteConfig(env?: Record<string, any>): Record<string, any>;
|
|
100
125
|
|
|
101
|
-
export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
|
|
126
|
+
export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, toValue, validateSiteConfigStack };
|
|
102
127
|
export type { GetSiteConfigOptions, MaybeComputedRef, MaybeComputedRefEntries, SiteConfig, SiteConfigInput, SiteConfigResolved, SiteConfigStack };
|
package/dist/index.d.mts
CHANGED
|
@@ -96,7 +96,32 @@ declare function createSiteConfigStack(options?: {
|
|
|
96
96
|
get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* `toValue` without importing `vue`.
|
|
101
|
+
*
|
|
102
|
+
* Site config values are refs, computeds, getters or plain values, so resolving
|
|
103
|
+
* one needs `toValue` — but importing it from `vue` costs the whole framework.
|
|
104
|
+
* `vue` re-exports it from `@vue/runtime-dom`, so a single named import pulls
|
|
105
|
+
* `@vue/runtime-dom` + `@vue/runtime-core` (~246 KB) into whatever graph asks
|
|
106
|
+
* for it. On the server that graph is a Nitro plugin, which on a Cloudflare
|
|
107
|
+
* Worker is evaluated at cold start, before the isolate can answer any request:
|
|
108
|
+
* the renderer, the scheduler and the component system all initialise so that
|
|
109
|
+
* one pure function can unwrap a value.
|
|
110
|
+
*
|
|
111
|
+
* `@vue/reactivity` is where `toValue` actually lives and is a tenth the size,
|
|
112
|
+
* but `vue` reaches it through `@vue/runtime-dom` rather than depending on it
|
|
113
|
+
* directly, so importing it here would make every consumer install a peer.
|
|
114
|
+
* Nine lines is a better trade than that.
|
|
115
|
+
*
|
|
116
|
+
* `__v_isRef` is the same marker Vue's own `isRef` reads, and it is how every
|
|
117
|
+
* other library in the ecosystem (VueUse's `unref`, for one) recognises a ref
|
|
118
|
+
* without a hard dependency on Vue.
|
|
119
|
+
*/
|
|
120
|
+
declare function toValue<T>(source: T | (() => T) | {
|
|
121
|
+
__v_isRef?: true;
|
|
122
|
+
value: T;
|
|
123
|
+
}): T;
|
|
99
124
|
declare function envSiteConfig(env?: Record<string, any>): Record<string, any>;
|
|
100
125
|
|
|
101
|
-
export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
|
|
126
|
+
export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, toValue, validateSiteConfigStack };
|
|
102
127
|
export type { GetSiteConfigOptions, MaybeComputedRef, MaybeComputedRefEntries, SiteConfig, SiteConfigInput, SiteConfigResolved, SiteConfigStack };
|
package/dist/index.d.ts
CHANGED
|
@@ -96,7 +96,32 @@ declare function createSiteConfigStack(options?: {
|
|
|
96
96
|
get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* `toValue` without importing `vue`.
|
|
101
|
+
*
|
|
102
|
+
* Site config values are refs, computeds, getters or plain values, so resolving
|
|
103
|
+
* one needs `toValue` — but importing it from `vue` costs the whole framework.
|
|
104
|
+
* `vue` re-exports it from `@vue/runtime-dom`, so a single named import pulls
|
|
105
|
+
* `@vue/runtime-dom` + `@vue/runtime-core` (~246 KB) into whatever graph asks
|
|
106
|
+
* for it. On the server that graph is a Nitro plugin, which on a Cloudflare
|
|
107
|
+
* Worker is evaluated at cold start, before the isolate can answer any request:
|
|
108
|
+
* the renderer, the scheduler and the component system all initialise so that
|
|
109
|
+
* one pure function can unwrap a value.
|
|
110
|
+
*
|
|
111
|
+
* `@vue/reactivity` is where `toValue` actually lives and is a tenth the size,
|
|
112
|
+
* but `vue` reaches it through `@vue/runtime-dom` rather than depending on it
|
|
113
|
+
* directly, so importing it here would make every consumer install a peer.
|
|
114
|
+
* Nine lines is a better trade than that.
|
|
115
|
+
*
|
|
116
|
+
* `__v_isRef` is the same marker Vue's own `isRef` reads, and it is how every
|
|
117
|
+
* other library in the ecosystem (VueUse's `unref`, for one) recognises a ref
|
|
118
|
+
* without a hard dependency on Vue.
|
|
119
|
+
*/
|
|
120
|
+
declare function toValue<T>(source: T | (() => T) | {
|
|
121
|
+
__v_isRef?: true;
|
|
122
|
+
value: T;
|
|
123
|
+
}): T;
|
|
99
124
|
declare function envSiteConfig(env?: Record<string, any>): Record<string, any>;
|
|
100
125
|
|
|
101
|
-
export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
|
|
126
|
+
export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, toValue, validateSiteConfigStack };
|
|
102
127
|
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,6 +10,32 @@ 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";
|
|
@@ -107,23 +132,4 @@ function createSiteConfigStack(options) {
|
|
|
107
132
|
};
|
|
108
133
|
}
|
|
109
134
|
|
|
110
|
-
|
|
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 };
|
|
135
|
+
export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, toValue, validateSiteConfigStack };
|