Skip to content

Commit

Permalink
build(docs-infra): ensure ngsw.json generation is correct and deter…
Browse files Browse the repository at this point in the history
…ministic (#43686)

As explained in #43679, currently the generation of the `ngsw.json` SW
manifest is non-deterministic and often incorrect. Until we can update
to an `@angular/service-worker` version that includes the fix from
PR #43679, we temporarily work-around the issue by re-generating the
`ngsw.json` manifest after `ng build` using the `ngsw-config` binary
exposed by `@angular/service-worker`.

NOTE:
This works around the issue, because the [FileSystem][1] class used by
the `ngsw-config` binary happens to be synchronous (unlike the
implementation provided by the Angular CLI), thus avoiding the race
conditions described in #43679.

[1]: https://github.com/angular/angular/blob/c721135e370b34c840756bcfb22c8119b4c8c452/packages/service-worker/cli/filesystem.ts#L15

PR Close #43686
  • Loading branch information
gkalpak authored and dylhunn committed Oct 6, 2021
1 parent 3d26a07 commit 841c5ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions aio/ngsw-config.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"/assets/js/*.js",
"/*.css",
"/*.js",
"!/ngsw-worker.js",
"!/safety-worker.js",
"!/worker-basic.min.js"
],
"urls": [
"https://fonts.googleapis.com/**",
Expand Down
2 changes: 1 addition & 1 deletion aio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"~~clean-generated": "node --eval \"require('shelljs').rm('-rf', 'src/generated')\"",
"pre~~build": "node scripts/build-ngsw-config",
"~~build": "ng build --configuration=stable",
"post~~build": "yarn build-404-page",
"post~~build": "yarn build-404-page && ngsw-config dist src/generated/ngsw-config.json",
"~~light-server": "light-server --bind=localhost --historyindex=/index.html --no-reload"
},
"//engines-comment": "Keep this in sync with /package.json and /aio/tools/examples/shared/package.json",
Expand Down

0 comments on commit 841c5ae

Please sign in to comment.