Skip to content

Commit

Permalink
fix: alias shared types for runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Nov 14, 2024
1 parent d0d2b4e commit d79a9c2
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 27 deletions.
20 changes: 10 additions & 10 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ export const UTILS_PKG = '@intlify/utils'
export const UTILS_H3_PKG = '@intlify/utils/h3'
export const UFO_PKG = 'ufo'
export const IS_HTTPS_PKG = 'is-https'
import {
STRATEGIES,
STRATEGY_PREFIX,
STRATEGY_PREFIX_EXCEPT_DEFAULT,
STRATEGY_PREFIX_AND_DEFAULT,
STRATEGY_NO_PREFIX
} from './runtime/shared-types'

// Options
export { STRATEGIES, STRATEGY_PREFIX, STRATEGY_PREFIX_EXCEPT_DEFAULT, STRATEGY_PREFIX_AND_DEFAULT, STRATEGY_NO_PREFIX }
export const STRATEGY_PREFIX = 'prefix'
export const STRATEGY_PREFIX_EXCEPT_DEFAULT = 'prefix_except_default'
export const STRATEGY_PREFIX_AND_DEFAULT = 'prefix_and_default'
export const STRATEGY_NO_PREFIX = 'no_prefix'
export const STRATEGIES = {
PREFIX: STRATEGY_PREFIX,
PREFIX_EXCEPT_DEFAULT: STRATEGY_PREFIX_EXCEPT_DEFAULT,
PREFIX_AND_DEFAULT: STRATEGY_PREFIX_AND_DEFAULT,
NO_PREFIX: STRATEGY_NO_PREFIX
} as const

