-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Auto generate TypeScript definition to allow chaining #884
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
Conversation
Haven't really looked at the generate script, but I think it'd be fine for it to use ES2015 (and thus require Node 6). It's something we'd have to run locally and then check in the results. |
types/generate.js
Outdated
var base = fs.readFileSync(path.join(__dirname, 'base.d.ts')).toString(); | ||
|
||
// All suported function names | ||
var allParts = ['serial', 'before', 'after', 'skip', 'todo', 'failing', 'only', 'beforeEach', 'afterEach', 'cb', 'always']; |
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.
It would be nice if it was exported from within the library https://github.com/avajs/ava/blob/master/lib/runner.js#L11. Then if something changes, the generate
script shouldn't be adjusted.
But then again, should libraries export stuff because of "documentation" purposes.
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.
Sounds like a good idea, it can be really annoying that the type definitions are not up to date.
I've addressed most of the comments and fixed the linting issues. Can you take another look? |
@@ -0,0 +1,122 @@ | |||
// TypeScript definitions are generated here. |
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.
'use strict'
Can you call the file And Travis is failing. |
I would make the file executable. './make.js' |
return Promise.resolve(this.tests.build(this._bail).run()).then(this._buildStats); | ||
}; | ||
|
||
Runner._chainableMethods = chainableMethods.chainableMethods; |
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.
Should we wrap these options in a generator function? So we aren't exporting a mutable copy?
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.
@jamestalmage Doesn't matter. It's for internal use only.
Are we good here? This all looks good to me. @SamVerschueren - should I merge? |
I did not test the output though but generally everything looks good. If you want me to test it more thoroughly, I'm ok with that. If you want to merge, that's ok as well. We can always finetune in follow up commits. Great work @ivogabe! |
Should we be storing Why not add it to |
Good point. Don't see any downside of doing that. |
I usually don't add generated files to a repo, though I had two reasons now: it's still possible to install AVA from GitHub, and you can easily see what changed when you update the generator script. |
I'd prefer ignoring it if possible. It would be awesome if npm had a "installed from GitHub" hook |
Can it be executed on |
I've added it to |
I say we start with it this way, and see if there are lots of complaints. |
package.json
Outdated
"test-win": "tap --no-cov --reporter=classic --timeout=150 test/*.js test/reporters/*.js", | ||
"visual": "node test/visual/run-visual-tests.js" | ||
"visual": "node test/visual/run-visual-tests.js", | ||
"make-ts": "node types/make" |
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.
This should probably be a prepublish
script. Otherwise I am going to forget this step when publishing.
I think that script generation should happen in a |
@jamestalmage I would agree, but I'm afraid that the package cannot be published anymore with that change... The generation script uses ES2015, thus needs Node 6, and |
@ivogabe I can't find features that can only be ran on Node 6 (spread operators for instance). Node 4 supports the majority of those features as well. |
That makes life easier then. I've added it in 54a8324. |
You need to polyfill |
// `after.cb` is fully written, and `cb.after` is emitted as an alias | ||
// using `typeof after.cb`. | ||
|
||
const path = require('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.
const => var
throughout. It's not supported on Node 0.12
or 0.10
.
Hopefully, that's the last of it. I would like to get this merged.
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.
Same with arrow functions, let
, etc, used here. Would be much easier to just require('babel/register')
this script.
@ivogabe ping :) => #884 (comment) |
Sorry, I've been too busy lately and forgot about this. I've added |
package.json
Outdated
"visual": "node test/visual/run-visual-tests.js" | ||
"visual": "node test/visual/run-visual-tests.js", | ||
"prepublish": "npm run make-ts", | ||
"make-ts": "node -e \"require('babel-register')({ presets: 'babel-preset-es2015' }); require('./types/make');\"" |
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.
Actually, we could just use babel-node
here instead of node
. We just need to add babel-cli
as a devDependency. Then we could drop this boilerplate.
https://babeljs.io/docs/usage/cli/#babel-node
This will also fix running it on Node.js 0.10 which is currently failing and would let you remove the polyfills in https://github.com/avajs/ava/pull/884/files#diff-148e5d484548912a06d9d0dd7cd4f891R19
Does |
@ivogabe Unfortunately yes, since Babel 6 everything needs config. Replace it with:
|
Awesome! Thanks for working on this @ivogabe :) |
Nice work @ivogabe ! |
🎉 |
I've implemented a generator that will create the TS definitions, with full support for chaining. Writing these type definitions by hand would be a lot of work or inaccurate. See the first comment in
types/generator.js
for details on how these definitions are created.Fixes #871. Tests for this would be useful too, see #870.
@jamestalmage @SamVerschueren What do you think?