Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kit): for better naming of index.vue components #628

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/devtools-kit/src/core/component/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { basename, classify } from '@vue/devtools-shared'
import { Fragment } from '../../../shared/stub-vue'

function getComponentTypeName(options: VueAppInstance['type']) {
return options.name || options._componentTag || options.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ || options.__name
const name = options.name || options._componentTag || options.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ || options.__name
if (name === 'index' && options.__file?.endsWith('index.vue')) {
return ''
}
return name
}

function getComponentFileName(options: VueAppInstance['type']) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
const text = ref('Index')
</script>

<template>
<div>
{{ text }} Component
</div>
</template>
2 changes: 2 additions & 0 deletions packages/playground/basic/src/pages/Home.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import Foo from '../components/Foo.vue'
import IndexComponent from '../components/IndexComponent/index.vue'

const visible = ref(false)

Expand All @@ -23,6 +24,7 @@ const toRefObj = toRefs(obj)
<div class="m-auto mt-3 h-80 w-120 flex flex-col items-center justify-center rounded bg-[#363636]">
Home
<Foo v-if="visible" />
<IndexComponent v-if="visible" />
<img src="/vite.svg" alt="Vite Logo">
<button class="w-30 cursor-pointer" @click="visible = !visible">
Toggle Foo
Expand Down
6 changes: 4 additions & 2 deletions packages/shared/src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export function kebabize(str: string) {
}

export function basename(filename: string, ext: string): string {
const normalizedFilename = filename.replace(/^[a-z]:/i, '').replace(/\\/g, '/')
let normalizedFilename = filename.replace(/^[a-z]:/i, '').replace(/\\/g, '/')
if (normalizedFilename.endsWith(`index${ext}`)) {
normalizedFilename = normalizedFilename.replace(`/index${ext}`, ext)
}
const lastSlashIndex = normalizedFilename.lastIndexOf('/')
const baseNameWithExt = normalizedFilename.substring(lastSlashIndex + 1)

if (ext) {
const extIndex = baseNameWithExt.lastIndexOf(ext)
return baseNameWithExt.substring(0, extIndex)
Expand Down