[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: fix type issues in lunaria + type check root ts files (#731)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Daniel Roe
autofix-ci[bot]
and committed by
GitHub
8b065441 bf03fba3

+38 -12
+31 -11
lunaria/prepare-json-files.ts
··· 1 - import type { Locale } from '@lunariajs/core' 2 1 import type { LocaleObject } from '@nuxtjs/i18n' 3 2 import * as path from 'node:path' 4 3 import * as fs from 'node:fs/promises' ··· 8 7 const destFolder = path.resolve('lunaria/files') 9 8 const localesFolder = path.resolve('i18n/locales') 10 9 11 - const defaultLocale = currentLocales.find(l => l.code === 'en-US')! 10 + const defaultLocale = currentLocales.find(l => l.code === 'en-US') 11 + if (!defaultLocale?.name) { 12 + throw new Error('Default locale en-US not found or has no name') 13 + } 12 14 export { lunariaJSONFiles } 13 15 export const sourceLocale = { 14 16 label: defaultLocale.name, 15 17 lang: defaultLocale.code, 16 18 } 17 - export const locales: Locale[] = currentLocales 18 - .filter(l => l.code !== 'en-US') 19 - .map(l => ({ 19 + const filteredLocales = currentLocales.filter( 20 + (l): l is typeof l & { name: string } => l.code !== 'en-US' && typeof l.name === 'string', 21 + ) 22 + const firstLocale = filteredLocales[0] 23 + if (!firstLocale) { 24 + throw new Error('No locales found besides en-US') 25 + } 26 + export const locales: [{ label: string; lang: string }, ...{ label: string; lang: string }[]] = [ 27 + { label: firstLocale.name, lang: firstLocale.code }, 28 + ...filteredLocales.slice(1).map(l => ({ 20 29 label: l.name, 21 30 lang: l.code, 22 - })) 31 + })), 32 + ] 23 33 24 34 export async function prepareJsonFiles() { 25 35 await fs.rm(destFolder, { recursive: true, force: true }) ··· 31 41 return JSON.parse(await fs.readFile(path.resolve(`${localesFolder}/${name}`), 'utf8')) 32 42 } 33 43 44 + function getFileName(file: string | { path: string }): string { 45 + return typeof file === 'string' ? file : file.path 46 + } 47 + 34 48 async function mergeLocale(locale: LocaleObject) { 35 - if (locale.file || locale.files.length === 1) { 36 - const json = locale.file || locale.files[0] 49 + const files = locale.files ?? [] 50 + if (locale.file || files.length === 1) { 51 + const json = locale.file ?? (files[0] ? getFileName(files[0]) : undefined) 52 + if (!json) return 37 53 await fs.cp(path.resolve(`${localesFolder}/${json}`), path.resolve(`${destFolder}/${json}`)) 38 54 return 39 55 } 40 56 41 - const source = await loadJsonFile(locale.files[0] as string) 57 + const firstFile = files[0] 58 + if (!firstFile) return 59 + const source = await loadJsonFile(getFileName(firstFile)) 42 60 let currentSource: unknown 43 - for (let i = 1; i < locale.files.length; i++) { 44 - currentSource = await loadJsonFile(locale.files[i] as string) 61 + for (let i = 1; i < files.length; i++) { 62 + const file = files[i] 63 + if (!file) continue 64 + currentSource = await loadJsonFile(getFileName(file)) 45 65 deepCopy(currentSource, source) 46 66 } 47 67
+6
nuxt.config.ts
··· 248 248 noUnusedLocals: true, 249 249 }, 250 250 }, 251 + nodeTsConfig: { 252 + compilerOptions: { 253 + allowImportingTsExtensions: true, 254 + }, 255 + include: ['../*.ts'], 256 + }, 251 257 }, 252 258 253 259 vite: {
+1 -1
uno.config.ts
··· 31 31 }, 32 32 }), 33 33 // keep this preset last 34 - process.env.CI ? undefined : presetRtl(), 34 + ...(process.env.CI ? [] : [presetRtl()]), 35 35 ].filter(Boolean), 36 36 transformers: [transformerDirectives(), transformerVariantGroup()], 37 37 theme: {