mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
[ci] format
This commit is contained in:
parent
4d905ccef6
commit
4efe519456
11 changed files with 28 additions and 27 deletions
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue