@nuxtjs/prismic 5.2.0 → 5.2.1-canary.d380eb6

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/README.md CHANGED
@@ -27,18 +27,7 @@ Install the module to your Nuxt application with one command:
27
27
  npx nuxi@latest module add prismic
28
28
  ```
29
29
 
30
- Then, configure your Prismic API endpoint:
31
-
32
- ```javascript
33
- import { defineNuxtConfig } from "nuxt"
34
-
35
- export default defineNuxtConfig({
36
- modules: ["@nuxtjs/prismic"],
37
- prismic: {
38
- endpoint: "my-repository",
39
- },
40
- })
41
- ```
30
+ The module automatically loads your repository name and `routes` from `prismic.config.json`, so for most projects all you need to do is register the module (done by the `module add` command). If needed, you can still override those values and configure the Nuxt module further in `nuxt.config.ts` or Nuxt's `runtimeConfig`.
42
31
 
43
32
  That's it! You can now use Prismic in your Nuxt app ✨
44
33
 
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/prismic",
3
- "version": "5.2.0",
3
+ "version": "5.2.1-canary.d380eb6",
4
4
  "configKey": "prismic",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.7.0"
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
4
  import { useLogger, defineNuxtModule, createResolver, addPlugin, addComponent, addImports, extendPages, getNuxtVersion, addTemplate } from '@nuxt/kit';
@@ -7,9 +7,10 @@ import { addDependency } from 'nypm';
7
7
  import { readPackage } from 'pkg-types';
8
8
 
9
9
  const name = "@nuxtjs/prismic";
10
- const version = "5.2.0";
10
+ const version = "5.2.1-canary.d380eb6";
11
11
 
12
12
  const logger = useLogger("nuxt:prismic");
13
+ const PRISMIC_CONFIG_FILENAME = "prismic.config.json";
13
14
  async function addPrismicClient() {
14
15
  try {
15
16
  const pkg = await readPackage();
@@ -73,6 +74,21 @@ const module$1 = defineNuxtModule({
73
74
  nuxt.options.runtimeConfig.public?.prismic,
74
75
  options
75
76
  );
77
+ const prismicConfig = readPrismicConfig(
78
+ nuxt.options.rootDir
79
+ );
80
+ const configKeys = [];
81
+ if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
82
+ moduleOptions.endpoint = prismicConfig.repositoryName;
83
+ configKeys.push("repository name");
84
+ }
85
+ if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
86
+ moduleOptions.clientConfig.routes = prismicConfig.routes;
87
+ configKeys.push("routes");
88
+ }
89
+ if (configKeys.length > 0) {
90
+ logger.info(`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``);
91
+ }
76
92
  exposeRuntimeConfig();
77
93
  transpileDependencies();
78
94
  const ok = proxyUserFiles();
@@ -298,5 +314,28 @@ function fileExists(path, extensions = ["js", "ts"]) {
298
314
  );
299
315
  return extension ? `${path}.${extension}` : null;
300
316
  }
317
+ function readPrismicConfig(rootDir) {
318
+ const configPath = join(rootDir, PRISMIC_CONFIG_FILENAME);
319
+ if (!existsSync(configPath)) {
320
+ return {};
321
+ }
322
+ try {
323
+ const contents = readFileSync(configPath, "utf-8");
324
+ const rawConfig = JSON.parse(contents);
325
+ if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
326
+ return {};
327
+ }
328
+ const config = {};
329
+ if ("repositoryName" in rawConfig && typeof rawConfig.repositoryName === "string") {
330
+ config.repositoryName = rawConfig.repositoryName;
331
+ }
332
+ if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
333
+ config.routes = rawConfig.routes;
334
+ }
335
+ return config;
336
+ } catch {
337
+ return {};
338
+ }
339
+ }
301
340
 
302
341
  export { module$1 as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/prismic",
3
- "version": "5.2.0",
3
+ "version": "5.2.1-canary.d380eb6",
4
4
  "description": "Easily connect your Nuxt application to your content hosted on Prismic",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -52,30 +52,30 @@
52
52
  "test": "npm run lint && npm run types && npm run unit && npm run build"
53
53
  },
