Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ef1d5d0
Add pre-release workflow in next branch.
jsonnull Oct 21, 2022
d392431
Add pre-release update for tRPC v10.
jsonnull Oct 21, 2022
9042876
Version Packages (next) (#23)
github-actions[bot] Oct 21, 2022
eba2b98
Change electron peer to minimum version. (#24)
jsonnull Oct 21, 2022
e9313a2
Version Packages (next) (#25)
github-actions[bot] Oct 21, 2022
073eecb
Fix server import from ipcLink. (#26)
jsonnull Oct 21, 2022
ef9df5e
Version Packages (next) (#27)
github-actions[bot] Oct 21, 2022
6d5ef0a
Use pnpm workspaces, add working example. (#29)
jsonnull Oct 23, 2022
228bf97
Remove example version. (#31)
jsonnull Oct 23, 2022
4d56516
Ignore examples in changesets. (#32)
jsonnull Oct 23, 2022
da6ba09
Re-add example version. (#33)
jsonnull Oct 23, 2022
3cadbd5
Version Packages (next) (#30)
github-actions[bot] Oct 23, 2022
7d412af
Fix lockfile, update trpc deps. (#34)
jsonnull Oct 23, 2022
6c0b801
fix: specify exported types in the exports field (#37)
skyrpex Oct 28, 2022
702b9af
Add changeset for types fix. (#39)
jsonnull Oct 28, 2022
6ff6963
Upgrade to tRPC v10 rc.1. (#41)
jsonnull Oct 28, 2022
9bb1b9f
Version Packages (next) (#40)
github-actions[bot] Oct 28, 2022
72b551c
Fix lockfile. (#42)
jsonnull Oct 28, 2022
b0cb440
Fix versioning. (#43)
jsonnull Oct 28, 2022
ed7446c
Configure Renovate (#44)
renovate[bot] Oct 30, 2022
b72fd58
Add renovate changeset workflow. (#48)
jsonnull Oct 30, 2022
dec2830
Update dependency workflow filter. (#49)
jsonnull Oct 30, 2022
333197f
Update trpc monorepo to v10.0.0-rc.2 (#45)
renovate[bot] Oct 30, 2022
19c617a
Remove automate renovate changesets. (#50)
jsonnull Oct 30, 2022
0c843d6
Update actions/checkout action to v3 (#51)
renovate[bot] Oct 30, 2022
c202161
Update dependency @types/node to v18 (#52)
renovate[bot] Oct 30, 2022
d6d6419
Update dependency vitest to ^0.24.0 (#46)
renovate[bot] Oct 30, 2022
2a70744
Version Packages (next) (#53)
github-actions[bot] Oct 30, 2022
2eab61c
Update dependency dts-bundle-generator to v7 (#55)
renovate[bot] Oct 30, 2022
fa9ffad
Update trpc monorepo to v10.0.0-rc.4 (#57)
renovate[bot] Nov 5, 2022
a2103c4
Simplify API surface area. (#58)
jsonnull Nov 5, 2022
2c71bd3
Version Packages (next) (#54)
github-actions[bot] Nov 5, 2022
bb31117
Update trpc monorepo to v10.0.0-rc.6 (#60)
renovate[bot] Nov 7, 2022
07373ef
Update vitest monorepo to ^0.25.0 (#61)
renovate[bot] Nov 10, 2022
169c47f
Update trpc monorepo to v10.0.0-rc.7 (#62)
renovate[bot] Nov 10, 2022
e684e1b
Version Packages (next) (#63)
github-actions[bot] Nov 10, 2022
533df2b
Back out 'automatic preload' changes. (#65)
jsonnull Nov 11, 2022
52d4cd1
Fix peer-dependency versions. (#66)
jsonnull Nov 11, 2022
3e19fca
Update trpc monorepo to v10.4.3 (#67)
renovate[bot] Dec 6, 2022
32e3b64
Finish prerelease.
jsonnull Dec 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"updateInternalDependencies": "patch"
}
5 changes: 5 additions & 0 deletions .changeset/green-badgers-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': patch
---

Set minimum version for electron peer dependency.
5 changes: 5 additions & 0 deletions .changeset/healthy-wolves-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': patch
---

Updated API to be simpler and require fewer steps.
5 changes: 5 additions & 0 deletions .changeset/kind-tables-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': patch
---

Update tRPC to rc.7.
20 changes: 20 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"mode": "exit",
"tag": "next",
"initialVersions": {
"electron-trpc": "0.1.0",
"examples/basic": "0.0.0",
"examples/custom-preload": "0.0.1-next.0"
},
"changesets": [
"green-badgers-move",
"healthy-wolves-boil",
"kind-tables-prove",
"rotten-forks-design",
"sharp-crews-melt",
"sweet-grapes-eat",
"ten-bobcats-ring",
"unlucky-seas-divide",
"wild-dots-change"
]
}
5 changes: 5 additions & 0 deletions .changeset/rotten-forks-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': patch
---

Upgrade to tRPC v10 rc.1.
5 changes: 5 additions & 0 deletions .changeset/sharp-crews-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': patch
---

Fix transformer path.
5 changes: 5 additions & 0 deletions .changeset/sweet-grapes-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': patch
---

Update tRPC to rc.2.
5 changes: 5 additions & 0 deletions .changeset/tasty-carrots-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': minor
---

Update electron-trpc to v10 release.
5 changes: 5 additions & 0 deletions .changeset/ten-bobcats-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': minor
---

Move to tRPC v10.
5 changes: 5 additions & 0 deletions .changeset/unlucky-seas-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': patch
---

Fix server import from ipcLink.
5 changes: 5 additions & 0 deletions .changeset/wild-dots-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'electron-trpc': patch
---

Fix TypeScript type resolution. (Authored by @skyrpex, thanks!)
34 changes: 31 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
Expand All @@ -19,10 +19,11 @@ jobs:
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm build
- run: pnpm --filter=examples/basic build
- run: pnpm test:coverage
- uses: codecov/codecov-action@v3

release:
release-main:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -33,7 +34,34 @@ jobs:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- uses: changesets/action@v1
with:
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

release-next:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['16.x']
os: [ubuntu-latest]

needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/next'

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
/dist
/coverage
dist/
dist-electron/
coverage/
packages/electron-trpc/renderer.d.ts
packages/electron-trpc/main.d.ts
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# electron-trpc

## 0.2.0-next.2

### Patch Changes

- [#26](https://github.com/jsonnull/electron-trpc/pull/26) [`073eecb`](https://github.com/jsonnull/electron-trpc/commit/073eecb504917ad7e8865a8f904827ca0a4ca2ba) Thanks [@jsonnull](https://github.com/jsonnull)! - Fix server import from ipcLink.

## 0.2.0-next.1

### Patch Changes

- [#24](https://github.com/jsonnull/electron-trpc/pull/24) [`eba2b98`](https://github.com/jsonnull/electron-trpc/commit/eba2b98506bcf4590a3689397f445a0443fa9188) Thanks [@jsonnull](https://github.com/jsonnull)! - Set minimum version for electron peer dependency.

## 0.2.0-next.0

### Minor Changes

- [`d392431`](https://github.com/jsonnull/electron-trpc/commit/d39243176897dd7cd209d768db68dc90cab92c58) Thanks [@jsonnull](https://github.com/jsonnull)! - Move to tRPC v10.

## 0.1.0

### Minor Changes
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,34 @@ yarn add electron-trpc
npm install --save electron-trpc
```

## Setup
## Basic Setup

1. Add your tRPC router to the Electron main process using `createIPCHandler`:

```ts
import { app, ipcMain } from 'electron';
import { createIPCHandler } from 'electron-trpc';
import { router, createContext } from './api';
import { app } from 'electron';
import { createIPCHandler } from 'electron-trpc/main';
import { router } from './api';

app.on('ready', () => {
createIPCHandler({ ipcMain, router, createContext });

// ...
createIPCHandler({ router });

const win = new BrowserWindow({
webPreferences: {
// Replace this path with the path to your preload file (see next step)
preload: 'path/to/preload.js',
},
});
});
```

2. Expose the IPC to the render process from the [preload file](https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts):

```ts
import { contextBridge, ipcRenderer } from 'electron';
import { exposeElectronTRPC } from 'electron-trpc';

process.once('loaded', async () => {
exposeElectronTRPC({ contextBridge, ipcRenderer });
exposeElectronTRPC();
});
```

Expand All @@ -67,7 +71,7 @@ npm install --save electron-trpc

```ts
import * as trpc from '@trpc/client';
import { ipcLink } from 'electron-trpc';
import { ipcLink } from 'electron-trpc/renderer';

export const trpcClient = trpc.createTRPCClient({
links: [ipcLink()],
Expand Down
11 changes: 0 additions & 11 deletions dts-bundle-generator.config.ts

This file was deleted.

22 changes: 22 additions & 0 deletions examples/basic/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# examples/basic

## 0.0.1-next.2

### Patch Changes

- Updated dependencies [[`169c47f`](https://github.com/jsonnull/electron-trpc/commit/169c47f325de8899784187af06140c29758b0c0a)]:
- electron-trpc@0.2.0-next.7

## 0.0.1-next.1

### Patch Changes

- Updated dependencies [[`a2103c4`](https://github.com/jsonnull/electron-trpc/commit/a2103c4e9789741aa98aa057fcebf78e4f339d9b)]:
- electron-trpc@0.2.0-next.6

## 0.0.1-next.0

### Patch Changes

- Updated dependencies [[`333197f`](https://github.com/jsonnull/electron-trpc/commit/333197fb3e567aa37f350af992d123f8f8ed6796)]:
- electron-trpc@0.2.0-next.5
16 changes: 16 additions & 0 deletions examples/basic/electron/api.ts
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;
28 changes: 28 additions & 0 deletions examples/basic/electron/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import path from 'path';
import { app, BrowserWindow } from 'electron';
import { createIPCHandler } from 'electron-trpc/main';
import { router } from './api';

process.env.DIST = path.join(__dirname, '../dist');
process.env.PUBLIC = app.isPackaged ? process.env.DIST : path.join(process.env.DIST, '../public');

const preload = path.join(__dirname, './preload.js');
const url = process.env['VITE_DEV_SERVER_URL'];

app.on('ready', () => {
createIPCHandler({ router });

const win = new BrowserWindow({
webPreferences: {
preload,
},
});

if (url) {
win.loadURL(url);
} else {
win.loadFile(path.join(process.env.DIST, 'index.html'));
}

win.show();
});
14 changes: 14 additions & 0 deletions examples/basic/index.html
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="./src/index.tsx"></script>
</html>
31 changes: 31 additions & 0 deletions examples/basic/package.json
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.1-next.2",
"private": true,
"main": "dist-electron/index.js",
"license": "MIT",
"scripts": {
"start": "vite",
"build": "vite build"
},
"dependencies": {
"@tanstack/react-query": "^4.8.0",
"@trpc/client": "10.4.3",
"@trpc/react-query": "10.4.3",
"@trpc/server": "10.4.3",
"electron": "^21.2.2",
"electron-trpc": "0.2.0-next.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zod": "^3.19.1"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.1.0",
"vite": "^3.0.3",
"vite-plugin-electron": "^0.10.3"
}
}
5 changes: 5 additions & 0 deletions examples/basic/preload/preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { exposeElectronTRPC } from 'electron-trpc/main';

process.once('loaded', async () => {
exposeElectronTRPC();
});
Loading