[ci] format

This commit is contained in:
matthewp 2022-05-31 15:41:24 +00:00 committed by github-actions[bot]
parent efccebb964
commit 1aeb1d0a00
4 changed files with 16 additions and 9 deletions

View file

@ -339,18 +339,18 @@ async function handleRequest(
* Vite HMR sends requests for new CSS and those get returned as JS, but we want it to be CSS * Vite HMR sends requests for new CSS and those get returned as JS, but we want it to be CSS
* since they are inside of a link tag for Astro. * since they are inside of a link tag for Astro.
*/ */
const forceTextCSSForStylesMiddleware: vite.Connect.NextHandleFunction = function(req, res, next) { const forceTextCSSForStylesMiddleware: vite.Connect.NextHandleFunction = function (req, res, next) {
if(req.url) { if (req.url) {
// We are just using this to parse the URL to get the search params object // We are just using this to parse the URL to get the search params object
// so the second arg here doesn't matter // so the second arg here doesn't matter
const url = new URL(req.url, 'https://astro.build'); const url = new URL(req.url, 'https://astro.build');
// lang.css is a search param that exists on Astro, Svelte, and Vue components. // lang.css is a search param that exists on Astro, Svelte, and Vue components.
// We only want to override for astro files. // We only want to override for astro files.
if(url.searchParams.has('astro') && url.searchParams.has('lang.css')) { if (url.searchParams.has('astro') && url.searchParams.has('lang.css')) {
// Override setHeader so we can set the correct content-type for this request. // Override setHeader so we can set the correct content-type for this request.
const setHeader = res.setHeader; const setHeader = res.setHeader;
res.setHeader = function(key, value) { res.setHeader = function (key, value) {
if(key.toLowerCase() === 'content-type') { if (key.toLowerCase() === 'content-type') {
return setHeader.call(this, key, 'text/css'); return setHeader.call(this, key, 'text/css');
} }
return setHeader.apply(this, [key, value]); return setHeader.apply(this, [key, value]);
@ -381,7 +381,10 @@ export default function createPlugin({ config, logging }: AstroPluginOptions): v
removeViteHttpMiddleware(viteServer.middlewares); removeViteHttpMiddleware(viteServer.middlewares);
// Push this middleware to the front of the stack so that it can intercept responses. // Push this middleware to the front of the stack so that it can intercept responses.
viteServer.middlewares.stack.unshift({ route: '', handle: forceTextCSSForStylesMiddleware }); viteServer.middlewares.stack.unshift({
route: '',
handle: forceTextCSSForStylesMiddleware,
});
viteServer.middlewares.use(async (req, res) => { viteServer.middlewares.use(async (req, res) => {
if (!req.url || !req.method) { if (!req.url || !req.method) {
throw new Error('Incomplete request'); throw new Error('Incomplete request');

View file

@ -22,7 +22,9 @@ describe('HMR - CSS', () => {
}); });
it('Timestamp URL used by Vite gets the right mime type', async () => { it('Timestamp URL used by Vite gets the right mime type', async () => {
let res = await fixture.fetch('/src/pages/index.astro?astro=&type=style&index=0&lang.css=&t=1653657441095'); let res = await fixture.fetch(
'/src/pages/index.astro?astro=&type=style&index=0&lang.css=&t=1653657441095'
);
let headers = res.headers; let headers = res.headers;
expect(headers.get('content-type')).to.equal('text/css'); expect(headers.get('content-type')).to.equal('text/css');
}); });

View file

@ -2,7 +2,9 @@ async function polyfill() {
const { hydrateShadowRoots } = await import( const { hydrateShadowRoots } = await import(
'@webcomponents/template-shadowroot/template-shadowroot.js' '@webcomponents/template-shadowroot/template-shadowroot.js'
); );
window.addEventListener('DOMContentLoaded', () => hydrateShadowRoots(document.body), { once: true }); window.addEventListener('DOMContentLoaded', () => hydrateShadowRoots(document.body), {
once: true,
});
} }
const polyfillCheckEl = new DOMParser() const polyfillCheckEl = new DOMParser()

View file

@ -77,7 +77,7 @@ var S = i(() => {
}); });
async function g() { async function g() {
let { hydrateShadowRoots: t } = await Promise.resolve().then(() => (S(), v)); let { hydrateShadowRoots: t } = await Promise.resolve().then(() => (S(), v));
window.addEventListener('DOMContentLoaded', () => t(document.body),{once:true}); window.addEventListener('DOMContentLoaded', () => t(document.body), { once: true });
} }
var x = new DOMParser() var x = new DOMParser()
.parseFromString('<p><template shadowroot="open"></template></p>', 'text/html', { .parseFromString('<p><template shadowroot="open"></template></p>', 'text/html', {