Skip to content

Commit

Permalink
chore: fix type check
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 20, 2024
1 parent 58f3c96 commit 240c9f9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/devtools-ui-kit/src/components/NDarkToggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const isDark = computed<boolean>({
})
const isAppearanceTransition = typeof document !== 'undefined'
// @ts-expect-error document.startViewTransition can be undefined
&& document.startViewTransition
&& !window.matchMedia('(prefers-reduced-motion: reduce)').matches
Expand All @@ -35,7 +36,6 @@ function toggle(event?: MouseEvent) {
Math.max(x, innerWidth - x),
Math.max(y, innerHeight - y),
)
// @ts-expect-error: Transition API
const transition = document.startViewTransition(async () => {
isDark.value = !isDark.value
await nextTick()
Expand Down
7 changes: 5 additions & 2 deletions packages/devtools/client/components/BuildAnalyzeDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { formatTimeAgo } from '@vueuse/core'
import { computed, ref } from 'vue'
import { ensureDevAuthToken } from '~/composables/dev-auth'
import { rpc } from '~/composables/rpc'
import { formatDuration } from '~/composables/utils'
const props = defineProps<{
current: AnalyzeBuildMeta
Expand All @@ -31,6 +30,10 @@ const tabs = computed(() => {
const selectedTab = ref(tabs.value[0])
function getDuration(build: AnalyzeBuildMeta) {
return `${((build.endTime - build.startTime) / 1000).toFixed(1)}s`
}
function formatFileSize(bytes: number) {
if (bytes < 1024)
return `${bytes}B`
Expand Down Expand Up @@ -81,7 +84,7 @@ async function clear(name: string) {
<div text-sm op50>
Build duration
</div>
<div>{{ formatDuration(current) }}</div>
<div>{{ getDuration(current) }}</div>
</div>
<template v-if="current.size?.clientBundle">
<div i-carbon-cics-program text-xl />
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools/client/components/DataSchemaDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const language = computed(() => languages.find(l => l.displayName === selectedLa
// TODO: use localStorage
const options = ref(language.value?.optionDefinitions.filter(o => typeof o.defaultValue === 'boolean'))
const generatedJson = computedAsync(async () => {
const generatedJson = computedAsync<string>(async () => {
// eslint-disable-next-line ts/no-unused-expressions
counter.value
Expand Down Expand Up @@ -70,7 +70,7 @@ watch(selectedLang, () => {
const copy = useCopy()
function copyToClipboard() {
copy(generatedJson.value)
copy(generatedJson.value || '')
}
</script>

Expand Down
7 changes: 4 additions & 3 deletions packages/devtools/client/components/StateEditor.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script setup lang="ts">
import type { useVModel, watchPausable } from '@vueuse/core'
import type { watchPausable } from '@vueuse/core'
import { useVModel } from '@vueuse/core'
import JsonEditorVue from 'json-editor-vue'
import { nextTick, onMounted, readonly, shallowRef, watch } from 'vue'
import { nextTick, onMounted, shallowRef, watch } from 'vue'
import { getColorMode } from '~/composables/client'
const props = defineProps<{
Expand Down Expand Up @@ -116,7 +117,7 @@ async function refresh() {
:main-menu-bar="false"
:navigation-bar="false"
:status-bar="false"
:read-only="readonly"
:read-only="props.readonly"
:indentation="2"
:tab-size="2"
/>
Expand Down
3 changes: 2 additions & 1 deletion packages/devtools/client/composables/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export function getSocialPreviewCard(
}
}

export function formatDuration(ms: number) {
export function formatDuration(ms: number | string) {
ms = Number(ms)
if (Number.isNaN(ms) || ms < 0)
return '-'
if (ms < 1)
Expand Down
9 changes: 7 additions & 2 deletions packages/devtools/client/pages/modules/analyze-build.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import type { AnalyzeBuildMeta } from '~/../src/types'
import { useRouter } from '#app/composables/router'
import { definePageMeta } from '#imports'
import { createTemplatePromise, formatTimeAgo } from '@vueuse/core'
Expand All @@ -11,7 +12,7 @@ import { registerCommands } from '~/composables/state-commands'
import { useCurrentTerminalId } from '~/composables/state-routes'
import { processAnalyzeBuildInfo } from '~/composables/state-subprocess'
import { telemetry } from '~/composables/telemetry'
import { formatDuration, useSessionState } from '~/composables/utils'
import { useSessionState } from '~/composables/utils'
definePageMeta({
icon: 'carbon-edge-node',
Expand Down Expand Up @@ -53,6 +54,10 @@ async function start() {
const terminalId = useCurrentTerminalId()
function getDuration(build: AnalyzeBuildMeta) {
return `${((build.endTime - build.startTime) / 1000).toFixed(1)}s`
}
function gotoTerminal() {
if (processAnalyzeBuildInfo.value?.processId) {
terminalId.value = processAnalyzeBuildInfo.value.processId
Expand Down Expand Up @@ -83,7 +88,7 @@ registerCommands(() => [
<code>{{ build.name }}</code>
<div flex="~ gap-1 items-center wrap" w-full text-sm op60>
<div i-carbon-time />
<span>{{ formatDuration(build) }}</span>
<span>{{ getDuration(build) }}</span>
<div flex-auto />
<span>{{ formatTimeAgo(new Date(build.endTime)) }}</span>
</div>
Expand Down

0 comments on commit 240c9f9

Please sign in to comment.