@serwist/vite 9.0.0-preview.2 → 9.0.0-preview.21

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 (86) hide show
  1. package/dist/chunks/schema.js +56 -0
  2. package/dist/index.d.ts +8 -7
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +360 -11
  5. package/dist/index.schema.d.ts +3 -0
  6. package/dist/index.schema.d.ts.map +1 -0
  7. package/dist/index.schema.js +3 -0
  8. package/dist/index.worker.d.ts +6 -0
  9. package/dist/index.worker.d.ts.map +1 -1
  10. package/dist/index.worker.js +84 -65
  11. package/dist/lib/api.d.ts.map +1 -0
  12. package/dist/lib/constants.d.ts.map +1 -0
  13. package/dist/{context.d.ts → lib/context.d.ts} +3 -3
  14. package/dist/lib/context.d.ts.map +1 -0
  15. package/dist/lib/log.d.ts.map +1 -0
  16. package/dist/{modules.d.ts → lib/modules.d.ts} +1 -1
  17. package/dist/lib/modules.d.ts.map +1 -0
  18. package/dist/lib/options.d.ts +4 -0
  19. package/dist/lib/options.d.ts.map +1 -0
  20. package/dist/lib/schema.d.ts +359 -0
  21. package/dist/lib/schema.d.ts.map +1 -0
  22. package/dist/lib/types.d.ts +127 -0
  23. package/dist/lib/types.d.ts.map +1 -0
  24. package/dist/lib/utils.d.ts.map +1 -0
  25. package/dist/lib/validator.d.ts +3 -0
  26. package/dist/lib/validator.d.ts.map +1 -0
  27. package/dist/plugins/build.d.ts +2 -2
  28. package/dist/plugins/build.d.ts.map +1 -1
  29. package/dist/plugins/dev.d.ts +2 -2
  30. package/dist/plugins/dev.d.ts.map +1 -1
  31. package/dist/plugins/main.d.ts +2 -2
  32. package/dist/plugins/main.d.ts.map +1 -1
  33. package/package.json +22 -62
  34. package/src/index.schema.ts +3 -0
  35. package/src/index.ts +8 -7
  36. package/src/index.worker.ts +111 -85
  37. package/src/{context.ts → lib/context.ts} +3 -3
  38. package/src/{log.ts → lib/log.ts} +1 -1
  39. package/src/{modules.ts → lib/modules.ts} +5 -6
  40. package/src/lib/options.ts +76 -0
  41. package/src/lib/schema.ts +35 -0
  42. package/src/lib/types.ts +163 -0
  43. package/src/lib/validator.ts +10 -0
  44. package/src/plugins/build.ts +2 -2
  45. package/src/plugins/dev.ts +3 -3
  46. package/src/plugins/main.ts +5 -5
  47. package/src/rollup.js +3 -24
  48. package/dist/api.d.ts.map +0 -1
  49. package/dist/assets.d.ts +0 -4
  50. package/dist/assets.d.ts.map +0 -1
  51. package/dist/constants.d.ts.map +0 -1
  52. package/dist/context.d.ts.map +0 -1
  53. package/dist/integration/svelte/build.d.ts +0 -5
  54. package/dist/integration/svelte/build.d.ts.map +0 -1
  55. package/dist/integration/svelte/config.d.ts +0 -9
  56. package/dist/integration/svelte/config.d.ts.map +0 -1
  57. package/dist/integration/svelte/index.d.ts +0 -10
  58. package/dist/integration/svelte/index.d.ts.map +0 -1
  59. package/dist/integration/svelte/index.js +0 -145
  60. package/dist/integration/svelte/types.d.ts +0 -24
  61. package/dist/integration/svelte/types.d.ts.map +0 -1
  62. package/dist/log.d.ts.map +0 -1
  63. package/dist/main.js +0 -470
  64. package/dist/modules.d.ts.map +0 -1
  65. package/dist/options.d.ts +0 -4
  66. package/dist/options.d.ts.map +0 -1
  67. package/dist/types.d.ts +0 -191
  68. package/dist/types.d.ts.map +0 -1
  69. package/dist/utils-types.d.ts +0 -2
  70. package/dist/utils-types.d.ts.map +0 -1
  71. package/dist/utils.d.ts.map +0 -1
  72. package/src/assets.ts +0 -76
  73. package/src/integration/svelte/build.ts +0 -21
  74. package/src/integration/svelte/config.ts +0 -141
  75. package/src/integration/svelte/index.ts +0 -27
  76. package/src/integration/svelte/types.ts +0 -26
  77. package/src/options.ts +0 -90
  78. package/src/types.ts +0 -207
  79. package/src/utils-types.ts +0 -1
  80. /package/dist/{api.d.ts → lib/api.d.ts} +0 -0
  81. /package/dist/{constants.d.ts → lib/constants.d.ts} +0 -0
  82. /package/dist/{log.d.ts → lib/log.d.ts} +0 -0
  83. /package/dist/{utils.d.ts → lib/utils.d.ts} +0 -0
  84. /package/src/{api.ts → lib/api.ts} +0 -0
  85. /package/src/{constants.ts → lib/constants.ts} +0 -0
  86. /package/src/{utils.ts → lib/utils.ts} +0 -0
