-
Notifications
You must be signed in to change notification settings - Fork 336
chore(vue,types): Add initial support for SFC files to improve runtime prop checking #4902
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
ddf330e
17168f7
d612ec5
fa6e4a4
efda20f
dca87dc
6ad2975
615b731
1f7ad16
f9a83c3
6d26ab1
772b8db
bc18a7a
c2f62ef
8ed8b4b
95feecb
3fb2d9d
03ab2e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@clerk/types': patch | ||
'@clerk/vue': patch | ||
--- | ||
|
||
Improve runtime prop checking for single-file components |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,10 +41,11 @@ | |
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsup", | ||
"build": "tsup --onSuccess \"pnpm build:dts\"", | ||
"build:dts": "vue-tsc --declaration --emitDeclarationOnly -p tsconfig.build.json", | ||
"dev": "tsup --watch", | ||
"lint": "eslint src/", | ||
"lint:attw": "attw --pack . --ignore-rules no-resolution cjs-resolves-to-esm", | ||
"lint:attw": "attw --pack . --ignore-rules no-resolution cjs-resolves-to-esm internal-resolution-error", | ||
"lint:publint": "publint", | ||
"publish:local": "pnpm yalc push --replace --sig", | ||
"test": "vitest", | ||
|
@@ -56,8 +57,11 @@ | |
}, | ||
"devDependencies": { | ||
"@testing-library/vue": "^8.1.0", | ||
"@vitejs/plugin-vue": "^5.2.1", | ||
"@vue.ts/tsx-auto-props": "^0.6.0", | ||
"vue": "3.5.12" | ||
"unplugin-vue": "^5.2.1", | ||
"vue": "3.5.12", | ||
"vue-tsc": "^2.0.24" | ||
Comment on lines
+62
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
"peerDependencies": { | ||
"vue": "^3.2.0" | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<script setup lang="ts"> | ||
import { useAttrs, useSlots } from 'vue'; | ||
import type { SignInProps } from '@clerk/types'; | ||
import { useClerk } from '../composables/useClerk'; | ||
import { assertSingleChild, normalizeWithDefaultValue } from '../utils'; | ||
|
||
type SignInButtonProps = Pick< | ||
SignInProps, | ||
'fallbackRedirectUrl' | 'forceRedirectUrl' | '#ForceRedirectUrl' | '#FallbackRedirectUrl' | 'initialValues' | ||
> & { | ||
mode?: 'modal' | 'redirect'; | ||
}; | ||
|
||
const props = defineProps<SignInButtonProps>(); | ||
|
||
const clerk = useClerk(); | ||
const slots = useSlots(); | ||
const attrs = useAttrs(); | ||
|
||
function getChildComponent() { | ||
const children = normalizeWithDefaultValue(slots.default?.({}), '#'); | ||
return assertSingleChild(children, 'SignInButton'); | ||
} | ||
|
||
function clickHandler() { | ||
const { mode, ...opts } = props; | ||
|
||
if (mode === 'modal') { | ||
return clerk.value?.openSignIn(opts); | ||
} | ||
|
||
void clerk.value?.redirectToSignIn({ | ||
...opts, | ||
signInFallbackRedirectUrl: props.fallbackRedirectUrl, | ||
signInForceRedirectUrl: props.forceRedirectUrl, | ||
}); | ||
} | ||
</script> | ||
|
||
<template> | ||
<component | ||
:is="getChildComponent" | ||
v-bind="attrs" | ||
@click="clickHandler" | ||
> | ||
<slot /> | ||
</component> | ||
</template> |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script setup lang="ts"> | ||
import { Portal } from '../uiComponents'; | ||
import { useClerk } from '../../composables'; | ||
import type { SignInProps } from '@clerk/types'; | ||
|
||
const clerk = useClerk(); | ||
|
||
const props = defineProps<SignInProps>(); | ||
</script> | ||
|
||
<template> | ||
<Portal | ||
:mount="clerk?.mountSignIn" | ||
:unmount="clerk?.unmountSignIn" | ||
:props="props" | ||
:update-props="(clerk as any)?.__unstable__updateProps" | ||
/> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare module '*.vue' { | ||
import type { DefineComponent } from 'vue'; | ||
|
||
const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, any>; | ||
export default component; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"declarationDir": "./dist" | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.vue"], | ||
"exclude": ["src/**/*.test.ts"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import autoPropsPlugin from '@vue.ts/tsx-auto-props/esbuild'; | ||
import { defineConfig, type Options } from 'tsup'; | ||
import vuePlugin from 'unplugin-vue/esbuild'; | ||
|
||
import { name, version } from './package.json'; | ||
|
||
|
@@ -13,8 +14,10 @@ export default defineConfig(() => { | |
bundle: true, | ||
sourcemap: true, | ||
minify: false, | ||
dts: true, | ||
dts: false, | ||
esbuildPlugins: [ | ||
// Adds .vue files support | ||
vuePlugin() as EsbuildPlugin, | ||
Comment on lines
+17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
// Automatically generates runtime props from TypeScript types/interfaces for all | ||
// control and UI components, adding them to Vue components during build via | ||
// Object.defineProperty | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import vue from '@vitejs/plugin-vue'; | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
}, | ||
plugins: [vue()], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required when testing |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting a transitive type dependency error because the
SignInProps
is exported but not theTransferableOption
interface that it depends on