Skip to content

Commit 8b06544

Browse files
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>
1 parent bf03fba commit 8b06544

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

lunaria/prepare-json-files.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Locale } from '@lunariajs/core'
21
import type { LocaleObject } from '@nuxtjs/i18n'
32
import * as path from 'node:path'
43
import * as fs from 'node:fs/promises'
@@ -8,18 +7,29 @@ import { deepCopy } from '@intlify/shared'
87
const destFolder = path.resolve('lunaria/files')
98
const localesFolder = path.resolve('i18n/locales')
109

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+
}
1214
export { lunariaJSONFiles }
1315
export const sourceLocale = {
1416
label: defaultLocale.name,
1517
lang: defaultLocale.code,
1618
}
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 => ({
2029
label: l.name,
2130
lang: l.code,
22-
}))
31+
})),
32+
]
2333

2434
export async function prepareJsonFiles() {
2535
await fs.rm(destFolder, { recursive: true, force: true })
@@ -31,17 +41,27 @@ async function loadJsonFile(name: string) {
3141
return JSON.parse(await fs.readFile(path.resolve(`${localesFolder}/${name}`), 'utf8'))
3242
}
3343

44+
function getFileName(file: string | { path: string }): string {
45+
return typeof file === 'string' ? file : file.path
46+
}
47+
3448
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
3753
await fs.cp(path.resolve(`${localesFolder}/${json}`), path.resolve(`${destFolder}/${json}`))
3854
return
3955
}
4056

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))
4260
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))
4565
deepCopy(currentSource, source)
4666
}
4767

nuxt.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ export default defineNuxtConfig({
248248
noUnusedLocals: true,
249249
},
250250
},
251+
nodeTsConfig: {
252+
compilerOptions: {
253+
allowImportingTsExtensions: true,
254+
},
255+
include: ['../*.ts'],
256+
},
251257
},
252258

253259
vite: {

uno.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default defineConfig({
3131
},
3232
}),
3333
// keep this preset last
34-
process.env.CI ? undefined : presetRtl(),
34+
...(process.env.CI ? [] : [presetRtl()]),
3535
].filter(Boolean),
3636
transformers: [transformerDirectives(), transformerVariantGroup()],
3737
theme: {

0 commit comments

Comments
 (0)