chore(lint): Prettier fix
This commit is contained in:
parent
19e2b5c56c
commit
b7ff454453
16 changed files with 120 additions and 105 deletions
|
@ -2,10 +2,10 @@
|
|||
export default {
|
||||
data() {
|
||||
return {
|
||||
greeting: 'Hello World!'
|
||||
}
|
||||
}
|
||||
}
|
||||
greeting: 'Hello World!',
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -78,7 +78,7 @@ class AstroBuilder {
|
|||
manifest: this.manifest,
|
||||
origin,
|
||||
routeCache: this.routeCache,
|
||||
viteServer: this.viteServer
|
||||
viteServer: this.viteServer,
|
||||
});
|
||||
debug(logging, 'build', timerMessage('All pages loaded', timer.loadStart));
|
||||
|
||||
|
@ -97,7 +97,7 @@ class AstroBuilder {
|
|||
logging: this.logging,
|
||||
origin: this.origin,
|
||||
routeCache: this.routeCache,
|
||||
viteConfig: this.viteConfig
|
||||
viteConfig: this.viteConfig,
|
||||
});
|
||||
} else {
|
||||
await scanBasedBuild({
|
||||
|
|
|
@ -39,7 +39,7 @@ export async function build(opts: ScanBasedBuildOptions) {
|
|||
// The `input` will be populated in the build rollup plugin.
|
||||
input: [],
|
||||
output: {
|
||||
format: 'esm'
|
||||
format: 'esm',
|
||||
},
|
||||
},
|
||||
target: 'es2020', // must match an esbuild target
|
||||
|
@ -56,7 +56,7 @@ export async function build(opts: ScanBasedBuildOptions) {
|
|||
viteServer,
|
||||
}),
|
||||
rollupPluginAstroBuildCSS({
|
||||
internals
|
||||
internals,
|
||||
}),
|
||||
...(viteConfig.plugins || []),
|
||||
],
|
||||
|
|
|
@ -53,7 +53,7 @@ export async function staticBuild(opts: StaticBuildOptions) {
|
|||
const internals = createBuildInternals();
|
||||
|
||||
// Perform the SSR build
|
||||
const result = (await ssrBuild(opts, internals, jsInput) as RollupOutput);
|
||||
const result = (await ssrBuild(opts, internals, jsInput)) as RollupOutput;
|
||||
|
||||
// Generate each of the pages.
|
||||
await generatePages(result, opts, internals, facadeIdToPageDataMap);
|
||||
|
@ -73,7 +73,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
|||
rollupOptions: {
|
||||
input: Array.from(input),
|
||||
output: {
|
||||
format: 'esm'
|
||||
format: 'esm',
|
||||
},
|
||||
},
|
||||
target: 'es2020', // must match an esbuild target
|
||||
|
@ -81,7 +81,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
|||
plugins: [
|
||||
vitePluginNewBuild(),
|
||||
rollupPluginAstroBuildCSS({
|
||||
internals
|
||||
internals,
|
||||
}),
|
||||
...(viteConfig.plugins || []),
|
||||
],
|
||||
|
@ -98,15 +98,12 @@ async function generatePages(result: RollupOutput, opts: StaticBuildOptions, int
|
|||
const generationPromises = [];
|
||||
for (let output of result.output) {
|
||||
if (output.type === 'chunk' && output.facadeModuleId) {
|
||||
generationPromises.push(
|
||||
generatePage(output, opts, internals, facadeIdToPageDataMap)
|
||||
);
|
||||
generationPromises.push(generatePage(output, opts, internals, facadeIdToPageDataMap));
|
||||
}
|
||||
}
|
||||
await Promise.all(generationPromises);
|
||||
}
|
||||
|
||||
|
||||
async function generatePage(output: OutputChunk, opts: StaticBuildOptions, internals: BuildInternals, facadeIdToPageDataMap: Map<string, PageBuildData>) {
|
||||
const { astroConfig } = opts;
|
||||
|
||||
|
@ -120,11 +117,11 @@ async function generatePage(output: OutputChunk, opts: StaticBuildOptions, inter
|
|||
const generationOptions: Readonly<GeneratePathOptions> = {
|
||||
pageData,
|
||||
linkIds,
|
||||
Component
|
||||
Component,
|
||||
};
|
||||
|
||||
const renderPromises = pageData.paths.map(path => {
|
||||
return generatePath(path, opts, generationOptions)
|
||||
const renderPromises = pageData.paths.map((path) => {
|
||||
return generatePath(path, opts, generationOptions);
|
||||
});
|
||||
return await Promise.all(renderPromises);
|
||||
}
|
||||
|
@ -147,7 +144,7 @@ async function generatePath(path: string, opts: StaticBuildOptions, gopts: Gener
|
|||
routeCache,
|
||||
logging,
|
||||
pathname: path,
|
||||
mod
|
||||
mod,
|
||||
});
|
||||
|
||||
info(logging, 'generate', `Generating: ${path}`);
|
||||
|
@ -157,14 +154,11 @@ async function generatePath(path: string, opts: StaticBuildOptions, gopts: Gener
|
|||
const outFile = new URL('./index.html', outFolder);
|
||||
await fs.promises.mkdir(outFolder, { recursive: true });
|
||||
await fs.promises.writeFile(outFile, html, 'utf-8');
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Error rendering:`, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function vitePluginNewBuild(): VitePlugin {
|
||||
return {
|
||||
name: '@astro/rollup-plugin-new-build',
|
||||
|
@ -185,9 +179,9 @@ export function vitePluginNewBuild(): VitePlugin {
|
|||
},
|
||||
chunkFileNames(_chunk: PreRenderedChunk) {
|
||||
return 'assets/[name].[hash].mjs';
|
||||
}
|
||||
},
|
||||
});
|
||||
return outputOptions;
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
|
@ -58,7 +58,7 @@ export const AstroConfigSchema = z.object({
|
|||
.union([z.literal('file'), z.literal('directory')])
|
||||
.optional()
|
||||
.default('directory'),
|
||||
experimentalStaticBuild: z.boolean().optional().default(false)
|
||||
experimentalStaticBuild: z.boolean().optional().default(false),
|
||||
})
|
||||
.optional()
|
||||
.default({}),
|
||||
|
|
|
@ -139,14 +139,25 @@ export async function preload({ astroConfig, filePath, viteServer }: SSROptions)
|
|||
return [renderers, mod];
|
||||
}
|
||||
|
||||
export async function renderComponent(renderers: Renderer[], Component: AstroComponentFactory, astroConfig: AstroConfig, pathname: string, origin: string, params: Params, pageProps: Props, links: string[] = []): Promise<string> {
|
||||
const _links = new Set<SSRElement>(links.map(href => ({
|
||||
export async function renderComponent(
|
||||
renderers: Renderer[],
|
||||
Component: AstroComponentFactory,
|
||||
astroConfig: AstroConfig,
|
||||
pathname: string,
|
||||
origin: string,
|
||||
params: Params,
|
||||
pageProps: Props,
|
||||
links: string[] = []
|
||||
): Promise<string> {
|
||||
const _links = new Set<SSRElement>(
|
||||
links.map((href) => ({
|
||||
props: {
|
||||
rel: 'stylesheet',
|
||||
href
|
||||
href,
|
||||
},
|
||||
children: ''
|
||||
})));
|
||||
children: '',
|
||||
}))
|
||||
);
|
||||
const result: SSRResult = {
|
||||
styles: new Set<SSRElement>(),
|
||||
scripts: new Set<SSRElement>(),
|
||||
|
@ -188,7 +199,7 @@ export async function renderComponent(renderers: Renderer[], Component: AstroCom
|
|||
_metadata: {
|
||||
renderers,
|
||||
pathname,
|
||||
experimentalStaticBuild: astroConfig.buildOptions.experimentalStaticBuild
|
||||
experimentalStaticBuild: astroConfig.buildOptions.experimentalStaticBuild,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -197,7 +208,19 @@ export async function renderComponent(renderers: Renderer[], Component: AstroCom
|
|||
return html;
|
||||
}
|
||||
|
||||
export async function getParamsAndProps({route, routeCache, logging, pathname, mod}: {route: RouteData | undefined, routeCache: RouteCache, pathname: string, mod: ComponentInstance, logging: LogOptions}): Promise<[Params, Props]> {
|
||||
export async function getParamsAndProps({
|
||||
route,
|
||||
routeCache,
|
||||
logging,
|
||||
pathname,
|
||||
mod,
|
||||
}: {
|
||||
route: RouteData | undefined;
|
||||
routeCache: RouteCache;
|
||||
pathname: string;
|
||||
mod: ComponentInstance;
|
||||
logging: LogOptions;
|
||||
}): Promise<[Params, Props]> {
|
||||
// Handle dynamic routes
|
||||
let params: Params = {};
|
||||
let pageProps: Props = {};
|
||||
|
@ -318,7 +341,7 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
|
|||
_metadata: {
|
||||
renderers,
|
||||
pathname,
|
||||
experimentalStaticBuild: astroConfig.buildOptions.experimentalStaticBuild
|
||||
experimentalStaticBuild: astroConfig.buildOptions.experimentalStaticBuild,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -372,8 +372,9 @@ const uniqueElements = (item: any, index: number, all: any[]) => {
|
|||
// styles and scripts into the head.
|
||||
export async function renderPage(result: SSRResult, Component: AstroComponentFactory, props: any, children: any) {
|
||||
const template = await renderToString(result, Component, props, children);
|
||||
const styles = result._metadata.experimentalStaticBuild ? [] :
|
||||
Array.from(result.styles)
|
||||
const styles = result._metadata.experimentalStaticBuild
|
||||
? []
|
||||
: Array.from(result.styles)
|
||||
.filter(uniqueElements)
|
||||
.map((style) =>
|
||||
renderElement('style', {
|
||||
|
@ -399,7 +400,7 @@ export async function renderPage(result: SSRResult, Component: AstroComponentFac
|
|||
|
||||
const links = Array.from(result.links)
|
||||
.filter(uniqueElements)
|
||||
.map(link => renderElement('link', link))
|
||||
.map((link) => renderElement('link', link));
|
||||
|
||||
// inject styles & scripts at end of <head>
|
||||
let headPos = template.indexOf('</head>');
|
||||
|
|
|
@ -30,8 +30,7 @@ async function compile(config: AstroConfig, filename: string, source: string, vi
|
|||
// pages and layouts should be transformed as full documents (implicit <head> <body> etc)
|
||||
// everything else is treated as a fragment
|
||||
const normalizedID = fileURLToPath(new URL(`file://${filename}`));
|
||||
const isPage = normalizedID.startsWith(fileURLToPath(config.pages)) ||
|
||||
normalizedID.startsWith(fileURLToPath(config.layouts));
|
||||
const isPage = normalizedID.startsWith(fileURLToPath(config.pages)) || normalizedID.startsWith(fileURLToPath(config.layouts));
|
||||
//let source = await fs.promises.readFile(id, 'utf8');
|
||||
let cssTransformError: Error | undefined;
|
||||
|
||||
|
@ -51,10 +50,11 @@ async function compile(config: AstroConfig, filename: string, source: string, vi
|
|||
const lang = `.${attrs?.lang || 'css'}`.toLowerCase();
|
||||
try {
|
||||
const result = await transformWithVite({
|
||||
value, lang,
|
||||
value,
|
||||
lang,
|
||||
id: filename,
|
||||
transformHook: viteTransform,
|
||||
ssr: isSSR(opts)
|
||||
ssr: isSSR(opts),
|
||||
});
|
||||
|
||||
let map: SourceMapInput | undefined;
|
||||
|
|
|
@ -37,8 +37,7 @@ export default function astro({ config }: AstroPluginOptions): vite.Plugin {
|
|||
if (filename.startsWith('/') && !filename.startsWith(config.projectRoot.pathname)) {
|
||||
filename = new URL('.' + filename, config.projectRoot).pathname;
|
||||
}
|
||||
const transformResult = await cachedCompilation(config, filename, null,
|
||||
viteTransform, opts);
|
||||
const transformResult = await cachedCompilation(config, filename, null, viteTransform, opts);
|
||||
|
||||
if (typeof query.index === 'undefined') {
|
||||
throw new Error(`Requests for Astro CSS must include an index.`);
|
||||
|
@ -48,7 +47,7 @@ export default function astro({ config }: AstroPluginOptions): vite.Plugin {
|
|||
const code = csses[query.index];
|
||||
|
||||
return {
|
||||
code
|
||||
code,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -61,15 +60,14 @@ export default function astro({ config }: AstroPluginOptions): vite.Plugin {
|
|||
}
|
||||
|
||||
try {
|
||||
const transformResult = await cachedCompilation(config, id, source,
|
||||
viteTransform, opts);
|
||||
const transformResult = await cachedCompilation(config, id, source, viteTransform, opts);
|
||||
|
||||
// Compile all TypeScript to JavaScript.
|
||||
// Also, catches invalid JS/TS in the compiled output before returning.
|
||||
const { code, map } = await esbuild.transform(transformResult.code, {
|
||||
loader: 'ts',
|
||||
sourcemap: 'external',
|
||||
sourcefile: id
|
||||
sourcefile: id,
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -126,11 +124,10 @@ export default function astro({ config }: AstroPluginOptions): vite.Plugin {
|
|||
|
||||
throw err;
|
||||
}
|
||||
|
||||
},
|
||||
async handleHotUpdate(context) {
|
||||
// Invalidate the compilation cache so it recompiles
|
||||
invalidateCompilation(config, context.file);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
export interface AstroQuery {
|
||||
astro?: boolean
|
||||
src?: boolean
|
||||
type?: 'script' | 'template' | 'style' | 'custom'
|
||||
index?: number
|
||||
lang?: string
|
||||
raw?: boolean
|
||||
astro?: boolean;
|
||||
src?: boolean;
|
||||
type?: 'script' | 'template' | 'style' | 'custom';
|
||||
index?: number;
|
||||
lang?: string;
|
||||
raw?: boolean;
|
||||
}
|
||||
|
||||
// Parses an id to check if its an Astro request.
|
||||
// CSS is imported like `import '/src/pages/index.astro?astro&type=style&index=0&lang.css';
|
||||
// This parses those ids and returns an object representing what it found.
|
||||
export function parseAstroRequest(id: string): {
|
||||
filename: string
|
||||
query: AstroQuery
|
||||
filename: string;
|
||||
query: AstroQuery;
|
||||
} {
|
||||
const [filename, rawQuery] = id.split(`?`, 2);
|
||||
const query = Object.fromEntries(new URLSearchParams(rawQuery).entries()) as AstroQuery;
|
||||
if (query.astro != null) {
|
||||
query.astro = true
|
||||
query.astro = true;
|
||||
}
|
||||
if (query.src != null) {
|
||||
query.src = true
|
||||
query.src = true;
|
||||
}
|
||||
if (query.index != null) {
|
||||
query.index = Number(query.index)
|
||||
query.index = Number(query.index);
|
||||
}
|
||||
if (query.raw != null) {
|
||||
query.raw = true
|
||||
query.raw = true;
|
||||
}
|
||||
return {
|
||||
filename,
|
||||
query
|
||||
}
|
||||
query,
|
||||
};
|
||||
}
|
|
@ -234,7 +234,7 @@ export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin {
|
|||
return `assets/${pageName}.[hash].js`;
|
||||
}
|
||||
return 'assets/[name].[hash].js';
|
||||
}
|
||||
},
|
||||
});
|
||||
return outputOptions;
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue