Skip to content

Commit 0ed5ed7

Browse files
committed
improve CI
1 parent b86e6b7 commit 0ed5ed7

File tree

11 files changed

+76
-58
lines changed

11 files changed

+76
-58
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
deno:
17-
- v1.x
18-
- canary
17+
- v2.x
1918
os:
2019
- ubuntu-22.04
2120
- windows-2022
22-
- macOS-12
2321

2422
steps:
2523
- name: Clone repository
@@ -28,11 +26,11 @@ jobs:
2826
submodules: true
2927

3028
- name: Set up Deno
31-
uses: denoland/setup-deno@v1
29+
uses: denoland/setup-deno@v2
3230
with:
3331
deno-version: ${{ matrix.deno }}
3432

35-
- name: Run tests canary
33+
- name: Run tests
3634
run: deno task test
3735

3836
- name: Generate lcov
@@ -56,12 +54,25 @@ jobs:
5654
persist-credentials: false
5755

5856
- name: Set up Deno
59-
uses: denoland/setup-deno@v1
60-
with:
61-
deno-version: canary
57+
uses: denoland/setup-deno@v2
6258

6359
- name: Format
6460
run: deno fmt --check
6561

6662
- name: Lint
6763
run: deno task lint
64+
65+
- name: Build for NPM
66+
run: deno task build
67+
68+
- name: Publish (dry run)
69+
run: deno publish --allow-dirty --dry-run
70+
71+
- name: Set up Node
72+
uses: actions/setup-node@v4
73+
with:
74+
node-version: '22.x'
75+
registry-url: 'https://registry.npmjs.org'
76+
77+
- name: NPM (dry run)
78+
run: npm publish --dry-run

.github/workflows/publish.yml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: publish
33
on:
44
push:
55
branches: [main]
6-
release:
7-
types: [published]
86

97
jobs:
108
publish:
@@ -20,37 +18,32 @@ jobs:
2018
uses: actions/checkout@v4
2119

2220
- name: Set up Deno
23-
uses: denoland/setup-deno@v1
21+
uses: denoland/setup-deno@v2
2422

2523
- name: Format
2624
run: deno fmt
2725

2826
- name: Type check
2927
run: deno task test
3028

31-
- name: Publish (dry run)
32-
if: github.event_name == 'push'
33-
run: deno publish --allow-dirty --dry-run
29+
- name: Build for NPM
30+
run: deno task build
3431

3532
- name: Publish (real)
36-
if: github.event_name == 'release'
3733
run: deno publish --allow-dirty
3834

39-
- name: Build for NPM
40-
run: deno task build
41-
42-
- name: Set up Node
43-
uses: actions/setup-node@v4
35+
- name: NPM (real)
36+
id: publish
37+
uses: JS-DevTools/npm-publish@v3
4438
with:
45-
node-version: '20.x'
46-
registry-url: 'https://registry.npmjs.org'
47-
48-
- name: NPM (dry run)
49-
if: github.event_name == 'push'
50-
run: npm publish --dry-run
39+
token: ${{secrets.NPM_TOKEN}}
40+
access: public
41+
provenance: true
5142

52-
- name: NPM (real)
53-
if: github.event_name == 'release'
54-
run: npm publish --provenance --access public
55-
env:
56-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
43+
- name: Release on GitHub
44+
if: ${{ steps.publish.outputs.type }}
45+
uses: softprops/action-gh-release@v1
46+
with:
47+
tag_name: v${{ steps.publish.outputs.version }}
48+
draft: false
49+
generate_release_notes: true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ npm install @yieldray/json-rpc-ts
2323
For Deno
2424

2525
```sh
26-
deno add @yieldray/json-rpc-ts
26+
deno add jsr:@yieldray/json-rpc-ts
2727
```
2828

2929
# Examples

build.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { execSync } from 'node:child_process'
2-
31
const pkg = JSON.parse(Deno.readTextFileSync('./deno.json'))
42

53
try {
@@ -45,5 +43,11 @@ Deno.writeTextFileSync('./package.json', JSON.stringify(packageJson, null, 4))
4543
console.log('New package.json created.')
4644
console.log(packageJson)
4745

48-
console.log('Building package using unbuild...')
49-
execSync('npx -y [email protected]', { stdio: ['ignore', 'inherit', 'inherit'] })
46+
const builderName = '[email protected]'
47+
console.log(`Building package using ${builderName}...`)
48+
new Deno.Command('npx', {
49+
args: ['-y', builderName],
50+
stdin: 'null',
51+
stdout: 'inherit',
52+
stderr: 'inherit',
53+
}).spawn()

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"useUnknownInCatchVariables": true,
2121
"noImplicitOverride": true
2222
},
23-
"imports": { "@std/assert": "jsr:@std/assert@^1.0.6" },
23+
"imports": { "@std/assert": "jsr:@std/assert@^1.0.13" },
2424
"tasks": {
2525
"lint": "deno lint",
2626
"fmt": "deno fmt",

deno.lock

Lines changed: 14 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export class JSONRPCClient<
5252
this.idGenerator = idGenerator || selfAddIdGenerator()
5353
}
5454

55+
/**
56+
* Creates a JSON-RPC request object with an automatically generated ID.
57+
*/
5558
public createRequest<T extends keyof Methods>(
5659
method: T extends string ? T : never,
5760
params: Parameters<Methods[T]>[0],

src/dto/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class JSONRPCError extends Error implements JSONRPCErrorInterface {
3636
}
3737

3838
/**
39-
* This ONLY check if `x` is `JSONRPCErrorInterface`
39+
* This function ONLY check that if `x` is `JSONRPCErrorInterface`
4040
*
4141
* Because it'a shared method between client and server, but `JSONRPCError` is server side only
4242
*/

src/id.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export type JSONRPCID =
33
| number // SHOULD NOT contain fractional parts
44
| null // unknown id
55

6+
/**
7+
* Creates a generator that yields incrementing numeric IDs starting from 1.
8+
*/
69
export function* selfAddIdGenerator(): Generator<number, void, unknown> {
710
let count = 0
811
for (;;) {
@@ -24,6 +27,12 @@ export function getIDFromGenerator(g: IDGenerator): JSONRPCID {
2427
}
2528
}
2629

30+
/**
31+
* Checks if the given value is a valid JSON-RPC ID.
32+
* A valid JSON-RPC ID can be a string, a number (without fractional parts), or null.
33+
*/
2734
export function isJSONRPCID(x: unknown): x is JSONRPCID {
28-
return typeof x === 'string' || typeof x === 'number' || x === null
35+
return typeof x === 'string' ||
36+
(typeof x === 'number' && Number.isInteger(x)) ||
37+
x === null
2938
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface JSONRPCMethods {
3131
}
3232

3333
/**
34-
* Represent any json rpc method, any detailed method should extend it
34+
* Represents any JSON-RPC method. Detailed methods should extend this type.
3535
*/
3636
export type JSONRPCMethod<Params, Result> = (
3737
params: Params,

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"strict": true,
1515
"target": "esnext",
1616
"useDefineForClassFields": true,
17-
"allowImportingTsExtensions": true
17+
"allowImportingTsExtensions": true,
18+
"noEmit": true
1819
}
1920
}

0 commit comments

Comments
 (0)