From cfbf428643a04f7630e45c59e6d70d77de6673f1 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 28 Aug 2024 11:21:37 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/@types/astro.ts | 6 +++--- packages/astro/src/container/pipeline.ts | 11 ++++------ packages/astro/src/core/app/pipeline.ts | 6 +++--- packages/astro/src/core/app/types.ts | 2 +- packages/astro/src/core/base-pipeline.ts | 8 ++++---- packages/astro/src/core/build/generate.ts | 2 +- packages/astro/src/core/build/pipeline.ts | 4 ++-- .../src/core/build/plugins/plugin-manifest.ts | 2 +- packages/astro/src/core/config/schema.ts | 2 +- packages/astro/src/core/render-context.ts | 2 +- packages/astro/src/core/routing/rewrite.ts | 6 +++--- packages/astro/src/i18n/index.ts | 6 +++--- packages/astro/src/i18n/utils.ts | 7 ++++--- packages/astro/src/virtual-modules/i18n.ts | 10 +++++----- .../src/vite-plugin-astro-server/plugin.ts | 2 +- packages/astro/test/i18n-routing.test.js | 12 +++++------ packages/db/src/core/cli/migration-queries.ts | 6 +++--- .../db/src/core/integration/vite-plugin-db.ts | 7 ++++++- packages/db/src/core/utils.ts | 20 ++++++++++--------- packages/db/src/runtime/db-client.ts | 10 +++++----- 20 files changed, 67 insertions(+), 64 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index a366444b9639..d4f5d9b6beff 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -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({ @@ -1703,7 +1703,7 @@ export interface AstroUserConfig { * }) * ``` */ - fallbackType: "redirect" | "rewrite" + fallbackType: 'redirect' | 'rewrite'; /** * @name i18n.routing.strategy diff --git a/packages/astro/src/container/pipeline.ts b/packages/astro/src/container/pipeline.ts index 481994aae45c..6a2af65ce384 100644 --- a/packages/astro/src/container/pipeline.ts +++ b/packages/astro/src/container/pipeline.ts @@ -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, @@ -68,11 +68,8 @@ export class ContainerPipeline extends Pipeline { return { links, styles, scripts }; } - async tryRewrite( - payload: RewritePayload, - request: Request, - ): Promise { - const {newUrl,pathname,routeData} = findRouteToRewrite({ + async tryRewrite(payload: RewritePayload, request: Request): Promise { + const { newUrl, pathname, routeData } = findRouteToRewrite({ payload, request, routes: this.manifest?.routes.map((r) => r.routeData), @@ -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 { diff --git a/packages/astro/src/core/app/pipeline.ts b/packages/astro/src/core/app/pipeline.ts index 0b6de4f6cdd9..5ae5b775dde0 100644 --- a/packages/astro/src/core/app/pipeline.ts +++ b/packages/astro/src/core/app/pipeline.ts @@ -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'; @@ -95,7 +95,7 @@ export class AppPipeline extends Pipeline { request: Request, _sourceRoute: RouteData, ): Promise { - const { newUrl,pathname,routeData} = findRouteToRewrite({ + const { newUrl, pathname, routeData } = findRouteToRewrite({ payload, request, routes: this.manifest?.routes.map((r) => r.routeData), @@ -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 { diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 9d5bf982e1c4..6a00ec0a7993 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -76,7 +76,7 @@ export type SSRManifest = { export type SSRManifestI18n = { fallback: Record | undefined; - fallbackType: "redirect" | "rewrite"; + fallbackType: 'redirect' | 'rewrite'; strategy: RoutingStrategies; locales: Locales; defaultLocale: string; diff --git a/packages/astro/src/core/base-pipeline.ts b/packages/astro/src/core/base-pipeline.ts index 0d4dc78c24d5..2281c562dc30 100644 --- a/packages/astro/src/core/base-pipeline.ts +++ b/packages/astro/src/core/base-pipeline.ts @@ -108,8 +108,8 @@ export abstract class Pipeline { export interface HeadElements extends Pick {} export interface TryRewriteResult { - routeData: RouteData, - componentInstance: ComponentInstance, - newUrl: URL, - pathname: string + routeData: RouteData; + componentInstance: ComponentInstance; + newUrl: URL; + pathname: string; } diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index c4dd13399d1a..b24fb17c416c 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -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'; diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index ae1cea799ccb..414144359a8c 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -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'; @@ -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. @@ -291,7 +291,7 @@ export class BuildPipeline extends Pipeline { request: Request, _sourceRoute: RouteData, ): Promise { - const { routeData, pathname, newUrl} = findRouteToRewrite({ + const { routeData, pathname, newUrl } = findRouteToRewrite({ payload, request, routes: this.options.manifest.routes, diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts index 9ffc615f62d9..e540ab7ca75b 100644 --- a/packages/astro/src/core/build/plugins/plugin-manifest.ts +++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts @@ -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 { diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 9c9bfd03aa03..8634e0c0f0ea 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -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 }) => { diff --git a/packages/astro/src/core/render-context.ts b/packages/astro/src/core/render-context.ts index d7400afff1af..6dfa10137556 100644 --- a/packages/astro/src/core/render-context.ts +++ b/packages/astro/src/core/render-context.ts @@ -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, diff --git a/packages/astro/src/core/routing/rewrite.ts b/packages/astro/src/core/routing/rewrite.ts index 43bd3a2ac95d..d50434f22096 100644 --- a/packages/astro/src/core/routing/rewrite.ts +++ b/packages/astro/src/core/routing/rewrite.ts @@ -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 }; } } } diff --git a/packages/astro/src/i18n/index.ts b/packages/astro/src/i18n/index.ts index d00345d55527..2e8da37c6a3e 100644 --- a/packages/astro/src/i18n/index.ts +++ b/packages/astro/src/i18n/index.ts @@ -282,7 +282,7 @@ export type MiddlewarePayload = { defaultLocale: string; domains: Record | undefined; fallback: Record | undefined; - fallbackType: "redirect" | "rewrite"; + fallbackType: 'redirect' | 'rewrite'; }; // NOTE: public function exported to the users via `astro:i18n` module @@ -341,7 +341,7 @@ export function redirectToFallback({ defaultLocale, strategy, base, - fallbackType + fallbackType, }: MiddlewarePayload) { return async function (context: APIContext, response: Response): Promise { if (response.status >= 300 && fallback) { @@ -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); diff --git a/packages/astro/src/i18n/utils.ts b/packages/astro/src/i18n/utils.ts index ed256b7ab06b..47addeacbae6 100644 --- a/packages/astro/src/i18n/utils.ts +++ b/packages/astro/src/i18n/utils.ts @@ -216,10 +216,11 @@ export function toRoutingStrategy( return strategy; } -export function toFallbackType(routing: NonNullable['routing']): "redirect" | "rewrite" { +export function toFallbackType( + routing: NonNullable['routing'], +): 'redirect' | 'rewrite' { if (routing === 'manual') { return 'rewrite'; } return routing.fallbackType; - -} +} diff --git a/packages/astro/src/virtual-modules/i18n.ts b/packages/astro/src/virtual-modules/i18n.ts index 114e76bb42fd..b8829c716551 100644 --- a/packages/astro/src/virtual-modules/i18n.ts +++ b/packages/astro/src/virtual-modules/i18n.ts @@ -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'; @@ -268,7 +268,7 @@ if (i18n?.routing === 'manual') { strategy, domains, fallback, - fallbackType + fallbackType, }); } else { redirectToDefaultLocale = noop('redirectToDefaultLocale'); @@ -297,7 +297,7 @@ if (i18n?.routing === 'manual') { strategy, domains, fallback, - fallbackType + fallbackType, }); } else { notFound = noop('notFound'); @@ -334,7 +334,7 @@ if (i18n?.routing === 'manual') { strategy, domains, fallback, - fallbackType + fallbackType, }); } else { redirectToFallback = noop('useFallback'); @@ -384,7 +384,7 @@ if (i18n?.routing === 'manual') { fallback: undefined, strategy, domainLookupTable: {}, - fallbackType + fallbackType, }; return I18nInternals.createMiddleware(manifest, base, trailingSlash, format); }; diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index f38c84782118..19ceed811727 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -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'; diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index 06329aa329f1..ddb31762f490 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -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; @@ -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()); @@ -1977,7 +1975,7 @@ describe('Fallback rewrite SSG', () => { locales: ['en', 'fr'], routing: { prefixDefaultLocale: false, - fallbackType: "rewrite" + fallbackType: 'rewrite', }, fallback: { fr: 'en', @@ -2015,7 +2013,7 @@ describe('Fallback rewrite SSR', () => { locales: ['en', 'fr'], routing: { prefixDefaultLocale: false, - fallbackType: "rewrite" + fallbackType: 'rewrite', }, fallback: { fr: 'en', diff --git a/packages/db/src/core/cli/migration-queries.ts b/packages/db/src/core/cli/migration-queries.ts index 1a16001dff02..5c4a23557df2 100644 --- a/packages/db/src/core/cli/migration-queries.ts +++ b/packages/db/src/core/cli/migration-queries.ts @@ -436,7 +436,7 @@ export function getProductionCurrentSnapshot(options: { async function getDbCurrentSnapshot( appToken: string, - remoteUrl: string + remoteUrl: string, ): Promise { const client = createRemoteDatabaseClient({ dbType: 'libsql', @@ -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); @@ -464,7 +464,7 @@ async function getDbCurrentSnapshot( async function getStudioCurrentSnapshot( appToken: string, - remoteUrl: string + remoteUrl: string, ): Promise { const url = new URL('/db/schema', remoteUrl); diff --git a/packages/db/src/core/integration/vite-plugin-db.ts b/packages/db/src/core/integration/vite-plugin-db.ts index c8e273151fab..c00a99f3b4ff 100644 --- a/packages/db/src/core/integration/vite-plugin-db.ts +++ b/packages/db/src/core/integration/vite-plugin-db.ts @@ -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, diff --git a/packages/db/src/core/utils.ts b/packages/db/src/core/utils.ts index 9797992b864f..cf3e375354cc 100644 --- a/packages/db/src/core/utils.ts +++ b/packages/db/src/core/utils.ts @@ -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', diff --git a/packages/db/src/runtime/db-client.ts b/packages/db/src/runtime/db-client.ts index 08a68e2e830b..d667ecbb2532 100644 --- a/packages/db/src/runtime/db-client.ts +++ b/packages/db/src/runtime/db-client.ts @@ -43,10 +43,10 @@ const remoteResultSchema = z.object({ }); type RemoteDbClientOptions = { - dbType: 'studio' | 'libsql', - appToken: string, - remoteUrl: string | URL, -} + dbType: 'studio' | 'libsql'; + appToken: string; + remoteUrl: string | URL; +}; export function createRemoteDatabaseClient(options: RemoteDbClientOptions) { const remoteUrl = new URL(options.remoteUrl); @@ -65,7 +65,7 @@ function createRemoteLibSQLClient(appToken: string, remoteDbURL: URL) { authToken: appToken, url: remoteDbURL.protocol === 'memory:' ? ':memory:' : remoteDbURL.toString(), }); - return drizzleLibsql(client); + return drizzleLibsql(client); } function createStudioDatabaseClient(appToken: string, remoteDbURL: URL) {