Repository navigation
Re-run ngsw after modifications in app-shell #11583
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
cd4fac5
test(@angular-devkit/build-angular): add app-shell route test
filipesilva f29b962
test(@angular-devkit/build-angular): add failing app-shell + sw test
filipesilva 45d4971
fix(@angular-devkit/build-angular): only add ngsw after universal has…
filipesilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wonder if re-running this would introduce a noticeable delay for large projects (with lots of files to hash).
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.
That's a concern, yeah. I don't think
ngswhas a way to just update the hashes for some files though. I don't want to duplicate the hashing logic it uses inside the CLI.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 logic to hash files and write
ngsw.jsonleaves inangular/angular-clifwiw (mostly here). It wouldn't be too difiicult to add a function that readsngsw.json, updates some file hashes and writes it back.But this is not a very robust solution imo.
The current solution is probably fine for now, but on the long run I would expect a way to schedule "post-build" tasks, which would run after all builders have finished building.
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.
I think this is the bit that calculates hashes:
angular-cli/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/service-worker/index.ts
Lines 135 to 140 in 8475b3d
It lives in
@angular/service-workerbut we import it here to obtain the updated manifest, then write it back.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.
GeneratorcallsCliFilessytem.list()to get the files andCliFilesystem.hash()to hash them. Then thengsw.jsonmanifest is written to dist further below. So, all the tools needed to read the existinsngsw.json, read and hash files and write the updatedngsw.jsonback are mostly in this file. (OK, there is a tiny piece of logic; i.e. how to update the hashtable inngsw.json😁)Alternatively,
Generatorcould expose a method to update specific files in an existingngsw.json. So, then you could read the existingngsw.json, pass it toGenerator.updateHashes()and write the updatedngsw.jsonback.But, I guess, that would mean that you need to check if the method is available (and this wouldn't work with older versions). Not sure how much of a problem this would be and whether it is worth it.
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.
Oh wow, that is right. I hadn't noticed it.
@alxhub do you have a suggestion on what the best approach is? I think you were the one that wrote the original code.
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.
I'm not sure this is worth optimizing just yet.
Honestly, the "correct" solution to me is to not generate
ngsw.jsonuntil the entire build is done, including the App Shell. Running it twice seems like a hack (but a hack that will work).