Skip to content

Commit

Permalink
LTS tests, JSDoc3 & Prettier (#17)
Browse files Browse the repository at this point in the history
* chore: LTS tests, JSDoc3 & Prettier
* docker: dev env via docker
* package: update dependencies
* github workflow to publish to pages
  • Loading branch information
hertzg authored May 22, 2020
1 parent 71a5e3e commit e07342f
Show file tree
Hide file tree
Showing 22 changed files with 1,014 additions and 646 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
logs
*.log
pids
*.pid
*.seed
lib-cov
coverage
.nyc_output/
*.lcov
.grunt
.lock-wscript
build/Release
node_modules
.idea
docs/
30 changes: 30 additions & 0 deletions .github/workflows/jsdoc-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish JSDoc to Pages

on:
push:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2-beta

- run: npm ci
- run: npm run jsdoc --if-present

- name: Deploy to GitHub Pages
if: success()
uses: crazy-max/ghaction-github-pages@v2
with:
build_dir: docs
keep_history: true
allow_empty_commit: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ node_modules
*.tgz
*.tar.gz
*.tar

docs/
35 changes: 35 additions & 0 deletions .jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"source": {
"include": [
"./lib",
"./index.js"
],
"exclude": [
"node_modules"
]
},
"recurseDepth": 10,
"plugins": [
"plugins/markdown",
"plugins/summarize"
],
"opts": {
"readme": "./README.md",
"destination": "./docs/",
"encoding": "utf8",
"recurse": true,
"template": "./node_modules/minami"
},
"tags": {
"allowUnknownTags": true,
"dictionaries": [
"jsdoc"
]
},
"templates": {
"cleverLinks": false,
"monospaceLinks": true,
"useLongnameInNav": false,
"showInheritedInNav": true
}
}
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
docs/
build/Release
.lock-wscript
.grunt
Expand All @@ -17,3 +18,6 @@ scripts/
*.tar.gz
*.tar
.editorconfig
.prettierrc
.jsdoc.json
.github/
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"singleQuote": true,
"endOfLine": "lf",
"semi": false
}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
[codecov_shield]: https://codecov.io/gh/hertzg/node-net-keepalive/branch/master/graph/badge.svg


