Skip to content

Commit

Permalink
chore: update nuxt to 3.10.3 (#2610)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Feb 24, 2024
1 parent 1fefb6e commit 55037f0
Show file tree
Hide file tree
Showing 53 changed files with 3,388 additions and 3,570 deletions.
2 changes: 1 addition & 1 deletion app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provideGlobalCommands()
const route = useRoute()
if (process.server && !route.path.startsWith('/settings')) {
if (import.meta.server && !route.path.startsWith('/settings')) {
const url = useRequestURL()
useHead({
Expand Down
2 changes: 1 addition & 1 deletion components/aria/AriaAnnouncer.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import type { LocaleObject } from '@nuxtjs/i18n'
import type { AriaAnnounceType, AriaLive } from '~/composables/aria'
import type { LocaleObject } from '#i18n'
const router = useRouter()
const { t, locale, locales } = useI18n()
Expand Down
2 changes: 1 addition & 1 deletion components/common/CommonInputImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const previewImage = ref('')
const imageSrc = computed<string>(() => previewImage.value || defaultImage.value)
async function pickImage() {
if (process.server)
if (import.meta.server)
return
const image = await fileOpen({
description: 'Image',
Expand Down
2 changes: 1 addition & 1 deletion components/modal/ModalMediaPreviewCarousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const slider = ref()
const slide = ref()
const image = ref()
const reduceMotion = process.server ? ref(false) : useReducedMotion()
const reduceMotion = import.meta.server ? ref(false) : useReducedMotion()
const isInitialScrollDone = useTimeout(350)
const canAnimate = computed(() => isInitialScrollDone.value && !reduceMotion.value)
Expand Down
2 changes: 1 addition & 1 deletion components/settings/SettingsItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ useCommand({
@click="to ? $scrollToTop() : undefined"
>
<div
w-full flex w-fit px5 py3 md:gap2 gap4 items-center
w-full flex px5 py3 md:gap2 gap4 items-center
transition-250 group-hover:bg-active
group-focus-visible:ring="2 current"
>
Expand Down
2 changes: 1 addition & 1 deletion components/settings/SettingsLanguage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import type { ComputedRef } from 'vue'
import type { LocaleObject } from '#i18n'
import type { LocaleObject } from '@nuxtjs/i18n'
const userSettings = useUserSettings()
Expand Down
2 changes: 1 addition & 1 deletion components/status/StatusActionsMore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function deleteAndRedraft() {
}) !== 'confirm')
return
if (process.dev) {
if (import.meta.dev) {
// eslint-disable-next-line no-alert
const result = confirm('[DEV] Are you sure you want to delete and re-draft this post?')
if (!result)
Expand Down
5 changes: 2 additions & 3 deletions components/status/StatusPreviewGitHub.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const meta = computed(() => {
const avatar = `https://github.com/${user}.png?size=256`
const author = props.card.authorName
const info = {
return {
type,
user,
titleUrl: `https://github.com/${user}${repo ? `/${repo}` : ''}`,
Expand All @@ -78,8 +78,7 @@ const meta = computed(() => {
user: author,
}
: undefined,
}
return info
} satisfies Meta
})
</script>

Expand Down
5 changes: 2 additions & 3 deletions components/status/StatusPreviewStackBlitz.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ const meta = computed(() => {
const lines = meta?.[2]
const code = meta?.[3].split('\n').slice(0, maxLines).join('\n')
const project = props.card.title?.replace(' - StackBlitz', '')
const info = {
return {
file,
lines,
code,
project,
}
return info
} satisfies Meta
})
const vnodeCode = computed(() => {
Expand Down
2 changes: 1 addition & 1 deletion components/tiptap/TiptapEmojiList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { items, command } = defineProps<{
}>()
const emojis = computed(() => {
if (process.server)
if (import.meta.server)
return []
return items.map((item: CustomEmoji | Emoji) => {
Expand Down
2 changes: 1 addition & 1 deletion composables/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cache = new LRUCache<string, any>({
max: 1000,
})

if (process.dev && process.client)
if (import.meta.dev && import.meta.client)
// eslint-disable-next-line no-console
console.log({ cache })

Expand Down
2 changes: 1 addition & 1 deletion composables/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ComputedRef } from 'vue'
import { defineStore } from 'pinia'
import Fuse from 'fuse.js'
import type { LocaleObject } from '#i18n'
import type { LocaleObject } from '@nuxtjs/i18n'
import type { SearchResult } from '~/composables/masto/search'

// @unocss-include
Expand Down
4 changes: 2 additions & 2 deletions composables/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function openPublishDialog(draftKey = 'dialog', draft?: Draft, over
if (overwrite && !isEmptyDraft(currentUserDrafts.value[draftKey])) {
// TODO overwrite warning
// TODO don't overwrite, have a draft list
if (process.dev) {
if (import.meta.dev) {
// eslint-disable-next-line no-alert
const result = confirm('[DEV] Are you sure you overwrite draft content?')
if (!result)
Expand Down Expand Up @@ -89,7 +89,7 @@ function restoreMediaPreviewFromState() {
isMediaPreviewOpen.value = history.state?.mediaPreview ?? false
}

if (process.client) {
if (import.meta.client) {
window.addEventListener('popstate', restoreMediaPreviewFromState)

restoreMediaPreviewFromState()
Expand Down
2 changes: 1 addition & 1 deletion composables/emojis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getDefault(): CustomEmojisInfo {
}
}

export const currentCustomEmojis = process.server
export const currentCustomEmojis = import.meta.server
? computed(getDefault)
: useUserLocalStorage(STORAGE_KEY_CUSTOM_EMOJIS, getDefault)

Expand Down
2 changes: 1 addition & 1 deletion composables/idb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function useAsyncIDBKeyval<T>(

const data = (shallow ? shallowRef : ref)(initialValue) as Ref<T>

const rawInit: T = resolveUnref(initialValue)
const rawInit: T = toValue(initialValue)

async function read() {
if (!isIDBSupported)
Expand Down
2 changes: 1 addition & 1 deletion composables/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useMask(options: UseMaskOptions = {}) {
getContainer = () => document.body,
zIndex = 100,
} = options
const wrapperEl = (process.server ? null : document.createElement('div')) as HTMLDivElement
const wrapperEl = (import.meta.server ? null : document.createElement('div')) as HTMLDivElement

function show() {
const container = getContainer()
Expand Down
2 changes: 1 addition & 1 deletion composables/masto/masto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function useStreaming(
stream.value = cb(streamingClient.value)
})

if (process.client && !process.test)
if (import.meta.client && !process.test)
useNuxtApp().$pageLifecycle.addFrozenListener(cleanup)

tryOnBeforeUnmount(() => isActive.value = false)
Expand Down
4 changes: 2 additions & 2 deletions composables/masto/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function usePublish(options: {
...(isGlitchEdition.value ? { 'content-type': 'text/markdown' } : {}),
} as mastodon.rest.v1.CreateStatusParams

if (process.dev) {
if (import.meta.dev) {
// eslint-disable-next-line no-console
console.info({
raw: draft.value.params.status,
Expand Down Expand Up @@ -249,7 +249,7 @@ export function useUploadMediaAttachment(draft: Ref<Draft>) {
}

async function pickAttachments() {
if (process.server)
if (import.meta.server)
return
const mimeTypes = currentInstance.value!.configuration?.mediaAttachments.supportedMimeTypes
const files = await fileOpen({
Expand Down
2 changes: 1 addition & 1 deletion composables/masto/statusDrafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { STORAGE_KEY_DRAFTS } from '~/constants'
import type { Draft, DraftMap } from '~/types'
import type { Mutable } from '~/types/utils'

export const currentUserDrafts = (process.server || process.test)
export const currentUserDrafts = (import.meta.server || process.test)
? computed<DraftMap>(() => ({}))
: useUserLocalStorage<DraftMap>(STORAGE_KEY_DRAFTS, () => ({}))

Expand Down
2 changes: 1 addition & 1 deletion composables/masto/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const supportedTranslationCodes = [
export function getLanguageCode() {
let code = 'en'
const getCode = (code: string) => code.replace(/-.*$/, '')
if (!process.server) {
if (import.meta.client) {
const { locale } = useI18n()
code = getCode(locale.value ? locale.value : navigator.language)
}
Expand Down
2 changes: 1 addition & 1 deletion composables/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function usePaginator<T, P, U = T>(
bound.update()
}

if (process.client) {
if (import.meta.client) {
useIntervalFn(() => {
bound.update()
}, 1000)
Expand Down
2 changes: 1 addition & 1 deletion composables/settings/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface ThemeColors {
}

export function getDefaultLanguage(languages: string[]) {
if (process.server)
if (import.meta.server)
return 'en-US'
return matchLanguages(languages, navigator.languages) || 'en-US'
}
Expand Down
8 changes: 3 additions & 5 deletions composables/settings/storage.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { Ref } from 'vue'
import type { VueI18n } from 'vue-i18n'
import type { LocaleObject } from 'vue-i18n-routing'
import type { LocaleObject } from '@nuxtjs/i18n'
import type { FontSize, OldFontSize, PreferencesSettings, UserSettings } from './definition'
import { STORAGE_KEY_SETTINGS } from '~/constants'
import { oldFontSizeMap } from '~~/constants/options'

export function useUserSettings() {
const i18n = useNuxtApp().vueApp.config.globalProperties.$i18n as VueI18n
const { locales } = i18n
const supportLanguages = (locales as LocaleObject[]).map(locale => locale.code)
const { locales } = useNuxtApp().$i18n
const supportLanguages = (unref(locales) as LocaleObject[]).map(locale => locale.code)
const settingsStorage = useUserLocalStorage<UserSettings>(STORAGE_KEY_SETTINGS, () => getDefaultUserSettings(supportLanguages))

// Backward compatibility, font size was xs, sm, md, lg, xl before
Expand Down
5 changes: 2 additions & 3 deletions composables/setups.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Directions } from 'vue-i18n-routing'
import type { LocaleObject } from '#i18n'
import type { Directions, LocaleObject } from '@nuxtjs/i18n'

export function setupPageHeader() {
const { locale, locales, t } = useI18n()
Expand Down Expand Up @@ -52,7 +51,7 @@ export function setupPageHeader() {

return titleTemplate
},
link: (process.client && useAppConfig().pwaEnabled)
link: (import.meta.client && useAppConfig().pwaEnabled)
? () => [{
key: 'webmanifest',
rel: 'manifest',
Expand Down
2 changes: 1 addition & 1 deletion composables/tiptap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface UseTiptapOptions {
}

export function useTiptap(options: UseTiptapOptions) {
if (process.server)
if (import.meta.server)
return { editor: ref<Editor | undefined>() }

const {
Expand Down
4 changes: 2 additions & 2 deletions composables/tiptap/suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function isCustomEmoji(emoji: CustomEmoji | Emoji): emoji is CustomEmoji
return !!(emoji as CustomEmoji).custom
}

export const TiptapMentionSuggestion: Partial<SuggestionOptions> = process.server
export const TiptapMentionSuggestion: Partial<SuggestionOptions> = import.meta.server
? {}
: {
pluginKey: new PluginKey('mention'),
Expand Down Expand Up @@ -56,7 +56,7 @@ export const TiptapEmojiSuggestion: Partial<SuggestionOptions> = {
pluginKey: new PluginKey('emoji'),
char: ':',
async items({ query }): Promise<(CustomEmoji | Emoji)[]> {
if (process.server || query.length === 0)
if (import.meta.server || query.length === 0)
return []

if (currentCustomEmojis.value.emojis.length === 0)
Expand Down
12 changes: 6 additions & 6 deletions composables/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function initializeUsers(): Promise<Ref<UserLogin[]> | RemovableRef<UserLogin[]>
}
}

const users = process.server
const users = import.meta.server
? ref<UserLogin[]>(defaultUsers)
: useAsyncIDBKeyval<UserLogin[]>(STORAGE_KEY_USERS, defaultUsers, { deep: true })

Expand All @@ -42,7 +42,7 @@ function initializeUsers(): Promise<Ref<UserLogin[]> | RemovableRef<UserLogin[]>
return users
}

const users = process.server ? initializeUsers() as Ref<UserLogin[]> | RemovableRef<UserLogin[]> : await initializeUsers()
const users = import.meta.server ? initializeUsers() as Ref<UserLogin[]> | RemovableRef<UserLogin[]> : await initializeUsers()
const nodes = useLocalStorage<Record<string, any>>(STORAGE_KEY_NODES, {}, { deep: true })
const currentUserHandle = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER_HANDLE, mock ? mock.user.account.id : '')
export const instanceStorage = useLocalStorage<Record<string, mastodon.v1.Instance>>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true })
Expand Down Expand Up @@ -81,7 +81,7 @@ export const isGotoSocial = computed(() => currentNodeInfo.value?.software?.name
export const isGlitchEdition = computed(() => currentInstance.value?.version?.includes('+glitch'))

// when multiple tabs: we need to reload window when sign in, switch account or sign out
if (process.client) {
if (import.meta.client) {
const windowReload = () => {
document.visibilityState === 'visible' && window.location.reload()
}
Expand Down Expand Up @@ -184,15 +184,15 @@ export function getExpandSpoilersByDefault(account: mastodon.v1.AccountCredentia
* @returns `true` when user selected "Always show media" as Media Display preference
*/
export function getExpandMediaByDefault(account: mastodon.v1.AccountCredentials) {
return accountPreferencesMap.get(account.acct)?.['reading:expand:media'] === 'show_all' ?? false
return accountPreferencesMap.get(account.acct)?.['reading:expand:media'] === 'show_all'
}

/**
* @param account
* @returns `true` when user selected "Always hide media" as Media Display preference
*/
export function getHideMediaByDefault(account: mastodon.v1.AccountCredentials) {
return accountPreferencesMap.get(account.acct)?.['reading:expand:media'] === 'hide_all' ?? false
return accountPreferencesMap.get(account.acct)?.['reading:expand:media'] === 'hide_all'
}

export async function fetchAccountInfo(client: mastodon.rest.Client, server: string) {
Expand Down Expand Up @@ -343,7 +343,7 @@ interface UseUserLocalStorageCache {
* @param initial
*/
export function useUserLocalStorage<T extends object>(key: string, initial: () => T): Ref<T> {
if (process.server || process.test)
if (import.meta.server || process.test)
return shallowRef(initial())

// @ts-expect-error bind value to the function
Expand Down
2 changes: 1 addition & 1 deletion composables/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function onReactivated(hook: () => void, target?: ComponentInternalInstan
export function useHydratedHead<T extends SchemaAugmentations>(input: UseHeadInput<T>, options?: UseHeadOptions): ActiveHeadEntry<UseHeadInput<T>> | void {
if (input && typeof input === 'object' && !('value' in input)) {
const title = 'title' in input ? input.title : undefined
if (process.server && title) {
if (import.meta.server && title) {
input.meta = input.meta || []
if (Array.isArray(input.meta)) {
input.meta.push(
Expand Down
2 changes: 1 addition & 1 deletion composables/web-share-target.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function useWebShareTarget(listener?: (message: MessageEvent) => void) {
if (process.server)
if (import.meta.server)
return

onBeforeMount(() => {
Expand Down
20 changes: 20 additions & 0 deletions config/i18n.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
currentLocales,
datetimeFormats,
numberFormats,
pluralRules,
} from './i18n'

export default defineI18nConfig(() => {
return {
legacy: false,
availableLocales: currentLocales.map(l => l.code),
fallbackLocale: 'en-US',
fallbackWarn: true,
missingWarn: true,
datetimeFormats,
numberFormats,
// eslint-disable-next-line @typescript-eslint/comma-dangle
pluralRules
}
})
Loading

0 comments on commit 55037f0

Please sign in to comment.