diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index c2e33432cbf1..84574ace9b71 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -7,7 +7,6 @@ import { BuildInternals, createBuildInternals } from '../../core/build/internal. import { prependForwardSlash } from '../../core/path.js'; import { emptyDir, isModeServerWithNoAdapter, removeDir } from '../../core/util.js'; import { runHookBuildSetup } from '../../integrations/index.js'; -import { rollupPluginAstroBuildCSS } from './vite-plugin-css.js'; import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import type { ViteConfigWithSSR } from '../create-vite'; import { info } from '../logger/core.js'; @@ -16,6 +15,7 @@ import { trackPageData } from './internal.js'; import type { PageBuildData, StaticBuildOptions } from './types'; import { getTimeStat } from './util.js'; import { vitePluginAnalyzer } from './vite-plugin-analyzer.js'; +import { rollupPluginAstroBuildCSS } from './vite-plugin-css.js'; import { vitePluginHoistedScripts } from './vite-plugin-hoisted-scripts.js'; import { vitePluginInternals } from './vite-plugin-internals.js'; import { vitePluginPages } from './vite-plugin-pages.js'; diff --git a/packages/astro/src/core/build/vite-plugin-css.ts b/packages/astro/src/core/build/vite-plugin-css.ts index 87708181cfad..8b2a31005d1b 100644 --- a/packages/astro/src/core/build/vite-plugin-css.ts +++ b/packages/astro/src/core/build/vite-plugin-css.ts @@ -1,16 +1,16 @@ import type { GetModuleInfo, OutputChunk } from 'rollup'; +import type { AstroConfig } from '../../@types/astro'; import type { BuildInternals } from './internal'; import type { PageBuildData, StaticBuildOptions } from './types'; -import type { AstroConfig } from '../../@types/astro'; import crypto from 'crypto'; import esbuild from 'esbuild'; import npath from 'path'; import { Plugin as VitePlugin } from 'vite'; +import { isCSSRequest } from '../render/util.js'; +import { relativeToSrcDir } from '../util.js'; import { getTopLevelPages, walkParentInfos } from './graph.js'; import { getPageDataByViteID, getPageDatasByClientOnlyID } from './internal.js'; -import { relativeToSrcDir } from '../util.js'; -import { isCSSRequest } from '../render/util.js'; interface PluginOptions { internals: BuildInternals; @@ -30,7 +30,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] function nameifyPage(id: string) { let rel = relativeToSrcDir(astroConfig, id); // Remove pages, ex. blog/posts/something.astro - if(rel.startsWith('pages/')) { + if (rel.startsWith('pages/')) { rel = rel.slice(6); } // Remove extension, ex. blog/posts/something @@ -43,14 +43,14 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] function createNameForParentPages(id: string, ctx: { getModuleInfo: GetModuleInfo }): string { const parents = Array.from(getTopLevelPages(id, ctx)).sort(); - const proposedName = parents.map(page => nameifyPage(page.id)).join('-'); + const proposedName = parents.map((page) => nameifyPage(page.id)).join('-'); // We don't want absurdedly long chunk names, so if this is too long create a hashed version instead. - if(proposedName.length <= MAX_NAME_LENGTH) { + if (proposedName.length <= MAX_NAME_LENGTH) { return proposedName; } - const hash = crypto.createHash('sha256'); + const hash = crypto.createHash('sha256'); for (const page of parents) { hash.update(page.id, 'utf-8'); } diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index ac36f7a05f50..084ffaf555d1 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -188,7 +188,7 @@ export function isModeServerWithNoAdapter(config: AstroConfig): boolean { export function relativeToSrcDir(config: AstroConfig, idOrUrl: URL | string) { let id: string; - if(typeof idOrUrl !== 'string') { + if (typeof idOrUrl !== 'string') { id = unwrapId(viteID(idOrUrl)); } else { id = idOrUrl; diff --git a/packages/astro/test/glob-pages-css.test.js b/packages/astro/test/glob-pages-css.test.js index 2a3fdb435f29..72558490f406 100644 --- a/packages/astro/test/glob-pages-css.test.js +++ b/packages/astro/test/glob-pages-css.test.js @@ -17,6 +17,5 @@ describe('Astro.glob on pages/ directory', () => { let $ = cheerio.load(html); expect($('link[rel=stylesheet]')).to.have.a.lengthOf(1); - }); });