Navigation Menu

Skip to content
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: deprecate setup in favor of before and after hooks #1108

Merged

Conversation

mrtnbroder
Copy link
Contributor

@mrtnbroder mrtnbroder commented Sep 20, 2017

What kind of change does this PR introduce?

feature

Did you add or update the examples/?
yes, examples/node-api-middleware

Summary

fixes #869

Does this PR introduce a breaking change?

Not a breaking change, but a deprecation.

Other information
see #869

@jsf-clabot
Copy link

jsf-clabot commented Sep 20, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@shellscape shellscape left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like there's some test failures to address as well

lib/Server.js Outdated
@@ -323,7 +323,9 @@ function Server(compiler, options) {

middleware: () => {
// include our middleware to ensure it is able to handle '/index.html' request after redirect
if (typeof options.before === 'function') { options.before(app, this); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preferably we'd follow the same pattern established on line 342 with the setup middleware. 'before' would be inserted into that array before setup and after would be added to the array before line 355

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!
I've changed the example for middleware as well, saw that one was using the setup hook which is now the before hook.

@mrtnbroder mrtnbroder force-pushed the mb/feature/middleware-before-after branch 2 times, most recently from fd842ed to 89ae007 Compare September 21, 2017 07:58
@codecov
Copy link

codecov bot commented Sep 21, 2017

Codecov Report

Merging #1108 into master will increase coverage by 0.08%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1108      +/-   ##
=========================================
+ Coverage   71.92%     72%   +0.08%     
=========================================
  Files           5       5              
  Lines         463     468       +5     
  Branches      148     151       +3     
=========================================
+ Hits          333     337       +4     
- Misses        130     131       +1
Impacted Files Coverage Δ
lib/Server.js 78.61% <83.33%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8bc6daa...40c6ece. Read the comment docs.

@mrtnbroder mrtnbroder force-pushed the mb/feature/middleware-before-after branch from 89ae007 to 546adaa Compare September 21, 2017 08:02
lib/Server.js Outdated
if (typeof options.setup === 'function') { options.setup(app, this); }
}
};

const defaultFeatures = ['setup', 'headers', 'middleware'];
if (options.proxy) { defaultFeatures.push('proxy', 'middleware'); }
const defaultFeatures = ['before', 'setup', 'headers', 'middleware', 'after'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after shouldn't be here. same goes for the changes on lines 353, 357. rather, it should be pushed to defaultFeatures before line 365 - just before the forEach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@mrtnbroder mrtnbroder force-pushed the mb/feature/middleware-before-after branch from 546adaa to febf76f Compare September 26, 2017 07:27
@shellscape shellscape merged commit dcb4e3d into webpack:master Sep 26, 2017
@mrtnbroder mrtnbroder deleted the mb/feature/middleware-before-after branch September 26, 2017 20:16
if (typeof options.setup === 'function') { options.setup(app, this); }
}
};

const defaultFeatures = ['setup', 'headers', 'middleware'];
const defaultFeatures = ['before', 'setup', 'headers', 'middleware'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shellscape @mrtnbroder doesn't setup being in this array mean that everyone will see the deprecation warning no matter what? Shouldn't it not be in there but one of the things below this say if(options.setup) defaultFeatures.push('setup') or something? (or maybe keep it in but if options.setup is absent then remove it).

It seems that the loop on line 367 will always run the deprecation warning.

I'm asking because when i upgraded to 2.9 i noticed the deprecation warning even though I don't use this hook at all (though it may just be that a dependency of mine needs upgrading. I'm not totally sure)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either that or putting the logs on lines 346-347 inside the if on line 348

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made #1120 for this

@cletusw
Copy link

cletusw commented Sep 27, 2017

It took me a while to track down where this error was coming from. Please add a link to the changelog in the error message (or at least include the text webpack-dev-server somewhere).

@shellscape
Copy link
Contributor

shellscape commented Sep 27, 2017

@cletusw double posting the same comment in multiple places is generally frowned upon, please avoid that in the future (referencing your copied comment on 8de5d0a). logging in the module will be getting an overhaul in v3. the message being shown isn't an error message; it's a vanilla log message. Deprecation warnings are never error messages.

@cletusw
Copy link

cletusw commented Sep 27, 2017

@shellscape Sorry, I didn't realize that you were also on this issue. Sorry for the double post.

@cletusw
Copy link

cletusw commented Sep 27, 2017

As for error vs. log, I guess my original message wasn't entirely clear. What I meant was, I saw the log text, but I had no idea how to fix it since it wasn't at all clear which setup it was referring to. My mocha test files? Some random setup method in my code? A third-party library? My ask was that the deprecation message at least include the text webpack-dev-server so I know where the message is coming from. Ideally, it would include a link to a page somewhere on the web explaining what the deprecation entails. Sorry I wasn't clear originally.

@shellscape
Copy link
Contributor

logging in the module will be getting an overhaul in v3.

@cletusw
Copy link

cletusw commented Sep 27, 2017

logging in the module will be getting an overhaul in v3.

Not sure what you mean. Are you saying the deprecation warning will be ambiguous until v3 at which time it will change to say webpack-dev-server: "setup" is deprecated...?

@bdwain
Copy link
Contributor

bdwain commented Sep 27, 2017

agreed about the log prefix. most log messages I've seen from webpack dev server start with [WDS]. I spent about 20 minutes this morning googling and searching to see where the warning came from because it's just a random error in the console.

It seems like a simple enough change that it shouldn't have to wait until V3's log overhaul. People are going to start seeing the deprecation warning soon and have no idea where it's coming from. @shellscape Would a PR to add [WDS] be approved?

@shellscape
Copy link
Contributor

@bdwain very much appreciate the initiative, but we're about to announce a new feature freeze to focus on v3.0.0, and logging throughout the entire module needs improvement as it has the same/similar shortcomings. you can follow progress on v3 here. I won't comment yet on what that will entail because we haven't had time to vet all of the available options. in the meantime we ask for patience.

@cletusw
Copy link

cletusw commented Sep 28, 2017 via email

@shellscape
Copy link
Contributor

@cletusw I think you've made your position abundantly clear 😄 The change will stand as-is for the moment. I'll likely abstain from commenting on this PR moving forward, but please feel free to continue the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is the middlewares ordering correct?
5 participants