Skip to content

Commit 4312a28

Browse files
authored
Merge pull request #350 from open-rpc/feat/esm
Feat/esm
2 parents 6639ee3 + 1096a86 commit 4312a28

40 files changed

+2093
-17371
lines changed

.circleci/config.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,28 @@ aliases:
2222
branches:
2323
only: /^(pull|dependabot|fix|feat)\/.*$/
2424

25+
# -------------------------
26+
# ALIASES: Bun Install
27+
# -------------------------
28+
- &install-bun
29+
name: Install Bun
30+
command: |
31+
curl -fsSL https://bun.sh/install | bash -s "bun-v1.3.1"
32+
echo 'export PATH="$HOME/.bun/bin:$PATH"' >> $BASH_ENV
33+
2534
defaults: &defaults
2635
working_directory: ~/client-js
2736
docker:
28-
- image: cimg/node:20.11.0
37+
- image: cimg/node:24.10.0
2938

3039
jobs:
3140
test:
3241
<<: *defaults
3342
steps:
3443
- checkout
44+
- run: *install-bun
3545
- restore_cache: *restore-deps-cache
36-
- run: npm install
46+
- run: bun install
3747
- run: npm install codecov
3848
- run: npm test
3949
- run: ./node_modules/.bin/codecov
@@ -43,18 +53,20 @@ jobs:
4353
<<: *defaults
4454
steps:
4555
- checkout
56+
- run: *install-bun
4657
- restore_cache: *restore-deps-cache
47-
- run: npm install
48-
- run: npm run build
58+
- run: bun install
59+
- run: bun run build
4960
- save_cache: *save-deps-cache
5061

5162
release:
5263
<<: *defaults
5364
steps:
5465
- checkout
66+
- run: *install-bun
5567
- restore_cache: *restore-deps-cache
56-
- run: npm install
57-
- run: npm run build
68+
- run: bun install
69+
- run: bun run build
5870
- run: npm install semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/github @semantic-release/npm @semantic-release/commit-analyzer @semantic-release/release-notes-generator @qiwi/semantic-release-gh-pages-plugin
5971
- run: git checkout .
6072
- run: ./node_modules/.bin/semantic-release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ build
44
.DS_Store
55
node_modules
66
coverage
7+
dist

.prettierc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"endOfLine": "lf",
3+
"bracketSameLine": false,
4+
"arrowParens": "always",
5+
"bracketSpacing": true,
6+
"useTabs": false,
7+
"tabWidth": 2,
8+
"printWidth": 100,
9+
"trailingComma": "es5",
10+
"singleQuote": true,
11+
"semi": true
12+
}

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ A browser-compatible JSON-RPC client with multiple transports:
2020
- PostMessageWindow
2121
- PostMessageIframe
2222

23-
2423
```javascript
2524
import { RequestManager, HTTPTransport, Client } from "@open-rpc/client-js";
2625
const transport = new HTTPTransport("http://localhost:8545");
2726
const client = new Client(new RequestManager([transport]));
28-
const result = await client.request({method: "addition", params: [2, 2]});
27+
const result = await client.request({ method: "addition", params: [2, 2] });
2928
// => { jsonrpc: '2.0', id: 1, result: 4 }
3029
```
3130

@@ -36,7 +35,11 @@ const result = await client.request({method: "addition", params: [2, 2]});
3635

3736
```javascript
3837
import { EventEmitter } from "events";
39-
import { RequestManager, EventEmitterTransport, Client } from "@open-rpc/client-js";
38+
import {
39+
RequestManager,
40+
EventEmitterTransport,
41+
Client,
42+
} from "@open-rpc/client-js";
4043

4144
const chan1 = "chan1";
4245
const chan2 = "chan2";
@@ -57,7 +60,7 @@ emitter.on(chan1, (jsonrpcRequest) => {
5760
});
5861

5962
const main = async () => {
60-
const result = await client.request({method: "addition", params: [2, 2]});
63+
const result = await client.request({ method: "addition", params: [2, 2] });
6164
console.log(result);
6265
};
6366

@@ -68,7 +71,6 @@ main().then(() => {
6871

6972
</details>
7073

71-
7274
<details>
7375
<summary>HTTP</summary>
7476

@@ -80,7 +82,7 @@ const requestManager = new RequestManager([transport]);
8082
const client = new Client(requestManager);
8183

8284
const main = async () => {
83-
const result = await client.request({method: "addition", params: [2, 2]});
85+
const result = await client.request({ method: "addition", params: [2, 2] });
8486
console.log(result);
8587
};
8688

@@ -91,31 +93,43 @@ main().then(() => {
9193

9294
</details>
9395

94-
9596
<details>
9697
<summary>WebSocket</summary>
9798

9899
```javascript
99-
import { RequestManager, Client, WebSocketTransport } from "@open-rpc/client-js";
100+
import {
101+
RequestManager,
102+
Client,
103+
WebSocketTransport,
104+
} from "@open-rpc/client-js";
100105

101106
const transport = new WebSocketTransport("ws://localhost:3333");
102107
const requestManager = new RequestManager([transport]);
103108
const client = new Client(requestManager);
104109

105110
const main = async () => {
106-
const result = await client.request({method: "addition", params: [2, 2]});
111+
const result = await client.request({ method: "addition", params: [2, 2] });
107112
console.log(result);
108113
};
109114

110115
main().then(() => {
111116
console.log("DONE");
112117
client.close();
113118
});
114-
115119
```
116120

117121
</details>
118122

123+
### Building
124+
125+
```sh
126+
# Install bun
127+
curl -fsSL https://bun.sh/install | bash
128+
129+
# Build the repo
130+
bun install
131+
bun run build
132+
```
119133

120134
### Contributing
121135

build.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bun
2+
import { $ } from "bun";
3+
4+
const baseConfig = {
5+
entrypoints: ["./src/index.ts"],
6+
sourcemap: "external",
7+
minify: false,
8+
splitting: false,
9+
};
10+
11+
12+
await Bun.build({
13+
...baseConfig,
14+
outdir: "./dist",
15+
target: "node",
16+
format: "esm",
17+
external: ["ws", "isomorphic-ws"],
18+
});
19+
20+
await Bun.build({
21+
...baseConfig,
22+
outdir: "./dist/browser",
23+
target: "browser",
24+
format: "esm",
25+
});

0 commit comments

Comments
 (0)