@@ -0,0 +1,76 @@
1
+ import path from "node:path";
2
+ import process from "node:process";
3
+
4
+ import type { ResolvedConfig } from "vite";
5
+
6
+ import type { PluginOptions, PluginOptionsComplete } from "./types.js";
7
+ import { resolveBasePath, slash } from "./utils.js";
8
+ import { validateInjectManifestOptions } from "./validator.js";
9
+
10
+ const prepareConfigForValidation = (
11
+ viteConfig: ResolvedConfig,
12
+ {
13
+ mode = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "development" ? process.env.NODE_ENV : "production",
14
+ base = viteConfig.base,
15
+ scope: _scope,
16
+ devOptions,
17
+ ...injectManifest
18
+ }: PluginOptions,
19
+ ) => {
20
+ const basePath = resolveBasePath(base);
21
+ return {
22
+ mode,
23
+ base: basePath,
24
+ scope: _scope || basePath,
25
+ devOptions,
26
+ ...injectManifest,
27
+ };
28
+ };
29
+
30
+ export const resolveOptions = async (options: PluginOptions, viteConfig: ResolvedConfig): Promise<PluginOptionsComplete> => {
31
+ const {
32
+ mode,
33
+ type,
34
+ scope,
35
+ base,
36
+ disable,
37
+ integration,
38
+ swUrl,
39
+ swSrc,
40
+ swDest,
41
+ plugins,
42
+ rollupFormat,
43
+ rollupOptions,
44
+ devOptions,
45
+ ...userInjectManifest
46
+ } = await validateInjectManifestOptions(prepareConfigForValidation(viteConfig, options));
47
+
48
+ let assetsDir = slash(viteConfig.build.assetsDir ?? "assets");
49
+ if (assetsDir[assetsDir.length - 1] !== "/") assetsDir += "/";
50
+
51
+ // remove './' prefix from assetsDir
52
+ const dontCacheBustURLsMatching = new RegExp(`^${assetsDir.replace(/^\.*?\//, "")}`);
53
+
54
+ const resolvedPluginOptions = {
55
+ mode,
56
+ type,
57
+ scope,
58
+ base,
59
+ disable,
60
+ integration,
61
+ swUrl,
62
+ plugins,
63
+ rollupFormat,
64
+ rollupOptions,
65
+ devOptions,
66
+ injectManifest: {
67
+ dontCacheBustURLsMatching,
68
+ ...userInjectManifest,
69
+ swSrc: path.resolve(viteConfig.root, swSrc),
70
+ swDest: path.resolve(viteConfig.root, viteConfig.build.outDir, swDest),
71
+ disablePrecacheManifest: !viteConfig.isProduction,
72
+ },
73
+ } satisfies PluginOptionsComplete;
74
+
75
+ return resolvedPluginOptions;
76
+ };
@@ -0,0 +1,35 @@
1
+ import { basePartial, globPartial, injectPartial, requiredGlobDirectoryPartial, requiredSwDestPartial } from "@serwist/build/schema";
2
+ import { z } from "zod";
3
+
4
+ export const hooks = z.object({
5
+ beforeBuildServiceWorker: z.function(z.tuple([z.any()]), z.union([z.promise(z.void()), z.void()])).optional(),
6
+ closeBundleOrder: z.union([z.literal("pre"), z.literal("post"), z.null()]).optional(),
7
+ configureOptions: z.function(z.tuple([z.any(), z.any()]), z.union([z.promise(z.void()), z.void()])).optional(),
8
+ });
9
+
10
+ export const devOptions = z.object({
11
+ bundle: z.boolean().default(true),
12
+ minify: z.union([z.boolean(), z.literal("terser"), z.literal("esbuild")]).default(false),
13
+ });
14
+
15
+ export const injectManifestPartial = z.object({
16
+ mode: z.union([z.literal("development"), z.literal("production")]),
17
+ type: z.union([z.literal("classic"), z.literal("module")]).default("classic"),
18
+ scope: z.string(),
19
+ base: z.string(),
20
+ disable: z.boolean().default(false),
21
+ integration: hooks.default({}),
22
+ swUrl: z.string().default("/sw.js"),
23
+ plugins: z.array(z.any()).default([]),
24
+ rollupFormat: z.union([z.literal("es"), z.literal("iife")]).default("es"),
25
+ rollupOptions: z.record(z.string(), z.any()).default({}),
26
+ devOptions: devOptions.default({}),
27
+ });
28
+
29
+ export const injectManifestOptions = basePartial
30
+ .merge(globPartial)
31
+ .merge(injectPartial)
32
+ .merge(requiredSwDestPartial)
33
+ .merge(requiredGlobDirectoryPartial)
34
+ .merge(injectManifestPartial)
35
+ .strict("Do not pass invalid properties to InjectManifestOptions!");
@@ -0,0 +1,163 @@
1
+ import type {
2
+ BasePartial,
3
+ BaseResolved,
4
+ GlobPartial,
5
+ GlobResolved,
6
+ InjectPartial as BaseInjectPartial,
7
+ InjectResolved as BaseInjectResolved,
8
+ ManifestEntry,
9
+ RequiredGlobDirectoryPartial,
10
+ RequiredGlobDirectoryResolved,
11
+ RequiredSwDestPartial,
12
+ RequiredSwDestResolved,
13
+ } from "@serwist/build";
14
+ import type { Require } from "@serwist/utils";
15
+ import type { RollupOptions } from "rollup";
16
+ import type { BuildOptions, Plugin, ResolvedConfig } from "vite";
17
+
18
+ export interface InjectPartial {
19
+ /**
20
+ * The mode in which Serwist should be built.
21
+ *
22
+ * @default
23
+ * process.env.NODE_ENV // or "production" if undefined
24
+ */
25
+ mode?: "development" | "production";
26
+ /**
27
+ * The service worker type.
28
+ *
29
+ * @default "classic"
30
+ */
31
+ type?: WorkerType;
32
+ /**
33
+ * The scope with which Serwist should register the service worker.
34
+ *
35
+ * @default viteOptions.base
36
+ */
37
+ scope?: string;
38
+ /**
39
+ * The base from which Serwist resolves URLs.
40
+ *
41
+ * @default viteOptions.base
42
+ */
43
+ base?: string;
44
+ /**
45
+ * Whether Serwist should be disabled.
46
+ *
47
+ * @default false
48
+ */
49
+ disable?: boolean;
50
+ /**
51
+ * Hooks of the build lifecycle.
52
+ */
53
+ integration?: Hooks;
54
+ /**
55
+ * The URL to the service worker.
56
+ *
57
+ * @default "/sw.js"
58
+ */
59
+ swUrl?: string;
60
+ /**
61
+ * Plugins used to build your service worker.
62
+ */
63
+ plugins?: Plugin[];
64
+ /**
65
+ * The format used to build the service worker.
66
+ *
67
+ * @default "es"
68
+ */
69
+ rollupFormat?: "es" | "iife";
70
+ /**
71
+ * Custom Rollup options used to build the service worker.
72
+ */
73
+ rollupOptions?: Omit<RollupOptions, "plugins" | "output">;
74
+ /**
75
+ * Development-specific options.
76
+ */
77
+ devOptions?: DevOptions;
78
+ }
79
+
80
+ export interface InjectResolved extends Require<InjectPartial, "mode" | "type" | "scope" | "base" | "disable" | "swUrl" | "rollupFormat"> {
81
+ devOptions: Required<DevOptions>;
82
+ }
83
+
84
+ export interface InjectManifestOptions
85
+ extends Omit<BasePartial, "disablePrecacheManifest">,
86
+ GlobPartial,
87
+ BaseInjectPartial,
88
+ RequiredSwDestPartial,
89
+ RequiredGlobDirectoryPartial,
90
+ InjectPartial {}
91
+
92
+ export interface InjectManifestOptionsComplete
93
+ extends BaseResolved,
94
+ GlobResolved,
95
+ BaseInjectResolved,
96
+ RequiredSwDestResolved,
97
+ RequiredGlobDirectoryResolved,
98
+ InjectResolved {}
99
+
100
+ export interface Hooks {
101
+ beforeBuildServiceWorker?: (options: PluginOptionsComplete) => void | Promise<void>;
102
+ closeBundleOrder?: "pre" | "post" | null;
103
+ configureOptions?: (viteOptions: ResolvedConfig, options: PluginOptions) => void | Promise<void>;
104
+ }
105
+
106
+ export interface DevOptions {
107
+ /**
108
+ * Whether the service worker should be bundled in development mode.
109
+ *
110
+ * Many browsers still [do not support ES Modules in service workers](https://caniuse.com/mdn-api_serviceworker_ecmascript_modules). However, in development
111
+ * mode, certain frameworks, such as SvelteKit, do not bundle the service worker. As a result, trying to register that service worker on browsers lacking
112
+ * support, such as Firefox or Safari, will fail, but doing so on browsers not lacking support will not fail. This option is provided to prevent that from
113
+ * happening. What the plugin does is intercepting any request to the service worker (requests for `swUrl`) and returning a bundled one.
114
+ *
115
+ * @default true
116
+ */
117
+ bundle?: boolean;
118
+ /**
119
+ * Whether the service worker should be minified in development mode.
120
+ *
121
+ * @default false
122
+ */
123
+ minify?: BuildOptions["minify"];
124
+ }
125
+
126
+ export interface PluginOptions extends InjectManifestOptions {}
127
+
128
+ export interface PluginOptionsComplete extends InjectResolved {
129
+ injectManifest: Omit<InjectManifestOptionsComplete, keyof InjectResolved>;
130
+ }
131
+
132
+ export interface ShareTargetFiles {
133
+ name: string;
134
+ accept: string | string[];
135
+ }
136
+
137
+ // biome-ignore lint/complexity/noBannedTypes: We intentionally do this.
138
+ type Nothing = {};
139
+
140
+ /**
141
+ * type StringLiteralUnion<'maskable'> = 'maskable' | string
142
+ * This has auto completion whereas `'maskable' | string` doesn't
143
+ * Adapted from https://github.com/microsoft/TypeScript/issues/29729
144
+ */
145
+ export type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
146
+
147
+ export interface SerwistViteApi {
148
+ /**
149
+ * Whether the plugin is disabled.
150
+ */
151
+ disabled: boolean;
152
+ /**
153
+ * Extends the precache manifest.
154
+ * @param fn
155
+ */
156
+ extendManifestEntries(fn: ExtendManifestEntriesHook): void;
157
+ /*
158
+ * Generates the service worker.
159
+ */
160
+ generateSW(): Promise<void>;
161
+ }
162
+
163
+ export type ExtendManifestEntriesHook = (manifestEntries: (string | ManifestEntry)[]) => (string | ManifestEntry)[] | undefined;
@@ -0,0 +1,10 @@
1
+ import { SerwistConfigError, validationErrorMap } from "@serwist/build/schema";
2
+ import type { InjectManifestOptionsComplete } from "./types.js";
3
+
4
+ export const validateInjectManifestOptions = async (input: unknown): Promise<InjectManifestOptionsComplete> => {
5
+ const result = await (await import("./schema.js")).injectManifestOptions.spa(input, { errorMap: validationErrorMap });
6
+ if (!result.success) {
7
+ throw new SerwistConfigError({ moduleName: "@serwist/vite", message: JSON.stringify(result.error.format(), null, 2) });
8
+ }
9
+ return result.data;
10
+ };
@@ -1,7 +1,7 @@
1
1
  import type { Plugin } from "vite";
