Repository: withastro/astro
File: packages/astro/src/assets/vite-plugin-assets.ts (TypeScript)

Code before:
					}

					// If the requested ID doesn't end with a valid image extension, we'll let Vite handle it
					if (!assetRegexEnds.test(id)) {
						return;
					}

					const emitFile = shouldEmitFile ? this.emitFile.bind(this) : undefined;
					const imageMetadata = await emitESMImage(
						id,
						this.meta.watchMode,
						!!settings.config.experimental.svg,
						emitFile,
					);

					if (!imageMetadata) {
						throw new AstroError({
							...AstroErrorData.ImageNotFound,
							message: AstroErrorData.ImageNotFound.message(id),
						});
					}

					if (settings.config.experimental.svg && /\.svg$/.test(id)) {
						const { contents, ...metadata } = imageMetadata;
						// We know that the contents are present, as we only emit this property for SVG files
						return {
							code: makeSvgComponent(metadata, contents!, {
								mode: settings.config.experimental.svg.mode,
							}),
							moduleType: 'js',
						};
					}

					// We can only reliably determine if an image is used on the server, as we need to track its usage throughout the entire build.
					// Since you cannot use image optimization on the client anyway, it's safe to assume that if the user imported
					// an image on the client, it should be present in the final build.
					if (options?.ssr) {
						return {
							code: `export default ${getProxyCode(
								imageMetadata,
								settings.buildOutput === 'server',
							)}`,
							moduleType: 'js',
						};
					} else {
						globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath);
						return {
							code: `export default ${JSON.stringify(imageMetadata)}`,
							moduleType: 'js',
						};
					}

Review comment (suggestion):
Makes it an object that returns `code` (rollup/rolldown compatible shape) and `moduleType` (only rolldown I think)

Code after:

					// If the requested ID doesn't end with a valid image extension, we'll let Vite handle it
					if (!assetRegexEnds.test(id)) {
						return;
					}

					const emitFile = shouldEmitFile ? this.emitFile.bind(this) : undefined;
					const imageMetadata = await emitESMImage(
						id,
						this.meta.watchMode,
						!!settings.config.experimental.svg,
						emitFile,
					);

					if (!imageMetadata) {
						throw new AstroError({
							...AstroErrorData.ImageNotFound,
							message: AstroErrorData.ImageNotFound.message(id),
						});
					}

					if (settings.config.experimental.svg && /\.svg$/.test(id)) {
						const { contents, ...metadata } = imageMetadata;
						// We know that the contents are present, as we only emit this property for SVG files
						return { code: makeSvgComponent(metadata, contents!) };
					}

					// We can only reliably determine if an image is used on the server, as we need to track its usage throughout the entire build.
					// Since you cannot use image optimization on the client anyway, it's safe to assume that if the user imported
					// an image on the client, it should be present in the final build.
					if (options?.ssr) {
						return {
							code: `export default ${getProxyCode(
								imageMetadata,
								settings.buildOutput === 'server',
							)}`,
						};
					} else {
						globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath);
						return {
							code: `export default ${JSON.stringify(imageMetadata)}`,
						};
					}
				}
			},
		},
	];
}