Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit e7881f7

Browse files
authored
feat: remove hybrid (#375)
* feat: remove hybrid * fix: udpate with new API * fix: update for latest next changes * fix: more test-utils fix * fix: build * fix: build * fix: tests * fix: netlify * fix: astro env * fix: use types from AStro * chore: changeset
1 parent 17a7fe5 commit e7881f7

File tree

79 files changed

+382
-526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+382
-526
lines changed

.changeset/eighty-badgers-change.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@astrojs/cloudflare': major
3+
'@astrojs/netlify': major
4+
'@astrojs/vercel': major
5+
'@astrojs/node': major
6+
---
7+
8+
Updates internal code to works with Astro 5 changes to hybrid rendering. No changes are necessary to your project, apart from using Astro 5

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package-lock.json
1111
.eslintcache
1212
.pnpm-store
1313
.idea/
14+
**/fixtures/**/.astro
1415

1516
# ignore top-level vscode settings
1617
/.vscode/settings.json
@@ -20,4 +21,3 @@ package-lock.json
2021

2122
# exclude IntelliJ/WebStorm stuff
2223
.idea
23-

packages/cloudflare/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
"@inox-tools/astro-when": "^0.2.2"
4141
},
4242
"peerDependencies": {
43-
"astro": "^5.0.0-alpha.0"
43+
"astro": "^5.0.0-alpha.6"
4444
},
4545
"devDependencies": {
4646
"@astrojs/test-utils": "workspace:*",
47-
"astro": "^5.0.0-alpha.0",
47+
"astro": "^5.0.0-alpha.6",
4848
"astro-scripts": "workspace:*",
4949
"cheerio": "1.0.0",
5050
"execa": "^8.0.1",

packages/cloudflare/src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ export default function createIntegration(args?: Options): AstroIntegration {
141141
order: 'pre',
142142
});
143143
},
144-
'astro:config:done': ({ setAdapter, config }) => {
145-
if (config.output === 'static') {
146-
throw new AstroError(
147-
'[@astrojs/cloudflare] `output: "server"` or `output: "hybrid"` is required to use this adapter. Otherwise, this adapter is not necessary to deploy a static site to Cloudflare.'
144+
'astro:config:done': ({ setAdapter, config, buildOutput, logger }) => {
145+
if (buildOutput === 'static') {
146+
logger.warn(
147+
'[@astrojs/cloudflare] This adapter is intended to be used with server rendered pages, which this project does not contain any of. As such, this adapter is unnecessary.'
148148
);
149149
}
150150

@@ -156,6 +156,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
156156
exports: ['default'],
157157
adapterFeatures: {
158158
edgeMiddleware: false,
159+
buildOutput: 'server',
159160
},
160161
supportedAstroFeatures: {
161162
serverOutput: 'stable',

packages/cloudflare/src/utils/image-config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { AstroConfig, AstroIntegrationLogger } from 'astro';
1+
import type { AstroConfig, AstroIntegrationLogger, HookParameters } from 'astro';
22
import { passthroughImageService, sharpImageService } from 'astro/config';
33

44
export function setImageConfig(
55
service: string,
66
config: AstroConfig['image'],
7-
command: 'dev' | 'build' | 'preview',
7+
command: HookParameters<'astro:config:setup'>['command'],
88
logger: AstroIntegrationLogger
99
) {
1010
switch (service) {

packages/cloudflare/test/fixtures/astro-dev-platform/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
7-
"astro": "^5.0.0-alpha.0"
7+
"astro": "^5.0.0-alpha.6"
88
},
99
"devDependencies": {
1010
"wrangler": "^3.72.2"

packages/cloudflare/test/fixtures/astro-env/astro.config.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import cloudflare from '@astrojs/cloudflare';
22
import { defineConfig, envField } from 'astro/config';
33

44
export default defineConfig({
5-
experimental: {
6-
env: {
7-
schema: {
8-
API_URL: envField.string({ context: 'client', access: 'public', optional: true }),
9-
PORT: envField.number({ context: 'server', access: 'public', default: 4321 }),
10-
API_SECRET: envField.string({ context: 'server', access: 'secret' }),
11-
},
5+
env: {
6+
schema: {
7+
API_URL: envField.string({ context: 'client', access: 'public', optional: true }),
8+
PORT: envField.number({ context: 'server', access: 'public', default: 4321 }),
9+
API_SECRET: envField.string({ context: 'server', access: 'secret' }),
1210
},
1311
},
1412
adapter: cloudflare(),

packages/cloudflare/test/fixtures/astro-env/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
7-
"astro": "^5.0.0-alpha.0"
7+
"astro": "^5.0.0-alpha.6"
88
},
99
"devDependencies": {
1010
"wrangler": "^3.72.2"

packages/cloudflare/test/fixtures/compile-image-service/astro.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export default defineConfig({
55
adapter: cloudflare({
66
imageService: 'compile',
77
}),
8-
output: 'hybrid',
8+
output: 'static',
99
});

packages/cloudflare/test/fixtures/compile-image-service/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"private": true,
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
7-
"astro": "^5.0.0-alpha.0"
7+
"astro": "^5.0.0-alpha.6"
88
}
99
}

packages/cloudflare/test/fixtures/external-image-service/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"private": true,
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
7-
"astro": "^5.0.0-alpha.0"
7+
"astro": "^5.0.0-alpha.6"
88
}
99
}

packages/cloudflare/test/fixtures/module-loader/astro.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { defineConfig } from 'astro/config';
33

44
export default defineConfig({
55
adapter: cloudflare({}),
6-
output: 'hybrid'
6+
output: 'static'
77
});

packages/cloudflare/test/fixtures/module-loader/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"private": true,
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
7-
"astro": "^5.0.0-alpha.0"
7+
"astro": "^5.0.0-alpha.6"
88
}
99
}

packages/cloudflare/test/fixtures/no-output/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"private": true,
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
7-
"astro": "^5.0.0-alpha.0"
7+
"astro": "^5.0.0-alpha.6"
88
}
99
}

packages/cloudflare/test/fixtures/routes-json/astro.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig } from 'astro/config';
22

33
export default defineConfig({
4-
output: 'hybrid',
4+
output: 'static',
55
redirects: {
66
'/a/redirect': '/',
77
},

packages/cloudflare/test/fixtures/routes-json/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"private": true,
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
7-
"astro": "^5.0.0-alpha.0"
7+
"astro": "^5.0.0-alpha.6"
88
}
99
}

packages/cloudflare/test/fixtures/with-solid-js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
77
"@astrojs/solid-js": "^4.4.1",
8-
"astro": "^5.0.0-alpha.0",
8+
"astro": "^5.0.0-alpha.6",
99
"solid-js": "^1.8.21"
1010
}
1111
}

