Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Apr 23, 2024
1 parent 3294f7a commit 10c5b03
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/astro/src/assets/utils/emitAsset.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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}`);

Expand All @@ -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());
Expand Down
8 changes: 6 additions & 2 deletions packages/astro/src/content/runtime-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/content/vite-plugin-content-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ async function getDataEntryModule(
{ id, collection, _internal, unvalidatedData },
collectionConfig,
params.shouldEmitFile,
pluginContext,
pluginContext
)
: unvalidatedData;

Expand Down

0 comments on commit 10c5b03

Please sign in to comment.