@nuxtjs/prismic 5.3.0 → 5.3.1-canary.29138d8

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,9 +27,13 @@ Install the module to your Nuxt application with one command:
27
27
  npx nuxi@latest module add prismic
28
28
  ```
29
29
 
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`.
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`.
31
31
 
32
- That's it! You can now use Prismic in your Nuxt app ✨
32
+ Using an AI agent? Teach it how to use `@nuxtjs/prismic` by installing the Prismic skill:
33
+
34
+ ```bash
35
+ npx skills add --global --yes prismicio/skills
36
+ ```
33
37
 
34
38
  ## Documentation
35
39
 
@@ -55,6 +59,7 @@ For more clarity on this project and its structure you can also check out the de
55
59
 
56
60
  <!-- Links -->
57
61
 
62
+ [nuxt]: https://nuxt.com
58
63
  [prismic]: https://prismic.io
59
64
 
60
65
  <!-- Replace link with a more useful one if available -->
package/dist/module.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nuxtjs/prismic",
3
- "version": "5.3.0",
3
+ "version": "5.3.1-canary.29138d8",
4
4
  "configKey": "prismic",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.7.0"
7
7
  },
8
8
  "builder": {
9
- "@nuxt/module-builder": "1.0.2",
10
- "unbuild": "3.6.1"
9
+ "@nuxt/module-builder": "1.0.3",
10
+ "unbuild": "unknown"
11
11
  }
12
12
  }
package/dist/module.mjs CHANGED
@@ -7,7 +7,7 @@ import { addDependency } from 'nypm';
7
7
  import { readPackage } from 'pkg-types';
8
8
 
9
9
  const name = "@nuxtjs/prismic";
10
- const version = "5.3.0";
10
+ const version = "5.3.1-canary.29138d8";
11
11
 
12
12
  const logger = useLogger("nuxt:prismic");
13
13
  const PRISMIC_CONFIG_FILENAME = "prismic.config.json";
@@ -84,7 +84,10 @@ const module$1 = defineNuxtModule({
84
84
  addPreviewRoute();
85
85
  extendESLintConfig();
86
86
  function loadPrismicConfig() {
87
- const prismicConfigPath = join(nuxt.options.rootDir, PRISMIC_CONFIG_FILENAME);
87
+ const prismicConfigPath = join(
88
+ nuxt.options.rootDir,
89
+ PRISMIC_CONFIG_FILENAME
90
+ );
88
91
  const prismicConfig = readPrismicConfig(prismicConfigPath);
89
92
  const configKeys = [];
90
93
  if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
@@ -103,7 +106,9 @@ const module$1 = defineNuxtModule({
103
106
  await nuxt.callHook("restart");
104
107
  }
105
108
  });
106
- logger.info(`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``);
109
+ logger.info(
110
+ `Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``
111
+ );
107
112
  }
108
113
  }
109
114
  function exposeRuntimeConfig() {
@@ -288,7 +293,9 @@ const module$1 = defineNuxtModule({
288
293
  const configs = [];
289
294
  try {
290
295
  if (existsSync(configPath)) {
291
- const config = JSON.parse(await readFile(configPath, "utf-8"));
296
+ const config = JSON.parse(
297
+ await readFile(configPath, "utf-8")
298
+ );
292
299
  if (config && "libraries" in config && Array.isArray(config.libraries)) {
293
300
  configs.push(
294
301
  JSON.stringify({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/prismic",
3
- "version": "5.3.0",
3
+ "version": "5.3.1-canary.29138d8",
4
4
  "description": "Easily connect your Nuxt application to your content hosted on Prismic",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -52,27 +52,26 @@
52
52
  "test": "npm run lint && npm run types && npm run unit && npm run build"
53
53
  },
54
54
  "dependencies": {
55
- "@nuxt/kit": "^4.4.4",
56
- "@prismicio/vue": "^6.1.3",
55
+ "@nuxt/kit": "^4.5.2",
56
+ "@prismicio/vue": "^6.1.4",
57
57
  "defu": "^6.1.7",
58
- "nypm": "^0.6.6",
58
+ "nypm": "^0.6.9",
59
59
  "pkg-types": "^2.3.1"
60
60
  },
61
61
  "devDependencies": {
62
- "@nuxt/module-builder": "^1.0.2",
63
- "@nuxt/schema": "^4.4.4",
62
+ "@nuxt/module-builder": "^1.0.3",
63
+ "@nuxt/schema": "^4.5.2",
64
64
  "@nuxt/test-utils": "^3.23.0",
65
- "@prismicio/client": "^7.21.8",
65
+ "@prismicio/client": "^7.22.0",
66
66
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
67
- "@types/node": "^25.6.0",
68
- "@vitest/coverage-v8": "^4.1.5",
69
- "nuxt": "^4.4.4",
70
- "oxlint": "^1.62.0",
71
- "prettier": "^3.8.3",
72
- "prettier-plugin-jsdoc": "^1.8.0",
67
+ "@types/node": "^26.4.0",
68
+ "@vitest/coverage-v8": "^4.1.11",
69
+ "nuxt": "^4.5.2",
70
+ "oxfmt": "^0.65.0",
71
+ "oxlint": "^1.80.0",
73
72
  "typescript": "^6.0.3",
74
- "vitest": "^4.1.5",
75
- "vue-tsc": "^3.2.7"
73
+ "vitest": "^4.1.11",
74
+ "vue-tsc": "^3.3.11"
76
75
  },
77
76
  "peerDependencies": {
78
77
  "@prismicio/client": "^7.21.8"
@@ -83,5 +82,5 @@
83
82
  "publishConfig": {
84
83
  "access": "public"
85
84
  },
86
- "packageManager": "pnpm@10.28.0"
85
+ "packageManager": "pnpm@11.24.0"
87
86
  }
package/src/module.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { existsSync, readFileSync } from "node:fs"
2
- import { readFile } from "node:fs/promises"
3
- import { join } from "node:path"
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
4
 
5
5
  import {
6
6
  addComponent,
@@ -12,13 +12,13 @@ import {
12
12
  extendPages,
13
13
  getNuxtVersion,
14
14
  useLogger,
15
- } from "@nuxt/kit"
16
- import type { ClientConfig, Route } from "@prismicio/client"
17
- import { defu } from "defu"
18
- import { addDependency } from "nypm"
19
- import { readPackage } from "pkg-types"
15
+ } from "@nuxt/kit";
16
+ import type { ClientConfig, Route } from "@prismicio/client";
17
+ import { defu } from "defu";
18
+ import { addDependency } from "nypm";
19
+ import { readPackage } from "pkg-types";
20
20
 
21
- import { name, version } from "../package.json"
21
+ import { name, version } from "../package.json";
22
22
 
23
23
  /**
24
24
  * Prismic Nuxt module options.
@@ -44,7 +44,7 @@ export type PrismicModuleOptions = {
44
44
  *
45
45
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
46
46
  */
47
- endpoint?: string
47
+ endpoint?: string;
48
48
 
49
49
  /**
50
50
  * The Prismic environment in use by Slice Machine configured through
@@ -54,7 +54,7 @@ export type PrismicModuleOptions = {
54
54
  *
55
55
  * @internal
56
56
  */
57
- environment?: string
57
+ environment?: string;
58
58
 
59
59
  /**
60
60
  * Configuration options that determines how content will be queries from the
@@ -62,7 +62,7 @@ export type PrismicModuleOptions = {
62
62
  *
63
63
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
64
64
  */
65
- clientConfig?: ClientConfig
65
+ clientConfig?: ClientConfig;
66
66
 
67
67
  /**
68
68
  * An optional path to a file exporting a Prismic client instance used to
@@ -74,7 +74,7 @@ export type PrismicModuleOptions = {
74
74
  *
75
75
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
76
76
  */
77
- client?: string
77
+ client?: string;
78
78
 
79
79
  /**
80
80
  * The path to a file exporting a default link resolver used to resolve links
@@ -82,7 +82,7 @@ export type PrismicModuleOptions = {
82
82
  *
83
83
  * @see {@link https://prismic.io/docs/routes}
84
84
  */
85
- linkResolver?: string
85
+ linkResolver?: string;
86
86
 
87
87
  /**
88
88
  * Desired path of the preview page used by Prismic to enter preview session.
@@ -92,7 +92,7 @@ export type PrismicModuleOptions = {
92
92
  *
93
93
  * @defaultValue `"/preview"`
94
94
  */
95
- preview?: string | false
95
+ preview?: string | false;
96
96
 
97
97
  /**
98
98
  * Whether to inject Prismic toolbar script.
@@ -102,7 +102,7 @@ export type PrismicModuleOptions = {
102
102
  *
103
103
  * @defaultValue `true`
104
104
  */
105
- toolbar?: boolean
105
+ toolbar?: boolean;
106
106
 
107
107
  /**
108
108
  * Controls which auto-imports are added by the module.
@@ -117,7 +117,7 @@ export type PrismicModuleOptions = {
117
117
  *
118
118
  * @experimental
119
119
  */
120
- imports?: false | "all" | ("vue" | "javascript" | "content")[]
120
+ imports?: false | "all" | ("vue" | "javascript" | "content")[];
121
121
 
122
122
  /** Options used by Prismic Vue components. */
123
123
  components?: {
@@ -128,9 +128,9 @@ export type PrismicModuleOptions = {
128
128
  * @see {@link https://prismic.io/docs/fields/rich-text}
129
129
  * @see {@link https://prismic.io/docs/fields/table}
130
130
  */
131
- richTextComponents?: string
132
- }
133
- }
131
+ richTextComponents?: string;
132
+ };
133
+ };
134
134
 
135
135
  /**
136
136
  * Prismic Nuxt module options.
@@ -138,28 +138,28 @@ export type PrismicModuleOptions = {
138
138
  * @see {@link https://prismic.io/docs/nuxt}
139
139
  * @see {@link https://prismic.io/docs/technical-reference/nuxtjs-prismic}
140
140
  */
141
- export type ModuleOptions = PrismicModuleOptions
141
+ export type ModuleOptions = PrismicModuleOptions;
142
142
 
143
143
  declare module "@nuxt/schema" {
144
144
  interface PublicRuntimeConfig {
145
145
  /** The Prismic Nuxt module options. */
146
- prismic: PrismicModuleOptions
146
+ prismic: PrismicModuleOptions;
147
147
  }
148
148
  }
149
149
 
150
- const logger = useLogger("nuxt:prismic")
151
- const PRISMIC_CONFIG_FILENAME = "prismic.config.json"
150
+ const logger = useLogger("nuxt:prismic");
151
+ const PRISMIC_CONFIG_FILENAME = "prismic.config.json";
152
152
 
153
153
  async function addPrismicClient() {
154
154
  try {
155
- const pkg = await readPackage()
155
+ const pkg = await readPackage();
156
156
 
157
157
  if (
158
158
  !pkg.dependencies?.["@prismicio/client"] &&
159
159
  !pkg.devDependencies?.["@prismicio/client"]
160
160
  ) {
161
- await addDependency("@prismicio/client")
162
- logger.info("Added `@prismicio/client` required peer dependency")
161
+ await addDependency("@prismicio/client");
162
+ logger.info("Added `@prismicio/client` required peer dependency");
163
163
  }
164
164
  } catch {
165
165
  // noop
@@ -174,18 +174,18 @@ export default defineNuxtModule<PrismicModuleOptions>({
174
174
  compatibility: { nuxt: ">=3.7.0" },
175
175
  },
176
176
  onInstall() {
177
- return addPrismicClient()
177
+ return addPrismicClient();
178
178
  },
179
179
  onUpgrade(_options: unknown, _nuxt: unknown, previousVersion: string) {
180
- const previousMajor = parseInt(previousVersion.split(".")[0]!)
180
+ const previousMajor = parseInt(previousVersion.split(".")[0]!);
181
181
  if (previousMajor < 4) {
182
- return addPrismicClient()
182
+ return addPrismicClient();
183
183
  }
184
184
  },
185
185
  defaults: (nuxt): Required<PrismicModuleOptions> => {
186
186
  const nuxt3flavor =
187
187
  getNuxtVersion(nuxt).startsWith("3") &&
188
- !nuxt.options?.future?.compatibilityVersion
188
+ !nuxt.options?.future?.compatibilityVersion;
189
189
 
190
190
  if (nuxt3flavor) {
191
191
  return {
@@ -200,7 +200,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
200
200
  components: {
201
201
  richTextComponents: "~/app/prismic/richTextComponents ",
202
202
  },
203
- }
203
+ };
204
204
  }
205
205
 
206
206
  return {
@@ -215,57 +215,65 @@ export default defineNuxtModule<PrismicModuleOptions>({
215
215
  components: {
216
216
  richTextComponents: "~/prismic/richTextComponents",
217
217
  },
218
- }
218
+ };
219
219
  },
220
220
  setup(options, nuxt) {
221
- const resolver = createResolver(import.meta.url)
221
+ const resolver = createResolver(import.meta.url);
222
222
 
223
223
  const moduleOptions: PrismicModuleOptions = defu(
224
224
  nuxt.options.runtimeConfig.public?.prismic as PrismicModuleOptions,
225
225
  options,
226
- )
227
-
228
- loadPrismicConfig()
229
- exposeRuntimeConfig()
230
- transpileDependencies()
231
- const ok = proxyUserFiles()
232
- if (!ok) return
233
- addRuntimePlugins()
234
- addAutoImports()
235
- addPreviewRoute()
236
- extendESLintConfig()
226
+ );
227
+
228
+ loadPrismicConfig();
229
+ exposeRuntimeConfig();
230
+ transpileDependencies();
231
+ const ok = proxyUserFiles();
232
+ if (!ok) return;
233
+ addRuntimePlugins();
234
+ addAutoImports();
235
+ addPreviewRoute();
236
+ extendESLintConfig();
237
237
 
238
238
  function loadPrismicConfig() {
239
- const prismicConfigPath = join(nuxt.options.rootDir, PRISMIC_CONFIG_FILENAME)
240
- const prismicConfig = readPrismicConfig(prismicConfigPath)
239
+ const prismicConfigPath = join(
240
+ nuxt.options.rootDir,
241
+ PRISMIC_CONFIG_FILENAME,
242
+ );
243
+ const prismicConfig = readPrismicConfig(prismicConfigPath);
241
244
 
242
- const configKeys: string[] = []
245
+ const configKeys: string[] = [];
243
246
  if (!moduleOptions.endpoint && prismicConfig.repositoryName) {
244
- moduleOptions.endpoint = prismicConfig.repositoryName
245
- configKeys.push("repository name")
247
+ moduleOptions.endpoint = prismicConfig.repositoryName;
248
+ configKeys.push("repository name");
246
249
  }
247
250
  if (!moduleOptions.clientConfig?.routes && prismicConfig.routes) {
248
- moduleOptions.clientConfig!.routes = prismicConfig.routes
249
- configKeys.push("routes")
251
+ moduleOptions.clientConfig!.routes = prismicConfig.routes;
252
+ configKeys.push("routes");
250
253
  }
251
254
 
252
255
  if (configKeys.length > 0) {
253
- nuxt.options.watch.push(prismicConfigPath)
256
+ nuxt.options.watch.push(prismicConfigPath);
254
257
  nuxt.hook("builder:watch", async (_, path) => {
255
- if (path.replace(/\\/g, "/") === prismicConfigPath.replace(/\\/g, "/")) {
256
- logger.info(`${PRISMIC_CONFIG_FILENAME} updated`)
257
- await nuxt.callHook("restart")
258
+ if (
259
+ path.replace(/\\/g, "/") === prismicConfigPath.replace(/\\/g, "/")
260
+ ) {
261
+ logger.info(`${PRISMIC_CONFIG_FILENAME} updated`);
262
+ await nuxt.callHook("restart");
258
263
  }
259
- })
264
+ });
260
265
 
261
- logger.info(`Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``)
266
+ logger.info(
267
+ `Loaded ${configKeys.join(" and ")} from \`${PRISMIC_CONFIG_FILENAME}\``,
268
+ );
262
269
  }
