Skip to content

Commit

Permalink
refactor to work with latest fastify version
Browse files Browse the repository at this point in the history
* first commit

* more changes

* update

* fix

* fix
  • Loading branch information
tinchoz49 authored Jul 13, 2024
1 parent 4265eee commit 7758eaa
Show file tree
Hide file tree
Showing 35 changed files with 303 additions and 298 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Tests
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
jobs:
test:
timeout-minutes: 60
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ typings/
.next
dist
package-lock.json
.zed
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "tests/fastify/module"]
path = tests/fastify/module
url = [email protected]:fastify/fastify.git
branch = main
branch = 4.x
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
11 changes: 1 addition & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit",
"quickfix.biome": "explicit"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
}
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ $ npm install @geut/fastify-uws
## Usage

```javascript
import fastify from 'fastify'
import { serverFactory, getUws, WebSocketStream } from '@geut/fastify-uws'

import { getUws, serverFactory, WebSocketStream } from '@geut/fastify-uws'
import fastifyUwsPlugin from '@geut/fastify-uws/plugin'
import fastify from 'fastify'

const app = fastify({
serverFactory
Expand All @@ -32,19 +31,19 @@ app.addHook('onReady', async () => {
const uwsApp = getUws(app)
})

app.websocketServer.on('open', ws => {
app.websocketServer.on('open', (ws) => {
console.log('OPEN')
})

app.websocketServer.on('close', ws => {
app.websocketServer.on('close', (ws) => {
console.log('CLOSE')
})

app
.route({
method: 'GET',
url: '/',
handler (req, reply) {
handler(req, reply) {
return 'hello from http endpoint'
},
uws: {
Expand All @@ -54,7 +53,7 @@ app
'home/sensors/temp'
]
},
uwsHandler (conn) {
uwsHandler(conn) {
conn.subscribe('home/sensors/temp')
conn.on('message', (message) => {
conn.publish('home/sensors/temp', 'random message')
Expand All @@ -64,7 +63,7 @@ app
})
.get('/stream', { uws: true }, (conn) => {
const stream = new WebSocketStream(conn)
stream.on('data', data => {
stream.on('data', (data) => {
console.log('stream data from /stream')
})
})
Expand Down
114 changes: 0 additions & 114 deletions biome.json

This file was deleted.

10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { standard } from 'eslint-config-standard-ext'

export default standard({}, {
ignores: [
'dist/',
'tests/fastify/module/',
'example.js',
'types/',
],
})
15 changes: 6 additions & 9 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fastify from 'fastify'
import { WebSocketStream, getUws, serverFactory } from './src/server.js'

import fastifyUwsPlugin from './src/plugin.js'
import { getUws, serverFactory, WebSocketStream } from './src/server.js'

const app = fastify({
serverFactory,
Expand All @@ -22,6 +22,8 @@ app.websocketServer.on('close', (ws) => {
console.log('CLOSE')
})

app.get('/pepe', () => 'hi')

app
.route({
method: 'GET',
Expand All @@ -47,11 +49,6 @@ app
console.log('stream data from /stream')
})
})
.listen(
{
port: 3000,
},
(err) => {
err && console.error(err)
},
)
.listen({ port: 3000,}, (err) => {
err && console.error(err)
})
71 changes: 36 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
{
"name": "@geut/fastify-uws",
"type": "module",
"version": "4.0.0",
"description": "uWebSockets.js for fastify",
"type": "module",
"author": {
"name": "GEUT",
"email": "[email protected]"
},
"license": "MIT",
"homepage": "https://github.com/geut/fastify-uws#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/geut/fastify-uws.git"
},
"bugs": {
"url": "https://github.com/geut/fastify-uws/issues"
},
"keywords": [
"fastify",
"uWebSockets.js",
"fastify-plugin"
],
"exports": {
".": {
"types": "./types/server.d.ts",
Expand All @@ -20,67 +38,50 @@
"tests/fastify/module"
],
"files": [
"types",
"dist",
"src"
"src",
"types"
],
"engines": {
"node": ">=18"
},
"scripts": {
"start": "node index.js",
"build": "rm -rf dist && tsup src/server.js src/plugin.js --splitting",
"test": "uvu --ignore tests/fastify",
"posttest": "npm run lint && tsc",
"lint": "biome check .",
"lint:fix": "biome check --apply .",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"prepublishOnly": "npm test && npm run build && npm run types",
"types": "node scripts/generate-dts.js"
},
"dependencies": {
"fastify-plugin": "^4.5.1",
"fastq": "^1.13.0",
"ipaddr.js": "^2.0.1",
"fastq": "^1.17.1",
"ipaddr.js": "^2.2.0",
"nanoerror": "^2.0.0",
"streamx": "^2.12.5",
"tempy": "^1.0.1",
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.42.0"
"streamx": "^2.18.0",
"tempy": "^3.1.0",
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.44.0"
},
"devDependencies": {
"@biomejs/biome": "^1.7.3",
"@fastify/static": "^7.0.3",
"@fastify/static": "^7.0.4",
"@types/events": "^3.0.2",
"@types/node": "^20.8.10",
"@types/streamx": "^2.9.3",
"eslint": "^8.57.0",
"eslint-config-standard-ext": "^0.0.27",
"execa": "^8.0.1",
"fastify": "^4.24.3",
"fastify": "^4.28.1",
"require-inject": "^1.4.4",
"simple-get": "^4.0.1",
"tap": "^16.3.0",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"typescript": "^5.5.3",
"uvu": "^0.5.3",
"ws": "^8.9.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/geut/fastify-uws.git"
},
"keywords": [
"fastify",
"uWebSockets.js",
"fastify-plugin"
],
"author": {
"name": "GEUT",
"email": "[email protected]"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/geut/fastify-uws/issues"
},
"homepage": "https://github.com/geut/fastify-uws#readme",
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=18"
}
}
3 changes: 2 additions & 1 deletion scripts/generate-dts.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as fs from 'node:fs'

import { $ } from 'execa'

await $`tsc src/server.js src/plugin.js --declaration --allowJs --emitDeclarationOnly --outDir types`

const types = fs.readFileSync('types/plugin.d.ts', 'utf-8')
fs.writeFileSync(
'types/plugin.d.ts',
types + 'import "./fastify-overload.d.ts"',
types + 'import "./fastify-overload.d.ts"'
)
Loading

0 comments on commit 7758eaa

Please sign in to comment.