Repository navigation
Re-run ngsw after modifications in app-shell - #11583
Conversation
cbb62f6 to
55cca33
Compare
| 'ngsw-worker.js', | ||
| 'worker-basic.min.js', | ||
| 'safety-worker.js', | ||
| ]; |
There was a problem hiding this comment.
This hard-coded list feels very fragile 😁
There was a problem hiding this comment.
Those are the files we actually write back to disk further down on this file, so I think the knowledge of which files these are needs to be on the file anyway. Someone changing this file would have to change paths in both places though.
| return architect.getBuilderDescription(builderConfig).pipe( | ||
| concatMap(description => architect.validateBuilderOptions(builderConfig, description)), | ||
| map(config => join(normalize(config.options.outputPath), 'index.html')), | ||
| // map(config => join(normalize(config.options.outputPath), 'index.html')), |
| }) | ||
| .then(() => { | ||
| if (browserOptions.serviceWorker) { | ||
| return augmentAppWithServiceWorker( |
There was a problem hiding this comment.
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.
That's a concern, yeah. I don't think ngsw has 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.
The logic to hash files and write ngsw.json leaves in angular/angular-cli fwiw (mostly here). It wouldn't be too difiicult to add a function that reads ngsw.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.
I think this is the bit that calculates hashes:
It lives in @angular/service-worker but we import it here to obtain the updated manifest, then write it back.
There was a problem hiding this comment.
Generator calls CliFilessytem.list() to get the files and CliFilesystem.hash() to hash them. Then the ngsw.json manifest is written to dist further below. So, all the tools needed to read the existins ngsw.json, read and hash files and write the updated ngsw.json back are mostly in this file. (OK, there is a tiny piece of logic; i.e. how to update the hashtable in ngsw.json 😁)
Alternatively, Generator could expose a method to update specific files in an existing ngsw.json. So, then you could read the existing ngsw.json, pass it to Generator.updateHashes() and write the updated ngsw.json back.
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.
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.
I'm not sure this is worth optimizing just yet.
Honestly, the "correct" solution to me is to not generate ngsw.json until the entire build is done, including the App Shell. Running it twice seems like a hack (but a hack that will work).
55cca33 to
9594ceb
Compare
alxhub
left a comment
There was a problem hiding this comment.
LGTM
I would favor a solution which only runs ngsw generation once, after all other build steps are completed. But this is an acceptable workaround if that's architecturally difficult right now.
|
|
||
|
|
||
| class CliFilesystem implements Filesystem { | ||
| private _augmentedSwPaths = [ |
There was a problem hiding this comment.
Maybe extract this to a const instead of a private field, to further indicate these are hardcoded paths.
| }) | ||
| .then(() => { | ||
| if (browserOptions.serviceWorker) { | ||
| return augmentAppWithServiceWorker( |
There was a problem hiding this comment.
I'm not sure this is worth optimizing just yet.
Honestly, the "correct" solution to me is to not generate ngsw.json until the entire build is done, including the App Shell. Running it twice seems like a hack (but a hack that will work).
9594ceb to
45d4971
Compare
|
@gkalpak @alxhub took a slightly different approach: when running the browser target always override This way it only runs once and there's no need to change the service worker code. PTAL when you have time. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fix #8794