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

factor out shareable methods to a common class #140

Merged
merged 1 commit into from
Nov 9, 2016

Conversation

grawk
Copy link
Contributor

@grawk grawk commented Oct 13, 2016

Leaving this here to get your impression of this approach. Using it, it would be fairly simple to add an additional interface to the module. One which simply takes a file name and returns the bundle content.

@grawk
Copy link
Contributor Author

grawk commented Oct 14, 2016

FYI, here is what adding the "direct" interface looks like:
https://github.com/grawk/webpack-dev-middleware/blob/feature.new.api/middleware.js#L104-L156

@SpaceK33z
Copy link
Member

I'll try it out this weekend. Thanks for your effort!

@grawk
Copy link
Contributor Author

grawk commented Oct 26, 2016

Hi @SpaceK33z. Please let me know if you have any concerns with this PR which I can address. Thanks.

@SpaceK33z
Copy link
Member

@grawk, sorry, I'm a bit busier than expected. I still have it in my list to review.

var MemoryFileSystem = require("memory-fs");

module.exports = function shared(context) {
var shared = {
Copy link
Contributor

@shellscape shellscape Oct 27, 2016

Choose a reason for hiding this comment

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

I've never been a fan of vars sharing the same name as the fn that contains them. Makes for some funky reading. would have chosen result here instead, but that's just a random's $0.02. 😄

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you like me to underbar the variable as _shared or un-name the function? Or some other resolution?

Copy link
Member

Choose a reason for hiding this comment

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

I would say rename the function to Shared (note the capital) to be consistent with the other file, where you require it and call it Shared.

And maybe name the var something like share or config.

Copy link
Member

@SpaceK33z SpaceK33z left a comment

Choose a reason for hiding this comment

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

Some comments, but over all good work!

if(options.lazy && (!options.filename || options.filename.test(filename)))
rebuild();
if(context.options.lazy && (!context.options.filename || context.options.filename.test(filename)))
shared.rebuild();

if(HASH_REGEXP.test(filename)) {
Copy link
Member

Choose a reason for hiding this comment

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

Could this be moved to the shared part completely? I feel like this should not be exposed.

if(filename === false) return goNext();

// in lazy mode, rebuild on bundle request
if(options.lazy && (!options.filename || options.filename.test(filename)))
rebuild();
if(context.options.lazy && (!context.options.filename || context.options.filename.test(filename)))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also make a method for this in the shared file?

options.log("webpack: bundle is now INVALID.");
}
},
handleRangeHeaders: function handleRangeHeaders(content, req, res) {
Copy link
Member

Choose a reason for hiding this comment

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

This method assumes that res.setHeader, req.headers.range and res.statusCode work, but we don't know what server will be used, so this is a bit of a leaky abstraction. Don't know the correct way to do this though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment in the method, suggesting a way forward. E.g. conditional(s) based on an object check for various APIs. A new context flag could also be added to indicate what API is being used. But I believe that can be addressed in a future PR for support of additional server(s).

Copy link
Member

Choose a reason for hiding this comment

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

All right, fair enough.

@jsf-clabot
Copy link

jsf-clabot commented Nov 7, 2016

CLA assistant check
All committers have signed the CLA.

@SpaceK33z
Copy link
Member

@grawk, could you sign the CLA?

@grawk
Copy link
Contributor Author

grawk commented Nov 7, 2016

@SpaceK33z Hm. Somehow it seems these commits got associated with my corporate github ID. Therefore when I authorized the CLA app with my public github account, it's not able to link that with this changeset. Not sure how that happened :( Will look into it.

@grawk
Copy link
Contributor Author

grawk commented Nov 7, 2016

I've associated my other email address (found in .gitconfig), [email protected], with my "grawk" account. It's not seemingly resolving the issue as far as the CLA app is concerned. Is there some other way I can verify to you I've signed the CLA or what resolution would you recommend?

@SpaceK33z
Copy link
Member

I think squashing or making a new PR with the correct account is best. Sorry for the trouble.

@grawk
Copy link
Contributor Author

grawk commented Nov 7, 2016

OK. I was afraid you'd say that 😆

I'll probably have to table this today and complete it tomorrow.

refactor util as shared and make pass lint

uppercase module name

change exported function name to Shared, inner object name to share

addressing PR comments
@grawk
Copy link
Contributor Author

grawk commented Nov 8, 2016

squashed into a single commit, although the CLA badge is not reflecting a different status.

edit. looks all good now :)

@SpaceK33z SpaceK33z merged commit 6b49341 into webpack:master Nov 9, 2016
@SpaceK33z
Copy link
Member

Thanks, awesome work. I'll probably tweak some things here and there, but it looks good :).

@grawk
Copy link
Contributor Author

grawk commented Nov 9, 2016

Thank you :) Happy to help.

@SpaceK33z
Copy link
Member

FYI, Published this in 1.9.0.

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.

4 participants