-
Notifications
You must be signed in to change notification settings - Fork 484
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
feat(core): Switch to Promises everywhere. Adopt Node v4 ES6 #648
Conversation
e945617
to
62582d5
Compare
One note about documenting promise returns, if you use |
3e7812c
to
e37ce09
Compare
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.
Promises and Node4 makes the code easier to reason about. I'm all for it.
I took a quick look at the changes and made some minor comments.
.usage('Usage:\n\n' + | ||
'# generate markdown docs for index.js and files it references\n' + | ||
'$0 build index.js -f md\n\n' + | ||
.usage(`Usage: |
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.
You lost one newline here. Is that intentional?
.then(files => { | ||
watcher.add(files.map(data => | ||
typeof data === 'string' ? data : data.file)); | ||
}, err => { |
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.
General advice is to use then(a).catch(b)
instead of then(a, b)
since the former would catch errors in a too.
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.
👍 switched all the instances.
@@ -112,8 +110,7 @@ module.exports = function (comments) { | |||
node.comments.length ? path.concat(node.comments[0]) : []); | |||
} | |||
|
|||
for (var i = 0; i < node.comments.length; i++) { | |||
var comment = node.comments[i]; | |||
for (var comment of node.comments) { |
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.
Your PR description didn't mention for-of? I'm fine with that too even though it is pretty slow in Node4
@@ -97,7 +97,7 @@ function extractIdentifiers(path) { | |||
* @returns {undefined} has side-effects | |||
* @private | |||
*/ | |||
Identifier: function (path) { | |||
Identifier: path => { |
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.
Or using method syntax? Identifier(path) {
"glob": "^7.0.0", | ||
"globals-docs": "^2.3.0", |
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.
Maybe add an engines field too?
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.
👍 updated, added engines.
@@ -13,16 +13,7 @@ | |||
"type": "text", | |||
"value": "f" | |||
} | |||
], | |||
"data": { |
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 did these change?
970d1bb
to
c437326
Compare
Well, I'm unplugging and getting a brain-break shortly, but took the next step: using Flow to enforce types. That might look like just 'diving in', but I really think it is a winning move for the long-term success of documentation.js - it turns a lot of implicit types, like 'a comment' and 'a tag' into concrete types that we can enforce. I'm using the Flow comment syntax, so, at the added cost of 4 extra chars per annotation, it spares us the need to transpile or remove type annotations. |
131628e
to
e1fc69d
Compare
Big changes: * Uses template strings where appropriate * Config and argument parsing is unified and there is no such thing as formatterOptions anymore. All user-passed options go through mergeConfig. More changes: * Remove buildSync command * feat(inference): Partially implement object shorthand support * Refs #649 * Use Flow annotations to enforce types * Keep flow but switch to comment syntax * Clarify types * More flow improvements * Turn server into class * LinkerStack becomes class too * Fix comment description type * Run flow on lint * Many more flow fixes * More intense flow refactoring * Simplify inference steps * Update inference tests, flow errors down to 1 * Continue refining types * Fix more flow issues * Use 'use strict' everywhere * Make 'ast' property configurable * Fix many tests * Fix more tests * Fix more tests * Fix augments * Test Markdown meta support * Improve test coverage
I'm going to accept the -1.2% coverage increase and merge this, so that we can iterate on this in |
This is epic. Thanks. |
This is a big one: this would switch documentation.js from callbacks to Promises entirely, while also adopting ES6 template strings and arrow functions. I'm following this table for the features to use: only those available in Node v4.
This is a big one, so pinging @arv @jfirebaugh to weigh in. From my perspective right now, this feels really good and I'm going to continue working on it. Promises make a lot of sense for documentation.js's APIs, where the automatic error-passing works pretty well.
There's still more to do on this PR: I expect CI tests to fail.
TODO:
Figure out how we're going to handle options for both build & format steps. Right now that messes up some of the tests.Document the approach: running mergeOptions on all Node API endpointsRealizing that the refactored config system now runs mergeOptions twice if you call: buildSync is no longer an API method.build
. Should this be nixed?