serwist

A Swiss Army knife for service workers.

MIT License

Downloads
1.7M
Stars
667
Committers
81

Bot releases are visible (Hide)

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 add4fdd Thanks @DuCanhGH! - refactor(build): moved framework-specific types out of @serwist/build

    • Types the likes of WebpackPartial, WebpackInjectManifestOptions, ViteInjectManifestOptions, along with their according validators have been moved out of @serwist/build.

    • This design, a relic of Workbox, never made any sense in the first place. As such, we are getting rid of it and migrating to a design where types and validators are co-located with their related packages.

    • To migrate, update the imports:

      • @serwist/build.WebpackPartial -> @serwist/webpack-plugin.WebpackPartial
      • @serwist/build.WebpackInjectManifestOptions -> @serwist/webpack-plugin.InjectManifestOptions
      • @serwist/build.WebpackInjectManifestPartial -> Omit<import("@serwist/webpack-plugin").InjectManifestOptions, keyof import("@serwist/build").BasePartial | keyof import("@serwist/build").InjectPartial | keyof import("@serwist/webpack-plugin").WebpackPartial | keyof import("@serwist/build").OptionalSwDestPartial>
      • @serwist/build.ViteInjectManifestOptions -> @serwist/vite.PluginOptions
    • With this change, validators and schemas have also been made public. Validators can be imported from "/" files, whereas schemas can be imported from "/schema" ones.

  • #123 691ef0d Thanks @DuCanhGH! - refactor(vite): moved getSerwist from @serwist/vite/browser to virtual:serwist

    • @serwist/vite/browser.getSerwist required @serwist/vite to provide it build time information through virtual modules. However, this seems to cause bugs in development mode, and it is not a great pattern to use. As such, we are moving getSerwist from @serwist/vite/browser to virtual:serwist.

    • To migrate, simply update the import.

      • Old:
      import { getSerwist } from "@serwist/vite/browser";
      
      • New:
      import { getSerwist } from "virtual:serwist";
      
    • If you use TypeScript, you may also want to add @serwist/vite/typings to compilerOptions.types so Serwist can properly type the virtual module for you.

  • #123 db9f327 Thanks @DuCanhGH! - refactor(svelte): moved Svelte integration into a separate package

    • IMPORTANT NOTE: with this change, @serwist/svelte no longer makes use of any of the Serwist build tools.

      • This is because SvelteKit itself is capable of generating a list of precache manifest, and we'd like to leverage
        that capability. Essentially, Serwist, from now, only handles the service worker side for SvelteKit.
      • If the old behaviour is preferred, manual integration is required.
    • To migrate, uninstall @serwist/vite, remove @serwist/vite/integration/svelte.serwist from vite.config.(js|ts), install @serwist/svelte, and then update your service-worker.ts:

      • Old:
      /// <reference no-default-lib="true"/>
      /// <reference lib="esnext" />
      /// <reference lib="webworker" />
      /// <reference types="@sveltejs/kit" />
      import type { PrecacheEntry } from "@serwist/precaching";
      import { installSerwist } from "@serwist/sw";
      import { defaultCache } from "@serwist/vite/worker";
      
      declare global {
        interface WorkerGlobalScope {
          __SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
        }
      }
      
      declare const self: ServiceWorkerGlobalScope;
      
      installSerwist({
        precacheEntries: self.__SW_MANIFEST,
        skipWaiting: true,
        clientsClaim: true,
        navigationPreload: true,
        disableDevLogs: true,
        runtimeCaching: defaultCache,
      });
      
      • New:
      /// <reference no-default-lib="true"/>
      /// <reference lib="esnext" />
      /// <reference lib="webworker" />
      /// <reference types="@sveltejs/kit" />
      import {
        type StaticRevisions,
        // NOTE: `defaultCache` should now be imported from `@serwist/svelte/worker`.
        defaultCache,
        defaultIgnoreUrlParameters,
        getPrecacheManifest,
        staticAssets,
      } from "@serwist/svelte/worker";
      import { type SerwistGlobalConfig, Serwist } from "serwist";
      
      declare global {
        interface WorkerGlobalScope extends SerwistGlobalConfig {}
      }
      
      declare const self: ServiceWorkerGlobalScope;
      
      const serwist = new Serwist({
        precacheEntries: getPrecacheManifest({
          // precacheImmutable: false,
          // precacheStatic: false,
          // precachePrerendered: false,
          staticRevisions: "static-v1",
        }),
        precacheOptions: {
          cleanupOutdatedCaches: true,
          ignoreURLParametersMatching: defaultIgnoreUrlParameters,
        },
        skipWaiting: true,
        clientsClaim: true,
        navigationPreload: true,
        disableDevLogs: true,
        runtimeCaching: defaultCache,
      });
      
      serwist.addEventListeners();
      
  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Patch Changes

  • #123 db7776e Thanks @DuCanhGH! - fix(svelte,next,vite): force defaultCache to only use NetworkOnly in development mode

    • This is to prevent files from being accidentally cached during development mode, which isn't the behaviour you would expect to see anyway.
    • URLs that are matched by these entries in production are now handled by NetworkOnly in development. No option to override this behaviour is provided, for it would provide little to no value. If you do need runtime caching to work during development, you have to copy defaultCache into your code.
    • As a reminder for those who extend defaultCache, it should be placed below any custom entry, since such an entry wouldn't ever be matched otherwise.
  • Updated dependencies [add4fdd, b1df273, c65578b, b273b8c, 6c3e789, 7b55ac5, 4a5d51a, 7b55ac5, e4c00af, dc12dda, 10c3c17, 4a5d51a]:

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 add4fdd Thanks @DuCanhGH! - refactor(build): moved framework-specific types out of @serwist/build

    • Types the likes of WebpackPartial, WebpackInjectManifestOptions, ViteInjectManifestOptions, along with their according validators have been moved out of @serwist/build.

    • This design, a relic of Workbox, never made any sense in the first place. As such, we are getting rid of it and migrating to a design where types and validators are co-located with their related packages.

    • To migrate, update the imports:

      • @serwist/build.WebpackPartial -> @serwist/webpack-plugin.WebpackPartial
      • @serwist/build.WebpackInjectManifestOptions -> @serwist/webpack-plugin.InjectManifestOptions
      • @serwist/build.WebpackInjectManifestPartial -> Omit<import("@serwist/webpack-plugin").InjectManifestOptions, keyof import("@serwist/build").BasePartial | keyof import("@serwist/build").InjectPartial | keyof import("@serwist/webpack-plugin").WebpackPartial | keyof import("@serwist/build").OptionalSwDestPartial>
      • @serwist/build.ViteInjectManifestOptions -> @serwist/vite.PluginOptions
    • With this change, validators and schemas have also been made public. Validators can be imported from "/" files, whereas schemas can be imported from "/schema" ones.

  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 dc12dda Thanks @DuCanhGH! - chore(webpack-plugin): removed mode

    • This option was already a no-op before that, so this simply removes it from the types.
    • To migrate, just remove mode from your options.
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Minor Changes

  • #123 51a686f Thanks @DuCanhGH! - refactor(webpack,next): allow webpack to be an optional peerDependency

    • Since we support frameworks that ship a prebundled webpack, such as Next.js, it would be nice if we can take advantage of that as well.
    • As a result, webpack is now an optional peerDependency for @serwist/webpack-plugin and is no longer a peerDependency for @serwist/next. Thanks to the fact that we currently don't use any webpack plugin, it is also not indirectly installed.

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 db9f327 Thanks @DuCanhGH! - refactor(svelte): moved Svelte integration into a separate package

    • IMPORTANT NOTE: with this change, @serwist/svelte no longer makes use of any of the Serwist build tools.

      • This is because SvelteKit itself is capable of generating a list of precache manifest, and we'd like to leverage
        that capability. Essentially, Serwist, from now, only handles the service worker side for SvelteKit.
      • If the old behaviour is preferred, manual integration is required.
    • To migrate, uninstall @serwist/vite, remove @serwist/vite/integration/svelte.serwist from vite.config.(js|ts), install @serwist/svelte, and then update your service-worker.ts:

      • Old:
      /// <reference no-default-lib="true"/>
      /// <reference lib="esnext" />
      /// <reference lib="webworker" />
      /// <reference types="@sveltejs/kit" />
      import type { PrecacheEntry } from "@serwist/precaching";
      import { installSerwist } from "@serwist/sw";
      import { defaultCache } from "@serwist/vite/worker";
      
      declare global {
        interface WorkerGlobalScope {
          __SW_MANIFEST: (PrecacheEntry | string)[] | undefined;
        }
      }
      
      declare const self: ServiceWorkerGlobalScope;
      
      installSerwist({
        precacheEntries: self.__SW_MANIFEST,
        skipWaiting: true,
        clientsClaim: true,
        navigationPreload: true,
        disableDevLogs: true,
        runtimeCaching: defaultCache,
      });
      
      • New:
      /// <reference no-default-lib="true"/>
      /// <reference lib="esnext" />
      /// <reference lib="webworker" />
      /// <reference types="@sveltejs/kit" />
      import {
        type StaticRevisions,
        // NOTE: `defaultCache` should now be imported from `@serwist/svelte/worker`.
        defaultCache,
        defaultIgnoreUrlParameters,
        getPrecacheManifest,
        staticAssets,
      } from "@serwist/svelte/worker";
      import { type SerwistGlobalConfig, Serwist } from "serwist";
      
      declare global {
        interface WorkerGlobalScope extends SerwistGlobalConfig {}
      }
      
      declare const self: ServiceWorkerGlobalScope;
      
      const serwist = new Serwist({
        precacheEntries: getPrecacheManifest({
          // precacheImmutable: false,
          // precacheStatic: false,
          // precachePrerendered: false,
          staticRevisions: "static-v1",
        }),
        precacheOptions: {
          cleanupOutdatedCaches: true,
          ignoreURLParametersMatching: defaultIgnoreUrlParameters,
        },
        skipWaiting: true,
        clientsClaim: true,
        navigationPreload: true,
        disableDevLogs: true,
        runtimeCaching: defaultCache,
      });
      
      serwist.addEventListeners();
      

