Skip to content

Commit cba7281

Browse files
committed
publish to npm
1 parent 27e0aca commit cba7281

File tree

10 files changed

+128
-62
lines changed

10 files changed

+128
-62
lines changed

.github/workflows/publish.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: publish
2+
3+
on:
4+
push:
5+
branches: [main]
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-22.04
12+
timeout-minutes: 30
13+
14+
permissions:
15+
contents: read
16+
id-token: write
17+
18+
steps:
19+
- name: Clone repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Deno
23+
uses: denoland/setup-deno@v1
24+
25+
- name: Format
26+
run: deno fmt
27+
28+
- name: Type check
29+
run: deno task test
30+
31+
- name: Publish (dry run)
32+
if: github.event_name == 'push'
33+
run: deno publish --allow-dirty --dry-run
34+
35+
- name: Publish (real)
36+
if: github.event_name == 'release'
37+
run: deno publish --allow-dirty
38+
39+
- name: Build for NPM
40+
run: deno run -A build.ts
41+
42+
- name: NPM (dry run)
43+
if: github.event_name == 'push'
44+
run: npm publish --dry-run
45+
46+
- name: NPM (real)
47+
if: github.event_name == 'release'
48+
run: npm publish --provenance --access public

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
docs/
22
coverage/
33
cov.lcov
4+
node_modules/
5+
dist/
6+
package.json

README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
# json-rpc-ts
22

