Skip to content

Commit

Permalink
[ci] release
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jun 5, 2023
1 parent 57f8d14 commit 17eb3f3
Show file tree
Hide file tree
Showing 53 changed files with 307 additions and 266 deletions.
33 changes: 0 additions & 33 deletions .changeset/chatty-actors-stare.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/fuzzy-ladybugs-jump.md

This file was deleted.

7 changes: 0 additions & 7 deletions .changeset/hip-news-clean.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/lazy-falcons-divide.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/tasty-stingrays-smile.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changeset/twenty-suns-vanish.md

This file was deleted.

40 changes: 40 additions & 0 deletions packages/astro/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
# astro

## 2.6.0

### Minor Changes

- [#7067](https://github.com/withastro/astro/pull/7067) [`57f8d14c0`](https://github.com/withastro/astro/commit/57f8d14c027c30919363e12c664ccff4ed64d0fc) Thanks [@matthewp](https://github.com/matthewp)! - Experimental redirects support

This change adds support for the redirects RFC, currently in stage 3: https://github.com/withastro/roadmap/pull/587

Now you can specify redirects in your Astro config:

```js
import { defineConfig } from 'astro/config';

export defineConfig({
redirects: {
'/blog/old-post': '/blog/new-post'
}
});
```

You can also specify spread routes using the same syntax as in file-based routing:

```js
import { defineConfig } from 'astro/config';

export defineConfig({
redirects: {
'/blog/[...slug]': '/articles/[...slug]'
}
});
```

By default Astro will build HTML files that contain the `<meta http-equiv="refresh">` tag. Adapters can also support redirect routes and create configuration for real HTTP-level redirects in production.

### Patch Changes

- [#7294](https://github.com/withastro/astro/pull/7294) [`dd1a6b6c9`](https://github.com/withastro/astro/commit/dd1a6b6c941aeb7af934bd12db22412af262f5a1) Thanks [@matthewp](https://github.com/matthewp)! - Fix cookies not being set by middleware

- [#7242](https://github.com/withastro/astro/pull/7242) [`890a2bc98`](https://github.com/withastro/astro/commit/890a2bc9891a2449ab99b01b65468f6dddba6b12) Thanks [@JerryWu1234](https://github.com/JerryWu1234)! - remove the white space after the doctype according to the property compressHTML

## 2.5.7

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "astro",
"version": "2.5.7",
"version": "2.6.0",
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
"type": "module",
"author": "withastro",
Expand Down
32 changes: 16 additions & 16 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,21 +453,19 @@ export interface AstroUserConfig {
*/
cacheDir?: string;



/**
* @docs
* @name redirects (Experimental)
* @type {RedirectConfig}
* @default `{}`
* @version 2.6.0
* @description Specify a mapping of redirects where the key is the route to match
* and the value is the path to redirect to.
* and the value is the path to redirect to.
*
* You can redirect both static and dynamic routes, but only to the same kind of route.
* For example you cannot have a `'/article': '/blog/[...slug]'` redirect.
*
*
*
*
* ```js
* {
* redirects: {
Expand All @@ -477,16 +475,16 @@ export interface AstroUserConfig {
* }
* ```
*
*
*
* For statically-generated sites with no adapter installed, this will produce a client redirect using a [`<meta http-equiv="refresh">` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#http-equiv) and does not support status codes.
*
* When using SSR or with a static adapter in `output: static`
* mode, status codes are supported.
* Astro will serve redirected GET requests with a status of `301`
* and use a status of `308` for any other request method.
*
*
* You can customize the [redirection status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages) using an object in the redirect config:
*
*
* ```js
* {
* redirects: {
Expand Down Expand Up @@ -791,8 +789,8 @@ export interface AstroUserConfig {
* Specifies whether redirects will be output to HTML during the build.
* This option only applies to `output: 'static'` mode; in SSR redirects
* are treated the same as all responses.
*
* This option is mostly meant to be used by adapters that have special
*
* This option is mostly meant to be used by adapters that have special
* configuration files for redirects and do not need/want HTML based redirects.
*
* ```js
Expand Down Expand Up @@ -1270,7 +1268,7 @@ export interface AstroUserConfig {
* }
* ```
*/
redirects?: boolean;
redirects?: boolean;
};

// Legacy options to be removed
Expand Down Expand Up @@ -1924,10 +1922,12 @@ export interface RoutePart {
spread: boolean;
}

type RedirectConfig = string | {
status: ValidRedirectStatus;
destination: string;
}
type RedirectConfig =
| string
| {
status: ValidRedirectStatus;
destination: string;
};

export interface RouteData {
route: string;
Expand All @@ -1947,7 +1947,7 @@ export interface RouteData {

export type RedirectRouteData = RouteData & {
redirect: string;
}
};

export type SerializedRouteData = Omit<RouteData, 'generate' | 'pattern'> & {
generate: undefined;
Expand Down
8 changes: 5 additions & 3 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ export class App {
}

async #getModuleForRoute(route: RouteData): Promise<ComponentInstance> {
if(route.type === 'redirect') {
if (route.type === 'redirect') {
return RedirectComponentInstance;
} else {
const importComponentInstance = this.#manifest.pageMap.get(route.component);
if(!importComponentInstance) {
throw new Error(`Unexpectedly unable to find a component instance for route ${route.route}`);
if (!importComponentInstance) {
throw new Error(
`Unexpectedly unable to find a component instance for route ${route.route}`
);
}
const built = await importComponentInstance();
return built.page();
Expand Down
43 changes: 26 additions & 17 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ import { debug, info } from '../logger/core.js';
import { callMiddleware } from '../middleware/callMiddleware.js';
import { createEnvironment, createRenderContext, renderPage } from '../render/index.js';
import { callGetStaticPaths } from '../render/route-cache.js';
import { getRedirectLocationOrThrow, RedirectComponentInstance, routeIsRedirect } from '../redirects/index.js';
import {
import {
getRedirectLocationOrThrow,
RedirectComponentInstance,
routeIsRedirect,
} from '../redirects/index.js';
import {
createAssetLink,
createModuleScriptsSet,
createStylesheetElementSet,
Expand All @@ -52,7 +56,12 @@ import { createRequest } from '../request.js';
import { matchRoute } from '../routing/match.js';
import { getOutputFilename } from '../util.js';
import { getOutDirWithinCwd, getOutFile, getOutFolder } from './common.js';
import { cssOrder, getPageDataByComponent, mergeInlineCss, getEntryFilePathFromComponentPath } from './internal.js';
import {
cssOrder,
getPageDataByComponent,
mergeInlineCss,
getEntryFilePathFromComponentPath,
} from './internal.js';
import type {
PageBuildData,
SinglePageBuiltModule,
Expand All @@ -62,24 +71,24 @@ import type {
import { getTimeStat } from './util.js';

const StaticMiddlewareInstance: AstroMiddlewareInstance<unknown> = {
onRequest: (ctx, next) => next()
onRequest: (ctx, next) => next(),
};

function createEntryURL(filePath: string, outFolder: URL) {
return new URL('./' + filePath + `?time=${Date.now()}`, outFolder);
}
}

async function getEntryForRedirectRoute(
route: RouteData,
internals: BuildInternals,
outFolder: URL
): Promise<SinglePageBuiltModule> {
if(route.type !== 'redirect') {
if (route.type !== 'redirect') {
throw new Error(`Expected a redirect route.`);
}
if(route.redirectRoute) {
if (route.redirectRoute) {
const filePath = getEntryFilePathFromComponentPath(internals, route.redirectRoute.component);
if(filePath) {
if (filePath) {
const url = createEntryURL(filePath, outFolder);
const ssrEntryPage: SinglePageBuiltModule = await import(url.toString());
return ssrEntryPage;
Expand All @@ -89,8 +98,8 @@ async function getEntryForRedirectRoute(
return {
page: () => Promise.resolve(RedirectComponentInstance),
middleware: StaticMiddlewareInstance,
renderers: []
}
renderers: [],
};
}

function shouldSkipDraft(pageModule: ComponentInstance, settings: AstroSettings): boolean {
Expand Down Expand Up @@ -143,13 +152,13 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
if (ssr) {
for (const [pageData, filePath] of eachPageDataFromEntryPoint(internals)) {
if (pageData.route.prerender) {
const ssrEntryURLPage =createEntryURL(filePath, outFolder);
const ssrEntryURLPage = createEntryURL(filePath, outFolder);
const ssrEntryPage: SinglePageBuiltModule = await import(ssrEntryURLPage.toString());

await generatePage(opts, internals, pageData, ssrEntryPage, builtPaths);
}
}
for(const pageData of eachRedirectPageData(internals)) {
for (const pageData of eachRedirectPageData(internals)) {
const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder);
await generatePage(opts, internals, pageData, entry, builtPaths);
}
Expand All @@ -160,7 +169,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn

await generatePage(opts, internals, pageData, ssrEntryPage, builtPaths);
}
for(const pageData of eachRedirectPageData(internals)) {
for (const pageData of eachRedirectPageData(internals)) {
const entry = await getEntryForRedirectRoute(pageData.route, internals, outFolder);
await generatePage(opts, internals, pageData, entry, builtPaths);
}
Expand Down Expand Up @@ -208,7 +217,7 @@ async function generatePage(
ssrEntry: SinglePageBuiltModule,
builtPaths: Set<string>
) {
if(routeIsRedirect(pageData.route) &&!opts.settings.config.experimental.redirects) {
if (routeIsRedirect(pageData.route) && !opts.settings.config.experimental.redirects) {
throw new Error(`To use redirects first set experimental.redirects to \`true\``);
}

Expand Down Expand Up @@ -578,17 +587,17 @@ async function generatePath(
throw err;
}

if(response.status >= 300 && response.status < 400) {
if (response.status >= 300 && response.status < 400) {
// If redirects is set to false, don't output the HTML
if(!opts.settings.config.build.redirects) {
if (!opts.settings.config.build.redirects) {
return;
}
const location = getRedirectLocationOrThrow(response.headers);
body = `<!doctype html>
<title>Redirecting to: ${location}</title>
<meta http-equiv="refresh" content="0;url=${location}" />`;
// A dynamic redirect, set the location so that integrations know about it.
if(pageData.route.type !== 'redirect') {
if (pageData.route.type !== 'redirect') {
pageData.route.redirect = location;
}
} else {
Expand Down
10 changes: 7 additions & 3 deletions packages/astro/src/core/build/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import type { SSRResult } from '../../@types/astro';
import type { PageOptions } from '../../vite-plugin-astro/types';
import { prependForwardSlash, removeFileExtension } from '../path.js';
import { viteID } from '../util.js';
import { ASTRO_PAGE_EXTENSION_POST_PATTERN, ASTRO_PAGE_MODULE_ID, getVirtualModulePageIdFromPath } from './plugins/plugin-pages.js';
import {
ASTRO_PAGE_EXTENSION_POST_PATTERN,
ASTRO_PAGE_MODULE_ID,
getVirtualModulePageIdFromPath,
} from './plugins/plugin-pages.js';
import type { PageBuildData, StylesheetAsset, ViteID } from './types';

export interface BuildInternals {
Expand Down Expand Up @@ -218,8 +222,8 @@ export function* eachPageData(internals: BuildInternals) {
}

export function* eachRedirectPageData(internals: BuildInternals) {
for(const pageData of eachPageData(internals)) {
if(pageData.route.type === 'redirect') {
for (const pageData of eachPageData(internals)) {
if (pageData.route.type === 'redirect') {
yield pageData;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): V
const inputs: Set<string> = new Set();

for (const [path, pageData] of Object.entries(opts.allPages)) {
if(routeIsRedirect(pageData.route)) {
if (routeIsRedirect(pageData.route)) {
continue;
}
inputs.add(getVirtualModulePageNameFromPath(path));
Expand Down
Loading

0 comments on commit 17eb3f3

Please sign in to comment.