Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1befb90
feat: plugin hook filters
florian-lefebvre Dec 10, 2025
c383f54
wip
florian-lefebvre Dec 10, 2025
3feb29f
wip
florian-lefebvre Dec 10, 2025
5a5acbb
wip
florian-lefebvre Dec 10, 2025
c37813a
wip
florian-lefebvre Dec 10, 2025
3901a73
wip
florian-lefebvre Dec 10, 2025
fb6e01d
wip
florian-lefebvre Dec 10, 2025
e87df8d
wip
florian-lefebvre Dec 10, 2025
93c8cb2
wip
florian-lefebvre Dec 10, 2025
a3da79c
wip
florian-lefebvre Dec 10, 2025
e95e37e
wip
florian-lefebvre Dec 10, 2025
8f72ee4
wip
florian-lefebvre Dec 10, 2025
db456d0
wip
florian-lefebvre Dec 10, 2025
c76daa3
todos
florian-lefebvre Dec 10, 2025
e5a0b19
Merge branch 'next' into feat/plugin-hook-filters
florian-lefebvre Dec 10, 2025
bf3a9ed
fix
florian-lefebvre Dec 10, 2025
8750f02
fix: vite plugin config alias
florian-lefebvre Dec 10, 2025
8b23c66
feat: load
florian-lefebvre Dec 10, 2025
ecbb025
fix: misc
florian-lefebvre Dec 10, 2025
46e78fc
Merge branch 'next' into feat/plugin-hook-filters
florian-lefebvre Dec 10, 2025
e95d8e0
fix: regex
florian-lefebvre Dec 10, 2025
a358b76
fix: regex
florian-lefebvre Dec 10, 2025
da1cacd
fix: regex
florian-lefebvre Dec 10, 2025
6e5f017
fix: regex
florian-lefebvre Dec 11, 2025
4fa4903
Merge branch 'next' into feat/plugin-hook-filters
florian-lefebvre Dec 11, 2025
477d1ab
fix: regex
florian-lefebvre Dec 11, 2025
863606e
Merge branch 'next' into feat/plugin-hook-filters
florian-lefebvre Dec 11, 2025
5870997
fix: regex
florian-lefebvre Dec 11, 2025
3dc7098
improve regex
florian-lefebvre Dec 11, 2025
71a0b26
fix: unsufficient regex
florian-lefebvre Dec 11, 2025
fa7a8db
Merge branch 'next' into feat/plugin-hook-filters
florian-lefebvre Dec 11, 2025
e362a45
chore: format
florian-lefebvre Dec 12, 2025
d0cae56
Merge branch 'next' into feat/plugin-hook-filters
florian-lefebvre Dec 12, 2025
69bcb45
chore: format
florian-lefebvre Dec 12, 2025
dacba07
wip
florian-lefebvre Dec 12, 2025
547f756
Merge branch 'next' into feat/plugin-hook-filters
florian-lefebvre Dec 15, 2025
4c44b63
feat: plugin hook filters (part 2) (#15000)
florian-lefebvre Dec 15, 2025
4c5f2f3
Merge branch 'next' into feat/plugin-hook-filters
florian-lefebvre Dec 15, 2025
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
Prev Previous commit
Next Next commit
chore: format
  • Loading branch information
florian-lefebvre committed Dec 12, 2025
commit e362a45f93347c8b1a2030bfc359debbd3fdc912
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ When creating new tests, it's best to reference other existing test files and re
> [!IMPORTANT]
> If tests start to fail for no apparent reason, the first thing to look at the `outDir` configuration. As build cache artifacts between runs, different tests might end up sharing some of the emitted modules.
> To avoid this possible overlap, **make sure to add a custom `outDir` to your test case**
>
>
> ```js
> await loadFixture({
> root: "./fixtures/some-fixture",
> outDir: "./dist/some-folder"
> })
> root: './fixtures/some-fixture',
> outDir: './dist/some-folder',
> });
> ```

### Other useful commands
Expand Down
6 changes: 4 additions & 2 deletions packages/astro/e2e/cloudflare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ function sharedTests(testRunner, infoLogs = null) {
// Dev-specific tests
if (infoLogs) {
testRunner('dev server logs', () => {
const serverStartLog = infoLogs.find(log => log.message && log.message.includes('Local'));
const serverStartLog = infoLogs.find((log) => log.message && log.message.includes('Local'));
expect(serverStartLog).toBeDefined();
});

testRunner('all dependencies pre-optimized, none discovered', () => {
// Verify that all of Astro's dependencies are pre-optimized in the Vite cache
// and that no new dependencies are discovered and optimized during dev server startup
const optimizedLog = infoLogs.find(log => log.message && log.message.includes('new dependencies optimized'));
const optimizedLog = infoLogs.find(
(log) => log.message && log.message.includes('new dependencies optimized'),
);
expect(optimizedLog).toBeUndefined();
});
}
Expand Down
6 changes: 4 additions & 2 deletions packages/astro/src/assets/fonts/vite-plugin-fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ export function fontsPlugin({ settings, sync, logger }: Options): Plugin {
await initialize({
// In dev, we cache fonts data in .astro so it can be easily inspected and cleared
cacheDir: new URL(CACHE_DIR, settings.dotAstroDir),
modResolver: new DevServerRemoteFontProviderModResolver({ environment: server.environments[
modResolver: new DevServerRemoteFontProviderModResolver({
environment: server.environments[
ASTRO_VITE_ENVIRONMENT_NAMES.astro
] as RunnableDevEnvironment }),
] as RunnableDevEnvironment,
}),
cssRenderer: new MinifiableCssRenderer({ minify: false }),
urlResolver: new DevUrlResolver({
base: baseUrl,
Expand Down
9 changes: 6 additions & 3 deletions packages/astro/src/core/app/dev/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ export class DevPipeline extends Pipeline {

const importer = devCSSMap.get(routeData.component);
let css = new Set<ImportedDevStyle>();
if(importer) {
if (importer) {
const cssModule = await importer();
css = cssModule.css;
css = cssModule.css;
} else {
this.logger.warn('assets', `Unable to find CSS for ${routeData.component}. This is likely a bug in Astro.`);
this.logger.warn(
'assets',
`Unable to find CSS for ${routeData.component}. This is likely a bug in Astro.`,
);
}

// Pass framework CSS in as style tags to be appended to the page.
Expand Down
5 changes: 3 additions & 2 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ export { BaseApp, type RenderErrorOptions, type RenderOptions } from './base.js'
export { fromRoutingStrategy, toRoutingStrategy } from './common.js';
export { createConsoleLogger } from './logging.js';
export {
deserializeManifest, deserializeRouteData,
deserializeManifest,
deserializeRouteData,
deserializeRouteInfo,
serializeRouteData,
serializeRouteInfo
serializeRouteInfo,
} from './manifest.js';
export { AppPipeline } from './pipeline.js';
9 changes: 7 additions & 2 deletions packages/astro/src/core/app/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import type { AstroConfig, RouteData } from '../../types/public/index.js';
import type { RoutesList } from '../../types/astro.js';
import { decodeKey } from '../encryption.js';
import { NOOP_MIDDLEWARE_FN } from '../middleware/noop-middleware.js';
import type { RouteInfo, SerializedSSRManifest, SSRManifest, SerializedRouteInfo } from './types.js';

import type {
RouteInfo,
SerializedSSRManifest,
SSRManifest,
SerializedRouteInfo,
} from './types.js';

export function deserializeManifest(
serializedManifest: SerializedSSRManifest,
routesList?: RoutesList,
Expand Down
4 changes: 1 addition & 3 deletions packages/astro/src/core/app/validate-forwarded-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export function validateForwardedHeaders(
// Validate protocol
if (forwardedProtocol) {
if (allowedDomains && allowedDomains.length > 0) {
const hasProtocolPatterns = allowedDomains.some(
(pattern) => pattern.protocol !== undefined,
);
const hasProtocolPatterns = allowedDomains.some((pattern) => pattern.protocol !== undefined);
if (hasProtocolPatterns) {
// Validate against allowedDomains patterns
try {
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/build/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export class BuildApp extends BaseApp<BuildPipeline> {

async renderError(request: Request, options: RenderErrorOptions): Promise<Response> {
if (options.status === 500) {
if(options.response) {
return options.response;
if (options.response) {
return options.response;
}
throw options.error;
} else {
return super.renderError(request, {
...options,
prerenderedErrorPageFetch: undefined
prerenderedErrorPageFetch: undefined,
});
}
}
Expand Down
8 changes: 3 additions & 5 deletions packages/astro/src/core/build/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { ComponentInstance } from '../../types/astro.js';
import type { RewritePayload } from '../../types/public/common.js';
import type { RouteData, SSRElement, SSRResult } from '../../types/public/internal.js';
import {
VIRTUAL_PAGE_RESOLVED_MODULE_ID,
} from '../../vite-plugin-pages/const.js';
import { VIRTUAL_PAGE_RESOLVED_MODULE_ID } from '../../vite-plugin-pages/const.js';
import { getVirtualModulePageName } from '../../vite-plugin-pages/util.js';
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
import { createConsoleLogger } from '../app/index.js';
Expand Down Expand Up @@ -153,7 +151,7 @@ export class BuildPipeline extends Pipeline {
const pages = new Set<RouteData>();

// Keep a list of the default routes names for faster lookup
const defaultRouteComponents = new Set(this.defaultRoutes.map(route => route.component));
const defaultRouteComponents = new Set(this.defaultRoutes.map((route) => route.component));

for (const { routeData } of this.manifest.routes) {
if (routeIsRedirect(routeData)) {
Expand All @@ -168,7 +166,7 @@ export class BuildPipeline extends Pipeline {
}

// Default routes like the server islands route, should not be generated
if(defaultRouteComponents.has(routeData.component)) {
if (defaultRouteComponents.has(routeData.component)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async function buildManifest(
const assetQueryParams = settings.adapter?.client?.assetQueryParams;
const assetQueryString = assetQueryParams ? assetQueryParams.toString() : undefined;

const appendAssetQuery = (pth: string) => assetQueryString ? `${pth}?${assetQueryString}` : pth;
const appendAssetQuery = (pth: string) => (assetQueryString ? `${pth}?${assetQueryString}` : pth);

const prefixAssetPath = (pth: string) => {
let result = '';
Expand Down
5 changes: 1 addition & 4 deletions packages/astro/src/core/build/plugins/plugin-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import type { BuildInternals } from '../internal.js';
import type { StaticBuildOptions } from '../types.js';
import { ASTRO_VITE_ENVIRONMENT_NAMES } from '../../constants.js';

export function pluginMiddleware(
opts: StaticBuildOptions,
internals: BuildInternals,
): VitePlugin {
export function pluginMiddleware(opts: StaticBuildOptions, internals: BuildInternals): VitePlugin {
const plugin = vitePluginMiddlewareBuild(opts, internals);
return {
...plugin,
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/build/plugins/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function makePageDataKey(route: string, componentPath: string): string {
return route + ASTRO_PAGE_KEY_SEPARATOR + componentPath;
}


export function shouldInlineAsset(
assetContent: string,
assetPath: string,
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ async function buildEnvironments(opts: StaticBuildOptions, internals: BuildInter

// Build ssr environment for server output
const ssrOutput =
settings.buildOutput === 'static' ? [] : await builder.build(builder.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]);
settings.buildOutput === 'static'
? []
: await builder.build(builder.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]);

// Build prerender environment for static generation
const prerenderOutput = await builder.build(builder.environments.prerender);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/dev/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function createContainer({
{
dev: true,
// If the adapter explicitly set a buildOutput, don't override it
skipBuildOutputAssignment: !!settings.adapter?.adapterFeatures?.buildOutput
skipBuildOutputAssignment: !!settings.adapter?.adapterFeatures?.buildOutput,
},
);
const viteConfig = await createVite(
Expand Down
13 changes: 10 additions & 3 deletions packages/astro/src/core/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
import { AstroIntegrationLogger } from '../../core/logger/core.js';
import { telemetry } from '../../events/index.js';
import { eventCliSession } from '../../events/session.js';
import { normalizeCodegenDir, runHookConfigDone, runHookConfigSetup } from '../../integrations/hooks.js';
import {
normalizeCodegenDir,
runHookConfigDone,
runHookConfigSetup,
} from '../../integrations/hooks.js';
import type { AstroInlineConfig } from '../../types/public/config.js';
import type { PreviewModule, PreviewServer } from '../../types/public/preview.js';
import { resolveConfig } from '../config/config.js';
Expand Down Expand Up @@ -87,11 +91,14 @@ export default async function preview(inlineConfig: AstroInlineConfig): Promise<
logger: new AstroIntegrationLogger(logger.options, settings.adapter.name),
headers: settings.config.server.headers,
createCodegenDir: () => {
const codegenDir = new URL(normalizeCodegenDir(settings.adapter ? settings.adapter.name : "_temp"), settings.dotAstroDir);
const codegenDir = new URL(
normalizeCodegenDir(settings.adapter ? settings.adapter.name : '_temp'),
settings.dotAstroDir,
);
fs.mkdirSync(codegenDir, { recursive: true });
return codegenDir;
},
root: settings.config.root
root: settings.config.root,
});

return server;
Expand Down
12 changes: 10 additions & 2 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ async function syncContentCollections(
ssr: { external: [] },
logLevel: 'silent',
},
{ routesList, settings: {
{
routesList,
settings: {
...settings,
// Prevent mutation by vite plugins during sync
buildOutput: undefined,
Expand All @@ -248,7 +250,13 @@ async function syncContentCollections(
fontResources: new Set(),
styleHashes: [],
},
}, logger, mode, command: 'build', fs, sync: true },
},
logger,
mode,
command: 'build',
fs,
sync: true,
},
),
);

Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/vite-plugin-astro-server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export default function createVitePluginAstroServer({
if (!isRunnableDevEnvironment(viteServer.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr])) {
return;
}
const environment = viteServer.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr] as RunnableDevEnvironment;
const environment = viteServer.environments[
ASTRO_VITE_ENVIRONMENT_NAMES.ssr
] as RunnableDevEnvironment;
const loader = createViteLoader(viteServer, environment);
const { default: createAstroServerApp } = await environment.runner.import(ASTRO_DEV_APP_ID);
const controller = createController({ loader });
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-config-alias/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default function configAliasVitePlugin({
resolveId: {
filter: {
id: {
include: configAlias.map(alias => alias.find),
include: configAlias.map((alias) => alias.find),
exclude: /(?:\0|^virtual:|^astro:)/,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function vitePluginEnvironment({
const finalEnvironmentOptions: EnvironmentOptions = {
optimizeDeps: {
include: [],
exclude: []
exclude: [],
},
resolve: {
// Astro imports in third-party packages should use the same version as root
Expand Down
4 changes: 1 addition & 3 deletions packages/astro/src/vite-plugin-pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export {
pluginPage,
} from './page.js';
export { pluginPage } from './page.js';
export { pluginPages, VIRTUAL_PAGES_MODULE_ID } from './pages.js';
5 changes: 1 addition & 4 deletions packages/astro/src/vite-plugin-pages/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export function getVirtualModulePageName(virtualModulePrefix: string, path: stri
}

export function getVirtualModulePageNameForComponent(component: string) {
const virtualModuleName = getVirtualModulePageName(
VIRTUAL_PAGE_MODULE_ID,
component,
);
const virtualModuleName = getVirtualModulePageName(VIRTUAL_PAGE_MODULE_ID, component);
return virtualModuleName;
}
24 changes: 14 additions & 10 deletions packages/astro/test/astro-component-bundling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ describe('Component bundling', () => {
await fixture.build();
});

it('should treeshake FooComponent', {skip: "Not sure how this can possibly work, we bundle the module as an entrypoint."}, async () => {
const astroChunkDir = await fixture.readdir('/_astro');
const manyComponentsChunkName = astroChunkDir.find((chunk) =>
chunk.startsWith('ManyComponents'),
);
const manyComponentsChunkContent = await fixture.readFile(
`/_astro/${manyComponentsChunkName}`,
);
assert.equal(manyComponentsChunkContent.includes('FooComponent'), false);
});
it(
'should treeshake FooComponent',
{ skip: 'Not sure how this can possibly work, we bundle the module as an entrypoint.' },
async () => {
const astroChunkDir = await fixture.readdir('/_astro');
const manyComponentsChunkName = astroChunkDir.find((chunk) =>
chunk.startsWith('ManyComponents'),
);
const manyComponentsChunkContent = await fixture.readFile(
`/_astro/${manyComponentsChunkName}`,
);
assert.equal(manyComponentsChunkContent.includes('FooComponent'), false);
},
);

it('should not include Astro components in client bundles', async () => {
const html = await fixture.readFile('/astro-in-client/index.html');
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/test/astro-css-bundling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ describe('CSS Bundling', function () {
rollupOptions: {
output: {
assetFileNames: 'assets/[name][extname]',
}
}
}
}
}
},
},
},
},
},
},
});
await fixture.build({ mode: 'production' });
Expand Down
7 changes: 5 additions & 2 deletions packages/astro/test/astro-public.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ describe('Public', () => {

it('should not produce empty chunk warning when building with no client JS', () => {
// Check for empty chunk warnings in the build logs
const emptyChunkWarning = buildLogs.find((log) =>
log.message && (log.message.includes('empty chunk') || (log.message.includes('empty') && log.message.includes('chunk')))
const emptyChunkWarning = buildLogs.find(
(log) =>
log.message &&
(log.message.includes('empty chunk') ||
(log.message.includes('empty') && log.message.includes('chunk'))),
);

if (emptyChunkWarning) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('astro:assets - Support unconventional build settings properly', () =>
fixture = await loadFixture({
...defaultSettings,
build: {
assets: 'images'
assets: 'images',
},
vite: {
environments: {
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('astro:assets - Support unconventional build settings properly', () =>
fixture = await loadFixture({
...defaultSettings,
build: {
assets: 'assets'
assets: 'assets',
},
vite: {
environments: {
Expand Down
Loading