Skip to content

Commit

Permalink
Merge branch 'main' into feat/upgrade-sharp
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored May 1, 2023
2 parents 025d340 + d0cf3a2 commit 9cb3ca3
Show file tree
Hide file tree
Showing 52 changed files with 450 additions and 116 deletions.
6 changes: 0 additions & 6 deletions .changeset/polite-pears-kneel.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/tall-news-hang.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/tidy-singers-thank.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/wise-steaks-wash.md

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"eslint-plugin-prettier": "^4.2.1",
"only-allow": "^1.1.1",
"organize-imports-cli": "^0.10.0",
"prettier": "^2.8.7",
"prettier": "^2.8.8",
"prettier-plugin-astro": "^0.8.0",
"tiny-glob": "^0.2.9",
"turbo": "^1.9.3",
Expand Down
16 changes: 16 additions & 0 deletions packages/astro/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# astro

## 2.3.3

### Patch Changes

- [#6940](https://github.com/withastro/astro/pull/6940) [`a98df9374`](https://github.com/withastro/astro/commit/a98df9374dec65c678fa47319cb1481b1af123e2) Thanks [@delucis](https://github.com/delucis)! - Support custom 404s added via `injectRoute` or as `src/pages/404.html`

- [#6948](https://github.com/withastro/astro/pull/6948) [`50975f2ea`](https://github.com/withastro/astro/commit/50975f2ea3a59f9e023cc631a9372c0c7986eec9) Thanks [@imchell](https://github.com/imchell)! - Placeholders for slots are cleaned in HTML String that is rendered

- [#6848](https://github.com/withastro/astro/pull/6848) [`ebae1eaf8`](https://github.com/withastro/astro/commit/ebae1eaf87f49399036033c673b513338f7d9c42) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Update `experimental.assets`'s `image.service` configuration to allow for a config option in addition to an entrypoint

- [#6953](https://github.com/withastro/astro/pull/6953) [`dc062f669`](https://github.com/withastro/astro/commit/dc062f6695ce577dc569781fc0678c903012c336) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Update `astro check` to use version 1.0.0 of the Astro language server

- Updated dependencies [[`ac57b5549`](https://github.com/withastro/astro/commit/ac57b5549f828a17bdbebdaca7ace075307a3c9d)]:
- @astrojs/telemetry@2.1.1
- @astrojs/webapi@2.1.1

## 2.3.2

### Patch Changes
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astro",
"version": "2.3.2",
"version": "2.3.3",
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
"type": "module",
"author": "withastro",
Expand Down Expand Up @@ -106,11 +106,11 @@
"test:e2e:match": "playwright test -g"
},
"dependencies": {
"@astrojs/compiler": "^1.3.1",
"@astrojs/language-server": "^0.28.3",
"@astrojs/compiler": "^1.3.2",
"@astrojs/language-server": "^1.0.0",
"@astrojs/markdown-remark": "^2.1.4",
"@astrojs/telemetry": "^2.1.0",
"@astrojs/webapi": "^2.1.0",
"@astrojs/telemetry": "^2.1.1",
"@astrojs/webapi": "^2.1.1",
"@babel/core": "^7.18.2",
"@babel/generator": "^7.18.2",
"@babel/parser": "^7.18.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
if (isPage || renderer?.name === 'astro:jsx') {
yield html;
} else if (html && html.length > 0) {
yield markHTMLString(html.replace(/\<\/?astro-slot\>/g, ''));
yield markHTMLString(html.replace(/\<\/?astro-slot\b[^>]*>/g, ''));
} else {
yield '';
}
Expand Down
14 changes: 5 additions & 9 deletions packages/astro/src/vite-plugin-astro-server/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type http from 'http';
import mime from 'mime';
import type { AstroSettings, ComponentInstance, ManifestData, RouteData } from '../@types/astro';
import type { ComponentInstance, ManifestData, RouteData } from '../@types/astro';
import type {
ComponentPreload,
DevelopmentEnvironment,
Expand All @@ -12,12 +12,10 @@ import { call as callEndpoint } from '../core/endpoint/dev/index.js';
import { throwIfRedirectNotAllowed } from '../core/endpoint/index.js';
import { AstroErrorData } from '../core/errors/index.js';
import { warn } from '../core/logger/core.js';
import { appendForwardSlash } from '../core/path.js';
import { preload, renderPage } from '../core/render/dev/index.js';
import { getParamsAndProps, GetParamsAndPropsError } from '../core/render/index.js';
import { createRequest } from '../core/request.js';
import { matchAllRoutes } from '../core/routing/index.js';
import { resolvePages } from '../core/util.js';
import { log404 } from './common.js';
import { handle404Response, writeSSRResult, writeWebResponse } from './response.js';

Expand All @@ -35,11 +33,9 @@ interface MatchedRoute {
mod: ComponentInstance;
}

function getCustom404Route({ config }: AstroSettings, manifest: ManifestData) {
// For Windows compat, use relative page paths to match the 404 route
const relPages = resolvePages(config).href.replace(config.root.href, '');
const pattern = new RegExp(`${appendForwardSlash(relPages)}404.(astro|md)`);
return manifest.routes.find((r) => r.component.match(pattern));
function getCustom404Route(manifest: ManifestData): RouteData | undefined {
const route404 = /^\/404\/?$/;
return manifest.routes.find((r) => route404.test(r.route));
}

export async function matchRoute(
Expand Down Expand Up @@ -97,7 +93,7 @@ export async function matchRoute(
}

log404(logging, pathname);
const custom404 = getCustom404Route(settings, manifest);
const custom404 = getCustom404Route(manifest);

if (custom404) {
const filePath = new URL(`./${custom404.component}`, settings.config.root);
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/test/astro-slot-with-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ describe('Slots with client: directives', () => {
const $ = cheerio.load(html);
expect($('script')).to.have.a.lengthOf(1);
});

it('Astro slot tags are cleaned', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
expect($('astro-slot')).to.have.a.lengthOf(0);
});
});
42 changes: 42 additions & 0 deletions packages/astro/test/custom-404-html.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('Custom 404.html', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/custom-404-html/',
site: 'http://example.com',
});
});

describe('dev', () => {
let devServer;
let $;

before(async () => {
devServer = await fixture.startDevServer();
});

after(async () => {
await devServer.stop();
});

it('renders /', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
$ = cheerio.load(html);

expect($('h1').text()).to.equal('Home');
});

it('renders 404 for /a', async () => {
const html = await fixture.fetch('/a').then((res) => res.text());
$ = cheerio.load(html);

expect($('h1').text()).to.equal('Page not found');
expect($('p').text()).to.equal('This 404 is a static HTML file.');
});
});
});
42 changes: 42 additions & 0 deletions packages/astro/test/custom-404-injected.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('Custom 404 with injectRoute', () => {
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/custom-404-injected/',
site: 'http://example.com',
});
});

