Skip to content

Commit

Permalink
chore(nuxt): Re-export Vue components and composables (#4750)
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano authored Dec 12, 2024
1 parent f86e836 commit b34edd2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-dingos-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/nuxt": patch
---

Re-export Vue SDK components and composables to Nuxt SDK to support manual imports
8 changes: 8 additions & 0 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
"./server": {
"types": "./dist/runtime/server/index.d.ts",
"import": "./dist/runtime/server/index.js"
},
"./components": {
"types": "./dist/runtime/components/index.d.ts",
"import": "./dist/runtime/components/index.js"
},
"./composables": {
"types": "./dist/runtime/composables/index.d.ts",
"import": "./dist/runtime/composables/index.js"
}
},
"main": "./dist/module.js",
Expand Down
27 changes: 5 additions & 22 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { LoadClerkJsScriptOptions } from '@clerk/shared/loadClerkJsScript';
import {
addComponent,
addImports,
addImportsDir,
addPlugin,
addServerHandler,
createResolver,
Expand Down Expand Up @@ -91,12 +91,11 @@ export default defineNuxtModule<ModuleOptions>({
});
}

// eslint-disable-next-line @typescript-eslint/consistent-type-imports
type VueClerkImports = Array<keyof typeof import('@clerk/vue')>;

// Add auto-imports for Clerk components and composables
// More info https://nuxt.com/docs/guide/concepts/auto-imports
const components: VueClerkImports = [
addImportsDir(resolver.resolve('./runtime/composables'));

// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const components: Array<keyof typeof import('@clerk/vue')> = [
// Authentication Components
'SignIn',
'SignUp',
Expand Down Expand Up @@ -125,22 +124,6 @@ export default defineNuxtModule<ModuleOptions>({
'SignedIn',
'SignedOut',
];
const composables: VueClerkImports = [
'useAuth',
'useClerk',
'useSession',
'useSessionList',
'useSignIn',
'useSignUp',
'useUser',
'useOrganization',
];
addImports(
composables.map(composable => ({
name: composable,
from: '@clerk/vue',
})),
);
components.forEach(component => {
void addComponent({
name: component,
Expand Down
30 changes: 30 additions & 0 deletions packages/nuxt/src/runtime/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export {
// UI components
SignUp,
SignIn,
UserProfile,
UserButton,
OrganizationSwitcher,
OrganizationProfile,
CreateOrganization,
OrganizationList,
GoogleOneTap,
Waitlist,
// Control components
ClerkLoaded,
ClerkLoading,
SignedOut,
SignedIn,
Protect,
RedirectToSignIn,
RedirectToSignUp,
RedirectToUserProfile,
AuthenticateWithRedirectCallback,
RedirectToCreateOrganization,
RedirectToOrganizationProfile,
// Unstyled components
SignInButton,
SignUpButton,
SignOutButton,
SignInWithMetamaskButton,
} from '@clerk/vue';
1 change: 1 addition & 0 deletions packages/nuxt/src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useAuth, useUser, useSession, useClerk, useSignIn, useSignUp, useOrganization } from '@clerk/vue';
8 changes: 7 additions & 1 deletion packages/nuxt/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { name, version } from './package.json';
export default defineConfig(() => {
return {
clean: true,
entry: ['./src/module.ts', './src/runtime/plugin.ts', './src/runtime/server/*.ts'],
entry: [
'./src/module.ts',
'./src/runtime/plugin.ts',
'./src/runtime/components/index.ts',
'./src/runtime/composables/index.ts',
'./src/runtime/server/*.ts',
],
format: ['esm'],
// Make sure to not bundle the imports
// or else the Nuxt module will not be able to resolve them
Expand Down

0 comments on commit b34edd2

Please sign in to comment.