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

Webpack content hash #1070

Closed
wants to merge 7 commits into from
Closed

Webpack content hash #1070

wants to merge 7 commits into from

Conversation

HashTalmiz
Copy link

Description of proposed changes

What is the goal of this pull request? What does this pull request change?
To enable Cache busting.

Related issue(s)

Issue #1037, Added the features but still isn't working
Fixes #

Related to #

Testing

What steps should be taken to test the changes you've proposed?
If you added or changed behavior in the codebase, did you update the tests, or do you need help with this?

Thank you for contributing to Nextstrain!

@eharkins
Copy link
Contributor

Hey @HashTalmiz thanks for this! I think the reason for failing the tests is just a simple typo of the imported HtmlWebpackPlugin here.

Things like this should be caught by running eslint on js files, which only happens for files in the src dir when you run npm lint, so you'll have to run npx eslint webpack.config.js to get it to run on that file (we aim to include more files - like the webpack ones you are developing - in this built-in linting command soon).

This will also make the diff in the PR just show the important places where you've changed the code, so we can review and merge :) Let us know if you have any issues running linting. Thanks!

@HashTalmiz
Copy link
Author

HashTalmiz commented Apr 24, 2020

Hey @eharkins Thanks for looking into this. That typo was pretty dumb on my part lol. Installed ESLint and Linted the webpack.config file and its ready for a push with the typo fix :P
One question though, as mentioned here (#1037 (comment)), should I remove the other references and just have it hash to index.html OR keep what I've written and just fix the typos?

In other words, Is this required,

const HTMLdependentOnHash = [
		new HtmlWebpackPlugin({
			filename : 'index.html',
			template : './index.html'
		}),
		new HtmlWebpackPLugin({                   //fixed typo
			filename : 'requests.html',
			template : './docs/customise-client/requests.html'
		}),
		new HtmlWebpackPLugin({                   //fixed typo
			filename : 'services.html',
			template : './src/template/services.pug'
		}),
		new HtmlWebpackPLugin({                   //fixed typo
			filename : 'requestIndex.html',
			template : './docs/customise-client/requests/index.html'
		})
	];

or just this?

const HTMLdependentOnHash = [
		new HtmlWebpackPlugin({
			filename : 'index.html',
			template : './index.html'
		})
];

@eharkins
Copy link
Contributor

Yes, @HashTalmiz I think just the one HtmlWebpackPlugin should be necessary for index.html. For that one, is there a reason you specify explicitly the filename : 'index.html' (I think it is the default) or was that just to differentiate from the others? Will it end up in the webpack output directory dist like the example in the HtmlWebpackPlugin docs if you specify it explicitly like this?

I'm assuming the two entries that reference files in docs are because those files referenced the bundle file, but it looks like that was just listing the name of that file in the docs and not important for webpack, so I don't think they are needed in the webpack plugin.

What about this one, what does it do?

		new HtmlWebpackPLugin({                   //fixed typo
			filename : 'services.html',
			template : './src/template/services.pug'

Sorry for not getting to the actual content of your PR before. Go ahead and commit the linting so we can have a clean diff to look at. Thanks!

@HashTalmiz
Copy link
Author

HashTalmiz commented Apr 25, 2020

Yeah, the filename property decides what it'll be called in dist. I gave filenames to differentiate it from the other emitted files since I thought there would be more than one. But that isn't going to be the case. So here's where I am:

After a final Lint of webpack.config.js (--fix), I ran npm run dev, and was faced with this error (at the bottom):
contentHashrpob

So I did what it said. Running on dev again worked! So I did npm run build and:
Final
You can see the hashed auspice.bundle.js file in the first line and the rest of the chunks being hashed too!!

It ended with a warning:
warning

I'll commit the changes for you to see all the changes (and see if anything else is messed up by Prettier [my bad lol, I turned it off] )

@HashTalmiz
Copy link
Author

HashTalmiz commented Apr 25, 2020

@eharkins Well, this pull request was made a while ago and I guess a few new packages were added since then. Also I made changes on the master immediately after the fork. How you handle merge conflicts?

Note: I had a look at this tool

@eharkins
Copy link
Contributor

@HashTalmiz in terms of conflicts, it should work to rebase your branch on auspice/master.

In terms of the diff, it still seems like there are formatting changes to both files in the PR; after rebasing can you make sure that all of those are reverted so that it's just the changes relating to the html webpack plugin in the PR? Let me know if you have any trouble, thanks!

@HashTalmiz
Copy link
Author

HashTalmiz commented Apr 28, 2020

@eharkins So I've done my best in getting the merge conflicts fixed and did a rebase to the current upstream master. The CI still fails for some reason. I found this article on a similar issue locally. But I have no idea how I can fix this. Maybe @jameshadfield can help out here?

.eslintrc Outdated
@@ -7,6 +7,7 @@ globals:
browser: true
context: true
jestPuppeteer: true
BASE_URL: true
Copy link
Contributor

Choose a reason for hiding this comment

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

@HashTalmiz this line (and many others) that are supposedly changed in the PR have the exact same content as in master, which makes me think that something (perhaps the editor you're using) is adding different line ending characters (or something else invisible like tabs vs spaces) to all the lines that you edit (including the ones you merged) so that they show up different in diffs even though nothing has really changed with them.

Maybe you can test this by doing local git diff after saving with different editors (though you may have to explicitly remove special line ending characters if they are in there now).

Copy link
Author

Choose a reason for hiding this comment

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

The thing is, I haven't made any changes manually to any of these files for my editor to do anything (Except for webpack.config and package.json) All of these were bought by the rebase which I tried to do with the master branch

@eharkins
Copy link
Contributor

With respect to the npm ci command in the CI, it looks like it has to do with package.json being out of sync with package-lock.json.

Did you run npm install to update the package-lock after adding the html webpack plugin dependency?

@HashTalmiz
Copy link
Author

HashTalmiz commented Apr 28, 2020

Did you run npm install to update the package-lock after adding the html webpack plugin dependency?

I didn't. But when I did hit npm install or npm update or this as suggested in stackoverflow https://stackoverflow.com/questions/57867267/how-to-update-package-lock-json-without-doing-npm-install nothing changed. Nothing was added to lock.json, therefore nothing to commit, which is the reason why this seems bizzare :/

Copy link
Author

@HashTalmiz HashTalmiz left a comment

Choose a reason for hiding this comment

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

It wasn't white spaces or tabs, It was the date format, could it have been Git conforming to my format? Could you have a look at package.json and package-lock.json and see if there's something wrong there?

</span></div></article></div><div class="docLastUpdate"><em>Last updated on 24/03/2020</em></div><div class="docs-prevnext"><a class="docs-next button" href="/auspice/introduction/install"><span>Install Auspice</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#license-and-copyright">License and Copyright</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div><a href="/auspice/"><img style="padding-left:20px" src="/auspice/img/logo-light.svg" alt="Auspice" width="66" height="58"/></a></div><div><h5>External Links</h5><a href="https://github.com/nextstrain/auspice">GitHub repo</a><a href="https://www.npmjs.com/package/auspice">NPM package</a><a href="https://nextstrain.org">Nextstrain</a></div><div><h5>Contact Us</h5><a href="mailto:hello@nextstrain.org">email</a><a href="https://twitter.com/hamesjadfield">twitter</a></div></section><section class="copyright">Website built by <a href="https://twitter.com/hamesjadfield">James Hadfield</a> using <a href="https://docusaurus.io">Docusaurus</a></section><section class="copyright">If you use auspice, please cite <a href="https://doi.org/10.1093/bioinformatics/bty407">Hadfield et al., 2018</a></section><section class="copyright">Copyright © 2014-2020 Richard Neher &amp; Trevor Bedford</section></footer></div></body></html>
Copy link
Author

Choose a reason for hiding this comment

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

@HashTalmiz this line (and many others) that are supposedly changed in the PR have the exact same content as in master, which makes me think that something (perhaps the editor you're using) is adding different line ending characters (or something else invisible like tabs vs spaces) to all the lines that you edit

@eharkins I think you are referring to things like this? I almost agreed with you there but then I realized, every single one of these Lookalikes have the Date format changed!
For instance, look here, at the start of the second line on both sides
3/24/2020 on the left and 24/03/2020 on the right
I'm not sure how this came to be. I'm 100% sure I haven't opened these files for my editor to do this. Should I remove these from the PR right from github?

Copy link
Contributor

Choose a reason for hiding this comment

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

This change is from master

@HashTalmiz
Copy link
Author

@eharkins Btw I remember saying "yes" to a prompt saying something about adding Git LFS. Since then I've had these unwanted files coming up as unstaged commits. Could this be causing all the differences? I'm sorry if this seems unrelated/if you have no idea what this is.

@eharkins
Copy link
Contributor

@HashTalmiz Git LFS is a new dependency you need to install which is happening now because you rebased on master.

I think all the issues here come from the rebase and merge. Maybe you can get just your webpack related changes back from the reflog without this commit that changes all the other files and (re-)add them on top of a clean master?

I think this'll mean manually remaking the changes or add the commits with rebase and a clean merge. This may help https://git-scm.com/book/en/v2/Git-Branching-Rebasing.

Sorry for all the trouble here and thanks for your patience!

@HashTalmiz
Copy link
Author

HashTalmiz commented Apr 29, 2020

@eharkins Okay, so I reverted back to the best commit I've had which is where this PR is right now. Tried to do a fresh rebase after reading up all the info needed and there's where I found the problem.
realprobreal
All the files were fine before that last checkout command. Once I did that, all those unwanted & weird changes came back into the local repo on the master branch(which was clean thus far). It failed to checkout and this is what was added:
bs
(Notice the .eslint file change in the first line. This was the exact change you reviewed. All of this was in the last commit that turned things ugly)
I did a git reset --hard and a git clean to get back and tried it again. And the same thing happened when I did a rebase and merge! So now I can't even do a clean rebase or merge but I know the problem is related to git lfs. I don't have Git LFS installed locally, not sure what'll come up if I do. I'm considering just giving up at this point. 😞

@tsibley
Copy link
Member

tsibley commented Apr 29, 2020

@HashTalmiz Regarding the git lfs error you're seeing, I think it's the same issue as discussed and solved here: #1089 (comment)

all dependencies have been taken into consideration
Hashing is still not working
Also Previous commit made all the double quotes to single quotes.
Sorry bout that, That was my Prettier :P
Removed other html page references as per the comment made here ->(nextstrain#1037 (comment))
…ror on npm run dev)

npm run build shows the hashed files!!
@HashTalmiz
Copy link
Author

HashTalmiz commented Apr 30, 2020

Hey @tsibley, Thanks for that reference; got rid of the LFS in my global .config, I no longer get that error but for some reason when I do a git pull from auspice/master, I end up getting all the unwanted file changes (which aren't a part of master) exactly like last time. I'm not sure if its just me or you guys are facing this too. Can you guys try it out and let me know?

But anyway, I found a workaround with $ git checkout --track [remote]/master for a clean copy of aupsice/master, and did the rebase required.
@eharkins You can have a look at the Files changed now. I do apologize for the change of all double quotes to single quotes in webpack.config.js .It was from Prettier's JS standards from my editor, but I hope that isn't a problem. The indentation from tabs to spaces has been fixed so there's no merge confict in package.json

Edit: Some checks have failed. Not sure why but I know that the errors aren't because of the changes.
Edit 2: Updating dependencies didn't fix it, in fact, it made it worse. Reverting commit.

eharkins added a commit to eharkins/auspice that referenced this pull request Apr 30, 2020
@eharkins
Copy link
Contributor

@HashTalmiz I added your changes to the webpack config cleanly onto master in my fork, and was hoping to be able to use that to merge this work (while still attributing it to you).

However, upon testing it out with Auspice customizations which we rely on for nextstrain.org, I discovered some issues (described here) that would need resolving before we could use the added webpack functionality in Auspice, since keeping nextstrain.org up and running is a priority for us right now.

@HashTalmiz
Copy link
Author

@eharkins Responded here: eharkins@4741ed4#r39276548

@jameshadfield
Copy link
Member

Thanks both @HashTalmiz and @eharkins for your work here, it's really appreciated. I've just read through #1126 and believe that solution to be more far-reaching than this PR and thus am going to close this one. Please reopen if there are features here not implemented by #1126.

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