Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and actions-user committed Mar 24, 2022
1 parent e4025d1 commit f5b48bc
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 50 deletions.
14 changes: 7 additions & 7 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}].`);
Expand Down Expand Up @@ -95,8 +95,8 @@ export class App {
status: 200,
headers: {
'Content-Type': 'text/html',
'Content-Length': bytes.byteLength.toString()
}
'Content-Length': bytes.byteLength.toString(),
},
});
}

Expand All @@ -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,
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand All @@ -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.`);
}

Expand Down
29 changes: 14 additions & 15 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

Expand Down Expand Up @@ -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();
}
3 changes: 1 addition & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
15 changes: 7 additions & 8 deletions packages/astro/src/core/build/vite-plugin-pages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import type { Plugin as VitePlugin } from 'vite';
import type { BuildInternals } from './internal.js';
import type { StaticBuildOptions } from './types';
Expand All @@ -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}],`;
Expand All @@ -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++;
}

Expand All @@ -53,6 +52,6 @@ export const renderers = [${rendererItems}];`;

return def;
}
}
},
};
}
12 changes: 6 additions & 6 deletions packages/astro/src/core/build/vite-plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand All @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,3 @@ This file is in BETA. Please test and contribute to the discussion:
</html>
</xsl:template>
</xsl:stylesheet>`;

4 changes: 2 additions & 2 deletions packages/astro/src/vite-plugin-build-css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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)!;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-api-route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('API routes in SSR', () => {
buildOptions: {
experimentalSsr: true,
},
adapter: testAdapter()
adapter: testAdapter(),
});
await fixture.build();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/test-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) }; }`;
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit f5b48bc

Please sign in to comment.