nuxt-site-config 0.5.6 → 0.5.7
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/kit.d.ts +2 -2
- package/dist/kit.mjs +41 -12
- package/dist/module.d.ts +3 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -2
- package/dist/runtime/composables/updateSiteConfig.mjs +4 -4
- package/dist/runtime/composables/useSiteConfig.mjs +4 -4
- package/dist/runtime/nitro/composables/updateSiteConfig.mjs +2 -2
- package/dist/runtime/nitro/composables/useSiteConfig.mjs +2 -2
- package/dist/runtime/plugins/siteConfig.mjs +7 -7
- package/dist/runtime/siteConfig/env.mjs +1 -0
- package/dist/runtime/siteConfig/index.d.ts +1 -1
- package/dist/runtime/siteConfig/index.mjs +1 -1
- package/dist/runtime/siteConfig/stack.d.ts +2 -0
- package/dist/runtime/siteConfig/stack.mjs +32 -0
- package/dist/runtime/siteConfig/util.d.ts +1 -3
- package/dist/runtime/siteConfig/util.mjs +0 -1
- package/dist/{type-51d86304.d.ts → type-1234fa1d.d.ts} +11 -3
- package/package.json +1 -1
- package/dist/runtime/siteConfig/container.d.ts +0 -2
- package/dist/runtime/siteConfig/container.mjs +0 -18
package/dist/kit.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as
|
|
1
|
+
import { S as SiteConfigStack, a as SiteConfigInput, b as SiteConfig, A as AssertionModes } from './type-1234fa1d.js';
|
|
2
2
|
|
|
3
|
-
declare function initSiteConfig(): Promise<
|
|
3
|
+
declare function initSiteConfig(): Promise<SiteConfigStack | undefined>;
|
|
4
4
|
declare function updateSiteConfig(input: SiteConfigInput): Promise<void>;
|
|
5
5
|
declare function useSiteConfig(): Promise<SiteConfig>;
|
|
6
6
|
|
package/dist/kit.mjs
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import { tryUseNuxt, useLogger } from '@nuxt/kit';
|
|
2
2
|
import { readPackageJSON } from 'pkg-types';
|
|
3
|
-
import { defu } from 'defu';
|
|
4
3
|
|
|
5
|
-
function
|
|
4
|
+
function createSiteConfigStack() {
|
|
6
5
|
const stack = [];
|
|
7
6
|
function push(input) {
|
|
7
|
+
if (!input._context) {
|
|
8
|
+
let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
|
|
9
|
+
if (lastFunctionName?.includes("/"))
|
|
10
|
+
lastFunctionName = "anonymous";
|
|
11
|
+
input._context = lastFunctionName;
|
|
12
|
+
}
|
|
8
13
|
stack.push(input);
|
|
9
14
|
}
|
|
10
15
|
function get() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
const siteConfig = {
|
|
17
|
+
_context: {}
|
|
18
|
+
};
|
|
19
|
+
for (const o in stack) {
|
|
20
|
+
for (const k in stack[o]) {
|
|
21
|
+
const val = stack[o][k];
|
|
22
|
+
if (!k.endsWith("context") && typeof val !== "undefined") {
|
|
23
|
+
siteConfig[k] = val;
|
|
24
|
+
siteConfig._context[k] = stack[o]._context?.[k] || stack[o]._context || "anonymous";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return normalizeSiteConfig(siteConfig);
|
|
15
29
|
}
|
|
16
30
|
return {
|
|
17
31
|
push,
|
|
@@ -24,13 +38,13 @@ function normalizeSiteConfig(config) {
|
|
|
24
38
|
config.indexable = String(config.indexable) !== "false";
|
|
25
39
|
if (typeof config.trailingSlash !== "undefined")
|
|
26
40
|
config.trailingSlash = String(config.trailingSlash) !== "false";
|
|
27
|
-
delete config._id;
|
|
28
41
|
return config;
|
|
29
42
|
}
|
|
30
43
|
|
|
31
44
|
const processShim = typeof process !== "undefined" ? process : {};
|
|
32
45
|
const envShim = processShim.env || {};
|
|
33
46
|
const envSiteConfig = {
|
|
47
|
+
_context: "env",
|
|
34
48
|
url: [
|
|
35
49
|
envShim.NUXT_PUBLIC_VERCEL_URL,
|
|
36
50
|
// vercel
|
|
@@ -55,6 +69,7 @@ async function getPkgJsonContextConfig(rootDir) {
|
|
|
55
69
|
if (!pkgJson)
|
|
56
70
|
return {};
|
|
57
71
|
return {
|
|
72
|
+
_context: "package.json",
|
|
58
73
|
name: pkgJson.name,
|
|
59
74
|
description: pkgJson.description
|
|
60
75
|
};
|
|
@@ -65,11 +80,12 @@ async function initSiteConfig() {
|
|
|
65
80
|
return;
|
|
66
81
|
let siteConfig = nuxt._siteConfig;
|
|
67
82
|
if (siteConfig)
|
|
68
|
-
return;
|
|
83
|
+
return siteConfig;
|
|
69
84
|
const rootDir = nuxt?.options.rootDir || process.cwd();
|
|
70
|
-
siteConfig =
|
|
85
|
+
siteConfig = createSiteConfigStack();
|
|
71
86
|
const isNodeEnv = !!process.env.NODE_ENV;
|
|
72
87
|
siteConfig.push({
|
|
88
|
+
_context: "system",
|
|
73
89
|
name: rootDir.split("/").pop(),
|
|
74
90
|
indexable: isNodeEnv ? process.env.NODE_ENV === "production" : !process.dev
|
|
75
91
|
});
|
|
@@ -84,6 +100,7 @@ async function initSiteConfig() {
|
|
|
84
100
|
return runtimeConfig[`site${config}`] || runtimeConfig.public?.[`site${config}`];
|
|
85
101
|
}
|
|
86
102
|
siteConfig.push({
|
|
103
|
+
_context: "legacyRuntimeConfig",
|
|
87
104
|
url: getRuntimeConfig("Url", "_URL"),
|
|
88
105
|
name: getRuntimeConfig("Name", "_NAME"),
|
|
89
106
|
description: getRuntimeConfig("Description", "_DESCRIPTION"),
|
|
@@ -91,15 +108,27 @@ async function initSiteConfig() {
|
|
|
91
108
|
locale: getRuntimeConfig("Language", "_LANGUAGE"),
|
|
92
109
|
indexable: getRuntimeConfig("Indexable", "_INDEXABLE")
|
|
93
110
|
});
|
|
94
|
-
siteConfig.push(
|
|
111
|
+
siteConfig.push({
|
|
112
|
+
_context: "runtimeConfig",
|
|
113
|
+
...nuxt?.options.runtimeConfig.public.site || {}
|
|
114
|
+
});
|
|
95
115
|
nuxt._siteConfig = siteConfig;
|
|
96
116
|
return siteConfig;
|
|
97
117
|
}
|
|
118
|
+
async function getSiteConfigStack() {
|
|
119
|
+
const lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
|
|
120
|
+
const container = await initSiteConfig();
|
|
121
|
+
if (!container)
|
|
122
|
+
throw new Error(`Site config isn't initialized. Make sure you're calling \`${lastFunctionName}\` within the Nuxt context.`);
|
|
123
|
+
return container;
|
|
124
|
+
}
|
|
98
125
|
async function updateSiteConfig(input) {
|
|
99
|
-
|
|
126
|
+
const container = await getSiteConfigStack();
|
|
127
|
+
container.push(input);
|
|
100
128
|
}
|
|
101
129
|
async function useSiteConfig() {
|
|
102
|
-
|
|
130
|
+
const container = await getSiteConfigStack();
|
|
131
|
+
return container.get();
|
|
103
132
|
}
|
|
104
133
|
|
|
105
134
|
function requireSiteConfig(context, requirements, modes) {
|
package/dist/module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { S as
|
|
2
|
+
import { S as SiteConfigStack, a as SiteConfigInput, b as SiteConfig } from './type-1234fa1d.js';
|
|
3
3
|
import { AssertionModes, ModuleAssertion } from '~/src/type';
|
|
4
4
|
|
|
5
5
|
interface ModuleOptions extends SiteConfigInput {
|
|
@@ -9,7 +9,7 @@ interface ModulePublicRuntimeConfig {
|
|
|
9
9
|
}
|
|
10
10
|
declare module 'h3' {
|
|
11
11
|
interface H3EventContext {
|
|
12
|
-
siteConfig:
|
|
12
|
+
siteConfig: SiteConfigStack;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
declare module 'nuxt/schema' {
|
|
@@ -24,7 +24,7 @@ declare module '@nuxt/schema' {
|
|
|
24
24
|
site?: SiteConfigInput;
|
|
25
25
|
}
|
|
26
26
|
interface Nuxt {
|
|
27
|
-
_siteConfig?:
|
|
27
|
+
_siteConfig?: SiteConfigStack;
|
|
28
28
|
_siteConfigAsserts?: Partial<Record<Partial<AssertionModes>, ModuleAssertion[]>>;
|
|
29
29
|
}
|
|
30
30
|
}
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addImports, addComponent, addPlugin, addServerHandler } from '@nuxt/kit';
|
|
2
2
|
import { updateSiteConfig, useSiteConfig, assertSiteConfig } from './kit.mjs';
|
|
3
3
|
import 'pkg-types';
|
|
4
|
-
import 'defu';
|
|
5
4
|
|
|
6
5
|
const module = defineNuxtModule({
|
|
7
6
|
meta: {
|
|
@@ -22,7 +21,10 @@ const module = defineNuxtModule({
|
|
|
22
21
|
});
|
|
23
22
|
});
|
|
24
23
|
nuxt.hook("modules:done", async () => {
|
|
25
|
-
await updateSiteConfig(
|
|
24
|
+
await updateSiteConfig({
|
|
25
|
+
_context: "nuxt:config:site",
|
|
26
|
+
...config
|
|
27
|
+
});
|
|
26
28
|
const siteConfig = await useSiteConfig();
|
|
27
29
|
await nuxt.callHook("site-config:resolve", siteConfig);
|
|
28
30
|
nuxt.options.runtimeConfig.public.site = siteConfig;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useNuxtApp, useRequestEvent } from "#imports";
|
|
2
2
|
export function updateSiteConfig(input = {}) {
|
|
3
3
|
if (process.server) {
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const stack2 = useRequestEvent().context.siteConfig;
|
|
5
|
+
stack2.push(input);
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const stack = useNuxtApp().$siteConfig;
|
|
9
|
+
stack.push(input);
|
|
10
10
|
}
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
} from "#imports";
|
|
5
5
|
export function useSiteConfig() {
|
|
6
6
|
if (process.server) {
|
|
7
|
-
const
|
|
8
|
-
return
|
|
7
|
+
const stack2 = useRequestEvent().context.siteConfig;
|
|
8
|
+
return stack2.get();
|
|
9
9
|
}
|
|
10
|
-
const
|
|
11
|
-
return
|
|
10
|
+
const stack = useNuxtApp().$siteConfig;
|
|
11
|
+
return stack.get();
|
|
12
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSiteConfigStack } from "../../siteConfig/index.mjs";
|
|
2
2
|
export function updateSiteConfig(e, input) {
|
|
3
|
-
e.context.siteConfig = e.context.siteConfig ||
|
|
3
|
+
e.context.siteConfig = e.context.siteConfig || createSiteConfigStack();
|
|
4
4
|
e.context.siteConfig.push(input);
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSiteConfigStack } from "../../siteConfig/index.mjs";
|
|
2
2
|
export function useSiteConfig(e) {
|
|
3
|
-
e.context.siteConfig = e.context.siteConfig ||
|
|
3
|
+
e.context.siteConfig = e.context.siteConfig || createSiteConfigStack();
|
|
4
4
|
return e.context.siteConfig.get();
|
|
5
5
|
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSiteConfigStack } from "../siteConfig/index.mjs";
|
|
2
2
|
import { defineNuxtPlugin, useRequestEvent, useState } from "#imports";
|
|
3
3
|
export default defineNuxtPlugin({
|
|
4
4
|
name: "nuxt-site-config",
|
|
5
5
|
enforce: "pre",
|
|
6
6
|
// or 'post'
|
|
7
7
|
async setup(nuxtApp) {
|
|
8
|
-
let
|
|
8
|
+
let siteConfigStack;
|
|
9
9
|
if (process.server) {
|
|
10
|
-
|
|
10
|
+
siteConfigStack = useRequestEvent().context.siteConfig;
|
|
11
11
|
nuxtApp.hooks.hook("app:rendered", () => {
|
|
12
12
|
useState("site-config", () => useRequestEvent().context.siteConfig.get());
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
if (!
|
|
16
|
-
|
|
15
|
+
if (!siteConfigStack)
|
|
16
|
+
siteConfigStack = createSiteConfigStack();
|
|
17
17
|
if (process.client) {
|
|
18
18
|
const state = useState("site-config");
|
|
19
19
|
if (state)
|
|
20
|
-
|
|
20
|
+
siteConfigStack.push(state.value);
|
|
21
21
|
}
|
|
22
22
|
return {
|
|
23
23
|
provide: {
|
|
24
|
-
siteConfig:
|
|
24
|
+
siteConfig: siteConfigStack
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './stack';
|
|
2
2
|
export * from './util';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./stack.mjs";
|
|
2
2
|
export * from "./util.mjs";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { normalizeSiteConfig } from ".//index.mjs";
|
|
2
|
+
export function createSiteConfigStack() {
|
|
3
|
+
const stack = [];
|
|
4
|
+
function push(input) {
|
|
5
|
+
if (!input._context) {
|
|
6
|
+
let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
|
|
7
|
+
if (lastFunctionName?.includes("/"))
|
|
8
|
+
lastFunctionName = "anonymous";
|
|
9
|
+
input._context = lastFunctionName;
|
|
10
|
+
}
|
|
11
|
+
stack.push(input);
|
|
12
|
+
}
|
|
13
|
+
function get() {
|
|
14
|
+
const siteConfig = {
|
|
15
|
+
_context: {}
|
|
16
|
+
};
|
|
17
|
+
for (const o in stack) {
|
|
18
|
+
for (const k in stack[o]) {
|
|
19
|
+
const val = stack[o][k];
|
|
20
|
+
if (!k.endsWith("context") && typeof val !== "undefined") {
|
|
21
|
+
siteConfig[k] = val;
|
|
22
|
+
siteConfig._context[k] = stack[o]._context?.[k] || stack[o]._context || "anonymous";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return normalizeSiteConfig(siteConfig);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
push,
|
|
30
|
+
get
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -42,8 +42,16 @@ interface SiteConfig {
|
|
|
42
42
|
* Used by: nuxt-schema-org, nuxt-seo-kit
|
|
43
43
|
*/
|
|
44
44
|
logo?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The mapping of the context of each site config value being set.
|
|
47
|
+
*/
|
|
48
|
+
_context: Partial<Record<Exclude<keyof SiteConfig, '_meta'>, string>>;
|
|
45
49
|
}
|
|
46
50
|
interface SiteConfigInput {
|
|
51
|
+
/**
|
|
52
|
+
* A description of the context which added the config.
|
|
53
|
+
*/
|
|
54
|
+
_context?: string;
|
|
47
55
|
url?: string;
|
|
48
56
|
name?: string;
|
|
49
57
|
description?: string;
|
|
@@ -54,10 +62,10 @@ interface SiteConfigInput {
|
|
|
54
62
|
indexable?: boolean | string;
|
|
55
63
|
trailingSlash?: boolean | string;
|
|
56
64
|
}
|
|
57
|
-
interface
|
|
58
|
-
push: (config: SiteConfigInput) => void;
|
|
65
|
+
interface SiteConfigStack {
|
|
66
|
+
push: (config: SiteConfigInput | SiteConfig) => void;
|
|
59
67
|
get: () => SiteConfig;
|
|
60
68
|
}
|
|
61
69
|
type AssertionModes = 'prerender' | 'generate' | 'build';
|
|
62
70
|
|
|
63
|
-
export { AssertionModes as A,
|
|
71
|
+
export { AssertionModes as A, SiteConfigStack as S, SiteConfigInput as a, SiteConfig as b };
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defu } from "defu";
|
|
2
|
-
import { normalizeSiteConfig } from ".//index.mjs";
|
|
3
|
-
export function createSiteConfigContainer() {
|
|
4
|
-
const stack = [];
|
|
5
|
-
function push(input) {
|
|
6
|
-
stack.push(input);
|
|
7
|
-
}
|
|
8
|
-
function get() {
|
|
9
|
-
let mergedStack = {};
|
|
10
|
-
for (const o of stack)
|
|
11
|
-
mergedStack = defu(o, mergedStack);
|
|
12
|
-
return normalizeSiteConfig(mergedStack);
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
push,
|
|
16
|
-
get
|
|
17
|
-
};
|
|
18
|
-
}
|