[ci] format

This commit is contained in:
matthewp 2022-07-11 20:15:17 +00:00 committed by fredkbot
parent 5f4ecbad1b
commit 14ed29c645
3 changed files with 18 additions and 21 deletions

View file

@ -51,7 +51,7 @@ function getNormalizedID(filename: string): string {
try { try {
const filenameURL = new URL(`file://${filename}`); const filenameURL = new URL(`file://${filename}`);
return fileURLToPath(filenameURL); return fileURLToPath(filenameURL);
} catch(err) { } catch (err) {
// Not a real file, so just use the provided filename as the normalized id // Not a real file, so just use the provided filename as the normalized id
return filename; return filename;
} }
@ -165,9 +165,9 @@ export function isCached(config: AstroConfig, filename: string) {
} }
export function getCachedSource(config: AstroConfig, filename: string): string | null { export function getCachedSource(config: AstroConfig, filename: string): string | null {
if(!isCached(config, filename)) return null; if (!isCached(config, filename)) return null;
let src = configCache.get(config)!.get(filename); let src = configCache.get(config)!.get(filename);
if(!src) return null; if (!src) return null;
return src.source; return src.source;
} }

View file

@ -6,7 +6,6 @@ import type { PluginMetadata as AstroPluginMetadata } from './types';
import ancestor from 'common-ancestor-path'; import ancestor from 'common-ancestor-path';
import esbuild from 'esbuild'; import esbuild from 'esbuild';
import fs from 'fs';
import slash from 'slash'; import slash from 'slash';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import { isRelativePath, startsWithForwardSlash } from '../core/path.js'; import { isRelativePath, startsWithForwardSlash } from '../core/path.js';
@ -106,12 +105,12 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
// For CSS / hoisted scripts we need to load the source ourselves. // For CSS / hoisted scripts we need to load the source ourselves.
// It should be in the compilation cache at this point. // It should be in the compilation cache at this point.
let raw = await this.resolve(filename, undefined); let raw = await this.resolve(filename, undefined);
if(!raw) { if (!raw) {
return null; return null;
} }
let source = getCachedSource(config, raw.id); let source = getCachedSource(config, raw.id);
if(!source) { if (!source) {
return null; return null;
} }
@ -125,7 +124,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
pluginContext: this, pluginContext: this,
}; };
switch(query.type) { switch (query.type) {
case 'style': { case 'style': {
if (typeof query.index === 'undefined') { if (typeof query.index === 'undefined') {
throw new Error(`Requests for Astro CSS must include an index.`); throw new Error(`Requests for Astro CSS must include an index.`);
@ -188,7 +187,8 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
}, },
}; };
} }
default: return null; default:
return null;
} }
}, },
async transform(this: PluginContext, source, id, opts) { async transform(this: PluginContext, source, id, opts) {
@ -221,7 +221,6 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
pluginContext: this, pluginContext: this,
}; };
try { try {
const transformResult = await cachedCompilation(compileProps); const transformResult = await cachedCompilation(compileProps);
const { fileId: file, fileUrl: url } = getFileInfo(id, config); const { fileId: file, fileUrl: url } = getFileInfo(id, config);

View file

@ -1,4 +1,3 @@
import { transform } from '@astrojs/compiler';
import { renderMarkdown } from '@astrojs/markdown-remark'; import { renderMarkdown } from '@astrojs/markdown-remark';
import ancestor from 'common-ancestor-path'; import ancestor from 'common-ancestor-path';
import esbuild from 'esbuild'; import esbuild from 'esbuild';
@ -9,11 +8,10 @@ import type { Plugin } from 'vite';
import type { AstroConfig } from '../@types/astro'; import type { AstroConfig } from '../@types/astro';
import { pagesVirtualModuleId } from '../core/app/index.js'; import { pagesVirtualModuleId } from '../core/app/index.js';
import { collectErrorMetadata } from '../core/errors.js'; import { collectErrorMetadata } from '../core/errors.js';
import { prependForwardSlash } from '../core/path.js'; import { resolvePages } from '../core/util.js';
import { resolvePages, viteID } from '../core/util.js';
import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types';
import { cachedCompilation, CompileProps } from '../vite-plugin-astro/compile.js'; import { cachedCompilation, CompileProps } from '../vite-plugin-astro/compile.js';
import { getViteTransform, TransformHook } from '../vite-plugin-astro/styles.js'; import { getViteTransform, TransformHook } from '../vite-plugin-astro/styles.js';
import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types';
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js'; import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
import { getFileInfo } from '../vite-plugin-utils/index.js'; import { getFileInfo } from '../vite-plugin-utils/index.js';
@ -191,7 +189,7 @@ ${setup}`.trim();
pluginContext: this, pluginContext: this,
}; };
let transformResult = await cachedCompilation(compileProps) let transformResult = await cachedCompilation(compileProps);
let { code: tsResult } = transformResult; let { code: tsResult } = transformResult;
tsResult = `\nexport const metadata = ${JSON.stringify(metadata)}; tsResult = `\nexport const metadata = ${JSON.stringify(metadata)};