Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/astro/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { UserConfig as ViteUserConfig, UserConfigFn as ViteUserConfigFn } from 'vite';
import type { FontFamily } from '../assets/fonts/types.js';
import { createRoutesList } from '../core/routing/index.js';
import type {
AstroInlineConfig,
AstroUserConfig,
Expand Down Expand Up @@ -54,7 +53,6 @@ export function getViteConfig(
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
let settings = await createSettings(config, userViteConfig.root);
settings = await runHookConfigSetup({ settings, command: cmd, logger });
const routesList = await createRoutesList({ settings }, logger);
const viteConfig = await createVite(
{
plugins: config.legacy.collections
Expand All @@ -64,7 +62,7 @@ export function getViteConfig(
]
: [],
},
{ settings, command: cmd, logger, mode, sync: false, routesList },
{ settings, command: cmd, logger, mode, sync: false },
);
await runHookConfigDone({ settings, logger });
return mergeConfig(viteConfig, userViteConfig);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { RoutesList } from '../../types/astro.js';
import type { AstroConfig } from '../../types/public/index.js';
import { decodeKey } from '../encryption.js';
import { NOOP_MIDDLEWARE_FN } from '../middleware/noop-middleware.js';
import { deserializeRouteData } from '../routing/manifest/serialization.js';
import { deserializeRouteData } from './manifest.js';
import type { RouteInfo, SerializedSSRManifest, SSRManifest } from './types.js';

export function deserializeManifest(
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export { App } from './app.js';
export { BaseApp, type RenderErrorOptions, type RenderOptions } from './base.js';
export { deserializeManifest, fromRoutingStrategy, toRoutingStrategy } from './common.js';
export {
deserializeRouteData,
deserializeRouteInfo,
serializeRouteData,
serializeRouteInfo,
} from './manifest.js';
export { AppPipeline } from './pipeline.js';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SerializedRouteData } from '../../../types/astro.js';
import type { AstroConfig } from '../../../types/public/config.js';
import type { RouteData } from '../../../types/public/internal.js';
import type { SerializedRouteData } from '../../types/astro.js';
import type { AstroConfig, RouteData } from '../../types/public/index.js';
import type { RouteInfo, SerializedRouteInfo } from './types.js';

export function serializeRouteData(
routeData: RouteData,
Expand Down Expand Up @@ -40,3 +40,26 @@ export function deserializeRouteData(rawRouteData: SerializedRouteData): RouteDa
origin: rawRouteData.origin,
};
}

export function serializeRouteInfo(
routeInfo: RouteInfo,
trailingSlash: AstroConfig['trailingSlash'],
): SerializedRouteInfo {
return {
styles: routeInfo.styles,
file: routeInfo.file,
links: routeInfo.links,
scripts: routeInfo.scripts,
routeData: serializeRouteData(routeInfo.routeData, trailingSlash),
};
}

export function deserializeRouteInfo(rawRouteInfo: SerializedRouteInfo): RouteInfo {
return {
styles: rawRouteInfo.styles,
file: rawRouteInfo.file,
links: rawRouteInfo.links,
scripts: rawRouteInfo.scripts,
routeData: deserializeRouteData(rawRouteInfo.routeData),
};
}
2 changes: 0 additions & 2 deletions packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class AstroBuilder {
mode: this.mode,
command: 'build',
sync: false,
routesList: this.routesList,
},
);

