From 4efe519456de50ae9636ac7dce684af1830afccc Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 6 May 2024 15:28:05 +0000 Subject: [PATCH] [ci] format --- .../src/content/vite-plugin-content-virtual-mod.ts | 2 +- packages/astro/src/core/build/pipeline.ts | 2 +- .../astro/src/core/build/plugins/plugin-analyzer.ts | 12 ++++++------ .../astro/src/core/build/plugins/plugin-content.ts | 6 +++--- .../src/core/build/plugins/plugin-hoisted-scripts.ts | 12 ++++++------ packages/astro/src/core/build/plugins/plugin-ssr.ts | 2 +- packages/astro/src/core/build/static-build.ts | 4 ++-- packages/astro/src/core/util.ts | 7 ++++--- .../astro/src/vite-plugin-astro-server/pipeline.ts | 2 +- packages/astro/src/vite-plugin-scanner/index.ts | 2 +- .../experimental-content-collections-render.test.js | 4 ++-- 11 files changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts index bd3362343d..de50edeaaa 100644 --- a/packages/astro/src/content/vite-plugin-content-virtual-mod.ts +++ b/packages/astro/src/content/vite-plugin-content-virtual-mod.ts @@ -8,7 +8,7 @@ import type { AstroSettings } from '../@types/astro.js'; import { encodeName } from '../core/build/util.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js'; import { appendForwardSlash, removeFileExtension } from '../core/path.js'; -import { rootRelativePath, isServerLikeOutput } from '../core/util.js'; +import { isServerLikeOutput, rootRelativePath } from '../core/util.js'; import type { AstroPluginMetadata } from '../vite-plugin-astro/index.js'; import { CONTENT_FLAG, diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index 5df7cb1e30..a78c8eaf89 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -9,6 +9,7 @@ import { createModuleScriptsSet, createStylesheetElementSet, } from '../render/ssr-element.js'; +import { isServerLikeOutput } from '../util.js'; import { type BuildInternals, cssOrder, @@ -21,7 +22,6 @@ import { getVirtualModulePageNameFromPath } from './plugins/util.js'; import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js'; import type { PageBuildData, StaticBuildOptions } from './types.js'; import { i18nHasFallback } from './util.js'; -import { isServerLikeOutput } from '../util.js'; /** * The build pipeline is responsible to gather the files emitted by the SSR build and generate the pages by executing these files. diff --git a/packages/astro/src/core/build/plugins/plugin-analyzer.ts b/packages/astro/src/core/build/plugins/plugin-analyzer.ts index c72026e0f1..5bc0c53e04 100644 --- a/packages/astro/src/core/build/plugins/plugin-analyzer.ts +++ b/packages/astro/src/core/build/plugins/plugin-analyzer.ts @@ -53,7 +53,7 @@ export function vitePluginAnalyzer( if (hoistedScripts.size) { for (const parentInfo of getParentModuleInfos(from, this, isPropagatedAsset)) { if (isPropagatedAsset(parentInfo.id)) { - if(isContentCollectionsCacheEnabled(options.settings.config)) { + if (isContentCollectionsCacheEnabled(options.settings.config)) { if (!pageScripts.has(parentInfo.id)) { pageScripts.set(parentInfo.id, { type: 'content', @@ -62,8 +62,8 @@ export function vitePluginAnalyzer( }); } const propagaters = pageScripts.get(parentInfo.id)!.propagatedMapByImporter; - for(const hid of hoistedScripts) { - if(!propagaters.has(parentInfo.id)) { + for (const hid of hoistedScripts) { + if (!propagaters.has(parentInfo.id)) { propagaters.set(parentInfo.id, new Set()); } propagaters.get(parentInfo.id)!.add(hid); @@ -107,11 +107,11 @@ export function vitePluginAnalyzer( finalize() { for (const [pageId, { hoistedSet, propagatedMapByImporter, type }] of pageScripts) { let astroModuleId: string; - if(type === 'page') { + if (type === 'page') { const pageData = getPageDataByViteID(internals, pageId); if (!pageData) { continue; - }; + } const { component } = pageData; astroModuleId = prependForwardSlash(component); @@ -142,7 +142,7 @@ export function vitePluginAnalyzer( } } - if(type === 'page') { + if (type === 'page') { // Make sure to track that this page uses this set of hoisted scripts if (internals.hoistedScriptIdToPagesMap.has(moduleId)) { const pages = internals.hoistedScriptIdToPagesMap.get(moduleId); diff --git a/packages/astro/src/core/build/plugins/plugin-content.ts b/packages/astro/src/core/build/plugins/plugin-content.ts index c94f01f3fc..7210dd4f18 100644 --- a/packages/astro/src/core/build/plugins/plugin-content.ts +++ b/packages/astro/src/core/build/plugins/plugin-content.ts @@ -3,6 +3,7 @@ import fsMod from 'node:fs'; import { fileURLToPath } from 'node:url'; import pLimit from 'p-limit'; import { type Plugin as VitePlugin, normalizePath } from 'vite'; +import type { AstroConfig } from '../../../@types/astro.js'; import { CONTENT_RENDER_FLAG, PROPAGATED_ASSET_FLAG } from '../../../content/consts.js'; import { type ContentLookupMap, hasContentFlag } from '../../../content/utils.js'; import { @@ -17,6 +18,7 @@ import { removeFileExtension, removeLeadingForwardSlash, } from '../../path.js'; +import { isContentCollectionsCacheEnabled } from '../../util.js'; import { addRollupInput } from '../add-rollup-input.js'; import { CHUNKS_PATH } from '../consts.js'; import { type BuildInternals } from '../internal.js'; @@ -25,8 +27,6 @@ import { copyFiles } from '../static-build.js'; import type { StaticBuildOptions } from '../types.js'; import { encodeName } from '../util.js'; import { extendManualChunks } from './util.js'; -import { isContentCollectionsCacheEnabled } from '../../util.js'; -import type { AstroConfig } from '../../../@types/astro.js'; const CONTENT_CACHE_DIR = './content/'; const CONTENT_MANIFEST_FILE = './manifest.json'; @@ -479,7 +479,7 @@ export function pluginContent( }, async 'build:post'() { - if(!isContentCollectionsCacheEnabled(opts.settings.config)) { + if (!isContentCollectionsCacheEnabled(opts.settings.config)) { return; } // Cache build output of chunks and assets diff --git a/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts b/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts index 641665b84c..80bfa6a6e9 100644 --- a/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts +++ b/packages/astro/src/core/build/plugins/plugin-hoisted-scripts.ts @@ -11,7 +11,6 @@ function virtualHoistedEntry(id: string) { return id.startsWith('/astro/hoisted.js?q='); } - export function vitePluginHoistedScripts( settings: AstroSettings, internals: BuildInternals @@ -77,7 +76,7 @@ export function vitePluginHoistedScripts( const facadeId = output.facadeModuleId!; // Pages - if(internals.hoistedScriptIdToPagesMap.has(facadeId)) { + if (internals.hoistedScriptIdToPagesMap.has(facadeId)) { const pages = internals.hoistedScriptIdToPagesMap.get(facadeId)!; for (const pathname of pages) { const vid = viteID(new URL('.' + pathname, settings.config.root)); @@ -102,11 +101,12 @@ export function vitePluginHoistedScripts( // Content collection entries else { const contentModules = internals.hoistedScriptIdToContentMap.get(facadeId)!; - for(const contentId of contentModules) { - if(isContentCollectionsCacheEnabled(settings.config)) { - const scripts = internals.propagatedScriptsMap.get(contentId) ?? + for (const contentId of contentModules) { + if (isContentCollectionsCacheEnabled(settings.config)) { + const scripts = + internals.propagatedScriptsMap.get(contentId) ?? internals.propagatedScriptsMap.set(contentId, new Set()).get(contentId)!; - + scripts.add(facadeId); } } diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 1d8ea677f4..07cba1d57c 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -2,9 +2,9 @@ import { join } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import type { Plugin as VitePlugin } from 'vite'; import type { AstroAdapter } from '../../../@types/astro.js'; -import { isServerLikeOutput } from '../../util.js'; import { isFunctionPerRouteEnabled } from '../../../integrations/hooks.js'; import { routeIsRedirect } from '../../redirects/index.js'; +import { isServerLikeOutput } from '../../util.js'; import { addRollupInput } from '../add-rollup-input.js'; import type { BuildInternals } from '../internal.js'; import { eachPageFromAllPages } from '../internal.js'; diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 91d17e3743..e2acc4ea56 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -28,6 +28,7 @@ import { generatePages } from './generate.js'; import { trackPageData } from './internal.js'; import { type AstroBuildPluginContainer, createPluginContainer } from './plugin.js'; import { registerAllPlugins } from './plugins/index.js'; +import { copyContentToCache } from './plugins/plugin-content.js'; import { RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID } from './plugins/plugin-manifest.js'; import { ASTRO_PAGE_RESOLVED_MODULE_ID } from './plugins/plugin-pages.js'; import { RESOLVED_RENDERERS_MODULE_ID } from './plugins/plugin-renderers.js'; @@ -35,7 +36,6 @@ import { RESOLVED_SPLIT_MODULE_ID, RESOLVED_SSR_VIRTUAL_MODULE_ID } from './plug import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from './plugins/util.js'; import type { StaticBuildOptions } from './types.js'; import { encodeName, getTimeStat, viteBuildReturnToRollupOutputs } from './util.js'; -import { copyContentToCache } from './plugins/plugin-content.js'; export async function viteBuild(opts: StaticBuildOptions) { const { allPages, settings } = opts; @@ -108,7 +108,7 @@ export async function viteBuild(opts: StaticBuildOptions) { const ssrOutputs = viteBuildReturnToRollupOutputs(ssrOutput); const clientOutputs = viteBuildReturnToRollupOutputs(clientOutput ?? []); await runPostBuildHooks(container, ssrOutputs, clientOutputs); - if(opts.settings.config.experimental.contentCollectionCache) { + if (opts.settings.config.experimental.contentCollectionCache) { await copyContentToCache(opts); } settings.timer.end('Client build'); diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 405479030a..a48a85d16b 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -155,11 +155,12 @@ export function isModeServerWithNoAdapter(settings: AstroSettings): boolean { return isServerLikeOutput(settings.config) && !settings.adapter; } - export function isContentCollectionsCacheEnabled(config: AstroConfig): boolean { - return config.experimental.contentCollectionCache && + return ( + config.experimental.contentCollectionCache && // contentCollectionsCache is an SSG only feature - !isServerLikeOutput(config); + !isServerLikeOutput(config) + ); } export function relativeToSrcDir(config: AstroConfig, idOrUrl: URL | string) { diff --git a/packages/astro/src/vite-plugin-astro-server/pipeline.ts b/packages/astro/src/vite-plugin-astro-server/pipeline.ts index 2dfaaac55f..7ccc636382 100644 --- a/packages/astro/src/vite-plugin-astro-server/pipeline.ts +++ b/packages/astro/src/vite-plugin-astro-server/pipeline.ts @@ -16,7 +16,7 @@ import { AggregateError, CSSError, MarkdownError } from '../core/errors/index.js import type { Logger } from '../core/logger/core.js'; import type { ModuleLoader } from '../core/module-loader/index.js'; import { Pipeline, loadRenderer } from '../core/render/index.js'; -import { isPage, resolveIdToUrl, viteID, isServerLikeOutput } from '../core/util.js'; +import { isPage, isServerLikeOutput, resolveIdToUrl, viteID } from '../core/util.js'; import { PAGE_SCRIPT_ID } from '../vite-plugin-scripts/index.js'; import { getStylesForURL } from './css.js'; import { getComponentMetadata } from './metadata.js'; diff --git a/packages/astro/src/vite-plugin-scanner/index.ts b/packages/astro/src/vite-plugin-scanner/index.ts index b0065f1ab6..78069b937a 100644 --- a/packages/astro/src/vite-plugin-scanner/index.ts +++ b/packages/astro/src/vite-plugin-scanner/index.ts @@ -4,7 +4,7 @@ import type { Plugin as VitePlugin } from 'vite'; import { normalizePath } from 'vite'; import type { AstroSettings } from '../@types/astro.js'; import { type Logger } from '../core/logger/core.js'; -import { isEndpoint, isPage, rootRelativePath, isServerLikeOutput } from '../core/util.js'; +import { isEndpoint, isPage, isServerLikeOutput, rootRelativePath } from '../core/util.js'; import { getPrerenderDefault } from '../prerender/utils.js'; import { scan } from './scan.js'; diff --git a/packages/astro/test/experimental-content-collections-render.test.js b/packages/astro/test/experimental-content-collections-render.test.js index cf7a22bad1..19349dc397 100644 --- a/packages/astro/test/experimental-content-collections-render.test.js +++ b/packages/astro/test/experimental-content-collections-render.test.js @@ -114,10 +114,10 @@ if (!isWindows) { it('Includes CSS for rendered entry', async () => { const html = await fixture.readFile('/launch-week/index.html'); const $ = cheerio.load(html); - + // Renders content assert.equal($('ul li').length, 3); - + // Includes styles assert.equal($('link[rel=stylesheet]').length, 1); });