Skip to content
Merged
28 changes: 28 additions & 0 deletions .changeset/beige-clowns-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'@astrojs/vercel': major
'astro': major
---

Removes `entryPoints` on `astro:build:ssr` hook (Integration API)

In Astro 5.0, `functionPerRoute` was deprecated. That meant that `entryPoints` on the `astro:build:ssr` hook was always empty.

Astro 6.0 removes the `entryPoints` map passed to this hook entirely.

#### What should I do?

Remove any instance of `entryPoints` passed to `astro:build:ssr`:

```diff
// my-integration.mjs
const integration = () => {
return {
name: 'my-integration',
hooks: {
'astro:build:ssr': (params) => {
- someLogic(params.entryPoints)
},
}
}
}
```
41 changes: 41 additions & 0 deletions .changeset/cuddly-worlds-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
'@astrojs/sitemap': major
'astro': major
---

Removes `routes` on `astro:build:done` hook (Integration API)

In Astro 5.0, accessing `routes` on the `astro:build:done` hook was deprecated.

Astro 6.0 removes the `routes` array passed to this hook entirely. Instead, the `astro:routes:resolved` hook should be used.

#### What should I do?

Remove any instance of `routes` passed to `astro:build:done` and replace it with the new `astro:routes:resolved` hook. Access `distURL` on the newly exposed `assets` map:

```diff
// my-integration.mjs
const integration = () => {
+ let routes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unaligned with the rest

Suggested change
+ let routes
+ let routes

return {
name: 'my-integration',
hooks: {
+ 'astro:routes:resolved': (params) => {
+ routes = params.routes
+ },
'astro:build:done': ({
- routes
+ assets
}) => {
+ for (const route of routes) {
+ const distURL = assets.get(route.pattern)
+ if (distURL) {
+ Object.assign(route, { distURL })
+ }
+ }
console.log(routes)
}
}
}
}
```
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ jobs:
with:
repository: withastro/docs
path: smoke/docs
# For a commit event on the `next` branch (`ref_name`), use the `5.0.0-beta` branch.
# For a pull_request event merging into the `next` branch (`base_ref`), use the `5.0.0-beta` branch.
# For a commit event on the `next` branch (`ref_name`), use the `v6` branch.
# For a pull_request event merging into the `next` branch (`base_ref`), use the `v6` branch.
# NOTE: For a pull_request event, the `ref_name` is something like `<pr-number>/merge` than the branch name.
# NOTE: Perhaps docs repo should use a consistent `next` branch in the future.
ref: ${{ (github.ref_name == 'next' || github.base_ref == 'next') && '5.0.0-beta' || 'main' }}
ref: ${{ (github.ref_name == 'next' || github.base_ref == 'next') && 'v6' || 'main' }}

- name: Install dependencies
run: pnpm install --no-frozen-lockfile
Expand Down
4 changes: 1 addition & 3 deletions packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { AstroError, AstroErrorData } from '../errors/index.js';
import type { Logger } from '../logger/core.js';
import { levels, timerMessage } from '../logger/core.js';
import { createRoutesList } from '../routing/index.js';
import { getServerIslandRouteData } from '../server-islands/endpoint.js';
import { clearContentLayerCache } from '../sync/index.js';
import { ensureProcessNodeEnv } from '../util.js';
import { collectPagesData } from './page-data.js';
Expand Down Expand Up @@ -242,8 +241,7 @@ class AstroBuilder {
pages: pageNames,
routes: Object.values(allPages)
.flat()
.map((pageData) => pageData.route)
.concat(hasServerIslands ? getServerIslandRouteData(this.settings.config) : []),
.map((pageData) => pageData.route),
logger: this.logger,
});

