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

fix(deps): update dependency send to v1 #421

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/many-hornets-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': minor
---

Changes the logic which generates the `_routes.json` file to improve generation for projects with many static pages, while still making sure all routes work as expected.
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"files": {
"ignore": [
"**/dist",
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@
}
},
"devDependencies": {
"@astrojs/check": "^0.9.3",
"@biomejs/biome": "1.9.2",
"@astrojs/check": "^0.9.4",
"@biomejs/biome": "1.9.4",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.8",
"@types/node": "^20.16.10",
"@changesets/cli": "^2.27.9",
"@types/node": "^20.16.15",
"esbuild": "^0.21.5",
"eslint": "^9.11.1",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-no-only-tests": "^3.3.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-regexp": "^2.6.0",
"only-allow": "^1.2.1",
"prettier": "^3.3.3",
"prettier-plugin-astro": "^0.14.1",
"turbo": "^2.1.3",
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.0"
"turbo": "^2.2.3",
"typescript": "^5.6.3",
"typescript-eslint": "^8.11.0"
}
}
16 changes: 8 additions & 8 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@
"dependencies": {
"@astrojs/internal-helpers": "0.4.1",
"@astrojs/underscore-redirects": "^0.3.4",
"@cloudflare/workers-types": "^4.20240925.0",
"@cloudflare/workers-types": "^4.20241022.0",
"esbuild": "^0.21.5",
"estree-walker": "^3.0.3",
"magic-string": "^0.30.11",
"miniflare": "^3.20240925.0",
"magic-string": "^0.30.12",
"miniflare": "^3.20241018.0",
"tiny-glob": "^0.2.9",
"wrangler": "^3.78.12",
"@inox-tools/astro-when": "^0.2.3"
"wrangler": "^3.82.0",
"@inox-tools/astro-when": "^0.2.4"
},
"peerDependencies": {
"astro": "^4.10.3"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"astro": "^4.15.9",
"astro": "^4.16.7",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"execa": "^8.0.1",
"fast-glob": "^3.3.2",
"rollup": "^4.22.5",
"rollup": "^4.24.0",
"strip-ansi": "^7.1.0",
"vite": "^5.4.8"
"vite": "^5.4.10"
},
"publishConfig": {
"provenance": true
Expand Down
9 changes: 4 additions & 5 deletions packages/cloudflare/src/utils/generate-routes-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,10 @@ export async function createRoutesFile(
const EXTENDED_EXCLUDE_RULES_COUNT = excludeExtends?.length ?? 0;
const EXCLUDE_RULES_COUNT = AUTOMATIC_EXCLUDE_RULES_COUNT + EXTENDED_EXCLUDE_RULES_COUNT;

if (
!hasPrerendered404 ||
INCLUDE_RULES_COUNT > CLOUDFLARE_COMBINED_LIMIT ||
EXCLUDE_RULES_COUNT > CLOUDFLARE_COMBINED_LIMIT
) {
const OPTION2_TOTAL_COUNT =
INCLUDE_RULES_COUNT + (includedPathsHaveWildcard ? EXCLUDE_RULES_COUNT : 0);

if (!hasPrerendered404 || OPTION2_TOTAL_COUNT > CLOUDFLARE_COMBINED_LIMIT) {
await writeRoutesFileToOutDir(
_config,
logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^4.15.9"
"astro": "^4.16.7"
},
"devDependencies": {
"wrangler": "^3.78.12"
"wrangler": "^3.82.0"
}
}
4 changes: 2 additions & 2 deletions packages/cloudflare/test/fixtures/astro-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^4.15.9"
"astro": "^4.16.7"
},
"devDependencies": {
"wrangler": "^3.78.12"
"wrangler": "^3.82.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^4.15.9"
"astro": "^4.16.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^4.15.9"
"astro": "^4.16.7"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^4.15.9"
"astro": "^4.16.7"
}
}
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": "^4.15.9"
"astro": "^4.16.7"
}
}
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": "^4.15.9"
"astro": "^4.16.7"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../../.astro/types.d.ts" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
import type { GetStaticPaths } from "astro";

export const getStaticPaths = (() => {

return Array.from({length:100}).map((_, i) => ({
params: {
id: i.toString()
}
}));
}) satisfies GetStaticPaths;

const { id } = Astro.params;
---

id={id}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender = false;
---

dynamic
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../../.astro/types.d.ts" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
import type { GetStaticPaths } from "astro";

export const getStaticPaths = (() => {

return Array.from({length:100}).map((_, i) => ({
params: {
id: i.toString()
}
}));
}) satisfies GetStaticPaths;