263
270
  }
264
271
 
265
272
  function exposeRuntimeConfig() {
266
273
  nuxt.options.runtimeConfig.public ||=
267
- {} as typeof nuxt.options.runtimeConfig.public
268
- (nuxt.options.runtimeConfig.public.prismic as PrismicModuleOptions) = moduleOptions
274
+ {} as typeof nuxt.options.runtimeConfig.public;
275
+ (nuxt.options.runtimeConfig.public.prismic as PrismicModuleOptions) =
276
+ moduleOptions;
269
277
  }
270
278
 
271
279
  function transpileDependencies() {
@@ -273,10 +281,10 @@ export default defineNuxtModule<PrismicModuleOptions>({
273
281
  resolver.resolve("runtime"),
274
282
  "@nuxtjs/prismic",
275
283
  "@prismicio/vue",
276
- )
277
- nuxt.options.vite.optimizeDeps ||= {}
278
- nuxt.options.vite.optimizeDeps.exclude ||= []
279
- nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue")
284
+ );
285
+ nuxt.options.vite.optimizeDeps ||= {};
286
+ nuxt.options.vite.optimizeDeps.exclude ||= [];
287
+ nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue");
280
288
  }
281
289
 
282
290
  function proxyUserFiles() {
@@ -284,44 +292,44 @@ export default defineNuxtModule<PrismicModuleOptions>({
284
292
  filename: string,
285
293
  path: string,
286
294
  ): boolean => {
287
- const resolvedFilename = `prismic/proxy/${filename}.ts`
295
+ const resolvedFilename = `prismic/proxy/${filename}.ts`;
288
296
  const resolvedPath = path
289
297
  .replace(/^(~~|@@)/, nuxt.options.rootDir)
290
- .replace(/^(~|@)/, nuxt.options.srcDir)
298
+ .replace(/^(~|@)/, nuxt.options.srcDir);
291
299
  const maybeUserFile = fileExists(resolvedPath, [
292
300
  "js",
293
301
  "mjs",
294
302
  "ts",
295
303
  "vue",
296
- ])
304
+ ]);
297
305
 
298
306
  if (maybeUserFile) {
299
307
  // If user file exists, proxy it with vfs
300
308
  logger.info(
301
309
  `Using user-defined \`${filename}\` at \`${maybeUserFile.replace(nuxt.options.srcDir, "~").replace(nuxt.options.rootDir, "~~").replace(/\\/g, "/")}\``,
302
- )
310
+ );
303
311
 
304
312
  addTemplate({
305
313
  filename: resolvedFilename,
306
314
  getContents: () => `export { default } from '${path}'`,
307
- })
315
+ });
308
316
 
