Skip to content

Commit

Permalink
fix(types): expose types to runtime with alias (#3231)
Browse files Browse the repository at this point in the history
Co-authored-by: userquin <[email protected]>
  • Loading branch information
BobbieGoede and userquin authored Nov 14, 2024
1 parent 543e468 commit bc8a25f
Show file tree
Hide file tree
Showing 15 changed files with 555 additions and 550 deletions.
6 changes: 1 addition & 5 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
'src/module',
// Chunking
'src/types'
],
entries: ['src/module'],
externals: ['node:fs', 'node:url', 'webpack', '@babel/parser', 'unplugin-vue-router', 'unplugin-vue-router/options']
})
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['#internal-i18n-types'] = resolver.resolve('./types')
nuxt.options.build.transpile.push('#i18n')
nuxt.options.build.transpile.push('#internal-i18n-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 '#internal-i18n-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 '#internal-i18n-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 '#internal-i18n-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 '#internal-i18n-types'
import type { CoreContext } from '@intlify/h3'

type MessageLoaderFunction<T = DefineLocaleMessage> = (locale: Locale) => Promise<LocaleMessages<T>>
Expand Down
4 changes: 2 additions & 2 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 '#internal-i18n-types'
import type { I18nPublicRuntimeConfig } from '#internal-i18n-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
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 '#internal-i18n-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 '#internal-i18n-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 '#internal-i18n-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 '#internal-i18n-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 '#internal-i18n-types'
import type { Locale } from 'vue-i18n'

export const inBrowser = typeof window !== 'undefined'
Expand Down
Loading

0 comments on commit bc8a25f

Please sign in to comment.