[ci] format
This commit is contained in:
parent
ac3c60d48d
commit
edf2838a66
8 changed files with 68 additions and 52 deletions
|
@ -119,7 +119,7 @@ export function* getPageDatasByClientOnlyID(
|
|||
const pagesByClientOnly = internals.pagesByClientOnly;
|
||||
if (pagesByClientOnly.size) {
|
||||
const pathname = `/@fs${prependForwardSlash(viteid)}`;
|
||||
const pageBuildDatas = pagesByClientOnly.get(pathname)
|
||||
const pageBuildDatas = pagesByClientOnly.get(pathname);
|
||||
if (pageBuildDatas) {
|
||||
for (const pageData of pageBuildDatas) {
|
||||
yield pageData;
|
||||
|
|
|
@ -17,7 +17,11 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
|||
const { internals } = options;
|
||||
|
||||
// This walks up the dependency graph and yields out each ModuleInfo object.
|
||||
function* walkParentInfos(id: string, ctx: {getModuleInfo: GetModuleInfo}, seen = new Set<string>()): Generator<ModuleInfo, void, unknown> {
|
||||
function* walkParentInfos(
|
||||
id: string,
|
||||
ctx: { getModuleInfo: GetModuleInfo },
|
||||
seen = new Set<string>()
|
||||
): Generator<ModuleInfo, void, unknown> {
|
||||
seen.add(id);
|
||||
const info = ctx.getModuleInfo(id);
|
||||
if (info) {
|
||||
|
@ -34,7 +38,10 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
|||
|
||||
// This function walks the dependency graph, going up until it finds a page component.
|
||||
// This could be a .astro page or a .md page.
|
||||
function* getTopLevelPages(id: string, ctx: {getModuleInfo: GetModuleInfo}): Generator<string, void, unknown> {
|
||||
function* getTopLevelPages(
|
||||
id: string,
|
||||
ctx: { getModuleInfo: GetModuleInfo }
|
||||
): Generator<string, void, unknown> {
|
||||
for (const info of walkParentInfos(id, ctx)) {
|
||||
const importers = (info?.importers || []).concat(info?.dynamicImporters || []);
|
||||
if (importers.length <= 2 && importers[0] === resolvedPagesVirtualModuleId) {
|
||||
|
@ -52,7 +59,10 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
|||
return hash.digest('hex').slice(0, 8);
|
||||
}
|
||||
|
||||
function* getParentClientOnlys(id: string, ctx: {getModuleInfo: GetModuleInfo}): Generator<PageBuildData, void, unknown> {
|
||||
function* getParentClientOnlys(
|
||||
id: string,
|
||||
ctx: { getModuleInfo: GetModuleInfo }
|
||||
): Generator<PageBuildData, void, unknown> {
|
||||
for (const info of walkParentInfos(id, ctx)) {
|
||||
yield* getPageDatasByClientOnlyID(internals, info.id);
|
||||
}
|
||||
|
@ -83,7 +93,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
|||
const result = await renderChunk.apply(this, args);
|
||||
if (typeof result === 'string') {
|
||||
return {
|
||||
code: result
|
||||
code: result,
|
||||
};
|
||||
}
|
||||
resolvedConfig.build.minify = minifyOption;
|
||||
|
@ -128,7 +138,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
|||
type ViteMetadata = {
|
||||
importedAssets: Set<string>;
|
||||
importedCss: Set<string>;
|
||||
}
|
||||
};
|
||||
|
||||
for (const [_, chunk] of Object.entries(bundle)) {
|
||||
if (chunk.type === 'chunk') {
|
||||
|
@ -168,12 +178,15 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
|||
// This simply replaces single quotes with double quotes because the vite:css-post
|
||||
// plugin only works with single for some reason. This code can be removed
|
||||
// When the Vite bug is fixed: https://github.com/vitejs/vite/issues/8330
|
||||
const exp = new RegExp(`(\\bimport\\s*)[']([^']*(?:[a-z]+\.[0-9a-z]+\.m?js))['](;\n?)`, 'g');
|
||||
const exp = new RegExp(
|
||||
`(\\bimport\\s*)[']([^']*(?:[a-z]+\.[0-9a-z]+\.m?js))['](;\n?)`,
|
||||
'g'
|
||||
);
|
||||
chunk.code = chunk.code.replace(exp, (_match, begin, chunkPath, end) => {
|
||||
return begin + '"' + chunkPath + '"' + end;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -29,7 +29,8 @@ describe('CSS', function () {
|
|||
$ = cheerio.load(html);
|
||||
const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href');
|
||||
bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/')))
|
||||
.replace(/\s/g, '').replace('/n', '');
|
||||
.replace(/\s/g, '')
|
||||
.replace('/n', '');
|
||||
});
|
||||
|
||||
describe('Astro Styles', () => {
|
||||
|
|
|
@ -13,6 +13,6 @@ describe('Vite Config', async () => {
|
|||
it('Allows overriding bundle naming options in the build', async () => {
|
||||
const html = await fixture.readFile('/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
expect($('link').attr('href')).to.match(/\/assets\/testing-[a-z0-9]+\.css/)
|
||||
expect($('link').attr('href')).to.match(/\/assets\/testing-[a-z0-9]+\.css/);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,9 +10,9 @@ describe('Assets in CSS', () => {
|
|||
root: './fixtures/css-assets/',
|
||||
vite: {
|
||||
build: {
|
||||
assetsInlineLimit: 0
|
||||
}
|
||||
}
|
||||
assetsInlineLimit: 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
|
|
@ -19,7 +19,8 @@ describe('PostCSS', () => {
|
|||
const $ = cheerio.load(html);
|
||||
const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href');
|
||||
bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/')))
|
||||
.replace(/\s/g, '').replace('/n', '');
|
||||
.replace(/\s/g, '')
|
||||
.replace('/n', '');
|
||||
});
|
||||
|
||||
it('works in Astro page styles', () => {
|
||||
|
@ -43,7 +44,10 @@ describe('PostCSS', () => {
|
|||
});
|
||||
|
||||
it('ignores CSS in public/', async () => {
|
||||
const publicCSS = (await fixture.readFile('/global.css')).trim().replace(/\s/g, '').replace('/n', '');
|
||||
const publicCSS = (await fixture.readFile('/global.css'))
|
||||
.trim()
|
||||
.replace(/\s/g, '')
|
||||
.replace('/n', '');
|
||||
// neither minified nor prefixed
|
||||
expect(eol.lf(publicCSS)).to.equal(`.global{appearance:none;}`);
|
||||
});
|
||||
|
|
|
@ -38,9 +38,7 @@ describe('Tailwind', () => {
|
|||
expect(bundledCSS, 'includes responsive classes').to.match(/\.lg\\:py-3{/);
|
||||
|
||||
// tailwind escapes brackets, `font-[900]` compiles to `font-\[900\]`
|
||||
expect(bundledCSS, 'supports arbitrary value classes').to.match(
|
||||
/\.font-\\\[900\\\]{/
|
||||
);
|
||||
expect(bundledCSS, 'supports arbitrary value classes').to.match(/\.font-\\\[900\\\]{/);
|
||||
|
||||
// custom theme colors were included
|
||||
expect(bundledCSS, 'includes custom theme colors').to.match(/\.text-midnight{/);
|
||||
|
|
Loading…
Reference in a new issue