From 919bbe4a89287b4c7bb16045bb537dd219fff132 Mon Sep 17 00:00:00 2001 From: Arsh Date: Wed, 24 Jan 2024 15:42:42 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/core/errors/errors-data.ts | 3 +- packages/astro/src/i18n/index.ts | 12 ++-- packages/astro/src/i18n/middleware.ts | 5 +- packages/astro/src/i18n/vite-plugin-i18n.ts | 26 ++++++-- packages/astro/src/virtual-modules/i18n.ts | 63 ++++++++++++++++--- 5 files changed, 84 insertions(+), 25 deletions(-) diff --git a/packages/astro/src/core/errors/errors-data.ts b/packages/astro/src/core/errors/errors-data.ts index 63d7ef6311..74bd297702 100644 --- a/packages/astro/src/core/errors/errors-data.ts +++ b/packages/astro/src/core/errors/errors-data.ts @@ -1042,11 +1042,10 @@ export const UnhandledRejection = { export const i18nNotEnabled = { name: 'i18nNotEnabled', title: 'i18n Not Enabled', - message: "The `astro:i18n` module can not be used without enabling i18n in your Astro config.", + message: 'The `astro:i18n` module can not be used without enabling i18n in your Astro config.', hint: 'See https://docs.astro.build/en/guides/internationalization for a guide on setting up i18n.', } satisfies ErrorData; - /** * @docs * @kind heading diff --git a/packages/astro/src/i18n/index.ts b/packages/astro/src/i18n/index.ts index 16df08b1c0..4b882b7829 100644 --- a/packages/astro/src/i18n/index.ts +++ b/packages/astro/src/i18n/index.ts @@ -91,7 +91,7 @@ interface GetLocalesRelativeUrlList extends GetLocaleOptions { format: AstroConfig['build']['format']; routing?: RoutingStrategies; defaultLocale: string; -}; +} export function getLocaleRelativeUrlList({ base, @@ -124,7 +124,7 @@ export function getLocaleRelativeUrlList({ } interface GetLocalesAbsoluteUrlList extends GetLocalesRelativeUrlList { - site?: string + site?: string; } export function getLocaleAbsoluteUrlList({ site, ...rest }: GetLocalesAbsoluteUrlList) { @@ -245,10 +245,10 @@ function peekCodePathToUse(locales: Locales, locale: string): undefined | string class Unreachable extends Error { constructor() { super( - "Astro encountered an unexpected line of code.\n" + - "In most cases, this is not your fault, but a bug in astro code.\n" + - "If there isn't one already, please create an issue.\n" + - "https://astro.build/issues" + 'Astro encountered an unexpected line of code.\n' + + 'In most cases, this is not your fault, but a bug in astro code.\n' + + "If there isn't one already, please create an issue.\n" + + 'https://astro.build/issues' ); } } diff --git a/packages/astro/src/i18n/middleware.ts b/packages/astro/src/i18n/middleware.ts index 98141e1fd9..1298dcac81 100644 --- a/packages/astro/src/i18n/middleware.ts +++ b/packages/astro/src/i18n/middleware.ts @@ -35,10 +35,7 @@ export function createI18nMiddleware( return async (context, next) => { const routeData: RouteData | undefined = Reflect.get(context.request, routeDataSymbol); // If the route we're processing is not a page, then we ignore it - if ( - routeData?.type !== 'page' && - routeData?.type !== 'fallback' - ) { + if (routeData?.type !== 'page' && routeData?.type !== 'fallback') { return await next(); } diff --git a/packages/astro/src/i18n/vite-plugin-i18n.ts b/packages/astro/src/i18n/vite-plugin-i18n.ts index 2d295198b0..856ce46a74 100644 --- a/packages/astro/src/i18n/vite-plugin-i18n.ts +++ b/packages/astro/src/i18n/vite-plugin-i18n.ts @@ -11,26 +11,44 @@ type AstroInternationalization = { settings: AstroSettings; }; -export interface I18nInternalConfig extends Pick, NonNullable, Pick {} +export interface I18nInternalConfig + extends Pick, + NonNullable, + Pick {} export default function astroInternationalization({ settings, }: AstroInternationalization): vite.Plugin { - const { base, build: { format }, i18n, site, trailingSlash } = settings.config; + const { + base, + build: { format }, + i18n, + site, + trailingSlash, + } = settings.config; return { name: 'astro:i18n', enforce: 'pre', async resolveId(id) { if (id === virtualModuleId) { if (i18n === undefined) throw new AstroError(AstroErrorData.i18nNotEnabled); - return this.resolve("astro/virtual-modules/i18n.js"); + return this.resolve('astro/virtual-modules/i18n.js'); } if (id === configId) return resolvedConfigId; }, load(id) { if (id === resolvedConfigId) { const { defaultLocale, locales, routing, fallback } = i18n!; - const config: I18nInternalConfig = { base, format, site, trailingSlash, defaultLocale, locales, routing, fallback }; + const config: I18nInternalConfig = { + base, + format, + site, + trailingSlash, + defaultLocale, + locales, + routing, + fallback, + }; return `export default ${JSON.stringify(config)};`; } }, diff --git a/packages/astro/src/virtual-modules/i18n.ts b/packages/astro/src/virtual-modules/i18n.ts index 254a4ab314..d9d4704311 100644 --- a/packages/astro/src/virtual-modules/i18n.ts +++ b/packages/astro/src/virtual-modules/i18n.ts @@ -1,9 +1,10 @@ -import * as I18nInternals from "../i18n/index.js"; -import type { I18nInternalConfig } from "../i18n/vite-plugin-i18n.js"; -export { normalizeTheLocale, toCodes, toPaths } from "../i18n/index.js"; +import * as I18nInternals from '../i18n/index.js'; +import type { I18nInternalConfig } from '../i18n/vite-plugin-i18n.js'; +export { normalizeTheLocale, toCodes, toPaths } from '../i18n/index.js'; // @ts-expect-error -import config from "astro-internal:i18n-config" -const { trailingSlash, format, site, defaultLocale, locales, routing } = config as I18nInternalConfig; +import config from 'astro-internal:i18n-config'; +const { trailingSlash, format, site, defaultLocale, locales, routing } = + config as I18nInternalConfig; const base = import.meta.env.BASE_URL; export type GetLocaleOptions = I18nInternals.GetLocaleOptions; @@ -29,7 +30,18 @@ export type GetLocaleOptions = I18nInternals.GetLocaleOptions; * getRelativeLocaleUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // /blog/es_US/getting-started * ``` */ -export const getRelativeLocaleUrl = (locale: string, path?: string, options?: GetLocaleOptions) => I18nInternals.getLocaleRelativeUrl({ locale, path, base, trailingSlash, format, defaultLocale, locales, routing, ...options }); +export const getRelativeLocaleUrl = (locale: string, path?: string, options?: GetLocaleOptions) => + I18nInternals.getLocaleRelativeUrl({ + locale, + path, + base, + trailingSlash, + format, + defaultLocale, + locales, + routing, + ...options, + }); /** * @@ -56,7 +68,19 @@ export const getRelativeLocaleUrl = (locale: string, path?: string, options?: Ge * getAbsoluteLocaleUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // https://example.com/blog/es_US/getting-started * ``` */ -export const getAbsoluteLocaleUrl = (locale: string, path = "", options?: GetLocaleOptions) => I18nInternals.getLocaleAbsoluteUrl({ locale, path, base, trailingSlash, format, site, defaultLocale, locales, routing, ...options }); +export const getAbsoluteLocaleUrl = (locale: string, path = '', options?: GetLocaleOptions) => + I18nInternals.getLocaleAbsoluteUrl({ + locale, + path, + base, + trailingSlash, + format, + site, + defaultLocale, + locales, + routing, + ...options, + }); /** * @param path An optional path to add after the `locale`. @@ -64,7 +88,17 @@ export const getAbsoluteLocaleUrl = (locale: string, path = "", options?: GetLoc * * Works like `getRelativeLocaleUrl` but it emits the relative URLs for ALL locales: */ -export const getRelativeLocaleUrlList = (path?: string, options?: GetLocaleOptions) => I18nInternals.getLocaleRelativeUrlList({ base, path, trailingSlash, format, defaultLocale, locales, routing, ...options }); +export const getRelativeLocaleUrlList = (path?: string, options?: GetLocaleOptions) => + I18nInternals.getLocaleRelativeUrlList({ + base, + path, + trailingSlash, + format, + defaultLocale, + locales, + routing, + ...options, + }); /** * @param path An optional path to add after the `locale`. @@ -72,7 +106,18 @@ export const getRelativeLocaleUrlList = (path?: string, options?: GetLocaleOptio * * Works like `getAbsoluteLocaleUrl` but it emits the absolute URLs for ALL locales: */ -export const getAbsoluteLocaleUrlList = (path?: string, options?: GetLocaleOptions) => I18nInternals.getLocaleAbsoluteUrlList({ site, base, path, trailingSlash, format, defaultLocale, locales, routing, ...options }); +export const getAbsoluteLocaleUrlList = (path?: string, options?: GetLocaleOptions) => + I18nInternals.getLocaleAbsoluteUrlList({ + site, + base, + path, + trailingSlash, + format, + defaultLocale, + locales, + routing, + ...options, + }); /** * A function that return the `path` associated to a locale (defined as code). It's particularly useful in case you decide