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

[fix] #515: infer SFC names #523

Open
wants to merge 5 commits into
base: fresh-breath
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion packages/ui/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
storybook-static
cypress/screenshots
ts-build
ts-build
.vite-inspect
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"unplugin-auto-import": "^0.15.1",
"unplugin-icons": "^0.15.3",
"vite": "^4.1.4",
"vite-plugin-inspect": "^0.7.18",
"vite-plugin-windicss": "^1.8.10",
"vue-tsc": "^1.2.0",
"windicss": "^3.5.4"
Expand Down
7 changes: 1 addition & 6 deletions packages/ui/src/components/all-components.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { COMPONENTS } from './all-components'
import { getComponentName } from '../util'

for (const [nameExpected, component] of Object.entries(COMPONENTS)) {
// FIXME it seems that automatic name inference does not work anymore
// https://vuejs.org/api/sfc-spec.html#automatic-name-inference
// Should we really set it? Reasons:
// - DevTools inspection and dev warnings (should work without setting `.name`, need to check)
// - Global components registration
test.skip(`Component "${nameExpected}" should have the same actual "name"`, () => {
test(`Component "${nameExpected}" should have the same actual "name"`, () => {
const nameActual = getComponentName(component)

expect(nameActual).toEqual(nameExpected)
Expand Down
18 changes: 18 additions & 0 deletions packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config'
// @ts-ignore FIXME update when this package fixes its `exports`
import windiPlugin from 'vite-plugin-windicss'
import vuePlugin from '@vitejs/plugin-vue'
import inspectPlugin from 'vite-plugin-inspect'
import type { RootNode, TemplateChildNode } from '@vue/compiler-core'
import iconsPlugin from 'unplugin-icons/vite'
import svgPlugin from '@soramitsu-ui/vite-plugin-svg'
Expand Down Expand Up @@ -83,6 +84,19 @@ function checkAutoImportedTypesPlugin(checkDts = resolve('auto-imports.d.ts')):
}
}

function sfcInferNamePlugin(): Plugin {
return {
name: 'soramitsu-ui:sfc-infer-name',
transform(src, id) {
if (/\.vue(\?vue&type=script&setup=true)?/.test(id)) {
const code = src.replace(/(__name: "(\w+)")/, `$1, name: "$2"`)
return { code, map: null }
}
return undefined
},
}
}

export default defineConfig({
test: {
include: ['src/**/*.spec.ts'],
Expand Down Expand Up @@ -114,6 +128,7 @@ export default defineConfig({
},
},
}),
sfcInferNamePlugin(),
iconsPlugin(),
svgPlugin({
svgo: {
Expand Down Expand Up @@ -151,6 +166,9 @@ export default defineConfig({
},
}),
checkAutoImportedTypesPlugin(),

// save for future debugging needs
// inspectPlugin({ build: true, outputDir: '.vite-inspect' }),
],
build: {
sourcemap: true,
Expand Down
120 changes: 82 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.