309
- return true
317
+ return true;
310
318
  } else {
311
319
  // Else provide `undefined` fallback
312
320
  addTemplate({
313
321
  filename: resolvedFilename,
314
322
  getContents: () => "export default undefined",
315
- })
323
+ });
316
324
 
317
- return false
325
+ return false;
318
326
  }
319
- }
327
+ };
320
328
 
321
329
  const proxiedUserClient = proxyUserFileWithUndefinedFallback(
322
330
  "client",
323
331
  moduleOptions.client!,
324
- )
332
+ );
325
333
  if (
326
334
  !moduleOptions.endpoint &&
327
335
  !proxiedUserClient &&
@@ -329,34 +337,34 @@ export default defineNuxtModule<PrismicModuleOptions>({
329
337
  ) {
330
338
  logger.warn(
331
339
  `\`endpoint\` option is missing and \`${moduleOptions.client}\` was not found. At least one of them is required for the module to run. Disabling module...`,
332
- )
333
- return false
340
+ );
341
+ return false;
334
342
  }
335
343
  proxyUserFileWithUndefinedFallback(
336
344
  "linkResolver",
337
345
  moduleOptions.linkResolver!,
338
- )
346
+ );
339
347
  proxyUserFileWithUndefinedFallback(
340
348
  "richTextComponents",
341
349
  moduleOptions.components!.richTextComponents!,
342
- )
350
+ );
343
351
 
