convert to pnpm workspace

This commit is contained in:
Robert Soriano
2022-05-17 08:57:07 -07:00
parent e9224c3c5e
commit 3df0b44d44
25 changed files with 420 additions and 214 deletions

2
.npmrc
View File

@@ -1,2 +1,2 @@
shamefully-hoist=true
ignore-workspace-root-check=true
shamefully-hoist=true

View File

@@ -1,46 +1,18 @@
{
"name": "trpc-nuxt",
"type": "module",
"version": "0.0.3",
"license": "MIT",
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"exports": {
".": {
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
},
"./api": {
"import": "./dist/runtime/api.mjs",
"types": "./dist/runtime/api.d.ts"
}
},
"files": [
"dist",
"*.d.ts"
],
"name": "monorepo",
"packageManager": "pnpm@7.0.0",
"scripts": {
"prepack": "nuxt-module-build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"dev": "nr --parallel --filter trpc-nuxt --filter playground dev",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@nuxt/kit": "^3.0.0-rc.3",
"@trpc/server": "^9.23.2",
"fs-extra": "^10.1.0",
"pathe": "^0.3.0",
"ufo": "^0.8.4"
"lint:fix": "eslint . --fix",
"prepare": "nr --filter playground prepare"
},
"devDependencies": {
"@antfu/eslint-config": "^0.23.1",
"@antfu/ni": "^0.16.2",
"@nuxt/module-builder": "latest",
"@types/fs-extra": "^9.0.13",
"eslint": "latest",
"nuxt": "^3.0.0-rc.3",
"zod": "^3.16.0"
"eslint": "^8.14.0",
"pnpm": "^7.1.0"
},
"eslintConfig": {
"extends": "@antfu"

7
packages/playground/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
node_modules
*.log*
.nuxt
.nitro
.cache
.output
.env

View File

@@ -0,0 +1,42 @@
# Nuxt 3 Minimal Starter
Look at the [nuxt 3 documentation](https://v3.nuxtjs.org) to learn more.
## Setup
Make sure to install the dependencies:
```bash
# yarn
yarn install
# npm
npm install
# pnpm
pnpm install --shamefully-hoist
```
## Development Server
Start the development server on http://localhost:3000
```bash
npm run dev
```
## Production
Build the application for production:
```bash
npm run build
```
Locally preview production build:
```bash
npm run preview
```
Checkout the [deployment documentation](https://v3.nuxtjs.org/docs/deployment) for more information.

View File

@@ -0,0 +1,18 @@
<script setup lang="ts">
const { data, error } = useTrpcQuery('hello')
// const d = useLazyAsyncData('asd', () => $fetch('/api/hello'))
watch(data, (val) => {
console.log('val', val)
console.log('error', error.value)
}, {
immediate: true,
})
</script>
<template>
<div>
{{ data }}
</div>
</template>

View File

@@ -0,0 +1,6 @@
import { defineNuxtConfig } from 'nuxt'
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
modules: ['trpc-nuxt'],
})

View File

@@ -0,0 +1,18 @@
{
"name": "playground",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"prepare": "nuxt prepare"
},
"dependencies": {
"trpc-nuxt": "link:../trpc",
"zod": "^3.16.0"
},
"devDependencies": {
"nuxt": "3.0.0-rc.3"
}
}

View File

@@ -0,0 +1,11 @@
// generated by trpc-nuxt
import * as trpc from '@trpc/server'
export const router = trpc
.router()
.query('hello', {
resolve: () => 'world',
});
export type Router = typeof router

View File

@@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json"
}

1
packages/trpc/client.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
export * from './dist/runtime/client'

View File

@@ -0,0 +1,45 @@
{
"name": "trpc-nuxt",
"type": "module",
"version": "0.0.3",
"license": "MIT",
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"exports": {
".": {
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
},
"./api": {
"import": "./dist/runtime/api.mjs",
"types": "./dist/runtime/api.d.ts"
},
"./client": {
"import": "./dist/runtime/client.mjs",
"types": "./dist/runtime/client.d.ts"
}
},
"files": [
"dist",
"*.d.ts"
],
"scripts": {
"build": "nuxt-module-build",
"dev": "nuxt-module-build --stub"
},
"dependencies": {
"@nuxt/kit": "^3.0.0-rc.3",
"@trpc/client": "^9.23.3",
"@trpc/server": "^9.23.2",
"fs-extra": "^10.1.0",
"h3": "^0.7.8",
"ohash": "^0.1.0",
"pathe": "^0.3.0",
"ufo": "^0.8.4"
},
"devDependencies": {
"@nuxt/module-builder": "latest",
"@types/fs-extra": "^9.0.13",
"nuxt": "^3.0.0-rc.3"
}
}

