sw 0.1.0
sw: ^0.1.0 copied to clipboard
A command-line tool to generate service worker files for web applications. It simplifies the process of creating service workers.
0.1.0 — 2026-04-20 #
Complete rewrite replacing Flutter's default bootstrap with a professional two-artifact system.
Fixed (post-audit hardening) #
- Generator: crash on short or empty
engineRevisionnow surfaces a clear error before artifact generation. - CLI precedence:
--flagwith an ArgParser default no longer shadows YAML / env values (wasParsedgate). Glob options (--core,--required, …) now honourSW_CORE,SW_REQUIRED,SW_OPTIONAL,SW_IGNORE,SW_GLOB,SW_EXCLUDE_GLOBenvironment variables that previously did nothing. - CLI: invalid
--min-progress/--max-progressvalues now fail with exit code 64 instead of silently defaulting to0/90. - Cleanup: canvaskit pruning uses consistent URL-style paths, fixing a Windows case where
\-separated paths never matched the keep-set. - SW
notifyClients: a single dead client no longer aborts iteration — every other client still receives the progress update. - SW
cacheFirst: non-OK responses (4xx/5xx) now emit anerrorprogress event so the bootstrap UI can surface the failure instead of hanging onloading. Fallback 503s carryContent-Type: text/plain. - SW
swapCaches: reordered to copy-then-evict-then-persist-manifest, and eviction now excludes paths that were just re-precached from temp (no more accidental deletion of the fresh bytes). - SW
message-handler: accepts both"skipWaiting"strings and{type: "skipWaiting"|"getVersion", requestId?}objects;getVersionreplies echorequestIdfor correlation. - Loading widget: dispose adds a 600ms safety teardown, so the widget and its stylesheet don't leak when
transitionenddoesn't fire (reduced-motion, background tabs). - CanvasKit loader:
detectWebGLVersionreleases its temporary canvas + GL context viaWEBGL_lose_contextinstead of relying on GC.
Added #
- Deterministic
version: when--version/SW_VERSION/ YAML is absent, the generator derives a stable 12-char sha256 over the manifest contents. Re-running against an unchanged build now yields the same SW version. - Dart UI defaults → bootstrap:
--logo,--title,--theme,--color,--min-progress,--max-progressflags are baked intobootstrap.jsasBuildConfig.uiDefaults.data-configstill overrides at runtime. - Precache concurrency cap (
PRECACHE_CONCURRENCY = 6) so large manifests don't stampede the origin during install. - Manifest size warning: generator emits a stderr warning when
sw.jsexceeds 10 MB. - Update prompt API:
window.Bootstrap.onUpdateAvailable(handler)andwindow.Bootstrap.applyUpdate(reload=true)let apps prompt for and apply a waiting SW upgrade.sw-registration.tsexportsactivateWaitingSW(registration)for lower-level use. - CI: new
e2eGitHub Actions job runsflutter build web+dart run sw:generate+ Playwright on each PR;SW_E2E_BROWSERS=allopts into the Chromium/Firefox/WebKit matrix. - Tests:
test/config_test.dart,test/files_test.dart, and new injector cases coveringuiDefaults. Removed the emptytest/unit_test.dartplaceholder.
Original 0.1.0 feature set #
Breaking Changes #
- CLI arguments updated: new options added, some defaults changed
- Generated output now produces two files (
sw.js+bootstrap.js) instead of one - Requires
<script defer data-sw-bootstrap src="bootstrap.js">inindex.html - Old inline JS/CSS loading UI replaced by the built-in loading widget
Added #
- Bootstrap pipeline — 6-stage initialization replacing
flutter_bootstrap.js- Stages: Init → SW Registration → CanvasKit → Assets → Dart Entry → Dart Init
- Loading widget — Responsive circular progress with SVG ring, stall detection, error display, dark/light/auto theme
- CanvasKit CDN loading — Automatic
engineRevisionextraction, Google CDN with local fallback - Resource categorization — Core, Required, Optional, Ignore with glob-based overrides
- Global API —
window.Bootstrap.dispose(),.progress,.subscribe(cb)for Dart integration - YAML config —
sw.yamlas alternative to CLI args (priority: CLI > YAML > env > defaults) - Exponential backoff — 3 retry attempts with 1s/2s/4s delays and jitter
- Cache busting — Hash-based
?v={hash}query params on all cached resources - Atomic cache updates — Temp cache during install, swapped on activate
- Console logging — Styled version banner with engine revision, SW version, renderer info
- Stall detection — "Reset Cache" button after 30s without progress
- Auto-cleanup — Removes
flutter_bootstrap.js,flutter_service_worker.js,version.json,.js.map,.js.symbols - TypeScript source — SW and Bootstrap written in TypeScript, compiled via Vite to minified IIFE
Changed #
- Monorepo structure:
packages/sw/(TypeScript) + root (Dart CLI) - Service Worker rewritten in TypeScript with modular architecture
- Cache naming:
{prefix}-{version}for content,{prefix}-manifestfor manifest storage bootstrap.js,index.html,sw.jsare never cached by the SW
Removed #
- Inline JS/CSS string templates in Dart (replaced by compiled TypeScript)
downloadOfflinecommand (simplified caching model)- Navigation preload (replaced by simpler network-first for index.html)
- Comment stripping (Vite handles minification)
0.0.7 #
- Simplify service worker by removing retry logic and navigation preload.
- Replace
Promise.racetimeout wrappers with modernAbortController-basedfetchWithTimeout. - Remove unused constants (
MEDIA_EXT,NETWORK_ONLY,RETRY_DELAY). - Remove
INSTALL_TIMEOUT,ACTIVATE_TIMEOUTwrappers from install/activate events. - Streamline activate event handler by removing redundant
Promise.racenesting.
0.0.6 #
- Add timeout protection for install (30s) and activate (30s) events.
- Add fetch timeout (10s) and retry logic (2 retries with 500ms delay).
- Add navigation preload support for online-first strategy.
- Clean up all stale caches with matching prefix on activation.
- Ensure
self.clients.claim()is always called, even on error/timeout. - Emit
sw-version.txtalongsidesw.jsfor CI version injection.
0.0.5 #
- Update index.html example to include more features.
0.0.4 #
- Improved service worker generation.
0.0.3 #
- Service worker generation now based on the flutter's
flutter_service_worker.js.
0.0.2 #
- Proof of concept for service worker generation
0.0.1 #
- Initial release with basic functionality