@nuxtjs/prismic 4.0.0 → 4.1.0-canary.a1dda93

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.
Files changed (44) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +18 -32
  3. package/dist/module.d.mts +48 -75
  4. package/dist/module.json +3 -3
  5. package/dist/module.mjs +216 -240
  6. package/dist/runtime/PrismicPreview.d.vue.ts +3 -0
  7. package/dist/runtime/PrismicPreview.vue +10 -23
  8. package/dist/runtime/PrismicPreview.vue.d.ts +3 -0
  9. package/dist/runtime/plugin.client.js +10 -7
  10. package/dist/runtime/plugin.js +86 -69
  11. package/dist/runtime/usePrismicPreview.d.ts +1 -5
  12. package/dist/runtime/usePrismicPreview.js +2 -2
  13. package/dist/types.d.mts +3 -1
  14. package/package.json +42 -44
  15. package/src/module.ts +383 -185
  16. package/src/runtime/PrismicPreview.vue +10 -41
  17. package/src/runtime/plugin.client.ts +13 -13
  18. package/src/runtime/plugin.ts +114 -103
  19. package/src/runtime/usePrismicPreview.ts +6 -10
  20. package/dist/client/200.html +0 -1
  21. package/dist/client/404.html +0 -1
  22. package/dist/client/_nuxt/BMD6bpEv.js +0 -1
  23. package/dist/client/_nuxt/BQB6UGbx.js +0 -25
  24. package/dist/client/_nuxt/CkG7IjgS.js +0 -1
  25. package/dist/client/_nuxt/DlAUqK2U.js +0 -1
  26. package/dist/client/_nuxt/H1okkFcd.js +0 -1
  27. package/dist/client/_nuxt/RYS3n4u0.js +0 -1
  28. package/dist/client/_nuxt/V_weDLQm.js +0 -1
  29. package/dist/client/_nuxt/builds/latest.json +0 -1
  30. package/dist/client/_nuxt/builds/meta/ef21bbff-0463-480b-852c-adffad3f33b7.json +0 -1
  31. package/dist/client/_nuxt/entry.BC9BDAld.css +0 -1
  32. package/dist/client/_nuxt/error-404.smTsHvdw.css +0 -1
  33. package/dist/client/_nuxt/error-500.Bo-s0s94.css +0 -1
  34. package/dist/client/_nuxt/index.C4BggqQh.css +0 -1
  35. package/dist/client/index.html +0 -1
  36. package/dist/module.cjs +0 -5
  37. package/dist/module.d.ts +0 -136
  38. package/dist/types.d.ts +0 -1
  39. package/src/devtools/index.ts +0 -127
  40. package/src/devtools/types.ts +0 -22
  41. package/src/lib/fileExists.ts +0 -15
  42. package/src/lib/index.ts +0 -2
  43. package/src/lib/logger.ts +0 -3
  44. package/src/types.ts +0 -137
package/src/module.ts CHANGED
@@ -1,115 +1,259 @@
1
- import { join } from 'node:path'
2
- import { readFile } from 'node:fs/promises'
3
- import { existsSync } from 'node:fs'
1
+ import { existsSync } from "node:fs"
2
+ import { readFile } from "node:fs/promises"
3
+ import { join } from "node:path"
4
4
 
5
- import { defu } from 'defu'
6
5
  import {
7
- defineNuxtModule,
8
- createResolver,
9
- addTemplate,
10
- addPlugin,
11
- addImports,
12
6
  addComponent,
7
+ addImports,
8
+ addPlugin,
9
+ addTemplate,
10
+ createResolver,
11
+ defineNuxtModule,
13
12
  extendPages,
14
13
  getNuxtVersion,
15
- } from '@nuxt/kit'
14
+ useLogger,
15
+ } from "@nuxt/kit"
16
+ import type { ClientConfig } from "@prismicio/client"
17
+ import { defu } from "defu"
18
+ import { addDependency } from "nypm"
19
+ import { readPackage } from "pkg-types"
16
20
 