Expand Down
4 changes: 1 addition & 3 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Rollup } from 'vite';
import type { RouteData, SSRResult } from '../../types/public/internal.js';
import type { SSRResult } from '../../types/public/internal.js';
import { prependForwardSlash, removeFileExtension } from '../path.js';
import { viteID } from '../util.js';
import { makePageDataKey } from './plugins/util.js';
Expand Down Expand Up @@ -89,7 +89,6 @@ export interface BuildInternals {
// The SSR manifest entry chunk.
manifestEntryChunk?: Rollup.OutputChunk;
manifestFileName?: string;
entryPoints: Map<RouteData, URL>;
componentMetadata: SSRResult['componentMetadata'];
middlewareEntryPoint: URL | undefined;
astroActionsEntryPoint: URL | undefined;
Expand Down Expand Up @@ -121,7 +120,6 @@ export function createBuildInternals(): BuildInternals {
discoveredScripts: new Set(),
staticFiles: new Set(),
componentMetadata: new Map(),
entryPoints: new Map(),
prerenderOnlyChunks: [],
astroActionsEntryPoint: undefined,
middlewareEntryPoint: undefined,
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/build/plugins/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export function pluginManifest(
config: options.settings.config,
manifest,
logger: options.logger,
entryPoints: internals.entryPoints,
middlewareEntryPoint: shouldPassMiddlewareEntryPoint
? internals.middlewareEntryPoint
: undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/server-islands/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const SERVER_ISLAND_BASE_PREFIX = '_server-islands';

type ConfigFields = Pick<SSRManifest, 'base' | 'trailingSlash'>;

export function getServerIslandRouteData(config: ConfigFields) {
function getServerIslandRouteData(config: ConfigFields) {
const segments = [
[{ content: '_server-islands', dynamic: false, spread: false }],
[{ content: 'name', dynamic: true, spread: false }],
Expand Down
28 changes: 0 additions & 28 deletions packages/astro/src/integrations/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import type {
BaseIntegrationHooks,
HookParameters,
IntegrationResolvedRoute,
IntegrationRouteData,
RouteOptions,
RouteToHeaders,
} from '../types/public/integrations.js';
Expand Down Expand Up @@ -548,29 +547,22 @@ type RunHookBuildSsr = {
config: AstroConfig;
manifest: SerializedSSRManifest;
logger: Logger;
entryPoints: Map<RouteData, URL>;
middlewareEntryPoint: URL | undefined;
};

export async function runHookBuildSsr({
config,
manifest,
logger,
entryPoints,
middlewareEntryPoint,
}: RunHookBuildSsr) {
const entryPointsMap = new Map();
for (const [key, value] of entryPoints) {
entryPointsMap.set(toIntegrationRouteData(key), value);
}
for (const integration of config.integrations) {
await runHookInternal({
integration,
hookName: 'astro:build:ssr',
logger,
params: () => ({
manifest,
entryPoints: entryPointsMap,
middlewareEntryPoint,
}),
});
Expand Down Expand Up @@ -602,15 +594,13 @@ export async function runHookBuildGenerated({
type RunHookBuildDone = {
settings: AstroSettings;
pages: string[];
// TODO: remove in Astro 6
routes: RouteData[];
logger: Logger;
};

export async function runHookBuildDone({ settings, pages, routes, logger }: RunHookBuildDone) {
const dir = getClientOutputDirectory(settings);
await fsMod.promises.mkdir(dir, { recursive: true });
const integrationRoutes = routes.map(toIntegrationRouteData);

for (const integration of settings.config.integrations) {
await runHookInternal({
Expand All @@ -620,7 +610,6 @@ export async function runHookBuildDone({ settings, pages, routes, logger }: RunH
params: () => ({
pages: pages.map((p) => ({ pathname: p })),
dir,
routes: integrationRoutes,
assets: new Map(
routes.filter((r) => r.distURL !== undefined).map((r) => [r.route, r.distURL!]),
),
Expand Down Expand Up @@ -701,20 +690,3 @@ export function toIntegrationResolvedRoute(route: RouteData): IntegrationResolve
: undefined,
};
}

function toIntegrationRouteData(route: RouteData): IntegrationRouteData {
return {
route: route.route,
component: route.component,
generate: route.generate,
params: route.params,
pathname: route.pathname,
segments: route.segments,
prerender: route.prerender,
redirect: route.redirect,
redirectRoute: route.redirectRoute ? toIntegrationRouteData(route.redirectRoute) : undefined,
type: route.type,
pattern: route.pattern,
distURL: route.distURL,
};
}
22 changes: 0 additions & 22 deletions packages/astro/src/types/public/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ export interface BaseIntegrationHooks {
'astro:server:done': (options: { logger: AstroIntegrationLogger }) => void | Promise<void>;
'astro:build:ssr': (options: {
manifest: SerializedSSRManifest;
/**
* This maps a {@link RouteData} to an {@link URL}, this URL represents
* the physical file you should import.
*/
// TODO: Change in Astro 6.0
entryPoints: Map<IntegrationRouteData, URL>;
/**
* File path of the emitted middleware
*/
Expand All @@ -239,8 +233,6 @@ export interface BaseIntegrationHooks {
'astro:build:done': (options: {
pages: { pathname: string }[];
dir: URL;
/** @deprecated Use the `assets` map and the new `astro:routes:resolved` hook */
routes: IntegrationRouteData[];
assets: Map<string, URL[]>;
logger: AstroIntegrationLogger;
}) => void | Promise<void>;
Expand All @@ -263,20 +255,6 @@ export interface AstroIntegration {
} & Partial<Record<string, unknown>>;
}

/**
* A smaller version of the {@link RouteData} that is used in the integrations.
* @deprecated Use {@link IntegrationResolvedRoute}
*/
export type IntegrationRouteData = Omit<
RouteData,
'isIndex' | 'fallbackRoutes' | 'redirectRoute' | 'origin'
> & {
/**
* {@link RouteData.redirectRoute}
*/
redirectRoute?: IntegrationRouteData;
};

export type RouteToHeaders = Map<string, HeaderPayload>;

export type HeaderPayload = {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ describe('Middleware API in PROD mode, SSR', () => {
edgeMiddleware: true,
},
},
setMiddlewareEntryPoint(entryPointsOrMiddleware) {
middlewarePath = entryPointsOrMiddleware;
setMiddlewareEntryPoint(middlewareEntryPoint) {
middlewarePath = middlewareEntryPoint;
},
}),
});
Expand Down
20 changes: 10 additions & 10 deletions packages/astro/test/static-build-page-dist-url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';

describe('Static build: pages routes have distURL', () => {
/** @type {RouteData[]} */
let checkRoutes;
/** @type {Map<string, URL[]>} */
let assets;
before(async () => {
/** @type {import('./test-utils').Fixture} */
const fixture = await loadFixture({
Expand All @@ -13,8 +13,8 @@ describe('Static build: pages routes have distURL', () => {
{
name: '@astrojs/distURL',
hooks: {
'astro:build:done': ({ routes }) => {
checkRoutes = routes.filter((p) => p.type === 'page');
'astro:build:done': (params) => {
assets = params.assets;
},
},
},
Expand All @@ -23,11 +23,11 @@ describe('Static build: pages routes have distURL', () => {
await fixture.build();
});
it('Pages routes have distURL', async () => {
assert.equal(checkRoutes.length > 0, true, 'Pages not found: build end hook not being called');
checkRoutes.forEach((p) => {
p.distURL.forEach((distURL) => {
assert.equal(distURL instanceof URL, true, `${p.pathname} doesn't include distURL`);
});
});
assert.equal(assets.size > 0, true, 'Pages not found: build end hook not being called');
for (const [p, distURL] of assets.entries()) {
for (const url of distURL) {
assert.equal(url instanceof URL, true, `${p.pathname} doesn't include distURL`);
}
}
});
});
15 changes: 1 addition & 14 deletions packages/astro/test/test-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { viteID } from '../dist/core/util.js';
/**
* @typedef {import('../src/types/public/integrations.js').AstroAdapter} AstroAdapter
* @typedef {import('../src/types/public/integrations.js').AstroIntegration} AstroIntegration
* @typedef {import('../src/types/public/integrations.js').HookParameters<"astro:build:ssr">['entryPoints']} EntryPoints
* @typedef {import('../src/types/public/integrations.js').HookParameters<"astro:build:ssr">['middlewareEntryPoint']} MiddlewareEntryPoint
* @typedef {import('../src/types/public/integrations.js').HookParameters<"astro:build:done">['routes']} Routes
*/
Expand All @@ -13,9 +12,7 @@ import { viteID } from '../dist/core/util.js';
* @param {{
* provideAddress?: boolean;
* extendAdapter?: AstroAdapter;
* setEntryPoints?: (entryPoints: EntryPoints) => void;
* setMiddlewareEntryPoint?: (middlewareEntryPoint: MiddlewareEntryPoint) => void;
* setRoutes?: (routes: Routes) => void;
* env: Record<string, string | undefined>;
* }} param0
* @returns {AstroIntegration}
Expand All @@ -24,9 +21,7 @@ export default function ({
provideAddress = true,
staticHeaders = false,
extendAdapter,
setEntryPoints,
setMiddlewareEntryPoint,
setRoutes,
setManifest,
setRouteToHeaders,
env,
Expand Down Expand Up @@ -126,22 +121,14 @@ export default function ({
...extendAdapter,
});
},
'astro:build:ssr': ({ entryPoints, middlewareEntryPoint, manifest }) => {
if (setEntryPoints) {
setEntryPoints(entryPoints);
}
'astro:build:ssr': ({ middlewareEntryPoint, manifest }) => {
if (setMiddlewareEntryPoint) {
setMiddlewareEntryPoint(middlewareEntryPoint);
}
if (setManifest) {
setManifest(manifest);
}
},
'astro:build:done': ({ routes }) => {
if (setRoutes) {
setRoutes(routes);
}
},
'astro:build:generated': ({ experimentalRouteToHeaders }) => {
if (setRouteToHeaders) {
setRouteToHeaders(experimentalRouteToHeaders);
Expand Down
Loading
Loading