nuxt-site-config-kit 0.8.17 → 1.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
@@ -5,12 +5,40 @@ const pkgTypes = require('pkg-types');
5
5
  const siteConfigStack = require('site-config-stack');
6
6
  const ufo = require('ufo');
7
7
 
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
+ titleSeparator: "|"
15
+ };
16
+ const VendorEnv = {
17
+ _context: "vendorEnv",
18
+ url: [
19
+ // vercel
20
+ envShim.VERCEL_URL,
21
+ envShim.NUXT_ENV_VERCEL_URL,
22
+ // netlify
23
+ envShim.URL,
24
+ // cloudflare pages
25
+ envShim.CF_PAGES_URL
26
+ ].find((k) => Boolean(k)),
27
+ name: [
28
+ // vercel
29
+ envShim.NUXT_ENV_VERCEL_GIT_REPO_SLUG,
30
+ // netlify
31
+ envShim.SITE_NAME
32
+ ].find((k) => Boolean(k))
33
+ };
34
+
8
35
  async function getPkgJsonContextConfig(rootDir) {
9
36
  const pkgJson = await pkgTypes.readPackageJSON(void 0, { startingFrom: rootDir });
10
37
  if (!pkgJson)
11
38
  return {};
12
39
  return {
13
40
  _context: "package.json",
41
+ url: pkgJson.homepage,
14
42
  name: pkgJson.name,
15
43
  description: pkgJson.description
16
44
  };
@@ -22,42 +50,16 @@ async function initSiteConfig(nuxt = kit.tryUseNuxt()) {
22
50
  if (siteConfig)
23
51
  return siteConfig;
24
52
  siteConfig = siteConfigStack.createSiteConfigStack();
25
- siteConfig.push({
26
- _context: "defaults",
27
- locale: "en",
28
- trailingSlash: false,
29
- titleSeparator: "|"
30
- });
53
+ siteConfig.push(DefaultSiteConfig);
31
54
  const rootDir = nuxt?.options.rootDir || process.cwd();
32
- const isNodeEnv = !!process.env.NODE_ENV;
55
+ const isNodeEnv = !!envShim.NODE_ENV;
33
56
  siteConfig.push({
34
57
  _context: "system",
35
58
  name: rootDir.split("/").pop(),
36
- indexable: isNodeEnv ? process.env.NODE_ENV === "production" : !process.dev
59
+ indexable: isNodeEnv ? envShim.NODE_ENV === "production" : !process.dev
37
60
  });
38
61
  siteConfig.push(await getPkgJsonContextConfig(rootDir));
39
- siteConfig.push(siteConfigStack.envSiteConfig);
40
- const runtimeConfig = nuxt.options.runtimeConfig;
41
- function getRuntimeConfig(config, env) {
42
- if (process.env[`NUXT_${env}}`])
43
- return process.env[`NUXT_${env}}`];
44
- if (process.env[`NUXT_PUBLIC_${env}}`])
45
- return process.env[`NUXT_PUBLIC_${env}}`];
46
- return runtimeConfig[`site${config}`] || runtimeConfig.public?.[`site${config}`];
47
- }
48
- siteConfig.push({
49
- _context: "legacyRuntimeConfig",
50
- url: getRuntimeConfig("Url", "_URL"),
51
- name: getRuntimeConfig("Name", "_NAME"),
52
- description: getRuntimeConfig("Description", "_DESCRIPTION"),
53
- logo: getRuntimeConfig("Image", "_IMAGE"),
54
- locale: getRuntimeConfig("Language", "_LANGUAGE"),
55
- indexable: getRuntimeConfig("Indexable", "_INDEXABLE")
56
- });
57
- siteConfig.push({
58
- _context: "runtimeConfig",
59
- ...nuxt?.options.runtimeConfig.public.site || {}
60
- });
62
+ siteConfig.push(VendorEnv);
61
63
  nuxt._siteConfig = siteConfig;
62
64
  return siteConfig;
63
65
  }
@@ -76,7 +78,7 @@ function updateSiteConfig(input, nuxt = kit.tryUseNuxt()) {
76
78
  const container = getSiteConfigStack(nuxt);
77
79
  container.push(input);
78
80
  }
79
- function useSiteConfig(nuxt = kit.tryUseNuxt()) {
81
+ function useSiteConfig(context, nuxt = kit.tryUseNuxt()) {
80
82
  const container = getSiteConfigStack(nuxt);
81
83
  return container.get();
82
84
  }
package/dist/index.d.ts CHANGED
@@ -22,7 +22,9 @@ 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(nuxt?: Nuxt | null): SiteConfig;
25
+ declare function useSiteConfig(context?: {
26
+ path: string;
27
+ }, nuxt?: Nuxt | null): SiteConfig;
26
28
 
27
29
  declare function requireSiteConfig(context: string, requirements: Partial<Record<keyof SiteConfig, string>>, modes: Partial<Record<AssertionModes, boolean>>): void;
28
30
  declare function assertSiteConfig(mode: AssertionModes, options?: {
package/dist/index.mjs CHANGED
@@ -1,14 +1,42 @@
1
1
  import { tryUseNuxt, installModule, resolvePath, useNuxt, useLogger } from '@nuxt/kit';
2
2
  import { readPackageJSON } from 'pkg-types';
3
- import { createSiteConfigStack, envSiteConfig, resolveSitePath, fixSlashes } from 'site-config-stack';
3
+ import { createSiteConfigStack, resolveSitePath, fixSlashes } from 'site-config-stack';
4
4
  import { withoutProtocol } from 'ufo';
5
5
 
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
+ titleSeparator: "|"
13
+ };
14
+ const VendorEnv = {
15
+ _context: "vendorEnv",
16
+ url: [
17
+ // vercel
18
+ envShim.VERCEL_URL,
19
+ envShim.NUXT_ENV_VERCEL_URL,
20
+ // netlify
21
+ envShim.URL,
22
+ // cloudflare pages
23
+ envShim.CF_PAGES_URL
24
+ ].find((k) => Boolean(k)),
25
+ name: [
26
+ // vercel
27
+ envShim.NUXT_ENV_VERCEL_GIT_REPO_SLUG,
28
+ // netlify
29
+ envShim.SITE_NAME
30
+ ].find((k) => Boolean(k))
31
+ };
32
+
6
33
  async function getPkgJsonContextConfig(rootDir) {
7
34
  const pkgJson = await readPackageJSON(void 0, { startingFrom: rootDir });
8
35
  if (!pkgJson)
9
36
  return {};
10
37
  return {
11
38
  _context: "package.json",
39
+ url: pkgJson.homepage,
12
40
  name: pkgJson.name,
13
41
  description: pkgJson.description
14
42
  };
@@ -20,42 +48,16 @@ async function initSiteConfig(nuxt = tryUseNuxt()) {
20
48
  if (siteConfig)
21
49
  return siteConfig;
22
50
  siteConfig = createSiteConfigStack();
23
- siteConfig.push({
24
- _context: "defaults",
25
- locale: "en",
26
- trailingSlash: false,
27
- titleSeparator: "|"
28
- });
51
+ siteConfig.push(DefaultSiteConfig);
29
52
  const rootDir = nuxt?.options.rootDir || process.cwd();
30
- const isNodeEnv = !!process.env.NODE_ENV;
53
+ const isNodeEnv = !!envShim.NODE_ENV;
31
54
  siteConfig.push({
32
55
  _context: "system",
33
56
  name: rootDir.split("/").pop(),
34
- indexable: isNodeEnv ? process.env.NODE_ENV === "production" : !process.dev
57
+ indexable: isNodeEnv ? envShim.NODE_ENV === "production" : !process.dev
35
58
  });
36
59
  siteConfig.push(await getPkgJsonContextConfig(rootDir));
37
- siteConfig.push(envSiteConfig);
38
- const runtimeConfig = nuxt.options.runtimeConfig;
39
- function getRuntimeConfig(config, env) {
40
- if (process.env[`NUXT_${env}}`])
41
- return process.env[`NUXT_${env}}`];
42
- if (process.env[`NUXT_PUBLIC_${env}}`])
43
- return process.env[`NUXT_PUBLIC_${env}}`];
44
- return runtimeConfig[`site${config}`] || runtimeConfig.public?.[`site${config}`];
45
- }
46
- siteConfig.push({
47
- _context: "legacyRuntimeConfig",
48
- url: getRuntimeConfig("Url", "_URL"),
49
- name: getRuntimeConfig("Name", "_NAME"),
50
- description: getRuntimeConfig("Description", "_DESCRIPTION"),
51
- logo: getRuntimeConfig("Image", "_IMAGE"),
52
- locale: getRuntimeConfig("Language", "_LANGUAGE"),
53
- indexable: getRuntimeConfig("Indexable", "_INDEXABLE")
54
- });
55
- siteConfig.push({
56
- _context: "runtimeConfig",
57
- ...nuxt?.options.runtimeConfig.public.site || {}
58
- });
60
+ siteConfig.push(VendorEnv);
59
61
  nuxt._siteConfig = siteConfig;
60
62
  return siteConfig;
61
63
  }
@@ -74,7 +76,7 @@ function updateSiteConfig(input, nuxt = tryUseNuxt()) {
74
76
  const container = getSiteConfigStack(nuxt);
75
77
  container.push(input);
76
78
  }
77
- function useSiteConfig(nuxt = tryUseNuxt()) {
79
+ function useSiteConfig(context, nuxt = tryUseNuxt()) {
78
80
  const container = getSiteConfigStack(nuxt);
79
81
  return container.get();
80
82
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-site-config-kit",
3
3
  "type": "module",
4
- "version": "0.8.17",
4
+ "version": "1.0.0",
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",
@@ -32,7 +32,7 @@
32
32
  "defu": "^6.1.2",
33
33
  "pkg-types": "^1.0.3",
34
34
  "ufo": "^1.1.2",
35
- "site-config-stack": "0.8.17"
35
+ "site-config-stack": "1.0.0"
36
36
  },
37
37
  "scripts": {
38
38
  "lint": "eslint . --fix",