From ae920a37fd1e4da5dcc1ff77f21c6a01bcc8e36e Mon Sep 17 00:00:00 2001 From: Robert Soriano Date: Sat, 29 Oct 2022 21:50:27 -0700 Subject: [PATCH] make trpc-nuxt flexible by exporting server and client functions instead of nuxt modules --- client.d.ts | 2 +- package.json | 41 +- playground/nuxt.config.ts | 3 - playground/package.json | 16 +- playground/pages/index.vue | 5 +- playground/plugins/trpc-client.ts | 4 +- playground/server/api/trpc/[trpc].ts | 12 + playground/server/trpc/index.ts | 80 +- playground/server/trpc/routers/index.ts | 10 + playground/server/trpc/routers/todo.ts | 33 + playground/server/trpc/routers/user.ts | 33 + playground/tsconfig.json | 4 + pnpm-lock.yaml | 1160 +++++++++++------------ server.d.ts | 1 - src/{runtime => }/client.ts | 4 +- src/index.ts | 1 + src/module.ts | 58 -- src/{runtime => }/server.ts | 16 +- src/{runtime => }/types.ts | 0 tsup.config.ts | 10 + 20 files changed, 713 insertions(+), 780 deletions(-) create mode 100644 playground/server/api/trpc/[trpc].ts create mode 100644 playground/server/trpc/routers/index.ts create mode 100644 playground/server/trpc/routers/todo.ts create mode 100644 playground/server/trpc/routers/user.ts create mode 100644 playground/tsconfig.json delete mode 100644 server.d.ts rename src/{runtime => }/client.ts (96%) create mode 100644 src/index.ts delete mode 100644 src/module.ts rename src/{runtime => }/server.ts (87%) rename src/{runtime => }/types.ts (100%) create mode 100644 tsup.config.ts diff --git a/client.d.ts b/client.d.ts index 047203f..875737f 100644 --- a/client.d.ts +++ b/client.d.ts @@ -1 +1 @@ -export * from './dist/runtime/client' +export * from './dist/client' diff --git a/package.json b/package.json index 045f47c..961215a 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,22 @@ { "name": "trpc-nuxt", - "type": "module", "version": "0.3.1", "packageManager": "pnpm@7.5.0", "license": "MIT", - "main": "./dist/module.cjs", - "types": "./dist/types.d.ts", + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", "exports": { "./package.json": "./package.json", ".": { - "import": "./dist/module.mjs", - "require": "./dist/module.cjs" - }, - "./server": { - "import": "./dist/runtime/server.mjs", - "types": "./dist/runtime/server.d.ts" + "require": "./dist/index.js", + "import": "./dist/index.mjs", + "types": "./dist/index.d.ts" }, "./client": { - "import": "./dist/runtime/client.mjs", - "types": "./dist/runtime/client.d.ts" + "require": "./dist/client.js", + "import": "./dist/client.mjs", + "types": "./dist/client.d.ts" } }, "files": [ @@ -27,40 +25,33 @@ ], "scripts": { "prepublishOnly": "nr build", - "build": "nuxt-module-build", - "play": "nr build && nuxi dev playground", - "build:playground": "nuxi build playground", + "build": "tsup", "lint": "eslint .", "lint:fix": "eslint . --fix", - "release": "bumpp --commit --push --tag && npm publish", - "prepare": "nuxi prepare playground" + "release": "bumpp --commit --push --tag && npm publish" }, "peerDependencies": { "@trpc/client": "^10.0.0-proxy-beta.21", - "@trpc/server": "^10.0.0-proxy-beta.21" + "@trpc/server": "^10.0.0-proxy-beta.21", + "nuxt": "^3.0.0-rc.12" }, "dependencies": { - "@nuxt/kit": "3.0.0-rc.12", - "dedent": "^0.7.0", - "defu": "^6.1.0", "h3": "^0.8.5", "ohash": "^0.1.5", - "pathe": "^0.3.9", + "ohmyfetch": "^0.4.20", "ufo": "^0.8.6" }, "devDependencies": { "@antfu/eslint-config": "^0.23.1", "@antfu/ni": "^0.16.2", - "@nuxt/module-builder": "^0.2.0", "@trpc/client": "10.0.0-rc.1", "@trpc/server": "10.0.0-rc.1", - "@types/dedent": "^0.7.0", "bumpp": "^7.2.0", "eslint": "^8.25.0", "nuxt": "3.0.0-rc.12", "pnpm": "^7.5.0", - "trpc-nuxt": "workspace:*", - "zod": "^3.19.1" + "tsup": "^6.3.0", + "typescript": "4.5.4" }, "eslintConfig": { "extends": "@antfu", diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index b85f10e..970f193 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -1,8 +1,5 @@ -import Module from '../src/module' - // https://v3.nuxtjs.org/api/configuration/nuxt.config export default defineNuxtConfig({ - modules: [Module], runtimeConfig: { baseURL: '', }, diff --git a/playground/package.json b/playground/package.json index 51466b1..e433c56 100644 --- a/playground/package.json +++ b/playground/package.json @@ -1,4 +1,18 @@ { "name": "playground", - "private": true + "private": true, + "scripts": { + "build": "nuxt build", + "dev": "nuxt dev", + "generate": "nuxt generate", + "preview": "nuxt preview", + "postinstall": "nuxt prepare" + }, + "dependencies": { + "trpc-nuxt": "workspace:*", + "zod": "^3.19.1" + }, + "devDependencies": { + "nuxt": "3.0.0-rc.12" + } } diff --git a/playground/pages/index.vue b/playground/pages/index.vue index 1dab210..bd56eed 100644 --- a/playground/pages/index.vue +++ b/playground/pages/index.vue @@ -1,7 +1,6 @@