Skip to content

Commit ece667a

Browse files
feat: cleanup integration api (#14446)
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
1 parent ecb0b98 commit ece667a

14 files changed

Lines changed: 147 additions & 179 deletions

File tree

.changeset/beige-clowns-read.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'astro': major
3+
---
4+
5+
Removes `entryPoints` on `astro:build:ssr` hook (Integration API)
6+
7+
In Astro 5.0, `functionPerRoute` was deprecated. That meant that `entryPoints` on the `astro:build:ssr` hook was always empty. Astro integrations may have continued to work, even while `entryPoints` was not providing any useful data.
8+
9+
Astro 6.0 removes the `entryPoints` map passed to this hook entirely. Integrations may no longer include `entryPoints`.
10+
11+
#### What should I do?
12+
13+
Remove any instance of `entryPoints` passed to `astro:build:ssr`. This should be safe to remove because this logic was not providing any useful data, but you may need to restructure your code accordingly for its removal:
14+
15+
```diff
16+
// my-integration.mjs
17+
const integration = () => {
18+
return {
19+
name: 'my-integration',
20+
hooks: {
21+
'astro:build:ssr': (params) => {
22+
- someLogic(params.entryPoints)
23+
},
24+
}
25+
}
26+
}
27+
```

.changeset/cuddly-worlds-beam.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
'astro': major
3+
---
4+
5+
Removes `routes` on `astro:build:done` hook (Integration API)
6+
7+
In Astro 5.0, accessing `routes` on the `astro:build:done` hook was deprecated in favour of a new `astro:routes:resolved` hook. However, Astro integrations may have continued to function using the `routes` array.
8+
9+
Astro 6.0 removes the `routes` array passed to this hook entirely. Instead, the `astro:routes:resolved` hook must be used.
10+
11+
#### What should I do?
12+
13+
Remove any instance of `routes` passed to `astro:build:done` in your Astro integration and replace it with the new `astro:routes:resolved` hook. You can access `distURL` on the newly exposed `assets` map:
14+
15+
```diff
16+
// my-integration.mjs
17+
const integration = () => {
18+
+ let routes
19+
return {
20+
name: 'my-integration',
21+
hooks: {
22+
+ 'astro:routes:resolved': (params) => {
23+
+ routes = params.routes
24+
+ },
25+
'astro:build:done': ({
26+
- routes
27+
+ assets
28+
}) => {
29+
+ for (const route of routes) {
30+
+ const distURL = assets.get(route.pattern)
31+
+ if (distURL) {
32+
+ Object.assign(route, { distURL })
33+
+ }
34+
+ }
35+
console.log(routes)
36+
}
37+
}
38+
}
39+
}
40+
```

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ jobs:
219219
with:
220220
repository: withastro/docs
221221
path: smoke/docs
222-
# For a commit event on the `next` branch (`ref_name`), use the `5.0.0-beta` branch.
223-
# For a pull_request event merging into the `next` branch (`base_ref`), use the `5.0.0-beta` branch.
222+
# For a commit event on the `next` branch (`ref_name`), use the `v6` branch.
223+
# For a pull_request event merging into the `next` branch (`base_ref`), use the `v6` branch.
224224
# NOTE: For a pull_request event, the `ref_name` is something like `<pr-number>/merge` than the branch name.
225225
# NOTE: Perhaps docs repo should use a consistent `next` branch in the future.
226-
ref: ${{ (github.ref_name == 'next' || github.base_ref == 'next') && '5.0.0-beta' || 'main' }}
226+
ref: ${{ (github.ref_name == 'next' || github.base_ref == 'next') && 'v6' || 'main' }}
227227

228228
- name: Install dependencies
229229
run: pnpm install --no-frozen-lockfile

packages/astro/src/core/build/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { AstroError, AstroErrorData } from '../errors/index.js';
2323
import type { Logger } from '../logger/core.js';
2424
import { levels, timerMessage } from '../logger/core.js';
2525
import { createRoutesList } from '../routing/index.js';
26-
import { getServerIslandRouteData } from '../server-islands/endpoint.js';
2726
import { clearContentLayerCache } from '../sync/index.js';
2827
import { ensureProcessNodeEnv } from '../util.js';
2928
import { collectPagesData } from './page-data.js';
@@ -242,8 +241,7 @@ class AstroBuilder {
242241
pages: pageNames,
243242
routes: Object.values(allPages)
244243
.flat()
245-
.map((pageData) => pageData.route)
246-
.concat(hasServerIslands ? getServerIslandRouteData(this.settings.config) : []),
244+
.map((pageData) => pageData.route),
247245
logger: this.logger,
248246
});
249247

packages/astro/src/core/build/internal.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Rollup } from 'vite';
2-
import type { RouteData, SSRResult } from '../../types/public/internal.js';
2+
import type { SSRResult } from '../../types/public/internal.js';
33
import { prependForwardSlash, removeFileExtension } from '../path.js';
44
import { viteID } from '../util.js';
55
import { makePageDataKey } from './plugins/util.js';
@@ -89,7 +89,6 @@ export interface BuildInternals {
8989
// The SSR manifest entry chunk.
9090
manifestEntryChunk?: Rollup.OutputChunk;
9191
manifestFileName?: string;
92-
entryPoints: Map<RouteData, URL>;
9392
componentMetadata: SSRResult['componentMetadata'];
9493
middlewareEntryPoint: URL | undefined;
9594
astroActionsEntryPoint: URL | undefined;
@@ -121,7 +120,6 @@ export function createBuildInternals(): BuildInternals {
121120
discoveredScripts: new Set(),
122121
staticFiles: new Set(),
123122
componentMetadata: new Map(),
124-
entryPoints: new Map(),
125123
prerenderOnlyChunks: [],
126124
astroActionsEntryPoint: undefined,
127125
middlewareEntryPoint: undefined,

packages/astro/src/core/build/plugins/plugin-manifest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ export function pluginManifest(
140140
config: options.settings.config,
141141
manifest,
142142
logger: options.logger,
143-
entryPoints: internals.entryPoints,
144143
middlewareEntryPoint: shouldPassMiddlewareEntryPoint
145144
? internals.middlewareEntryPoint
146145
: undefined,

packages/astro/src/core/server-islands/endpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const SERVER_ISLAND_BASE_PREFIX = '_server-islands';
1717

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

20-
export function getServerIslandRouteData(config: ConfigFields) {
20+
function getServerIslandRouteData(config: ConfigFields) {
2121
const segments = [
2222
[{ content: '_server-islands', dynamic: false, spread: false }],
2323
[{ content: 'name', dynamic: true, spread: false }],

packages/astro/src/integrations/hooks.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import type {
3030
BaseIntegrationHooks,
3131
HookParameters,
3232
IntegrationResolvedRoute,
33-
IntegrationRouteData,
3433
RouteOptions,
3534
RouteToHeaders,
3635
} from '../types/public/integrations.js';
@@ -548,29 +547,22 @@ type RunHookBuildSsr = {
548547
config: AstroConfig;
549548
manifest: SerializedSSRManifest;
550549
logger: Logger;
551-
entryPoints: Map<RouteData, URL>;
552550
middlewareEntryPoint: URL | undefined;
553551
};
554552

555553
export async function runHookBuildSsr({
556554
config,
557555
manifest,
558556
logger,
559-
entryPoints,
560557
middlewareEntryPoint,
561558
}: RunHookBuildSsr) {
562-
const entryPointsMap = new Map();
563-
for (const [key, value] of entryPoints) {
564-
entryPointsMap.set(toIntegrationRouteData(key), value);
565-
}
566559
for (const integration of config.integrations) {
567560
await runHookInternal({
568561
integration,
569562
hookName: 'astro:build:ssr',
570563
logger,
571564
params: () => ({
572565
manifest,
573-
entryPoints: entryPointsMap,
574566
middlewareEntryPoint,
575567
}),
576568
});
@@ -602,15 +594,13 @@ export async function runHookBuildGenerated({
602594
type RunHookBuildDone = {
603595
settings: AstroSettings;
604596
pages: string[];
605-
// TODO: remove in Astro 6
606597
routes: RouteData[];
607598
logger: Logger;
608599
};
609600

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

615605
for (const integration of settings.config.integrations) {
616606
await runHookInternal({
@@ -620,7 +610,6 @@ export async function runHookBuildDone({ settings, pages, routes, logger }: RunH
620610
params: () => ({
621611
pages: pages.map((p) => ({ pathname: p })),
622612
dir,
623-
routes: integrationRoutes,
624613
assets: new Map(
625614
routes.filter((r) => r.distURL !== undefined).map((r) => [r.route, r.distURL!]),
626615
),
@@ -701,20 +690,3 @@ export function toIntegrationResolvedRoute(route: RouteData): IntegrationResolve
701690
: undefined,
702691
};
703692
}
704-
705-
function toIntegrationRouteData(route: RouteData): IntegrationRouteData {
706-
return {
707-
route: route.route,
708-
component: route.component,
709-
generate: route.generate,
710-
params: route.params,
711-
pathname: route.pathname,
712-
segments: route.segments,
713-
prerender: route.prerender,
714-
redirect: route.redirect,
715-
redirectRoute: route.redirectRoute ? toIntegrationRouteData(route.redirectRoute) : undefined,
716-
type: route.type,
717-
pattern: route.pattern,
718-
distURL: route.distURL,
719-
};
720-
}

packages/astro/src/types/public/integrations.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ export interface BaseIntegrationHooks {
211211
'astro:server:done': (options: { logger: AstroIntegrationLogger }) => void | Promise<void>;
212212
'astro:build:ssr': (options: {
213213
manifest: SerializedSSRManifest;
214-
/**
215-
* This maps a {@link RouteData} to an {@link URL}, this URL represents
216-
* the physical file you should import.
217-
*/
218-
// TODO: Change in Astro 6.0
219-
entryPoints: Map<IntegrationRouteData, URL>;
220214
/**
221215
* File path of the emitted middleware
222216
*/
@@ -239,8 +233,6 @@ export interface BaseIntegrationHooks {
239233
'astro:build:done': (options: {
240234
pages: { pathname: string }[];
241235
dir: URL;
242-
/** @deprecated Use the `assets` map and the new `astro:routes:resolved` hook */
243-
routes: IntegrationRouteData[];
244236
assets: Map<string, URL[]>;
245237
logger: AstroIntegrationLogger;
246238
}) => void | Promise<void>;
@@ -263,20 +255,6 @@ export interface AstroIntegration {
263255
} & Partial<Record<string, unknown>>;
264256
}
265257

266-
/**
267-
* A smaller version of the {@link RouteData} that is used in the integrations.
268-
* @deprecated Use {@link IntegrationResolvedRoute}
269-
*/
270-
export type IntegrationRouteData = Omit<
271-
RouteData,
272-
'isIndex' | 'fallbackRoutes' | 'redirectRoute' | 'origin'
273-
> & {
274-
/**
275-
* {@link RouteData.redirectRoute}
276-
*/
277-
redirectRoute?: IntegrationRouteData;
278-
};
279-
280258
export type RouteToHeaders = Map<string, HeaderPayload>;
281259

282260
export type HeaderPayload = {

packages/astro/test/middleware.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ describe('Middleware API in PROD mode, SSR', () => {
349349
edgeMiddleware: true,
350350
},
351351
},
352-
setMiddlewareEntryPoint(entryPointsOrMiddleware) {
353-
middlewarePath = entryPointsOrMiddleware;
352+
setMiddlewareEntryPoint(middlewareEntryPoint) {
353+
middlewarePath = middlewareEntryPoint;
354354
},
355355
}),
356356
});

0 commit comments

Comments
 (0)