Skip to content

Commit 0460fe4

Browse files
committed
Add vanilla esm support and example.
1 parent a386c98 commit 0460fe4

File tree

29 files changed

+398
-27
lines changed

29 files changed

+398
-27
lines changed

.changeset/healthy-tigers-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'electron-trpc': major
3+
---
4+
5+
Breaking change: exposeElectronTRPC is now imported from 'electron-trpc/preload'.

.github/workflows/test.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
node-version: ${{ matrix.node }}
2222
cache: 'pnpm'
2323
- run: pnpm install --frozen-lockfile
24-
- run: pnpm build
24+
- run: pnpm build:code
2525
- run: pnpm test:ci
2626
- uses: codecov/codecov-action@v4
2727

@@ -40,5 +40,10 @@ jobs:
4040
node-version: ${{ matrix.node }}
4141
cache: 'pnpm'
4242
- run: pnpm install --frozen-lockfile
43-
- run: pnpm build
43+
- run: pnpm build:code
44+
- run: |
45+
sudo chown root examples/basic-react/node_modules/electron/dist/chrome-sandbox \
46+
&& sudo chmod 4755 examples/basic-react/node_modules/electron/dist/chrome-sandbox \
47+
&& sudo chown root examples/basic-vanilla-esm/node_modules/electron/dist/chrome-sandbox \
48+
&& sudo chmod 4755 examples/basic-vanilla-esm/node_modules/electron/dist/chrome-sandbox
4449
- run: xvfb-run --auto-servernum -- pnpm test:e2e

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ npm install --save electron-trpc
5858
2. Expose the IPC to the render process from the [preload file](https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts):
5959

