Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Aug 25, 2022
1 parent 9490f0e commit ba1ca7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function moduleIsTopLevelPage(info: ModuleInfo): boolean {
// This could be a .astro page or a .md page.
export function* getTopLevelPages(
id: string,
ctx: { getModuleInfo: GetModuleInfo },
ctx: { getModuleInfo: GetModuleInfo }
): Generator<[ModuleInfo, number], void, unknown> {
for (const res of walkParentInfos(id, ctx)) {
if (moduleIsTopLevelPage(res[0])) {
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OutputChunk, RenderedChunk, ModuleInfo, GetModuleInfo } from 'rollup';
import type { OutputChunk, RenderedChunk } from 'rollup';
import type { PageBuildData, ViteID } from './types';

import { prependForwardSlash } from '../path.js';
Expand Down Expand Up @@ -207,10 +207,10 @@ export function* getPageDatasByHoistedScriptId(
id: string
): Generator<PageBuildData, void, unknown> {
const set = internals.hoistedScriptIdToPagesMap.get(id);
if(set) {
for(const pageId of set) {
if (set) {
for (const pageId of set) {
const pageData = getPageDataByComponent(internals, pageId.slice(1));
if(pageData) {
if (pageData) {
yield pageData;
}
}
Expand Down
26 changes: 19 additions & 7 deletions packages/astro/src/core/build/vite-plugin-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ import npath from 'path';
import { Plugin as VitePlugin, ResolvedConfig } from 'vite';
import { isCSSRequest } from '../render/util.js';
import { relativeToSrcDir } from '../util.js';
import { getTopLevelPages, walkParentInfos, moduleIsTopLevelPage } from './graph.js';
import { eachPageData, getPageDataByViteID, getPageDatasByClientOnlyID, getPageDatasByHoistedScriptId, isHoistedScript } from './internal.js';
import { getTopLevelPages, moduleIsTopLevelPage, walkParentInfos } from './graph.js';
import {
eachPageData,
getPageDataByViteID,
getPageDatasByClientOnlyID,
getPageDatasByHoistedScriptId,
isHoistedScript,
} from './internal.js';

interface PluginOptions {
internals: BuildInternals;
Expand Down Expand Up @@ -118,7 +124,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
pageData?.css.set(importedCssImport, { depth });
}
}
}
};

for (const [_, chunk] of Object.entries(bundle)) {
if (chunk.type === 'chunk') {
Expand All @@ -144,14 +150,20 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
// For this CSS chunk, walk parents until you find a page. Add the CSS to that page.
for (const [id] of Object.entries(c.modules)) {
for (const [pageInfo, depth] of walkParentInfos(id, this)) {
if(moduleIsTopLevelPage(pageInfo)) {
if (moduleIsTopLevelPage(pageInfo)) {
const pageViteID = pageInfo.id;
const pageData = getPageDataByViteID(internals, pageViteID);
if(pageData) {
if (pageData) {
appendCSSToPage(pageData, meta, depth);
}
} else if(options.target === 'client' && isHoistedScript(internals, pageInfo.id)) {
for(const pageData of getPageDatasByHoistedScriptId(internals, pageInfo.id)) {
} else if (
options.target === 'client' &&
isHoistedScript(internals, pageInfo.id)
) {
for (const pageData of getPageDatasByHoistedScriptId(
internals,
pageInfo.id
)) {
appendCSSToPage(pageData, meta, -1);
}
}
Expand Down

0 comments on commit ba1ca7e

Please sign in to comment.