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

View file

@ -12,12 +12,10 @@ export interface RouteInfo {
routeData: RouteData; routeData: RouteData;
file: string; file: string;
links: string[]; links: string[];
scripts: scripts: // Integration injected
( (| { children: string; stage: string }
// Integration injected
{ children: string; stage: string } |
// Hoisted // Hoisted
{ type: 'inline' | 'external'; value: string; } | { type: 'inline' | 'external'; value: string }
)[]; )[];
} }

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

View file

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

View file

@ -50,7 +50,9 @@ export function vitePluginHoistedScripts(
output.facadeModuleId && output.facadeModuleId &&
virtualHoistedEntry(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; Buffer.byteLength(output.code) <= assetInlineLimit;
let removeFromBundle = false; let removeFromBundle = false;
const facadeId = output.facadeModuleId!; const facadeId = output.facadeModuleId!;
@ -62,13 +64,13 @@ export function vitePluginHoistedScripts(
if (canBeInlined) { if (canBeInlined) {
pageInfo.hoistedScript = { pageInfo.hoistedScript = {
type: 'inline', type: 'inline',
value: output.code value: output.code,
}; };
removeFromBundle = true; removeFromBundle = true;
} else { } else {
pageInfo.hoistedScript = { pageInfo.hoistedScript = {
type: 'external', type: 'external',
value: id value: id,
}; };
} }
} }

View file

@ -25,7 +25,10 @@ export function createLinkStylesheetElementSet(hrefs: string[], site?: string) {
return new Set<SSRElement>(hrefs.map((href) => createLinkStylesheetElement(href, site))); return new Set<SSRElement>(hrefs.map((href) => createLinkStylesheetElement(href, site)));
} }
export function createModuleScriptElement(script: { type: 'inline' | 'external'; value: string; }, site?: string): SSRElement { export function createModuleScriptElement(
script: { type: 'inline' | 'external'; value: string },
site?: string
): SSRElement {
if (script.type === 'external') { if (script.type === 'external') {
return createModuleScriptElementWithSrc(script.value, site); return createModuleScriptElementWithSrc(script.value, site);
} else { } else {
@ -56,8 +59,8 @@ export function createModuleScriptElementWithSrcSet(
} }
export function createModuleScriptsSet( export function createModuleScriptsSet(
scripts: { type: 'inline' | 'external'; value: string; }[], scripts: { type: 'inline' | 'external'; value: string }[],
site?: string site?: string
): Set<SSRElement> { ): 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 html = await fixture.readFile('/inline-shared-one/index.html');
let $ = cheerio.load(html); let $ = cheerio.load(html);