[ci] format
This commit is contained in:
parent
5f4ecbad1b
commit
14ed29c645
3 changed files with 18 additions and 21 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,14 +124,14 @@ 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.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformResult = await cachedCompilation(compileProps);
|
const transformResult = await cachedCompilation(compileProps);
|
||||||
|
|
||||||
// Track any CSS dependencies so that HMR is triggered when they change.
|
// Track any CSS dependencies so that HMR is triggered when they change.
|
||||||
await trackCSSDependencies.call(this, {
|
await trackCSSDependencies.call(this, {
|
||||||
viteDevServer,
|
viteDevServer,
|
||||||
|
@ -142,7 +141,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
||||||
});
|
});
|
||||||
const csses = transformResult.css;
|
const csses = transformResult.css;
|
||||||
const code = csses[query.index];
|
const code = csses[query.index];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code,
|
code,
|
||||||
};
|
};
|
||||||
|
@ -157,15 +156,15 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
||||||
code: `/* client hoisted script, empty in SSR: ${id} */`,
|
code: `/* client hoisted script, empty in SSR: ${id} */`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformResult = await cachedCompilation(compileProps);
|
const transformResult = await cachedCompilation(compileProps);
|
||||||
const scripts = transformResult.scripts;
|
const scripts = transformResult.scripts;
|
||||||
const hoistedScript = scripts[query.index];
|
const hoistedScript = scripts[query.index];
|
||||||
|
|
||||||
if (!hoistedScript) {
|
if (!hoistedScript) {
|
||||||
throw new Error(`No hoisted script at index ${query.index}`);
|
throw new Error(`No hoisted script at index ${query.index}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hoistedScript.type === 'external') {
|
if (hoistedScript.type === 'external') {
|
||||||
const src = hoistedScript.src!;
|
const src = hoistedScript.src!;
|
||||||
if (src.startsWith('/') && !isBrowserPath(src)) {
|
if (src.startsWith('/') && !isBrowserPath(src)) {
|
||||||
|
@ -175,7 +174,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code:
|
code:
|
||||||
hoistedScript.type === 'inline'
|
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) {
|
async transform(this: PluginContext, source, id, opts) {
|
||||||
|
@ -220,7 +220,6 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
||||||
viteTransform,
|
viteTransform,
|
||||||
pluginContext: this,
|
pluginContext: this,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const transformResult = await cachedCompilation(compileProps);
|
const transformResult = await cachedCompilation(compileProps);
|
||||||
|
|
|
@ -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)};
|
||||||
|
|
Loading…
Reference in a new issue