Unverified Commit 5da8ef12 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[image-optimization] Expose `next/image-optimizer-transform` as a public subpath (#99312)

Vercel's proxy service runs the image optimizer transform step in a child process and imports `next/dist/server/image-optimizer/transform` directly, which pins an internal file layout that should be free to change. This PR exposes the module as the public subpath `next/image-optimizer-transform`, following the existing `next/og` pattern of a root-level pass-through plus a type stub registered in the package `files` array. The new entry also re-exports `ImageError` and `getMaxAge` (both already in the module's dependency graph) so consumers can drop every deep `next/dist/server/image-optimizer/*` import, and the module header now states that its location and export surface are a stable contract. The existing unit test imports the module through the new subpath to keep it exercised, and a new API reference page documents `imageOptimizerTransform`, `optimizeImage`, `getSharp`, `getMaxAge`, and `ImageError`.

Verified with `pnpm test-unit test/unit/image-optimizer/transform.test.ts` (passes through the new subpath), `pnpm --filter=next types`, and an `npm pack --dry-run` confirming both stub files ship in the tarball. The 22 failures in the broader unit run reproduce on clean canary and are unrelated to this change.
parent c0c6790f
export * from './dist/server/image-optimizer/transform'
module.exports = require('./dist/server/image-optimizer/transform')
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
"head.d.ts", "head.d.ts",
"image.js", "image.js",
"image.d.ts", "image.d.ts",
"image-optimizer-transform.js",
"image-optimizer-transform.d.ts",
"link.js", "link.js",
"link.d.ts", "link.d.ts",
"offline.js", "offline.js",
......
// WARNING: Please keep this module lightweight with very few imports since // WARNING: This module is publicly exposed as `next/image-optimizer-transform`
// we intend to run it in a child process in the future. Please do NOT // and consumed outside this repo, so its location and export surface are a
// add new imports without considering their impact on its dependency graph. // stable contract. Please keep this module lightweight with very few imports
// since it runs in a child process. Please do NOT add new imports without
// considering their impact on its dependency graph.
import isAnimated from 'next/dist/compiled/is-animated' import isAnimated from 'next/dist/compiled/is-animated'
import type { NextConfigComplete } from '../config-shared' import type { NextConfigComplete } from '../config-shared'
import isError from '../../lib/is-error' import isError from '../../lib/is-error'
...@@ -22,6 +24,9 @@ import { getImageEtag } from './extract-etag' ...@@ -22,6 +24,9 @@ import { getImageEtag } from './extract-etag'
import { getMaxAge } from './get-max-age' import { getMaxAge } from './get-max-age'
import { ImageError } from './image-error' import { ImageError } from './image-error'
export { ImageError }
export { getMaxAge }
const ANIMATABLE_TYPES = [WEBP, PNG, GIF] const ANIMATABLE_TYPES = [WEBP, PNG, GIF]
const BYPASS_TYPES = [SVG, ICO, ICNS, BMP, JXL, HEIC] const BYPASS_TYPES = [SVG, ICO, ICNS, BMP, JXL, HEIC]
......
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
getSharp, getSharp,
imageOptimizerTransform, imageOptimizerTransform,
type ImageOptimizerTransformConfig, type ImageOptimizerTransformConfig,
} from 'next/dist/server/image-optimizer/transform' } from 'next/image-optimizer-transform'
import type { import type {
CachedRouteKind, CachedRouteKind,
IncrementalResponseCacheEntry, IncrementalResponseCacheEntry,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment