Skip to content

Commit

Permalink
feat(support): support Node.js v6.x
Browse files Browse the repository at this point in the history
- pulls in userland [es6-promisify](https://npm.im/es6-promisify)
- avoids `async` keyword
- add version 6 check to CI
- add `engines` field to `package.json`
  • Loading branch information
boneskull committed Jan 31, 2018
1 parent 349868e commit 9b7f6ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const promisify = require('util').promisify
const {promisify} = require('es6-promisify')

class PromiseModule {
constructor (mod) {
Expand All @@ -13,9 +13,7 @@ const handler = {
if (target.mod[name]) {
let val
if (typeof target.mod[name] === 'function') {
val = async (...args) => {
return promisify(cb => target.mod[name](...args, cb))()
}
val = (...args) => promisify(cb => target.mod[name](...args, cb))()
} else {
val = target.mod[name]
}
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@
"repository": {
"type": "git",
"url": "https://github.com/boneskull/promwrap.git"
},
"dependencies": {
"es6-promisify": "^6.0.0"
},
"engines": {
"node": ">=6.0.0"
}
}
8 changes: 5 additions & 3 deletions test/test-basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ const promwrap = require('../')
let fun = (x, cb) => cb(null, x)
let _module = {fun, prop: 'test'}

test('test basics', async t => {
test('test basics', t => {
t.plan(4)
let mod = promwrap(_module)
t.same(mod.prop, 'test')
t.same(mod.prop, 'test')
t.same(await mod.fun('test1'), 'test1')
t.same(await promwrap(fun)('test2'), 'test2')
return Promise.all([
mod.fun('test1').then(res => t.same(res, 'test1')),
promwrap(fun)('test2').then(res => t.same(res, 'test2'))
])
})

test('test error', t => {
Expand Down

0 comments on commit 9b7f6ca

Please sign in to comment.