Skip to content

Commit 05e6a2f

Browse files
authored
chore(core): add resolver options (#37)
1 parent 0e30660 commit 05e6a2f

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

‎packages/core/src/config.ts‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,34 @@ function checkOptions<
225225
return resolvedOptions
226226
}
227227

228+
/**
229+
* The resolver options containing environment information and callbacks for `resolvePwaConfiguration`.
230+
*/
231+
export interface ResolverOptions {
232+
/**
233+
* Whether the current environment is a development environment.
234+
*/
235+
isDev: boolean
236+
/**
237+
* When using `inject-manifest`, this callback must resolve if the strategy is wrong, the implementation should be:
238+
* - if the service worker with `.ts` or `.mts` extension, then, it is `build-sw` and not `inject-manifest` strategy: must return true
239+
* - if the service worker outside public dir, then, it is `build-sw` and not `inject-manifest` strategy: must return true
240+
* - otherwise must return false
241+
*/
242+
isWrongInjectManifest: (swSrc: string) => boolean | Promise<boolean>
243+
}
244+
228245
/**
229246
* Resolves the PWA configuration based on the provided options and resolver options.
230247
*
231248
* This function will search for the PWA configuration file if the `path` option is not provided,
232249
* and will merge the loaded configuration with the provided options.
233250
*
251+
* When using `inject-manifest`, the `resolverOptions.isWrongInjectManifest` callback must resolve if the strategy is wrong, the implementation should be:
252+
* - if the service worker with `.ts` or `.mts` extension, then, it is `build-sw` and not `inject-manifest` strategy: must return true
253+
* - if the service worker outside public dir, then, it is `build-sw` and not `inject-manifest` strategy: must return true
254+
* - otherwise must return false
255+
*
234256
* @param pwaOptions The PWA options to resolve.
235257
* @param resolverOptions The resolver options containing environment information and callbacks.
236258
* @returns The resolved PWA options.
@@ -240,19 +262,7 @@ export async function resolvePwaConfiguration<
240262
T extends SWType,
241263
>(
242264
pwaOptions: Partial<VitePWAOptions<UserStrategy, T>>,
243-
resolverOptions: {
244-
/**
245-
* Whether the current environment is a development environment.
246-
*/
247-
isDev: boolean
248-
/**
249-
* When using `inject-manifest`, this callback must resolve if the strategy is wrong, the implementation should be:
250-
* - if the service worker with `.ts` or `.mts` extension, then, it is `build-sw` and not `inject-manifest` strategy: must return true
251-
* - if the service worker outside public dir, then, it is `build-sw` and not `inject-manifest` strategy: must return true
252-
* - otherwise must return false
253-
*/
254-
isWrongInjectManifest: (swSrc: string) => boolean | Promise<boolean>
255-
},
265+
resolverOptions: ResolverOptions,
256266
): Promise<ResolvedVitePWAOptions<ExtractStrategy<UserStrategy>, T>> {
257267
const resolvedPath = pwaOptions.path ?? resolveDefaultConfig(pwaOptions.cwd)
258268
const config = await loadConfiguration(Object.assign(

0 commit comments

Comments
 (0)