Skip to content

Commit

Permalink
fix: auto imports for linkRel, richTextComponents, and `sliceZone…
Browse files Browse the repository at this point in the history
…DefaultComponent` in nuxt 4
  • Loading branch information
lihbr committed Jan 13, 2025
1 parent 5b754e4 commit bbec245
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
17 changes: 12 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export default defineNuxtModule<PrismicModuleOptions>({
richTextSerializer: '~/app/prismic/richTextSerializer',
}

let prismicComponentsFiles = {
linkRel: '~/app/prismic/linkRel',
richTextComponents: '~/app/prismic/richTextComponents',
sliceZoneDefaultComponent: '~/app/prismic/sliceZoneDefaultComponent',
}

// Nuxt 4 sets `app` as its `srcDir`, so we're just using the `prismic` folder there.
if (
nuxt.options?.future?.compatibilityVersion === 4
Expand All @@ -59,6 +65,11 @@ export default defineNuxtModule<PrismicModuleOptions>({
linkResolver: '~/prismic/linkResolver',
richTextSerializer: '~/prismic/richTextSerializer',
}
prismicComponentsFiles = {
linkRel: '~/prismic/linkRel',
richTextComponents: '~/prismic/richTextComponents',
sliceZoneDefaultComponent: '~/prismic/sliceZoneDefaultComponent',
}
}

return {
Expand All @@ -67,11 +78,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
clientConfig: {},
...prismicFiles,
injectComponents: true,
components: {
linkRel: '~/prismic/linkRel',
richTextComponents: '~/prismic/richTextComponents',
sliceZoneDefaultComponent: '~/prismic/sliceZoneDefaultComponent',
},
components: prismicComponentsFiles,
preview: '/preview',
toolbar: true,
devtools: true,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { PrismicPluginOptions, SliceComponentProps, TODOSliceComponent } fr
*/
export type PrismicModuleOptions = Omit<
PrismicPluginOptions,
'endpoint' | 'client' | 'linkResolver' | 'htmlSerializer' | 'richTextSerializer' | 'components'
'endpoint' | 'client' | 'linkResolver' | 'richTextSerializer' | 'components'
> & {
/**
* A Prismic repository endpoint to init the module's `@prismicio/client`
Expand Down
6 changes: 3 additions & 3 deletions test/module-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ it('exposes options in runtime config', () => {
"client": "~/app/prismic/client",
"clientConfig": {},
"components": {
"linkRel": "~/prismic/linkRel",
"richTextComponents": "~/prismic/richTextComponents",
"sliceZoneDefaultComponent": "~/prismic/sliceZoneDefaultComponent",
"linkRel": "~/app/prismic/linkRel",
"richTextComponents": "~/app/prismic/richTextComponents",
"sliceZoneDefaultComponent": "~/app/prismic/sliceZoneDefaultComponent",
},
"devtools": true,
"endpoint": "qwerty",
Expand Down
24 changes: 12 additions & 12 deletions test/module-userFileProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ it('proxies user files from default location', () => {
],
[
"prismic/proxy/linkRel.ts",
"export default undefined",
"export { default } from '~/app/prismic/linkRel'",
],
[
"prismic/proxy/richTextComponents.ts",
"export default undefined",
"export { default } from '~/app/prismic/richTextComponents'",
],
[
"prismic/proxy/sliceZoneDefaultComponent.ts",
"export default undefined",
"export { default } from '~/app/prismic/sliceZoneDefaultComponent'",
],
]
`)
Expand Down Expand Up @@ -131,15 +131,15 @@ it('proxies user files from default location (Nuxt 4)', () => {
],
[
"prismic/proxy/linkRel.ts",
"export default undefined",
"export { default } from '~/app/prismic/linkRel'",
],
[
"prismic/proxy/richTextComponents.ts",
"export default undefined",
"export { default } from '~/app/prismic/richTextComponents'",
],
[
"prismic/proxy/sliceZoneDefaultComponent.ts",
"export default undefined",
"export { default } from '~/app/prismic/sliceZoneDefaultComponent'",
],
]
`)
Expand All @@ -150,9 +150,9 @@ it('proxies user files from provided location', () => {
'/tmp/nuxt/custom/client.ts': '',
'/tmp/nuxt/custom/linkResolver.ts': '',
'/tmp/nuxt/custom/richTextSerializer.ts': '',
'/tmp/nuxt/custom/prismic/linkRel.ts': '',
'/tmp/nuxt/custom/prismic/richTextComponents.ts': '',
'/tmp/nuxt/custom/prismic/sliceZoneDefaultComponent.vue': '',
'/tmp/nuxt/custom/linkRel.ts': '',
'/tmp/nuxt/custom/richTextComponents.ts': '',
'/tmp/nuxt/custom/sliceZoneDefaultComponent.vue': '',
})

mockedPrismicModule({
Expand Down Expand Up @@ -185,15 +185,15 @@ it('proxies user files from provided location', () => {
],
[
"prismic/proxy/linkRel.ts",
"export default undefined",
"export { default } from '~/custom/linkRel'",
],
[
"prismic/proxy/richTextComponents.ts",
"export default undefined",
"export { default } from '~/custom/richTextComponents'",
],
[
"prismic/proxy/sliceZoneDefaultComponent.ts",
"export default undefined",
"export { default } from '~/custom/sliceZoneDefaultComponent'",
],
]
`)
Expand Down

0 comments on commit bbec245

Please sign in to comment.