Skip to content

Commit b0aec7b

Browse files
[v6] remove emitESMImage() (#12403)
1 parent 3e61972 commit b0aec7b

File tree

2 files changed

+23
-42
lines changed

2 files changed

+23
-42
lines changed

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ import { ClientRouter } from 'astro:transitions';
102102

103103
<ReadMore>Read more about [view transitions and client-side routing in Astro](/en/guides/view-transitions/).</ReadMore>
104104

105+
### Removed: `emitESMImage()`
106+
107+
<SourcePR number="14426" title="feat!: remove emitESMImage()"/>
108+
109+
In Astro 5.6.2, the `emitESMImage()` function was deprecated in favor of `emitImageMetadata()`, which removes two deprecated arguments that were not meant to be exposed for public use: `_watchMode` and `experimentalSvgEnabled`.
110+
111+
Astro 6.0 removes `emitESMImage()` entirely. Update to `emitImageMetadata()` to keep your current behavior.
112+
113+
#### What should I do?
114+
115+
Replace all occurrences of the `emitESMImage()` with `emitImageMetadata()` and remove unused arguments:
116+
117+
```ts del={1,5} ins={2,6}
118+
import { emitESMImage } from 'astro/assets/utils';
119+
import { emitImageMetadata } from 'astro/assets/utils';
120+
121+
const imageId = '/images/photo.jpg';
122+
const result = await emitESMImage(imageId, false, false);
123+
const result = await emitImageMetadata(imageId);
124+
```
125+
126+
<ReadMore>Read more about [`emitImageMetadata()`](/en/reference/image-service-reference/#emitimagemetadata).</ReadMore>
127+
105128
## Changed Defaults
106129

107130
Some default behavior has changed in Astro v5.0 and your project code may need updating to account for these changes.

src/content/docs/en/reference/image-service-reference.mdx

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -601,48 +601,6 @@ async function extractImageMetadata() {
601601
await extractImageMetadata();
602602
```
603603

604-
### `emitESMImage()`
605-
606-
:::caution[Deprecated]
607-
Use the [`emitImageMetadata`](#emitimagemetadata) function instead.
608-
:::
609-
610-
<p>
611-
**Type:** `(id: string | undefined, _watchMode: boolean, experimentalSvgEnabled: boolean, fileEmitter?: FileEmitter) => Promise<ImageMetadataWithContents | undefined>`<br />
612-
<Since v="4.0.0" />
613-
</p>
614-
615-
616-
Processes an image file and emits its metadata and optionally its contents. In build mode, the function uses `fileEmitter` to generate an asset reference. In development mode, it resolves to a local file URL with query parameters for metadata.
617-
618-
```ts
619-
620-
import { emitESMImage } from 'astro/assets/utils';
621-
622-
const imageId = '/images/photo.jpg';
623-
const unusedWatchMode = false; // Deprecated, unused
624-
const unusedExperimentalSvgEnabled = false; // Set to `true` only if you are using SVG and want the file data to be embedded
625-
626-
try {
627-
const result = await emitESMImage(imageId, unusedWatchMode, unusedExperimentalSvgEnabled);
628-
if (result) {
629-
console.log('Image metadata with contents:', result);
630-
// Example output:
631-
// {
632-
// width: 800,
633-
// height: 600,
634-
// format: 'jpg',
635-
// contents: Uint8Array([...])
636-
// }
637-
} else {
638-
console.log('No metadata was emitted for this image.');
639-
}
640-
} catch (error) {
641-
console.error('Failed to emit ESM image:', error);
642-
}
643-
644-
```
645-
646604
### `emitImageMetadata()`
647605

648606
<p>

0 commit comments

Comments
 (0)