diff --git a/src/module.ts b/src/module.ts index 57003b522..a25d65b0b 100644 --- a/src/module.ts +++ b/src/module.ts @@ -40,12 +40,10 @@ const imageModule: Module = async function imageModule (moduleOpt const imageOptions: Omit = pick(options, [ 'screens', 'presets', - 'provider' + 'provider', + 'domains' ]) - options.static = options.static || {} - options.static.domains = options.domains - const providers = resolveProviders(nuxt, options) // Run setup diff --git a/src/runtime/providers/ipx.ts b/src/runtime/providers/ipx.ts index ea5d97fdf..ffe56880e 100644 --- a/src/runtime/providers/ipx.ts +++ b/src/runtime/providers/ipx.ts @@ -16,7 +16,7 @@ const operationsGenerator = createOperationsGenerator({ formatter: (key, val) => encodeQueryItem(key, val) }) -export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL = '/_ipx', domains = [] } = {}) => { +export const getImage: ProviderGetImage = (src, { modifiers = {}, baseURL = '/_ipx' } = {}, { options: { domains = [] } }) => { if (modifiers.width && modifiers.height) { modifiers.resize = `${modifiers.width}_${modifiers.height}` delete modifiers.width diff --git a/src/types/image.ts b/src/types/image.ts index bdec600b2..30669cf79 100644 --- a/src/types/image.ts +++ b/src/types/image.ts @@ -35,6 +35,7 @@ export interface CreateImageOptions { presets: { [name: string]: ImageOptions } provider: string screens?: Record, + domains?: string[] } export interface ImageInfo { diff --git a/test/unit/providers.test.ts b/test/unit/providers.test.ts index 6cf8bb470..ec88b4dde 100644 --- a/test/unit/providers.test.ts +++ b/test/unit/providers.test.ts @@ -12,13 +12,15 @@ import * as netlify from '~/runtime/providers/netlify' import * as prismic from '~/runtime/providers/prismic' import * as sanity from '~/runtime/providers/sanity' +const emptyContext = { options: {} } as any + describe('Providers', () => { test('ipx', () => { const providerOptions = {} for (const image of images) { const [src, modifiers] = image.args - const generated = ipx.getImage(src, { modifiers: { ...modifiers }, ...providerOptions }, {} as any) + const generated = ipx.getImage(src, { modifiers: { ...modifiers }, ...providerOptions }, emptyContext) generated.url = cleanDoubleSlashes(generated.url) expect(generated).toMatchObject(image.ipx) } @@ -31,7 +33,7 @@ describe('Providers', () => { for (const image of images) { const [src, modifiers] = image.args - const generated = cloudinary.getImage(src, { modifiers, ...providerOptions }, {} as any) + const generated = cloudinary.getImage(src, { modifiers, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.cloudinary) } }) @@ -50,7 +52,7 @@ describe('Providers', () => { height: 300 }, ...providerOptions - }, {} as any + }, emptyContext ) expect(generated).toMatchObject({ url: `https://res.cloudinary.com/demo/image/fetch/f_auto,q_auto,w_300,h_300/${remoteUrl}` @@ -69,7 +71,7 @@ describe('Providers', () => { height: 300 }, ...providerOptions - }, {} as any + }, emptyContext ) expect(generated).toMatchObject({ url: 'https://res.cloudinary.com/demo/image/upload/f_auto,q_auto,w_300,h_300/remote/1/13/Benedict_Cumberbatch_2011.png' @@ -83,7 +85,7 @@ describe('Providers', () => { for (const image of images) { const [src, modifiers] = image.args - const generated = twicpics.getImage(src, { modifiers, ...providerOptions }, {} as any) + const generated = twicpics.getImage(src, { modifiers, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.twicpics) } }) @@ -94,7 +96,7 @@ describe('Providers', () => { } for (const image of images) { const [src, modifiers] = image.args - const generated = glide.getImage(src, { modifiers, ...providerOptions }, {} as any) + const generated = glide.getImage(src, { modifiers, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.glide) } }) @@ -105,7 +107,7 @@ describe('Providers', () => { } for (const image of images) { const [src, modifiers] = image.args - const generated = fastly.getImage(src, { modifiers, ...providerOptions }, {} as any) + const generated = fastly.getImage(src, { modifiers, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.fastly) } }) @@ -117,7 +119,7 @@ describe('Providers', () => { for (const image of images) { const [src, modifiers] = image.args - const generated = imgix.getImage(src, { modifiers, ...providerOptions }, {} as any) + const generated = imgix.getImage(src, { modifiers, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.imgix) } }) @@ -129,7 +131,7 @@ describe('Providers', () => { for (const image of images) { const [src, modifiers] = image.args - const generated = imagekit.getImage(src, { modifiers, ...providerOptions }, {} as any) + const generated = imagekit.getImage(src, { modifiers, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.imagekit) } }) @@ -141,7 +143,7 @@ describe('Providers', () => { for (const image of images) { const [src, modifiers] = image.args - const generated = netlify.getImage(src, { modifiers: { ...modifiers }, ...providerOptions }, {} as any) + const generated = netlify.getImage(src, { modifiers: { ...modifiers }, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.netlify) } }) @@ -156,7 +158,7 @@ describe('Providers', () => { for (const image of images) { const [src, modifiers] = image.args - const generated = prismic.getImage(`${src}${EXISTING_QUERY_PARAMETERS}`, { modifiers, ...providerOptions }, {} as any) + const generated = prismic.getImage(`${src}${EXISTING_QUERY_PARAMETERS}`, { modifiers, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.prismic) } }) @@ -169,7 +171,7 @@ describe('Providers', () => { for (const image of images) { const [, modifiers] = image.args - const generated = sanity.getImage('image-test-300x450-png', { modifiers: { ...modifiers }, ...providerOptions }, {} as any) + const generated = sanity.getImage('image-test-300x450-png', { modifiers: { ...modifiers }, ...providerOptions }, emptyContext) expect(generated).toMatchObject(image.sanity) } })