Expand All @@ -155,7 +154,6 @@ class AstroBuilder {
settings: this.settings,
logger,
fs,
routesList: this.routesList,
command: 'build',
});

Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/core/build/plugins/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { normalizeTheLocale } from '../../../i18n/index.js';
import { runHookBuildSsr } from '../../../integrations/hooks.js';
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../../vite-plugin-scripts/index.js';
import { toFallbackType } from '../../app/common.js';
import { toRoutingStrategy } from '../../app/index.js';
import { serializeRouteData, toRoutingStrategy } from '../../app/index.js';
import type {
SerializedRouteInfo,
SerializedSSRManifest,
Expand All @@ -31,7 +31,6 @@ import {
import { encodeKey } from '../../encryption.js';
import { fileExtension, joinPaths, prependForwardSlash } from '../../path.js';
import { DEFAULT_COMPONENTS } from '../../routing/default.js';
import { serializeRouteData } from '../../routing/index.js';
import { addRollupInput } from '../add-rollup-input.js';
import { getOutFile, getOutFolder } from '../common.js';
import { type BuildInternals, cssOrder, mergeInlineCss } from '../internal.js';
Expand Down
11 changes: 5 additions & 6 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import astroVirtualManifestPlugin from '../manifest/virtual-module.js';
import astroPrefetch from '../prefetch/vite-plugin-prefetch.js';
import astroDevToolbar from '../toolbar/vite-plugin-dev-toolbar.js';
import astroTransitions from '../transitions/vite-plugin-transitions.js';
import type { AstroSettings, RoutesList } from '../types/astro.js';
import type { AstroSettings } from '../types/astro.js';
import astroVitePlugin from '../vite-plugin-astro/index.js';
import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.js';
import { vitePluginAstroServer } from '../vite-plugin-astro-server/index.js';
Expand All @@ -33,7 +33,7 @@ import htmlVitePlugin from '../vite-plugin-html/index.js';
import astroIntegrationsContainerPlugin from '../vite-plugin-integrations-container/index.js';
import astroLoadFallbackPlugin from '../vite-plugin-load-fallback/index.js';
import markdownVitePlugin from '../vite-plugin-markdown/index.js';
import astroScannerPlugin from '../vite-plugin-scanner/index.js';
import astroPluginRoutes from '../vite-plugin-routes/index.js';
import astroScriptsPlugin from '../vite-plugin-scripts/index.js';
import astroScriptsPageSSRPlugin from '../vite-plugin-scripts/page-ssr.js';
import { vitePluginSSRManifest } from '../vite-plugin-ssr-manifest/index.js';
Expand All @@ -50,7 +50,6 @@ type CreateViteOptions = {
mode: string;
fs?: typeof nodeFs;
sync: boolean;
routesList: RoutesList;
} & (
| {
command: 'dev';
Expand Down Expand Up @@ -87,7 +86,7 @@ const ONLY_DEV_EXTERNAL = [
/** Return a base vite config as a common starting point for all Vite commands. */
export async function createVite(
commandConfig: vite.InlineConfig,
{ settings, logger, mode, command, fs = nodeFs, sync, routesList }: CreateViteOptions,
{ settings, logger, mode, command, fs = nodeFs, sync }: CreateViteOptions,
): Promise<vite.InlineConfig> {
const astroPkgsConfig = await crawlFrameworkPkgs({
root: fileURLToPath(settings.config.root),
Expand Down Expand Up @@ -144,14 +143,15 @@ export async function createVite(
},
plugins: [
await serializedManifestPlugin({ settings }),
await astroPluginRoutes({ settings, logger, fsMod: fs }),
astroVirtualManifestPlugin(),
configAliasVitePlugin({ settings }),
astroLoadFallbackPlugin({ fs, root: settings.config.root }),
astroVitePlugin({ settings, logger }),
astroScriptsPlugin({ settings }),
// The server plugin is for dev only and having it run during the build causes
// the build to run very slow as the filewatcher is triggered often.
command === 'dev' && vitePluginAstroServer({ settings, logger, fs, routesList }), // manifest is only required in dev mode, where it gets created before a Vite instance is created, and get passed to this function
command === 'dev' && vitePluginAstroServer({ settings, logger, fs }), // manifest is only required in dev mode, where it gets created before a Vite instance is created, and get passed to this function
importMetaEnv({ envLoader }),
astroEnv({ settings, sync, envLoader }),
markdownVitePlugin({ settings, logger }),
Expand All @@ -160,7 +160,6 @@ export async function createVite(
astroIntegrationsContainerPlugin({ settings, logger }),
astroScriptsPageSSRPlugin({ settings }),
astroHeadPlugin(),
astroScannerPlugin({ settings, logger, routesList }),
astroContentVirtualModPlugin({ fs, settings }),
astroContentImportPlugin({ fs, settings, logger }),
astroContentAssetPropagationPlugin({ settings }),
Expand Down
4 changes: 0 additions & 4 deletions packages/astro/src/core/dev/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type { AstroInlineConfig } from '../../types/public/config.js';
import { createVite } from '../create-vite.js';
import type { Logger } from '../logger/core.js';
import { apply as applyPolyfill } from '../polyfill.js';
import { createRoutesList } from '../routing/index.js';
import { syncInternal } from '../sync/index.js';
import { warnMissingAdapter } from './adapter-validation.js';

Expand Down Expand Up @@ -80,7 +79,6 @@ export async function createContainer({
.filter(Boolean) as string[];

// Create the route manifest already outside of Vite so that `runHookConfigDone` can use it to inform integrations of the build output
const routesList = await createRoutesList({ settings, fsMod: fs }, logger, { dev: true });
await runHookConfigDone({ settings, logger, command: 'dev' });

warnMissingAdapter(logger, settings);
Expand All @@ -100,7 +98,6 @@ export async function createContainer({
command: 'dev',
fs,
sync: false,
routesList,
},
);
const viteServer = await vite.createServer(viteConfig);
Expand All @@ -114,7 +111,6 @@ export async function createContainer({
cleanup: true,
},
force: inlineConfig?.force,
routesList,
command: 'dev',
watcher: viteServer.watcher,
});
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/routing/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { createRoutesList } from './manifest/create.js';
export { serializeRouteData } from './manifest/serialization.js';
export { matchAllRoutes } from './match.js';
18 changes: 4 additions & 14 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { syncAstroEnv } from '../../env/sync.js';
import { telemetry } from '../../events/index.js';
import { eventCliSession } from '../../events/session.js';
import { runHookConfigDone, runHookConfigSetup } from '../../integrations/hooks.js';
import type { AstroSettings, RoutesList } from '../../types/astro.js';
import type { AstroSettings } from '../../types/astro.js';
import type { AstroInlineConfig } from '../../types/public/config.js';
import { getTimeStat } from '../build/util.js';
import { resolveConfig } from '../config/config.js';
Expand All @@ -30,7 +30,6 @@ import {
isAstroError,
} from '../errors/index.js';
import type { Logger } from '../logger/core.js';
import { createRoutesList } from '../routing/index.js';
import { ensureProcessNodeEnv } from '../util.js';
import { normalizePath } from '../viteUtils.js';

Expand All @@ -49,7 +48,6 @@ type SyncOptions = {
// Cleanup can be skipped in dev as some state can be reused on updates
cleanup?: boolean;
};
routesList: RoutesList;
command: 'build' | 'dev' | 'sync';
watcher?: FSWatcher;
};
Expand All @@ -70,7 +68,6 @@ export default async function sync(
settings,
logger,
});
const routesList = await createRoutesList({ settings, fsMod: fs }, logger);
await runHookConfigDone({ settings, logger });

return await syncInternal({
Expand All @@ -79,7 +76,6 @@ export default async function sync(
mode: 'production',
fs,
force: inlineConfig.force,
routesList,
command: 'sync',
});
}
Expand Down Expand Up @@ -119,7 +115,6 @@ export async function syncInternal({
settings,
skip,
force,
routesList,
command,
watcher,
}: SyncOptions): Promise<void> {
Expand All @@ -131,7 +126,7 @@ export async function syncInternal({
const timerStart = performance.now();

if (!skip?.content) {
await syncContentCollections(settings, { mode, fs, logger, routesList });
await syncContentCollections(settings, { mode, fs, logger });
settings.timer.start('Sync content layer');

let store: MutableDataStore | undefined;
Expand Down Expand Up @@ -228,12 +223,7 @@ function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
*/
async function syncContentCollections(
settings: AstroSettings,
{
mode,
logger,
fs,
routesList,
}: Required<Pick<SyncOptions, 'mode' | 'logger' | 'fs' | 'routesList'>>,
{ mode, logger, fs }: Required<Pick<SyncOptions, 'mode' | 'logger' | 'fs'>>,
): Promise<void> {
// Needed to load content config
const tempViteServer = await createServer(
Expand All @@ -244,7 +234,7 @@ async function syncContentCollections(
ssr: { external: [] },
logLevel: 'silent',
},
{ settings, logger, mode, command: 'build', fs, sync: true, routesList },
{ settings, logger, mode, command: 'build', fs, sync: true },
),
);

Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/vite-plugin-astro-server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class DevApp extends BaseApp<DevPipeline> {
this.manifestData = manifestData;
}

// TODO remove routelist once it's a plugin
static async create(
routesList: RoutesList,
settings: AstroSettings,
Expand Down
9 changes: 4 additions & 5 deletions packages/astro/src/vite-plugin-astro-server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { normalizePath } from 'vite';
import { toFallbackType } from '../core/app/common.js';
import { toRoutingStrategy } from '../core/app/index.js';
import type {
RouteInfo,
SerializedSSRManifest,
SSRManifest,
SSRManifestCSP,
Expand All @@ -33,7 +34,6 @@ import { patchOverlay } from '../core/errors/overlay.js';
import type { Logger } from '../core/logger/core.js';
import { NOOP_MIDDLEWARE_FN } from '../core/middleware/noop-middleware.js';
import { createViteLoader } from '../core/module-loader/index.js';
import { createRoutesList } from '../core/routing/index.js';
import { getRoutePrerenderOption } from '../core/routing/manifest/prerender.js';
import { runHookRoutesResolved } from '../integrations/hooks.js';
import type { AstroSettings, RoutesList } from '../types/astro.js';
Expand All @@ -48,19 +48,20 @@ interface AstroPluginOptions {
settings: AstroSettings;
logger: Logger;
fs: typeof fs;
routesList: RoutesList;
}

export default function createVitePluginAstroServer({
settings,
logger,
fs: fsMod,
routesList,
}: AstroPluginOptions): vite.Plugin {
return {
name: 'astro:server',
async configureServer(viteServer) {
const loader = createViteLoader(viteServer);
const { routes } = await loader.import('astro:routes');
const routesList: RoutesList = { routes: routes.map((r: RouteInfo) => r.routeData) };

const app = await DevApp.create(routesList, settings, logger, loader);

const controller = createController({ loader });
Expand Down Expand Up @@ -88,8 +89,6 @@ export default function createVitePluginAstroServer({
await getRoutePrerenderOption(content, route, settings, logger);
await runHookRoutesResolved({ routes: routesList.routes, settings, logger });
} catch (_) {}
} else {
routesList = await createRoutesList({ settings, fsMod }, logger, { dev: true });
}

warnMissingAdapter(logger, settings);
Expand Down
Loading
Loading