17
- import * as prismicVue from '@prismicio/vue'
18
- import { setupDevToolsUI } from './devtools'
21
+ import { name, version } from "../package.json"
19
22
 
20
- import { logger, fileExists } from './lib'
21
- import type { PrismicModuleOptions } from './types'
23
+ /**
24
+ * Prismic Nuxt module options.
25
+ *
26
+ * @see {@link https://prismic.io/docs/nuxt}
27
+ * @see {@link https://prismic.io/docs/technical-reference/nuxtjs-prismic}
28
+ */
29
+ export type PrismicModuleOptions = {
30
+ /**
31
+ * The Prismic repository name or full Content API endpoint to init the
32
+ * module's client instance used to fetch content from a Prismic repository
33
+ * with.
34
+ *
35
+ * @example
36
+ *
37
+ * ```typescript
38
+ * // With a repository name
39
+ * createClient("my-repo")
40
+ *
41
+ * // With a full Prismic Content API endpoint
42
+ * createClient("https://my-repo.cdn.prismic.io/api/v2")
43
+ * ```
44
+ *
45
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
46
+ */
47
+ endpoint?: string
22
48
 
23
- // Options export
24
- export type { PrismicModuleOptions, PrismicModuleOptions as ModuleOptions } from './types'
49
+ /**
50
+ * The Prismic environment in use by Slice Machine configured through
51
+ * environment variables.
52
+ *
53
+ * @defaultValue `endpoint` value.
54
+ *
55
+ * @internal
56
+ */
57
+ environment?: string
25
58
 
26
- declare module '@nuxt/schema' {
27
- interface PublicRuntimeConfig {
59
+ /**
60
+ * Configuration options that determines how content will be queries from the
61
+ * Prismic repository.
62
+ *
63
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
64
+ */
65
+ clientConfig?: ClientConfig
66
+
67
+ /**
68
+ * An optional path to a file exporting a Prismic client instance used to
69
+ * fetch content from a Prismic repository to configure the module with.
70
+ *
71
+ * @remarks
72
+ * When provided, it takes precedence over the `endpoint` and `clientConfig`
73
+ * options.
74
+ *
75
+ * @see {@link https://prismic.io/docs/technical-reference/prismicio-client}
76
+ */
77
+ client?: string
78
+
79
+ /**
80
+ * The path to a file exporting a default link resolver used to resolve links
81
+ * when route resolvers cannot be used.
82
+ *
83
+ * @see {@link https://prismic.io/docs/routes}
84
+ */
85
+ linkResolver?: string
86
+
87
+ /**
88
+ * Desired path of the preview page used by Prismic to enter preview session.
89
+ *
90
+ * @remarks
91
+ * `false` can be used to disable the preview page.
92
+ *
93
+ * @defaultValue `"/preview"`
94
+ */
95
+ preview?: string | false
96
+
97
+ /**
98
+ * Whether to inject Prismic toolbar script.
99
+ *
100
+ * @remarks
101
+ * The toolbar script is required for previews to work.
102
+ *
103
+ * @defaultValue `true`
104
+ */
105
+ toolbar?: boolean
106
+
107
+ /** Options used by Prismic Vue components. */
108
+ components?: {
28
109
  /**
29
- * `@nuxtjs/prismic` module options.
110
+ * The path to a file exporting default components or shorthand definitions
111
+ * for rich text and table components.
30
112
  *
31
- * @see Module documentation: {@link https://prismic.nuxtjs.org}
32
- * @see Prismic documentation: {@link https://prismic.io/docs/nuxt-3-setup}
113
+ * @see {@link https://prismic.io/docs/fields/rich-text}
114
+ * @see {@link https://prismic.io/docs/fields/table}
33
115
  */
116
+ richTextComponents?: string
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Prismic Nuxt module options.
122
+ *
123
+ * @see {@link https://prismic.io/docs/nuxt}
124
+ * @see {@link https://prismic.io/docs/technical-reference/nuxtjs-prismic}
125
+ */
126
+ export type ModuleOptions = PrismicModuleOptions
127
+
128
+ declare module "@nuxt/schema" {
129
+ interface PublicRuntimeConfig {
130
+ /** The Prismic Nuxt module options. */
34
131
  prismic: PrismicModuleOptions
35
132
  }
36
133
  }
37
134
 
38
- // Module export
135
+ const logger = useLogger("nuxt:prismic")
136
+
137
+ async function addPrismicClient() {
138
+ try {
139
+ const pkg = await readPackage()
140
+
141
+ if (
142
+ !pkg.dependencies?.["@prismicio/client"] &&
143
+ !pkg.devDependencies?.["@prismicio/client"]
144
+ ) {
145
+ await addDependency("@prismicio/client")
146
+ logger.info("Added `@prismicio/client` required peer dependency")
147
+ }
148
+ } catch {
149
+ // noop
150
+ }
151
+ }
152
+
39
153
  export default defineNuxtModule<PrismicModuleOptions>({
40
154
  meta: {
41
- name: '@nuxtjs/prismic',
42
- configKey: 'prismic',
43
- compatibility: { nuxt: '>=3.7.0' },
155
+ name,
156
+ version,
157
+ configKey: "prismic",
158
+ compatibility: { nuxt: ">=3.7.0" },
44
159
  },
45
- defaults: (nuxt) => {
46
- let prismicFiles = {
47
- client: '~/app/prismic/client',
48
- linkResolver: '~/app/prismic/linkResolver',
49
- richTextSerializer: '~/app/prismic/richTextSerializer',
50
- }
51
-
52
- let prismicComponentsFiles = {
53
- linkRel: '~/app/prismic/linkRel',
54
- richTextComponents: '~/app/prismic/richTextComponents',
55
- sliceZoneDefaultComponent: '~/app/prismic/sliceZoneDefaultComponent',
160
+ onInstall() {
161
+ return addPrismicClient()
162
+ },
163
+ onUpgrade(_options: unknown, _nuxt: unknown, previousVersion: string) {
164
+ const previousMajor = parseInt(previousVersion.split(".")[0]!)
165
+ if (previousMajor < 4) {
166
+ return addPrismicClient()
56
167
  }
168
+ },
169
+ defaults: (nuxt): Required<PrismicModuleOptions> => {
170
+ const nuxt3flavor =
171
+ getNuxtVersion(nuxt).startsWith("3") &&
172
+ !nuxt.options?.future?.compatibilityVersion
57
173
 
58
- // Nuxt 4 sets `app` as its `srcDir`, so we're just using the `prismic` folder there.
59
- if (
60
- nuxt.options?.future?.compatibilityVersion === 4
61
- || getNuxtVersion(nuxt).startsWith('4')
62
- ) {
63
- prismicFiles = {
64
- client: '~/prismic/client',
65
- linkResolver: '~/prismic/linkResolver',
66
- richTextSerializer: '~/prismic/richTextSerializer',
67
- }
68
- prismicComponentsFiles = {
69
- linkRel: '~/prismic/linkRel',
70
- richTextComponents: '~/prismic/richTextComponents',
71
- sliceZoneDefaultComponent: '~/prismic/sliceZoneDefaultComponent',
174
+ if (nuxt3flavor) {
175
+ return {
176
+ endpoint: "",
177
+ environment: "",
178
+ clientConfig: {},
179
+ client: "~/app/prismic/client",
180
+ linkResolver: "~/app/prismic/linkResolver",
181
+ preview: "/preview",
182
+ toolbar: true,
183
+ components: {
184
+ richTextComponents: "~/app/prismic/richTextComponents ",
185
+ },
72
186
  }
73
187
  }
74
188
 
75
189
  return {
76
- endpoint: '',
77
- environment: '',
190
+ endpoint: "",
191
+ environment: "",
192
+ client: "~/prismic/client",
193
+ linkResolver: "~/prismic/linkResolver",
78
194
  clientConfig: {},
79
- ...prismicFiles,
80
- injectComponents: true,
81
- components: prismicComponentsFiles,
82
- preview: '/preview',
195
+ preview: "/preview",
83
196
  toolbar: true,
84
- devtools: true,
197
+ components: {
198
+ richTextComponents: "~/prismic/richTextComponents",
199
+ },
85
200
  }
86
201
  },
87
- hooks: {},
88
202
  setup(options, nuxt) {
89
- // Expose options through public runtime config
90
- nuxt.options.runtimeConfig.public ||= {} as typeof nuxt.options.runtimeConfig.public
91
- const moduleOptions: PrismicModuleOptions = defu(nuxt.options.runtimeConfig.public.prismic, options)
92
- nuxt.options.runtimeConfig.public.prismic = moduleOptions
93
-
94
- // Runtime dir boilerplate
95
203
  const resolver = createResolver(import.meta.url)
96
- if (nuxt.options.devtools && options.devtools) {
97
- setupDevToolsUI(nuxt, resolver)
204
+
205
+ const moduleOptions: PrismicModuleOptions = defu(
206
+ nuxt.options.runtimeConfig.public?.prismic,
207
+ options,
208
+ )
209
+
210
+ exposeRuntimeConfig()
211
+ transpileDependencies()
212
+ const ok = proxyUserFiles()
213
+ if (!ok) return
214
+ addRuntimePlugins()
215
+ addAutoImports()
216
+ addPreviewRoute()
217
+ extendESLintConfig()
218
+
219
+ function exposeRuntimeConfig() {
220
+ nuxt.options.runtimeConfig.public ||=
221
+ {} as typeof nuxt.options.runtimeConfig.public
222
+ nuxt.options.runtimeConfig.public.prismic = moduleOptions
98
223
  }
99
224
 
100
- // Add runtime user code
101
- const proxyUserFileWithUndefinedFallback
102
- = (filename: string, path: string, deprecated?: boolean | string): boolean => {
225
+ function transpileDependencies() {
226
+ nuxt.options.build.transpile.push(
227
+ resolver.resolve("runtime"),
228
+ "@nuxtjs/prismic",
229
+ "@prismicio/vue",
230
+ )
231
+ nuxt.options.vite.optimizeDeps ||= {}
232
+ nuxt.options.vite.optimizeDeps.exclude ||= []
233
+ nuxt.options.vite.optimizeDeps.exclude.push("@prismicio/vue")
234
+ }
235
+
236
+ function proxyUserFiles() {
237
+ const proxyUserFileWithUndefinedFallback = (
238
+ filename: string,
239
+ path: string,
240
+ ): boolean => {
103
241
  const resolvedFilename = `prismic/proxy/${filename}.ts`
104
- const resolvedPath = path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir)
105
- const maybeUserFile = fileExists(resolvedPath, ['js', 'mjs', 'ts', 'vue'])
242
+ const resolvedPath = path
243
+ .replace(/^(~~|@@)/, nuxt.options.rootDir)
244
+ .replace(/^(~|@)/, nuxt.options.srcDir)
245
+ const maybeUserFile = fileExists(resolvedPath, [
246
+ "js",
247
+ "mjs",
248
+ "ts",
249
+ "vue",
250
+ ])
106
251
 
107
252
  if (maybeUserFile) {
108
- // If user file exists, proxy it with vfs
109
- logger.info(`Using user-defined \`${filename}\` at \`${maybeUserFile.replace(nuxt.options.srcDir, '~').replace(nuxt.options.rootDir, '~~').replace(/\\/g, '/')}\``)
110
- if (deprecated) {
111
- logger.warn(`\`${filename}\` is deprecated and will be removed in a future version.${typeof deprecated === 'string' ? `${deprecated}` : ''}`)
112
- }
253
+ // If user file exists, proxy it with vfs
254
+ logger.info(
255
+ `Using user-defined \`${filename}\` at \`${maybeUserFile.replace(nuxt.options.srcDir, "~").replace(nuxt.options.rootDir, "~~").replace(/\\/g, "/")}\``,
256
+ )
113
257
 
114
258
  addTemplate({
115
259
  filename: resolvedFilename,
@@ -117,136 +261,190 @@ export default defineNuxtModule<PrismicModuleOptions>({
117
261
  })
118
262
 
119
263
  return true
120
- }
121
- else {
122
- // Else provide `undefined` fallback
264
+ } else {
265
+ // Else provide `undefined` fallback
123
266
  addTemplate({
124
267
  filename: resolvedFilename,
125
- getContents: () => 'export default undefined',
268
+ getContents: () => "export default undefined",
126
269
  })
127
270
 
128
271
  return false
129
272
  }
130
273
  }
131
274
 
132
- const proxiedUserClient = proxyUserFileWithUndefinedFallback('client', moduleOptions.client!)
133
- if (!moduleOptions.endpoint && !proxiedUserClient && !process.env.NUXT_PUBLIC_PRISMIC_ENDPOINT) {
134
- logger.warn(`\`endpoint\` option is missing and \`${moduleOptions.client}\` was not found. At least one of them is required for the module to run. Disabling module...`)
135
- return
275
+ const proxiedUserClient = proxyUserFileWithUndefinedFallback(
276
+ "client",
277
+ moduleOptions.client!,
278
+ )
279
+ if (
280
+ !moduleOptions.endpoint &&
281
+ !proxiedUserClient &&
282
+ !process.env.NUXT_PUBLIC_PRISMIC_ENDPOINT
283
+ ) {
284
+ logger.warn(
285
+ `\`endpoint\` option is missing and \`${moduleOptions.client}\` was not found. At least one of them is required for the module to run. Disabling module...`,
286
+ )
287
+ return false
288
+ }
289
+ proxyUserFileWithUndefinedFallback(
290
+ "linkResolver",
291
+ moduleOptions.linkResolver!,
292
+ )
293
+ proxyUserFileWithUndefinedFallback(
294
+ "richTextComponents",
295
+ moduleOptions.components!.richTextComponents!,
296
+ )
297
+
298
+ return true
299
+ }
300
+
301
+ function addRuntimePlugins() {
302
+ addPlugin(resolver.resolve("runtime/plugin"))
303
+ addPlugin(resolver.resolve("runtime/plugin.client"))
136
304
  }
137
- proxyUserFileWithUndefinedFallback('linkResolver', moduleOptions.linkResolver!)
138
- proxyUserFileWithUndefinedFallback('richTextSerializer', moduleOptions.richTextSerializer!, 'Use `components.richTextComponents` instead.')
139
-
140
- // Components
141
- proxyUserFileWithUndefinedFallback('linkRel', moduleOptions.components!.linkRel!)
142
- proxyUserFileWithUndefinedFallback('richTextComponents', moduleOptions.components!.richTextComponents!)
143
- proxyUserFileWithUndefinedFallback('sliceZoneDefaultComponent', moduleOptions.components!.sliceZoneDefaultComponent!)
144
-
145
- nuxt.options.build.transpile.push(resolver.resolve('runtime'), '@nuxtjs/prismic', '@prismicio/vue')
146
- nuxt.options.vite.optimizeDeps ||= {}
147
- nuxt.options.vite.optimizeDeps.exclude ||= []
148
- nuxt.options.vite.optimizeDeps.exclude.push('@prismicio/vue')
149
-
150
- // Add plugin
151
- addPlugin(resolver.resolve('runtime/plugin'))
152
- addPlugin(resolver.resolve('runtime/plugin.client'))
153
-
154
- // Add components auto import
155
- if (moduleOptions.injectComponents) {
156
- [
157
- 'PrismicEmbed',
158
- 'PrismicImage',
159
- 'PrismicLink',
160
- 'PrismicText',
161
- 'PrismicRichText',
162
- 'SliceZone',
163
- ].forEach((component) => {
305
+
306
+ function addAutoImports() {
307
+ // Components
308
+ ;[
309
+ "PrismicImage",
310
+ "PrismicLink",
311
+ "PrismicText",
312
+ "PrismicRichText",
313
+ "PrismicTable",
314
+ "SliceZone",
315
+ ].forEach((entry) => {
164
316
  addComponent({
165
- name: component,
166
- export: component,
167
- filePath: '@prismicio/vue',
317
+ name: entry,
318
+ export: entry,
319
+ filePath: "@prismicio/vue",
168
320
  })
169
321
  })
170
- }
171
322
 
172
- // Add auto imports
173
- const prismicVueAutoImports = Object
174
- .keys(prismicVue)
175
- .filter(key => key.startsWith('use'))
176
- .concat('getSliceComponentProps', 'defineSliceZoneComponents', 'getRichTextComponentProps')
177
- .map((key) => {
178
- return {
179
- name: key,
180
- as: key,
181
- from: '@prismicio/vue',
182
- }
323
+ // Composables and utils
324
+ addImports(
325
+ [
326
+ "usePrismic",
327
+ "getSliceComponentProps",
328
+ "defineSliceZoneComponents",
329
+ "getRichTextComponentProps",
330
+ "getTableComponentProps",
331
+ ].map((entry) => ({ name: entry, as: entry, from: "@prismicio/vue" })),
332
+ )
333
+ addImports({
334
+ name: "usePrismicPreview",
335
+ as: "usePrismicPreview",
336
+ from: resolver.resolve("runtime/usePrismicPreview"),
183
337
  })
184
- addImports(prismicVueAutoImports)
185
- addImports({
186
- name: 'usePrismicPreview',
187
- as: 'usePrismicPreview',
188
- from: resolver.resolve('runtime/usePrismicPreview'),
189
- })
190
-
191
- // Add preview route
192
- if (moduleOptions.preview) {
193
- const maybeUserPreviewPage = fileExists(join(nuxt.options.srcDir, nuxt.options.dir.pages, moduleOptions.preview), ['js', 'ts', 'vue'])
194
-
195
- if (maybeUserPreviewPage) {
196
- logger.info(`Using user-defined preview page at \`${maybeUserPreviewPage.replace(join(nuxt.options.srcDir), '~').replace(nuxt.options.rootDir, '~~').replace(/\\/g, '/')
197
- }\`, available at \`${moduleOptions.preview}\``)
198
- }
199
- else {
200
- logger.info(`Using default preview page, available at \`${moduleOptions.preview}\``)
201
-
202
- extendPages((pages) => {
203
- pages.unshift({
204
- name: 'prismic-preview',
205
- path: moduleOptions.preview as string, // Checked before
206
- file: resolver.resolve('runtime/PrismicPreview.vue'),
338
+ }
339
+
340
+ function addPreviewRoute() {
341
+ if (moduleOptions.preview) {
342
+ const maybeUserPreviewPage = fileExists(
343
+ join(
344
+ nuxt.options.srcDir,
345
+ nuxt.options.dir.pages,
346
+ moduleOptions.preview,
347
+ ),
348
+ ["js", "ts", "vue"],
349
+ )
350
+
351
+ if (maybeUserPreviewPage) {
352
+ logger.info(
353
+ `Using user-defined preview page at \`${maybeUserPreviewPage
354
+ .replace(join(nuxt.options.srcDir), "~")
355
+ .replace(nuxt.options.rootDir, "~~")
356
+ .replace(
357
+ /\\/g,
358
+ "/",
359
+ )}\`, available at \`${moduleOptions.preview}\``,
360
+ )
361
+ } else {
362
+ logger.info(
363
+ `Using default preview page, available at \`${moduleOptions.preview}\``,
364
+ )
365
+
366
+ extendPages((pages) => {
367
+ pages.unshift({
368
+ name: "prismic-preview",
369
+ path: moduleOptions.preview as string, // Checked before
370
+ file: resolver.resolve("runtime/PrismicPreview.vue"),
371
+ })
207
372
  })
208
- })
209
- }
373
+ }
210
374
 
211
- if (!moduleOptions.toolbar) {
212
- logger.warn('`toolbar` option is disabled but `preview` is enabled. Previews won\'t work unless you manually load the toolbar.')
375
+ if (!moduleOptions.toolbar) {
376
+ logger.warn(
377
+ "`toolbar` option is disabled but `preview` is enabled. Previews won't work unless you manually load the toolbar.",
378
+ )
379
+ }
213
380
  }
214
381
  }
215
382
 
216
- // Integrate with @nuxt/eslint
217
- // @ts-expect-error 3rd party hook
218
- nuxt.hook('eslint:config:addons', (addons: {
219
- name: string
220
- getConfigs: () => Promise<{ configs: string[] }>
221
- }[]) => {
222
- addons.push({
223
- name: '@nuxtjs/prismic',
224
- async getConfigs() {
225
- const configPath = resolver.resolve(nuxt.options.rootDir, 'slicemachine.config.json')
226
-
227
- const configs: string[] = []
228
-
229
- try {
230
- if (existsSync(configPath)) {
231
- const config = JSON.parse(await readFile(configPath, 'utf-8'))
232
-
233
- if (config && 'libraries' in config && Array.isArray(config.libraries)) {
234
- configs.push(JSON.stringify({
235
- files: config.libraries.map((library: string) => `${library.replace('./', '')}/**/index.vue`),
236
- rules: {
237
- 'vue/multi-word-component-names': 'off',
238
- },
239
- }))
383
+ function extendESLintConfig() {
384
+ nuxt.hook(
385
+ // @ts-expect-error 3rd party hook
386
+ "eslint:config:addons",
387
+ (
388
+ addons: {
389
+ name: string
390
+ getConfigs: () => Promise<{ configs: string[] }>
391
+ }[],
392
+ ) => {
393
+ addons.push({
394
+ name: "@nuxtjs/prismic",
395
+ async getConfigs() {
396
+ const configPath = resolver.resolve(
397
+ nuxt.options.rootDir,
398
+ "slicemachine.config.json",
399
+ )
400
+
401
+ const configs: string[] = []
402
+
403
+ try {
404
+ if (existsSync(configPath)) {
405
+ const config = JSON.parse(await readFile(configPath, "utf-8"))
406
+
407
+ if (
408
+ config &&
409
+ "libraries" in config &&
410
+ Array.isArray(config.libraries)
411
+ ) {
412
+ configs.push(
413
+ JSON.stringify({
414
+ files: config.libraries.map(
415
+ (library: string) =>
416
+ `${library.replace("./", "")}/**/index.vue`,
417
+ ),
418
+ rules: {
419
+ "vue/multi-word-component-names": "off",
420
+ },
421
+ }),
422
+ )
423
+ }
424
+ }
425
+ } catch {
426
+ // noop
240
427
  }
241
- }
242
- }
243
- catch {
244
- // noop
245
- }
246
428
 
247
- return { configs }
429
+ return { configs }
430
+ },
431
+ })
248
432
  },
249
- })
250
- })
433
+ )
434
+ }
251
435
  },
252
436
  })
437
+
438
+ function fileExists(path?: string, extensions = ["js", "ts"]): string | null {
439
+ if (!path) {
440
+ return null
441
+ } else if (existsSync(path)) {
442
+ return path
443
+ }
444
+
445
+ const extension = extensions.find((extension) =>
446
+ existsSync(`${path}.${extension}`),
447
+ )
448
+
449
+ return extension ? `${path}.${extension}` : null
450
+ }