-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Refactored deprecation message for default
format
#207
base: master
Are you sure you want to change the base?
Conversation
… using `esm` module. see expressjs#190
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 thing that is deprecated is the morgan.default property, not just using a format string that happens to be the same format...
This would falsy give the message if the user gave their own string that is the same as the default level, which is definitely not deprecated (and is the only method to use that format in a non deprecated way).
Ah, sorry I missed that...does my latest commit work? It's not checking for the case where no format is passed, but that already has its own deprecation message ( |
I think my latest changes should work? Can this be merged? Thank you |
Thank you, sorry I didn't see your previous message. It looks like there is no warning displayed on the usage of the deprecated property though? For example the following should produce a deprecated warning so folks know it will stop working in the next release: app.use(morgan(`ACCESS ${morgan.default}`)) |
It shows the deprecation warning if you do: If |
So the idea is to remove the module.exports.default property, so the deprecation warning is to let folks know to not use it since it's going to be removed. Are you saying we shouldn't remove that property? |
Actually I just thought of a solution that I think preserves the current behavior...in my initial testing it seems to work fine. It's a change to the exports at the top of the file: Object.defineProperty(module.exports, '__esModule', { value: true })
module.exports.default = morgan
module.exports.compile = compile
module.exports.format = format
module.exports.token = token
morgan.compile = compile
morgan.format = format
morgan.token = token Can you think of any compatibility issues with this approach? If not, I can do some more testing and update the PR. |
I'm not familiar with that property, so no idea what it's effects would be. |
I'm guessing that as long as this solution works in native node.js and also with bundlers like webpack and rollup, that it should be fine? If all of those work, I can't think of a scenario where it would fail, unless older versions of node use a very different module resolution algorithm. I can test it with node 6 just in case. |
This module supports down to Node.js 0.8 |
P.S. The |
So from reading through Babel issues, etc. the From my limited searching it would seem that setting This is because when |
After further investigation, I found that my proposed solution doesn't work the way I thought it would. (I think the only way that would work correctly is if it were a module imported by another module that had been transpiled from ES6, but obviously node users who aren't using any module bundler need to be able to require morgan directly.) So this brings it back to a choice: either don't address this issue at all, or accept the fact that the deprecation warning would only show up with standard usage, i.e. The good news is that this library seems to work fine as-is with native modules support using |
And just to clarify here: we are sure this is not just some kind of esm bug? |
Originally I didn't think it was an esm bug, but after looking into this I'm wondering if maybe it is...maybe it wouldn't happen if esm checked for that |
Looks like someone reported this same issue in the esm repo: |
Thank you for the research you have put into this, it is really appreciated. Perhaps the best solution overall here is just to set some time aside this weekend and I will push out a 2.0 of morgan which will drop the |
@dougwilson any updates on finally removing |
app.use(morgan('tiny')); this code the magic for me |
Fixes #190