2
2
 
3
- import type { SerwistViteContext } from "../context.js";
4
- import type { SerwistViteApi } from "../types.js";
3
+ import type { SerwistViteContext } from "../lib/context.js";
4
+ import type { SerwistViteApi } from "../lib/types.js";
5
5
 
6
6
  /**
7
7
  * Internal build plugin used by `@serwist/vite`.
@@ -3,9 +3,9 @@ import path from "node:path";
3
3
 
4
4
  import { type Plugin, normalizePath } from "vite";
5
5
 
6
- import type { SerwistViteContext } from "../context.js";
7
- import type { SerwistViteApi } from "../types.js";
8
- import { toFs } from "../utils.js";
6
+ import type { SerwistViteContext } from "../lib/context.js";
7
+ import type { SerwistViteApi } from "../lib/types.js";
8
+ import { toFs } from "../lib/utils.js";
9
9
 
10
10
  // This plugin handles the service worker in two ways:
11
11
  // - If `devOptions.bundle` is enabled, hook a middleware that bundles the service worker
@@ -2,10 +2,10 @@ import path from "node:path";
2
2
 
3
3
  import type { Plugin, UserConfig } from "vite";
4
4
 
5
- import { INTERNAL_SERWIST_VIRTUAL, RESOLVED_INTERNAL_SERWIST_VIRTUAL } from "../constants.js";
6
- import type { SerwistViteContext } from "../context.js";
7
- import { resolveOptions } from "../options.js";
8
- import type { SerwistViteApi } from "../types.js";
5
+ import { INTERNAL_SERWIST_VIRTUAL, RESOLVED_INTERNAL_SERWIST_VIRTUAL } from "../lib/constants.js";
6
+ import type { SerwistViteContext } from "../lib/context.js";
7
+ import { resolveOptions } from "../lib/options.js";
8
+ import type { SerwistViteApi } from "../lib/types.js";
9
9
 
10
10
  /**
11
11
  * Internal plugin used by `@serwist/vite`.
@@ -38,7 +38,7 @@ export const mainPlugin = (ctx: SerwistViteContext, api: SerwistViteApi) => {
38
38
  },
39
39
  load(id) {
40
40
  if (id === RESOLVED_INTERNAL_SERWIST_VIRTUAL) {
41
- return `export const swUrl = "${path.posix.join(ctx.options.buildBase, ctx.options.swUrl)}";
41
+ return `export const swUrl = "${path.posix.join(ctx.options.base, ctx.options.swUrl)}";
42
42
  export const swScope = "${ctx.options.scope}";
43
43
  export const swType = "${ctx.devEnvironment ? "module" : ctx.options.type}";`;
44
44
  }
package/src/rollup.js CHANGED
@@ -1,28 +1,8 @@
1
1
  // @ts-check
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
-
5
2
  import { getRollupOptions } from "@serwist/constants/rollup";
6
- import fg from "fast-glob";
7
3
 
8
4
  import packageJson from "../package.json" assert { type: "json" };
9
5
 
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
-
12
- const clientEntries = /** @type {Record<string, string>} */ ({});
13
-
14
- for (const clientPath of await fg("client/*.ts", { cwd: __dirname })) {
15
- const parsedClientPath = path.parse(clientPath);
16
- clientEntries[`client/${parsedClientPath.name}`] = path.join("src", clientPath);
17
- }
18
-
19
- const integrationEntries = /** @type {Record<string, string>} */ ({});
20
-
21
- for (const integrationPath of await fg("integration/*/index.ts", { cwd: __dirname })) {
22
- const parsedClientPath = path.parse(integrationPath);
23
- integrationEntries[`${parsedClientPath.dir}/${parsedClientPath.name}`] = path.join("src", integrationPath);
24
- }
25
-
26
6
  export default getRollupOptions({
27
7
  packageJson,
28
8
  jsFiles: [
@@ -31,14 +11,13 @@ export default getRollupOptions({
31
11
  index: "src/index.ts",
32
12
  "index.browser": "src/index.browser.ts",
33
13
  "index.worker": "src/index.worker.ts",
34
- ...clientEntries,
35
- ...integrationEntries,
14
+ "index.schema": "src/index.schema.ts",
36
15
  },
37
16
  output: {
38
17
  dir: "dist",
39
- format: "esm",
40
18
  entryFileNames: "[name].js",
41
- chunkFileNames: "[name].js",
19
+ chunkFileNames: "chunks/[name].js",
20
+ format: "esm",
42
21
  },
43
22
  external: ["virtual:internal-serwist"],
44
23
  },
package/dist/api.d.ts.map DELETED
@@ -1 +0,0 @@
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 DELETED
@@ -1,4 +0,0 @@
1
- import type { ResolvedConfig } from "vite";
2
- import type { ResolvedPluginOptions } from "./types.js";
3
- export declare const configureStaticAssets: (resolvedPluginOptions: ResolvedPluginOptions, viteConfig: ResolvedConfig) => Promise<void>;
4
- //# sourceMappingURL=assets.d.ts.map
@@ -1 +0,0 @@
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 +0,0 @@
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"}
@@ -1 +0,0 @@
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,5 +0,0 @@
1
- import type { Plugin } from "vite";
2
- import type { SerwistViteContext } from "../../context.js";
3
- import type { SerwistViteApi } from "../../types.js";
4
- export declare const buildPlugin: (ctx: SerwistViteContext, api: SerwistViteApi) => Plugin<any>;
5
- //# sourceMappingURL=build.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,9 +0,0 @@
1
- import type { ManifestTransform } from "@serwist/build";
2
- import type { ResolvedConfig } from "vite";
3
- import type { PluginOptions as BasePluginOptions } from "../../types.js";
4
- import type { KitOptions } from "./types.js";
5
- export declare const configurateSvelteKitOptions: (viteConfig: ResolvedConfig, kit: KitOptions, options: BasePluginOptions) => void;
6
- export declare function createManifestTransform(base: string, webManifestName?: string, options?: KitOptions): ManifestTransform;
7
- export declare function buildGlobPatterns(globPatterns?: string[]): string[];
8
- export declare function buildGlobIgnores(globIgnores?: string[]): string[];
9
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,10 +0,0 @@
1
- import type { Plugin } from "vite";
2
- import type { PluginOptions } from "./types.js";
3
- /**
4
- * Integrates Serwist into your SvelteKit app.
5
- * @param userOptions
6
- * @returns
7
- */
8
- export declare const serwist: (userOptions?: PluginOptions) => Plugin[];
9
- export * from "./types.js";
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,145 +0,0 @@
1
- import { r as resolveEntry, m as mainPlugin, d as devPlugin, c as createContext, a as createApi } from '../../main.js';
2
- import crypto from 'node:crypto';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { errors } from '@serwist/build';
6
- import 'node:fs/promises';
7
- import 'vite';
8
- import 'node:process';
9
- import 'node:fs';
10
- import 'fast-glob';
11
- import 'node:assert';
12
-
13
- const buildPlugin = (ctx, api)=>{
14
- return {
15
- name: "@serwist/vite/integration-svelte:build",
16
- apply: "build",
17
- enforce: "pre",
18
- closeBundle: {
19
- sequential: true,
20
- enforce: "pre",
21
- async handler () {
22
- if (api && !api.disabled && ctx.viteConfig.build.ssr) {
23
- await api.generateSW();
24
- }
25
- }
26
- }
27
- };
28
- };
29
-
30
- const configurateSvelteKitOptions = (viteConfig, kit, options)=>{
31
- const clientOutDir = path.resolve(viteConfig.root, viteConfig.build.outDir, "../client");
32
- if (viteConfig.isProduction) {
33
- options.swSrc = path.resolve(clientOutDir, "service-worker.js");
34
- options.swDest = path.resolve(clientOutDir, "service-worker.js");
35
- } else {
36
- const swSrc = resolveEntry(path.join(viteConfig.root, kit.files?.serviceWorker ?? "src/service-worker"));
37
- if (swSrc) {
38
- options.swSrc = swSrc;
39
- options.swDest = path.join(os.tmpdir(), `serwist-vite-integration-svelte-${crypto.randomUUID()}.js`);
40
- } else {
41
- throw new Error(errors["invalid-sw-src"]);
42
- }
43
- }
44
- options.swUrl = "/service-worker.js";
45
- if (!options.globDirectory) {
46
- options.globDirectory = path.resolve(clientOutDir, "..");
47
- }
48
- if (!options.manifestTransforms) {
49
- options.manifestTransforms = [
50
- createManifestTransform(viteConfig.base, undefined, kit)
51
- ];
52
- }
53
- let buildAssetsDir = kit.appDir ?? "_app/";
54
- if (buildAssetsDir[0] === "/") buildAssetsDir = buildAssetsDir.slice(1);
55
- if (buildAssetsDir[buildAssetsDir.length - 1] !== "/") buildAssetsDir += "/";
56
- if (!options.modifyURLPrefix) {
57
- options.globPatterns = buildGlobPatterns(options.globPatterns);
58
- if (kit.includeVersionFile) {
59
- options.globPatterns.push(`client/${buildAssetsDir}version.json`);
60
- }
61
- }
62
- options.globIgnores = buildGlobIgnores(options.globIgnores);
63
- if (!("dontCacheBustURLsMatching" in options)) {
64
- options.dontCacheBustURLsMatching = new RegExp(`${buildAssetsDir}immutable/`);
65
- }
66
- if (!options.injectionPoint) {
67
- options.injectionPoint = "self.__SW_MANIFEST";
68
- }
69
- };
70
- function createManifestTransform(base, webManifestName, options) {
71
- return async (entries)=>{
72
- const defaultAdapterFallback = "prerendered/fallback.html";
73
- const suffix = options?.trailingSlash === "always" ? "/" : "";
74
- let adapterFallback = options?.adapterFallback;
75
- let excludeFallback = false;
76
- if (!adapterFallback) {
77
- adapterFallback = defaultAdapterFallback;
78
- excludeFallback = true;
79
- }
80
- const manifest = entries.filter(({ url })=>!(excludeFallback && url === defaultAdapterFallback)).map((e)=>{
81
- let url = e.url;
82
- if (url.startsWith("client/")) url = url.slice(7);
83
- else if (url.startsWith("prerendered/pages/")) url = url.slice(18);
84
- else if (url === defaultAdapterFallback) url = adapterFallback;
85
- if (url.endsWith(".html")) {
86
- if (url.startsWith("/")) url = url.slice(1);
87
- if (url === "index.html") {
88
- url = base;
89
- } else {
90
- const idx = url.lastIndexOf("/");
91
- if (idx > -1) {
92
- if (url.endsWith("/index.html")) url = `${url.slice(0, idx)}${suffix}`;
93
- else url = `${url.substring(0, url.lastIndexOf("."))}${suffix}`;
94
- } else {
95
- url = `${url.substring(0, url.lastIndexOf("."))}${suffix}`;
96
- }
97
- }
98
- }
99
- e.url = url;
100
- return e;
101
- });
102
- if (!webManifestName) return {
103
- manifest
104
- };
105
- return {
106
- manifest: manifest.filter((e)=>e.url !== webManifestName)
107
- };
108
- };
109
- }
110
- function buildGlobPatterns(globPatterns) {
111
- if (globPatterns) {
112
- if (!globPatterns.some((g)=>g.startsWith("prerendered/"))) globPatterns.push("prerendered/**/*.html");
113
- if (!globPatterns.some((g)=>g.startsWith("client/"))) globPatterns.push("client/**/*.{js,css,ico,png,svg,webp,webmanifest}");
114
- if (!globPatterns.some((g)=>g.includes("webmanifest"))) globPatterns.push("client/*.webmanifest");
115
- return globPatterns;
116
- }
117
- return [
118
- "client/**/*.{js,css,ico,png,svg,webp,webmanifest}",
119
- "prerendered/**/*.html"
120
- ];
121
- }
122
- function buildGlobIgnores(globIgnores) {
123
- if (globIgnores) {
124
- if (!globIgnores.some((g)=>g.startsWith("server/"))) globIgnores.push("server/*.*");
125
- return globIgnores;
126
- }
127
- return [
128
- "server/*.*"
129
- ];
130
- }
131
-
132
- const serwist = (userOptions = {})=>{
133
- if (!userOptions.integration) userOptions.integration = {};
134
- userOptions.integration.closeBundleOrder = "pre";
135
- userOptions.integration.configureOptions = (viteConfig, options)=>configurateSvelteKitOptions(viteConfig, userOptions.kit ?? {}, options);
136
- const ctx = createContext(userOptions, "sveltekit");
137
- const api = createApi(ctx);
138
- return [
139
- mainPlugin(ctx, api),
140
- devPlugin(ctx, api),
141
- buildPlugin(ctx, api)
142
- ];
143
- };
144
-
145
- export { serwist };
@@ -1,24 +0,0 @@
1
- import type { KitConfig } from "@sveltejs/kit";
2
- import type { PluginOptions as BasePluginOptions } from "../../types.js";
3
- import type { Optional } from "../../utils-types.js";
4
- export interface KitOptions extends Pick<KitConfig, "appDir" | "files"> {
5
- /**
6
- * @see https://kit.svelte.dev/docs/adapter-static#options-fallback
7
- */
8
- adapterFallback?: string;
9
- /**
10
- * `trailingSlash` in `+page.{ts,js}` or `+layout.{ts,js}` files.
11
- * @default "never"
12
- */
13
- trailingSlash?: "never" | "always" | "ignore";
14
- /**
15
- * Should `"${appDir}/version.json"` be included in the service worker's precache manifest?
16
- *
17
- * @default false
18
- */
19
- includeVersionFile?: boolean;
20
- }
21
- export interface PluginOptions extends Optional<Omit<BasePluginOptions, "swSrc" | "swDest" | "swUrl">, "globDirectory"> {
22
- kit?: KitOptions;
23
- }
24
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
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.map DELETED
@@ -1 +0,0 @@
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"}