0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

fix(core): add error log for server islands

This commit is contained in:
Emanuele Stoppa 2024-12-17 16:31:55 +00:00
parent 8da2318551
commit 6ce0348d14
9 changed files with 41 additions and 8 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes an issue where Astro didn't print error logs when Astro Islands were used in incorrect cases.

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes an issue where Astro was printing the incorrect output format when running the `astro build` command

View file

@ -0,0 +1,5 @@
---
'@astrojs/underscore-redirects': minor
---
Adds a new `buildOutput` property to the API `createRedirectsFromAstroRoutes`

View file

@ -12,7 +12,7 @@ import {
runHookConfigSetup, runHookConfigSetup,
} from '../../integrations/hooks.js'; } from '../../integrations/hooks.js';
import type { AstroSettings, ManifestData } from '../../types/astro.js'; import type { AstroSettings, ManifestData } from '../../types/astro.js';
import type { AstroConfig, AstroInlineConfig, RuntimeMode } from '../../types/public/config.js'; import type { AstroInlineConfig, RuntimeMode } from '../../types/public/config.js';
import { resolveConfig } from '../config/config.js'; import { resolveConfig } from '../config/config.js';
import { createNodeLogger } from '../config/logging.js'; import { createNodeLogger } from '../config/logging.js';
import { createSettings } from '../config/settings.js'; import { createSettings } from '../config/settings.js';
@ -163,7 +163,7 @@ class AstroBuilder {
await runHookBuildStart({ config: this.settings.config, logging: this.logger }); await runHookBuildStart({ config: this.settings.config, logging: this.logger });
this.validateConfig(); this.validateConfig();
this.logger.info('build', `output: ${blue('"' + this.settings.config.output + '"')}`); this.logger.info('build', `output: ${blue('"' + this.settings.buildOutput + '"')}`);
this.logger.info('build', `directory: ${blue(fileURLToPath(this.settings.config.outDir))}`); this.logger.info('build', `directory: ${blue(fileURLToPath(this.settings.config.outDir))}`);
if (this.settings.adapter) { if (this.settings.adapter) {
this.logger.info('build', `adapter: ${green(this.settings.adapter.name)}`); this.logger.info('build', `adapter: ${green(this.settings.adapter.name)}`);
@ -283,7 +283,7 @@ class AstroBuilder {
logger: Logger; logger: Logger;
timeStart: number; timeStart: number;
pageCount: number; pageCount: number;
buildMode: AstroConfig['output']; buildMode: AstroSettings['buildOutput'];
}) { }) {
const total = getTimeStat(timeStart, performance.now()); const total = getTimeStat(timeStart, performance.now());

View file

@ -63,7 +63,7 @@ export async function viteBuild(opts: StaticBuildOptions) {
registerAllPlugins(container); registerAllPlugins(container);
// Build your project (SSR application code, assets, client JS, etc.) // Build your project (SSR application code, assets, client JS, etc.)
const ssrTime = performance.now(); const ssrTime = performance.now();
opts.logger.info('build', `Building ${settings.config.output} entrypoints...`); opts.logger.info('build', `Building ${settings.buildOutput} entrypoints...`);
const ssrOutput = await ssrBuild(opts, internals, pageInput, container); const ssrOutput = await ssrBuild(opts, internals, pageInput, container);
opts.logger.info('build', green(`✓ Completed in ${getTimeStat(ssrTime, performance.now())}.`)); opts.logger.info('build', green(`✓ Completed in ${getTimeStat(ssrTime, performance.now())}.`));

View file

@ -170,7 +170,7 @@ export async function createVite(
astroInternationalization({ settings }), astroInternationalization({ settings }),
vitePluginActions({ fs, settings }), vitePluginActions({ fs, settings }),
vitePluginUserActions({ settings }), vitePluginUserActions({ settings }),
vitePluginServerIslands({ settings }), vitePluginServerIslands({ settings, logger }),
astroContainer(), astroContainer(),
astroHmrReloadPlugin(), astroHmrReloadPlugin(),
], ],

View file

@ -33,6 +33,7 @@ export type LoggerLabel =
| 'env' | 'env'
| 'update' | 'update'
| 'adapter' | 'adapter'
| 'islands'
// SKIP_FORMAT: A special label that tells the logger not to apply any formatting. // SKIP_FORMAT: A special label that tells the logger not to apply any formatting.
// Useful for messages that are already formatted, like the server start message. // Useful for messages that are already formatted, like the server start message.
| 'SKIP_FORMAT'; | 'SKIP_FORMAT';

View file

@ -1,12 +1,12 @@
import type { ConfigEnv, ViteDevServer, Plugin as VitePlugin } from 'vite'; import type { ConfigEnv, ViteDevServer, Plugin as VitePlugin } from 'vite';
import type { AstroSettings } from '../../types/astro.js'; import type { AstroPluginOptions } from '../../types/astro.js';
import type { AstroPluginMetadata } from '../../vite-plugin-astro/index.js'; import type { AstroPluginMetadata } from '../../vite-plugin-astro/index.js';
export const VIRTUAL_ISLAND_MAP_ID = '@astro-server-islands'; export const VIRTUAL_ISLAND_MAP_ID = '@astro-server-islands';
export const RESOLVED_VIRTUAL_ISLAND_MAP_ID = '\0' + VIRTUAL_ISLAND_MAP_ID; export const RESOLVED_VIRTUAL_ISLAND_MAP_ID = '\0' + VIRTUAL_ISLAND_MAP_ID;
const serverIslandPlaceholder = "'$$server-islands$$'"; const serverIslandPlaceholder = "'$$server-islands$$'";
export function vitePluginServerIslands({ settings }: { settings: AstroSettings }): VitePlugin { export function vitePluginServerIslands({ settings, logger }: AstroPluginOptions): VitePlugin {
let command: ConfigEnv['command'] = 'serve'; let command: ConfigEnv['command'] = 'serve';
let viteServer: ViteDevServer | null = null; let viteServer: ViteDevServer | null = null;
const referenceIdMap = new Map<string, string>(); const referenceIdMap = new Map<string, string>();
@ -37,6 +37,20 @@ export function vitePluginServerIslands({ settings }: { settings: AstroSettings
if (astro?.serverComponents.length) { if (astro?.serverComponents.length) {
for (const comp of astro.serverComponents) { for (const comp of astro.serverComponents) {
if (!settings.serverIslandNameMap.has(comp.resolvedPath)) { if (!settings.serverIslandNameMap.has(comp.resolvedPath)) {
if (!settings.adapter) {
logger.error(
'islands',
"You tried to use a server island without an adapter. This an error and your project won't build.",
);
}
if (settings.buildOutput !== 'server') {
logger.error(
'islands',
'You tried to use a server island, but your output isn\'t `"server"`. Use an adapter that support server output.',
);
}
let name = comp.localName; let name = comp.localName;
let idx = 1; let idx = 1;

View file

@ -18,6 +18,7 @@ interface CreateRedirectsFromAstroRoutesParams {
*/ */
routeToDynamicTargetMap: Map<IntegrationRouteData, string>; routeToDynamicTargetMap: Map<IntegrationRouteData, string>;
dir: URL; dir: URL;
buildOutput: 'static' | 'server';
} }
/** /**
@ -27,6 +28,7 @@ export function createRedirectsFromAstroRoutes({
config, config,
routeToDynamicTargetMap, routeToDynamicTargetMap,
dir, dir,
buildOutput,
}: CreateRedirectsFromAstroRoutesParams) { }: CreateRedirectsFromAstroRoutesParams) {
const base = const base =
config.base && config.base !== '/' config.base && config.base !== '/'
@ -34,7 +36,8 @@ export function createRedirectsFromAstroRoutes({
? config.base.slice(0, -1) ? config.base.slice(0, -1)
: config.base : config.base
: ''; : '';
const output = config.output; // TODO: the use of `config.output` is deprecated. We need to update the adapters that use this package to pass the new buildOutput
const output = buildOutput ?? config.output;
const _redirects = new Redirects(); const _redirects = new Redirects();
for (const [route, dynamicTarget = ''] of routeToDynamicTargetMap) { for (const [route, dynamicTarget = ''] of routeToDynamicTargetMap) {