packages/cloudflare/test/fixtures/wrangler-preview-platform/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"private": true,
55
"dependencies": {
66
"@astrojs/cloudflare": "workspace:*",
7-
"astro": "^5.0.0-alpha.0"
7+
"astro": "^5.0.0-alpha.6"
88
}
99
}

packages/cloudflare/test/no-output.test.js

-23
This file was deleted.

packages/cloudflare/test/routes-json.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('_routes.json generation', () => {
2323

2424
assert.deepEqual(routes, {
2525
version: 1,
26-
include: ['/_image', '/a/*'],
26+
include: ['/a/*', '/_image'],
2727
exclude: ['/_astro/*', '/redirectme', '/public.txt', '/a', '/a/redirect', '/404', '/b'],
2828
});
2929
});
@@ -71,7 +71,7 @@ describe('_routes.json generation', () => {
7171

7272
assert.deepEqual(routes, {
7373
version: 1,
74-
include: ['/_image'],
74+
include: [],
7575
exclude: [],
7676
});
7777
});
@@ -101,7 +101,7 @@ describe('_routes.json generation', () => {
101101

102102
assert.deepEqual(routes, {
103103
version: 1,
104-
include: ['/_image', '/a/*', '/another'],
104+
include: ['/a/*', '/_image', '/another'],
105105
exclude: ['/_astro/*', '/redirectme', '/public.txt', '/a', '/a/redirect', '/404', '/b'],
106106
});
107107
});
@@ -131,7 +131,7 @@ describe('_routes.json generation', () => {
131131

132132
assert.deepEqual(routes, {
133133
version: 1,
134-
include: ['/_image', '/a/*'],
134+
include: ['/a/*', '/_image'],
135135
exclude: [
136136
'/_astro/*',
137137
'/redirectme',

packages/netlify/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
"esbuild": "^0.23.1"
3939
},
4040
"peerDependencies": {
41-
"astro": "^5.0.0-alpha.0"
41+
"astro": "^5.0.0-alpha.6"
4242
},
4343
"devDependencies": {
4444
"@astrojs/test-utils": "workspace:*",
4545
"@netlify/edge-functions": "^2.10.0",
4646
"@netlify/edge-handler-types": "^0.34.1",
4747
"@types/node": "^20.16.1",
48-
"astro": "^5.0.0-alpha.0",
48+
"astro": "^5.0.0-alpha.6",
4949
"astro-scripts": "workspace:*",
5050
"cheerio": "1.0.0",
5151
"execa": "^8.0.1",

packages/netlify/src/index.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { fileURLToPath } from 'node:url';
55
import { emptyDir } from '@astrojs/internal-helpers/fs';
66
import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects';
77
import type { Context } from '@netlify/functions';
8-
import type { AstroConfig, AstroIntegration, AstroIntegrationLogger, RouteData } from 'astro';
8+
import type {
9+
AstroConfig,
10+
AstroIntegration,
11+
AstroIntegrationLogger,
12+
HookParameters,
13+
RouteData,
14+
} from 'astro';
915
import { build } from 'esbuild';
1016
import { copyDependenciesToFunction } from './lib/nft.js';
1117
import type { Args } from './ssr-function.js';
@@ -201,6 +207,8 @@ export default function netlifyIntegration(
201207
// Secret used to verify that the caller is the astro-generated edge middleware and not a third-party
202208
const middlewareSecret = randomUUID();
203209

210+
let finalBuildOutput: HookParameters<'astro:config:done'>['buildOutput'];
211+
204212
const TRACE_CACHE = {};
205213

206214
const ssrBuildDir = () => new URL('./.netlify/build/', rootDir);
@@ -215,7 +223,7 @@ export default function netlifyIntegration(
215223
]);
216224

217225
async function writeRedirects(routes: RouteData[], dir: URL) {
218-
const fallback = _config.output === 'static' ? '/.netlify/static' : '/.netlify/functions/ssr';
226+
const fallback = finalBuildOutput === 'static' ? '/.netlify/static' : '/.netlify/functions/ssr';
219227
const redirects = createRedirectsFromAstroRoutes({
220228
config: _config,
221229
dir,
@@ -283,7 +291,7 @@ export default function netlifyIntegration(
283291
import { createContext, trySerializeLocals } from 'astro/middleware';
284292
285293
export default async (request, context) => {
286-
const ctx = createContext({
294+
const ctx = createContext({
287295
request,
288296
params: {}
289297
});
@@ -294,7 +302,7 @@ export default function netlifyIntegration(
294302
request.headers.set("x-astro-middleware-secret", "${middlewareSecret}");
295303
return context.next();
296304
};
297-
305+
298306
return onRequest(ctx, next);
299307
}
300308
@@ -440,10 +448,12 @@ export default function netlifyIntegration(
440448
},
441449
});
442450
},
443-
'astro:config:done': async ({ config, setAdapter, logger }) => {
451+
'astro:config:done': async ({ config, setAdapter, logger, buildOutput }) => {
444452
rootDir = config.root;
445453
_config = config;
446454

455+
finalBuildOutput = buildOutput;
456+
447457
await writeNetlifyFrameworkConfig(config, logger);
448458

449459
const edgeMiddleware = integrationConfig?.edgeMiddleware ?? false;
@@ -477,7 +487,7 @@ export default function netlifyIntegration(
477487
await writeRedirects(routes, dir);
478488
logger.info('Emitted _redirects');
479489

480-
if (_config.output !== 'static') {
490+
if (finalBuildOutput !== 'static') {
481491
let notFoundContent = undefined;
482492
try {
483493
notFoundContent = await readFile(new URL('./404.html', dir), 'utf8');

packages/netlify/test/functions/fixtures/redirects/astro.config.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import netlify from '@astrojs/netlify';
22
import { defineConfig } from 'astro/config';
33

44
export default defineConfig({
5-
output: 'hybrid',
5+
output: 'static',
66
adapter: netlify(),
77
site: `http://example.com`,
88
redirects: {
99
'/other': '/',
1010
},
11-
});
11+
});

packages/netlify/test/hosted/hosted-astro-project/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
},
88
"dependencies": {
99
"@astrojs/netlify": "workspace:*",
10-
"astro": "^5.0.0-alpha.0"
10+
"astro": "^5.0.0-alpha.6"
1111
}
1212
}

packages/node/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
"server-destroy": "^1.0.1"
3131
},
3232
"peerDependencies": {
33-
"astro": "^5.0.0-alpha.0"
33+
"astro": "^5.0.0-alpha.6"
3434
},
3535
"devDependencies": {
3636
"@astrojs/test-utils": "workspace:*",
3737
"@types/node": "^18.17.8",
3838
"@types/send": "^0.17.4",
3939
"@types/server-destroy": "^1.0.4",
40-
"astro": "^5.0.0-alpha.0",
40+
"astro": "^5.0.0-alpha.6",
4141
"astro-scripts": "workspace:*",
4242
"cheerio": "1.0.0",
4343
"express": "^4.19.2",

0 commit comments

Comments
 (0)