0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

[ci] format

This commit is contained in:
Matthew Phillips 2024-04-23 11:59:51 +00:00 committed by astrobot-houston
parent 3294f7a343
commit 10c5b039f9
3 changed files with 11 additions and 7 deletions

View file

@ -1,9 +1,9 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type * as vite from 'vite';
import { prependForwardSlash, slash } from '../../core/path.js';
import type { ImageMetadata } from '../types.js';
import type * as vite from 'vite';
import { imageMetadata } from './metadata.js';
type FileEmitter = vite.Rollup.EmitFile;
@ -14,7 +14,7 @@ export async function emitESMImage(
_watchMode: boolean,
// FIX: in Astro 5, this function should not be passed in dev mode at all.
// Or rethink the API so that a function that throws isn't passed through.
fileEmitter?: FileEmitter,
fileEmitter?: FileEmitter
): Promise<ImageMetadata | undefined> {
if (!id) {
return undefined;
@ -44,7 +44,7 @@ export async function emitESMImage(
// Build
let isBuild = typeof fileEmitter === 'function';
if(isBuild) {
if (isBuild) {
const pathname = decodeURI(url.pathname);
const filename = path.basename(pathname, path.extname(pathname) + `.${fileMetadata.format}`);
@ -62,7 +62,7 @@ export async function emitESMImage(
}
}
if(!isBuild) {
if (!isBuild) {
// Pass the original file information through query params so we don't have to load the file twice
url.searchParams.append('origWidth', fileMetadata.width.toString());
url.searchParams.append('origHeight', fileMetadata.height.toString());

View file

@ -2,14 +2,18 @@ import type { PluginContext } from 'rollup';
import { z } from 'zod';
import { emitESMImage } from '../assets/utils/emitAsset.js';
export function createImage(pluginContext: PluginContext, shouldEmitFile: boolean, entryFilePath: string) {
export function createImage(
pluginContext: PluginContext,
shouldEmitFile: boolean,
entryFilePath: string
) {
return () => {
return z.string().transform(async (imagePath, ctx) => {
const resolvedFilePath = (await pluginContext.resolve(imagePath, entryFilePath))?.id;
const metadata = await emitESMImage(
resolvedFilePath,
pluginContext.meta.watchMode,
shouldEmitFile ? pluginContext.emitFile : undefined,
shouldEmitFile ? pluginContext.emitFile : undefined
);
if (!metadata) {

View file

@ -265,7 +265,7 @@ async function getDataEntryModule(
{ id, collection, _internal, unvalidatedData },
collectionConfig,
params.shouldEmitFile,
pluginContext,
pluginContext
)
: unvalidatedData;