nuxt-site-config-kit 0.8.4 → 0.8.10
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 +35 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +34 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const kit = require('@nuxt/kit');
|
|
4
4
|
const pkgTypes = require('pkg-types');
|
|
5
5
|
const siteConfigStack = require('site-config-stack');
|
|
6
|
+
const ufo = require('ufo');
|
|
6
7
|
|
|
7
8
|
async function getPkgJsonContextConfig(rootDir) {
|
|
8
9
|
const pkgJson = await pkgTypes.readPackageJSON(void 0, { startingFrom: rootDir });
|
|
@@ -123,6 +124,24 @@ async function assertSiteConfig(mode, options) {
|
|
|
123
124
|
};
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
function useNitroOrigin() {
|
|
128
|
+
const cert = process.env.NITRO_SSL_CERT;
|
|
129
|
+
const key = process.env.NITRO_SSL_KEY;
|
|
130
|
+
let host = process.env.NITRO_HOST || process.env.HOST || false;
|
|
131
|
+
let port = process.env.NITRO_PORT || process.env.PORT || (process.dev ? 3e3 : false);
|
|
132
|
+
let protocol = cert && key || !process.dev ? "https" : "http";
|
|
133
|
+
if ((process.dev || process.env.prerender) && process.env.NUXT_VITE_NODE_OPTIONS) {
|
|
134
|
+
const origin = JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS).baseURL.replace("/__nuxt_vite_node__", "");
|
|
135
|
+
host = ufo.withoutProtocol(origin);
|
|
136
|
+
protocol = origin.includes("https") ? "https" : "http";
|
|
137
|
+
}
|
|
138
|
+
if (typeof host === "string" && host.includes(":")) {
|
|
139
|
+
port = host.split(":").pop();
|
|
140
|
+
host = host.split(":")[0];
|
|
141
|
+
}
|
|
142
|
+
port = port ? `:${port}` : "";
|
|
143
|
+
return `${protocol}://${host}${port}/`;
|
|
144
|
+
}
|
|
126
145
|
function withSiteUrl(path, options = {}) {
|
|
127
146
|
const siteConfig = useSiteConfig();
|
|
128
147
|
if (!siteConfig.url && options.throwErrorOnMissingSiteUrl)
|
|
@@ -141,12 +160,28 @@ function withSiteTrailingSlash(path) {
|
|
|
141
160
|
const siteConfig = useSiteConfig();
|
|
142
161
|
return siteConfigStack.fixSlashes(siteConfig.trailingSlash, path);
|
|
143
162
|
}
|
|
163
|
+
function createSitePathResolver(options = {}, nuxt = kit.useNuxt()) {
|
|
164
|
+
const siteConfig = useSiteConfig();
|
|
165
|
+
const nitroOrigin = useNitroOrigin();
|
|
166
|
+
const canUseSiteUrl = options.canonical !== false || process.env.prerender && siteConfig.url;
|
|
167
|
+
const nuxtBase = nuxt.options.app.baseURL || "/";
|
|
168
|
+
return (path) => {
|
|
169
|
+
return siteConfigStack.resolveSitePath(path, {
|
|
170
|
+
...options,
|
|
171
|
+
siteUrl: canUseSiteUrl ? siteConfig.url : nitroOrigin,
|
|
172
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
173
|
+
base: nuxtBase
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
}
|
|
144
177
|
|
|
145
178
|
exports.assertSiteConfig = assertSiteConfig;
|
|
179
|
+
exports.createSitePathResolver = createSitePathResolver;
|
|
146
180
|
exports.initSiteConfig = initSiteConfig;
|
|
147
181
|
exports.installNuxtSiteConfig = installNuxtSiteConfig;
|
|
148
182
|
exports.requireSiteConfig = requireSiteConfig;
|
|
149
183
|
exports.updateSiteConfig = updateSiteConfig;
|
|
184
|
+
exports.useNitroOrigin = useNitroOrigin;
|
|
150
185
|
exports.useSiteConfig = useSiteConfig;
|
|
151
186
|
exports.withSiteTrailingSlash = withSiteTrailingSlash;
|
|
152
187
|
exports.withSiteUrl = withSiteUrl;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SiteConfigInput, SiteConfigStack, SiteConfig } from 'site-config-stack';
|
|
2
2
|
export { SiteConfig, SiteConfigInput, SiteConfigStack } from 'site-config-stack';
|
|
3
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
3
4
|
import { Nuxt } from '@nuxt/schema';
|
|
4
5
|
|
|
5
6
|
type AssertionModes = 'prerender' | 'generate' | 'build';
|
|
@@ -32,10 +33,16 @@ declare function assertSiteConfig(mode: AssertionModes, options?: {
|
|
|
32
33
|
messages: string[];
|
|
33
34
|
}>;
|
|
34
35
|
|
|
36
|
+
declare function useNitroOrigin(): string;
|
|
35
37
|
declare function withSiteUrl(path: string, options?: {
|
|
36
38
|
withBase?: boolean;
|
|
37
39
|
throwErrorOnMissingSiteUrl?: boolean;
|
|
38
40
|
}): string;
|
|
39
41
|
declare function withSiteTrailingSlash(path: string): string;
|
|
42
|
+
declare function createSitePathResolver(options?: {
|
|
43
|
+
canonical?: boolean;
|
|
44
|
+
absolute?: boolean;
|
|
45
|
+
withBase?: boolean;
|
|
46
|
+
}, nuxt?: _nuxt_schema.Nuxt): (path: string) => string;
|
|
40
47
|
|
|
41
|
-
export { AssertionModes, ModuleAssertion, assertSiteConfig, initSiteConfig, installNuxtSiteConfig, requireSiteConfig, updateSiteConfig, useSiteConfig, withSiteTrailingSlash, withSiteUrl };
|
|
48
|
+
export { AssertionModes, ModuleAssertion, assertSiteConfig, createSitePathResolver, initSiteConfig, installNuxtSiteConfig, requireSiteConfig, updateSiteConfig, useNitroOrigin, useSiteConfig, withSiteTrailingSlash, withSiteUrl };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { tryUseNuxt, installModule, resolvePath, useNuxt, useLogger } from '@nuxt/kit';
|
|
2
2
|
import { readPackageJSON } from 'pkg-types';
|
|
3
3
|
import { createSiteConfigStack, envSiteConfig, resolveSitePath, fixSlashes } from 'site-config-stack';
|
|
4
|
+
import { withoutProtocol } from 'ufo';
|
|
4
5
|
|
|
5
6
|
async function getPkgJsonContextConfig(rootDir) {
|
|
6
7
|
const pkgJson = await readPackageJSON(void 0, { startingFrom: rootDir });
|
|
@@ -121,6 +122,24 @@ async function assertSiteConfig(mode, options) {
|
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
function useNitroOrigin() {
|
|
126
|
+
const cert = process.env.NITRO_SSL_CERT;
|
|
127
|
+
const key = process.env.NITRO_SSL_KEY;
|
|
128
|
+
let host = process.env.NITRO_HOST || process.env.HOST || false;
|
|
129
|
+
let port = process.env.NITRO_PORT || process.env.PORT || (process.dev ? 3e3 : false);
|
|
130
|
+
let protocol = cert && key || !process.dev ? "https" : "http";
|
|
131
|
+
if ((process.dev || process.env.prerender) && process.env.NUXT_VITE_NODE_OPTIONS) {
|
|
132
|
+
const origin = JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS).baseURL.replace("/__nuxt_vite_node__", "");
|
|
133
|
+
host = withoutProtocol(origin);
|
|
134
|
+
protocol = origin.includes("https") ? "https" : "http";
|
|
135
|
+
}
|
|
136
|
+
if (typeof host === "string" && host.includes(":")) {
|
|
137
|
+
port = host.split(":").pop();
|
|
138
|
+
host = host.split(":")[0];
|
|
139
|
+
}
|
|
140
|
+
port = port ? `:${port}` : "";
|
|
141
|
+
return `${protocol}://${host}${port}/`;
|
|
142
|
+
}
|
|
124
143
|
function withSiteUrl(path, options = {}) {
|
|
125
144
|
const siteConfig = useSiteConfig();
|
|
126
145
|
if (!siteConfig.url && options.throwErrorOnMissingSiteUrl)
|
|
@@ -139,5 +158,19 @@ function withSiteTrailingSlash(path) {
|
|
|
139
158
|
const siteConfig = useSiteConfig();
|
|
140
159
|
return fixSlashes(siteConfig.trailingSlash, path);
|
|
141
160
|
}
|
|
161
|
+
function createSitePathResolver(options = {}, nuxt = useNuxt()) {
|
|
162
|
+
const siteConfig = useSiteConfig();
|
|
163
|
+
const nitroOrigin = useNitroOrigin();
|
|
164
|
+
const canUseSiteUrl = options.canonical !== false || process.env.prerender && siteConfig.url;
|
|
165
|
+
const nuxtBase = nuxt.options.app.baseURL || "/";
|
|
166
|
+
return (path) => {
|
|
167
|
+
return resolveSitePath(path, {
|
|
168
|
+
...options,
|
|
169
|
+
siteUrl: canUseSiteUrl ? siteConfig.url : nitroOrigin,
|
|
170
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
171
|
+
base: nuxtBase
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
}
|
|
142
175
|
|
|
143
|
-
export { assertSiteConfig, initSiteConfig, installNuxtSiteConfig, requireSiteConfig, updateSiteConfig, useSiteConfig, withSiteTrailingSlash, withSiteUrl };
|
|
176
|
+
export { assertSiteConfig, createSitePathResolver, initSiteConfig, installNuxtSiteConfig, requireSiteConfig, updateSiteConfig, useNitroOrigin, useSiteConfig, withSiteTrailingSlash, withSiteUrl };
|
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.
|
|
4
|
+
"version": "0.8.10",
|
|
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",
|
|
@@ -27,11 +27,12 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@nuxt/kit": "^3.6.
|
|
30
|
+
"@nuxt/kit": "^3.6.2",
|
|
31
|
+
"@nuxt/schema": "^3.6.2",
|
|
31
32
|
"defu": "^6.1.2",
|
|
32
33
|
"pkg-types": "^1.0.3",
|
|
33
34
|
"ufo": "^1.1.2",
|
|
34
|
-
"site-config-stack": "0.8.
|
|
35
|
+
"site-config-stack": "0.8.10"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"lint": "eslint . --fix",
|