[ci] format
This commit is contained in:
parent
f5afaf2498
commit
948f82048b
17 changed files with 61 additions and 73 deletions
|
@ -61,7 +61,8 @@ function shouldSkipDraft(pageModule: ComponentInstance, astroConfig: AstroConfig
|
|||
// Drafts are disabled
|
||||
!astroConfig.markdown.drafts &&
|
||||
// This is a draft post
|
||||
('frontmatter' in pageModule && (pageModule as any).frontmatter.draft === true)
|
||||
'frontmatter' in pageModule &&
|
||||
(pageModule as any).frontmatter.draft === true
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -133,7 +134,7 @@ async function generatePage(
|
|||
);
|
||||
}
|
||||
|
||||
if(shouldSkipDraft(pageModule, opts.astroConfig)) {
|
||||
if (shouldSkipDraft(pageModule, opts.astroConfig)) {
|
||||
info(opts.logging, null, `${magenta('⚠️')} Skipping draft ${pageData.route.component}`);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { GetModuleInfo, ModuleInfo, OutputChunk } from 'rollup';
|
||||
import type { GetModuleInfo, ModuleInfo } from 'rollup';
|
||||
import { resolvedPagesVirtualModuleId } from '../app/index.js';
|
||||
|
||||
// This walks up the dependency graph and yields out each ModuleInfo object.
|
||||
|
|
|
@ -8,7 +8,6 @@ import * as colors from 'kleur/colors';
|
|||
import { fileURLToPath } from 'url';
|
||||
import { debug } from '../logger/core.js';
|
||||
import { removeTrailingForwardSlash } from '../path.js';
|
||||
import { preload as ssrPreload } from '../render/dev/index.js';
|
||||
import { callGetStaticPaths, RouteCache, RouteCacheEntry } from '../render/route-cache.js';
|
||||
import { matchRoute } from '../routing/match.js';
|
||||
import { isBuildingToSSR } from '../util.js';
|
||||
|
@ -132,7 +131,7 @@ export async function collectPagesData(
|
|||
moduleSpecifier: '',
|
||||
css: new Set(),
|
||||
hoistedScript: undefined,
|
||||
scripts: new Set()
|
||||
scripts: new Set(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,7 @@ import { bgGreen, bgMagenta, black, dim } from 'kleur/colors';
|
|||
import type { RollupOutput } from 'rollup';
|
||||
import { fileURLToPath } from 'url';
|
||||
import * as vite from 'vite';
|
||||
import {
|
||||
BuildInternals,
|
||||
createBuildInternals,
|
||||
} from '../../core/build/internal.js';
|
||||
import { BuildInternals, createBuildInternals } from '../../core/build/internal.js';
|
||||
import { prependForwardSlash } from '../../core/path.js';
|
||||
import { emptyDir, removeDir } from '../../core/util.js';
|
||||
import { runHookBuildSetup } from '../../integrations/index.js';
|
||||
|
@ -19,11 +16,11 @@ import { generatePages } from './generate.js';
|
|||
import { trackPageData } from './internal.js';
|
||||
import type { PageBuildData, StaticBuildOptions } from './types';
|
||||
import { getTimeStat } from './util.js';
|
||||
import { vitePluginAnalyzer } from './vite-plugin-analyzer.js';
|
||||
import { vitePluginHoistedScripts } from './vite-plugin-hoisted-scripts.js';
|
||||
import { vitePluginInternals } from './vite-plugin-internals.js';
|
||||
import { vitePluginPages } from './vite-plugin-pages.js';
|
||||
import { vitePluginSSR, injectManifest } from './vite-plugin-ssr.js';
|
||||
import { vitePluginAnalyzer } from './vite-plugin-analyzer.js';
|
||||
import { injectManifest, vitePluginSSR } from './vite-plugin-ssr.js';
|
||||
|
||||
export async function staticBuild(opts: StaticBuildOptions) {
|
||||
const { allPages, astroConfig } = opts;
|
||||
|
@ -73,7 +70,7 @@ export async function staticBuild(opts: StaticBuildOptions) {
|
|||
const clientInput = new Set<string>([
|
||||
...internals.discoveredHydratedComponents,
|
||||
...internals.discoveredClientOnlyComponents,
|
||||
...astroConfig._ctx.renderers.map(r => r.clientEntrypoint).filter(a => a) as string[],
|
||||
...(astroConfig._ctx.renderers.map((r) => r.clientEntrypoint).filter((a) => a) as string[]),
|
||||
...internals.discoveredScripts,
|
||||
]);
|
||||
|
||||
|
@ -90,7 +87,7 @@ export async function staticBuild(opts: StaticBuildOptions) {
|
|||
}
|
||||
} else {
|
||||
// Inject the manifest
|
||||
await injectManifest(opts, internals)
|
||||
await injectManifest(opts, internals);
|
||||
|
||||
info(opts.logging, null, `\n${bgMagenta(black(' finalizing server assets '))}\n`);
|
||||
await ssrMoveAssets(opts);
|
||||
|
@ -144,7 +141,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
|||
// SSR needs to be last
|
||||
isBuildingToSSR(opts.astroConfig) &&
|
||||
vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter!),
|
||||
vitePluginAnalyzer(opts.astroConfig, internals)
|
||||
vitePluginAnalyzer(opts.astroConfig, internals),
|
||||
],
|
||||
publicDir: ssr ? false : viteConfig.publicDir,
|
||||
root: viteConfig.root,
|
||||
|
|
|
@ -1,41 +1,33 @@
|
|||
|
||||
|
||||
import type { Plugin as VitePlugin } from 'vite';
|
||||
import type { PluginContext } from 'rollup';
|
||||
import type { Plugin as VitePlugin } from 'vite';
|
||||
import type { AstroConfig } from '../../@types/astro';
|
||||
import type { BuildInternals } from '../../core/build/internal.js';
|
||||
import type { PluginMetadata as AstroPluginMetadata } from '../../vite-plugin-astro/types';
|
||||
|
||||
import { prependForwardSlash } from '../../core/path.js';
|
||||
import { getPageDataByViteID, trackClientOnlyPageDatas } from './internal.js';
|
||||
import { getTopLevelPages } from './graph.js';
|
||||
|
||||
import { getPageDataByViteID, trackClientOnlyPageDatas } from './internal.js';
|
||||
|
||||
export function vitePluginAnalyzer(
|
||||
astroConfig: AstroConfig,
|
||||
internals: BuildInternals
|
||||
): VitePlugin {
|
||||
|
||||
function hoistedScriptScanner() {
|
||||
const uniqueHoistedIds = new Map<string, string>();
|
||||
const pageScripts = new Map<string, Set<string>>();
|
||||
|
||||
return {
|
||||
scan(
|
||||
this: PluginContext,
|
||||
scripts: AstroPluginMetadata['astro']['scripts'],
|
||||
from: string
|
||||
) {
|
||||
scan(this: PluginContext, scripts: AstroPluginMetadata['astro']['scripts'], from: string) {
|
||||
const hoistedScripts = new Set<string>();
|
||||
for(let i = 0; i < scripts.length; i++) {
|
||||
for (let i = 0; i < scripts.length; i++) {
|
||||
const hid = `${from.replace('/@fs', '')}?astro&type=script&index=${i}`;
|
||||
hoistedScripts.add(hid);
|
||||
}
|
||||
|
||||
if (hoistedScripts.size) {
|
||||
for(const pageId of getTopLevelPages(from, this)) {
|
||||
for(const hid of hoistedScripts) {
|
||||
if(pageScripts.has(pageId)) {
|
||||
for (const pageId of getTopLevelPages(from, this)) {
|
||||
for (const hid of hoistedScripts) {
|
||||
if (pageScripts.has(pageId)) {
|
||||
pageScripts.get(pageId)?.add(hid);
|
||||
} else {
|
||||
pageScripts.set(pageId, new Set([hid]));
|
||||
|
@ -46,16 +38,16 @@ export function vitePluginAnalyzer(
|
|||
},
|
||||
|
||||
finalize() {
|
||||
for(const [pageId, hoistedScripts] of pageScripts) {
|
||||
for (const [pageId, hoistedScripts] of pageScripts) {
|
||||
const pageData = getPageDataByViteID(internals, pageId);
|
||||
if(!pageData) continue;
|
||||
if (!pageData) continue;
|
||||
|
||||
const { component } = pageData;
|
||||
const astroModuleId = prependForwardSlash(component);
|
||||
|
||||
const uniqueHoistedId = JSON.stringify(Array.from(hoistedScripts).sort());
|
||||
let moduleId: string;
|
||||
|
||||
|
||||
// If we're already tracking this set of hoisted scripts, get the unique id
|
||||
if (uniqueHoistedIds.has(uniqueHoistedId)) {
|
||||
moduleId = uniqueHoistedIds.get(uniqueHoistedId)!;
|
||||
|
@ -65,7 +57,7 @@ export function vitePluginAnalyzer(
|
|||
uniqueHoistedIds.set(uniqueHoistedId, moduleId);
|
||||
}
|
||||
internals.discoveredScripts.add(moduleId);
|
||||
|
||||
|
||||
// Make sure to track that this page uses this set of hoisted scripts
|
||||
if (internals.hoistedScriptIdToPagesMap.has(moduleId)) {
|
||||
const pages = internals.hoistedScriptIdToPagesMap.get(moduleId);
|
||||
|
@ -75,42 +67,42 @@ export function vitePluginAnalyzer(
|
|||
internals.hoistedScriptIdToHoistedMap.set(moduleId, hoistedScripts);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
name: '@astro/rollup-plugin-astro-analyzer',
|
||||
generateBundle() {
|
||||
const hoistScanner = hoistedScriptScanner();
|
||||
|
||||
const ids = this.getModuleIds();
|
||||
for(const id of ids) {
|
||||
for (const id of ids) {
|
||||
const info = this.getModuleInfo(id);
|
||||
if(!info || !info.meta?.astro) continue;
|
||||
if (!info || !info.meta?.astro) continue;
|
||||
|
||||
const astro = info.meta.astro as AstroPluginMetadata['astro'];
|
||||
|
||||
for(const c of astro.hydratedComponents) {
|
||||
for (const c of astro.hydratedComponents) {
|
||||
internals.discoveredHydratedComponents.add(c.resolvedPath || c.specifier);
|
||||
}
|
||||
|
||||
// Scan hoisted scripts
|
||||
hoistScanner.scan.call(this, astro.scripts, id);
|
||||
|
||||
if(astro.clientOnlyComponents.length) {
|
||||
if (astro.clientOnlyComponents.length) {
|
||||
const clientOnlys: string[] = [];
|
||||
|
||||
for(const c of astro.clientOnlyComponents) {
|
||||
for (const c of astro.clientOnlyComponents) {
|
||||
const cid = c.resolvedPath || c.specifier;
|
||||
internals.discoveredClientOnlyComponents.add(cid);
|
||||
clientOnlys.push(cid);
|
||||
}
|
||||
|
||||
for(const pageId of getTopLevelPages(id, this)) {
|
||||
for (const pageId of getTopLevelPages(id, this)) {
|
||||
const pageData = getPageDataByViteID(internals, pageId);
|
||||
if(!pageData) continue;
|
||||
|
||||
if (!pageData) continue;
|
||||
|
||||
trackClientOnlyPageDatas(internals, pageData, clientOnlys);
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +110,6 @@ export function vitePluginAnalyzer(
|
|||
|
||||
// Finalize hoisting
|
||||
hoistScanner.finalize();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { BuildInternals } from './internal.js';
|
|||
import type { StaticBuildOptions } from './types';
|
||||
|
||||
import glob from 'fast-glob';
|
||||
import * as fs from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { runHookBuildSsr } from '../../integrations/index.js';
|
||||
import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||
|
@ -12,7 +13,6 @@ import { pagesVirtualModuleId } from '../app/index.js';
|
|||
import { serializeRouteData } from '../routing/index.js';
|
||||
import { addRollupInput } from './add-rollup-input.js';
|
||||
import { eachPageData } from './internal.js';
|
||||
import * as fs from 'fs';
|
||||
|
||||
export const virtualModuleId = '@astrojs-ssr-virtual-entry';
|
||||
const resolvedVirtualModuleId = '\0' + virtualModuleId;
|
||||
|
@ -82,7 +82,7 @@ if(_start in adapter) {
|
|||
internals.staticFiles.add(chunk.fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (const [chunkName, chunk] of Object.entries(bundle)) {
|
||||
if (chunk.type === 'asset') {
|
||||
continue;
|
||||
|
@ -97,7 +97,7 @@ if(_start in adapter) {
|
|||
}
|
||||
|
||||
export async function injectManifest(buildOpts: StaticBuildOptions, internals: BuildInternals) {
|
||||
if(!internals.ssrEntryChunk) {
|
||||
if (!internals.ssrEntryChunk) {
|
||||
throw new Error(`Did not generate an entry chunk for SSR`);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,8 @@ export class Metadata {
|
|||
|
||||
*hoistedScriptPaths() {
|
||||
for (const metadata of this.deepMetadata()) {
|
||||
let i = 0, pathname = metadata.mockURL.pathname;
|
||||
let i = 0,
|
||||
pathname = metadata.mockURL.pathname;
|
||||
|
||||
while (i < metadata.hoisted.length) {
|
||||
// Strip off the leading "/@fs" added during compilation.
|
||||
|
|
|
@ -113,7 +113,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
|||
source,
|
||||
ssr: Boolean(opts?.ssr),
|
||||
viteTransform,
|
||||
pluginContext: this
|
||||
pluginContext: this,
|
||||
};
|
||||
if (query.astro) {
|
||||
if (query.type === 'style') {
|
||||
|
@ -222,7 +222,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
|||
const astroMetadata: AstroPluginMetadata['astro'] = {
|
||||
clientOnlyComponents: transformResult.clientOnlyComponents,
|
||||
hydratedComponents: transformResult.hydratedComponents,
|
||||
scripts: transformResult.scripts
|
||||
scripts: transformResult.scripts,
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -2,8 +2,8 @@ import type { TransformResult } from '@astrojs/compiler';
|
|||
|
||||
export interface PluginMetadata {
|
||||
astro: {
|
||||
hydratedComponents: TransformResult['hydratedComponents'],
|
||||
clientOnlyComponents: TransformResult['clientOnlyComponents'],
|
||||
scripts: TransformResult['scripts']
|
||||
}
|
||||
hydratedComponents: TransformResult['hydratedComponents'];
|
||||
clientOnlyComponents: TransformResult['clientOnlyComponents'];
|
||||
scripts: TransformResult['scripts'];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import type { GetModuleInfo, ModuleInfo, OutputChunk } from 'rollup';
|
||||
import type { GetModuleInfo, OutputChunk } from 'rollup';
|
||||
import { BuildInternals } from '../core/build/internal';
|
||||
import type { PageBuildData } from '../core/build/types';
|
||||
|
||||
import crypto from 'crypto';
|
||||
import esbuild from 'esbuild';
|
||||
import { Plugin as VitePlugin } from 'vite';
|
||||
import { resolvedPagesVirtualModuleId } from '../core/app/index.js';
|
||||
import { getPageDataByViteID, getPageDatasByClientOnlyID } from '../core/build/internal.js';
|
||||
import { getTopLevelPages, walkParentInfos } from '../core/build/graph.js';
|
||||
import { getPageDataByViteID, getPageDatasByClientOnlyID } from '../core/build/internal.js';
|
||||
import { isCSSRequest } from '../core/render/util.js';
|
||||
|
||||
interface PluginOptions {
|
||||
|
|
|
@ -7,15 +7,14 @@ import matter from 'gray-matter';
|
|||
import { fileURLToPath } from 'url';
|
||||
import type { Plugin } from 'vite';
|
||||
import type { AstroConfig } from '../@types/astro';
|
||||
import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types';
|
||||
import { pagesVirtualModuleId } from '../core/app/index.js';
|
||||
import { collectErrorMetadata } from '../core/errors.js';
|
||||
import { prependForwardSlash } from '../core/path.js';
|
||||
import { resolvePages, viteID } from '../core/util.js';
|
||||
import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types';
|
||||
import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js';
|
||||
import { getFileInfo } from '../vite-plugin-utils/index.js';
|
||||
|
||||
|
||||
interface AstroPluginOptions {
|
||||
config: AstroConfig;
|
||||
}
|
||||
|
@ -212,7 +211,7 @@ ${tsResult}`;
|
|||
const astroMetadata: AstroPluginMetadata['astro'] = {
|
||||
clientOnlyComponents: transformResult.clientOnlyComponents,
|
||||
hydratedComponents: transformResult.hydratedComponents,
|
||||
scripts: transformResult.scripts
|
||||
scripts: transformResult.scripts,
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -19,7 +19,7 @@ describe('Astro Markdown with draft posts disabled', () => {
|
|||
} catch (err) {
|
||||
expect(err.code).to.equal('ENOENT');
|
||||
}
|
||||
expect(renderedDraft).to.equal(false,'Rendered a draft post');
|
||||
expect(renderedDraft).to.equal(false, 'Rendered a draft post');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ document.getElementsByTagName = () => [];
|
|||
document.currentScript = null;
|
||||
|
||||
const ceDefine = customElements.define;
|
||||
customElements.define = function(tagName, Ctr) {
|
||||
customElements.define = function (tagName, Ctr) {
|
||||
Ctr[Symbol.for('tagName')] = tagName;
|
||||
return ceDefine.call(this, tagName, Ctr);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ function isCustomElementTag(name) {
|
|||
function getCustomElementConstructor(name) {
|
||||
if (typeof customElements !== 'undefined' && isCustomElementTag(name)) {
|
||||
return customElements.get(name) || null;
|
||||
} else if(typeof name === 'function') {
|
||||
} else if (typeof name === 'function') {
|
||||
return name;
|
||||
}
|
||||
return null;
|
||||
|
@ -28,7 +28,7 @@ async function check(Component, _props, _children) {
|
|||
|
||||
function* render(Component, attrs, children) {
|
||||
let tagName = Component;
|
||||
if(typeof tagName !== 'string') {
|
||||
if (typeof tagName !== 'string') {
|
||||
tagName = Component[Symbol.for('tagName')];
|
||||
}
|
||||
const instance = new LitElementRenderer(tagName);
|
||||
|
|
|
@ -18,7 +18,7 @@ function getViteConfiguration() {
|
|||
'@lit-labs/ssr/lib/install-global-dom-shim.js',
|
||||
'@lit-labs/ssr/lib/render-lit-html.js',
|
||||
'@lit-labs/ssr/lib/lit-element-renderer.js',
|
||||
'@astrojs/lit/server.js'
|
||||
'@astrojs/lit/server.js',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import type { AstroAdapter, AstroConfig, AstroIntegration, BuildConfig, RouteData } from 'astro';
|
||||
import type { Plugin as VitePlugin } from 'vite';
|
||||
import esbuild from 'esbuild';
|
||||
import * as fs from 'fs';
|
||||
import * as npath from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import type { Plugin as VitePlugin } from 'vite';
|
||||
import { createRedirects } from './shared.js';
|
||||
|
||||
export function getAdapter(): AstroAdapter {
|
||||
|
@ -109,19 +109,19 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
|
|||
const injectPlugin: VitePlugin = {
|
||||
name: '@astrojs/netlify/plugin-inject',
|
||||
generateBundle(_options, bundle) {
|
||||
if(_buildConfig.serverEntry in bundle) {
|
||||
if (_buildConfig.serverEntry in bundle) {
|
||||
const chunk = bundle[_buildConfig.serverEntry];
|
||||
if(chunk && chunk.type === 'chunk') {
|
||||
if (chunk && chunk.type === 'chunk') {
|
||||
chunk.code = `globalThis.process = { argv: [], env: {}, };${chunk.code}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
updateConfig({
|
||||
vite: {
|
||||
plugins: [injectPlugin]
|
||||
}
|
||||
plugins: [injectPlugin],
|
||||
},
|
||||
});
|
||||
},
|
||||
'astro:config:done': ({ config, setAdapter }) => {
|
||||
|
|
|
@ -19,7 +19,7 @@ Deno.test({
|
|||
const doc = new DOMParser().parseFromString(html, `text/html`);
|
||||
const div = doc.querySelector('#thing');
|
||||
assert(div, 'div exists');
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
await close();
|
||||
|
|
Loading…
Reference in a new issue