Add TypeScript to app-frontend (#2364)

* Add TypeScript to app-frontend

Co-authored-by: Evan Song <52982404+ferothefox@users.noreply.github.com>

* Switch app-frontend to ESLint 9 & Nuxt config

* Fix ESLint issues after config change in app-frontend

---------

Co-authored-by: Evan Song <52982404+ferothefox@users.noreply.github.com>
This commit is contained in:
Sasha Sorokin 2024-09-08 08:40:40 +02:00 committed by GitHub
parent 16c5a5a3a6
commit b3a6393c91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 1050 additions and 252 deletions

View File

@ -1,4 +0,0 @@
module.exports = {
root: true,
extends: ['custom/vue'],
}

View File

@ -0,0 +1,22 @@
import { createConfigForNuxt } from '@nuxt/eslint-config/flat'
import { fixupPluginRules } from '@eslint/compat'
import turboPlugin from 'eslint-plugin-turbo'
export default createConfigForNuxt().append([
{
name: 'turbo',
plugins: {
turbo: fixupPluginRules(turboPlugin),
},
rules: {
'turbo/no-undeclared-env-vars': 'error',
},
},
{
name: 'modrinth',
rules: {
'vue/html-self-closing': 'off',
'vue/multi-word-component-names': 'off',
},
},
])

View File

@ -5,7 +5,8 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vue-tsc --noEmit && vite build",
"tsc:check": "vue-tsc --noEmit",
"lint": "eslint . && prettier --check .", "lint": "eslint . && prettier --check .",
"fix": "eslint . --fix && prettier --write ." "fix": "eslint . --fix && prettier --write ."
}, },
@ -13,37 +14,42 @@
"@modrinth/assets": "workspace:*", "@modrinth/assets": "workspace:*",
"@modrinth/ui": "workspace:*", "@modrinth/ui": "workspace:*",
"@modrinth/utils": "workspace:*", "@modrinth/utils": "workspace:*",
"@sentry/vue": "^8.27.0",
"@tauri-apps/api": "^2.0.0-rc.3", "@tauri-apps/api": "^2.0.0-rc.3",
"@tauri-apps/plugin-dialog": "^2.0.0-rc.0", "@tauri-apps/plugin-dialog": "^2.0.0-rc.0",
"@tauri-apps/plugin-os": "^2.0.0-rc.0", "@tauri-apps/plugin-os": "^2.0.0-rc.0",
"@tauri-apps/plugin-window-state": "^2.0.0-rc.0",
"@tauri-apps/plugin-shell": "^2.0.0-rc.0", "@tauri-apps/plugin-shell": "^2.0.0-rc.0",
"@tauri-apps/plugin-updater": "^2.0.0-rc.0", "@tauri-apps/plugin-updater": "^2.0.0-rc.0",
"@tauri-apps/plugin-window-state": "^2.0.0-rc.0",
"@vintl/vintl": "^4.4.1", "@vintl/vintl": "^4.4.1",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"floating-vue": "^5.2.2", "floating-vue": "^5.2.2",
"ofetch": "^1.3.4", "ofetch": "^1.3.4",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"posthog-js": "^1.158.2",
"vite-svg-loader": "^5.1.0", "vite-svg-loader": "^5.1.0",
"vue": "^3.4.21", "vue": "^3.4.21",
"vue-multiselect": "3.0.0", "vue-multiselect": "3.0.0",
"vue-router": "4.3.0", "vue-router": "4.3.0",
"vue-virtual-scroller": "v2.0.0-beta.8", "vue-virtual-scroller": "v2.0.0-beta.8"
"posthog-js": "^1.158.2",
"@sentry/vue": "^8.27.0"
}, },
"devDependencies": { "devDependencies": {
"@eslint/compat": "^1.1.1",
"@nuxt/eslint-config": "^0.5.6",
"@tauri-apps/cli": "^2.0.0-rc", "@tauri-apps/cli": "^2.0.0-rc",
"@vitejs/plugin-vue": "^5.0.4", "@vitejs/plugin-vue": "^5.0.4",
"autoprefixer": "^10.4.19", "autoprefixer": "^10.4.19",
"eslint": "^8.57.0", "eslint": "^9.9.1",
"eslint-config-custom": "workspace:*", "eslint-config-custom": "workspace:*",
"eslint-plugin-turbo": "^2.1.1",
"postcss": "^8.4.39", "postcss": "^8.4.39",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"sass": "^1.74.1", "sass": "^1.74.1",
"tailwindcss": "^3.4.4", "tailwindcss": "^3.4.4",
"tsconfig": "workspace:*", "tsconfig": "workspace:*",
"vite": "^5.2.8" "typescript": "^5.5.4",
"vite": "^5.2.8",
"vue-tsc": "^2.1.6"
}, },
"packageManager": "pnpm@9.4.0" "packageManager": "pnpm@9.4.0"
} }

