From 91dc0f401545bef49f19193029349fc01c811b1d Mon Sep 17 00:00:00 2001 From: matthewp Date: Mon, 6 Feb 2023 15:43:56 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/content/index.ts | 4 +- .../src/content/vite-plugin-content-assets.ts | 46 +++++++++---------- packages/astro/src/core/build/graph.ts | 2 +- .../src/core/build/plugins/plugin-analyzer.ts | 6 +-- packages/astro/src/core/build/static-build.ts | 9 ++-- .../test/content-collections-render.test.js | 4 +- 6 files changed, 35 insertions(+), 36 deletions(-) diff --git a/packages/astro/src/content/index.ts b/packages/astro/src/content/index.ts index 818e87e35417..f12106b0aa31 100644 --- a/packages/astro/src/content/index.ts +++ b/packages/astro/src/content/index.ts @@ -1,8 +1,6 @@ export { attachContentServerListeners } from './server-listeners.js'; export { createContentTypesGenerator } from './types-generator.js'; export { contentObservable, getContentPaths, getDotAstroTypeReference } from './utils.js'; -export { - astroContentAssetPropagationPlugin, -} from './vite-plugin-content-assets.js'; +export { astroContentAssetPropagationPlugin } from './vite-plugin-content-assets.js'; export { astroContentImportPlugin } from './vite-plugin-content-imports.js'; export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js'; diff --git a/packages/astro/src/content/vite-plugin-content-assets.ts b/packages/astro/src/content/vite-plugin-content-assets.ts index 7610d9f9d0db..74378f4e0f50 100644 --- a/packages/astro/src/content/vite-plugin-content-assets.ts +++ b/packages/astro/src/content/vite-plugin-content-assets.ts @@ -1,11 +1,13 @@ -import { pathToFileURL } from 'url'; import npath from 'node:path'; +import { pathToFileURL } from 'url'; import type { Plugin } from 'vite'; import { moduleIsTopLevelPage, walkParentInfos } from '../core/build/graph.js'; import { BuildInternals, getPageDataByViteID } from '../core/build/internal.js'; import { AstroBuildPlugin } from '../core/build/plugin.js'; +import type { StaticBuildOptions } from '../core/build/types'; import type { ModuleLoader } from '../core/module-loader/loader.js'; import { createViteLoader } from '../core/module-loader/vite.js'; +import { prependForwardSlash } from '../core/path.js'; import { getStylesForURL } from '../core/render/dev/css.js'; import { getScriptsForURL } from '../core/render/dev/scripts.js'; import { @@ -15,8 +17,6 @@ import { SCRIPTS_PLACEHOLDER, STYLES_PLACEHOLDER, } from './consts.js'; -import type { RollupOutput, OutputChunk, StaticBuildOptions } from '../core/build/types'; -import { prependForwardSlash } from '../core/path.js'; function isPropagatedAsset(viteId: string): boolean { const url = new URL(viteId, 'file://'); @@ -76,7 +76,10 @@ export function astroContentAssetPropagationPlugin({ mode }: { mode: string }): }; } -export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: BuildInternals): AstroBuildPlugin { +export function astroConfigBuildPlugin( + options: StaticBuildOptions, + internals: BuildInternals +): AstroBuildPlugin { let ssrPluginContext: any = undefined; return { build: 'ssr', @@ -86,15 +89,15 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B vitePlugin: { name: 'astro:content-build-plugin', generateBundle() { - if(build === 'ssr') { + if (build === 'ssr') { ssrPluginContext = this; } - } + }, }, }; }, 'build:post': ({ ssrOutputs, clientOutputs, mutate }) => { - const outputs = ssrOutputs.flatMap(o => o.output); + const outputs = ssrOutputs.flatMap((o) => o.output); for (const chunk of outputs) { if ( chunk.type === 'chunk' && @@ -109,16 +112,16 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B const pageViteID = pageInfo.id; const pageData = getPageDataByViteID(internals, pageViteID); if (!pageData) continue; - + const _entryCss = pageData.propagatedStyles?.get(id); const _entryScripts = pageData.propagatedScripts?.get(id); - if(_entryCss) { - for(const value of _entryCss) { + if (_entryCss) { + for (const value of _entryCss) { entryCSS.add(value); } } - if(_entryScripts) { - for(const value of _entryScripts) { + if (_entryScripts) { + for (const value of _entryScripts) { entryScripts.add(value); } } @@ -135,11 +138,11 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B } if (entryScripts.size) { const entryFileNames = new Set(); - for(const output of clientOutputs) { - for(const clientChunk of output.output) { - if(clientChunk.type !== 'chunk') continue; - for(const [id] of Object.entries(clientChunk.modules)) { - if(entryScripts.has(id)) { + for (const output of clientOutputs) { + for (const clientChunk of output.output) { + if (clientChunk.type !== 'chunk') continue; + for (const [id] of Object.entries(clientChunk.modules)) { + if (entryScripts.has(id)) { entryFileNames.add(clientChunk.fileName); } } @@ -150,11 +153,8 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B JSON.stringify( [...entryFileNames].map((src) => ({ props: { - src: prependForwardSlash(npath.posix.join( - options.settings.config.base, - src - )), - type: 'module' + src: prependForwardSlash(npath.posix.join(options.settings.config.base, src)), + type: 'module', }, children: '', })) @@ -164,7 +164,7 @@ export function astroConfigBuildPlugin(options: StaticBuildOptions, internals: B mutate(chunk, 'server', newCode); } } - } + }, }, }; } diff --git a/packages/astro/src/core/build/graph.ts b/packages/astro/src/core/build/graph.ts index a0ae053d5f1a..5edb07a710e2 100644 --- a/packages/astro/src/core/build/graph.ts +++ b/packages/astro/src/core/build/graph.ts @@ -40,7 +40,7 @@ export function moduleIsTopLevelPage(info: ModuleInfo): boolean { // This could be a .astro page, a .markdown or a .md (or really any file extension for markdown files) page. export function* getTopLevelPages( id: string, - ctx: { getModuleInfo: GetModuleInfo }, + ctx: { getModuleInfo: GetModuleInfo } ): Generator<[ModuleInfo, number, number], void, unknown> { for (const res of walkParentInfos(id, ctx)) { if (moduleIsTopLevelPage(res[0])) { diff --git a/packages/astro/src/core/build/plugins/plugin-analyzer.ts b/packages/astro/src/core/build/plugins/plugin-analyzer.ts index df7faebf09cd..ff2ac3bbc8cb 100644 --- a/packages/astro/src/core/build/plugins/plugin-analyzer.ts +++ b/packages/astro/src/core/build/plugins/plugin-analyzer.ts @@ -4,14 +4,14 @@ import type { PluginMetadata as AstroPluginMetadata } from '../../../vite-plugin import type { BuildInternals } from '../internal.js'; import type { AstroBuildPlugin } from '../plugin.js'; +import { PROPAGATED_ASSET_FLAG } from '../../../content/consts.js'; import { prependForwardSlash } from '../../../core/path.js'; import { getTopLevelPages, moduleIsTopLevelPage, walkParentInfos } from '../graph.js'; import { getPageDataByViteID, trackClientOnlyPageDatas } from '../internal.js'; -import { PROPAGATED_ASSET_FLAG } from '../../../content/consts.js'; function isPropagatedAsset(id: string) { try { - return new URL('file://' + id).searchParams.has(PROPAGATED_ASSET_FLAG) + return new URL('file://' + id).searchParams.has(PROPAGATED_ASSET_FLAG); } catch { return false; } @@ -180,7 +180,7 @@ export function pluginAnalyzer(internals: BuildInternals): AstroBuildPlugin { return { vitePlugin: vitePluginAnalyzer(internals), }; - } + }, }, }; } diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 0dcfa6a51782..aef8a1aabab7 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -248,9 +248,12 @@ async function runPostBuildHooks( const config = container.options.settings.config; const buildConfig = container.options.settings.config.build; for (const [fileName, mutation] of mutations) { - const root = config.output === 'server' ? - mutation.build === 'server' ? buildConfig.server : buildConfig.client : - config.outDir; + const root = + config.output === 'server' + ? mutation.build === 'server' + ? buildConfig.server + : buildConfig.client + : config.outDir; const fileURL = new URL(fileName, root); await fs.promises.mkdir(new URL('./', fileURL), { recursive: true }); await fs.promises.writeFile(fileURL, mutation.code, 'utf-8'); diff --git a/packages/astro/test/content-collections-render.test.js b/packages/astro/test/content-collections-render.test.js index ad45e58a4c61..8410487c62a4 100644 --- a/packages/astro/test/content-collections-render.test.js +++ b/packages/astro/test/content-collections-render.test.js @@ -45,9 +45,7 @@ describe('Content Collections - render()', () => { // Includes hoisted script expect( - [...allScripts].find((script) => - $(script).attr('src')?.includes('WithScripts') - ), + [...allScripts].find((script) => $(script).attr('src')?.includes('WithScripts')), '`WithScripts.astro` hoisted script missing from head.' ).to.not.be.undefined;