344
- return true
352
+ return true;
345
353
  }
346
354
 
347
355
  function addRuntimePlugins() {
348
- addPlugin(resolver.resolve("runtime/plugin"))
349
- addPlugin(resolver.resolve("runtime/plugin.client"))
356
+ addPlugin(resolver.resolve("runtime/plugin"));
357
+ addPlugin(resolver.resolve("runtime/plugin.client"));
350
358
  }
351
359
 
352
360
  function addAutoImports() {
353
- if (!moduleOptions.imports) return
361
+ if (!moduleOptions.imports) return;
354
362
 
355
363
  if (
356
364
  moduleOptions.imports === "all" ||
357
365
  moduleOptions.imports.includes("vue")
358
366
  ) {
359
- ;[
367
+ [
360
368
  "PrismicImage",
361
369
  "PrismicLink",
362
370
  "PrismicText",
@@ -369,8 +377,8 @@ export default defineNuxtModule<PrismicModuleOptions>({
369
377
  name: entry,
370
378
  export: entry,
371
379
  filePath: "@prismicio/vue",
372
- })
373
- })
380
+ });
381
+ });
374
382
 
375
383
  addImports(
376
384
  [
@@ -384,12 +392,12 @@ export default defineNuxtModule<PrismicModuleOptions>({
384
392
  as: entry,
385
393
  from: "@prismicio/vue",
386
394
  })),
387
- )
395
+ );
388
396
  addImports({
389
397
  name: "usePrismicPreview",
390
398
  as: "usePrismicPreview",
391
399
  from: resolver.resolve("runtime/usePrismicPreview"),
392
- })
400
+ });
393
401
  }