# net-keepalive
# 🔗 net-keepalive
[![NPM](https://nodei.co/npm/net-keepalive.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/net-keepalive/)

The Missing (`TCP_KEEPINTVL` and `TCP_KEEPCNT`) `SO_KEEPALIVE` socket option setters and getters for Node using [`ffi-napi`](https://www.npmjs.com/package/ffi-napi) module. Tested on `linux`, should work on `osx` and `freebsd`.
The Missing (`TCP_KEEPINTVL` and `TCP_KEEPCNT`) `SO_KEEPALIVE` socket option setters and getters for Node using [`ffi-napi`](https://www.npmjs.com/package/ffi-napi) module.

Tested on 🐧 `linux` & 🍏 `osx` (both `amd64` and `arm64`), should work on 😈 `freebsd` and others. Does not work on 🐄 `win32` (pull requests welcome).

## Install

Expand Down
75 changes: 75 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
x-service_defaults_volumes_npmCache: &service_defaults_volumes_npmCache dot_npm:/root/.npm:rw
x-service_defaults_volumes_app: &service_defaults_volumes_app ./:/app:rw
x-service_defaults: &service_defaults
image: node:alpine
working_dir: /app
links:
- verdaccio
depends_on:
- verdaccio
entrypoint:
- /app/scripts/docker/entrypoint.sh
volumes:
- *service_defaults_volumes_app

version: '3.5'
services:
verdaccio:
image: verdaccio/verdaccio:4
ports:
- 4873:4873
volumes:
- verdaccio_storage:/verdaccio/storage:rw
- verdaccio_conf:/verdaccio/conf:rw

node-latest:
<<: *service_defaults
image: node:alpine
volumes:
- *service_defaults_volumes_app
- latest_node_modules:/app/node_modules/:rw

node-lts-current:
<<: *service_defaults
image: node:current-alpine
volumes:
- *service_defaults_volumes_app
- current_node_modules:/app/node_modules/:rw

node-lts-dubnium:
<<: *service_defaults
image: node:dubnium-alpine
volumes:
- *service_defaults_volumes_app
- dubnium_node_modules:/app/node_modules/:rw

node-lts-carbon:
<<: *service_defaults
image: node:carbon-alpine
volumes:
- *service_defaults_volumes_app
- carbon_node_modules:/app/node_modules/:rw

node-lts-boron:
<<: *service_defaults
image: node:boron-alpine
volumes:
- *service_defaults_volumes_app
- boron_node_modules:/app/node_modules/:rw

node-lts-argon:
<<: *service_defaults
image: node:argon-alpine
volumes:
- *service_defaults_volumes_app
- argon_node_modules:/app/node_modules:rw

volumes:
verdaccio_storage:
verdaccio_conf:
latest_node_modules:
current_node_modules:
dubnium_node_modules:
carbon_node_modules:
boron_node_modules:
argon_node_modules:
15 changes: 10 additions & 5 deletions lib/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const tryGetUV = (() => {
return () => {
if (UV === null) {
try {
UV = typeof process.binding === 'function' ? process.binding('uv') : undefined
UV =
typeof process.binding === 'function'
? process.binding('uv')
: undefined
} catch (ex) {
// Continue regardless
}
Expand All @@ -16,7 +19,7 @@ const tryGetUV = (() => {
}
})()

const uvErrName = (errno) => {
const uvErrName = errno => {
const UV = tryGetUV()
return UV && UV.errname ? UV.errname(errno) : 'UNKNOWN'
}
Expand All @@ -26,8 +29,10 @@ const errnoException = (errno, syscall, original) => {
return Util._errnoException(-errno, syscall, original)
}

const errname = uvErrName(-errno)
, message = original ? `${syscall} ${errname} (${errno}) ${original}` : `${syscall} ${errname} (${errno})`
const errname = uvErrName(-errno),
message = original
? `${syscall} ${errname} (${errno}) ${original}`
: `${syscall} ${errname} (${errno})`

const e = new Error(message)
e.code = errname
Expand All @@ -37,5 +42,5 @@ const errnoException = (errno, syscall, original) => {
}

module.exports = {
errnoException
errnoException,
}
3 changes: 1 addition & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ const OS = require('os')
const Constants = {
SOL_TCP: 6,
TCP_KEEPINTVL: undefined,
TCP_KEEPCNT: undefined
TCP_KEEPCNT: undefined,
}

switch (OS.platform()) {

case 'darwin':
Constants.TCP_KEEPINTVL = 0x101
Constants.TCP_KEEPCNT = 0x102
Expand Down
15 changes: 7 additions & 8 deletions lib/ffi-bindings.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
'use strict'

const Ref = require('ref-napi')
, FFI = require('ffi-napi')
, Commons = require('./commons')
const Ref = require('ref-napi'),
FFI = require('ffi-napi'),
Commons = require('./commons')


const cInt = Ref.types.int
, cVoid = Ref.types.void
const cInt = Ref.types.int,
cVoid = Ref.types.void

const ffi = FFI.Library(null, {
//name ret 1 2 3 4 5
setsockopt: [cInt, [cInt, cInt, cInt, Ref.refType(cVoid), cInt]],
getsockopt: [cInt, [cInt, cInt, cInt, Ref.refType(cVoid), Ref.refType(cInt)]]
getsockopt: [cInt, [cInt, cInt, cInt, Ref.refType(cVoid), Ref.refType(cInt)]],
})

const setsockopt = (fd, level, name, value, valueLength) => {
Expand All @@ -37,5 +36,5 @@ const getsockopt = (fd, level, name, value, valueLength) => {

module.exports = {
setsockopt,
getsockopt
getsockopt,
}
Loading

0 comments on commit e07342f

Please sign in to comment.