describe('dev', () => {
let devServer;
let $;

before(async () => {
devServer = await fixture.startDevServer();
});

after(async () => {
await devServer.stop();
});

it('renders /', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
$ = cheerio.load(html);

expect($('h1').text()).to.equal('Home');
});

it('renders 404 for /a', async () => {
const html = await fixture.fetch('/a').then((res) => res.text());
$ = cheerio.load(html);

expect($('h1').text()).to.equal('Page not found');
expect($('p').text()).to.equal('/a');
});
});
});
4 changes: 4 additions & 0 deletions packages/astro/test/fixtures/custom-404-html/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({});
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/custom-404-html/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/custom-404-html",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html lang="en">
<head>
<title>Not Found - Custom 404</title>
</head>
<body>
<h1>Page not found</h1>
<p>This 404 is a static HTML file.</p>
</body>
</html>
11 changes: 11 additions & 0 deletions packages/astro/test/fixtures/custom-404-html/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
---

<html lang="en">
<head>
<title>Custom 404</title>
</head>
<body>
<h1>Home</h1>
</body>
</html>
18 changes: 18 additions & 0 deletions packages/astro/test/fixtures/custom-404-injected/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
integrations: [
{
name: '404-integration',
hooks: {
'astro:config:setup': ({ injectRoute }) => {
injectRoute({
pattern: '404',
entryPoint: 'src/404.astro',
});
},
},
},
],
});
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/custom-404-injected/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/custom-404-injected",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
13 changes: 13 additions & 0 deletions packages/astro/test/fixtures/custom-404-injected/src/404.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
---

<html lang="en">
<head>
<title>Not Found - Custom 404</title>
</head>
<body>
<h1>Page not found</h1>
<p>{canonicalURL.pathname}</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
---

<html lang="en">
<head>
<title>Custom 404</title>
</head>
<body>
<h1>Home</h1>
</body>
</html>
62 changes: 62 additions & 0 deletions packages/astro/test/units/dev/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,68 @@ describe('dev container', () => {
);
});

it('Serves injected 404 route for any 404', async () => {
const fs = createFs(
{
'/src/components/404.astro': `<h1>Custom 404</h1>`,
'/src/pages/page.astro': `<h1>Regular page</h1>`,
},
root
);

await runInContainer(
{
fs,
root,
userConfig: {
output: 'server',
integrations: [
{
name: '@astrojs/test-integration',
hooks: {
'astro:config:setup': ({ injectRoute }) => {
injectRoute({
pattern: '/404',
entryPoint: './src/components/404.astro',
});
},
},
},
],
},
},
async (container) => {
{
// Regular pages are served as expected.
const r = createRequestAndResponse({ method: 'GET', url: '/page' });
container.handle(r.req, r.res);
await r.done;
const doc = await r.text();
expect(doc).to.match(/<h1>Regular page<\/h1>/);
expect(r.res.statusCode).to.equal(200);
}
{
// `/404` serves the custom 404 page as expected.
const r = createRequestAndResponse({ method: 'GET', url: '/404' });
container.handle(r.req, r.res);
await r.done;
const doc = await r.text();
expect(doc).to.match(/<h1>Custom 404<\/h1>/);
expect(r.res.statusCode).to.equal(200);
}
{
// A non-existent page also serves the custom 404 page.
const r = createRequestAndResponse({ method: 'GET', url: '/other-page' });
container.handle(r.req, r.res);
await r.done;
const doc = await r.text();
expect(doc).to.match(/<h1>Custom 404<\/h1>/);
expect(r.res.statusCode).to.equal(200);
}
}
);
});

it('items in public/ are not available from root when using a base', async () => {
await runInContainer(
{
Expand Down
Loading

0 comments on commit 9cb3ca3

Please sign in to comment.