-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to hapi 17, node 8 and async/await closes #568 #572
Conversation
|
||
const req = request.raw.req; | ||
const res = request.raw.res; | ||
|
||
this.event = 'response'; | ||
this.timestamp = request.info.received; | ||
this.id = request.id; | ||
this.instance = request.connection.info.uri; | ||
this.labels = request.connection.settings.labels; | ||
this.instance = server.info.uri; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the server
not exposed in the request
anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the upgrade instructions in the release notes for this. I also just searched the API docs page for uri
and only see it as ever being attached to the server
} | ||
|
||
startOps(interval) { | ||
|
||
this._ops && this._ops.start(interval); | ||
} | ||
|
||
start(callback) { | ||
start() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So since we are cutting ties with old versions of hapi and node, you can rewrite
const ctorArgs = spec.args ? spec.args.slice() : [];
ctorArgs.unshift(null);
Ctor = Ctor.bind.apply(Ctor, ctorArgs);
const stream = new Ctor();
to use rest parameters. Not sure if you were planning on a subsequent JavaScript updates PR or not.
Should be a one-liner with rest parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch I also removed the use of arguments bellow that
lib/monitor.js
Outdated
@@ -187,9 +154,10 @@ class Monitor { | |||
}); | |||
} | |||
|
|||
return callback(); | |||
return Promise.resolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly no as the callback that was there before wasn't needed the whole function is synchronous. However I assume it was there to avoid confusion. At first I made the function async but then I got this linting error
Line 75: require-await - Async method 'start' has no 'await' expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean can you just not return anything? As you said, this isn't even an async function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
pkg: require('../package.json') | ||
}; | ||
exports.pkg = require('../package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin format has changed without it you get this error
[1] "name" is required
at Object.exports.apply (/root/node_modules/hapi/lib/config.js:22:10)
at internals.Server.register (/root/node_modules/hapi/lib/server.js:384:31)
at it (/root/test/index.js:70:22)
at Immediate.setImmediate (/root/node_modules/lab/lib/runner.js:566:31)
at runCallback (timers.js:800:20)
at tryOnImmediate (timers.js:762:5)
at processImmediate [as _immediateCallback] (timers.js:733:5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, you're sure that this works? According to the error message you have to provide exports.name
in addition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frankthelen Yes I am sure the error was provided simply by switching it back and running the test suit to see it fail. pkg can be used as well please see the very last paragraph and code example here: https://hapijs.com/api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. You're right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments have been fixed or replied to. Let me know if I need to do anything else. Thanks so much!
lib/monitor.js
Outdated
@@ -187,9 +154,10 @@ class Monitor { | |||
}); | |||
} | |||
|
|||
return callback(); | |||
return Promise.resolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly no as the callback that was there before wasn't needed the whole function is synchronous. However I assume it was there to avoid confusion. At first I made the function async but then I got this linting error
Line 75: require-await - Async method 'start' has no 'await' expression.
|
||
const req = request.raw.req; | ||
const res = request.raw.res; | ||
|
||
this.event = 'response'; | ||
this.timestamp = request.info.received; | ||
this.id = request.id; | ||
this.instance = request.connection.info.uri; | ||
this.labels = request.connection.settings.labels; | ||
this.instance = server.info.uri; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the upgrade instructions in the release notes for this. I also just searched the API docs page for uri
and only see it as ever being attached to the server
} | ||
|
||
startOps(interval) { | ||
|
||
this._ops && this._ops.start(interval); | ||
} | ||
|
||
start(callback) { | ||
start() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch I also removed the use of arguments bellow that
|
||
pkg: require('../package.json') | ||
}; | ||
exports.pkg = require('../package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin format has changed without it you get this error
[1] "name" is required
at Object.exports.apply (/root/node_modules/hapi/lib/config.js:22:10)
at internals.Server.register (/root/node_modules/hapi/lib/server.js:384:31)
at it (/root/test/index.js:70:22)
at Immediate.setImmediate (/root/node_modules/lab/lib/runner.js:566:31)
at runCallback (timers.js:800:20)
at tryOnImmediate (timers.js:762:5)
at processImmediate [as _immediateCallback] (timers.js:733:5)
|
||
}); | ||
console.info(`Server started at ${ server.info.uri }`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add something about the supported versions of hapi somewhere in the readme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What format do you want this in. I looked at all the other plugins in the hapi namespace and didn't see an others doing this as was just going to follow whatever format was there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arb Just wanted to check if you had a chance to think about this. Don't mean to rush know we all get busy just excited ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put it high in the README. Doesn't matter to me what the format is, just so long as it's there so when people open issues complaining, it is documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arb Done!
lib/monitor.js
Outdated
@@ -187,9 +154,10 @@ class Monitor { | |||
}); | |||
} | |||
|
|||
return callback(); | |||
return Promise.resolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean can you just not return anything? As you said, this isn't even an async function.
lib/monitor.js
Outdated
@@ -207,8 +169,9 @@ class Monitor { | |||
|
|||
// Do a setImmediate here so that all the streams listening for "end" have a chance to run | |||
// https://github.com/nodejs/node/blob/master/lib/_stream_readable.js#L894-L897 | |||
setImmediate(callback); | |||
return new Promise((resolve) => setImmediate(() => resolve())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious if we still need this?
If so you can write it as return new Promise((resolve) => setImmediate(resolve));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so so removing
I've just gone through upgrading a couple of apps to Hapi 17 and have also upgraded our good logging to @corbinu 's fork, all looking good for us, so far, thank you |
Thanks @corbinu for taking care of this migration! |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Migrates to hapi 17, node 8 and async/await
I removed wreck support as wreck no longer issues the events needed
I am still trying to solve an issue where the tests emit
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added. Use emitter.setMaxListeners() to increase limit
Any comments and help would be appreciated