[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 {
const filenameURL = new URL(`file://${filename}`);
return fileURLToPath(filenameURL);
} catch(err) {
} catch (err) {
// Not a real file, so just use the provided filename as the normalized id
return filename;
}
@ -165,9 +165,9 @@ export function isCached(config: AstroConfig, filename: string) {
}
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);
if(!src) return null;
if (!src) return null;
return src.source;
}

View file

@ -6,7 +6,6 @@ import type { PluginMetadata as AstroPluginMetadata } from './types';
import ancestor from 'common-ancestor-path';
import esbuild from 'esbuild';
import fs from 'fs';
import slash from 'slash';
import { fileURLToPath } from 'url';
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.
// It should be in the compilation cache at this point.
let raw = await this.resolve(filename, undefined);
if(!raw) {
if (!raw) {
return null;
}
let source = getCachedSource(config, raw.id);
if(!source) {
if (!source) {
return null;
}
@ -125,14 +124,14 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
pluginContext: this,
};
switch(query.type) {
switch (query.type) {
case 'style': {
if (typeof query.index === 'undefined') {
throw new Error(`Requests for Astro CSS must include an index.`);
}
const transformResult = await cachedCompilation(compileProps);
// Track any CSS dependencies so that HMR is triggered when they change.
await trackCSSDependencies.call(this, {
viteDevServer,
@ -142,7 +141,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
});
const csses = transformResult.css;
const code = csses[query.index];
return {
code,
};
@ -157,15 +156,15 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
code: `/* client hoisted script, empty in SSR: ${id} */`,
};
}
const transformResult = await cachedCompilation(compileProps);
const scripts = transformResult.scripts;
const hoistedScript = scripts[query.index];
if (!hoistedScript) {
throw new Error(`No hoisted script at index ${query.index}`);
}
if (hoistedScript.type === 'external') {
const src = hoistedScript.src!;
if (src.startsWith('/') && !isBrowserPath(src)) {
@ -175,7 +174,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
);
}
}
return {
code:
hoistedScript.type === 'inline'
@ -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) {
@ -220,7 +220,6 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
viteTransform,
pluginContext: this,
};
try {
const transformResult = await cachedCompilation(compileProps);

View file

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