@wpnuxt/core 2.0.0-alpha.13 → 2.0.0-alpha.15
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/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { consola } from 'consola';
|
|
1
2
|
import { defu } from 'defu';
|
|
2
3
|
import { promises, cpSync, existsSync, readdirSync, statSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import { writeFile, rename, readFile, mkdir } from 'node:fs/promises';
|
|
@@ -7,9 +8,8 @@ import { upperFirst } from 'scule';
|
|
|
7
8
|
import { ref } from 'vue';
|
|
8
9
|
import { parse, GraphQLError } from 'graphql';
|
|
9
10
|
import { execSync } from 'node:child_process';
|
|
10
|
-
import { consola } from 'consola';
|
|
11
11
|
|
|
12
|
-
const version = "2.0.0-alpha.
|
|
12
|
+
const version = "2.0.0-alpha.15";
|
|
13
13
|
|
|
14
14
|
function createModuleError(module, message) {
|
|
15
15
|
return new Error(formatErrorMessage(module, message));
|
|
@@ -807,7 +807,7 @@ const module$1 = defineNuxtModule({
|
|
|
807
807
|
},
|
|
808
808
|
async setup(options, nuxt) {
|
|
809
809
|
const startTime = (/* @__PURE__ */ new Date()).getTime();
|
|
810
|
-
const wpNuxtConfig = loadConfig(options, nuxt);
|
|
810
|
+
const wpNuxtConfig = await loadConfig(options, nuxt);
|
|
811
811
|
if (!wpNuxtConfig) {
|
|
812
812
|
const logger2 = initLogger(false);
|
|
813
813
|
logger2.warn("WordPress URL not configured. Skipping WPNuxt setup. Set it in nuxt.config.ts or via WPNUXT_WORDPRESS_URL environment variable.");
|
|
@@ -819,6 +819,7 @@ const module$1 = defineNuxtModule({
|
|
|
819
819
|
nuxt.options.runtimeConfig.public.buildHash = randHashGenerator();
|
|
820
820
|
addPlugin(resolver.resolve("./runtime/plugins/graphqlConfig"));
|
|
821
821
|
addPlugin(resolver.resolve("./runtime/plugins/graphqlErrors"));
|
|
822
|
+
addPlugin(resolver.resolve("./runtime/plugins/sanitizeHtml"));
|
|
822
823
|
configureTrailingSlash(nuxt, logger);
|
|
823
824
|
const mergedQueriesFolder = await mergeQueries(nuxt, wpNuxtConfig, resolver);
|
|
824
825
|
await setupServerOptions(nuxt, resolver, logger);
|
|
@@ -950,7 +951,7 @@ const module$1 = defineNuxtModule({
|
|
|
950
951
|
await runInstall(nuxt);
|
|
951
952
|
}
|
|
952
953
|
});
|
|
953
|
-
function loadConfig(options, nuxt) {
|
|
954
|
+
async function loadConfig(options, nuxt) {
|
|
954
955
|
const config = defu({
|
|
955
956
|
wordpressUrl: process.env.WPNUXT_WORDPRESS_URL,
|
|
956
957
|
graphqlEndpoint: process.env.WPNUXT_GRAPHQL_ENDPOINT,
|
|
@@ -962,6 +963,42 @@ function loadConfig(options, nuxt) {
|
|
|
962
963
|
if (config.downloadSchema === void 0) {
|
|
963
964
|
config.downloadSchema = true;
|
|
964
965
|
}
|
|
966
|
+
if (!config.wordpressUrl?.trim()) {
|
|
967
|
+
if (nuxt.options._prepare) {
|
|
968
|
+
return null;
|
|
969
|
+
}
|
|
970
|
+
if (nuxt.options.dev && process.stdout.isTTY) {
|
|
971
|
+
const wordpressUrl = await consola.prompt(
|
|
972
|
+
"Enter your WordPress site URL (must have WPGraphQL installed):",
|
|
973
|
+
{ type: "text", placeholder: "https://your-wordpress-site.com" }
|
|
974
|
+
);
|
|
975
|
+
if (wordpressUrl && typeof wordpressUrl === "string" && wordpressUrl.trim()) {
|
|
976
|
+
const validation = validateWordPressUrl(wordpressUrl);
|
|
977
|
+
if (validation.valid && validation.normalizedUrl) {
|
|
978
|
+
config.wordpressUrl = validation.normalizedUrl;
|
|
979
|
+
const envPath = join(nuxt.options.rootDir, ".env");
|
|
980
|
+
const envLine = `WPNUXT_WORDPRESS_URL=${validation.normalizedUrl}
|
|
981
|
+
`;
|
|
982
|
+
if (existsSync(envPath)) {
|
|
983
|
+
const existing = await readFile(envPath, "utf-8");
|
|
984
|
+
await atomicWriteFile(envPath, existing.trimEnd() + "\n" + envLine);
|
|
985
|
+
} else {
|
|
986
|
+
await atomicWriteFile(envPath, envLine);
|
|
987
|
+
}
|
|
988
|
+
consola.success(`WordPress URL saved to .env: ${validation.normalizedUrl}`);
|
|
989
|
+
} else {
|
|
990
|
+
throw createModuleError("core", `Invalid WordPress URL: ${validation.error}`);
|
|
991
|
+
}
|
|
992
|
+
} else {
|
|
993
|
+
throw createModuleError("core", "WordPress URL is required. Set it in nuxt.config.ts or via WPNUXT_WORDPRESS_URL environment variable.");
|
|
994
|
+
}
|
|
995
|
+
} else {
|
|
996
|
+
throw createModuleError("core", "WordPress URL is required. Set it in nuxt.config.ts or via WPNUXT_WORDPRESS_URL environment variable.");
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
if (config.wordpressUrl.endsWith("/")) {
|
|
1000
|
+
throw createModuleError("core", `WordPress URL should not have a trailing slash: ${config.wordpressUrl}`);
|
|
1001
|
+
}
|
|
965
1002
|
nuxt.options.runtimeConfig.public.wordpressUrl = config.wordpressUrl;
|
|
966
1003
|
nuxt.options.runtimeConfig.public.wpNuxt = {
|
|
967
1004
|
wordpressUrl: config.wordpressUrl,
|
|
@@ -975,15 +1012,6 @@ function loadConfig(options, nuxt) {
|
|
|
975
1012
|
swr: config.cache?.swr ?? true
|
|
976
1013
|
}
|
|
977
1014
|
};
|
|
978
|
-
if (!config.wordpressUrl?.trim()) {
|
|
979
|
-
if (nuxt.options._prepare) {
|
|
980
|
-
return null;
|
|
981
|
-
}
|
|
982
|
-
throw createModuleError("core", "WordPress URL is required. Set it in nuxt.config.ts or via WPNUXT_WORDPRESS_URL environment variable.");
|
|
983
|
-
}
|
|
984
|
-
if (config.wordpressUrl.endsWith("/")) {
|
|
985
|
-
throw createModuleError("core", `WordPress URL should not have a trailing slash: ${config.wordpressUrl}`);
|
|
986
|
-
}
|
|
987
1015
|
return config;
|
|
988
1016
|
}
|
|
989
1017
|
const SERVER_OPTIONS_TEMPLATE = `import { defineGraphqlServerOptions } from '@wpnuxt/core/server-options'
|
|
@@ -1193,7 +1221,6 @@ async function registerModules(nuxt, resolver, wpNuxtConfig, mergedQueriesFolder
|
|
|
1193
1221
|
improvedQueryParamEncoding: true
|
|
1194
1222
|
}
|
|
1195
1223
|
});
|
|
1196
|
-
await registerModule("@radya/nuxt-dompurify", "dompurify", {});
|
|
1197
1224
|
}
|
|
1198
1225
|
|
|
1199
1226
|
export { module$1 as default };
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from "#imports";
|
|
2
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
3
|
+
let sanitize;
|
|
4
|
+
if (import.meta.server) {
|
|
5
|
+
sanitize = (html) => html;
|
|
6
|
+
} else {
|
|
7
|
+
let purify = null;
|
|
8
|
+
sanitize = (html) => {
|
|
9
|
+
if (purify) {
|
|
10
|
+
return purify.sanitize(html);
|
|
11
|
+
}
|
|
12
|
+
return html;
|
|
13
|
+
};
|
|
14
|
+
import("dompurify").then((DOMPurify) => {
|
|
15
|
+
purify = DOMPurify.default(window);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
nuxtApp.vueApp.directive("sanitize-html", {
|
|
19
|
+
created(el, binding) {
|
|
20
|
+
el.innerHTML = sanitize(binding.value);
|
|
21
|
+
},
|
|
22
|
+
updated(el, binding) {
|
|
23
|
+
el.innerHTML = sanitize(binding.value);
|
|
24
|
+
},
|
|
25
|
+
getSSRProps(binding) {
|
|
26
|
+
return { innerHTML: sanitize(binding.value) };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wpnuxt/core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.15",
|
|
4
4
|
"description": "Nuxt module for WordPress integration via GraphQL (WPGraphQL)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@nuxt/kit": "4.3.1",
|
|
47
|
-
"
|
|
47
|
+
"dompurify": "^3.1.7",
|
|
48
48
|
"consola": "^3.4.0",
|
|
49
49
|
"defu": "^6.1.4",
|
|
50
50
|
"graphql": "^16.12.0",
|