forked from jsonnull/electron-trpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pnpm workspaces, add working example. (jsonnull#29)
* Use pnpm workspaces, add working example. * Add example build to CI workflow. * Add changeset for fix.
- Loading branch information
Showing
30 changed files
with
751 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'electron-trpc': patch | ||
--- | ||
|
||
Fix transformer path. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
node_modules | ||
/dist | ||
/coverage | ||
examples/*/dist | ||
examples/*/coverage | ||
examples/*/*/dist | ||
examples/*/*/coverage | ||
packages/*/dist | ||
packages/*/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import z from 'zod'; | ||
import { initTRPC } from '@trpc/server'; | ||
|
||
const t = initTRPC.create({ isServer: true }); | ||
|
||
export const router = t.router({ | ||
greeting: t.procedure.input(z.object({ name: z.string() })).query((req) => { | ||
const { input } = req; | ||
|
||
return { | ||
text: `Hello ${input.name}` as const, | ||
}; | ||
}), | ||
}); | ||
|
||
export type AppRouter = typeof router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import path from 'path'; | ||
import { app, ipcMain, BrowserWindow } from 'electron'; | ||
import { createIPCHandler } from 'electron-trpc'; | ||
import { router } from './api'; | ||
|
||
app.on('ready', () => { | ||
createIPCHandler({ ipcMain, router: router as any }); | ||
|
||
const win = new BrowserWindow({ | ||
webPreferences: { | ||
preload: path.resolve(__dirname, 'preload.js'), | ||
}, | ||
}); | ||
|
||
win.loadFile(path.resolve(__dirname, '../../renderer/dist/index.html')); | ||
|
||
win.show(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { contextBridge, ipcRenderer } from 'electron'; | ||
import { exposeElectronTRPC } from 'electron-trpc'; | ||
|
||
process.once('loaded', async () => { | ||
exposeElectronTRPC({ contextBridge, ipcRenderer }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"alwaysStrict": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"lib": ["dom", "es2017"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"outDir": "dist", | ||
"resolveJsonModule": true, | ||
"strict": true, | ||
"target": "esnext" | ||
}, | ||
"include": ["./*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "examples/basic", | ||
"description": "Electron support for tRPC", | ||
"version": "0.0.0", | ||
"private": true, | ||
"main": "main/dist/main.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "electron .", | ||
"build": "tsc -p main && tsc -p renderer && vite build renderer " | ||
}, | ||
"dependencies": { | ||
"@tanstack/react-query": "^4.8.0", | ||
"@trpc/client": "10.0.0-proxy-beta.25", | ||
"@trpc/react": "10.0.0-proxy-beta.11", | ||
"@trpc/react-query": "10.0.0-proxy-beta.25", | ||
"@trpc/server": "10.0.0-proxy-beta.25", | ||
"electron": "^19.0.9", | ||
"electron-trpc": "0.2.0-next.2", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"zod": "^3.19.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17.0.10", | ||
"@types/react": "^18.0.21", | ||
"@types/react-dom": "^18.0.6", | ||
"@vitejs/plugin-react": "^2.1.0", | ||
"vite": "^3.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'" /> | ||
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'" /> | ||
<title>Hello from Electron renderer!</title> | ||
</head> | ||
<body> | ||
<div id="react-root"></div> | ||
</body> | ||
<script type="module" src="./index"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useState } from 'react'; | ||
import ReactDom from 'react-dom'; | ||
import { ipcLink } from 'electron-trpc'; | ||
import { createTRPCReact } from '@trpc/react-query'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import type { AppRouter } from '../main/api'; | ||
|
||
const trpcReact = createTRPCReact<AppRouter>(); | ||
|
||
function App() { | ||
const [queryClient] = useState(() => new QueryClient()); | ||
const [trpcClient] = useState(() => | ||
trpcReact.createClient({ | ||
links: [ipcLink()], | ||
}) | ||
); | ||
|
||
return ( | ||
<trpcReact.Provider client={trpcClient} queryClient={queryClient}> | ||
<QueryClientProvider client={queryClient}> | ||
<HelloElectron /> | ||
</QueryClientProvider> | ||
</trpcReact.Provider> | ||
); | ||
} | ||
|
||
function HelloElectron() { | ||
const { data } = trpcReact.greeting.useQuery({ name: 'Electron' }); | ||
|
||
if (!data) { | ||
return null; | ||
} | ||
|
||
return <div>{data.text}</div>; | ||
} | ||
|
||
ReactDom.render(<App />, document.getElementById('react-root')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"alwaysStrict": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"jsx": "react", | ||
"lib": ["dom", "es2017"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noEmit": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"target": "esnext" | ||
}, | ||
"include": ["./*.ts", "./*.tsx"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
|
||
export default defineConfig({ | ||
base: './', | ||
define: { | ||
'process.env': {}, | ||
}, | ||
plugins: [react()], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,17 @@ | ||
{ | ||
"name": "electron-trpc", | ||
"description": "Electron support for tRPC", | ||
"version": "0.2.0-next.2", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"author": "Jason Nall <[email protected]>", | ||
"license": "MIT", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts", | ||
"test": "vitest", | ||
"test:coverage": "vitest run --coverage", | ||
"build": "pnpm --filter=electron-trpc build", | ||
"test": "pnpm --filter=electron-trpc test", | ||
"test:coverage": "pnpm --filter=electron-trpc test:coverage", | ||
"prepublish": "yarn build", | ||
"changeset": "changeset", | ||
"release": "changeset publish" | ||
}, | ||
"devDependencies": { | ||
"@changesets/changelog-github": "^0.4.6", | ||
"@changesets/cli": "^2.24.1", | ||
"@tanstack/react-query": "^4.8.0", | ||
"@trpc/client": "10.0.0-proxy-beta.11", | ||
"@trpc/react": "10.0.0-proxy-beta.11", | ||
"@trpc/server": "10.0.0-proxy-beta.11", | ||
"@types/node": "^17.0.10", | ||
"builtin-modules": "^3.3.0", | ||
"c8": "^7.12.0", | ||
"dts-bundle-generator": "^6.12.0", | ||
"electron": "^19.0.9", | ||
"prettier": "^2.5.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"typescript": "^4.5.5", | ||
"vite": "^3.0.3", | ||
"vite-plugin-commonjs-externals": "^0.1.1", | ||
"vitest": "^0.19.1", | ||
"zod": "^3.19.1" | ||
}, | ||
"peerDependencies": { | ||
"@trpc/client": "10.0.0-proxy-beta.11", | ||
"@trpc/server": "10.0.0-proxy-beta.11", | ||
"electron": ">19.0.0" | ||
"typescript": "^4.5.5" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "electron-trpc", | ||
"description": "Electron support for tRPC", | ||
"version": "0.2.0-next.2", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"author": "Jason Nall <[email protected]>", | ||
"license": "MIT", | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"scripts": { | ||
"build": "tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts", | ||
"test": "vitest", | ||
"test:coverage": "vitest run --coverage", | ||
"prepublish": "yarn build", | ||
"changeset": "changeset", | ||
"release": "changeset publish" | ||
}, | ||
"devDependencies": { | ||
"@tanstack/react-query": "^4.8.0", | ||
"@trpc/client": "10.0.0-proxy-beta.25", | ||
"@trpc/react": "10.0.0-proxy-beta.20", | ||
"@trpc/server": "10.0.0-proxy-beta.25", | ||
"@types/node": "^17.0.10", | ||
"builtin-modules": "^3.3.0", | ||
"c8": "^7.12.0", | ||
"dts-bundle-generator": "^6.12.0", | ||
"electron": "^19.0.9", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"vite": "^3.0.3", | ||
"vite-plugin-commonjs-externals": "^0.1.1", | ||
"vitest": "^0.19.1", | ||
"zod": "^3.19.1" | ||
}, | ||
"peerDependencies": { | ||
"@trpc/client": "10.0.0-proxy-beta.11", | ||
"@trpc/server": "10.0.0-proxy-beta.11", | ||
"electron": ">19.0.0" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.