54
54
  "dependencies": {
55
- "@nuxt/kit": "^4.2.2",
56
- "@prismicio/vue": "^6.1.1",
57
- "defu": "^6.1.4",
58
- "nypm": "^0.6.2",
55
+ "@nuxt/kit": "^4.4.2",
56
+ "@prismicio/vue": "^6.1.3",
57
+ "defu": "^6.1.7",
58
+ "nypm": "^0.6.5",
59
59
  "pkg-types": "^2.3.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@nuxt/module-builder": "^1.0.2",
63
- "@nuxt/schema": "^4.2.2",
63
+ "@nuxt/schema": "^4.4.2",
64
64
  "@nuxt/test-utils": "^3.23.0",
65
- "@prismicio/client": "^7.21.3",
65
+ "@prismicio/client": "^7.21.8",
66
66
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
67
- "@types/node": "^25.0.9",
68
- "@vitest/coverage-v8": "^4.0.17",
69
- "nuxt": "^4.2.2",
70
- "oxlint": "^1.41.0",
71
- "prettier": "^3.8.0",
67
+ "@types/node": "^25.5.2",
68
+ "@vitest/coverage-v8": "^4.1.3",
69
+ "nuxt": "^4.4.2",
70
+ "oxlint": "^1.59.0",
71
+ "prettier": "^3.8.1",
72
72
  "prettier-plugin-jsdoc": "^1.8.0",
73
- "typescript": "^5.9.3",
74
- "vitest": "^4.0.17",
75
- "vue-tsc": "^3.2.2"
73
+ "typescript": "^6.0.2",
74
+ "vitest": "^4.1.3",
75
+ "vue-tsc": "^3.2.6"
76
76
  },
77
77
  "peerDependencies": {
78
- "@prismicio/client": "^7"
78
+ "@prismicio/client": "^7.21.8"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=20.0.0"
package/src/module.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync } from "node:fs"
1
+ import { existsSync, readFileSync } from "node:fs"
2
2
  import { readFile } from "node:fs/promises"
3
3
  import { join } from "node:path"
4
4
 
@@ -13,7 +13,7 @@ import {
13
13
  getNuxtVersion,
14
14
  useLogger,
15
15
  } from "@nuxt/kit"
16
- import type { ClientConfig } from "@prismicio/client"
16
+ import type { ClientConfig, Route } from "@prismicio/client"
17
17
  import { defu } from "defu"
18
18
  import { addDependency } from "nypm"
19
19
  import { readPackage } from "pkg-types"
@@ -148,6 +148,7 @@ declare module "@nuxt/schema" {
148
148
  }
149
149
 
150
150
  const logger = useLogger("nuxt:prismic")
151
+ const PRISMIC_CONFIG_FILENAME = "prismic.config.json"
151
152
 
152
153
  async function addPrismicClient() {
153
154
  try {
@@ -224,6 +225,24 @@ export default defineNuxtModule<PrismicModuleOptions>({
224
225
  options,
225
226
  )
226
227
 
228
+ const prismicConfig = readPrismicConfig(
229
+ nuxt.options.rootDir,
230
+ )
231
+
232
+ const configKeys: string[] = []
233
+ if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
234
+ moduleOptions.endpoint = prismicConfig.repositoryName
235
+ configKeys.push("repository name")
236
+ }
237
+ if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
238
+ moduleOptions.clientConfig!.routes = prismicConfig.routes
239
+ configKeys.push("routes")
240
+ }
241
+
242
+ if (configKeys.length > 0) {
243
+ logger.info(`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``)
244
+ }
245
+
227
246
  exposeRuntimeConfig()
228
247
  transpileDependencies()
229
248
  const ok = proxyUserFiles()
@@ -510,3 +529,40 @@ function fileExists(path?: string, extensions = ["js", "ts"]): string | null {
510
529
 
511
530
  return extension ? `${path}.${extension}` : null
512
531
  }
532
+
533
+ type PrismicConfig = {
534
+ repositoryName?: string
535
+ routes?: Route[]
536
+ }
537
+
538
+ function readPrismicConfig(
539
+ rootDir: string,
540
+ ): PrismicConfig {
541
+ const configPath = join(rootDir, PRISMIC_CONFIG_FILENAME)
542
+
543
+ if (!existsSync(configPath)) {
544
+ return {}
545
+ }
546
+
547
+ try {
548
+ const contents = readFileSync(configPath, "utf-8")
549
+ const rawConfig = JSON.parse(contents) as unknown
550
+
551
+ if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
552
+ return {}
553
+ }
554
+
555
+ const config: PrismicConfig = {}
556
+ if ("repositoryName" in rawConfig && typeof rawConfig.repositoryName === "string") {
557
+ config.repositoryName = rawConfig.repositoryName
558
+ }
559
+
560
+ if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
561
+ config.routes = rawConfig.routes
562
+ }
563
+
564
+ return config
565
+ } catch {
566
+ return {}
567
+ }
568
+ }