394
402
 
395
403
  if (
@@ -412,7 +420,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
412
420
  as: entry,
413
421
  from: "@prismicio/client",
414
422
  })),
415
- )
423
+ );
416
424
  }
417
425
 
418
426
  if (
@@ -424,7 +432,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
424
432
  from: "@prismicio/client",
425
433
  typeFrom: "@prismicio/client",
426
434
  type: true,
427
- })
435
+ });
428
436
  }
429
437
  }
430
438
 
@@ -437,7 +445,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
437
445
  moduleOptions.preview,
438
446
  ),
439
447
  ["js", "ts", "vue"],
440
- )
448
+ );
441
449
 
442
450
  if (maybeUserPreviewPage) {
443
451
  logger.info(
@@ -448,25 +456,25 @@ export default defineNuxtModule<PrismicModuleOptions>({
448
456
  /\\/g,
449
457
  "/",
450
458
  )}\`, available at \`${moduleOptions.preview}\``,
451
- )
459
+ );
452
460
  } else {
453
461
  logger.info(
454
462
  `Using default preview page, available at \`${moduleOptions.preview}\``,
455
- )
463
+ );
456
464
 
457
465
  extendPages((pages) => {
458
466
  pages.unshift({
459
467
  name: "prismic-preview",
460
468
  path: moduleOptions.preview as string, // Checked before
461
469
  file: resolver.resolve("runtime/PrismicPreview.vue"),
462
- })
463
- })
470
+ });
471
+ });
464
472
  }
