Skip to content

Commit

Permalink
always use next/image, since in next 12.3.2 next/future/image was…
Browse files Browse the repository at this point in the history
… renamed to `next/image` (#937)
  • Loading branch information
dimaMachina committed Oct 27, 2022
1 parent 0c136ad commit a9414be
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-gifts-juggle.md
@@ -0,0 +1,5 @@
---
'nextra': patch
---

always use `next/image`, since in next 12.3.2 `next/future/image` was renamed to `next/image`
7 changes: 2 additions & 5 deletions packages/nextra/src/compile.ts
Expand Up @@ -48,7 +48,6 @@ export async function compileMdx(
| 'unstable_flexsearch'
| 'unstable_defaultShowCopyCode'
| 'unstable_readingTime'
| 'allowFutureImage'
> & {
mdxOptions?: LoaderOptions['mdxOptions'] &
Pick<ProcessorOptions, 'jsx' | 'outputFormat'>
Expand All @@ -67,10 +66,8 @@ export async function compileMdx(
...(mdxOptions.remarkPlugins || []),
remarkGfm,
remarkHeadings,
loaderOptions.unstable_staticImage && [
remarkStaticImage,
{ allowFutureImage: loaderOptions.allowFutureImage, filePath }
] as any,
loaderOptions.unstable_staticImage &&
([remarkStaticImage, { filePath }] as any),
loaderOptions.unstable_flexsearch &&
structurize(structurizedData, loaderOptions.unstable_flexsearch),
loaderOptions.unstable_readingTime && readingTime
Expand Down
6 changes: 0 additions & 6 deletions packages/nextra/src/index.js
@@ -1,4 +1,3 @@
import next from 'next/package.json'
import { NextraPlugin, pageMapCache } from './plugin'
import {
DEFAULT_LOCALE,
Expand All @@ -8,10 +7,6 @@ import {

const DEFAULT_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx']

const [major, minor] = next.version.split('.').map(Number)
const nextVersion = major + (0.1 * minor)
const hasFutureImage = nextVersion >= 12.3

const nextra = (...config) =>
function withNextra(nextConfig = {}) {
const nextraConfig =
Expand Down Expand Up @@ -46,7 +41,6 @@ const nextra = (...config) =>
defaultLocale: nextConfig.i18n?.defaultLocale || DEFAULT_LOCALE,
pageMapCache,
newNextLinkBehavior: nextConfig.experimental?.newNextLinkBehavior,
allowFutureImage: hasFutureImage
}

config.module.rules.push(
Expand Down
2 changes: 0 additions & 2 deletions packages/nextra/src/loader.ts
Expand Up @@ -72,7 +72,6 @@ async function loader(
mdxOptions,
pageMapCache,
newNextLinkBehavior,
allowFutureImage
} = context.getOptions()

context.cacheable(true)
Expand Down Expand Up @@ -128,7 +127,6 @@ async function loader(
unstable_defaultShowCopyCode,
unstable_staticImage,
unstable_flexsearch,
allowFutureImage
},
mdxPath
)
Expand Down
12 changes: 3 additions & 9 deletions packages/nextra/src/mdx-plugins/static-image.ts
Expand Up @@ -35,11 +35,8 @@ const getASTNodeImport = (name: string, from: string) => ({

// Based on the remark-embed-images project
// https://github.com/remarkjs/remark-embed-images
export const remarkStaticImage: Plugin<
[{ allowFutureImage?: boolean; filePath: string }],
Root
> =
({ allowFutureImage, filePath }) =>
export const remarkStaticImage: Plugin<[{ filePath: string }], Root> =
({ filePath }) =>
(tree, _file, done) => {
const importsToInject: any[] = []

Expand Down Expand Up @@ -118,10 +115,7 @@ export const remarkStaticImage: Plugin<
})

tree.children.unshift(
getASTNodeImport(
'$NextImageNextra',
allowFutureImage ? 'next/future/image' : 'next/image'
) as any,
getASTNodeImport('$NextImageNextra', 'next/image') as any,
...importsToInject
)
done()
Expand Down
1 change: 0 additions & 1 deletion packages/nextra/src/types.ts
Expand Up @@ -15,7 +15,6 @@ export interface LoaderOptions extends NextraConfig {
defaultLocale: string
pageMapCache: PageMapCache
newNextLinkBehavior?: boolean
allowFutureImage?: boolean
}

export interface Folder<FileType = PageMapItem> {
Expand Down

0 comments on commit a9414be

Please sign in to comment.