Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored and astrobot-houston committed Aug 28, 2024
1 parent cb356a5 commit cfbf428
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 64 deletions.
6 changes: 3 additions & 3 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1678,14 +1678,14 @@ export interface AstroUserConfig {
* @description
*
* When [`i18n.fallback`](#i18nfallback) is configured to avoid showing a 404 page for missing page routes, this option controls whether to [redirect](https://docs.astro.build/en/guides/routing/#redirects) to the fallback page, or to [rewrite](https://docs.astro.build/en/guides/routing/#rewrites) the fallback page's content in place.
*
*
* By default, Astro's i18n routing creates pages that redirect your visitors to a new destination based on your fallback configuration. The browser will refresh and show the destination address in the URL bar.
*
* When `i18n.routing.fallback: "rewrite"` is configured, Astro will create pages that render the contents of the fallback page on the original, requested URL.
*
* With the following configuration, if you have the file `src/pages/en/about.astro` but not `src/pages/fr/about.astro`, the `astro build` command will generate `dist/fr/about.html` with the same content as the `dist/en/index.html` page.
* Your site visitor will see the English version of the page at `https://example.com/fr/about/` and will not be redirected.
*
*
* ```js
* //astro.config.mjs
* export default defineConfig({
Expand All @@ -1703,7 +1703,7 @@ export interface AstroUserConfig {
* })
* ```
*/
fallbackType: "redirect" | "rewrite"
fallbackType: 'redirect' | 'rewrite';

/**
* @name i18n.routing.strategy
Expand Down
11 changes: 4 additions & 7 deletions packages/astro/src/container/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
SSRElement,
SSRResult,
} from '../@types/astro.js';
import {type HeadElements, Pipeline, type TryRewriteResult} from '../core/base-pipeline.js';
import { type HeadElements, Pipeline, type TryRewriteResult } from '../core/base-pipeline.js';
import type { SinglePageBuiltModule } from '../core/build/types.js';
import {
createModuleScriptElement,
Expand Down Expand Up @@ -68,11 +68,8 @@ export class ContainerPipeline extends Pipeline {
return { links, styles, scripts };
}

async tryRewrite(
payload: RewritePayload,
request: Request,
): Promise<TryRewriteResult> {
const {newUrl,pathname,routeData} = findRouteToRewrite({
async tryRewrite(payload: RewritePayload, request: Request): Promise<TryRewriteResult> {
const { newUrl, pathname, routeData } = findRouteToRewrite({
payload,
request,
routes: this.manifest?.routes.map((r) => r.routeData),
Expand All @@ -82,7 +79,7 @@ export class ContainerPipeline extends Pipeline {
});

const componentInstance = await this.getComponentByRoute(routeData);
return {componentInstance, routeData, newUrl, pathname};
return { componentInstance, routeData, newUrl, pathname };
}

insertRoute(route: RouteData, componentInstance: ComponentInstance): void {
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/app/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
SSRElement,
SSRResult,
} from '../../@types/astro.js';
import {Pipeline, type TryRewriteResult} from '../base-pipeline.js';
import { Pipeline, type TryRewriteResult } from '../base-pipeline.js';
import type { SinglePageBuiltModule } from '../build/types.js';
import { RedirectSinglePageBuiltModule } from '../redirects/component.js';
import { createModuleScriptElement, createStylesheetElementSet } from '../render/ssr-element.js';
Expand Down Expand Up @@ -95,7 +95,7 @@ export class AppPipeline extends Pipeline {
request: Request,
_sourceRoute: RouteData,
): Promise<TryRewriteResult> {
const { newUrl,pathname,routeData} = findRouteToRewrite({
const { newUrl, pathname, routeData } = findRouteToRewrite({
payload,
request,
routes: this.manifest?.routes.map((r) => r.routeData),
Expand All @@ -105,7 +105,7 @@ export class AppPipeline extends Pipeline {
});

const componentInstance = await this.getComponentByRoute(routeData);
return {newUrl, pathname, componentInstance, routeData};
return { newUrl, pathname, componentInstance, routeData };
}

async getModuleForRoute(route: RouteData): Promise<SinglePageBuiltModule> {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export type SSRManifest = {

export type SSRManifestI18n = {
fallback: Record<string, string> | undefined;
fallbackType: "redirect" | "rewrite";
fallbackType: 'redirect' | 'rewrite';
strategy: RoutingStrategies;
locales: Locales;
defaultLocale: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/core/base-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ export abstract class Pipeline {
export interface HeadElements extends Pick<SSRResult, 'scripts' | 'styles' | 'links'> {}

export interface TryRewriteResult {
routeData: RouteData,
componentInstance: ComponentInstance,
newUrl: URL,
pathname: string
routeData: RouteData;
componentInstance: ComponentInstance;
newUrl: URL;
pathname: string;
}
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
removeLeadingForwardSlash,
removeTrailingForwardSlash,
} from '../../core/path.js';
import {toFallbackType, toRoutingStrategy} from '../../i18n/utils.js';
import { toFallbackType, toRoutingStrategy } from '../../i18n/utils.js';
import { runHookBuildGenerated } from '../../integrations/hooks.js';
import { getOutputDirectory } from '../../prerender/utils.js';
import type { SSRManifestI18n } from '../app/types.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
import { getOutputDirectory } from '../../prerender/utils.js';
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
import type { SSRManifest } from '../app/types.js';
import type { TryRewriteResult } from '../base-pipeline.js';
import { routeIsFallback, routeIsRedirect } from '../redirects/helpers.js';
import { RedirectSinglePageBuiltModule } from '../redirects/index.js';
import { Pipeline } from '../render/index.js';
Expand All @@ -26,7 +27,6 @@ import { RESOLVED_SPLIT_MODULE_ID } from './plugins/plugin-ssr.js';
import { getPagesFromVirtualModulePageName, getVirtualModulePageName } from './plugins/util.js';
import type { PageBuildData, SinglePageBuiltModule, StaticBuildOptions } from './types.js';
import { i18nHasFallback } from './util.js';
import type {TryRewriteResult} from "../base-pipeline.js";

/**
* The build pipeline is responsible to gather the files emitted by the SSR build and generate the pages by executing these files.
Expand Down Expand Up @@ -291,7 +291,7 @@ export class BuildPipeline extends Pipeline {
request: Request,
_sourceRoute: RouteData,
): Promise<TryRewriteResult> {
const { routeData, pathname, newUrl} = findRouteToRewrite({
const { routeData, pathname, newUrl } = findRouteToRewrite({
payload,
request,
routes: this.options.manifest.routes,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { OutputChunk } from 'rollup';
import type { Plugin as VitePlugin } from 'vite';
import { getAssetsPrefix } from '../../../assets/utils/getAssetsPrefix.js';
import { normalizeTheLocale } from '../../../i18n/index.js';
import {toFallbackType, toRoutingStrategy} from '../../../i18n/utils.js';
import { toFallbackType, toRoutingStrategy } from '../../../i18n/utils.js';
import { runHookBuildSsr } from '../../../integrations/hooks.js';
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../../vite-plugin-scripts/index.js';
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export const AstroConfigSchema = z.object({
.object({
prefixDefaultLocale: z.boolean().optional().default(false),
redirectToDefaultLocale: z.boolean().optional().default(true),
fallbackType: z.enum(["redirect", "rewrite"]).optional().default("redirect"),
fallbackType: z.enum(['redirect', 'rewrite']).optional().default('redirect'),
})
.refine(
({ prefixDefaultLocale, redirectToDefaultLocale }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/render-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class RenderContext {
if (payload) {
pipeline.logger.debug('router', 'Called rewriting to:', payload);
// we intentionally let the error bubble up
const { routeData, componentInstance: newComponent} = await pipeline.tryRewrite(
const { routeData, componentInstance: newComponent } = await pipeline.tryRewrite(
payload,
this.request,
this.originalRoute,
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/src/core/routing/rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ export function findRouteToRewrite({
if (foundRoute) {
return {
routeData: foundRoute,
newUrl,
pathname
newUrl,
pathname,
};
} else {
const custom404 = routes.find((route) => route.route === '/404');
if (custom404) {
return { routeData: custom404, newUrl, pathname };
} else {
return { routeData: DEFAULT_404_ROUTE, newUrl, pathname };
return { routeData: DEFAULT_404_ROUTE, newUrl, pathname };
}
}
}
6 changes: 3 additions & 3 deletions packages/astro/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export type MiddlewarePayload = {
defaultLocale: string;
domains: Record<string, string> | undefined;
fallback: Record<string, string> | undefined;
fallbackType: "redirect" | "rewrite";
fallbackType: 'redirect' | 'rewrite';
};

// NOTE: public function exported to the users via `astro:i18n` module
Expand Down Expand Up @@ -341,7 +341,7 @@ export function redirectToFallback({
defaultLocale,
strategy,
base,
fallbackType
fallbackType,
}: MiddlewarePayload) {
return async function (context: APIContext, response: Response): Promise<Response> {
if (response.status >= 300 && fallback) {
Expand Down Expand Up @@ -378,7 +378,7 @@ export function redirectToFallback({
newPathname = context.url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
}

if (fallbackType === "rewrite") {
if (fallbackType === 'rewrite') {
return await context.rewrite(newPathname);
} else {
return context.redirect(newPathname);
Expand Down
7 changes: 4 additions & 3 deletions packages/astro/src/i18n/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ export function toRoutingStrategy(
return strategy;
}

export function toFallbackType(routing: NonNullable<AstroConfig['i18n']>['routing']): "redirect" | "rewrite" {
export function toFallbackType(
routing: NonNullable<AstroConfig['i18n']>['routing'],
): 'redirect' | 'rewrite' {
if (routing === 'manual') {
return 'rewrite';
}
return routing.fallbackType;

}
}
10 changes: 5 additions & 5 deletions packages/astro/src/virtual-modules/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IncorrectStrategyForI18n } from '../core/errors/errors-data.js';
import { AstroError } from '../core/errors/index.js';
import * as I18nInternals from '../i18n/index.js';
import type { RedirectToFallback } from '../i18n/index.js';
import {toFallbackType, toRoutingStrategy} from '../i18n/utils.js';
import { toFallbackType, toRoutingStrategy } from '../i18n/utils.js';
import type { I18nInternalConfig } from '../i18n/vite-plugin-i18n.js';

export { normalizeTheLocale, toCodes, toPaths } from '../i18n/index.js';
Expand Down Expand Up @@ -268,7 +268,7 @@ if (i18n?.routing === 'manual') {
strategy,
domains,
fallback,
fallbackType
fallbackType,
});
} else {
redirectToDefaultLocale = noop('redirectToDefaultLocale');
Expand Down Expand Up @@ -297,7 +297,7 @@ if (i18n?.routing === 'manual') {
strategy,
domains,
fallback,
fallbackType
fallbackType,
});
} else {
notFound = noop('notFound');
Expand Down Expand Up @@ -334,7 +334,7 @@ if (i18n?.routing === 'manual') {
strategy,
domains,
fallback,
fallbackType
fallbackType,
});
} else {
redirectToFallback = noop('useFallback');
Expand Down Expand Up @@ -384,7 +384,7 @@ if (i18n?.routing === 'manual') {
fallback: undefined,
strategy,
domainLookupTable: {},
fallbackType
fallbackType,
};
return I18nInternals.createMiddleware(manifest, base, trailingSlash, format);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Logger } from '../core/logger/core.js';
import { createViteLoader } from '../core/module-loader/index.js';
import { injectDefaultRoutes } from '../core/routing/default.js';
import { createRouteManifest } from '../core/routing/index.js';
import {toFallbackType, toRoutingStrategy} from '../i18n/utils.js';
import { toFallbackType, toRoutingStrategy } from '../i18n/utils.js';
import { baseMiddleware } from './base.js';
import { createController } from './controller.js';
import { recordServerError } from './error.js';
Expand Down
12 changes: 5 additions & 7 deletions packages/astro/test/i18n-routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1930,8 +1930,6 @@ describe('SSR fallback from missing locale index to default locale index', () =>
});
});



describe('Fallback rewrite dev server', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
Expand All @@ -1949,14 +1947,14 @@ describe('Fallback rewrite dev server', () => {
fallback: {
fr: 'en',
},
fallbackType: "rewrite"
fallbackType: 'rewrite',
},
});
devServer = await fixture.startDevServer();
});
after(async () => {
devServer.stop()
})
devServer.stop();
});

it('should correctly rewrite to en', async () => {
const html = await fixture.fetch('/fr').then((res) => res.text());
Expand All @@ -1977,7 +1975,7 @@ describe('Fallback rewrite SSG', () => {
locales: ['en', 'fr'],
routing: {
prefixDefaultLocale: false,
fallbackType: "rewrite"
fallbackType: 'rewrite',
},
fallback: {
fr: 'en',
Expand Down Expand Up @@ -2015,7 +2013,7 @@ describe('Fallback rewrite SSR', () => {
locales: ['en', 'fr'],
routing: {
prefixDefaultLocale: false,
fallbackType: "rewrite"
fallbackType: 'rewrite',
},
fallback: {
fr: 'en',
Expand Down
6 changes: 3 additions & 3 deletions packages/db/src/core/cli/migration-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export function getProductionCurrentSnapshot(options: {

async function getDbCurrentSnapshot(
appToken: string,
remoteUrl: string
remoteUrl: string,
): Promise<DBSnapshot | undefined> {
const client = createRemoteDatabaseClient({
dbType: 'libsql',
Expand All @@ -447,7 +447,7 @@ async function getDbCurrentSnapshot(
try {
const res = await client.get<{ snapshot: string }>(
// Latest snapshot
sql`select snapshot from _astro_db_snapshot order by id desc limit 1;`
sql`select snapshot from _astro_db_snapshot order by id desc limit 1;`,
);

return JSON.parse(res.snapshot);
Expand All @@ -464,7 +464,7 @@ async function getDbCurrentSnapshot(

async function getStudioCurrentSnapshot(
appToken: string,
remoteUrl: string
remoteUrl: string,
): Promise<DBSnapshot | undefined> {
const url = new URL('/db/schema', remoteUrl);

Expand Down
7 changes: 6 additions & 1 deletion packages/db/src/core/integration/vite-plugin-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { DB_PATH, RUNTIME_IMPORT, RUNTIME_VIRTUAL_IMPORT, VIRTUAL_MODULE_ID } fr
import { getResolvedFileUrl } from '../load-file.js';
import { SEED_DEV_FILE_NAME, getCreateIndexQueries, getCreateTableQuery } from '../queries.js';
import type { DBTables } from '../types.js';
import { type VitePlugin, getAstroEnv, getDbDirectoryUrl, getRemoteDatabaseInfo } from '../utils.js';
import {
type VitePlugin,
getAstroEnv,
getDbDirectoryUrl,
getRemoteDatabaseInfo,
} from '../utils.js';

export const resolved = {
module: '\0' + VIRTUAL_MODULE_ID,
Expand Down
20 changes: 11 additions & 9 deletions packages/db/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ export function getRemoteDatabaseInfo(): RemoteDatabaseInfo {
const astroEnv = getAstroEnv();
const studioEnv = getAstroStudioEnv();

if (studioEnv.ASTRO_STUDIO_REMOTE_DB_URL) return {
type: 'studio',
url: studioEnv.ASTRO_STUDIO_REMOTE_DB_URL,
};

if (astroEnv.ASTRO_DB_REMOTE_URL) return {
type: 'libsql',
url: astroEnv.ASTRO_DB_REMOTE_URL,
};
if (studioEnv.ASTRO_STUDIO_REMOTE_DB_URL)
return {
type: 'studio',
url: studioEnv.ASTRO_STUDIO_REMOTE_DB_URL,
};

if (astroEnv.ASTRO_DB_REMOTE_URL)
return {
type: 'libsql',
url: astroEnv.ASTRO_DB_REMOTE_URL,
};

return {
type: 'studio',
Expand Down
Loading

0 comments on commit cfbf428

Please sign in to comment.