View File

@@ -0,0 +1,93 @@
import { dirname, join, resolve } from 'pathe'
import { addServerHandler, defineNuxtModule } from '@nuxt/kit'
import fs from 'fs-extra'
export interface ModuleOptions {}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'trpc-nuxt',
configKey: 'trpc',
},
defaults: {},
async setup(_options, nuxt) {
const clientPath = join(nuxt.options.buildDir, 'trpc-client.ts')
const handlerPath = join(nuxt.options.buildDir, 'trpc-handler.ts')
nuxt.hook('config', () => {
nuxt.options.build.transpile.push('trpc-nuxt/client')
})
addServerHandler({
route: '/trpc/*',
handler: handlerPath,
})
nuxt.hook('autoImports:extend', (imports) => {
imports.push(
{ name: 'useTrpcQuery', from: clientPath },
{ name: 'useTrpcLazyQuery', from: clientPath },
{ name: 'useTrpcMutation', from: clientPath },
)
})
const srcDir = nuxt.options.srcDir
const optionsPath = resolve(srcDir, 'server/fn/index.ts')
await fs.ensureDir(dirname(clientPath))
nuxt.options.build.transpile.push('trpc-nuxt/client')
nuxt.hook('autoImports:extend', (imports) => {
imports.push(
{ name: 'useTrpcQuery', as: 'useTrpcQuery', from: clientPath },
{ name: 'useTrpcLazyQuery', as: 'useTrpcLazyQuery', from: clientPath },
{ name: 'useTrpcMutation', as: 'useTrpcMutation', from: clientPath },
)
})
await fs.writeFile(clientPath, `
import * as trpc from '@trpc/client'
import { createTRPCComposables } from 'trpc-nuxt/client'
import { router } from '~/server/fn'
const client = trpc.createTRPCClient<typeof router>({
url: process.browser ? '/trpc' : 'http://localhost:3000/trpc',
})
const {
useTrpcQuery,
useTrpcLazyQuery,
useTrpcMutation
} = createTRPCComposables(client)
export {
useTrpcQuery,
useTrpcLazyQuery,
useTrpcMutation
}
`)
await fs.writeFile(handlerPath, `
import { createTRPCHandler } from 'trpc-nuxt/api'
import * as functions from '~/server/fn'
export default createTRPCHandler({
router: functions.router
})
`)
if (!fs.existsSync(optionsPath)) {
await fs.writeFile(optionsPath, `
// Generated by trpc-nuxt
import * as trpc from '@trpc/server'
export const router = trpc
.router()
.query('hello', {
resolve: () => 'world',
});
export type Router = typeof router
`.trimStart())
}
},
})

View File

@@ -51,7 +51,7 @@ export function createTRPCHandler<Router extends AnyRouter>({
body: isMethod(event, 'GET') ? null : await useBody(event),
query: $url.searchParams,
},
path: $url.pathname.substring(url.length + 5),
path: $url.pathname.substring(url.length + 1),
createContext: async () => createContext?.(req),
responseMeta,
})

View File

@@ -0,0 +1,33 @@
import { objectHash } from 'ohash'
import type { TRPCClient } from '@trpc/client'
import { useAsyncData, useLazyAsyncData } from '#imports'
// type ReturnType<T> = T extends (...args: any) => infer R ? R : never
export function createTRPCComposables<T extends TRPCClient<any>>(client: T): {
useTrpcQuery: (...args: Parameters<typeof client['query']>) => ReturnType<typeof useAsyncData>
useTrpcLazyQuery: (...args: Parameters<typeof client['query']>) => ReturnType<typeof useLazyAsyncData>
useTrpcMutation: (...args: Parameters<typeof client['mutation']>) => ReturnType<typeof useAsyncData>
}
export function createTRPCComposables<
T extends TRPCClient<any>,
>(client: T) {
const useTrpcQuery = (...args: Parameters<typeof client.query>) => {
return useAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.query(...args))
}
const useTrpcLazyQuery = (...args: Parameters<typeof client.query>) => {
return useLazyAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.query(...args))
}
const useTrpcMutation = (...args: Parameters<typeof client.mutation>) => {
return useAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.mutation(...args))
}
return {
useTrpcQuery,
useTrpcLazyQuery,
useTrpcMutation,
}
}

