nuxt-site-config-kit 1.1.3 → 1.2.1

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
@@ -3,44 +3,9 @@
3
3
  const kit = require('@nuxt/kit');
4
4
  const pkgTypes = require('pkg-types');
5
5
  const siteConfigStack = require('site-config-stack');
6
+ const stdEnv = require('std-env');
6
7
  const ufo = require('ufo');
7
8
 
8
- const processShim = typeof process !== "undefined" ? process : {};
9
- const envShim = processShim.env || {};
10
- const DefaultSiteConfig = {
11
- _context: "defaults",
12
- defaultLocale: "en",
13
- trailingSlash: false
14
- };
15
- const VendorEnv = {
16
- _context: "vendorEnv",
17
- url: [
18
- // vercel
19
- envShim.VERCEL_URL,
20
- envShim.NUXT_ENV_VERCEL_URL,
21
- // netlify
22
- envShim.URL,
23
- // cloudflare pages
24
- envShim.CF_PAGES_URL
25
- ].find((k) => Boolean(k)),
26
- name: [
27
- // vercel
28
- envShim.NUXT_ENV_VERCEL_GIT_REPO_SLUG,
29
- // netlify
30
- envShim.SITE_NAME
31
- ].find((k) => Boolean(k))
32
- };
33
-
34
- async function getPkgJsonContextConfig(rootDir) {
35
- const pkgJson = await pkgTypes.readPackageJSON(void 0, { startingFrom: rootDir });
36
- if (!pkgJson)
37
- return {};
38
- return {
39
- _context: "package.json",
40
- name: pkgJson.name,
41
- description: pkgJson.description
42
- };
43
- }
44
9
  async function initSiteConfig(nuxt = kit.tryUseNuxt()) {
45
10
  if (!nuxt)
46
11
  return;
@@ -48,16 +13,79 @@ async function initSiteConfig(nuxt = kit.tryUseNuxt()) {
48
13
  if (siteConfig)
49
14
  return siteConfig;
50
15
  siteConfig = siteConfigStack.createSiteConfigStack();
51
- siteConfig.push(DefaultSiteConfig);
52
- const rootDir = nuxt?.options.rootDir || process.cwd();
53
- const isNodeEnv = !!envShim.NODE_ENV;
16
+ siteConfig.push({
17
+ _priority: -20,
18
+ _context: "defaults",
19
+ defaultLocale: "en",
20
+ trailingSlash: false
21
+ });
22
+ const rootDir = nuxt?.options.rootDir || stdEnv.process.cwd?.() || false;
54
23
  siteConfig.push({
55
24
  _context: "system",
56
- name: rootDir.split("/").pop(),
57
- indexable: isNodeEnv ? envShim.NODE_ENV === "production" : !process.dev
25
+ _priority: -15,
26
+ name: rootDir ? rootDir.split("/").pop() : void 0,
27
+ indexable: stdEnv.isProduction
28
+ });
29
+ if (rootDir) {
30
+ const pkgJson = await pkgTypes.readPackageJSON(void 0, { startingFrom: rootDir });
31
+ if (pkgJson) {
32
+ siteConfig.push({
33
+ _context: "package.json",
34
+ _priority: -10,
35
+ name: pkgJson.name,
36
+ description: pkgJson.description
37
+ });
38
+ }
39
+ }
40
+ siteConfig.push({
41
+ _context: "vendorEnv",
42
+ _priority: -5,
43
+ url: [
44
+ // vercel
45
+ stdEnv.env.VERCEL_URL,
46
+ stdEnv.env.NUXT_ENV_VERCEL_URL,
47
+ // netlify
48
+ stdEnv.env.URL,
49
+ // cloudflare pages
50
+ stdEnv.env.CF_PAGES_URL
51
+ ].find((k) => Boolean(k)),
52
+ name: [
53
+ // vercel
54
+ stdEnv.env.NUXT_ENV_VERCEL_GIT_REPO_SLUG,
55
+ // netlify
56
+ stdEnv.env.SITE_NAME
57
+ ].find((k) => Boolean(k))
58
+ });
59
+ const runtimeConfig = nuxt.options.runtimeConfig;
60
+ function getRuntimeConfig(config) {
61
+ return runtimeConfig[`site${config}`] || runtimeConfig.public?.[`site${config}`];
62
+ }
63
+ function getEnv(config) {
64
+ const key = config.toUpperCase();
65
+ if (stdEnv.env[`NUXT_SITE_${key}`])
66
+ return stdEnv.env[`NUXT_SITE_${key}`];
67
+ if (stdEnv.env[`NUXT_PUBLIC_SITE_${key}`])
68
+ return stdEnv.env[`NUXT_PUBLIC_SITE_${key}`];
69
+ }
70
+ siteConfig.push({
71
+ _context: "env",
72
+ url: getEnv("Url"),
73
+ name: getEnv("Name"),
74
+ description: getEnv("Description"),
75
+ logo: getEnv("Image"),
76
+ defaultLocale: getEnv("Language"),
77
+ indexable: getEnv("Indexable")
78
+ });
79
+ siteConfig.push({
80
+ _context: "runtimeConfig",
81
+ url: getRuntimeConfig("Url"),
82
+ name: getRuntimeConfig("Name"),
83
+ description: getRuntimeConfig("Description"),
84
+ logo: getRuntimeConfig("Image"),
85
+ defaultLocale: getRuntimeConfig("Language"),
86
+ indexable: getRuntimeConfig("Indexable"),
87
+ ...nuxt?.options.runtimeConfig.public.site || {}
58
88
  });
59
- siteConfig.push(await getPkgJsonContextConfig(rootDir));
60
- siteConfig.push(VendorEnv);
61
89
  nuxt._siteConfig = siteConfig;
62
90
  return siteConfig;
63
91
  }
@@ -76,7 +104,7 @@ function updateSiteConfig(input, nuxt = kit.tryUseNuxt()) {
76
104
  const container = getSiteConfigStack(nuxt);
77
105
  container.push(input);
78
106
  }
79
- function useSiteConfig(context, nuxt = kit.tryUseNuxt()) {
107
+ function useSiteConfig(nuxt = kit.tryUseNuxt()) {
80
108
  const container = getSiteConfigStack(nuxt);
81
109
  return container.get();
82
110
  }
@@ -114,13 +142,13 @@ function assertSiteConfig(module, requirements, options) {
114
142
  }
115
143
 
116
144
  function useNitroOrigin() {
117
- const cert = process.env.NITRO_SSL_CERT;
118
- const key = process.env.NITRO_SSL_KEY;
119
- let host = process.env.NITRO_HOST || process.env.HOST || false;
120
- let port = process.env.NITRO_PORT || process.env.PORT || (process.dev ? 3e3 : false);
121
- let protocol = cert && key || !process.dev ? "https" : "http";
122
- if ((process.dev || process.env.prerender) && process.env.NUXT_VITE_NODE_OPTIONS) {
123
- const origin = JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS).baseURL.replace("/__nuxt_vite_node__", "");
145
+ const cert = stdEnv.env.NITRO_SSL_CERT;
146
+ const key = stdEnv.env.NITRO_SSL_KEY;
147
+ let host = stdEnv.env.NITRO_HOST || stdEnv.env.HOST || false;
148
+ let port = stdEnv.env.NITRO_PORT || stdEnv.env.PORT || (stdEnv.isDevelopment ? 3e3 : false);
149
+ let protocol = cert && key || !stdEnv.isDevelopment ? "https" : "http";
150
+ if ((stdEnv.isDevelopment || stdEnv.env.prerender) && stdEnv.env.NUXT_VITE_NODE_OPTIONS) {
151
+ const origin = JSON.parse(stdEnv.env.NUXT_VITE_NODE_OPTIONS).baseURL.replace("/__nuxt_vite_node__", "");
124
152
  host = ufo.withoutProtocol(origin);
125
153
  protocol = origin.includes("https") ? "https" : "http";
126
154
  }
@@ -152,7 +180,7 @@ function withSiteTrailingSlash(path) {
152
180
  function createSitePathResolver(options = {}, nuxt = kit.useNuxt()) {
153
181
  const siteConfig = useSiteConfig();
154
182
  const nitroOrigin = useNitroOrigin();
155
- const canUseSiteUrl = (options.canonical !== false || process.env.prerender) && siteConfig.url;
183
+ const canUseSiteUrl = (options.canonical !== false || stdEnv.env.prerender) && siteConfig.url;
156
184
  const nuxtBase = nuxt.options.app.baseURL || "/";
157
185
  return (path) => {
158
186
  return siteConfigStack.resolveSitePath(path, {
package/dist/index.d.cts CHANGED
@@ -22,9 +22,7 @@ declare module '@nuxt/schema' {
22
22
  declare function initSiteConfig(nuxt?: Nuxt | null): Promise<SiteConfigStack | undefined>;
23
23
  declare function installNuxtSiteConfig(nuxt?: Nuxt | null): Promise<void>;
24
24
  declare function updateSiteConfig(input: SiteConfigInput, nuxt?: Nuxt | null): void;
25
- declare function useSiteConfig(context?: {
26
- path: string;
27
- }, nuxt?: Nuxt | null): SiteConfig;
25
+ declare function useSiteConfig(nuxt?: Nuxt | null): SiteConfig;
28
26
 
29
27
  /**
30
28
  * @deprecated No longer used
package/dist/index.d.mts CHANGED
@@ -22,9 +22,7 @@ declare module '@nuxt/schema' {
22
22
  declare function initSiteConfig(nuxt?: Nuxt | null): Promise<SiteConfigStack | undefined>;
23
23
  declare function installNuxtSiteConfig(nuxt?: Nuxt | null): Promise<void>;
24
24
  declare function updateSiteConfig(input: SiteConfigInput, nuxt?: Nuxt | null): void;
25
- declare function useSiteConfig(context?: {
26
- path: string;
27
- }, nuxt?: Nuxt | null): SiteConfig;
25
+ declare function useSiteConfig(nuxt?: Nuxt | null): SiteConfig;
28
26
 
29
27
  /**
30
28
  * @deprecated No longer used
package/dist/index.d.ts CHANGED
@@ -22,9 +22,7 @@ declare module '@nuxt/schema' {
22
22
  declare function initSiteConfig(nuxt?: Nuxt | null): Promise<SiteConfigStack | undefined>;
23
23
  declare function installNuxtSiteConfig(nuxt?: Nuxt | null): Promise<void>;
24
24
  declare function updateSiteConfig(input: SiteConfigInput, nuxt?: Nuxt | null): void;
25
- declare function useSiteConfig(context?: {
26
- path: string;
27
- }, nuxt?: Nuxt | null): SiteConfig;
25
+ declare function useSiteConfig(nuxt?: Nuxt | null): SiteConfig;
28
26
 
29
27
  /**
30
28
  * @deprecated No longer used
package/dist/index.mjs CHANGED
@@ -1,44 +1,9 @@
1
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
+ import { process, isProduction, env, isDevelopment } from 'std-env';
4
5
  import { withoutProtocol } from 'ufo';
5
6
 
6
- const processShim = typeof process !== "undefined" ? process : {};
7
- const envShim = processShim.env || {};
8
- const DefaultSiteConfig = {
9
- _context: "defaults",
10
- defaultLocale: "en",
11
- trailingSlash: false
12
- };
13
- const VendorEnv = {
14
- _context: "vendorEnv",
15
- url: [
16
- // vercel
17
- envShim.VERCEL_URL,
18
- envShim.NUXT_ENV_VERCEL_URL,
19
- // netlify
20
- envShim.URL,
21
- // cloudflare pages
22
- envShim.CF_PAGES_URL
23
- ].find((k) => Boolean(k)),
24
- name: [
25
- // vercel
26
- envShim.NUXT_ENV_VERCEL_GIT_REPO_SLUG,
27
- // netlify
28
- envShim.SITE_NAME
29
- ].find((k) => Boolean(k))
30
- };
31
-
32
- async function getPkgJsonContextConfig(rootDir) {
33
- const pkgJson = await readPackageJSON(void 0, { startingFrom: rootDir });
34
- if (!pkgJson)
35
- return {};
36
- return {
37
- _context: "package.json",
38
- name: pkgJson.name,
39
- description: pkgJson.description
40
- };
41
- }
42
7
  async function initSiteConfig(nuxt = tryUseNuxt()) {
43
8
  if (!nuxt)
44
9
  return;
@@ -46,16 +11,79 @@ async function initSiteConfig(nuxt = tryUseNuxt()) {
46
11
  if (siteConfig)
47
12
  return siteConfig;
48
13
  siteConfig = createSiteConfigStack();
49
- siteConfig.push(DefaultSiteConfig);
50
- const rootDir = nuxt?.options.rootDir || process.cwd();
51
- const isNodeEnv = !!envShim.NODE_ENV;
14
+ siteConfig.push({
15
+ _priority: -20,
16
+ _context: "defaults",
17
+ defaultLocale: "en",
18
+ trailingSlash: false
19
+ });
20
+ const rootDir = nuxt?.options.rootDir || process.cwd?.() || false;
52
21
  siteConfig.push({
53
22
  _context: "system",
54
- name: rootDir.split("/").pop(),
55
- indexable: isNodeEnv ? envShim.NODE_ENV === "production" : !process.dev
23
+ _priority: -15,
24
+ name: rootDir ? rootDir.split("/").pop() : void 0,
25
+ indexable: isProduction
26
+ });
27
+ if (rootDir) {
28
+ const pkgJson = await readPackageJSON(void 0, { startingFrom: rootDir });
29
+ if (pkgJson) {
30
+ siteConfig.push({
31
+ _context: "package.json",
32
+ _priority: -10,
33
+ name: pkgJson.name,
34
+ description: pkgJson.description
35
+ });
36
+ }
37
+ }
38
+ siteConfig.push({
39
+ _context: "vendorEnv",
40
+ _priority: -5,
41
+ url: [
42
+ // vercel
43
+ env.VERCEL_URL,
44
+ env.NUXT_ENV_VERCEL_URL,
45
+ // netlify
46
+ env.URL,
47
+ // cloudflare pages
48
+ env.CF_PAGES_URL
49
+ ].find((k) => Boolean(k)),
50
+ name: [
51
+ // vercel
52
+ env.NUXT_ENV_VERCEL_GIT_REPO_SLUG,
53
+ // netlify
54
+ env.SITE_NAME
55
+ ].find((k) => Boolean(k))
56
+ });
57
+ const runtimeConfig = nuxt.options.runtimeConfig;
58
+ function getRuntimeConfig(config) {
59
+ return runtimeConfig[`site${config}`] || runtimeConfig.public?.[`site${config}`];
60
+ }
61
+ function getEnv(config) {
62
+ const key = config.toUpperCase();
63
+ if (env[`NUXT_SITE_${key}`])
64
+ return env[`NUXT_SITE_${key}`];
65
+ if (env[`NUXT_PUBLIC_SITE_${key}`])
66
+ return env[`NUXT_PUBLIC_SITE_${key}`];
67
+ }
68
+ siteConfig.push({
69
+ _context: "env",
70
+ url: getEnv("Url"),
71
+ name: getEnv("Name"),
72
+ description: getEnv("Description"),
73
+ logo: getEnv("Image"),
74
+ defaultLocale: getEnv("Language"),
75
+ indexable: getEnv("Indexable")
76
+ });
77
+ siteConfig.push({
78
+ _context: "runtimeConfig",
79
+ url: getRuntimeConfig("Url"),
80
+ name: getRuntimeConfig("Name"),
81
+ description: getRuntimeConfig("Description"),
82
+ logo: getRuntimeConfig("Image"),
83
+ defaultLocale: getRuntimeConfig("Language"),
84
+ indexable: getRuntimeConfig("Indexable"),
85
+ ...nuxt?.options.runtimeConfig.public.site || {}
56
86
  });
57
- siteConfig.push(await getPkgJsonContextConfig(rootDir));
58
- siteConfig.push(VendorEnv);
59
87
  nuxt._siteConfig = siteConfig;
60
88
  return siteConfig;
61
89
  }
@@ -74,7 +102,7 @@ function updateSiteConfig(input, nuxt = tryUseNuxt()) {
74
102
  const container = getSiteConfigStack(nuxt);
75
103
  container.push(input);
76
104
  }
77
- function useSiteConfig(context, nuxt = tryUseNuxt()) {
105
+ function useSiteConfig(nuxt = tryUseNuxt()) {
78
106
  const container = getSiteConfigStack(nuxt);
79
107
  return container.get();
80
108
  }
@@ -112,13 +140,13 @@ function assertSiteConfig(module, requirements, options) {
112
140
  }
113
141
 
114
142
  function useNitroOrigin() {
115
- const cert = process.env.NITRO_SSL_CERT;
116
- const key = process.env.NITRO_SSL_KEY;
117
- let host = process.env.NITRO_HOST || process.env.HOST || false;
118
- let port = process.env.NITRO_PORT || process.env.PORT || (process.dev ? 3e3 : false);
119
- let protocol = cert && key || !process.dev ? "https" : "http";
120
- if ((process.dev || process.env.prerender) && process.env.NUXT_VITE_NODE_OPTIONS) {
121
- const origin = JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS).baseURL.replace("/__nuxt_vite_node__", "");
143
+ const cert = env.NITRO_SSL_CERT;
144
+ const key = env.NITRO_SSL_KEY;
145
+ let host = env.NITRO_HOST || env.HOST || false;
146
+ let port = env.NITRO_PORT || env.PORT || (isDevelopment ? 3e3 : false);
147
+ let protocol = cert && key || !isDevelopment ? "https" : "http";
148
+ if ((isDevelopment || env.prerender) && env.NUXT_VITE_NODE_OPTIONS) {
149
+ const origin = JSON.parse(env.NUXT_VITE_NODE_OPTIONS).baseURL.replace("/__nuxt_vite_node__", "");
122
150
  host = withoutProtocol(origin);
123
151
  protocol = origin.includes("https") ? "https" : "http";
124
152
  }
@@ -150,7 +178,7 @@ function withSiteTrailingSlash(path) {
150
178
  function createSitePathResolver(options = {}, nuxt = useNuxt()) {
151
179
  const siteConfig = useSiteConfig();
152
180
  const nitroOrigin = useNitroOrigin();
153
- const canUseSiteUrl = (options.canonical !== false || process.env.prerender) && siteConfig.url;
181
+ const canUseSiteUrl = (options.canonical !== false || env.prerender) && siteConfig.url;
154
182
  const nuxtBase = nuxt.options.app.baseURL || "/";
155
183
  return (path) => {
156
184
  return resolveSitePath(path, {
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.3",
4
+ "version": "1.2.1",
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",
@@ -30,8 +30,9 @@
30
30
  "@nuxt/kit": "^3.7.1",
31
31
  "@nuxt/schema": "^3.7.1",
32
32
  "pkg-types": "^1.0.3",
33
+ "std-env": "^3.4.3",
33
34
  "ufo": "^1.3.0",
34
- "site-config-stack": "1.1.3"
35
+ "site-config-stack": "1.2.1"
35
36
  },
36
37
  "scripts": {
37
38
  "lint": "eslint . --fix",