6060
```ts
61-
import { exposeElectronTRPC } from 'electron-trpc/main';
61+
import { exposeElectronTRPC } from 'electron-trpc/preload';
6262

6363
process.once('loaded', async () => {
6464
exposeElectronTRPC();

examples/basic-react-superjson/preload/preload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exposeElectronTRPC } from 'electron-trpc/main';
1+
import { exposeElectronTRPC } from 'electron-trpc/preload';
22

33
process.once('loaded', async () => {
44
exposeElectronTRPC();

examples/basic-react-superjson/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"forceConsistentCasingInFileNames": true,
66
"jsx": "react",
77
"lib": ["dom", "esnext"],
8-
"module": "esnext",
8+
"module": "node16",
99
"moduleResolution": "node16",
1010
"noEmit": true,
1111
"noFallthroughCasesInSwitch": true,

examples/basic-react/index.e2e.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { _electron as electron, test, expect } from '@playwright/test';
33
test('Hello Electron', async () => {
44
const electronApp = await electron.launch({
55
args: [`${__dirname}`],
6-
executablePath: process.env.PLAYWRIGHT_ELECTRON_PATH ?? undefined,
6+
executablePath: process.env.PLAYWRIGHT_ELECTRON_PATH || undefined,
7+
env: {
8+
...process.env,
9+
NODE_ENV: 'development',
10+
},
711
});
812

913
const window = await electronApp.firstWindow();

examples/basic-react/preload/preload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { exposeElectronTRPC } from 'electron-trpc/main';
1+
import { exposeElectronTRPC } from 'electron-trpc/preload';
22

33
process.once('loaded', async () => {
44
exposeElectronTRPC();

examples/basic-react/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"forceConsistentCasingInFileNames": true,
66
"jsx": "react",
77
"lib": ["dom", "esnext"],
8-
"module": "esnext",
8+
"module": "node16",
99
"moduleResolution": "node16",
1010
"noEmit": true,
1111
"noFallthroughCasesInSwitch": true,
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# examples/basic
2+
3+
## 0.0.16
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [[`fb7845f`](https://github.com/jsonnull/electron-trpc/commit/fb7845fbc771002309dea9d8b4c2079860350656), [`2bc0233`](https://github.com/jsonnull/electron-trpc/commit/2bc02333172b8a25a493c34c8e17434b8ffb4eea)]:
8+
- electron-trpc@0.6.1
9+
10+
## 0.0.15
11+
12+
### Patch Changes
13+
14+
- Updated dependencies [[`a15c6c4d0c531b3596689b4cc470548a5228c989`](https://github.com/jsonnull/electron-trpc/commit/a15c6c4d0c531b3596689b4cc470548a5228c989), [`50953c7e5bcb69d4e5482405f4a621b229f0ca82`](https://github.com/jsonnull/electron-trpc/commit/50953c7e5bcb69d4e5482405f4a621b229f0ca82)]:
15+
- electron-trpc@0.6.0
16+
17+
## 0.0.14
18+
19+
### Patch Changes
20+
21+
- Updated dependencies [[`0e72fe9`](https://github.com/jsonnull/electron-trpc/commit/0e72fe93b7605636b80cb3b3e47b6992cb4c097a), [`0e72fe9`](https://github.com/jsonnull/electron-trpc/commit/0e72fe93b7605636b80cb3b3e47b6992cb4c097a)]:
22+
- electron-trpc@0.5.2
23+
24+
## 0.0.13
25+
26+
### Patch Changes
27+
28+
- Updated dependencies [[`c43ae93`](https://github.com/jsonnull/electron-trpc/commit/c43ae93df4af397986c602c432fc32178d62796b)]:
29+
- electron-trpc@0.5.1
30+
31+
## 0.0.12
32+
33+
### Patch Changes
34+
35+
- Updated dependencies [[`68ddf63`](https://github.com/jsonnull/electron-trpc/commit/68ddf63ff6b3560626bf78d45ca2bf7ed2851f22)]:
36+
- electron-trpc@0.5.0
37+
38+
## 0.0.11
39+
40+
### Patch Changes
41+
42+
- Updated dependencies [[`70d13e4`](https://github.com/jsonnull/electron-trpc/commit/70d13e400d8b0678a359c633511b419736ef4b5d)]:
43+
- electron-trpc@0.4.5
44+
45+
## 0.0.10
46+
47+
### Patch Changes
48+
49+
- Updated dependencies [[`84d1139`](https://github.com/jsonnull/electron-trpc/commit/84d1139d6b6970b8863fdb1ba22a0aaa709045ec)]:
50+
- electron-trpc@0.4.4
51+
52+
## 0.0.9
53+
54+
### Patch Changes
55+
56+
- Updated dependencies [[`42abc41`](https://github.com/jsonnull/electron-trpc/commit/42abc4182c260580e320e8ec61926ed3ad372940)]:
57+
- electron-trpc@0.4.3
58+
59+
## 0.0.8
60+
61+
### Patch Changes
62+
63+
- Updated dependencies [[`cbae157`](https://github.com/jsonnull/electron-trpc/commit/cbae1570ddeab2405950806656c0d4fc19d72855)]:
64+
- electron-trpc@0.4.2
65+
66+
## 0.0.7
67+
68+
### Patch Changes
69+
70+
- Updated dependencies [[`b73c1a8`](https://github.com/jsonnull/electron-trpc/commit/b73c1a89c77258bf4372991fda563d6fa0ba299f)]:
71+
- electron-trpc@0.4.1
72+
73+
## 0.0.6
74+
75+
### Patch Changes
76+
77+
- Updated dependencies [[`70e8e5c`](https://github.com/jsonnull/electron-trpc/commit/70e8e5c5f3e2654d055663a286c4107a66f362e7)]:
78+
- electron-trpc@0.4.0
79+
80+
## 0.0.5
81+
82+
### Patch Changes
83+
84+
- Updated dependencies [[`46d79ef`](https://github.com/jsonnull/electron-trpc/commit/46d79efde7ccc12cd1e99eb086413aa83bda29f8)]:
85+
- electron-trpc@0.3.2
86+
87+
## 0.0.4
88+
89+
### Patch Changes
90+
91+
- Updated dependencies [[`25b6c5a`](https://github.com/jsonnull/electron-trpc/commit/25b6c5a5cb56a93a4facf7345a10c3bb2db37730), [`25b6c5a`](https://github.com/jsonnull/electron-trpc/commit/25b6c5a5cb56a93a4facf7345a10c3bb2db37730), [`25b6c5a`](https://github.com/jsonnull/electron-trpc/commit/25b6c5a5cb56a93a4facf7345a10c3bb2db37730)]:
92+
- electron-trpc@0.3.1
93+
94+
## 0.0.3
95+
96+
### Patch Changes
97+
98+
- Updated dependencies [[`b67f2a7`](https://github.com/jsonnull/electron-trpc/commit/b67f2a7a87cd77b88d337e6996d78c6507a9c187)]:
99+
- electron-trpc@0.3.0
100+
101+
## 0.0.2
102+
103+
### Patch Changes
104+
105+
- Updated dependencies [[`c9031f5`](https://github.com/jsonnull/electron-trpc/commit/c9031f5b521095d3c648fc905b642471e875d86f)]:
106+
- electron-trpc@0.2.1
107+
108+
## 0.0.1
109+
110+
### Patch Changes
111+
112+
- Updated dependencies [[`231afea`](https://github.com/jsonnull/electron-trpc/commit/231afea9f21f0d4ba7f12c37fd781f22ca5d4141), [`960999f`](https://github.com/jsonnull/electron-trpc/commit/960999f5c2fec8b70152cfdf6cadc737c60edd48), [`3c76498`](https://github.com/jsonnull/electron-trpc/commit/3c76498c152e92fe1b084d3e7a5170d8f2c1dee3), [`7c7ee89`](https://github.com/jsonnull/electron-trpc/commit/7c7ee89b45c6c27527e26b0a6100fc0cb41d8ba6), [`ddc11cb`](https://github.com/jsonnull/electron-trpc/commit/ddc11cb1f1502568a028476acdefdb8d95d9562c), [`4615cf6`](https://github.com/jsonnull/electron-trpc/commit/4615cf63c382a0ea21781efb5093a531cc6378e6), [`006d01e`](https://github.com/jsonnull/electron-trpc/commit/006d01e73a995f756be622769192444bba3b4a87), [`c46f700`](https://github.com/jsonnull/electron-trpc/commit/c46f700b6171835a5b00d6d2c44061acdcd49874), [`42f2b09`](https://github.com/jsonnull/electron-trpc/commit/42f2b09efbaf322af42df176b74f72b972724f99), [`d2870a4`](https://github.com/jsonnull/electron-trpc/commit/d2870a4ef4429053c6a0d3e44bb204d0177adda9)]:
113+
- electron-trpc@0.2.0
114+
115+
## 0.0.1-next.2
116+
117+
### Patch Changes
118+
119+
- Updated dependencies [[`169c47f`](https://github.com/jsonnull/electron-trpc/commit/169c47f325de8899784187af06140c29758b0c0a)]:
120+
- electron-trpc@0.2.0-next.7
121+
122+
## 0.0.1-next.1
123+
124+
### Patch Changes
125+
126+
- Updated dependencies [[`a2103c4`](https://github.com/jsonnull/electron-trpc/commit/a2103c4e9789741aa98aa057fcebf78e4f339d9b)]:
127+
- electron-trpc@0.2.0-next.6
128+
129+
## 0.0.1-next.0
130+
131+
### Patch Changes
132+
133+
- Updated dependencies [[`333197f`](https://github.com/jsonnull/electron-trpc/commit/333197fb3e567aa37f350af992d123f8f8ed6796)]:
134+
- electron-trpc@0.2.0-next.5
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import z from 'zod';
2+
import { initTRPC } from '@trpc/server';
3+
import { observable } from '@trpc/server/observable';
4+
import { EventEmitter } from 'events';
5+
6+
const ee = new EventEmitter();
7+
8+
const t = initTRPC.create({ isServer: true });
9+
10+
export const router = t.router({
11+
greeting: t.procedure.input(z.object({ name: z.string() })).query((req) => {
12+
const { input } = req;
13+
14+
ee.emit('greeting', `Greeted ${input.name}`);
15+
return {
16+
text: `Hello ${input.name}`,
17+
};
18+
}),
19+
subscription: t.procedure.subscription(() => {
20+
return observable((emit) => {
21+
function onGreet(text) {
22+
emit.next({ text });
23+
}
24+
25+
ee.on('greeting', onGreet);
26+
27+
return () => {
28+
ee.off('greeting', onGreet);
29+
};
30+
});
31+
}),
32+
});

0 commit comments

Comments
 (0)