Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove hybrid #375

Merged
merged 11 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package-lock.json
.eslintcache
.pnpm-store
.idea/
**/fixtures/**/.astro

# ignore top-level vscode settings
/.vscode/settings.json
Expand All @@ -20,4 +21,3 @@ package-lock.json

# exclude IntelliJ/WebStorm stuff
.idea

4 changes: 2 additions & 2 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
"@inox-tools/astro-when": "^0.2.2"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"astro": "^5.0.0-alpha.0",
"astro": "^5.0.0-alpha.6",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"execa": "^8.0.1",
Expand Down
9 changes: 5 additions & 4 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ export default function createIntegration(args?: Options): AstroIntegration {
order: 'pre',
});
},
'astro:config:done': ({ setAdapter, config }) => {
if (config.output === 'static') {
throw new AstroError(
'[@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.'
'astro:config:done': ({ setAdapter, config, buildOutput, logger }) => {
if (buildOutput === 'static') {
logger.warn(
'[@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.'
);
}

Expand All @@ -156,6 +156,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
exports: ['default'],
adapterFeatures: {
edgeMiddleware: false,
buildOutput: 'server',
},
supportedAstroFeatures: {
serverOutput: 'stable',
Expand Down
4 changes: 2 additions & 2 deletions packages/cloudflare/src/utils/image-config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { AstroConfig, AstroIntegrationLogger } from 'astro';
import type { AstroConfig, AstroIntegrationLogger, HookParameters } from 'astro';
import { passthroughImageService, sharpImageService } from 'astro/config';

export function setImageConfig(
service: string,
config: AstroConfig['image'],
command: 'dev' | 'build' | 'preview',
command: HookParameters<'astro:config:setup'>['command'],
logger: AstroIntegrationLogger
) {
switch (service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
},
"devDependencies": {
"wrangler": "^3.72.2"
Expand Down
12 changes: 5 additions & 7 deletions packages/cloudflare/test/fixtures/astro-env/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import cloudflare from '@astrojs/cloudflare';
import { defineConfig, envField } from 'astro/config';

export default defineConfig({
experimental: {
env: {
schema: {
API_URL: envField.string({ context: 'client', access: 'public', optional: true }),
PORT: envField.number({ context: 'server', access: 'public', default: 4321 }),
API_SECRET: envField.string({ context: 'server', access: 'secret' }),
},
env: {
schema: {
API_URL: envField.string({ context: 'client', access: 'public', optional: true }),
PORT: envField.number({ context: 'server', access: 'public', default: 4321 }),
API_SECRET: envField.string({ context: 'server', access: 'secret' }),
},
},
adapter: cloudflare(),
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/test/fixtures/astro-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
},
"devDependencies": {
"wrangler": "^3.72.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export default defineConfig({
adapter: cloudflare({
imageService: 'compile',
}),
output: 'hybrid',
output: 'static',
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { defineConfig } from 'astro/config';

export default defineConfig({
adapter: cloudflare({}),
output: 'hybrid'
output: 'static'
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
}
}
2 changes: 1 addition & 1 deletion packages/cloudflare/test/fixtures/no-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'astro/config';

export default defineConfig({
output: 'hybrid',
output: 'static',
redirects: {
'/a/redirect': '/',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/test/fixtures/routes-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"@astrojs/solid-js": "^4.4.1",
"astro": "^5.0.0-alpha.0",
"astro": "^5.0.0-alpha.6",
"solid-js": "^1.8.21"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
}
}
23 changes: 0 additions & 23 deletions packages/cloudflare/test/no-output.test.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/cloudflare/test/routes-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('_routes.json generation', () => {

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

assert.deepEqual(routes, {
version: 1,
include: ['/_image'],
include: [],
exclude: [],
});
});
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('_routes.json generation', () => {

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

assert.deepEqual(routes, {
version: 1,
include: ['/_image', '/a/*'],
include: ['/a/*', '/_image'],
exclude: [
'/_astro/*',
'/redirectme',
Expand Down
4 changes: 2 additions & 2 deletions packages/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"esbuild": "^0.23.1"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"@netlify/edge-functions": "^2.10.0",
"@netlify/edge-handler-types": "^0.34.1",
"@types/node": "^20.16.1",
"astro": "^5.0.0-alpha.0",
"astro": "^5.0.0-alpha.6",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"execa": "^8.0.1",
Expand Down
22 changes: 16 additions & 6 deletions packages/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { fileURLToPath } from 'node:url';
import { emptyDir } from '@astrojs/internal-helpers/fs';
import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects';
import type { Context } from '@netlify/functions';
import type { AstroConfig, AstroIntegration, AstroIntegrationLogger, RouteData } from 'astro';
import type {
AstroConfig,
AstroIntegration,
AstroIntegrationLogger,
HookParameters,
RouteData,
} from 'astro';
import { build } from 'esbuild';
import { copyDependenciesToFunction } from './lib/nft.js';
import type { Args } from './ssr-function.js';
Expand Down Expand Up @@ -201,6 +207,8 @@ export default function netlifyIntegration(
// Secret used to verify that the caller is the astro-generated edge middleware and not a third-party
const middlewareSecret = randomUUID();

let finalBuildOutput: HookParameters<'astro:config:done'>['buildOutput'];

const TRACE_CACHE = {};

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

async function writeRedirects(routes: RouteData[], dir: URL) {
const fallback = _config.output === 'static' ? '/.netlify/static' : '/.netlify/functions/ssr';
const fallback = finalBuildOutput === 'static' ? '/.netlify/static' : '/.netlify/functions/ssr';
const redirects = createRedirectsFromAstroRoutes({
config: _config,
dir,
Expand Down Expand Up @@ -283,7 +291,7 @@ export default function netlifyIntegration(
import { createContext, trySerializeLocals } from 'astro/middleware';

export default async (request, context) => {
const ctx = createContext({
const ctx = createContext({
request,
params: {}
});
Expand All @@ -294,7 +302,7 @@ export default function netlifyIntegration(
request.headers.set("x-astro-middleware-secret", "${middlewareSecret}");
return context.next();
};

return onRequest(ctx, next);
}

Expand Down Expand Up @@ -440,10 +448,12 @@ export default function netlifyIntegration(
},
});
},
'astro:config:done': async ({ config, setAdapter, logger }) => {
'astro:config:done': async ({ config, setAdapter, logger, buildOutput }) => {
rootDir = config.root;
_config = config;

finalBuildOutput = buildOutput;

await writeNetlifyFrameworkConfig(config, logger);

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

if (_config.output !== 'static') {
if (finalBuildOutput !== 'static') {
let notFoundContent = undefined;
try {
notFoundContent = await readFile(new URL('./404.html', dir), 'utf8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import netlify from '@astrojs/netlify';
import { defineConfig } from 'astro/config';

export default defineConfig({
output: 'hybrid',
output: 'static',
adapter: netlify(),
site: `http://example.com`,
redirects: {
'/other': '/',
},
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
},
"dependencies": {
"@astrojs/netlify": "workspace:*",
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
}
}
4 changes: 2 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
"server-destroy": "^1.0.1"
},
"peerDependencies": {
"astro": "^5.0.0-alpha.0"
"astro": "^5.0.0-alpha.6"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"@types/node": "^18.17.8",
"@types/send": "^0.17.4",
"@types/server-destroy": "^1.0.4",
"astro": "^5.0.0-alpha.0",
"astro": "^5.0.0-alpha.6",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"express": "^4.19.2",
Expand Down
Loading