Patch Changes

  • #123 db7776e Thanks @DuCanhGH! - fix(svelte,next,vite): force defaultCache to only use NetworkOnly in development mode

    • This is to prevent files from being accidentally cached during development mode, which isn't the behaviour you would expect to see anyway.
    • URLs that are matched by these entries in production are now handled by NetworkOnly in development. No option to override this behaviour is provided, for it would provide little to no value. If you do need runtime caching to work during development, you have to copy defaultCache into your code.
    • As a reminder for those who extend defaultCache, it should be placed below any custom entry, since such an entry wouldn't ever be matched otherwise.
  • Updated dependencies [b1df273, c65578b, b273b8c, 6c3e789, 4a5d51a, 7b55ac5, e4c00af, dc12dda, 10c3c17, 4a5d51a]:

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 b1df273 Thanks @DuCanhGH! - chore(core): allow non-Promise return types for SerwistPlugin callbacks

    • Usually you don't need to do anything to migrate, but we still mark it as a breaking change because changing a function's signature is considered a breaking one in this project.
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 b1df273 Thanks @DuCanhGH! - chore(core): allow non-Promise return types for SerwistPlugin callbacks

    • Usually you don't need to do anything to migrate, but we still mark it as a breaking change because changing a function's signature is considered a breaking one in this project.
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

  • #123 e4c00af Thanks @DuCanhGH! - refactor(core): replaced installSerwist, PrecacheController, and Router with Serwist

    • `installSerwist, PrecacheController, and Router have been moved to serwist/legacy. Their functionalities have been merged into the Serwist class.

    • The new Serwist class does NOT have a singleton instance. As such, serwist.initializeGoogleAnalytics() and @serwist/recipes's functions now require you to pass in your own Serwist instance.

    • This was done because separating Serwist's functionalities into three separate classes, namely PrecacheController, Router, and Serwist, was not only unnecessary, but it also required the code to be rather... boilerplatey. In the past, to set up, you needed to install all the necessary packages (workbox-routing, workbox-precaching, workbox-strategies), import all the necessary classes (PrecacheController, Router,...), and know all the APIs needed (PrecacheController.precache, Router.registerRoute, new PrecacheRoute(), runtime caching strategies,...) to get yourself started. To simplify that whole process, the Workbox team provided GenerateSW, which allowed you to create a service worker without having to write one. However, this design was not my cup of tea, one of the reasons of which was that you needed to migrate from GenerateSW to InjectManifest if you needed to do anything remotely complex, so I replaced it with installSerwist. Still, I was not satisfied by the result. I wanted an API where things are simple enough that you don't need to have multiple ways of doing one same thing, some more straightforward than others. This change where we merge the three classes is an effort to simplify and unify the API.

    • To migrate, either:

      • Use the new Serwist class:
      import { Serwist } from "serwist";
      
      const serwist = new Serwist({
        // Initial list of precache entries.
        precacheEntries: [],
        // Initial list of runtime caching strategies.
        runtimeCaching: [],
      });
      
      // Additionally append another list of precache entries.
      // Make sure there are no duplicates in the initial list.
      serwist.addToPrecacheList([]);
      
      // Register another runtime caching strategy.
      serwist.registerRoute(
        new Route(/\/api\/.*\/*.json/, new NetworkOnly(), "POST"),
      );
      
      // This should be called before `Serwist.addEventListeners`.
      self.addEventListener("message", (event) => {
        if (event.data && event.data.type === "YOUR_MESSAGE_TYPE") {
          // Do something
        }
      });
      
      // Finally, add Serwist's listeners.
      serwist.addEventListeners();
      
      • Or import PrecacheController and Router from serwist/legacy:
      import { PrecacheController, Router } from "serwist/legacy";
      

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 add4fdd Thanks @DuCanhGH! - refactor(build): moved framework-specific types out of @serwist/build

    • Types the likes of WebpackPartial, WebpackInjectManifestOptions, ViteInjectManifestOptions, along with their according validators have been moved out of @serwist/build.

    • This design, a relic of Workbox, never made any sense in the first place. As such, we are getting rid of it and migrating to a design where types and validators are co-located with their related packages.

    • To migrate, update the imports:

      • @serwist/build.WebpackPartial -> @serwist/webpack-plugin.WebpackPartial
      • @serwist/build.WebpackInjectManifestOptions -> @serwist/webpack-plugin.InjectManifestOptions
      • @serwist/build.WebpackInjectManifestPartial -> Omit<import("@serwist/webpack-plugin").InjectManifestOptions, keyof import("@serwist/build").BasePartial | keyof import("@serwist/build").InjectPartial | keyof import("@serwist/webpack-plugin").WebpackPartial | keyof import("@serwist/build").OptionalSwDestPartial>
      • @serwist/build.ViteInjectManifestOptions -> @serwist/vite.PluginOptions
    • With this change, validators and schemas have also been made public. Validators can be imported from "/" files, whereas schemas can be imported from "/schema" ones.

  • #123 4a5d51a Thanks @DuCanhGH! - chore(next): renamed "/browser" to "/worker"

    • This new name makes more sense than the old one, for these exports are actually for use in service workers.

    • To migrate, simply change all imports of @serwist/next/browser to those of @serwist/next/worker:

      • Old:
      import { installSerwist } from "@serwist/sw";
      import { defaultCache } from "@serwist/next/browser";
      
      installSerwist({
        // Other options
        runtimeCaching: defaultCache,
      });
      
      • New:
      import { Serwist } from "serwist";
      import { defaultCache } from "@serwist/next/worker";
      
      const serwist = new Serwist({
        // Other options
        runtimeCaching: defaultCache,
      });
      
      serwist.addEventListeners();
      
  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

  • #123 7524712 Thanks @DuCanhGH! - chore(next): changed defaultCache's "next-data"'s handler to NetworkFirst

  • #123 837cd0d Thanks @DuCanhGH! - chore(next): renamed cacheOnFrontEndNav to cacheOnNavigation

    • Generally, we avoid using abbreviations (except for acronyms) to name Serwist's APIs.

    • To migrate, simply replace cacheOnFrontEndNav with cacheOnNavigation:

      • Old:
      const withSerwist = withSerwistInit({
        cacheOnFrontEndNav: true,
      });
      
      /** @type {import("next").NextConfig} */
      const nextConfig = {};
      
      export default withSerwist(nextConfig);
      
      • New:
      const withSerwist = withSerwistInit({
        cacheOnNavigation: true,
      });
      
      /** @type {import("next").NextConfig} */
      const nextConfig = {};
      
      export default withSerwist(nextConfig);
      

Minor Changes

  • #123 51a686f Thanks @DuCanhGH! - refactor(webpack,next): allow webpack to be an optional peerDependency

    • Since we support frameworks that ship a prebundled webpack, such as Next.js, it would be nice if we can take advantage of that as well.
    • As a result, webpack is now an optional peerDependency for @serwist/webpack-plugin and is no longer a peerDependency for @serwist/next. Thanks to the fact that we currently don't use any webpack plugin, it is also not indirectly installed.
  • #123 4a5d51a Thanks @DuCanhGH! - feat(next): added @serwist/next/worker.PAGES_CACHE_NAME

    • Due to the fact that App Router pages use RSC, we define 3 runtimeCaching entries in defaultCache, which are "pages-rsc-prefetch", "pages-rsc", and "pages". This simply re-exports these cacheName's for the users so that they can use them in their own extensions of our defaultCache.

    • If you previously copied these values from the source code, it is recommended that you migrate to this constant:

      • Old:
      import { defaultCache } from "@serwist/next/browser";
      import { installSerwist } from "@serwist/sw";
      
      installSerwist({
        // Other options...
        runtimeCaching: [
          {
            urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("RSC") === "1" &&
              request.headers.get("Next-Router-Prefetch") === "1" &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            handler: "NetworkFirst",
            options: {
              cacheName: "pages-rsc-prefetch",
              expiration: {
                maxEntries: 32,
                maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
              },
            },
          },
          {
            urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("RSC") === "1" &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            handler: "NetworkFirst",
            options: {
              cacheName: "pages-rsc",
              expiration: {
                maxEntries: 32,
                maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
              },
            },
          },
          {
            urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("Content-Type")?.includes("text/html") &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            handler: "NetworkFirst",
            options: {
              cacheName: "pages",
              expiration: {
                maxEntries: 32,
                maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
              },
            },
          },
          ...defaultCache,
        ],
      });
      
      • New:
      import { defaultCache, PAGES_CACHE_NAME } from "@serwist/next/worker";
      import { Serwist } from "serwist";
      
      const serwist = new Serwist({
        // Other options...
        runtimeCaching: [
          {
            matcher: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("RSC") === "1" &&
              request.headers.get("Next-Router-Prefetch") === "1" &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            handler: new NetworkFirst({
              cacheName: PAGES_CACHE_NAME.rscPrefetch,
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 32,
                  maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
                }),
              ],
            }),
          },
          {
            matcher: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("RSC") === "1" &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            handler: new NetworkFirst({
              cacheName: PAGES_CACHE_NAME.rsc,
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 32,
                  maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
                }),
              ],
            }),
          },
          {
            matcher: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("Content-Type")?.includes("text/html") &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            handler: new NetworkFirst({
              cacheName: PAGES_CACHE_NAME.html,
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 32,
                  maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
                }),
              ],
            }),
          },
          ...defaultCache,
        ],
      });
      
      serwist.addEventListeners();
      

Patch Changes

  • #123 db7776e Thanks @DuCanhGH! - fix(svelte,next,vite): force defaultCache to only use NetworkOnly in development mode

    • This is to prevent files from being accidentally cached during development mode, which isn't the behaviour you would expect to see anyway.
    • URLs that are matched by these entries in production are now handled by NetworkOnly in development. No option to override this behaviour is provided, for it would provide little to no value. If you do need runtime caching to work during development, you have to copy defaultCache into your code.
    • As a reminder for those who extend defaultCache, it should be placed below any custom entry, since such an entry wouldn't ever be matched otherwise.
  • Updated dependencies [add4fdd, b1df273, c65578b, b273b8c, 6c3e789, 7b55ac5, 4a5d51a, 51a686f, dc12dda, 7b55ac5, e4c00af, dc12dda, 10c3c17, 4a5d51a]:

serwist - [email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 b1df273 Thanks @DuCanhGH! - chore(core): allow non-Promise return types for SerwistPlugin callbacks

    • Usually you don't need to do anything to migrate, but we still mark it as a breaking change because changing a function's signature is considered a breaking one in this project.
  • #123 6c3e789 Thanks @DuCanhGH! - feat(precaching.PrecacheFallbackPlugin): renamed fallbackURL, added support for a matcher

    • fallbackURL has been renamed to fallbackUrls, which should now be an array of strings or PrecacheFallbackEntry's.

      • PrecacheFallbackEntry is an interface that requires a fallback URL and a matcher, which is used to check whether the current fallback entry can be used for a request.

      • To migrate:

        • Old:
        new PrecacheFallbackPlugin({
          fallbackURL: "/~offline",
        });
        
        • New:
        new PrecacheFallbackPlugin({
          fallbackUrls: ["/~offline"],
        });
        // Or
        new PrecacheFallbackPlugin({
          fallbackUrls: [
            {
              url: "/~offline",
              matcher({ request }) {
                return request.destination === "document";
              },
            },
          ],
        });
        
    • With this change, serwist.Serwist.fallbacks now also uses PrecacheFallbackPlugin. This means that FallbackEntry.cacheMatchOptions has been removed, for PrecacheController.matchPrecache doesn't support a custom matchOptions. This option is most likely not needed anyway.

      • To migrate:

        • Old:
        fallbacks({
          entries: [
            {
              url: "/~offline",
              revision,
              matcher({ request }) {
                return request.destination === "document";
              },
              cacheMatchOptions: { ignoreSearch: true },
            },
          ],
          runtimeCaching,
        });
        
        • New:
        new Serwist({
          fallbacks: {
            entries: [
              {
                url: "/~offline",
                revision,
                matcher({ request }) {
                  return request.destination === "document";
                },
              },
            ],
          }
          runtimeCaching,
        });
        
  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

  • #123 e4c00af Thanks @DuCanhGH! - refactor(core): replaced installSerwist, PrecacheController, and Router with Serwist

    • `installSerwist, PrecacheController, and Router have been moved to serwist/legacy. Their functionalities have been merged into the Serwist class.

    • The new Serwist class does NOT have a singleton instance. As such, serwist.initializeGoogleAnalytics() and @serwist/recipes's functions now require you to pass in your own Serwist instance.

    • This was done because separating Serwist's functionalities into three separate classes, namely PrecacheController, Router, and Serwist, was not only unnecessary, but it also required the code to be rather... boilerplatey. In the past, to set up, you needed to install all the necessary packages (workbox-routing, workbox-precaching, workbox-strategies), import all the necessary classes (PrecacheController, Router,...), and know all the APIs needed (PrecacheController.precache, Router.registerRoute, new PrecacheRoute(), runtime caching strategies,...) to get yourself started. To simplify that whole process, the Workbox team provided GenerateSW, which allowed you to create a service worker without having to write one. However, this design was not my cup of tea, one of the reasons of which was that you needed to migrate from GenerateSW to InjectManifest if you needed to do anything remotely complex, so I replaced it with installSerwist. Still, I was not satisfied by the result. I wanted an API where things are simple enough that you don't need to have multiple ways of doing one same thing, some more straightforward than others. This change where we merge the three classes is an effort to simplify and unify the API.

    • To migrate, either:

      • Use the new Serwist class:
      import { Serwist } from "serwist";
      
      const serwist = new Serwist({
        // Initial list of precache entries.
        precacheEntries: [],
        // Initial list of runtime caching strategies.
        runtimeCaching: [],
      });
      
      // Additionally append another list of precache entries.
      // Make sure there are no duplicates in the initial list.
      serwist.addToPrecacheList([]);
      
      // Register another runtime caching strategy.
      serwist.registerRoute(
        new Route(/\/api\/.*\/*.json/, new NetworkOnly(), "POST"),
      );
      
      // This should be called before `Serwist.addEventListeners`.
      self.addEventListener("message", (event) => {
        if (event.data && event.data.type === "YOUR_MESSAGE_TYPE") {
          // Do something
        }
      });
      
      // Finally, add Serwist's listeners.
      serwist.addEventListeners();
      
      • Or import PrecacheController and Router from serwist/legacy:
      import { PrecacheController, Router } from "serwist/legacy";
      
  • #123 dc12dda Thanks @DuCanhGH! - chore(sw): renamed urlPattern to matcher

    • Quoting jeffposnick:

    Workbox used to go all-in on RegExp based routing for runtime caching, and the runtimeCaching options in our build tools use the property named urlPattern to configure the match criteria. This criteria is passed in under the hood to the first parameter of registerRoute(), which is overloaded and takes either a string, a RegExp, or a matchCallback function.

    Beyond the fact that this overloaded can be confusing, I think it's doubly-confusing that the runtimeCaching property is called urlPattern, in that it makes it seem like only a RegExp pattern is supported.

    I'd like to change that name to match as an alias for urlPattern, and then eventually deprecate urlPattern in a future release of Workbox.

    • To migrate, simply rename urlPattern to matcher.

      • Old:
      registerRuntimeCaching(
        {
          urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
          handler: new StaleWhileRevalidate({
            cacheName: "static-image-assets",
            plugins: [
              new ExpirationPlugin({
                maxEntries: 64,
                maxAgeSeconds: 24 * 60 * 60, // 24 hours
              }),
            ],
          }),
        },
        {
          urlPattern: /\.(?:js)$/i,
          handler: new StaleWhileRevalidate({
            cacheName: "static-js-assets",
            plugins: [
              new ExpirationPlugin({
                maxEntries: 32,
                maxAgeSeconds: 24 * 60 * 60, // 24 hours
              }),
            ],
          }),
        },
        {
          urlPattern: /\.(?:css|less)$/i,
          handler: new StaleWhileRevalidate({
            cacheName: "static-style-assets",
            plugins: [
              new ExpirationPlugin({
                maxEntries: 32,
                maxAgeSeconds: 24 * 60 * 60, // 24 hours
              }),
            ],
          }),
        },
      );
      
      • New:
      new Serwist({
        runtimeCaching: [
          {
            matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
            handler: new StaleWhileRevalidate({
              cacheName: "static-image-assets",
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 64,
                  maxAgeSeconds: 24 * 60 * 60, // 24 hours
                }),
              ],
            }),
          },
          {
            matcher: /\.(?:js)$/i,
            handler: new StaleWhileRevalidate({
              cacheName: "static-js-assets",
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 32,
                  maxAgeSeconds: 24 * 60 * 60, // 24 hours
                }),
              ],
            }),
          },
          {
            matcher: /\.(?:css|less)$/i,
            handler: new StaleWhileRevalidate({
              cacheName: "static-style-assets",
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 32,
                  maxAgeSeconds: 24 * 60 * 60, // 24 hours
                }),
              ],
            }),
          },
        ],
      });
      
  • #123 10c3c17 Thanks @DuCanhGH! - refactor(sw): removed support for string handlers in registerRuntimeCaching

    • The runtimeCaching option of the Serwist class and its legacy counterpart registerRuntimeCaching no longer support string handlers, such as "NetworkFirst", "NetworkOnly", "CacheFirst", etc. You should migrate to passing the strategies' instances yourself:

    • By supporting this, a relic of GenerateSW, we are simply adding unwarranted complexity to the codebase.

    • Usually, if you only use the defaultCache array from a Serwist framework integration, you don't need to do anything. Otherwise, to migrate:

      • Old:
      import { defaultCache } from "@serwist/next/worker";
      import { installSerwist } from "@serwist/sw";
      
      installSerwist({
        // Other options...
        runtimeCaching: [
          {
            urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("RSC") === "1" &&
              request.headers.get("Next-Router-Prefetch") === "1" &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            // OLD: a string handler alongside `options`.
            handler: "NetworkFirst",
            options: {
              cacheName: "pages-rsc-prefetch",
              expiration: {
                maxEntries: 32,
                maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
              },
            },
          },
          {
            urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("RSC") === "1" &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            // OLD: a string handler alongside `options`.
            handler: "NetworkFirst",
            options: {
              cacheName: "pages-rsc",
              expiration: {
                maxEntries: 32,
                maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
              },
            },
          },
          {
            urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("Content-Type")?.includes("text/html") &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            // OLD: a string handler alongside `options`.
            handler: "NetworkFirst",
            options: {
              cacheName: "pages",
              expiration: {
                maxEntries: 32,
                maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
              },
            },
          },
          ...defaultCache,
        ],
      });
      
      • New:
      import { defaultCache, PAGES_CACHE_NAME } from "@serwist/next/worker";
      import { Serwist } from "serwist";
      
      const serwist = new Serwist({
        // Other options...
        runtimeCaching: [
          {
            matcher: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("RSC") === "1" &&
              request.headers.get("Next-Router-Prefetch") === "1" &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            // NEW: an initialized instance.
            handler: new NetworkFirst({
              cacheName: PAGES_CACHE_NAME.rscPrefetch,
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 32,
                  maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
                }),
              ],
            }),
          },
          {
            matcher: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("RSC") === "1" &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            // NEW: an initialized instance.
            handler: new NetworkFirst({
              cacheName: PAGES_CACHE_NAME.rsc,
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 32,
                  maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
                }),
              ],
            }),
          },
          {
            matcher: ({ request, url: { pathname }, sameOrigin }) =>
              request.headers.get("Content-Type")?.includes("text/html") &&
              sameOrigin &&
              !pathname.startsWith("/api/"),
            // NEW: an initialized instance.
            handler: new NetworkFirst({
              cacheName: PAGES_CACHE_NAME.html,
              plugins: [
                new ExpirationPlugin({
                  maxEntries: 32,
                  maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
                }),
              ],
            }),
          },
          ...defaultCache,
        ],
      });
      
      serwist.addEventListeners();
      
  • #123 4a5d51a Thanks @DuCanhGH! - refactor(sw): moved @serwist/build.RuntimeCaching to serwist

    • Since runtimeCaching is now a part of serwist rather than @serwist/build, it makes more sense to move the types there as well.
    • To migrate, simply update the imports.
      • Old:
      import type { StrategyName, RuntimeCaching } from "@serwist/build";
      
      • New:
      import type { StrategyName, RuntimeCaching } from "serwist";
      

Minor Changes

  • #123 c65578b Thanks @DuCanhGH! - refactor: merge service worker modules into serwist

    • These service worker modules have been merged into serwist:

      • Modules now located at serwist:

        • @serwist/navigation-preload:

          • @serwist/navigation-preload.disable -> serwist.disableNavigationPreload.
          • @serwist/navigation-preload.enable -> serwist.enableNavigationPreload.
          • @serwist/navigation-preload.isSupported -> serwist.isNavigationPreloadSupported.
        • @serwist/background-sync

          • @serwist/background-sync.QueueEntry -> serwist.BackgroundSyncQueueEntry
          • @serwist/background-sync.QueueOptions -> serwist.BackgroundSyncQueueOptions
          • @serwist/background-sync.Queue -> serwist.BackgroundSyncQueue
          • @serwist/background-sync.QueueStore -> serwist.BackgroundSyncQueueStore
        • @serwist/broadcast-update

        • @serwist/cacheable-response

        • @serwist/expiration

        • @serwist/google-analytics

          • @serwist/google-analytics.initialize -> serwist.initializeGoogleAnalytics
        • @serwist/range-requests

        • @serwist/precaching

        • @serwist/routing

        • @serwist/strategies

    • They remain operable for compatibility, but they will be marked as deprecated on npm.

Patch Changes

  • #123 b273b8c Thanks @DuCanhGH! - fix(sw.handlePrecaching): fixed code still being erroneously executed when precacheEntries is falsy

    • We weren't supposed to handle cleanupOutdatedCaches and navigateFallback when the precache manifest is falsy. Really sorry for the inconvenience!
serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 2ad49d6 Thanks @DuCanhGH! - refactor(cli): removed/renamed certain features

    • copyLibraries was already a no-op, so this simply removes the empty command.
    • wizard --injectManifest has become wizard, thanks to the fact that GenerateSW no longer exists.
    • Renamed the injectManifest command to inject-manifest. From now on, the CLI uses kebab-case rather than camelCase.
  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 add4fdd Thanks @DuCanhGH! - refactor(build): moved framework-specific types out of @serwist/build

    • Types the likes of WebpackPartial, WebpackInjectManifestOptions, ViteInjectManifestOptions, along with their according validators have been moved out of @serwist/build.

    • This design, a relic of Workbox, never made any sense in the first place. As such, we are getting rid of it and migrating to a design where types and validators are co-located with their related packages.

    • To migrate, update the imports:

      • @serwist/build.WebpackPartial -> @serwist/webpack-plugin.WebpackPartial
      • @serwist/build.WebpackInjectManifestOptions -> @serwist/webpack-plugin.InjectManifestOptions
      • @serwist/build.WebpackInjectManifestPartial -> Omit<import("@serwist/webpack-plugin").InjectManifestOptions, keyof import("@serwist/build").BasePartial | keyof import("@serwist/build").InjectPartial | keyof import("@serwist/webpack-plugin").WebpackPartial | keyof import("@serwist/build").OptionalSwDestPartial>
      • @serwist/build.ViteInjectManifestOptions -> @serwist/vite.PluginOptions
    • With this change, validators and schemas have also been made public. Validators can be imported from "/" files, whereas schemas can be imported from "/schema" ones.

  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(validators): migrate to Zod

    • We now use Zod instead of AJV.

    • This allows us to further validate the values, as AJV didn't support validating functions, classes, and more.

    • Usually, you don't need to do anything. However, if you manipulate the log/error message to do something wicked, you may need to adapt to the new format:

      Received an invalid Serwist configuration: {
      "_errors": [
      "Received unrecognized keys: someInvalidKey"
      ],
      "additionalPrecacheEntries": {
      "_errors": [
      "Received invalid type: expected array, received string."
      ]
      }
      }

  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 b1df273 Thanks @DuCanhGH! - chore(core): allow non-Promise return types for SerwistPlugin callbacks

    • Usually you don't need to do anything to migrate, but we still mark it as a breaking change because changing a function's signature is considered a breaking one in this project.
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Minor Changes

  • #123 c65578b Thanks @DuCanhGH! - refactor: merge service worker modules into serwist

    • These service worker modules have been merged into serwist:

      • Modules now located at serwist:

        • @serwist/navigation-preload:

          • @serwist/navigation-preload.disable -> serwist.disableNavigationPreload.
          • @serwist/navigation-preload.enable -> serwist.enableNavigationPreload.
          • @serwist/navigation-preload.isSupported -> serwist.isNavigationPreloadSupported.
        • @serwist/background-sync

          • @serwist/background-sync.QueueEntry -> serwist.BackgroundSyncQueueEntry
          • @serwist/background-sync.QueueOptions -> serwist.BackgroundSyncQueueOptions
          • @serwist/background-sync.Queue -> serwist.BackgroundSyncQueue
          • @serwist/background-sync.QueueStore -> serwist.BackgroundSyncQueueStore
        • @serwist/broadcast-update

        • @serwist/cacheable-response

        • @serwist/expiration

        • @serwist/google-analytics

          • @serwist/google-analytics.initialize -> serwist.initializeGoogleAnalytics
        • @serwist/range-requests

        • @serwist/precaching

        • @serwist/routing

        • @serwist/strategies

    • They remain operable for compatibility, but they will be marked as deprecated on npm.

Patch Changes

serwist - @serwist/[email protected]

Published by github-actions[bot] 6 months ago

Major Changes

  • #123 b1df273 Thanks @DuCanhGH! - chore(core): allow non-Promise return types for SerwistPlugin callbacks

    • Usually you don't need to do anything to migrate, but we still mark it as a breaking change because changing a function's signature is considered a breaking one in this project.
  • #123 4a5d51a Thanks @DuCanhGH! - chore(peerDeps): bump minimum supported TypeScript and Node.js version

    • From now, we only support TypeScript versions later than 5.0.0 and Node.js ones later than 18.0.0.
    • To migrate, simply update these tools.
    # Change to your preferred way of updating Node.js
    nvm use 18
    # Change to your package manager
    npm i -D typescript@5
    
  • #123 7b55ac5 Thanks @DuCanhGH! - refactor(js): dropped the CommonJS build

    • Serwist is now an ESM-only project.

    • This was done because our tooling around supporting CJS had always been crappy: it was slow, had no way of supporting emitting .d.cts (we used to copy .d.ts to .d.cts), and was too error-prone (there were various issues of our builds crashing due to an ESM-only package slipping in).

    • If you already use ESM, there's nothing to be done. Great! Otherwise, to migrate:

      • Migrate to ESM if possible.

      • Otherwise, use dynamic imports. For example, to migrate to the new @serwist/next:

        • Old:
        // @ts-check
        const withSerwist = require("@serwist/next").default({
          cacheOnNavigation: true,
          swSrc: "app/sw.ts",
          swDest: "public/sw.js",
        });
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = withSerwist(nextConfig);
        
        • New:
        // @ts-check
        /** @type {import("next").NextConfig} */
        const nextConfig = {
          reactStrictMode: true,
        };
        
        module.exports = async () => {
          const withSerwist = (await import("@serwist/next")).default({
            cacheOnNavigation: true,
            swSrc: "app/sw.ts",
            swDest: "public/sw.js",
          });
          return withSerwist(nextConfig);
        };
        
      • If all else fails, use require(esm). This may or may not be supported on your current Node.js version.

Minor Changes

  • #123 c65578b Thanks @DuCanhGH! - refactor: merge service worker modules into serwist

    • These service worker modules have been merged into serwist:

      • Modules now located at serwist:

        • @serwist/navigation-preload:

          • @serwist/navigation-preload.disable -> serwist.disableNavigationPreload.
          • @serwist/navigation-preload.enable -> serwist.enableNavigationPreload.
          • @serwist/navigation-preload.isSupported -> serwist.isNavigationPreloadSupported.
        • @serwist/background-sync

          • @serwist/background-sync.QueueEntry -> serwist.BackgroundSyncQueueEntry
          • @serwist/background-sync.QueueOptions -> serwist.BackgroundSyncQueueOptions
          • @serwist/background-sync.Queue -> serwist.BackgroundSyncQueue
          • @serwist/background-sync.QueueStore -> serwist.BackgroundSyncQueueStore
        • @serwist/broadcast-update

        • @serwist/cacheable-response

        • @serwist/expiration

        • @serwist/google-analytics

          • @serwist/google-analytics.initialize -> serwist.initializeGoogleAnalytics
        • @serwist/range-requests

        • @serwist/precaching

        • @serwist/routing

        • @serwist/strategies

    • They remain operable for compatibility, but they will be marked as deprecated on npm.

Patch Changes

Package Rankings
Top 23.13% on Npmjs.org