Skip to content

Commit

Permalink
fix: improve module meta resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 17, 2023
1 parent a158b1b commit 7dc3d93
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 38 deletions.
16 changes: 1 addition & 15 deletions packages/devtools/client/components/ModuleItem.vue
Expand Up @@ -5,24 +5,10 @@ const props = defineProps<{
mod: InstalledModuleInfo
}>()
const config = useServerConfig()
const isPackageModule = computed(() => props.mod.entryPath && isNodeModulePath(props.mod.entryPath))
const name = computed(() => {
if (props.mod.meta?.name)
return props.mod.meta.name
if (props.mod.entryPath) {
return isPackageModule.value
? getModuleNameFromPath(props.mod.entryPath)
: config.value?.rootDir
? parseReadablePath(props.mod.entryPath, config.value?.rootDir).path
: ''
}
return ''
})
const staticInfo = computed(() => props.mod.info)
const data = computed(() => ({
name,
...props.mod?.meta,
...props.mod,
...staticInfo.value,
}))
</script>
Expand Down
26 changes: 6 additions & 20 deletions packages/devtools/client/components/ModuleItemBase.vue
@@ -1,29 +1,15 @@
<script setup lang="ts">
import type { BasicModuleInfo, ModuleStaticInfo } from '../../src/types'
import type { InstalledModuleInfo, ModuleStaticInfo } from '../../src/types'
const props = defineProps<{
mod: BasicModuleInfo
mod: InstalledModuleInfo
info?: ModuleStaticInfo
compact?: boolean
}>()
const config = useServerConfig()
const isPackageModule = computed(() => props.mod.entryPath && isNodeModulePath(props.mod.entryPath))
const name = computed(() => {
if (props.mod.meta?.name)
return props.mod.meta.name
if (props.mod.entryPath) {
return isPackageModule.value
? getModuleNameFromPath(props.mod.entryPath)
: config.value?.rootDir
? parseReadablePath(props.mod.entryPath, config.value?.rootDir).path
: ''
}
return ''
})
const data = computed(() => ({
name,
...props.mod?.meta,
...props.mod,
...props.info,
}))
Expand All @@ -40,7 +26,7 @@ const openInEditor = useOpenInEditor()
<div flex="~ col gap2" flex-auto of-hidden px1>
<div gap-1t flex items-center text-ellipsis ws-nowrap text-lg>
<NuxtLink
v-if="isPackageModule"
v-if="mod.isPackageModule"
:to="npmBase + (data.npm || data.name)"
target="_blank"
hover="underline text-primary"
Expand Down Expand Up @@ -98,11 +84,11 @@ const openInEditor = useOpenInEditor()
</div>
<div flex="~ col" items-end>
<div
v-if="data.icon || isPackageModule"
v-if="data.icon || mod.isPackageModule"

h-20 w-20 flex flex-none rounded bg-gray:3 p4
>
<img v-if="data.icon" :src="iconBase + data.icon" :alt="name" ma>
<img v-if="data.icon" :src="iconBase + data.icon" :alt="mod.name" ma>
<div i-carbon-circle-dash ma text-4xl op50 />
</div>
<div v-if="data.maintainers?.length" flex="~" mt2 flex-auto items-end justify-end>
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/client/composables/client.ts
Expand Up @@ -14,7 +14,7 @@ export function useClientRoute() {
return computed(() => client.value?.nuxt.vueApp.config.globalProperties?.$route)
}

export function useClientRouter() {
export function useClientRouter(): ComputedRef<ReturnType<typeof useRouter>> {
const client = useClient()
return computed(() => client.value?.nuxt.vueApp.config.globalProperties?.$router)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/client/composables/state.ts
Expand Up @@ -43,7 +43,7 @@ export function useInstalledModules() {
: undefined

const isUninstallable = config.value?.modules?.includes(name)
const info = modules.value?.find(m => m.npm === name)
const info = modules.value?.find(m => m.npm === name) || modules.value?.find(m => m.name === name)

return {
name,
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/client/pages/modules/modules.vue
Expand Up @@ -24,7 +24,7 @@ const userModules = computed(() => installedModules.value.filter(i => !i.isPacka
>
<ModuleItem
v-for="m of packageModules"
:key="m.meta?.name || m.entryPath"
:key="m.name"
:mod="m"
/>
<NCard
Expand Down

0 comments on commit 7dc3d93

Please sign in to comment.