-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
convert generator-mw with deprecation warning #683
Conversation
You need to fix the existing generator test here. I would recommend also testing that the middleware handles a request as expected. Other than that, I'd say this is good. |
Aye, as noted that in the description (that I haven't updated the tests yet). I wasn't sure if this was a direction you were willing to take this; as we discussed deprecating usage in |
I'm fine with the util.deprecate logging, the one thing is that it won't log the name of the middleware that is using a generator, but hardly anybody names their generators anyway and it should be fairly easy to spot. |
I'm trying to figure out how I can catch and/or assert that a util.deprecate output was made. Any pointers? |
if we're okay with including |
@jonathanong saw same usage from cookie (throws deprecation during tests btw). Updating PR as we speak for depd and to include tests. |
@tejasmanohar I reverted to "old style" in master (one line, w/ body). Figured there's a reason that specific line exceeds ~72 character limit. |
Oops, there seems to be some linting issues. I assumed linting occurred while doing |
@@ -100,7 +104,7 @@ module.exports = class Application extends Emitter { | |||
|
|||
use(fn) { | |||
if (typeof fn !== 'function') throw new TypeError('middleware must be a function!'); | |||
if (isGeneratorFunction(fn)) throw new TypeError('Support for generators has been removed. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/tree/v2.x#old-signature-middleware-v1x'); | |||
if (isGeneratorFunction(fn)) { fn = convert(fn); deprecate('Support for generators will been removed. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/tree/v2.x#old-signature-middleware-v1x'); } |
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 should probably split this up into four lines now that it isn't a single statement.
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.
Also, we might want to change that link/not link to it since it just says to use koa-convert.
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.
+1 to both ^
What's the end goal? I'd prefer we don't take the responsibility of koa-convert in Koa itself. |
@tejasmanohar to make the new koa less of a breaking change. It would follow the Ember and React style where you deprecate something in v+1 and remove it in v+2. In addition, we wouldn't be taking responsibility, it would be less of a breaking change, this wouldn't be guaranteed to not break things. As for taking responsibility of the core of koa-convert, it's not that bad, it's pretty much just |
@PlasmaPower I understand, but since most but not everything will work out-of-the-box with koa-convert (example), we're bound to receive lots of issues about why X works in Koa v1 but not v2. A clear differentiation between what signature and return values v1 and v2 accepts makes things a lot simpler to wrap your head around and support. Anyways, that's just my take. |
Updated deprecation message accordingly. @tejasmanohar I understand that concern; I am new so my input isn't necessarily valid. I drew inspiration from Ember. This PR arose from the bikeshedding in #533 regarding pro's and con's for releasing People want/use I made this PR to illustrate a potential solution as discussed in #533, which actually was about introducing a deprecation message in |
@koajs yes or no? i don't mind adding this for v2 and removing it in v3. |
Correct me if I'm wrong, but if this is added in then there wouldn't be any breaking changes, right? You could publish the current v2 branch as a new minor version (1.3), and then 2.x will be the one that removes deprecation warnings. I'm not one for strict semver doctrine, but I think that makes more sense than bumping the major version twice for one breaking change. |
@lourd The flushing headers support breaks an edge case, and deprecating generators means deprecating the entire codebase of v1. |
+1 for add generator function support in v2. |
Two questions
|
@fl0w A small note about this in the README might be helpful, maybe modify the note about koa-convert to include this. As for the depd message, I don't like the proposed addition given that it implies that using generators is the problem. Maybe add on "Some v1 middleware may not work with v2, use at your own risk" or something like that. |
Somehow this branch is out of date from |
A problem with this is that then generators would work with |
yeah, docs in the readme are always helpful. for depd, as long as you say something along the lines of, "generator usage is deprecated in v2.x and will be removed in v3.x. please use the new koa v2 signature w/ async functions". |
@@ -100,7 +104,11 @@ module.exports = class Application extends Emitter { | |||
|
|||
use(fn) { | |||
if (typeof fn !== 'function') throw new TypeError('middleware must be a function!'); | |||
if (isGeneratorFunction(fn)) throw new TypeError('Support for generators has been removed. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa/tree/v2.x#old-signature-middleware-v1x'); | |||
if (isGeneratorFunction(fn)) { | |||
deprecate('Support for generators will been removed. ' + |
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.
let's add that it'll be removed in v3
and have a link to the docs
yeah, that'll have to be done in those middleware otherwise, LGTM! |
Ok - give me a few hours (on the run) and I'll:
|
I would prefer #686 merged (or denied) before this so I can update accordingly. |
@jonathanong updated. I apologise btw. I could have sworn that PR introduced markdown linting which I wanted to conform with. |
@fl0w it did, but the linter would force us to make some style changes that we didn't want so we disabled it. |
convert generator-mw with deprecation warning
As discussed with @PlasmaPower in #533 (from issuecomment-196293199 to issuecomment-196326368)
Enable support for old-style middleware using
koa-convert
with an added deprecation warning.Left tests as is for now to illustrate impact on current coverage.