View File

@ -134,9 +134,9 @@ const logout = async (id) => {
trackEvent('AccountLogOut') trackEvent('AccountLogOut')
} }
let showCard = ref(false) const showCard = ref(false)
let card = ref(null) const card = ref(null)
let button = ref(null) const button = ref(null)
const handleClickOutside = (event) => { const handleClickOutside = (event) => {
const elements = document.elementsFromPoint(event.clientX, event.clientY) const elements = document.elementsFromPoint(event.clientX, event.clientY)
if ( if (

View File

@ -462,7 +462,7 @@ const promises = profileOptions.value.map(async (option) => {
option.name, option.name,
instances.map((name) => ({ name, selected: false })), instances.map((name) => ({ name, selected: false })),
) )
} catch (error) { } catch {
// Allow failure silently // Allow failure silently
} }
}) })

View File

@ -124,7 +124,7 @@ async function testJava() {
} }
async function handleJavaFileInput() { async function handleJavaFileInput() {
let filePath = await open() const filePath = await open()
if (filePath) { if (filePath) {
let result = await get_jre(filePath.path) let result = await get_jre(filePath.path)
@ -150,7 +150,7 @@ async function autoDetect() {
if (!props.compact) { if (!props.compact) {
detectJavaModal.value.show(props.version, props.modelValue) detectJavaModal.value.show(props.version, props.modelValue)
} else { } else {
let versions = await find_filtered_jres(props.version).catch(handleError) const versions = await find_filtered_jres(props.version).catch(handleError)
if (versions.length > 0) { if (versions.length > 0) {
emit('update:modelValue', versions[0]) emit('update:modelValue', versions[0])
} }

View File

@ -88,8 +88,6 @@ import { loading_listener } from '@/helpers/events.js'
import { getCurrentWindow } from '@tauri-apps/api/window' import { getCurrentWindow } from '@tauri-apps/api/window'
import { XIcon } from '@modrinth/assets' import { XIcon } from '@modrinth/assets'
import { MaximizeIcon, MinimizeIcon } from '@/assets/icons/index.js' import { MaximizeIcon, MinimizeIcon } from '@/assets/icons/index.js'
import { TauriEvent } from '@tauri-apps/api/event'
import { saveWindowState, StateFlags } from '@tauri-apps/plugin-window-state'
import { getOS } from '@/helpers/utils.js' import { getOS } from '@/helpers/utils.js'
import { useLoading } from '@/store/loading.js' import { useLoading } from '@/store/loading.js'

View File

@ -66,7 +66,7 @@ const selectedVersion = ref(null)
const incompatibleModal = ref(null) const incompatibleModal = ref(null)
const installing = ref(false) const installing = ref(false)
let onInstall = ref(() => {}) const onInstall = ref(() => {})
defineExpose({ defineExpose({
show: (instanceVal, projectVal, projectVersions, callback) => { show: (instanceVal, projectVal, projectVersions, callback) => {

View File

@ -12,7 +12,7 @@ const project = ref()
const confirmModal = ref(null) const confirmModal = ref(null)
const installing = ref(false) const installing = ref(false)
let onInstall = ref(() => {}) const onInstall = ref(() => {})
defineExpose({ defineExpose({
show: (projectVal, versionIdVal, callback) => { show: (projectVal, versionIdVal, callback) => {

View File

@ -48,7 +48,7 @@ const shownProfiles = computed(() =>
return profile.name.toLowerCase().includes(searchFilter.value.toLowerCase()) return profile.name.toLowerCase().includes(searchFilter.value.toLowerCase())
}) })
.filter((profile) => { .filter((profile) => {
let loaders = versions.value.flatMap((v) => v.loaders) const loaders = versions.value.flatMap((v) => v.loaders)
return ( return (
versions.value.flatMap((v) => v.game_versions).includes(profile.game_version) && versions.value.flatMap((v) => v.game_versions).includes(profile.game_version) &&
@ -59,7 +59,7 @@ const shownProfiles = computed(() =>
}), }),
) )
let onInstall = ref(() => {}) const onInstall = ref(() => {})
defineExpose({ defineExpose({
show: async (projectVal, versionsVal, callback) => { show: async (projectVal, versionsVal, callback) => {
@ -77,7 +77,7 @@ defineExpose({
onInstall.value = callback onInstall.value = callback
const profilesVal = await list().catch(handleError) const profilesVal = await list().catch(handleError)
for (let profile of profilesVal) { for (const profile of profilesVal) {
profile.installing = false profile.installing = false
profile.installedMod = await check_installed(profile.path, project.value.id).catch( profile.installedMod = await check_installed(profile.path, project.value.id).catch(
handleError, handleError,

View File

@ -56,7 +56,7 @@ export function debounce(fn, wait) {
if (timer) { if (timer) {
clearTimeout(timer) // clear any pre-existing timer clearTimeout(timer) // clear any pre-existing timer
} }
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this // get the current context const context = this // get the current context
timer = setTimeout(() => { timer = setTimeout(() => {
fn.apply(context, args) // call the function if time expires fn.apply(context, args) // call the function if time expires

View File

@ -381,20 +381,20 @@ const sortedCategories = computed(() => {
// identifier[0], then if it ties, identifier[1], etc // identifier[0], then if it ties, identifier[1], etc
async function sortByNameOrNumber(sortable, identifiers) { async function sortByNameOrNumber(sortable, identifiers) {
sortable.sort((a, b) => { sortable.sort((a, b) => {
for (let identifier of identifiers) { for (const identifier of identifiers) {
let aNum = parseFloat(a[identifier]) const aNum = parseFloat(a[identifier])
let bNum = parseFloat(b[identifier]) const bNum = parseFloat(b[identifier])
if (isNaN(aNum) && isNaN(bNum)) { if (isNaN(aNum) && isNaN(bNum)) {
// Both are strings, sort alphabetically // Both are strings, sort alphabetically
let stringComp = a[identifier].localeCompare(b[identifier]) const stringComp = a[identifier].localeCompare(b[identifier])
if (stringComp != 0) return stringComp if (stringComp != 0) return stringComp
} else if (!isNaN(aNum) && !isNaN(bNum)) { } else if (!isNaN(aNum) && !isNaN(bNum)) {
// Both are numbers, sort numerically // Both are numbers, sort numerically
let numComp = aNum - bNum const numComp = aNum - bNum
if (numComp != 0) return numComp if (numComp != 0) return numComp
} else { } else {
// One is a number and one is a string, numbers go first // One is a number and one is a string, numbers go first
let numStringComp = isNaN(aNum) ? 1 : -1 const numStringComp = isNaN(aNum) ? 1 : -1
if (numStringComp != 0) return numStringComp if (numStringComp != 0) return numStringComp
} }
} }

View File

@ -47,7 +47,7 @@ const getInstances = async () => {
return dateB - dateA return dateB - dateA
}) })
let filters = [] const filters = []
for (const instance of recentInstances.value) { for (const instance of recentInstances.value) {
if (instance.linked_data && instance.linked_data.project_id) { if (instance.linked_data && instance.linked_data.project_id) {
filters.push(`NOT"project_id"="${instance.linked_data.project_id}"`) filters.push(`NOT"project_id"="${instance.linked_data.project_id}"`)

View File

@ -406,14 +406,14 @@ async function purgeCache() {
<span class="label__title size-card-header">Java settings</span> <span class="label__title size-card-header">Java settings</span>
</h3> </h3>
</div> </div>
<template v-for="version in [21, 17, 8]"> <template v-for="javaVersion in [21, 17, 8]" :key="`java-${javaVersion}`">
<label :for="'java-' + version"> <label :for="'java-' + javaVersion">
<span class="label__title">Java {{ version }} location</span> <span class="label__title">Java {{ javaVersion }} location</span>
</label> </label>
<JavaSelector <JavaSelector
:id="'java-selector-' + version" :id="'java-selector-' + javaVersion"
v-model="javaVersions[version]" v-model="javaVersions[javaVersion]"
:version="version" :version="javaVersion"
@update:model-value="updateJavaVersion" @update:model-value="updateJavaVersion"
/> />
</template> </template>

View File

@ -296,7 +296,7 @@ if (logs.value.length > 1 && !props.playing) {
const deleteLog = async () => { const deleteLog = async () => {
if (logs.value[selectedLogIndex.value] && selectedLogIndex.value !== 0) { if (logs.value[selectedLogIndex.value] && selectedLogIndex.value !== 0) {
let deleteIndex = selectedLogIndex.value const deleteIndex = selectedLogIndex.value
selectedLogIndex.value = deleteIndex - 1 selectedLogIndex.value = deleteIndex - 1
await delete_logs_by_filename( await delete_logs_by_filename(
props.instance.path, props.instance.path,

View File

@ -717,7 +717,7 @@ const updateProject = async (mod) => {
}) })
} }
let locks = {} const locks = {}
const toggleDisableMod = async (mod) => { const toggleDisableMod = async (mod) => {
// Use mod's id as the key for the lock. If mod doesn't have a unique id, replace `mod.id` with some unique property. // Use mod's id as the key for the lock. If mod doesn't have a unique id, replace `mod.id` with some unique property.
@ -725,7 +725,7 @@ const toggleDisableMod = async (mod) => {
locks[mod.id] = ref(null) locks[mod.id] = ref(null)
} }
let lock = locks[mod.id] const lock = locks[mod.id]
while (lock.value) { while (lock.value) {
await lock.value await lock.value

View File

@ -880,7 +880,7 @@ const editing = ref(false)
async function saveGvLoaderEdits() { async function saveGvLoaderEdits() {
editing.value = true editing.value = true
let editProfile = editProfileObject.value const editProfile = editProfileObject.value
editProfile.loader = loader.value editProfile.loader = loader.value
editProfile.game_version = gameVersion.value editProfile.game_version = gameVersion.value

View File

@ -102,9 +102,9 @@ const props = defineProps({
}, },
}) })
let expandedGalleryItem = ref(null) const expandedGalleryItem = ref(null)
let expandedGalleryIndex = ref(0) const expandedGalleryIndex = ref(0)
let zoomedIn = ref(false) const zoomedIn = ref(false)
const nextImage = () => { const nextImage = () => {
expandedGalleryIndex.value++ expandedGalleryIndex.value++

View File

@ -232,15 +232,7 @@ import {
GlobeIcon, GlobeIcon,
ClipboardCopyIcon, ClipboardCopyIcon,
} from '@modrinth/assets' } from '@modrinth/assets'
import { import { Categories, EnvironmentIndicator, Card, Avatar, Button, NavRow } from '@modrinth/ui'
Categories,
EnvironmentIndicator,
Card,
Avatar,
Button,
Promotion,
NavRow,
} from '@modrinth/ui'
import { formatNumber } from '@modrinth/utils' import { formatNumber } from '@modrinth/utils'
import { import {
BuyMeACoffeeIcon, BuyMeACoffeeIcon,
@ -261,7 +253,7 @@ import { handleError } from '@/store/notifications.js'
import { convertFileSrc } from '@tauri-apps/api/core' import { convertFileSrc } from '@tauri-apps/api/core'
import ContextMenu from '@/components/ui/ContextMenu.vue' import ContextMenu from '@/components/ui/ContextMenu.vue'
import { install as installVersion } from '@/store/install.js' import { install as installVersion } from '@/store/install.js'
import { get_project, get_project_many, get_team, get_version_many } from '@/helpers/cache.js' import { get_project, get_team, get_version_many } from '@/helpers/cache.js'
import PromotionWrapper from '@/components/ui/PromotionWrapper.vue' import PromotionWrapper from '@/components/ui/PromotionWrapper.vue'
dayjs.extend(relativeTime) dayjs.extend(relativeTime)

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowJs": true,
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "preserve",
"strict": true,
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src"]
}

View File

@ -1,12 +1,4 @@
{ {
"compilerOptions": { "files": [],
"module": "NodeNext", "references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }]
"moduleResolution": "NodeNext",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"target": "ESNext"
},
"exclude": ["node_modules", "dist"]
} }

View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"strict": true
},
"include": ["vite.config.ts"]
}

1125
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff