@serwist/vite 8.4.4 → 9.0.0-preview.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/api.d.ts +1 -0
  2. package/dist/api.d.ts.map +1 -0
  3. package/dist/assets.d.ts +1 -0
  4. package/dist/assets.d.ts.map +1 -0
  5. package/dist/constants.d.ts +1 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/context.d.ts +1 -0
  8. package/dist/context.d.ts.map +1 -0
  9. package/dist/index.browser.d.ts +1 -0
  10. package/dist/index.browser.d.ts.map +1 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.worker.d.ts +2 -1
  14. package/dist/index.worker.d.ts.map +1 -0
  15. package/dist/integration/svelte/build.d.ts +1 -0
  16. package/dist/integration/svelte/build.d.ts.map +1 -0
  17. package/dist/integration/svelte/config.d.ts +1 -0
  18. package/dist/integration/svelte/config.d.ts.map +1 -0
  19. package/dist/integration/svelte/index.d.ts +1 -0
  20. package/dist/integration/svelte/index.d.ts.map +1 -0
  21. package/dist/integration/svelte/types.d.ts +1 -0
  22. package/dist/integration/svelte/types.d.ts.map +1 -0
  23. package/dist/log.d.ts +1 -0
  24. package/dist/log.d.ts.map +1 -0
  25. package/dist/main.js +6 -6
  26. package/dist/modules.d.ts +1 -0
  27. package/dist/modules.d.ts.map +1 -0
  28. package/dist/options.d.ts +1 -0
  29. package/dist/options.d.ts.map +1 -0
  30. package/dist/plugins/build.d.ts +1 -0
  31. package/dist/plugins/build.d.ts.map +1 -0
  32. package/dist/plugins/dev.d.ts +1 -0
  33. package/dist/plugins/dev.d.ts.map +1 -0
  34. package/dist/plugins/main.d.ts +1 -0
  35. package/dist/plugins/main.d.ts.map +1 -0
  36. package/dist/types.d.ts +1 -0
  37. package/dist/types.d.ts.map +1 -0
  38. package/dist/utils-types.d.ts +1 -0
  39. package/dist/utils-types.d.ts.map +1 -0
  40. package/dist/utils.d.ts +2 -1
  41. package/dist/utils.d.ts.map +1 -0
  42. package/package.json +38 -34
  43. package/src/api.ts +38 -0
  44. package/src/assets.ts +76 -0
  45. package/src/constants.ts +2 -0
  46. package/src/context.ts +45 -0
  47. package/src/index.browser.ts +8 -0
  48. package/src/index.ts +25 -0
  49. package/src/index.worker.ts +95 -0
  50. package/src/integration/svelte/build.ts +21 -0
  51. package/src/integration/svelte/config.ts +141 -0
  52. package/src/integration/svelte/index.ts +27 -0
  53. package/src/integration/svelte/types.ts +26 -0
  54. package/src/log.ts +25 -0
  55. package/src/modules.ts +174 -0
  56. package/src/options.ts +90 -0
  57. package/src/plugins/build.ts +31 -0
  58. package/src/plugins/dev.ts +61 -0
  59. package/src/plugins/main.ts +49 -0
  60. package/src/rollup.js +46 -0
  61. package/src/types.ts +207 -0
  62. package/src/utils-types.ts +1 -0
  63. package/src/utils.ts +69 -0
  64. package/src/virtual.d.ts +5 -0
package/dist/api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { SerwistViteContext } from "./context.js";
2
2
  import type { SerwistViteApi } from "./types.js";
3
3
  export declare const createApi: (ctx: SerwistViteContext) => SerwistViteApi;
4
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,KAAK,EAA6B,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5E,eAAO,MAAM,SAAS,QAAS,kBAAkB,KAAG,cA8BnD,CAAC"}
package/dist/assets.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { ResolvedConfig } from "vite";
2
2
  import type { ResolvedPluginOptions } from "./types.js";
3
3
  export declare const configureStaticAssets: (resolvedPluginOptions: ResolvedPluginOptions, viteConfig: ResolvedConfig) => Promise<void>;
4
+ //# sourceMappingURL=assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AA+BxD,eAAO,MAAM,qBAAqB,0BAAiC,qBAAqB,cAAc,cAAc,kBAoCnH,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export declare const INTERNAL_SERWIST_VIRTUAL = "virtual:internal-serwist";
2
2
  export declare const RESOLVED_INTERNAL_SERWIST_VIRTUAL = "\0virtual:internal-serwist";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AACnE,eAAO,MAAM,iCAAiC,+BAAkC,CAAC"}
package/dist/context.d.ts CHANGED
@@ -30,3 +30,4 @@ export interface SerwistViteContext {
30
30
  framework: SerwistViteFrameworks | undefined;
31
31
  }
32
32
  export declare const createContext: (userOptions: PluginOptions, framework: SerwistViteFrameworks | undefined) => SerwistViteContext;
33
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEvE,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,WAAW,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,UAAU,EAAE,cAAc,CAAC;IAC3B;;OAEG;IACH,WAAW,EAAE,aAAa,CAAC;IAC3B;;;;;OAKG;IACH,OAAO,EAAE,qBAAqB,CAAC;IAC/B,iBAAiB,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAC;IACxB,8CAA8C;IAC9C,SAAS,EAAE,qBAAqB,GAAG,SAAS,CAAC;CAC9C;AAED,eAAO,MAAM,aAAa,gBAAiB,aAAa,aAAa,qBAAqB,GAAG,SAAS,KAAG,kBASxG,CAAC"}
@@ -1 +1,2 @@
1
1
  export declare const getSerwist: () => Promise<import("@serwist/window").Serwist | undefined>;
2
+ //# sourceMappingURL=index.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,8DAKtB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export declare const serwist: (userOptions: PluginOptions) => Plugin[];
15
15
  export { buildPlugin as build, createApi, createContext, devPlugin as dev, mainPlugin as main, resolveEntry, toFs };
16
16
  export type { SerwistViteContext } from "./context.js";
17
17
  export * from "./types.js";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,OAAO,gBAAiB,aAAa,KAAG,MAAM,EAI1D,CAAC;AAGF,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,IAAI,GAAG,EAAE,UAAU,IAAI,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AACpH,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,cAAc,YAAY,CAAC"}
@@ -1,2 +1,3 @@
1
- import type { RuntimeCaching } from "@serwist/build";
1
+ import type { RuntimeCaching } from "@serwist/sw";
2
2
  export declare const defaultCache: RuntimeCaching[];
3
+ //# sourceMappingURL=index.worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,YAAY,EAAE,cAAc,EA4FxC,CAAC"}
@@ -2,3 +2,4 @@ import type { Plugin } from "vite";
2
2
  import type { SerwistViteContext } from "../../context.js";
3
3
  import type { SerwistViteApi } from "../../types.js";
4
4
  export declare const buildPlugin: (ctx: SerwistViteContext, api: SerwistViteApi) => Plugin<any>;
5
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/integration/svelte/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,eAAO,MAAM,WAAW,QAAS,kBAAkB,OAAO,cAAc,gBAevE,CAAC"}
@@ -6,3 +6,4 @@ export declare const configurateSvelteKitOptions: (viteConfig: ResolvedConfig, k
6
6
  export declare function createManifestTransform(base: string, webManifestName?: string, options?: KitOptions): ManifestTransform;
7
7
  export declare function buildGlobPatterns(globPatterns?: string[]): string[];
8
8
  export declare function buildGlobIgnores(globIgnores?: string[]): string[];
9
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/integration/svelte/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,2BAA2B,eAAgB,cAAc,OAAO,UAAU,WAAW,iBAAiB,SAiDlH,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,iBAAiB,CAqDvH;AAED,wBAAgB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,YAYxD;AAED,wBAAgB,gBAAgB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,YAQtD"}
@@ -7,3 +7,4 @@ import type { PluginOptions } from "./types.js";
7
7
  */
8
8
  export declare const serwist: (userOptions?: PluginOptions) => Plugin[];
9
9
  export * from "./types.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/integration/svelte/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AASnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,OAAO,iBAAiB,aAAa,KAAQ,MAAM,EAO/D,CAAC;AAEF,cAAc,YAAY,CAAC"}
@@ -21,3 +21,4 @@ export interface KitOptions extends Pick<KitConfig, "appDir" | "files"> {
21
21
  export interface PluginOptions extends Optional<Omit<BasePluginOptions, "swSrc" | "swDest" | "swUrl">, "globDirectory"> {
22
22
  kit?: KitOptions;
23
23
  }
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/integration/svelte/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,WAAW,UAAW,SAAQ,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAC;IACrE;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC9C;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,aAAc,SAAQ,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC,EAAE,eAAe,CAAC;IACrH,GAAG,CAAC,EAAE,UAAU,CAAC;CAClB"}
package/dist/log.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { BuildResult } from "@serwist/build";
2
2
  import type { ResolvedConfig } from "vite";
3
3
  export declare const logSerwistResult: (buildResult: Pick<BuildResult, "count" | "size" | "warnings">, viteOptions: ResolvedConfig) => void;
4
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI3C,eAAO,MAAM,gBAAgB,gBAAiB,KAAK,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC,eAAe,cAAc,SAkB1H,CAAC"}
package/dist/main.js CHANGED
@@ -67,7 +67,7 @@ const green = kolorist(32, 39);
67
67
  const yellow = kolorist(33, 39);
68
68
  const cyan = kolorist(36, 39);
69
69
 
70
- var version = "8.4.4";
70
+ var version = "9.0.0-preview.0";
71
71
 
72
72
  const logSerwistResult = (buildResult, viteOptions)=>{
73
73
  const { logLevel = "info" } = viteOptions;
@@ -100,7 +100,7 @@ const loadSerwistBuild = async ()=>{
100
100
  };
101
101
  const injectManifest = async (config)=>{
102
102
  const { validateViteInjectManifestOptions, getFileManifestEntries, stringify } = await loadSerwistBuild();
103
- const options = validateViteInjectManifestOptions(config);
103
+ const options = await validateViteInjectManifestOptions(config);
104
104
  const { count, size, manifestEntries, warnings } = await getFileManifestEntries(options);
105
105
  const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
106
106
  return {
@@ -326,11 +326,11 @@ const isAbsolute = (url)=>{
326
326
  * @param ctx
327
327
  * @param api
328
328
  * @returns
329
- */ function toFs(str) {
329
+ */ const toFs = (str)=>{
330
330
  str = str.replace(/\\/g, "/");
331
331
  // Windows/Linux separation - Windows starts with a drive letter, we need a / in front there
332
332
  return `/@fs${str.startsWith("/") ? "" : "/"}${str}`;
333
- }
333
+ };
334
334
 
335
335
  // This plugin handles the service worker in two ways:
336
336
  // - If `devOptions.bundle` is enabled, hook a middleware that bundles the service worker
@@ -463,8 +463,8 @@ const resolveOptions = async (options, viteConfig)=>{
463
463
  // remove './' prefix from assetsDir
464
464
  const dontCacheBustURLsMatching = new RegExp(`^${assetsDir.replace(/^\.*?\//, "")}`);
465
465
  const { validateViteInjectManifestOptions } = await loadSerwistBuild();
466
- validateViteInjectManifestOptions(injectManifest);
467
- const { swSrc, swDest, ...userInjectManifest } = injectManifest || {};
466
+ const validatedInjectManifest = await validateViteInjectManifestOptions(injectManifest);
467
+ const { swSrc, swDest, ...userInjectManifest } = validatedInjectManifest || {};
468
468
  const resolvedPluginOptions = {
469
469
  base: basePath,
470
470
  type,
package/dist/modules.d.ts CHANGED
@@ -7,3 +7,4 @@ interface BuildResult extends SerwistBuild.GetManifestResult {
7
7
  export declare const injectManifest: (config: SerwistBuild.ViteInjectManifestOptions) => Promise<BuildResult>;
8
8
  export declare const generateServiceWorker: (ctx: SerwistViteContext) => Promise<BuildResult | undefined>;
9
9
  export {};
10
+ //# sourceMappingURL=modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAEpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,eAAO,MAAM,gBAAgB,QAAa,QAAQ,mBAAmB,CASpE,CAAC;AAEF,UAAU,WAAY,SAAQ,YAAY,CAAC,iBAAiB;IAC1D,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,cAAc,WAAkB,aAAa,yBAAyB,KAAG,QAAQ,WAAW,CAYxG,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAe,kBAAkB,qCAwIlE,CAAC"}
package/dist/options.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { ResolvedConfig } from "vite";
2
2
  import type { PluginOptions, ResolvedPluginOptions } from "./types.js";
3
3
  export declare const resolveOptions: (options: PluginOptions, viteConfig: ResolvedConfig) => Promise<ResolvedPluginOptions>;
4
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI3C,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGvE,eAAO,MAAM,cAAc,YAAmB,aAAa,cAAc,cAAc,KAAG,QAAQ,qBAAqB,CA+EtH,CAAC"}
@@ -9,3 +9,4 @@ import type { SerwistViteApi } from "../types.js";
9
9
  * @returns
10
10
  */
11
11
  export declare const buildPlugin: (ctx: SerwistViteContext, api: SerwistViteApi) => Plugin<any>;
12
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/plugins/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAS,kBAAkB,OAAO,cAAc,gBAkBvE,CAAC"}
@@ -9,3 +9,4 @@ import type { SerwistViteApi } from "../types.js";
9
9
  * @returns
10
10
  */
11
11
  export declare const devPlugin: (ctx: SerwistViteContext, api: SerwistViteApi) => Plugin;
12
+ //# sourceMappingURL=dev.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/plugins/dev.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,MAAM,EAAiB,MAAM,MAAM,CAAC;AAElD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AASlD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,QAAS,kBAAkB,OAAO,cAAc,KAAG,MAsCxE,CAAC"}
@@ -9,3 +9,4 @@ import type { SerwistViteApi } from "../types.js";
9
9
  * @returns
10
10
  */
11
11
  export declare const mainPlugin: (ctx: SerwistViteContext, api: SerwistViteApi) => Plugin<any>;
12
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/plugins/main.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAG/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,QAAS,kBAAkB,OAAO,cAAc,gBAgCtE,CAAC"}
package/dist/types.d.ts CHANGED
@@ -188,3 +188,4 @@ export interface SerwistViteApi {
188
188
  }
189
189
  export type ExtendManifestEntriesHook = (manifestEntries: (string | ManifestEntry)[]) => (string | ManifestEntry)[] | undefined;
190
190
  export {};
191
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEjE,MAAM,MAAM,yBAAyB,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;AAC3F,MAAM,WAAW,2BAA4B,SAAQ,IAAI,CAAC,yBAAyB,EAAE,yBAAyB,CAAC;IAC7G;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,YAAY,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAC7B;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE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7B;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,qBAAqB,CAAC,EAAE,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAI3D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,eAAe,EAAE,CAAC,MAAM,GAAG,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,aAAa,CAAC,EAAE,GAAG,SAAS,CAAC"}
@@ -1 +1,2 @@
1
1
  export type Optional<T, U extends keyof T> = Omit<T, U> & Partial<Pick<T, U>>;
2
+ //# sourceMappingURL=utils-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-types.d.ts","sourceRoot":"","sources":["../src/utils-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -20,4 +20,5 @@ export declare const resolveEntry: (entry: string) => string | null;
20
20
  * @param api
21
21
  * @returns
22
22
  */
23
- export declare function toFs(str: string): string;
23
+ export declare const toFs: (str: string) => string;
24
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,QAAS,MAAM,WAEhC,CAAC;AAEF,eAAO,MAAM,eAAe,SAAU,MAAM,WAG3C,CAAC;AAEF,eAAO,MAAM,UAAU,QAAS,MAAM,4BAErC,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,MAAM,WAEzC,CAAC;AAIF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MAAM,GAAG,IAqBrD,CAAC;AAIF;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,QAAS,MAAM,WAI/B,CAAC"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@serwist/vite",
3
- "version": "8.4.4",
3
+ "version": "9.0.0-preview.0",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Vite application.",
6
6
  "files": [
7
- "dist",
8
- "!dist/dts"
7
+ "src",
8
+ "dist"
9
9
  ],
10
10
  "keywords": [
11
11
  "react",
@@ -25,6 +25,9 @@
25
25
  "web",
26
26
  "service-worker"
27
27
  ],
28
+ "engines": {
29
+ "node": ">=18.0.0"
30
+ },
28
31
  "author": "antfu <anthonyfu117@hotmail.com>, Serwist's Team",
29
32
  "license": "MIT",
30
33
  "repository": "serwist/serwist",
@@ -48,28 +51,20 @@
48
51
  },
49
52
  "exports": {
50
53
  ".": {
51
- "import": {
52
- "types": "./dist/index.d.ts",
53
- "default": "./dist/index.js"
54
- }
54
+ "types": "./dist/index.d.ts",
55
+ "default": "./dist/index.js"
55
56
  },
56
57
  "./browser": {
57
- "import": {
58
- "types": "./dist/index.browser.d.ts",
59
- "default": "./dist/index.browser.js"
60
- }
58
+ "types": "./dist/index.browser.d.ts",
59
+ "default": "./dist/index.browser.js"
61
60
  },
62
61
  "./worker": {
63
- "import": {
64
- "types": "./dist/index.worker.d.ts",
65
- "default": "./dist/index.worker.js"
66
- }
62
+ "types": "./dist/index.worker.d.ts",
63
+ "default": "./dist/index.worker.js"
67
64
  },
68
65
  "./integration-*": {
69
- "import": {
70
- "types": "./dist/integration/*/index.d.ts",
71
- "default": "./dist/integration/*/index.js"
72
- }
66
+ "types": "./dist/integration/*/index.d.ts",
67
+ "default": "./dist/integration/*/index.js"
73
68
  },
74
69
  "./package.json": "./package.json"
75
70
  },
@@ -77,29 +72,30 @@
77
72
  "debug": "4.3.4",
78
73
  "fast-glob": "3.3.2",
79
74
  "pretty-bytes": "6.1.1",
80
- "@serwist/build": "8.4.4",
81
- "@serwist/window": "8.4.4"
75
+ "@serwist/build": "9.0.0-preview.0",
76
+ "@serwist/window": "9.0.0-preview.0"
82
77
  },
83
78
  "devDependencies": {
84
- "@playwright/test": "1.40.1",
85
- "@sveltejs/kit": "2.0.6",
79
+ "@playwright/test": "1.41.2",
80
+ "@sveltejs/kit": "2.5.0",
86
81
  "@types/debug": "4.1.12",
87
- "@types/node": "20.10.5",
82
+ "@types/node": "20.11.16",
88
83
  "@types/prompts": "2.4.9",
89
- "@types/react": "18.2.45",
90
- "bumpp": "9.2.1",
84
+ "@types/react": "18.2.52",
85
+ "bumpp": "9.3.0",
91
86
  "kolorist": "1.8.0",
92
87
  "preact": "10.19.3",
93
88
  "prompts": "2.4.2",
94
89
  "publint": "0.2.7",
95
90
  "react": "18.2.0",
96
- "rollup": "4.9.1",
97
- "solid-js": "1.8.7",
98
- "svelte": "5.0.0-next.26",
99
- "typescript": "5.4.0-dev.20231226",
100
- "vite": "5.0.10",
101
- "vue": "3.3.13",
102
- "@serwist/constants": "8.4.4"
91
+ "rollup": "4.9.6",
92
+ "solid-js": "1.8.12",
93
+ "svelte": "5.0.0-next.45",
94
+ "typescript": "5.4.0-dev.20240203",
95
+ "vite": "5.0.12",
96
+ "vue": "3.4.15",
97
+ "@serwist/constants": "9.0.0-preview.0",
98
+ "@serwist/sw": "9.0.0-preview.0"
103
99
  },
104
100
  "peerDependencies": {
105
101
  "@sveltejs/kit": "^1.0.0 || ^2.0.0",
@@ -107,10 +103,15 @@
107
103
  "react": "^18.0.0",
108
104
  "solid-js": "^1.8.7",
109
105
  "svelte": "^4.0.0 || ^5.0.0",
106
+ "typescript": ">=5.0.0",
110
107
  "vite": "^5.0.0",
111
- "vue": "^3.0.0"
108
+ "vue": "^3.0.0",
109
+ "@serwist/sw": "9.0.0-preview.0"
112
110
  },
113
111
  "peerDependenciesMeta": {
112
+ "@serwist/sw": {
113
+ "optional": true
114
+ },
114
115
  "@sveltejs/kit": {
115
116
  "optional": true
116
117
  },
@@ -126,6 +127,9 @@
126
127
  "svelte": {
127
128
  "optional": true
128
129
  },
130
+ "typescript": {
131
+ "optional": true
132
+ },
129
133
  "vue": {
130
134
  "optional": true
131
135
  }
package/src/api.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { yellow } from "kolorist";
2
+
3
+ import type { SerwistViteContext } from "./context.js";
4
+ import { logSerwistResult } from "./log.js";
5
+ import { generateServiceWorker } from "./modules.js";
6
+ import type { ExtendManifestEntriesHook, SerwistViteApi } from "./types.js";
7
+
8
+ export const createApi = (ctx: SerwistViteContext): SerwistViteApi => {
9
+ return {
10
+ get disabled() {
11
+ return ctx?.options?.disable;
12
+ },
13
+ async generateSW() {
14
+ if (ctx.options.disable) {
15
+ return undefined;
16
+ }
17
+ const buildResult = await generateServiceWorker(ctx);
18
+ if (buildResult) {
19
+ if (ctx.viteConfig.isProduction) {
20
+ // Log Serwist result
21
+ logSerwistResult(buildResult, ctx.viteConfig);
22
+ } else if (buildResult.warnings && buildResult.warnings.length > 0) {
23
+ console.warn(yellow(["[@serwist/vite] Warnings", ...buildResult.warnings.map((w) => ` - ${w}`), ""].join("\n")));
24
+ }
25
+ }
26
+ },
27
+ extendManifestEntries(fn: ExtendManifestEntriesHook) {
28
+ const { options } = ctx;
29
+ if (options.disable) return;
30
+
31
+ const result = fn(options.injectManifest.additionalPrecacheEntries || []);
32
+
33
+ if (result != null) {
34
+ options.injectManifest.additionalPrecacheEntries = result;
35
+ }
36
+ },
37
+ };
38
+ };
package/src/assets.ts ADDED
@@ -0,0 +1,76 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ import { resolve as resolveFs } from "node:path";
4
+
5
+ import type { InjectManifestOptions, ManifestEntry } from "@serwist/build";
6
+ import fg from "fast-glob";
7
+ import type { ResolvedConfig } from "vite";
8
+
9
+ import type { ResolvedPluginOptions } from "./types.js";
10
+
11
+ const buildManifestEntry = (publicDir: string, url: string): Promise<ManifestEntry> => {
12
+ return new Promise((resolve, reject) => {
13
+ const cHash = crypto.createHash("MD5");
14
+ const stream = fs.createReadStream(resolveFs(publicDir, url));
15
+ stream.on("error", (err) => {
16
+ reject(err);
17
+ });
18
+ stream.on("data", (chunk) => {
19
+ cHash.update(chunk);
20
+ });
21
+ stream.on("end", () => {
22
+ return resolve({
23
+ url,
24
+ revision: `${cHash.digest("hex")}`,
25
+ });
26
+ });
27
+ });
28
+ };
29
+
30
+ const lookupAdditionalPrecacheEntries = (serwistOptions: Partial<InjectManifestOptions>): (string | ManifestEntry)[] => {
31
+ return serwistOptions.additionalPrecacheEntries || [];
32
+ };
33
+
34
+ // we need to make icons relative, we can have for example icon entries with: /pwa.png
35
+ // fast-glob will not resolve absolute paths
36
+ const normalizeIconPath = (path: string) => {
37
+ return path.startsWith("/") ? path.substring(1) : path;
38
+ };
39
+
40
+ export const configureStaticAssets = async (resolvedPluginOptions: ResolvedPluginOptions, viteConfig: ResolvedConfig) => {
41
+ const { injectManifest, includeAssets } = resolvedPluginOptions;
42
+
43
+ const { publicDir } = viteConfig;
44
+ const globs: string[] = [];
45
+ const manifestEntries: (string | ManifestEntry)[] = lookupAdditionalPrecacheEntries(injectManifest);
46
+ if (includeAssets) {
47
+ // we need to make icons relative, we can have for example icon entries with: /pwa.png
48
+ // fast-glob will not resolve absolute paths
49
+ if (Array.isArray(includeAssets)) globs.push(...includeAssets.map(normalizeIconPath));
50
+ else globs.push(normalizeIconPath(includeAssets));
51
+ }
52
+ if (globs.length > 0) {
53
+ let assets = await fg(globs, {
54
+ cwd: publicDir,
55
+ onlyFiles: true,
56
+ unique: true,
57
+ });
58
+ // we also need to remove from the list existing included by the user
59
+ if (manifestEntries.length > 0) {
60
+ const included = manifestEntries.map((me) => {
61
+ if (typeof me === "string") return me;
62
+ return me.url;
63
+ });
64
+ assets = assets.filter((a) => !included.includes(a));
65
+ }
66
+ const assetsEntries = await Promise.all(
67
+ assets.map((a) => {
68
+ return buildManifestEntry(publicDir, a);
69
+ }),
70
+ );
71
+ manifestEntries.push(...assetsEntries);
72
+ }
73
+ if (manifestEntries.length > 0) {
74
+ injectManifest.additionalPrecacheEntries = manifestEntries;
75
+ }
76
+ };
@@ -0,0 +1,2 @@
1
+ export const INTERNAL_SERWIST_VIRTUAL = "virtual:internal-serwist";
2
+ export const RESOLVED_INTERNAL_SERWIST_VIRTUAL = `\0${INTERNAL_SERWIST_VIRTUAL}`;
package/src/context.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { ResolvedConfig } from "vite";
2
+
3
+ import type { PluginOptions, ResolvedPluginOptions } from "./types.js";
4
+
5
+ export type SerwistViteFrameworks = "nuxt" | "sveltekit";
6
+
7
+ export interface SerwistViteContext {
8
+ /**
9
+ * Resolved Vite config.
10
+ *
11
+ * Note: This value is set by our main plugin, located at plugins/main.ts.
12
+ */
13
+ viteConfig: ResolvedConfig;
14
+ /**
15
+ * Provided options.
16
+ */
17
+ userOptions: PluginOptions;
18
+ /**
19
+ * Resolved options.
20
+ *
21
+ * Note: this is different from `userOptions` in that it has been parsed, whereas
22
+ * `userOptions` is the raw configuration that the user provides us.
23
+ */
24
+ options: ResolvedPluginOptions;
25
+ useImportRegister: boolean;
26
+ /**
27
+ * Is the plugin running on dev?
28
+ *
29
+ * Note: This value is set by our dev plugin, located at plugins/dev.ts.
30
+ */
31
+ devEnvironment: boolean;
32
+ /** To tailor our APIs to these frameworks. */
33
+ framework: SerwistViteFrameworks | undefined;
34
+ }
35
+
36
+ export const createContext = (userOptions: PluginOptions, framework: SerwistViteFrameworks | undefined): SerwistViteContext => {
37
+ return {
38
+ userOptions,
39
+ options: undefined!,
40
+ viteConfig: undefined!,
41
+ useImportRegister: false,
42
+ devEnvironment: false,
43
+ framework,
44
+ };
45
+ };
@@ -0,0 +1,8 @@
1
+ import { swScope, swType, swUrl } from "virtual:internal-serwist";
2
+
3
+ export const getSerwist = async () => {
4
+ if ("serviceWorker" in navigator) {
5
+ return new (await import("@serwist/window")).Serwist(swUrl, { scope: swScope, type: swType });
6
+ }
7
+ return undefined;
8
+ };
package/src/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { Plugin } from "vite";
2
+
3
+ import { createApi } from "./api.js";
4
+ import { createContext } from "./context.js";
5
+ import { buildPlugin } from "./plugins/build.js";
6
+ import { devPlugin } from "./plugins/dev.js";
7
+ import { mainPlugin } from "./plugins/main.js";
8
+ import type { PluginOptions } from "./types.js";
9
+ import { resolveEntry, toFs } from "./utils.js";
10
+
11
+ /**
12
+ * Integrates Serwist into your Vite app.
13
+ * @param userOptions
14
+ * @returns
15
+ */
16
+ export const serwist = (userOptions: PluginOptions): Plugin[] => {
17
+ const ctx = createContext(userOptions, undefined);
18
+ const api = createApi(ctx);
19
+ return [mainPlugin(ctx, api), buildPlugin(ctx, api), devPlugin(ctx, api)];
20
+ };
21
+
22
+ // This allows for customization.
23
+ export { buildPlugin as build, createApi, createContext, devPlugin as dev, mainPlugin as main, resolveEntry, toFs };
24
+ export type { SerwistViteContext } from "./context.js";
25
+ export * from "./types.js";