0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-24 22:46:02 -05:00

[ci] format

This commit is contained in:
matthewp 2022-05-26 18:01:35 +00:00 committed by github-actions[bot]
parent ac3c60d48d
commit edf2838a66
8 changed files with 68 additions and 52 deletions

View file

@ -119,7 +119,7 @@ export function* getPageDatasByClientOnlyID(
const pagesByClientOnly = internals.pagesByClientOnly; const pagesByClientOnly = internals.pagesByClientOnly;
if (pagesByClientOnly.size) { if (pagesByClientOnly.size) {
const pathname = `/@fs${prependForwardSlash(viteid)}`; const pathname = `/@fs${prependForwardSlash(viteid)}`;
const pageBuildDatas = pagesByClientOnly.get(pathname) const pageBuildDatas = pagesByClientOnly.get(pathname);
if (pageBuildDatas) { if (pageBuildDatas) {
for (const pageData of pageBuildDatas) { for (const pageData of pageBuildDatas) {
yield pageData; yield pageData;

View file

@ -17,7 +17,11 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
const { internals } = options; const { internals } = options;
// This walks up the dependency graph and yields out each ModuleInfo object. // 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); seen.add(id);
const info = ctx.getModuleInfo(id); const info = ctx.getModuleInfo(id);
if (info) { 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 function walks the dependency graph, going up until it finds a page component.
// This could be a .astro page or a .md page. // 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)) { for (const info of walkParentInfos(id, ctx)) {
const importers = (info?.importers || []).concat(info?.dynamicImporters || []); const importers = (info?.importers || []).concat(info?.dynamicImporters || []);
if (importers.length <= 2 && importers[0] === resolvedPagesVirtualModuleId) { if (importers.length <= 2 && importers[0] === resolvedPagesVirtualModuleId) {
@ -52,7 +59,10 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
return hash.digest('hex').slice(0, 8); 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)) { for (const info of walkParentInfos(id, ctx)) {
yield* getPageDatasByClientOnlyID(internals, info.id); yield* getPageDatasByClientOnlyID(internals, info.id);
} }
@ -83,7 +93,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
const result = await renderChunk.apply(this, args); const result = await renderChunk.apply(this, args);
if (typeof result === 'string') { if (typeof result === 'string') {
return { return {
code: result code: result,
}; };
} }
resolvedConfig.build.minify = minifyOption; resolvedConfig.build.minify = minifyOption;
@ -128,7 +138,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
type ViteMetadata = { type ViteMetadata = {
importedAssets: Set<string>; importedAssets: Set<string>;
importedCss: Set<string>; importedCss: Set<string>;
} };
for (const [_, chunk] of Object.entries(bundle)) { for (const [_, chunk] of Object.entries(bundle)) {
if (chunk.type === 'chunk') { 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 // 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 // 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 // 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) => { chunk.code = chunk.code.replace(exp, (_match, begin, chunkPath, end) => {
return begin + '"' + chunkPath + '"' + end; return begin + '"' + chunkPath + '"' + end;
}); });
} }
} }
} },
}; };
} }

View file

@ -29,7 +29,8 @@ describe('CSS', function () {
$ = cheerio.load(html); $ = cheerio.load(html);
const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href'); const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href');
bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/'))) bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/')))
.replace(/\s/g, '').replace('/n', ''); .replace(/\s/g, '')
.replace('/n', '');
}); });
describe('Astro Styles', () => { describe('Astro Styles', () => {

View file

@ -13,6 +13,6 @@ describe('Vite Config', async () => {
it('Allows overriding bundle naming options in the build', async () => { it('Allows overriding bundle naming options in the build', async () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(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/);
}); });
}); });

View file

@ -10,9 +10,9 @@ describe('Assets in CSS', () => {
root: './fixtures/css-assets/', root: './fixtures/css-assets/',
vite: { vite: {
build: { build: {
assetsInlineLimit: 0 assetsInlineLimit: 0,
} },
} },
}); });
await fixture.build(); await fixture.build();
}); });

View file

@ -19,7 +19,8 @@ describe('PostCSS', () => {
const $ = cheerio.load(html); const $ = cheerio.load(html);
const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href'); const bundledCSSHREF = $('link[rel=stylesheet][href^=/assets/]').attr('href');
bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/'))) bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/')))
.replace(/\s/g, '').replace('/n', ''); .replace(/\s/g, '')
.replace('/n', '');
}); });
it('works in Astro page styles', () => { it('works in Astro page styles', () => {
@ -43,7 +44,10 @@ describe('PostCSS', () => {
}); });
it('ignores CSS in public/', async () => { 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 // neither minified nor prefixed
expect(eol.lf(publicCSS)).to.equal(`.global{appearance:none;}`); expect(eol.lf(publicCSS)).to.equal(`.global{appearance:none;}`);
}); });

View file

@ -38,9 +38,7 @@ describe('Tailwind', () => {
expect(bundledCSS, 'includes responsive classes').to.match(/\.lg\\:py-3{/); expect(bundledCSS, 'includes responsive classes').to.match(/\.lg\\:py-3{/);
// tailwind escapes brackets, `font-[900]` compiles to `font-\[900\]` // tailwind escapes brackets, `font-[900]` compiles to `font-\[900\]`
expect(bundledCSS, 'supports arbitrary value classes').to.match( expect(bundledCSS, 'supports arbitrary value classes').to.match(/\.font-\\\[900\\\]{/);
/\.font-\\\[900\\\]{/
);
// custom theme colors were included // custom theme colors were included
expect(bundledCSS, 'includes custom theme colors').to.match(/\.text-midnight{/); expect(bundledCSS, 'includes custom theme colors').to.match(/\.text-midnight{/);