[ci] format

This commit is contained in:
matthewp 2022-06-22 16:04:06 +00:00 committed by github-actions[bot]
parent aeab890971
commit 5a41ea1202
7 changed files with 25 additions and 26 deletions

View file

@ -16,7 +16,6 @@ import { render } from '../render/core.js';
import { RouteCache } from '../render/route-cache.js';
import {
createLinkStylesheetElementSet,
createModuleScriptElementWithSrcSet,
createModuleScriptElement,
} from '../render/ssr-element.js';
import { matchRoute } from '../routing/match.js';
@ -83,8 +82,8 @@ export class App {
let scripts = new Set<SSRElement>();
for (const script of info.scripts) {
if (('stage' in script)) {
if(script.stage === 'head-inline') {
if ('stage' in script) {
if (script.stage === 'head-inline') {
scripts.add({
props: {},
children: script.children,

View file

@ -12,13 +12,11 @@ export interface RouteInfo {
routeData: RouteData;
file: string;
links: string[];
scripts:
(
// Integration injected
{ children: string; stage: string } |
// Hoisted
{ type: 'inline' | 'external'; value: string; }
)[];
scripts: // Integration injected
(| { children: string; stage: string }
// Hoisted
| { type: 'inline' | 'external'; value: string }
)[];
}
export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {

View file

@ -16,10 +16,7 @@ import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
import { call as callEndpoint } from '../endpoint/index.js';
import { debug, info } from '../logger/core.js';
import { render } from '../render/core.js';
import {
createLinkStylesheetElementSet,
createModuleScriptsSet,
} from '../render/ssr-element.js';
import { createLinkStylesheetElementSet, createModuleScriptsSet } from '../render/ssr-element.js';
import { createRequest } from '../request.js';
import { getOutputFilename, isBuildingToSSR } from '../util.js';
import { getOutFile, getOutFolder } from './common.js';
@ -167,7 +164,7 @@ interface GeneratePathOptions {
pageData: PageBuildData;
internals: BuildInternals;
linkIds: string[];
scripts: { type: 'inline' | 'external', value: string } | null;
scripts: { type: 'inline' | 'external'; value: string } | null;
mod: ComponentInstance;
renderers: SSRLoadedRenderer[];
}

View file

@ -19,7 +19,7 @@ export interface PageBuildData {
route: RouteData;
moduleSpecifier: string;
css: Set<string>;
hoistedScript: { type: 'inline' | 'external', value: string } | undefined;
hoistedScript: { type: 'inline' | 'external'; value: string } | undefined;
}
export type AllPagesData = Record<ComponentPath, PageBuildData>;

View file

@ -50,7 +50,9 @@ export function vitePluginHoistedScripts(
output.facadeModuleId &&
virtualHoistedEntry(output.facadeModuleId)
) {
const canBeInlined = output.imports.length === 0 && output.dynamicImports.length === 0 &&
const canBeInlined =
output.imports.length === 0 &&
output.dynamicImports.length === 0 &&
Buffer.byteLength(output.code) <= assetInlineLimit;
let removeFromBundle = false;
const facadeId = output.facadeModuleId!;
@ -59,23 +61,23 @@ export function vitePluginHoistedScripts(
const vid = viteID(new URL('.' + pathname, astroConfig.root));
const pageInfo = getPageDataByViteID(internals, vid);
if (pageInfo) {
if(canBeInlined) {
if (canBeInlined) {
pageInfo.hoistedScript = {
type: 'inline',
value: output.code
value: output.code,
};
removeFromBundle = true;
} else {
pageInfo.hoistedScript = {
type: 'external',
value: id
value: id,
};
}
}
}
// Remove the bundle if it was inlined
if(removeFromBundle) {
if (removeFromBundle) {
delete bundle[id];
}
}

View file

@ -25,8 +25,11 @@ export function createLinkStylesheetElementSet(hrefs: string[], site?: string) {
return new Set<SSRElement>(hrefs.map((href) => createLinkStylesheetElement(href, site)));
}
export function createModuleScriptElement(script: { type: 'inline' | 'external'; value: string; }, site?: string): SSRElement {
if(script.type === 'external') {
export function createModuleScriptElement(
script: { type: 'inline' | 'external'; value: string },
site?: string
): SSRElement {
if (script.type === 'external') {
return createModuleScriptElementWithSrc(script.value, site);
} else {
return {
@ -56,8 +59,8 @@ export function createModuleScriptElementWithSrcSet(
}
export function createModuleScriptsSet(
scripts: { type: 'inline' | 'external'; value: string; }[],
scripts: { type: 'inline' | 'external'; value: string }[],
site?: string
): Set<SSRElement> {
return new Set<SSRElement>(scripts.map(script => createModuleScriptElement(script, site)));
return new Set<SSRElement>(scripts.map((script) => createModuleScriptElement(script, site)));
}

View file

@ -58,7 +58,7 @@ describe('Scripts (hoisted and not)', () => {
);
});
it('Inline scripts that are shared by multiple pages create chunks, and aren\'t inlined into the HTML', async () => {
it("Inline scripts that are shared by multiple pages create chunks, and aren't inlined into the HTML", async () => {
let html = await fixture.readFile('/inline-shared-one/index.html');
let $ = cheerio.load(html);