export const DEFAULT_DYNAMIC_PARAMS_KEY = 'nuxtI18nInternal'
export const DEFAULT_COOKIE_KEY = 'i18n_redirected'
Expand Down
2 changes: 2 additions & 0 deletions src/prepare/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function prepareRuntime(ctx: I18nNuxtContext, nuxt: Nuxt) {

// for composables
nuxt.options.alias['#i18n'] = resolver.resolve('./runtime/composables/index')
nuxt.options.alias['#i18n-shared-types'] = resolver.resolve('./types')
nuxt.options.build.transpile.push('#i18n')
nuxt.options.build.transpile.push('#i18n-shared-types')
nuxt.options.build.transpile.push(VIRTUAL_NUXT_I18N_LOGGER)

const genTemplate = (isServer: boolean, lazy?: boolean) => {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getLocale, getLocales, getComposer } from '../compatibility'

import type { Ref } from 'vue'
import type { Locale } from 'vue-i18n'
import type { I18nHeadMetaInfo, I18nHeadOptions, LocaleObject, SeoAttributesOptions } from '../shared-types'
import type { I18nHeadMetaInfo, I18nHeadOptions, SeoAttributesOptions } from '#i18n-shared-types'
import type { RouteLocationAsRelativeI18n, RouteLocationResolvedI18n, RouteMapI18n } from 'vue-router'
import type { HeadParam } from '../utils'

Expand Down Expand Up @@ -392,7 +392,7 @@ export function useBrowserLocale(): string | null {
const headers = useRequestHeaders(['accept-language'])
return (
findBrowserLocale(
normalizedLocales as LocaleObject[],
normalizedLocales,
import.meta.client ? (navigator.languages as string[]) : parseAcceptLanguage(headers['accept-language'] || '')
) || null
)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import { initCommonComposableOptions, type CommonComposableOptions } from './uti
import { createLogger } from 'virtual:nuxt-i18n-logger'

import type { Locale } from 'vue-i18n'
import type { DetectBrowserLanguageOptions, LocaleObject } from './shared-types'
import type { DetectBrowserLanguageOptions, LocaleObject } from '#i18n-shared-types'
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded } from 'vue-router'
import type { CookieRef, NuxtApp } from 'nuxt/app'
import type { I18nPublicRuntimeConfig } from './shared-types'
import type { I18nPublicRuntimeConfig } from '#i18n-shared-types'

export function formatMessage(message: string) {
return NUXT_I18N_MODULE_ID + ' ' + message
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createLogger } from 'virtual:nuxt-i18n-logger'
import type { I18nOptions, Locale, FallbackLocale, LocaleMessages, DefineLocaleMessage } from 'vue-i18n'
import type { NuxtApp } from '#app'
import type { DeepRequired } from 'ts-essentials'
import type { VueI18nConfig, NuxtI18nOptions } from './shared-types'
import type { VueI18nConfig, NuxtI18nOptions } from '#i18n-shared-types'
import type { CoreContext } from '@intlify/h3'

type MessageLoaderFunction<T = DefineLocaleMessage> = (locale: Locale) => Promise<LocaleMessages<T>>
Expand Down
5 changes: 2 additions & 3 deletions src/runtime/plugins/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { createLogger } from 'virtual:nuxt-i18n-logger'
import type { NuxtI18nPluginInjections } from '../injections'
import type { Locale, I18nOptions } from 'vue-i18n'
import type { NuxtApp } from '#app'
import type { LocaleObject } from '../shared-types'
import type { I18nPublicRuntimeConfig } from '../shared-types'
import type { LocaleObject } from '#i18n-shared-types'
import type { I18nPublicRuntimeConfig } from '#i18n-shared-types'

// from https://github.com/nuxt/nuxt/blob/2466af53b0331cdb8b17c2c3b08675c5985deaf3/packages/nuxt/src/core/templates.ts#L152
type Decorate<T extends Record<string, unknown>> = { [K in keyof T as K extends string ? `$${K}` : never]: T[K] }
Expand Down Expand Up @@ -153,7 +153,6 @@ export default defineNuxtPlugin<NuxtI18nPluginInjections>({
const _localeCodes = ref<Locale[]>(localeCodes)
const _baseUrl = ref<string>('')

// @ts-expect-error type mismatch
composer.locales = computed(() => _locales.value)

Check failure on line 156 in src/runtime/plugins/i18n.ts

View workflow job for this annotation

GitHub Actions / Test on Node.js 18

Type 'ComputedRef<string[] | { [x: string]: any; code: string; name?: string | undefined; dir?: Directions | undefined; domain?: string | undefined; domains?: string[] | undefined; defaultForDomains?: string[] | undefined; file?: string | ... 1 more ... | undefined; files?: string[] | ... 1 more ... | undefined; isCatchal...' is not assignable to type 'ComputedRef<LocaleObject<string>[]>'.
composer.localeCodes = computed(() => _localeCodes.value)
composer.baseUrl = computed(() => _baseUrl.value)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/routing/compatibles/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getRouteBaseName, localeRoute, switchLocalePath } from './routing'
import { getComposer, getLocale, getLocales } from '../../compatibility'

import type { I18n } from 'vue-i18n'
import type { I18nHeadMetaInfo, MetaAttrs, LocaleObject, I18nHeadOptions } from '../../shared-types'
import type { I18nHeadMetaInfo, MetaAttrs, LocaleObject, I18nHeadOptions } from '#i18n-shared-types'
import type { CommonComposableOptions } from '../../utils'

/**
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/routing/compatibles/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { resolve, routeToObject } from './utils'
import { getLocaleRouteName, getRouteName } from '../utils'
import { extendPrefixable, extendSwitchLocalePathIntercepter, type CommonComposableOptions } from '../../utils'

import type { Strategies, PrefixableOptions } from '../../shared-types'
import type { Strategies, PrefixableOptions } from '#i18n-shared-types'
import type { Locale } from 'vue-i18n'
import type {
RouteLocation,
Expand All @@ -20,7 +20,7 @@ import type {
RouteLocationNormalizedLoaded,
RouteLocationNormalized
} from 'vue-router'
import type { I18nPublicRuntimeConfig } from '../../shared-types'
import type { I18nPublicRuntimeConfig } from '#i18n-shared-types'

const RESOLVED_PREFIXED = new Set<Strategies>(['prefix_and_default', 'prefix_except_default'])

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/routing/compatibles/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assign } from '@intlify/shared'

import type { Locale } from 'vue-i18n'
import type { RouteLocationNormalizedLoaded, RouteLocationPathRaw } from 'vue-router'
import type { Strategies } from '../../shared-types'
import type { Strategies } from '#i18n-shared-types'
import type { CommonComposableOptions } from '../../utils'

function split(str: string, index: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/routing/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isString, isSymbol, isFunction } from '@intlify/shared'

import type { LocaleObject, Strategies, BaseUrlResolveHandler } from '../shared-types'
import type { LocaleObject, Strategies, BaseUrlResolveHandler } from '#i18n-shared-types'
import type { Locale } from 'vue-i18n'

export const inBrowser = typeof window !== 'undefined'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NuxtApp } from '#app'
import type { ComputedRef } from 'vue'
import type { Directions, LocaleObject, Strategies } from './shared-types'
import type { Directions, LocaleObject, Strategies } from '#i18n-shared-types'
import type { Locale } from 'vue-i18n'

/**
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ import type { DetectLocaleContext } from './internal'
import type { HeadSafe } from '@unhead/vue'
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded } from 'vue-router'
import type { RuntimeConfig } from 'nuxt/schema'
import type { I18nPublicRuntimeConfig } from './shared-types'
import type { I18nPublicRuntimeConfig } from '#i18n-shared-types'
import type {
RootRedirectOptions,
PrefixableOptions,
SwitchLocalePathIntercepter,
BaseUrlResolveHandler,
Strategies,
LocaleObject
} from './shared-types'
} from '#i18n-shared-types'

/**
* Common options used internally by composable functions, these
Expand Down
Loading

0 comments on commit d79a9c2

Please sign in to comment.