33
[![deno.land/x](https://shield.deno.dev/x/json_rpc_ts)](https://deno.land/x/json_rpc_ts)
4+
[![JSR](https://jsr.io/badges/@yieldray/json-rpc-ts)](https://jsr.io/@yieldray/json-rpc-ts)
5+
[![npm](https://img.shields.io/npm/v/@yieldray/json-rpc-ts)](https://www.npmjs.com/package/@yieldray/json-rpc-ts)
46
[![codecov](https://codecov.io/gh/YieldRay/json-rpc-ts/graph/badge.svg?token=BabjRkI8jk)](https://codecov.io/gh/YieldRay/json-rpc-ts)
57
[![ci](https://github.com/yieldray/json-rpc-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/yieldray/json-rpc-ts/actions/workflows/ci.yml)
68

79
A strictly typed json-rpc(2.0) implementation, zero dependency, minimal abstraction, with simple api
810

911
> Specification <https://www.jsonrpc.org/specification>
1012
13+
# Installation
14+
15+
For Node.js
16+
17+
```sh
18+
npx jsr add @yieldray/json-rpc-ts # recommended
19+
# or
20+
npm install @yieldray/json-rpc-ts
21+
```
22+
23+
For Deno
24+
25+
```sh
26+
deno add @yieldray/json-rpc-ts
27+
```
28+
29+
# Examples
30+
1131
Example to use the client
1232

1333
```ts
@@ -60,13 +80,3 @@ const httpServer = Deno.serve(
6080
},
6181
)
6282
```
63-
64-
# build for JavaScript
65-
66-
To use this library without typescript, you have to build it to javascript.
67-
68-
```sh
69-
git clone https://github.com/YieldRay/json-rpc-ts.git
70-
cd json-rpc-ts
71-
esbuild --bundle src/index.ts --outdir=dist --format=esm
72-
```

build.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as esbuild from 'npm:esbuild'
2+
3+
console.log(
4+
await esbuild.build({
5+
entryPoints: ['src/index.ts'],
6+
bundle: true,
7+
outdir: 'dist',
8+
format: 'esm',
9+
}),
10+
)
11+
12+
const pkg = JSON.parse(Deno.readTextFileSync('./deno.json'))
13+
14+
if (Deno.statSync('./package.json').isFile) {
15+
Deno.removeSync('./package.json')
16+
}
17+
18+
const packageJson = {
19+
name: pkg.name,
20+
version: pkg.version,
21+
main: 'dist/index.js',
22+
files: ['dist'],
23+
author: 'YieldRay',
24+
license: 'MIT',
25+
repository: {
26+
type: 'git',
27+
url: 'git+https://github.com/YieldRay/json-rpc-ts.git',
28+
},
29+
bugs: {
30+
url: 'https://github.com/YieldRay/json-rpc-ts/issues',
31+
},
32+
homepage: 'https://github.com/YieldRay/json-rpc-ts#readme',
33+
}
34+
35+
console.log(packageJson)
36+
37+
Deno.writeTextFileSync('./package.json', JSON.stringify(packageJson, null, 4))

deno.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@ray/json-rpc-ts",
3-
"version": "0.1.3",
2+
"name": "@yieldray/json-rpc-ts",
3+
"version": "0.2.0",
44
"exports": "./mod.ts",
55
"publish": {
66
"include": [
@@ -21,7 +21,7 @@
2121
"noImplicitOverride": true
2222
},
2323
"imports": {
24-
"std/": "https://deno.land/std@0.220.1/"
24+
"std/": "https://deno.land/std@0.221.0/"
2525
},
2626
"tasks": {
2727
"lint": "deno lint",
@@ -30,7 +30,8 @@
3030
"test": "deno test --parallel --coverage --trace-ops",
3131
"cov:gen": "deno coverage coverage --lcov --output=cov.lcov",
3232
"cov:view": "deno coverage --html coverage",
33-
"cov:clean": "rm -rf ./coverage/ cov.lcov"
33+
"cov:clean": "rm -rf ./coverage/ cov.lcov",
34+
"build": "deno run -A build.ts"
3435
},
3536
"fmt": {
3637
"lineWidth": 80,
@@ -43,12 +44,13 @@
4344
".github",
4445
"deno.json",
4546
"README.md",
46-
"mod.ts"
47+
"*.ts"
4748
]
4849
},
4950
"exclude": [
5051
".git",
5152
"docs",
52-
"coverage"
53+
"coverage",
54+
"dist"
5355
]
5456
}

deno.lock

-37
This file was deleted.

src/client.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {
33
assertInstanceOf,
44
assertObjectMatch,
55
} from 'std/assert/mod.ts'
6-
import { JSONRPCClient, JSONRPCClientParseError } from './client.ts'
7-
import { JSONRPCFulfilledResult } from './types.ts'
8-
import { JSONRPCRequest } from './dto/request.ts'
6+
import type { JSONRPCFulfilledResult } from './types.ts'
7+
import type { JSONRPCRequest } from './dto/request.ts'
98
import { JSONRPCErrorResponse, JSONRPCSuccessResponse } from './dto/response.ts'
9+
import { JSONRPCClient, JSONRPCClientParseError } from './client.ts'
1010
import { JSONRPCError } from './dto/errors.ts'
1111

1212
Deno.test('client', async () => {

src/client.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { JSONRPCMethods, JSONRPCSettledResult } from './types.ts'
2+
import type {
3+
JSONRPCErrorResponse,
4+
JSONRPCSuccessResponse,
5+
} from './dto/response.ts'
26
import { JSONRPCNotification, JSONRPCRequest } from './dto/request.ts'
3-
import { JSONRPCErrorResponse, JSONRPCSuccessResponse } from './dto/response.ts'
4-
import { isJSONRPCResponse, JSONRPCResponse } from './dto/response.ts'
7+
import { isJSONRPCResponse, type JSONRPCResponse } from './dto/response.ts'
58
import { JSONRPCError } from './dto/errors.ts'
69
import {
710
getIDFromGenerator,

src/dto/response.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { JSONRPCValue, WithOptionalJSONRPCVersion } from '../types.ts'
22
import { isJSONRPCID, type JSONRPCID } from '../id.ts'
3-
import { isJSONRPCError, JSONRPCErrorInterface } from './errors.ts'
3+
import { isJSONRPCError, type JSONRPCErrorInterface } from './errors.ts'
44

55
export class JSONRPCSuccessResponse {
66
public jsonrpc = '2.0' as const

src/server.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {
77
} from './dto/errors.ts'
88
import {
99
isJSONRPCRequest,
10-
JSONRPCNotification,
11-
JSONRPCRequest,
10+
type JSONRPCNotification,
11+
type JSONRPCRequest,
1212
} from './dto/request.ts'
1313
import {
1414
JSONRPCErrorResponse,
15-
JSONRPCResponse,
15+
type JSONRPCResponse,
1616
JSONRPCSuccessResponse,
1717
} from './dto/response.ts'
1818
import { isJSONRPCID } from './id.ts'

0 commit comments

Comments
 (0)