View File

@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2018",
"module": "esnext",
"lib": ["esnext"],
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"strictNullChecks": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true
}
}

View File

@@ -1,8 +0,0 @@
<script setup>
</script>
<template>
<div>
Nuxt module playground!
</div>
</template>

View File

@@ -1,11 +0,0 @@
import { defineNuxtConfig } from 'nuxt'
import MyModule from '..'
export default defineNuxtConfig({
modules: [
MyModule,
],
myModule: {
addPlugin: true,
},
})

View File

@@ -1,4 +0,0 @@
{
"name": "playground",
"private": true
}

View File

@@ -1,11 +0,0 @@
// generated by trpc-nuxt
import * as trpc from '@trpc/server'
export const router = trpc
.router()
.query('hello', {
resolve: () => 'world',
})
export type Router = typeof router

184
pnpm-lock.yaml generated
View File

@@ -5,29 +5,54 @@ importers:
.:
specifiers:
'@antfu/eslint-config': ^0.23.1
'@nuxt/kit': ^3.0.0-rc.3
'@antfu/ni': ^0.16.2
'@nuxt/module-builder': latest
'@trpc/server': ^9.23.2
'@types/fs-extra': ^9.0.13
eslint: latest
fs-extra: ^10.1.0
nuxt: ^3.0.0-rc.3
pathe: ^0.3.0
ufo: ^0.8.4
eslint: ^8.14.0
pnpm: ^7.1.0
devDependencies:
'@antfu/eslint-config': 0.23.1_eslint@8.15.0
'@antfu/ni': 0.16.2
'@nuxt/module-builder': 0.1.7
eslint: 8.15.0
pnpm: 7.1.0
packages/playground:
specifiers:
nuxt: 3.0.0-rc.3
trpc-nuxt: link:../trpc
zod: ^3.16.0
dependencies:
trpc-nuxt: link:../trpc
zod: 3.16.0
devDependencies:
nuxt: 3.0.0-rc.3
packages/trpc:
specifiers:
'@nuxt/kit': ^3.0.0-rc.3
'@nuxt/module-builder': latest
'@trpc/client': ^9.23.3
'@trpc/server': ^9.23.2
'@types/fs-extra': ^9.0.13
fs-extra: ^10.1.0
h3: ^0.7.8
nuxt: ^3.0.0-rc.3
ohash: ^0.1.0
pathe: ^0.3.0
ufo: ^0.8.4
dependencies:
'@nuxt/kit': 3.0.0-rc.3
'@trpc/server': 9.23.3
'@trpc/client': 9.23.4_@trpc+server@9.23.4
'@trpc/server': 9.23.4
fs-extra: 10.1.0
h3: 0.7.8
ohash: 0.1.0
pathe: 0.3.0
ufo: 0.8.4
devDependencies:
'@antfu/eslint-config': 0.23.1_eslint@8.15.0
'@nuxt/module-builder': 0.1.7
'@types/fs-extra': 9.0.13
eslint: 8.15.0
nuxt: 3.0.0-rc.3
zod: 3.16.0
packages:
@@ -38,7 +63,7 @@ packages:
'@jridgewell/gen-mapping': 0.1.1
'@jridgewell/trace-mapping': 0.3.13
/@antfu/eslint-config-basic/0.23.1_doddzorl55y6dbr5ij3nshfl64:
/@antfu/eslint-config-basic/0.23.1_ae4wjpjlz2l2qm7erdt4inxtpu:
resolution: {integrity: sha512-9h0hqK+E/upIrSVTo2Nt2SQoKRqouDhiJcrdkOx3RgvQkcZItuZnpWI2WGDMWQ3WTjE4fYyd+F4p7Mx/QHvX8w==}
peerDependencies:
eslint: '>=7.4.0'
@@ -47,7 +72,7 @@ packages:
eslint-plugin-antfu: 0.23.1_eslint@8.15.0
eslint-plugin-eslint-comments: 3.2.0_eslint@8.15.0
eslint-plugin-html: 6.2.0
eslint-plugin-import: 2.26.0_doddzorl55y6dbr5ij3nshfl64
eslint-plugin-import: 2.26.0_ae4wjpjlz2l2qm7erdt4inxtpu
eslint-plugin-jsonc: 2.2.1_eslint@8.15.0
eslint-plugin-markdown: 2.2.1_eslint@8.15.0
eslint-plugin-n: 15.2.0_eslint@8.15.0
@@ -85,9 +110,9 @@ packages:
eslint: '>=7.4.0'
typescript: '>=3.9'
dependencies:
'@antfu/eslint-config-basic': 0.23.1_doddzorl55y6dbr5ij3nshfl64
'@typescript-eslint/eslint-plugin': 5.23.0_doddzorl55y6dbr5ij3nshfl64
'@typescript-eslint/parser': 5.23.0_eslint@8.15.0
'@antfu/eslint-config-basic': 0.23.1_ae4wjpjlz2l2qm7erdt4inxtpu
'@typescript-eslint/eslint-plugin': 5.24.0_ae4wjpjlz2l2qm7erdt4inxtpu
'@typescript-eslint/parser': 5.24.0_eslint@8.15.0
eslint: 8.15.0
transitivePeerDependencies:
- eslint-import-resolver-typescript
@@ -117,12 +142,12 @@ packages:
dependencies:
'@antfu/eslint-config-react': 0.23.1_eslint@8.15.0
'@antfu/eslint-config-vue': 0.23.1_eslint@8.15.0
'@typescript-eslint/eslint-plugin': 5.23.0_doddzorl55y6dbr5ij3nshfl64
'@typescript-eslint/parser': 5.23.0_eslint@8.15.0
'@typescript-eslint/eslint-plugin': 5.24.0_ae4wjpjlz2l2qm7erdt4inxtpu
'@typescript-eslint/parser': 5.24.0_eslint@8.15.0
eslint: 8.15.0
eslint-plugin-eslint-comments: 3.2.0_eslint@8.15.0
eslint-plugin-html: 6.2.0
eslint-plugin-import: 2.26.0_doddzorl55y6dbr5ij3nshfl64
eslint-plugin-import: 2.26.0_ae4wjpjlz2l2qm7erdt4inxtpu
eslint-plugin-jsonc: 2.2.1_eslint@8.15.0
eslint-plugin-n: 15.2.0_eslint@8.15.0
eslint-plugin-promise: 6.0.0_eslint@8.15.0
@@ -138,6 +163,11 @@ packages:
- typescript
dev: true
/@antfu/ni/0.16.2:
resolution: {integrity: sha512-HZH4I07EYKU4KZLtUYm/zEmaDIhaq51H/qu45uH1AcUPWqMGbB7evE/TnSr0SGInEA+oQs4Is5Vn/PmQhfuU5w==}
hasBin: true
dev: true
/@babel/code-frame/7.16.7:
resolution: {integrity: sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg==}
engines: {node: '>=6.9.0'}
@@ -375,6 +405,13 @@ packages:
- supports-color
dev: true
/@babel/runtime/7.17.9:
resolution: {integrity: sha512-lSiBBvodq29uShpWGNbgFdKYNiFDo5/HIYsaCEY9ff4sb10x9jizo2+pRrSyF4jKZCXqgzuqBOQKbUm90gQwJg==}
engines: {node: '>=6.9.0'}
dependencies:
regenerator-runtime: 0.13.9
dev: false
/@babel/standalone/7.17.11:
resolution: {integrity: sha512-47wVYBeTktYHwtzlFuK7qqV/H5X6mU4MUNqpQ9iiJOqnP8rWL0eX0GWLKRsv8D8suYzhuS1K/dtwgGr+26U7Gg==}
engines: {node: '>=6.9.0'}
@@ -871,8 +908,17 @@ packages:
estree-walker: 2.0.2
picomatch: 2.3.1
/@trpc/server/9.23.3:
resolution: {integrity: sha512-J8TWw/Y5TFp6QGfdry224TgfnkqXETpxAwYZS+dwf3uYCQG49sdl9RUgrf5V2IxVnQA5OXQtjDHJUSzHM7okwQ==}
/@trpc/client/9.23.4_@trpc+server@9.23.4:
resolution: {integrity: sha512-usZgbydmqqzUqJQD5yY9f+KftYBKz6ed0J90MYETqRwXl9XtR9kKOwRRMBQwZDdeMhai3Hlk4sDWeC9HR3auRQ==}
peerDependencies:
'@trpc/server': 9.23.4
dependencies:
'@babel/runtime': 7.17.9
'@trpc/server': 9.23.4
dev: false
/@trpc/server/9.23.4:
resolution: {integrity: sha512-nlOgft5g4BziNplDHhw7f4m9+k8lRPFtVVi8VGxOINt7sQ8pzzEti0WMIl2BX6gugw92t+kae2O5e793AFJs9g==}
dev: false
/@trysound/sax/0.2.0:
@@ -942,8 +988,8 @@ packages:
resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==}
dev: true
/@typescript-eslint/eslint-plugin/5.23.0_doddzorl55y6dbr5ij3nshfl64:
resolution: {integrity: sha512-hEcSmG4XodSLiAp1uxv/OQSGsDY6QN3TcRU32gANp+19wGE1QQZLRS8/GV58VRUoXhnkuJ3ZxNQ3T6Z6zM59DA==}
/@typescript-eslint/eslint-plugin/5.24.0_ae4wjpjlz2l2qm7erdt4inxtpu:
resolution: {integrity: sha512-6bqFGk6wa9+6RrU++eLknKyDqXU1Oc8nyoLu5a1fU17PNRJd9UBr56rMF7c4DRaRtnarlkQ4jwxUbvBo8cNlpw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
'@typescript-eslint/parser': ^5.0.0
@@ -953,10 +999,10 @@ packages:
typescript:
optional: true
dependencies:
'@typescript-eslint/parser': 5.23.0_eslint@8.15.0
'@typescript-eslint/scope-manager': 5.23.0
'@typescript-eslint/type-utils': 5.23.0_eslint@8.15.0
'@typescript-eslint/utils': 5.23.0_eslint@8.15.0
'@typescript-eslint/parser': 5.24.0_eslint@8.15.0
'@typescript-eslint/scope-manager': 5.24.0
'@typescript-eslint/type-utils': 5.24.0_eslint@8.15.0
'@typescript-eslint/utils': 5.24.0_eslint@8.15.0
debug: 4.3.4
eslint: 8.15.0
functional-red-black-tree: 1.0.1
@@ -968,8 +1014,8 @@ packages:
- supports-color
dev: true
/@typescript-eslint/parser/5.23.0_eslint@8.15.0:
resolution: {integrity: sha512-V06cYUkqcGqpFjb8ttVgzNF53tgbB/KoQT/iB++DOIExKmzI9vBJKjZKt/6FuV9c+zrDsvJKbJ2DOCYwX91cbw==}
/@typescript-eslint/parser/5.24.0_eslint@8.15.0:
resolution: {integrity: sha512-4q29C6xFYZ5B2CXqSBBdcS0lPyfM9M09DoQLtHS5kf+WbpV8pBBhHDLNhXfgyVwFnhrhYzOu7xmg02DzxeF2Uw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
@@ -978,25 +1024,25 @@ packages:
typescript:
optional: true
dependencies:
'@typescript-eslint/scope-manager': 5.23.0
'@typescript-eslint/types': 5.23.0
'@typescript-eslint/typescript-estree': 5.23.0
'@typescript-eslint/scope-manager': 5.24.0
'@typescript-eslint/types': 5.24.0
'@typescript-eslint/typescript-estree': 5.24.0
debug: 4.3.4
eslint: 8.15.0
transitivePeerDependencies:
- supports-color
dev: true
/@typescript-eslint/scope-manager/5.23.0:
resolution: {integrity: sha512-EhjaFELQHCRb5wTwlGsNMvzK9b8Oco4aYNleeDlNuL6qXWDF47ch4EhVNPh8Rdhf9tmqbN4sWDk/8g+Z/J8JVw==}
/@typescript-eslint/scope-manager/5.24.0:
resolution: {integrity: sha512-WpMWipcDzGmMzdT7NtTjRXFabx10WleLUGrJpuJLGaxSqpcyq5ACpKSD5VE40h2nz3melQ91aP4Du7lh9FliCA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dependencies:
'@typescript-eslint/types': 5.23.0
'@typescript-eslint/visitor-keys': 5.23.0
'@typescript-eslint/types': 5.24.0
'@typescript-eslint/visitor-keys': 5.24.0
dev: true
/@typescript-eslint/type-utils/5.23.0_eslint@8.15.0:
resolution: {integrity: sha512-iuI05JsJl/SUnOTXA9f4oI+/4qS/Zcgk+s2ir+lRmXI+80D8GaGwoUqs4p+X+4AxDolPpEpVUdlEH4ADxFy4gw==}
/@typescript-eslint/type-utils/5.24.0_eslint@8.15.0:
resolution: {integrity: sha512-uGi+sQiM6E5CeCZYBXiaIvIChBXru4LZ1tMoeKbh1Lze+8BO9syUG07594C4lvN2YPT4KVeIupOJkVI+9/DAmQ==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
eslint: '*'
@@ -1005,7 +1051,7 @@ packages:
typescript:
optional: true
dependencies:
'@typescript-eslint/utils': 5.23.0_eslint@8.15.0
'@typescript-eslint/utils': 5.24.0_eslint@8.15.0
debug: 4.3.4
eslint: 8.15.0
tsutils: 3.21.0
@@ -1013,13 +1059,13 @@ packages:
- supports-color
dev: true
/@typescript-eslint/types/5.23.0:
resolution: {integrity: sha512-NfBsV/h4dir/8mJwdZz7JFibaKC3E/QdeMEDJhiAE3/eMkoniZ7MjbEMCGXw6MZnZDMN3G9S0mH/6WUIj91dmw==}
/@typescript-eslint/types/5.24.0:
resolution: {integrity: sha512-Tpg1c3shTDgTmZd3qdUyd+16r/pGmVaVEbLs+ufuWP0EruVbUiEOmpBBQxBb9a8iPRxi8Rb2oiwOxuZJzSq11A==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dev: true
/@typescript-eslint/typescript-estree/5.23.0:
resolution: {integrity: sha512-xE9e0lrHhI647SlGMl+m+3E3CKPF1wzvvOEWnuE3CCjjT7UiRnDGJxmAcVKJIlFgK6DY9RB98eLr1OPigPEOGg==}
/@typescript-eslint/typescript-estree/5.24.0:
resolution: {integrity: sha512-zcor6vQkQmZAQfebSPVwUk/FD+CvnsnlfKXYeQDsWXRF+t7SBPmIfNia/wQxCSeu1h1JIjwV2i9f5/DdSp/uDw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
typescript: '*'
@@ -1027,8 +1073,8 @@ packages:
typescript:
optional: true
dependencies:
'@typescript-eslint/types': 5.23.0
'@typescript-eslint/visitor-keys': 5.23.0
'@typescript-eslint/types': 5.24.0
'@typescript-eslint/visitor-keys': 5.24.0
debug: 4.3.4
globby: 11.1.0
is-glob: 4.0.3
@@ -1038,16 +1084,16 @@ packages:
- supports-color
dev: true
/@typescript-eslint/utils/5.23.0_eslint@8.15.0:
resolution: {integrity: sha512-dbgaKN21drqpkbbedGMNPCtRPZo1IOUr5EI9Jrrh99r5UW5Q0dz46RKXeSBoPV+56R6dFKpbrdhgUNSJsDDRZA==}
/@typescript-eslint/utils/5.24.0_eslint@8.15.0:
resolution: {integrity: sha512-K05sbWoeCBJH8KXu6hetBJ+ukG0k2u2KlgD3bN+v+oBKm8adJqVHpSSLHNzqyuv0Lh4GVSAUgZ5lB4icmPmWLw==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
peerDependencies:
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0
dependencies:
'@types/json-schema': 7.0.11
'@typescript-eslint/scope-manager': 5.23.0
'@typescript-eslint/types': 5.23.0
'@typescript-eslint/typescript-estree': 5.23.0
'@typescript-eslint/scope-manager': 5.24.0
'@typescript-eslint/types': 5.24.0
'@typescript-eslint/typescript-estree': 5.24.0
eslint: 8.15.0
eslint-scope: 5.1.1
eslint-utils: 3.0.0_eslint@8.15.0
@@ -1056,11 +1102,11 @@ packages:
- typescript
dev: true
/@typescript-eslint/visitor-keys/5.23.0:
resolution: {integrity: sha512-Vd4mFNchU62sJB8pX19ZSPog05B0Y0CE2UxAZPT5k4iqhRYjPnqyY3woMxCd0++t9OTqkgjST+1ydLBi7e2Fvg==}
/@typescript-eslint/visitor-keys/5.24.0:
resolution: {integrity: sha512-qzGwSXMyMnogcAo+/2fU+jhlPPVMXlIH2PeAonIKjJSoDKl1+lJVvG5Z5Oud36yU0TWK2cs1p/FaSN5J2OUFYA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
dependencies:
'@typescript-eslint/types': 5.23.0
'@typescript-eslint/types': 5.24.0
eslint-visitor-keys: 3.3.0
dev: true
@@ -1750,7 +1796,6 @@ packages:
/cookie-es/0.5.0:
resolution: {integrity: sha512-RyZrFi6PNpBFbIaQjXDlFIhFVqV42QeKSZX1yQIl6ihImq6vcHNGMtqQ/QzY3RMPuYSkvsRwtnt5M9NeYxKt0g==}
dev: true
/core-util-is/1.0.3:
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
@@ -2576,7 +2621,7 @@ packages:
- supports-color
dev: true
/eslint-module-utils/2.7.3_cphntlaow2spielwlvsegonsm4:
/eslint-module-utils/2.7.3_bi6p7cyrvxrvblpcgmvuwzeqom:
resolution: {integrity: sha512-088JEC7O3lDZM9xGe0RerkOMd0EjFl+Yvd1jPWIkMT5u3H9+HC34mWWPnqPrN13gieT9pBOO+Qt07Nb/6TresQ==}
engines: {node: '>=4'}
peerDependencies:
@@ -2594,7 +2639,7 @@ packages:
eslint-import-resolver-webpack:
optional: true
dependencies:
'@typescript-eslint/parser': 5.23.0_eslint@8.15.0
'@typescript-eslint/parser': 5.24.0_eslint@8.15.0
debug: 3.2.7
eslint-import-resolver-node: 0.3.6
find-up: 2.1.0
@@ -2605,7 +2650,7 @@ packages:
/eslint-plugin-antfu/0.23.1_eslint@8.15.0:
resolution: {integrity: sha512-GCc4hqHqPPVM4xIFHUKJFpOZbl9C48t9SupePiNjFisUHAxrZj/c1EHCt0LV0TONJHtSZDR53NNWMuB3O2USSg==}
dependencies:
'@typescript-eslint/utils': 5.23.0_eslint@8.15.0
'@typescript-eslint/utils': 5.24.0_eslint@8.15.0
transitivePeerDependencies:
- eslint
- supports-color
@@ -2640,7 +2685,7 @@ packages:
htmlparser2: 7.2.0
dev: true
/eslint-plugin-import/2.26.0_doddzorl55y6dbr5ij3nshfl64:
/eslint-plugin-import/2.26.0_ae4wjpjlz2l2qm7erdt4inxtpu:
resolution: {integrity: sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==}
engines: {node: '>=4'}
peerDependencies:
@@ -2650,14 +2695,14 @@ packages:
'@typescript-eslint/parser':
optional: true
dependencies:
'@typescript-eslint/parser': 5.23.0_eslint@8.15.0
'@typescript-eslint/parser': 5.24.0_eslint@8.15.0
array-includes: 3.1.5
array.prototype.flat: 1.3.0
debug: 2.6.9
doctrine: 2.1.0
eslint: 8.15.0
eslint-import-resolver-node: 0.3.6
eslint-module-utils: 2.7.3_cphntlaow2spielwlvsegonsm4
eslint-module-utils: 2.7.3_bi6p7cyrvxrvblpcgmvuwzeqom
has: 1.0.3
is-core-module: 2.9.0
is-glob: 4.0.3
@@ -3327,7 +3372,6 @@ packages:
destr: 1.1.1
radix3: 0.1.2
ufo: 0.8.4
dev: true
/has-bigints/1.0.2:
resolution: {integrity: sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==}
@@ -4569,7 +4613,6 @@ packages:
/ohash/0.1.0:
resolution: {integrity: sha512-KvclyhWseX6F2UTEEp9Qzybb0LTGorTSVufAToV5tR2B6Q64rVhKhkcU/o+mBaiqGa5+PdobtfSVelp8VOCR6A==}
dev: true
/ohmyfetch/0.4.17:
resolution: {integrity: sha512-jUpCDJIDlTZdS4PE3veoHIXoUSm2NRJfFMIROd29/qeOsbJEoEYBzJ6re+W1hskc44ej11IL//scfhckIcCN8Q==}
@@ -4812,6 +4855,12 @@ packages:
engines: {node: '>=4'}
dev: true
/pnpm/7.1.0:
resolution: {integrity: sha512-iT2Hk2jycfh8NXoEnwpg7oCNMwsMlheSR9QAgkhWtRHvjfAAtp0HsKEOA62ILoAwbvv/ea8Ph5lTQLsGQJRq+w==}
engines: {node: '>=14.19'}
hasBin: true
dev: true
/postcss-calc/8.2.4_postcss@8.4.13:
resolution: {integrity: sha512-SmWMSJmB8MRnnULldx0lQIyhSNvuDl9HfrZkaqqE/WHAhToYsAvDq+yAsA/kIyINDszOp3Rh0GFoNuH5Ypsm3Q==}
peerDependencies:
@@ -5204,7 +5253,6 @@ packages:
/radix3/0.1.2:
resolution: {integrity: sha512-Mpfd/OuX0zoJ6ojLD/RTOHvJPg6e6PjINtmYzV87kIXc5iUtDz34i7gg4SV4XjqRJTmSiYO/g9i/mKWGf4z8wg==}
dev: true
/randombytes/2.1.0:
resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==}
@@ -5307,6 +5355,10 @@ packages:
redis-errors: 1.2.0
dev: true
/regenerator-runtime/0.13.9:
resolution: {integrity: sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==}
dev: false
/regexp-tree/0.1.24:
resolution: {integrity: sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw==}
hasBin: true
@@ -6512,7 +6564,7 @@ packages:
/wide-align/1.1.5:
resolution: {integrity: sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==}
dependencies:
string-width: 1.0.2
string-width: 4.2.3
dev: true
/word-wrap/1.2.3:
@@ -6606,4 +6658,4 @@ packages:
/zod/3.16.0:
resolution: {integrity: sha512-szrIkryADbTM+xBt2a1KoS2CJQXec4f9xG78bj5MJeEH/XqmmHpnO+fG3IE115AKBJak+2HrbxLZkc9mhdbDKA==}
dev: true
dev: false

View File

@@ -1,2 +1,2 @@
packages:
- playground
- packages/*

View File

@@ -1,72 +0,0 @@
import { fileURLToPath } from 'url'
import { dirname, resolve } from 'path'
import { addServerHandler, addTemplate, defineNuxtModule } from '@nuxt/kit'
import fs from 'fs-extra'
export interface ModuleOptions {}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'trpc-nuxt',
configKey: 'trpc',
},
defaults: {},
async setup(_options, nuxt) {
const srcDir = nuxt.options.srcDir
// const root = nuxt.options.rootDir
// const clientPath = join(nuxt.options.buildDir, 'trpc-client.ts')
// const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
// const serverPath = resolve(root, 'server/fn')
const buildDir = fileURLToPath(new URL(nuxt.options.buildDir, import.meta.url))
// const rootDir = fileURLToPath(new URL(root, import.meta.url))
// nuxt.hook('config', (options) => {
// options.build.transpile.push('trpc-nuxt/client')
// })
// nuxt.hook('autoImports:extend', (imports) => {
// imports.push({
// from: clientPath,
// name: 'useServerFn',
// as: 'useServerFn',
// })
// })
const routePath = resolve(srcDir, 'server/fn/index.ts')
await fs.ensureDir(dirname(routePath))
if (!fs.existsSync(routePath)) {
await fs.writeFile(routePath, `
// generated by trpc-nuxt
import * as trpc from '@trpc/server'
export const router = trpc
.router()
.query('hello', {
resolve: () => 'world',
});
export type Router = typeof router
`.trimStart())
}
const handlerPath = resolve(srcDir, 'server/fn')
addTemplate({
filename: 'trpc-handler.mjs',
write: true,
getContents() {
return `
import { createTRPCHandler } from 'trpc-nuxt/api'
import * as functions from "${handlerPath}"
export default createTRPCHandler({
router: functions.router
})
`.trimStart()
},
})
addServerHandler({
route: '/api/trpc/*',
handler: resolve(buildDir, 'trpc-handler.mjs'),
})
},
})

View File

@@ -1,3 +0,0 @@
{
"extends": "./playground/.nuxt/tsconfig.json"
}