diff options
-rw-r--r-- | packages/astro/src/core/app/index.ts | 14 | ||||
-rw-r--r-- | packages/astro/src/core/build/generate.ts | 6 | ||||
-rw-r--r-- | packages/astro/src/core/build/internal.ts | 29 | ||||
-rw-r--r-- | packages/astro/src/core/build/static-build.ts | 3 | ||||
-rw-r--r-- | packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/core/build/vite-plugin-pages.ts | 15 | ||||
-rw-r--r-- | packages/astro/src/core/build/vite-plugin-ssr.ts | 12 | ||||
-rw-r--r-- | packages/astro/src/core/util.ts | 1 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-build-css/index.ts | 4 | ||||
-rw-r--r-- | packages/astro/test/ssr-api-route.test.js | 2 | ||||
-rw-r--r-- | packages/astro/test/test-adapter.js | 2 | ||||
-rw-r--r-- | packages/astro/test/test-utils.js | 4 | ||||
-rw-r--r-- | packages/integrations/node/src/server.ts | 2 |
13 files changed, 46 insertions, 50 deletions
diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 050802ee0..404492398 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -43,9 +43,9 @@ export class App { const mod = this.#manifest.pageMap.get(routeData.component)!; - if(routeData.type === 'page') { + if (routeData.type === 'page') { return this.#renderPage(request, routeData, mod); - } else if(routeData.type === 'endpoint') { + } else if (routeData.type === 'endpoint') { return this.#callEndpoint(request, routeData, mod); } else { throw new Error(`Unsupported route type [${routeData.type}].`); @@ -95,8 +95,8 @@ export class App { status: 200, headers: { 'Content-Type': 'text/html', - 'Content-Length': bytes.byteLength.toString() - } + 'Content-Length': bytes.byteLength.toString(), + }, }); } @@ -113,20 +113,20 @@ export class App { ssr: true, }); - if(result.type === 'response') { + if (result.type === 'response') { return result.response; } else { const body = result.body; const headers = new Headers(); const mimeType = mime.getType(url.pathname); - if(mimeType) { + if (mimeType) { headers.set('Content-Type', mimeType); } const bytes = this.#encoder.encode(body); headers.set('Content-Length', bytes.byteLength.toString()); return new Response(bytes, { status: 200, - headers + headers, }); } } diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index cbd5b3c2b..b4e77a9e0 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -74,7 +74,7 @@ export async function generatePages(result: RollupOutput, opts: StaticBuildOptio const ssrEntryURL = new URL(`./entry.mjs?time=${Date.now()}`, outFolder); const ssrEntry = await import(ssrEntryURL.toString()); - for(const pageData of eachPageData(internals)) { + for (const pageData of eachPageData(internals)) { await generatePage(opts, internals, pageData, ssrEntry); } } @@ -86,7 +86,7 @@ async function generatePage( pageData: PageBuildData, ssrEntry: SingleFileBuiltModule ) { - let timeStart = performance.now(); + let timeStart = performance.now(); const renderers = ssrEntry.renderers; const pageInfo = getPageDataByComponent(internals, pageData.route.component); @@ -95,7 +95,7 @@ async function generatePage( const pageModule = ssrEntry.pageMap.get(pageData.component); - if(!pageModule) { + if (!pageModule) { throw new Error(`Unable to find the module for ${pageData.component}. This is unexpected and likely a bug in Astro, please report.`); } diff --git a/packages/astro/src/core/build/internal.ts b/packages/astro/src/core/build/internal.ts index 62186f678..c436b9c5c 100644 --- a/packages/astro/src/core/build/internal.ts +++ b/packages/astro/src/core/build/internal.ts @@ -32,15 +32,15 @@ export interface BuildInternals { chunkToReferenceIdMap: Map<string, string>; /** - * This is a mapping of pathname to the string source of all collected inline <style> for a page. - * @deprecated This Map is only used for the legacy build. - */ + * This is a mapping of pathname to the string source of all collected inline <style> for a page. + * @deprecated This Map is only used for the legacy build. + */ astroStyleMap: Map<string, string>; - + /** - * This is a virtual JS module that imports all dependent styles for a page. - * @deprecated This Map is only used for the legacy build. - */ + * This is a virtual JS module that imports all dependent styles for a page. + * @deprecated This Map is only used for the legacy build. + */ astroPageStyleMap: Map<string, string>; } @@ -82,30 +82,29 @@ export function trackPageData(internals: BuildInternals, component: string, page internals.pagesByViteID.set(viteID(componentURL), pageData); } - -export function * getPageDatasByChunk(internals: BuildInternals, chunk: RenderedChunk): Generator<PageBuildData, void, unknown> { +export function* getPageDatasByChunk(internals: BuildInternals, chunk: RenderedChunk): Generator<PageBuildData, void, unknown> { const pagesByViteID = internals.pagesByViteID; - for(const [modulePath] of Object.entries(chunk.modules)) { - if(pagesByViteID.has(modulePath)) { + for (const [modulePath] of Object.entries(chunk.modules)) { + if (pagesByViteID.has(modulePath)) { yield pagesByViteID.get(modulePath)!; } } } export function getPageDataByComponent(internals: BuildInternals, component: string): PageBuildData | undefined { - if(internals.pagesByComponent.has(component)) { + if (internals.pagesByComponent.has(component)) { return internals.pagesByComponent.get(component); } return undefined; } export function getPageDataByViteID(internals: BuildInternals, viteid: ViteID): PageBuildData | undefined { - if(internals.pagesByViteID.has(viteid)) { + if (internals.pagesByViteID.has(viteid)) { return internals.pagesByViteID.get(viteid); } return undefined; } -export function * eachPageData(internals: BuildInternals) { - yield * internals.pagesByComponent.values(); +export function* eachPageData(internals: BuildInternals) { + yield* internals.pagesByComponent.values(); } diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 64579c2c8..337bc1d59 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -150,8 +150,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp }), ...(viteConfig.plugins || []), // SSR needs to be last - isBuildingToSSR(opts.astroConfig) && - vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter!), + isBuildingToSSR(opts.astroConfig) && vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter!), ], publicDir: ssr ? false : viteConfig.publicDir, root: viteConfig.root, diff --git a/packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts b/packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts index bad98209e..8f2480a63 100644 --- a/packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts +++ b/packages/astro/src/core/build/vite-plugin-hoisted-scripts.ts @@ -41,7 +41,7 @@ export function vitePluginHoistedScripts(astroConfig: AstroConfig, internals: Bu const vid = viteID(new URL('.' + pathname, astroConfig.projectRoot)); const pageInfo = getPageDataByViteID(internals, vid); - if(pageInfo) { + if (pageInfo) { pageInfo.hoistedScript = id; } } diff --git a/packages/astro/src/core/build/vite-plugin-pages.ts b/packages/astro/src/core/build/vite-plugin-pages.ts index 1a01e9672..22991c8ae 100644 --- a/packages/astro/src/core/build/vite-plugin-pages.ts +++ b/packages/astro/src/core/build/vite-plugin-pages.ts @@ -1,4 +1,3 @@ - import type { Plugin as VitePlugin } from 'vite'; import type { BuildInternals } from './internal.js'; import type { StaticBuildOptions } from './types'; @@ -14,23 +13,23 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern name: '@astro/plugin-build-pages', options(options) { - if(!isBuildingToSSR(opts.astroConfig)) { + if (!isBuildingToSSR(opts.astroConfig)) { return addRollupInput(options, [virtualModuleId]); } }, resolveId(id) { - if(id === virtualModuleId) { + if (id === virtualModuleId) { return resolvedVirtualModuleId; } }, load(id) { - if(id === resolvedVirtualModuleId) { + if (id === resolvedVirtualModuleId) { let importMap = ''; let imports = []; let i = 0; - for(const pageData of eachPageData(internals)) { + for (const pageData of eachPageData(internals)) { const variable = `_page${i}`; imports.push(`import * as ${variable} from '${pageData.moduleSpecifier}';`); importMap += `['${pageData.component}', ${variable}],`; @@ -39,10 +38,10 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern i = 0; let rendererItems = ''; - for(const renderer of opts.astroConfig._ctx.renderers) { + for (const renderer of opts.astroConfig._ctx.renderers) { const variable = `_renderer${i}`; imports.push(`import ${variable} from '${renderer.serverEntrypoint}';`); - rendererItems += `Object.assign(${JSON.stringify(renderer)}, { ssr: ${variable} }),` + rendererItems += `Object.assign(${JSON.stringify(renderer)}, { ssr: ${variable} }),`; i++; } @@ -53,6 +52,6 @@ export const renderers = [${rendererItems}];`; return def; } - } + }, }; } diff --git a/packages/astro/src/core/build/vite-plugin-ssr.ts b/packages/astro/src/core/build/vite-plugin-ssr.ts index 989a0ceb8..692d21741 100644 --- a/packages/astro/src/core/build/vite-plugin-ssr.ts +++ b/packages/astro/src/core/build/vite-plugin-ssr.ts @@ -53,10 +53,10 @@ if(_start in adapter) { generateBundle(opts, bundle) { const manifest = buildManifest(buildOpts, internals); - - for(const [_chunkName, chunk] of Object.entries(bundle)) { - if(chunk.type === 'asset') continue; - if(chunk.modules[resolvedVirtualModuleId]) { + + for (const [_chunkName, chunk] of Object.entries(bundle)) { + if (chunk.type === 'asset') continue; + if (chunk.modules[resolvedVirtualModuleId]) { const exp = new RegExp(`['"]${manifestReplace}['"]`); const code = chunk.code; chunk.code = code.replace(exp, () => { @@ -73,9 +73,9 @@ function buildManifest(opts: StaticBuildOptions, internals: BuildInternals): Ser const routes: SerializedRouteInfo[] = []; - for(const pageData of eachPageData(internals)) { + for (const pageData of eachPageData(internals)) { const scripts = Array.from(pageData.scripts); - if(pageData.hoistedScript) { + if (pageData.hoistedScript) { scripts.unshift(pageData.hoistedScript); } diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index ce5e307b9..6787f177b 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -239,4 +239,3 @@ This file is in BETA. Please test and contribute to the discussion: </html> </xsl:template> </xsl:stylesheet>`; - diff --git a/packages/astro/src/vite-plugin-build-css/index.ts b/packages/astro/src/vite-plugin-build-css/index.ts index e6f8b5fc6..7de50af4e 100644 --- a/packages/astro/src/vite-plugin-build-css/index.ts +++ b/packages/astro/src/vite-plugin-build-css/index.ts @@ -138,7 +138,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin { internals.chunkToReferenceIdMap.set(chunk.fileName, referenceId); if (chunk.type === 'chunk') { const fileName = this.getFileName(referenceId); - for(const pageData of getPageDatasByChunk(internals, chunk)) { + for (const pageData of getPageDatasByChunk(internals, chunk)) { pageData.css.add(fileName); } } @@ -160,7 +160,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin { if (chunk.type === 'chunk') { // This find shared chunks of CSS and adds them to the main CSS chunks, // so that shared CSS is added to the page. - for(const { css: cssSet } of getPageDatasByChunk(internals, chunk)) { + for (const { css: cssSet } of getPageDatasByChunk(internals, chunk)) { for (const imp of chunk.imports) { if (internals.chunkToReferenceIdMap.has(imp) && !pureChunkFilenames.has(imp)) { const referenceId = internals.chunkToReferenceIdMap.get(imp)!; diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index 4555dd56d..2131c2b6f 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -13,7 +13,7 @@ describe('API routes in SSR', () => { buildOptions: { experimentalSsr: true, }, - adapter: testAdapter() + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/test-adapter.js b/packages/astro/test/test-adapter.js index 90ae3aa13..99ab34e5d 100644 --- a/packages/astro/test/test-adapter.js +++ b/packages/astro/test/test-adapter.js @@ -22,7 +22,7 @@ export default function () { } }, load(id) { - if(id === '@my-ssr') { + if (id === '@my-ssr') { return `import { App } from 'astro/app';export function createExports(manifest) { return { manifest, createApp: () => new App(manifest) }; }`; } }, diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index 88d29cc5a..d978c4d65 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -89,9 +89,9 @@ export async function loadFixture(inlineConfig) { clean: () => fs.promises.rm(config.dist, { maxRetries: 10, recursive: true, force: true }), loadTestAdapterApp: async () => { const url = new URL('./server/entry.mjs', config.dist); - const {createApp} = await import(url); + const { createApp } = await import(url); return createApp(); - } + }, }; } diff --git a/packages/integrations/node/src/server.ts b/packages/integrations/node/src/server.ts index d643e8367..44a43431c 100644 --- a/packages/integrations/node/src/server.ts +++ b/packages/integrations/node/src/server.ts @@ -36,7 +36,7 @@ async function writeWebResponse(res: ServerResponse, webResponse: Response) { const { status, headers, body } = webResponse; res.writeHead(status, Object.fromEntries(headers.entries())); if (body) { - for await(const chunk of (body as unknown as Readable)) { + for await (const chunk of body as unknown as Readable) { res.write(chunk); } } |