465
473
 
466
474
  if (!moduleOptions.toolbar) {
467
475
  logger.warn(
468
476
  "`toolbar` option is disabled but `preview` is enabled. Previews won't work unless you manually load the toolbar.",
469
- )
477
+ );
470
478
  }
471
479
  }
472
480
  }
@@ -477,8 +485,8 @@ export default defineNuxtModule<PrismicModuleOptions>({
477
485
  "eslint:config:addons",
478
486
  (
479
487
  addons: {
480
- name: string
481
- getConfigs: () => Promise<{ configs: string[] }>
488
+ name: string;
489
+ getConfigs: () => Promise<{ configs: string[] }>;
482
490
  }[],
483
491
  ) => {
484
492
  addons.push({
@@ -487,13 +495,15 @@ export default defineNuxtModule<PrismicModuleOptions>({
487
495
  const configPath = resolver.resolve(
488
496
  nuxt.options.rootDir,
489
497
  "slicemachine.config.json",
490
- )
498
+ );
491
499
 
492
- const configs: string[] = []
500
+ const configs: string[] = [];
493
501
 
494
502
  try {
495
503
  if (existsSync(configPath)) {
496
- const config = JSON.parse(await readFile(configPath, "utf-8"))
504
+ const config = JSON.parse(
505
+ await readFile(configPath, "utf-8"),
506
+ );
497
507
 
498
508
  if (
499
509
  config &&
@@ -510,67 +520,72 @@ export default defineNuxtModule<PrismicModuleOptions>({
510
520
  "vue/multi-word-component-names": "off",
511
521
  },
512
522
  }),
513
- )
523
+ );
514
524
  }
515
525
  }
516
526
  } catch {
517
527
  // noop
518
528
  }
519
529
 
520
- return { configs }
530
+ return { configs };
521
531
  },
522
- })
532
+ });
523
533
  },
524
- )
534
+ );
525
535
  }
526
536
  },
527
- })
537
+ });
528
538
 
529
539
  function fileExists(path?: string, extensions = ["js", "ts"]): string | null {
530
540
  if (!path) {
531
- return null
541
+ return null;
532
542
  } else if (existsSync(path)) {
533
- return path
543
+ return path;
534
544
  }
535
545
 
536
546
  const extension = extensions.find((extension) =>
537
547
  existsSync(`${path}.${extension}`),
538
- )
548
+ );
539
549
 
540
- return extension ? `${path}.${extension}` : null
550
+ return extension ? `${path}.${extension}` : null;
541
551
  }
542
552
 
543
553
  type PrismicConfig = {
544
- repositoryName?: string
545
- routes?: Route[]
546
- }
554
+ repositoryName?: string;
555
+ routes?: Route[];
556
+ };
547
557
 
548
- function readPrismicConfig(
549
- configPath: string,
550
- ): PrismicConfig {
558
+ function readPrismicConfig(configPath: string): PrismicConfig {
551
559
  if (!existsSync(configPath)) {
552
- return {}
560
+ return {};
553
561
  }
554
562
 
555
563
  try {
556
- const contents = readFileSync(configPath, "utf-8")
557
- const rawConfig = JSON.parse(contents) as unknown
564
+ const contents = readFileSync(configPath, "utf-8");
565
+ const rawConfig = JSON.parse(contents) as unknown;
558
566
 
559
- if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
560
- return {}
567
+ if (
568
+ !rawConfig ||
569
+ typeof rawConfig !== "object" ||
570
+ Array.isArray(rawConfig)
571
+ ) {
572
+ return {};
561
573
  }
562
574
 
563
- const config: PrismicConfig = {}
564
- if ("repositoryName" in rawConfig && typeof rawConfig.repositoryName === "string") {
565
- config.repositoryName = rawConfig.repositoryName
575
+ const config: PrismicConfig = {};
576
+ if (
577
+ "repositoryName" in rawConfig &&
578
+ typeof rawConfig.repositoryName === "string"
579
+ ) {
580
+ config.repositoryName = rawConfig.repositoryName;
566
581
  }
567
582
 
568
583
  if ("routes" in rawConfig && Array.isArray(rawConfig.routes)) {
569
- config.routes = rawConfig.routes
584
+ config.routes = rawConfig.routes;
570
585
  }
571
586
 
572
- return config
587
+ return config;
573
588
  } catch {
574
- return {}
589
+ return {};
575
590
  }
576
591
  }
@@ -1,8 +1,8 @@
1
1
  <script setup>
2
- import { usePrismicPreview, useSeoMeta } from "#imports"
2
+ import { usePrismicPreview, useSeoMeta } from "#imports";
3
3
 
4
- useSeoMeta({ title: "Prismic Preview - Loading" })
5
- usePrismicPreview()
4
+ useSeoMeta({ title: "Prismic Preview - Loading" });
5
+ usePrismicPreview();
6
6
  </script>
7
7
 
8
8
  <template>
@@ -1,5 +1,5 @@
1
- import { defineNuxtPlugin } from "#app"
2
- import { refreshNuxtData, useRuntimeConfig } from "#imports"
1
+ import { defineNuxtPlugin } from "#app";
2
+ import { refreshNuxtData, useRuntimeConfig } from "#imports";
3
3
 
4
4
  export default defineNuxtPlugin({
5
5
  name: "prismic:plugin:client",
@@ -7,9 +7,9 @@ export default defineNuxtPlugin({
7
7
  setup() {
8
8
  if (useRuntimeConfig().public.prismic?.preview) {
9
9
  window.addEventListener("prismicPreviewUpdate", (event) => {
10
- event.preventDefault()
11
- refreshNuxtData()
12
- })
10
+ event.preventDefault();
11
+ refreshNuxtData();
12
+ });
13
13
  }
14
14
  },
15
- })
15
+ });
@@ -1,10 +1,10 @@
1
- import { defineNuxtPlugin } from "#app"
2
- import NuxtLink from "#app/components/nuxt-link"
3
- import _client from "#build/prismic/proxy/client"
1
+ import { defineNuxtPlugin } from "#app";
2
+ import NuxtLink from "#app/components/nuxt-link";
3
+ import _client from "#build/prismic/proxy/client";
4
4
  // @ts-expect-error - Proxy file
5
- import linkResolver from "#build/prismic/proxy/linkResolver"
5
+ import linkResolver from "#build/prismic/proxy/linkResolver";
6
6
  // @ts-expect-error - Proxy file
7
- import richTextComponents from "#build/prismic/proxy/richTextComponents"
7
+ import richTextComponents from "#build/prismic/proxy/richTextComponents";
8
8
  import {
9
9
  onNuxtReady,
10
10
  refreshNuxtData,
@@ -13,57 +13,57 @@ import {
13
13
  useRequestEvent,
14
14
  useRouter,
15
15
  useRuntimeConfig,
16
- } from "#imports"
17
- import { Client, cookie, createClient, getToolbarSrc } from "@prismicio/client"
18
- import { createPrismic } from "@prismicio/vue"
16
+ } from "#imports";
17
+ import { Client, cookie, createClient, getToolbarSrc } from "@prismicio/client";
18
+ import { createPrismic } from "@prismicio/vue";
19
19
 
20
20
  export default defineNuxtPlugin({
21
21
  name: "prismic:setup",
22
22
  parallel: true,
23
23
  async setup(nuxtApp) {
24
- const options = useRuntimeConfig().public.prismic
24
+ const options = useRuntimeConfig().public.prismic;
25
25
 
26
- const client = await resolveClient()
27
- handlePreview()
28
- addToolbar()
26
+ const client = await resolveClient();
27
+ handlePreview();
28
+ addToolbar();
29
29
 
30
30
  async function resolveClient() {
31
31
  if ((_client as unknown) instanceof Client) {
32
- return _client!
32
+ return _client!;
33
33
  } else if (typeof _client === "function") {
34
34
  try {
35
35
  return await nuxtApp.runWithContext(() =>
36
36
  (_client as unknown as () => Client)(),
37
- )
37
+ );
38
38
  } catch (error) {
39
39
  console.error(
40
40
  "[@nuxtjs/prismic] An error happened while resolving your Prismic custom client, disabling Prismic module gracefully...",
41
41
  error,
42
- )
42
+ );
43
43
 
44
44
  // The Vue plugin still requires a client to work, we're providing an obviously broken one.
45
45
  return createClient(
46
46
  "error-resolving-custom-client",
47
47
  options.clientConfig,
48
- )
48
+ );
49
49
  }
50
50
  } else {
51
51
  return createClient(
52
52
  options.environment || options.endpoint || "endpoint-not-provided",
53
53
  options.clientConfig,
54
- )
54
+ );
55
55
  }
