Skip to content

Commit

Permalink
fix(types): InjectManifest's options and GenerateSW's shouldn't be in…
Browse files Browse the repository at this point in the history
…terchangeable anymore
  • Loading branch information
DuCanhGH committed Dec 5, 2022
1 parent a7defcc commit 1dfb305
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export default withPWA({

### Available options

See [PluginOptions](https://github.com/DuCanhGH/next-pwa/blob/master/src/types.ts?plain=1#L3)
See [PluginOptions](https://github.com/DuCanhGH/next-pwa/blob/master/src/types.ts?plain=1#L5)

### Other options

Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ const withPWAInit = (
...workbox
} = workboxOptions;

Object.keys(workbox).forEach(
(key) =>
workbox[key as keyof typeof workbox] === undefined &&
delete workbox[key as keyof typeof workbox]
);

let importScripts: string[] = [];
let runtimeCaching: RuntimeCaching[] = defaultCache;

Expand Down
55 changes: 50 additions & 5 deletions src/private_types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
import type { WebpackInjectManifestOptions } from "workbox-build";
import type {
WebpackGenerateSWOptions,
WebpackInjectManifestOptions,
} from "workbox-build";
import type { GenerateSWConfig } from "workbox-webpack-plugin";

type Impossible<K extends keyof any> = { [P in K]?: never };

type GenerateSWOverrideJSDoc = {
/**
* Note: This plugin changes the default to `true`.
*
* @default true ("next-pwa")
*/
skipWaiting?: GenerateSWConfig["skipWaiting"];
/**
* Note: This plugin changes the default to `true`.
*
* @default true ("next-pwa")
*/
clientsClaim?: GenerateSWConfig["clientsClaim"];
/**
* Note: This plugin changes the default to `true`.
*
* @default true ("next-pwa")
*/
cleanUpOutdatedCaches?: GenerateSWConfig["cleanupOutdatedCaches"];
/** Note: This plugin changes the default to `[]`. */
ignoreURLParametersMatching?: GenerateSWConfig["ignoreURLParametersMatching"];
};

export type WorkboxTypes = {
GenerateSW: GenerateSWConfig & {
swSrc?: undefined;
};
InjectManifest: WebpackInjectManifestOptions;
GenerateSW: Impossible<
Exclude<
keyof WebpackInjectManifestOptions,
Extract<
keyof WebpackGenerateSWOptions,
keyof WebpackInjectManifestOptions
>
>
> &
GenerateSWConfig &
GenerateSWOverrideJSDoc;
InjectManifest: Impossible<
Exclude<
keyof WebpackGenerateSWOptions,
Extract<
keyof WebpackInjectManifestOptions,
keyof WebpackGenerateSWOptions
>
>
> &
WebpackInjectManifestOptions;
};
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export interface PluginOptions {
* @deprecated Use `basePath` in `next.config.js` instead.
*/
subdomainPrefix?: string;
/** Pass options to workbox-webpack-plugin */
/** Pass options to `workbox-webpack-plugin` */
workboxOptions?: WorkboxTypes[keyof WorkboxTypes];
}

Expand Down

0 comments on commit 1dfb305

Please sign in to comment.