@wpnuxt/core 1.0.0-edge.17 → 1.0.0-edge.19

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.d.mts CHANGED
@@ -40,6 +40,9 @@ interface WPNuxtConfig {
40
40
  * @default true
41
41
  */
42
42
  downloadSchema?: boolean
43
+
44
+ hasBlocksModule?: boolean
45
+ hasAuthModule?: boolean
43
46
  }
44
47
 
45
48
  interface WPNuxtConfigQueries {
package/dist/module.d.ts CHANGED
@@ -40,6 +40,9 @@ interface WPNuxtConfig {
40
40
  * @default true
41
41
  */
42
42
  downloadSchema?: boolean
43
+
44
+ hasBlocksModule?: boolean
45
+ hasAuthModule?: boolean
43
46
  }
44
47
 
45
48
  interface WPNuxtConfigQueries {
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "1.0.0-edge.17",
3
+ "version": "1.0.0-edge.19",
4
4
  "configKey": "wpNuxt",
5
5
  "nuxt": ">=3.1.0",
6
6
  "builder": {
package/dist/module.mjs CHANGED
@@ -1,13 +1,13 @@
1
- import { promises, statSync, existsSync, cpSync } from 'node:fs';
2
- import { resolveFiles, defineNuxtModule, createResolver, addPlugin, addImports, addComponentsDir, addServerHandler, installModule, hasNuxtModule, addTemplate, addTypeTemplate } from '@nuxt/kit';
3
- import { join } from 'pathe';
1
+ import { createResolver, hasNuxtModule, addTemplate, resolveFiles, defineNuxtModule, addPlugin, addImports, addComponentsDir, addServerHandler, installModule, addTypeTemplate } from '@nuxt/kit';
4
2
  import consola, { createConsola } from 'consola';
3
+ import { promises, existsSync, cpSync, statSync } from 'node:fs';
5
4
  import { ref } from 'vue';
5
+ import { join } from 'pathe';
6
6
  import { upperFirst } from 'scule';
7
7
  import { parse } from 'graphql';
8
8
 
9
9
  const name = "@wpnuxt/core";
10
- const version = "1.0.0-edge.17";
10
+ const version = "1.0.0-edge.19";
11
11
 
12
12
  const loggerRef = ref();
13
13
  const initLogger = (logLevel) => {
@@ -37,6 +37,53 @@ function validateConfig(options) {
37
37
  throw new Error("WPNuxt error: frontend url should not have a trailing slash: " + options.frontendUrl);
38
38
  }
39
39
  }
40
+ async function mergeQueries(nuxt) {
41
+ const { resolve } = createResolver(import.meta.url);
42
+ const resolveRuntimeModule = (path) => resolve("./runtime", path);
43
+ const logger = getLogger();
44
+ const queryOutputPath = resolve((nuxt.options.srcDir || nuxt.options.rootDir) + "/.queries/");
45
+ await promises.rm(queryOutputPath, { recursive: true, force: true });
46
+ const userQueryPath = "~/extend/queries/".replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
47
+ const userQueryPathExists = existsSync(userQueryPath);
48
+ cpSync(resolveRuntimeModule("./queries/"), queryOutputPath, { recursive: true });
49
+ addQueriesFromAddOnModule("@wpnuxt/blocks", queryOutputPath, nuxt, resolve);
50
+ addQueriesFromAddOnModule("@wpnuxt/auth", queryOutputPath, nuxt, resolve);
51
+ if (userQueryPathExists) {
52
+ logger.debug("Extending queries:", userQueryPath);
53
+ cpSync(resolve(userQueryPath), queryOutputPath, { recursive: true });
54
+ }
55
+ logger.debug("Copied merged queries in folder:", queryOutputPath);
56
+ return queryOutputPath;
57
+ }
58
+ function addQueriesFromAddOnModule(addOnModuleName, queryOutputPath, nuxt, resolve) {
59
+ const logger = getLogger();
60
+ if (hasNuxtModule(addOnModuleName)) {
61
+ console.log("addOnModule found:", addOnModuleName);
62
+ for (const m of nuxt.options._installedModules) {
63
+ if (m.meta.name === addOnModuleName && m.entryPath) {
64
+ logger.debug("Loading queries from " + addOnModuleName);
65
+ let blocksQueriesPath;
66
+ if (m.entryPath == "../src/module") {
67
+ blocksQueriesPath = join(nuxt.options.rootDir, "../src/runtime/queries/");
68
+ } else if (m.entryPath.startsWith("../")) {
69
+ blocksQueriesPath = join(nuxt.options.rootDir, "../", m.entryPath, "./runtime/queries/");
70
+ } else {
71
+ blocksQueriesPath = join("./node_modules", m.entryPath, "dist/runtime/queries/");
72
+ }
73
+ console.log("blocksQueriesPath", blocksQueriesPath);
74
+ cpSync(blocksQueriesPath, queryOutputPath, { recursive: true });
75
+ }
76
+ }
77
+ } else {
78
+ const moduleName = addOnModuleName.replace("@", "");
79
+ addTemplate({
80
+ write: true,
81
+ filename: moduleName + ".mjs",
82
+ getContents: () => `export { }`
83
+ });
84
+ nuxt.options.alias["#" + moduleName] = resolve(nuxt.options.buildDir, moduleName);
85
+ }
86
+ }
40
87
 
41
88
  const _parseDoc = async (doc) => {
42
89
  const { definitions } = parse(doc);
@@ -148,7 +195,9 @@ const defaultConfigs = {
148
195
  enableCache: true,
149
196
  staging: false,
150
197
  logLevel: 3,
151
- composablesPrefix: "useWP"
198
+ composablesPrefix: "useWP",
199
+ hasBlocksModule: false,
200
+ hasAuthModule: false
152
201
  };
153
202
  const module = defineNuxtModule({
154
203
  meta: {
@@ -170,11 +219,14 @@ const module = defineNuxtModule({
170
219
  staging: process.env.WPNUXT_STAGING === "true" || options.staging,
171
220
  downloadSchema: process.env.WPNUXT_DOWNLOAD_SCHEMA === "true" || options.downloadSchema,
172
221
  logLevel: process.env.WPNUXT_LOG_LEVEL ? Number.parseInt(process.env.WPNUXT_LOG_LEVEL) : options.logLevel,
173
- composablesPrefix: process.env.WPNUXT_COMPOSABLES_PREFIX || options.composablesPrefix
222
+ composablesPrefix: process.env.WPNUXT_COMPOSABLES_PREFIX || options.composablesPrefix,
223
+ hasBlocksModule: hasNuxtModule("@wpnuxt/blocks"),
224
+ hasAuthModule: hasNuxtModule("@wpnuxt/auth")
174
225
  };
175
226
  nuxt.options.runtimeConfig.public.wpNuxt = publicWPNuxtConfig;
176
227
  validateConfig(publicWPNuxtConfig);
177
228
  const logger = initLogger(publicWPNuxtConfig.logLevel);
229
+ logger.info("config:", publicWPNuxtConfig);
178
230
  logger.info("Connecting GraphQL to", publicWPNuxtConfig.wordpressUrl);
179
231
  logger.info("frontendUrl:", publicWPNuxtConfig.frontendUrl);
180
232
  if (publicWPNuxtConfig.enableCache)
@@ -218,41 +270,13 @@ const module = defineNuxtModule({
218
270
  route: "/api/wpContent",
219
271
  handler: resolveRuntimeModule("./server/api/wpContent.post")
220
272
  });
273
+ addServerHandler({
274
+ route: "/api/config",
275
+ handler: resolveRuntimeModule("./server/api/config")
276
+ });
221
277
  await installModule("@vueuse/nuxt", {});
222
- const queryOutputPath = resolve((nuxt.options.srcDir || nuxt.options.rootDir) + "/.queries/");
223
- await promises.rm(queryOutputPath, { recursive: true, force: true });
224
- const userQueryPath = "~/extend/queries/".replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
225
- const userQueryPathExists = existsSync(userQueryPath);
226
- cpSync(resolveRuntimeModule("./queries/"), queryOutputPath, { recursive: true });
227
- if (hasNuxtModule("@wpnuxt/blocks")) {
228
- for (const m of nuxt.options._installedModules) {
229
- if (m.meta.name === "@wpnuxt/blocks" && m.entryPath) {
230
- logger.debug("Loading queries from @wpnuxt/blocks");
231
- let blocksQueriesPath;
232
- if (m.entryPath == "../src/module") {
233
- blocksQueriesPath = join(nuxt.options.rootDir, "../src/runtime/queries/");
234
- } else if (m.entryPath.startsWith("../")) {
235
- blocksQueriesPath = join(nuxt.options.rootDir, "../", m.entryPath, "./runtime/queries/");
236
- } else {
237
- blocksQueriesPath = join("./node_modules", m.entryPath, "dist/runtime/queries/");
238
- }
239
- cpSync(blocksQueriesPath, queryOutputPath, { recursive: true });
240
- }
241
- }
242
- } else {
243
- logger.debug("Tip: Install the @wpnuxt/blocks module if you want to render Gutenberg blocks with separate vue components");
244
- addTemplate({
245
- write: true,
246
- filename: "wpnuxt/blocks.mjs",
247
- getContents: () => `export { }`
248
- });
249
- nuxt.options.alias["#wpnuxt/blocks"] = resolve(nuxt.options.buildDir, "wpnuxt/blocks");
250
- }
251
- if (userQueryPathExists) {
252
- logger.debug("Extending queries:", userQueryPath);
253
- cpSync(resolve(userQueryPath), queryOutputPath, { recursive: true });
254
- }
255
- logger.debug("Copied merged queries in folder:", queryOutputPath);
278
+ const mergedQueriesFolder = await mergeQueries(nuxt);
279
+ console.log("mergedQueriesFolder", mergedQueriesFolder);
256
280
  await installModule("nuxt-graphql-middleware", {
257
281
  debug: publicWPNuxtConfig.logLevel ? publicWPNuxtConfig.logLevel > 3 : false,
258
282
  graphqlEndpoint: `${publicWPNuxtConfig.wordpressUrl}/graphql`,
@@ -283,7 +307,7 @@ const module = defineNuxtModule({
283
307
  }
284
308
  },
285
309
  outputDocuments: true,
286
- autoImportPatterns: queryOutputPath,
310
+ autoImportPatterns: mergedQueriesFolder,
287
311
  includeComposables: true,
288
312
  devtools: true
289
313
  });
@@ -315,7 +339,7 @@ const module = defineNuxtModule({
315
339
  fnImports: [],
316
340
  composablesPrefix: publicWPNuxtConfig.composablesPrefix
317
341
  };
318
- await generateWPNuxtComposables(ctx, queryOutputPath, srcResolver);
342
+ await generateWPNuxtComposables(ctx, mergedQueriesFolder, srcResolver);
319
343
  addTemplate({
320
344
  write: true,
321
345
  filename: "wpnuxt/index.mjs",
@@ -9,7 +9,7 @@ const _useWPContent = async (operation, queryName, nodes, fixImagePaths, params)
9
9
  }
10
10
  });
11
11
  return {
12
- data: error ? void 0 : transformData(data, nodes, fixImagePaths),
12
+ data: data ? transformData(data, nodes, fixImagePaths) : void 0,
13
13
  error
14
14
  };
15
15
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ export default defineEventHandler(async (event) => {
2
+ const config = useRuntimeConfig(event);
3
+ console.log("config", config);
4
+ return {
5
+ wpNuxt: config.public.wpNuxt
6
+ };
7
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "1.0.0-edge.17",
3
+ "version": "1.0.0-edge.19",
4
4
  "description": "WPNuxt",
5
5
  "repository": {
6
6
  "type": "git",
@@ -66,12 +66,12 @@
66
66
  "@graphql-codegen/client-preset": "^4.3.3",
67
67
  "@graphql-codegen/typescript-operations": "^4.2.3",
68
68
  "@nuxt/devtools": "^1.4.1",
69
- "@nuxt/eslint-config": "^0.5.3",
69
+ "@nuxt/eslint-config": "^0.5.4",
70
70
  "@nuxt/module-builder": "^0.8.3",
71
71
  "@nuxt/schema": "3.13.0",
72
72
  "@nuxt/test-utils": "^3.14.1",
73
- "@rollup/rollup-linux-arm64-gnu": "^4.21.1",
74
- "@rollup/rollup-linux-arm64-musl": "^4.21.1",
73
+ "@rollup/rollup-linux-arm64-gnu": "^4.21.2",
74
+ "@rollup/rollup-linux-arm64-musl": "^4.21.2",
75
75
  "@types/node": "22.5.1",
76
76
  "@vitest/coverage-v8": "^2.0.5",
77
77
  "@vue/test-utils": "^2.4.6",
@@ -81,14 +81,14 @@
81
81
  "nuxt": "^3.13.0",
82
82
  "nuxt-content-twoslash": "^0.1.1",
83
83
  "release-it": "^17.6.0",
84
- "shiki": "^1.13.0",
84
+ "shiki": "^1.15.0",
85
85
  "twoslash": "^0.2.9",
86
86
  "typescript": "^5.5.4",
87
87
  "untyped": "1.4.2",
88
88
  "vite": "^5.4.2",
89
89
  "vitest": "^2.0.5",
90
90
  "vue-docgen-web-types": "^0.1.8",
91
- "vue-tsc": "2.1.0"
91
+ "vue-tsc": "2.1.2"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "consola": "^3.2.3",