Skip to content

Commit

Permalink
fix: client function import
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Nov 30, 2022
1 parent 58b0af7 commit f444b22
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'url'
import { addImportsDir, addServerHandler, addTemplate, addVitePlugin, defineNuxtModule } from '@nuxt/kit'
import { addImports, addImportsDir, addServerHandler, addTemplate, addVitePlugin, defineNuxtModule } from '@nuxt/kit'
import fg from 'fast-glob'
import { join } from 'pathe'
import dedent from 'dedent'
Expand Down Expand Up @@ -34,6 +34,11 @@ export default defineNuxtModule({
})

addVitePlugin(transformServerFiles())
addImports({
name: 'callRemoteFunction',
as: 'callRemoteFunction',
from: join(runtimeDir, 'client')
})

await scanRemoteFunctions()

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { $fetch } from 'ofetch'

export function callRemoteFunction (path: string, args: any[]) {
return $fetch(`/api/__remote/${path}`, {
export function callRemoteFunction <T> (path: string, args: any[]) {
return $fetch<T>(`/api/__remote/${path}`, {
method: 'POST',
body: {
input: args
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function transformExportsToRemoteFunctions (src: string, moduleId: string)
})

return `
import { callRemoteFunction } from 'nuxt-remote-fn/client'
import { callRemoteFunction } from '#imports'
${exportList.join('\n')}
`
}

0 comments on commit f444b22

Please sign in to comment.