56
56
  }
57
57
 
58
58
  function handlePreview() {
59
59
  if (options.preview) {
60
- const previewCookie = useCookie("io.prismic.preview").value
60
+ const previewCookie = useCookie("io.prismic.preview").value;
61
61
 
62
62
  // Update client with req when running server side
63
63
  if (import.meta.server) {
64
- const req = useRequestEvent()?.node.req
64
+ const req = useRequestEvent()?.node.req;
65
65
  if (req) {
66
- client.enableAutoPreviewsFromReq(req)
66
+ client.enableAutoPreviewsFromReq(req);
67
67
  }
68
68
  }
69
69
 
@@ -72,7 +72,7 @@ export default defineNuxtPlugin({
72
72
  const session =
73
73
  typeof previewCookie === "string"
74
74
  ? JSON.parse(decodeURIComponent(previewCookie))
75
- : previewCookie
75
+ : previewCookie;
76
76
 
77
77
  if (
78
78
  Object.keys(session).some(
@@ -84,19 +84,19 @@ export default defineNuxtPlugin({
84
84
  session[key].preview,
85
85
  )
86
86
  ) {
87
- let afterEachCalled = false
87
+ let afterEachCalled = false;
88
88
  onNuxtReady(() => {
89
89
  if (!afterEachCalled) {
90
- refreshNuxtData()
90
+ refreshNuxtData();
91
91
  }
92
- })
92
+ });
93
93
  useRouter().afterEach(() => {
94
- afterEachCalled = true
95
- refreshNuxtData()
96
- })
94
+ afterEachCalled = true;
95
+ refreshNuxtData();
96
+ });
97
97
  }
98
98
  } catch (error) {
99
- console.warn("Failed to parse Prismic preview cookie", error)
99
+ console.warn("Failed to parse Prismic preview cookie", error);
100
100
  }
101
101
  }
102
102
  }
@@ -115,10 +115,10 @@ export default defineNuxtPlugin({
115
115
  crossorigin: "anonymous",
116
116
  },
117
117
  ],
118
- })
118
+ });
119
119
  } else {
120
120
  // TODO: We might want to let user disable this behavior because it might have unexpected side effects
121
- useCookie(cookie.preview).value = null
121
+ useCookie(cookie.preview).value = null;
122
122
  }
123
123
  }
124
124
 
@@ -130,11 +130,11 @@ export default defineNuxtPlugin({
130
130
  linkExternalComponent: NuxtLink,
131
131
  richTextComponents,
132
132
  },
133
- })
133
+ });
134
134
 
135
- nuxtApp.vueApp.use(prismicPlugin)
135
+ nuxtApp.vueApp.use(prismicPlugin);
136
136
  return {
137
137
  provide: { prismic: prismicPlugin },
138
- }
138
+ };
139
139
  },
140
- })
140
+ });
@@ -1,17 +1,17 @@
1
1
  // @ts-expect-error - Proxy file
2
- import { usePrismic, useRouter } from "#imports"
3
- import { onMounted } from "vue"
2
+ import { usePrismic, useRouter } from "#imports";
3
+ import { onMounted } from "vue";
4
4
 
5
5
  /** Resolves Prismic previews on the preview entry page (`/preview`) */
6
6
  export const usePrismicPreview = (defaultURL = "/"): void => {
7
- const { client, linkResolver } = usePrismic()
8
- const { push } = useRouter()
7
+ const { client, linkResolver } = usePrismic();
8
+ const { push } = useRouter();
9
9
  onMounted(async () => {
10
10
  const redirectURL = await client.resolvePreviewURL({
11
11
  linkResolver,
12
12
  defaultURL,
13
- })
13
+ });
14
14
 
15
- push(redirectURL)
16
- })
17
- }
15
+ push(redirectURL);
16
+ });
17
+ };