const { id } = Astro.params;
---

id={id}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
export const prerender = false;
---

dynamic
4 changes: 2 additions & 2 deletions packages/cloudflare/test/fixtures/with-solid-js/package.json
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.2",
"astro": "^4.15.9",
"solid-js": "^1.9.1"
"astro": "^4.16.7",
"solid-js": "^1.9.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "^4.15.9"
"astro": "^4.16.7"
}
}
54 changes: 54 additions & 0 deletions packages/cloudflare/test/routes-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,58 @@ describe('_routes.json generation', () => {
});
});
});

describe('with many static files', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/routes-json/', import.meta.url).toString(),
srcDir: './src/manyStatic',
adapter: cloudflare({}),
});
await fixture.build();
});

it('creates a wildcard `include` and `exclude` for as many static assets and redirects as possible, truncating after 100 rules', async () => {
const _routesJson = await fixture.readFile('/_routes.json');
const routes = JSON.parse(_routesJson);

assert.deepEqual(routes, {
version: 1,
include: ['/*'],
exclude: [
'/_astro/*',
'/redirectme',
'/public.txt',
'/a/*',
...Array.from({ length: 95 }, (_, i) => `/${i}`),
],
});
});
});

describe('with many static files when a static 404 is present', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: new URL('./fixtures/routes-json/', import.meta.url).toString(),
srcDir: './src/manyStaticWith404',
adapter: cloudflare({}),
});
await fixture.build();
});

it('creates `include` for on-demand and `exclude` that are supposed to match nothin', async () => {
const _routesJson = await fixture.readFile('/_routes.json');
const routes = JSON.parse(_routesJson);

assert.deepEqual(routes, {
version: 1,
include: ['/_image', '/dynamic'],
exclude: [],
});
});
});
});
6 changes: 6 additions & 0 deletions packages/netlify/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @astrojs/netlify

## 5.5.4

### Patch Changes

- [#413](https://github.com/withastro/adapters/pull/413) [`1b18e67`](https://github.com/withastro/adapters/commit/1b18e671a689b67bde20fdc7fb8cf1d6283e4ec9) Thanks [@ascorbic](https://github.com/ascorbic)! - Fixes `context.rewrite` in edge middleware

## 5.5.3

### Patch Changes
Expand Down
12 changes: 6 additions & 6 deletions packages/netlify/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@astrojs/netlify",
"description": "Deploy your site to Netlify",
"version": "5.5.3",
"version": "5.5.4",
"type": "module",
"types": "./dist/index.d.ts",
"author": "withastro",
Expand Down Expand Up @@ -34,9 +34,9 @@
"@astrojs/internal-helpers": "0.4.1",
"@astrojs/underscore-redirects": "^0.3.4",
"@netlify/functions": "^2.8.0",
"@vercel/nft": "^0.27.4",
"@vercel/nft": "^0.27.5",
"esbuild": "^0.21.5",
"vite": "^5.4.8"
"vite": "^5.4.10"
},
"peerDependencies": {
"astro": "^4.2.0"
Expand All @@ -45,14 +45,14 @@
"@astrojs/test-utils": "workspace:*",
"@netlify/edge-functions": "^2.11.0",
"@netlify/edge-handler-types": "^0.34.1",
"@types/node": "^20.16.10",
"astro": "^4.15.9",
"@types/node": "^20.16.15",
"astro": "^4.16.7",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"execa": "^8.0.1",
"fast-glob": "^3.3.2",
"strip-ansi": "^7.1.0",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
},
"astro": {
"external": true
Expand Down
19 changes: 19 additions & 0 deletions packages/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,25 @@ export default function netlifyIntegration(
params: {}
});
ctx.locals = { netlify: { context } }
// https://docs.netlify.com/edge-functions/api/#return-a-rewrite
ctx.rewrite = (target) => {
if(target instanceof Request) {
// We can only mutate headers, so if anything else is different, we need to fetch
// the target URL instead.
if(target.method !== request.method || target.body || target.url.origin !== request.url.origin) {
return fetch(target);
}
// We can't replace the headers object, so we need to delete all headers and set them again
request.headers.forEach((_value, key) => {
request.headers.delete(key);
});
target.headers.forEach((value, key) => {
request.headers.set(key, value);
});
return new URL(target.url);
}
return new URL(target, request.url);
};
const next = () => {
const { netlify, ...otherLocals } = ctx.locals;
request.headers.set("x-astro-locals", trySerializeLocals(otherLocals));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
},
"dependencies": {
"@astrojs/netlify": "workspace:*",
"astro": "^4.15.9"
"astro": "^4.16.7"
}
}
Loading