@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
package/dist/main.js DELETED
@@ -1,470 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path, { resolve } from 'node:path';
3
- import { normalizePath } from 'vite';
4
- import process$1 from 'node:process';
5
- import crypto from 'node:crypto';
6
- import fs$1 from 'node:fs';
7
- import fg from 'fast-glob';
8
- import assert from 'node:assert';
9
-
10
- let enabled = true;
11
- const globalVar = typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
12
- let supportLevel = 0;
13
- if (globalVar.process && globalVar.process.env && globalVar.process.stdout) {
14
- const { FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, COLORTERM } = globalVar.process.env;
15
- if (NODE_DISABLE_COLORS || NO_COLOR || FORCE_COLOR === '0') {
16
- enabled = false;
17
- } else if (FORCE_COLOR === '1' || FORCE_COLOR === '2' || FORCE_COLOR === '3') {
18
- enabled = true;
19
- } else if (TERM === 'dumb') {
20
- enabled = false;
21
- } else if ('CI' in globalVar.process.env && [
22
- 'TRAVIS',
23
- 'CIRCLECI',
24
- 'APPVEYOR',
25
- 'GITLAB_CI',
26
- 'GITHUB_ACTIONS',
27
- 'BUILDKITE',
28
- 'DRONE'
29
- ].some((vendor)=>vendor in globalVar.process.env)) {
30
- enabled = true;
31
- } else {
32
- enabled = process.stdout.isTTY;
33
- }
34
- if (enabled) {
35
- if (process.platform === 'win32') {
36
- supportLevel = 3;
37
- } else {
38
- if (COLORTERM && (COLORTERM === 'truecolor' || COLORTERM === '24bit')) {
39
- supportLevel = 3;
40
- } else if (TERM && (TERM.endsWith('-256color') || TERM.endsWith('256'))) {
41
- supportLevel = 2;
42
- } else {
43
- supportLevel = 1;
44
- }
45
- }
46
- }
47
- }
48
- let options = {
49
- enabled,
50
- supportLevel
51
- };
52
- function kolorist(start, end, level = 1) {
53
- const open = `\x1b[${start}m`;
54
- const close = `\x1b[${end}m`;
55
- const regex = new RegExp(`\\x1b\\[${end}m`, 'g');
56
- return (str)=>{
57
- return options.enabled && options.supportLevel >= level ? open + ('' + str).replace(regex, open) + close : '' + str;
58
- };
59
- }
60
- const dim = kolorist(2, 22);
61
- const green = kolorist(32, 39);
62
- const yellow = kolorist(33, 39);
63
- const cyan = kolorist(36, 39);
64
-
65
- var version = "9.0.0-preview.2";
66
-
67
- const logSerwistResult = (buildResult, viteOptions)=>{
68
- const { logLevel = "info" } = viteOptions;
69
- if (logLevel === "silent") return;
70
- const { count, size, warnings } = buildResult;
71
- if (logLevel === "info") {
72
- console.info([
73
- "",
74
- `${cyan(`@serwist/vite v${version}`)} ${green("files generated.")}`,
75
- `${green("✓")} ${count} precache entries ${dim(`(${(size / 1024).toFixed(2)} KiB)`)}`,
76
- warnings && warnings.length > 0 ? yellow([
77
- "⚠ warnings",
78
- ...warnings.map((w)=>` ${w}`),
79
- ""
80
- ].join("\n")) : ""
81
- ].join("\n"));
82
- }
83
- };
84
-
85
- const loadSerwistBuild = async ()=>{
86
- try {
87
- return await import('@serwist/build');
88
- } catch (_) {
89
- return require("@serwist/build");
90
- }
91
- };
92
- const injectManifest = async (config)=>{
93
- const { validateViteInjectManifestOptions, getFileManifestEntries, stringify } = await loadSerwistBuild();
94
- const options = await validateViteInjectManifestOptions(config);
95
- const { count, size, manifestEntries, warnings } = await getFileManifestEntries(options);
96
- const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
97
- return {
98
- warnings,
99
- size,
100
- count,
101
- manifestEntries,
102
- manifestString
103
- };
104
- };
105
- const generateServiceWorker = async (ctx)=>{
106
- const { format, plugins, rollupOptions } = ctx.options.injectManifestRollupOptions;
107
- const parsedSwDest = path.parse(ctx.options.injectManifest.swDest);
108
- let injectManifestResult = undefined;
109
- if (ctx.options.injectManifest.injectionPoint) {
110
- await ctx.options.integration?.beforeBuildServiceWorker?.(ctx.options);
111
- injectManifestResult = await injectManifest(ctx.options.injectManifest);
112
- }
113
- const isProduction = ctx.options.mode === "production";
114
- const isDev = ctx.options.mode === "development";
115
- if (isProduction && ctx.framework === "sveltekit" || isDev && !ctx.options.devOptions.bundle) {
116
- if (!injectManifestResult) {
117
- throw new Error("injectManifest failed to generate results. This is likely a bug.");
118
- }
119
- const { errors, escapeRegExp, getSourceMapURL, rebasePath, replaceAndUpdateSourceMap, translateURLToSourcemapPaths } = await loadSerwistBuild();
120
- for (const file of [
121
- ctx.options.injectManifest.swSrc,
122
- ctx.options.injectManifest.swDest
123
- ]){
124
- ctx.options.injectManifest.globIgnores.push(rebasePath({
125
- file,
126
- baseDirectory: ctx.options.injectManifest.globDirectory
127
- }));
128
- }
129
- const injectionPoint = ctx.options.injectManifest.injectionPoint;
130
- const globalRegexp = new RegExp(escapeRegExp(injectionPoint), "g");
131
- let swFileContents;
132
- try {
133
- swFileContents = await fs.readFile(ctx.options.injectManifest.swSrc, "utf8");
134
- } catch (error) {
135
- throw new Error(`${errors["invalid-sw-src"]} ${error instanceof Error && error.message ? error.message : ""}`);
136
- }
137
- const injectionResults = swFileContents.match(globalRegexp);
138
- if (!injectionResults) {
139
- throw new Error(`${errors["injection-point-not-found"]} ${injectionPoint}`);
140
- }
141
- assert(injectionResults.length === 1, `${errors["multiple-injection-points"]} ${injectionPoint}`);
142
- const filesToWrite = {};
143
- const url = getSourceMapURL(swFileContents);
144
- const { destPath, srcPath, warning } = translateURLToSourcemapPaths(url, ctx.options.injectManifest.swSrc, ctx.options.injectManifest.swDest);
145
- if (warning) {
146
- injectManifestResult.warnings.push(warning);
147
- }
148
- if (srcPath && destPath) {
149
- const { map, source } = await replaceAndUpdateSourceMap({
150
- originalMap: JSON.parse(await fs.readFile(srcPath, "utf8")),
151
- jsFilename: path.basename(ctx.options.injectManifest.swDest),
152
- originalSource: swFileContents,
153
- replaceString: injectManifestResult.manifestString,
154
- searchString: injectionPoint
155
- });
156
- filesToWrite[ctx.options.injectManifest.swDest] = source;
157
- filesToWrite[destPath] = map;
158
- } else {
159
- filesToWrite[ctx.options.injectManifest.swDest] = swFileContents.replace(globalRegexp, injectManifestResult.manifestString);
160
- }
161
- for (const [file, contents] of Object.entries(filesToWrite)){
162
- try {
163
- await fs.mkdir(path.dirname(file), {
164
- recursive: true
165
- });
166
- } catch (error) {
167
- throw new Error(`${errors["unable-to-make-sw-directory"]} '${error instanceof Error && error.message ? error.message : ""}'`);
168
- }
169
- await fs.writeFile(file, contents);
170
- }
171
- } else {
172
- const define = {
173
- ...ctx.framework === "nuxt" ? undefined : ctx.viteConfig.define,
174
- "process.env.NODE_ENV": `"${ctx.options.mode}"`
175
- };
176
- if (ctx.options.injectManifest.injectionPoint && injectManifestResult) {
177
- define[ctx.options.injectManifest.injectionPoint] = injectManifestResult.manifestString;
178
- }
179
- const { build } = await import('vite');
180
- await build({
181
- logLevel: ctx.viteConfig.isProduction ? "info" : "warn",
182
- root: ctx.viteConfig.root,
183
- base: ctx.viteConfig.base,
184
- resolve: ctx.viteConfig.resolve,
185
- publicDir: false,
186
- build: {
187
- sourcemap: ctx.viteConfig.build.sourcemap,
188
- lib: {
189
- entry: ctx.options.injectManifest.swSrc,
190
- name: "app",
191
- formats: [
192
- format
193
- ]
194
- },
195
- rollupOptions: {
196
- ...rollupOptions,
197
- plugins,
198
- output: {
199
- entryFileNames: parsedSwDest.base
200
- }
201
- },
202
- outDir: parsedSwDest.dir,
203
- emptyOutDir: false,
204
- minify: isProduction || ctx.options.devOptions.minify
205
- },
206
- configFile: false,
207
- define
208
- });
209
- }
210
- return injectManifestResult;
211
- };
212
-
213
- const createApi = (ctx)=>{
214
- return {
215
- get disabled () {
216
- return ctx?.options?.disable;
217
- },
218
- async generateSW () {
219
- if (ctx.options.disable) {
220
- return undefined;
221
- }
222
- const buildResult = await generateServiceWorker(ctx);
223
- if (buildResult) {
224
- if (ctx.viteConfig.isProduction) {
225
- logSerwistResult(buildResult, ctx.viteConfig);
226
- } else if (buildResult.warnings && buildResult.warnings.length > 0) {
227
- console.warn(yellow([
228
- "[@serwist/vite] Warnings",
229
- ...buildResult.warnings.map((w)=>` - ${w}`),
230
- ""
231
- ].join("\n")));
232
- }
233
- }
234
- },
235
- extendManifestEntries (fn) {
236
- const { options } = ctx;
237
- if (options.disable) return;
238
- const result = fn(options.injectManifest.additionalPrecacheEntries || []);
239
- if (result != null) {
240
- options.injectManifest.additionalPrecacheEntries = result;
241
- }
242
- }
243
- };
244
- };
245
-
246
- const createContext = (userOptions, framework)=>{
247
- return {
248
- userOptions,
249
- options: undefined,
250
- viteConfig: undefined,
251
- useImportRegister: false,
252
- devEnvironment: false,
253
- framework
254
- };
255
- };
256
-
257
- const slash = (str)=>{
258
- return str.replace(/\\/g, "/");
259
- };
260
- const resolveBasePath = (base)=>{
261
- if (isAbsolute(base)) return base;
262
- return !base.startsWith("/") && !base.startsWith("./") ? `/${base}` : base;
263
- };
264
- const isAbsolute = (url)=>{
265
- return url.match(/^(?:[a-z]+:)?\/\//i);
266
- };
267
- const resolveEntry = (entry)=>{
268
- if (fs$1.existsSync(entry)) {
269
- const stats = fs$1.statSync(entry);
270
- if (stats.isDirectory()) {
271
- return resolveEntry(path.join(entry, "index"));
272
- }
273
- return entry;
274
- }
275
- const dir = path.dirname(entry);
276
- if (fs$1.existsSync(dir)) {
277
- const base = path.basename(entry);
278
- const files = fs$1.readdirSync(dir);
279
- const found = files.find((file)=>file.replace(/\.[^.]+$/, "") === base);
280
- if (found) return path.join(dir, found);
281
- }
282
- return null;
283
- };
284
- const toFs = (str)=>{
285
- str = str.replace(/\\/g, "/");
286
- return `/@fs${str.startsWith("/") ? "" : "/"}${str}`;
287
- };
288
-
289
- const devPlugin = (ctx, api)=>{
290
- return {
291
- name: "@serwist/vite:dev",
292
- apply: "serve",
293
- configureServer (server) {
294
- ctx.devEnvironment = true;
295
- server.middlewares.use(async (req, res, next)=>{
296
- if (!ctx.options.disable && req.url === ctx.options.swUrl) {
297
- if (ctx.options.devOptions.bundle) {
298
- await api.generateSW();
299
- const content = await fs.readFile(ctx.options.injectManifest.swDest, "utf-8");
300
- await fs.rm(ctx.options.injectManifest.swDest);
301
- res.setHeader("Content-Type", "application/javascript");
302
- res.write(content);
303
- res.end();
304
- } else {
305
- res.setHeader("Content-Type", "application/javascript");
306
- res.write(`import "${toFs(path.resolve(ctx.options.injectManifest.swSrc))}";`);
307
- res.end();
308
- }
309
- } else {
310
- next();
311
- }
312
- });
313
- },
314
- async load (id) {
315
- if (!ctx.options.disable && !ctx.options.devOptions.bundle) {
316
- const swSrcId = normalizePath(ctx.options.injectManifest.swSrc);
317
- if (id === swSrcId) {
318
- await api.generateSW();
319
- const content = await fs.readFile(ctx.options.injectManifest.swDest, "utf-8");
320
- await fs.rm(ctx.options.injectManifest.swDest);
321
- return content;
322
- }
323
- }
324
- return undefined;
325
- }
326
- };
327
- };
328
-
329
- const INTERNAL_SERWIST_VIRTUAL = "virtual:internal-serwist";
330
- const RESOLVED_INTERNAL_SERWIST_VIRTUAL = `\0${INTERNAL_SERWIST_VIRTUAL}`;
331
-
332
- const buildManifestEntry = (publicDir, url)=>{
333
- return new Promise((resolve$1, reject)=>{
334
- const cHash = crypto.createHash("MD5");
335
- const stream = fs$1.createReadStream(resolve(publicDir, url));
336
- stream.on("error", (err)=>{
337
- reject(err);
338
- });
339
- stream.on("data", (chunk)=>{
340
- cHash.update(chunk);
341
- });
342
- stream.on("end", ()=>{
343
- return resolve$1({
344
- url,
345
- revision: `${cHash.digest("hex")}`
346
- });
347
- });
348
- });
349
- };
350
- const lookupAdditionalPrecacheEntries = (serwistOptions)=>{
351
- return serwistOptions.additionalPrecacheEntries || [];
352
- };
353
- const normalizeIconPath = (path)=>{
354
- return path.startsWith("/") ? path.substring(1) : path;
355
- };
356
- const configureStaticAssets = async (resolvedPluginOptions, viteConfig)=>{
357
- const { injectManifest, includeAssets } = resolvedPluginOptions;
358
- const { publicDir } = viteConfig;
359
- const globs = [];
360
- const manifestEntries = lookupAdditionalPrecacheEntries(injectManifest);
361
- if (includeAssets) {
362
- if (Array.isArray(includeAssets)) globs.push(...includeAssets.map(normalizeIconPath));
363
- else globs.push(normalizeIconPath(includeAssets));
364
- }
365
- if (globs.length > 0) {
366
- let assets = await fg(globs, {
367
- cwd: publicDir,
368
- onlyFiles: true,
369
- unique: true
370
- });
371
- if (manifestEntries.length > 0) {
372
- const included = manifestEntries.map((me)=>{
373
- if (typeof me === "string") return me;
374
- return me.url;
375
- });
376
- assets = assets.filter((a)=>!included.includes(a));
377
- }
378
- const assetsEntries = await Promise.all(assets.map((a)=>{
379
- return buildManifestEntry(publicDir, a);
380
- }));
381
- manifestEntries.push(...assetsEntries);
382
- }
383
- if (manifestEntries.length > 0) {
384
- injectManifest.additionalPrecacheEntries = manifestEntries;
385
- }
386
- };
387
-
388
- const resolveOptions = async (options, viteConfig)=>{
389
- const { type = "classic", mode = process$1.env.NODE_ENV || "production", injectRegister = "auto", registerType = "prompt", minify = true, base = viteConfig.base, scope: _scope, swUrl = "/sw.js", includeAssets = undefined, useCredentials = false, disable = false, integration = {}, buildBase, devOptions, plugins = [], rollupOptions = {}, rollupFormat = "es", ...injectManifest } = options;
390
- const basePath = resolveBasePath(base);
391
- const scope = _scope || basePath;
392
- let assetsDir = slash(viteConfig.build.assetsDir ?? "assets");
393
- if (assetsDir[assetsDir.length - 1] !== "/") assetsDir += "/";
394
- const resolvedDevOptions = {
395
- bundle: true,
396
- minify: false,
397
- ...devOptions
398
- };
399
- const dontCacheBustURLsMatching = new RegExp(`^${assetsDir.replace(/^\.*?\//, "")}`);
400
- const { validateViteInjectManifestOptions } = await loadSerwistBuild();
401
- const validatedInjectManifest = await validateViteInjectManifestOptions(injectManifest);
402
- const { swSrc, swDest, ...userInjectManifest } = validatedInjectManifest || {};
403
- const resolvedPluginOptions = {
404
- base: basePath,
405
- type,
406
- mode,
407
- injectRegister,
408
- registerType,
409
- useCredentials,
410
- swUrl,
411
- injectManifest: {
412
- dontCacheBustURLsMatching,
413
- ...userInjectManifest,
414
- swSrc: path.resolve(viteConfig.root, swSrc),
415
- swDest: path.resolve(viteConfig.root, viteConfig.build.outDir, swDest),
416
- disablePrecacheManifest: !viteConfig.isProduction
417
- },
418
- scope,
419
- minify,
420
- includeAssets,
421
- disable,
422
- integration,
423
- buildBase: buildBase ?? basePath,
424
- injectManifestRollupOptions: {
425
- plugins,
426
- rollupOptions,
427
- format: rollupFormat
428
- },
429
- devOptions: resolvedDevOptions
430
- };
431
- const calculateHash = !resolvedPluginOptions.disable && resolvedPluginOptions.includeAssets && viteConfig.command === "build";
432
- if (calculateHash) await configureStaticAssets(resolvedPluginOptions, viteConfig);
433
- return resolvedPluginOptions;
434
- };
435
-
436
- const mainPlugin = (ctx, api)=>{
437
- return {
438
- name: "@serwist/vite",
439
- enforce: "pre",
440
- config () {
441
- return {
442
- ssr: {
443
- noExternal: []
444
- }
445
- };
446
- },
447
- async configResolved (config) {
448
- ctx.viteConfig = config;
449
- ctx.userOptions?.integration?.configureOptions?.(config, ctx.userOptions);
450
- ctx.options = await resolveOptions(ctx.userOptions, config);
451
- },
452
- resolveId (id) {
453
- if (id === INTERNAL_SERWIST_VIRTUAL) {
454
- return RESOLVED_INTERNAL_SERWIST_VIRTUAL;
455
- }
456
- return undefined;
457
- },
458
- load (id) {
459
- if (id === RESOLVED_INTERNAL_SERWIST_VIRTUAL) {
460
- return `export const swUrl = "${path.posix.join(ctx.options.buildBase, ctx.options.swUrl)}";
461
- export const swScope = "${ctx.options.scope}";
462
- export const swType = "${ctx.devEnvironment ? "module" : ctx.options.type}";`;
463
- }
464
- return undefined;
465
- },
466
- api
467
- };
468
- };
469
-
470
- export { createApi as a, createContext as c, devPlugin as d, mainPlugin as m, resolveEntry as r, toFs as t };
@@ -1 +0,0 @@
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 DELETED
@@ -1,4 +0,0 @@
1
- import type { ResolvedConfig } from "vite";
2
- import type { PluginOptions, ResolvedPluginOptions } from "./types.js";
3
- export declare const resolveOptions: (options: PluginOptions, viteConfig: ResolvedConfig) => Promise<ResolvedPluginOptions>;
4
- //# sourceMappingURL=options.d.ts.map
@@ -1 +0,0 @@
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"}
package/dist/types.d.ts DELETED
@@ -1,191 +0,0 @@
1
- import type { ManifestEntry, ViteInjectManifestOptions } from "@serwist/build";
2
- import type { RollupOptions } from "rollup";
3
- import type { BuildOptions, Plugin, ResolvedConfig } from "vite";
4
- export type InjectManifestVitePlugins = string[] | ((vitePluginIds: string[]) => string[]);
5
- export interface CustomInjectManifestOptions extends Omit<ViteInjectManifestOptions, "disablePrecacheManifest"> {
6
- /**
7
- * The URL to the service worker.
8
- * @default "/sw.js"
9
- */
10
- swUrl?: string;
11
- /**
12
- * Configure the format to use in the Rollup build.
13
- *
14
- * @default 'es'
15
- */
16
- rollupFormat?: "es" | "iife";
17
- /**
18
- * Since `v0.15.0` you can add plugins to build your service worker.
19
- *
20
- * When using `injectManifest` there are 2 builds, your application and the service worker.
21
- * If you're using custom configuration for your service worker (for example custom plugins) you can use this option to configure the service worker build.
22
- * Both configurations cannot be shared, and so you'll need to duplicate the configuration, with the exception of `define`.
23
- *
24
- * **WARN**: this option is for advanced usage, be aware that you may break your application build.
25
- */
26
- plugins?: Plugin[];
27
- /**
28
- * Since `v0.15.0` you can add custom Rollup options to build your service worker: we expose the same configuration to build a worker using Vite.
29
- */
30
- rollupOptions?: Omit<RollupOptions, "plugins" | "output">;
31
- }
32
- export interface SerwistViteHooks {
33
- beforeBuildServiceWorker?: (options: ResolvedPluginOptions) => void | Promise<void>;
34
- closeBundleOrder?: "pre" | "post" | null;
35
- configureOptions?: (viteOptions: ResolvedConfig, options: PluginOptions) => void | Promise<void>;
36
- }
37
- export interface DevOptions {
38
- /**
39
- * Whether the service worker should be bundled in development mode.
40
- *
41
- * [Many browsers still do not support ES Modules in service workers.](https://caniuse.com/mdn-api_serviceworker_ecmascript_modules) However, in development
42
- * mode, certain frameworks, such as SvelteKit, do not bundle the service worker. As a result, trying to register that service worker on browsers lacking
43
- * 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
44
- * happening. What the plugin does is intercepting any request to the service worker (requests for `swUrl`) and returning a bundled one.
45
- */
46
- bundle?: boolean;
47
- minify?: BuildOptions["minify"];
48
- }
49
- /**
50
- * Plugin options.
51
- */
52
- export interface BasePluginOptions {
53
- /**
54
- * Build mode
55
- *
56
- * @default
57
- * process.env.NODE_ENV // or "production" if undefined
58
- */
59
- mode?: "development" | "production";
60
- /**
61
- * The service worker type.
62
- *
63
- * @default "classic"
64
- */
65
- type?: WorkerType;
66
- /**
67
- * The scope to register the Service Worker
68
- *
69
- * @default `viteOptions.base`
70
- */
71
- scope?: string;
72
- /**
73
- * Inject the service worker register inlined in the index.html
74
- *
75
- * If set to "auto", depends on whether you used the `import { registerSW } from 'virtual:pwa-register'`
76
- * it will do nothing or use the `script` mode
77
- *
78
- * `"inline"` - inject a simple register, inlined with the generated html
79
- *
80
- * `"script"` - inject `<script/>` in `<head>` with `src` attribute to a generated script to register the service worker
81
- *
82
- * `"script-defer"` - inject `<script defer />` in `<head>`, with `src` attribute to a generated script to register the service worker
83
- *
84
- * `null` - do nothing. You will need to register the service worker yourself or import `registerSW` from `virtual:pwa-register`.
85
- *
86
- * @default "auto"
87
- */
88
- injectRegister: "inline" | "script" | "script-defer" | "auto" | null | false;
89
- /**
90
- * Mode for the virtual register.
91
- * This is NOT available if `injectRegister` is set to `"inline"` or `"script"`
92
- *
93
- * `"prompt"` - you will need to show a popup/dialog to the user to confirm the reload.
94
- *
95
- * `"autoUpdate"` - when new content is available, the new service worker will update caches and reload all browser
96
- * windows/tabs with the application open automatically, it must take the control for the application to work
97
- * properly.
98
- *
99
- * @default "prompt"
100
- */
101
- registerType?: "prompt" | "autoUpdate";
102
- /**
103
- * Minify the generated manifest
104
- *
105
- * @default true
106
- */
107
- minify: boolean;
108
- /**
109
- * Whether to add the `crossorigin="use-credentials"` attribute to `<link rel="manifest">`
110
- * @default false
111
- */
112
- useCredentials?: boolean;
113
- /**
114
- * Override Vite's base options for `@serwist/vite`.
115
- *
116
- * @default viteOptions.base
117
- */
118
- base?: string;
119
- /**
120
- * `public` resources to be added to the PWA manifest.
121
- *
122
- * You don't need to add `manifest` icons here, it will be auto included.
123
- *
124
- * The `public` directory will be resolved from Vite's `publicDir` option directory.
125
- */
126
- includeAssets: string | string[] | undefined;
127
- /**
128
- * Whether Serwist should be disabled.
129
- *
130
- * @default false
131
- */
132
- disable: boolean;
133
- /**
134
- * `@serwist/vite` integration.
135
- */
136
- integration?: SerwistViteHooks;
137
- /**
138
- * When Vite's build folder is not the same as your base root folder, configure it here.
139
- *
140
- * This option will be useful for integrations like `vite-plugin-laravel` where Vite's build folder is `public/build` but Laravel's base path is `public`.
141
- *
142
- * This option will be used to configure the path for the service worker, "registerSW.js" and the web manifest assets.
143
- *
144
- * For example, if your base path is `/`, then, in your Laravel PWA configuration use `buildPath: '/build/'`.
145
- *
146
- * By default: `vite.base`.
147
- */
148
- buildBase?: string;
149
- }
150
- export interface PluginOptions extends Partial<BasePluginOptions>, CustomInjectManifestOptions {
151
- devOptions?: DevOptions;
152
- }
153
- export interface InjectManifestRollupOptions {
154
- format: "es" | "iife";
155
- plugins: Plugin[];
156
- rollupOptions: RollupOptions;
157
- }
158
- export interface ResolvedPluginOptions extends Required<BasePluginOptions>, Required<Pick<CustomInjectManifestOptions, "swUrl">> {
159
- injectManifest: ViteInjectManifestOptions;
160
- injectManifestRollupOptions: InjectManifestRollupOptions;
161
- devOptions: Required<DevOptions>;
162
- }
163
- export interface ShareTargetFiles {
164
- name: string;
165
- accept: string | string[];
166
- }
167
- /**
168
- * @see https://developer.mozilla.org/en-US/docs/Web/Manifest/launch_handler#launch_handler_item_values
169
- */
170
- export type LaunchHandlerClientMode = "auto" | "focus-existing" | "navigate-existing" | "navigate-new";
171
- export type Display = "fullscreen" | "standalone" | "minimal-ui" | "browser";
172
- export type DisplayOverride = Display | "window-controls-overlay";
173
- export type IconPurpose = "monochrome" | "maskable" | "any";
174
- type Nothing = {};
175
- /**
176
- * type StringLiteralUnion<'maskable'> = 'maskable' | string
177
- * This has auto completion whereas `'maskable' | string` doesn't
178
- * Adapted from https://github.com/microsoft/TypeScript/issues/29729
179
- */
180
- export type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
181
- export interface SerwistViteApi {
182
- /**
183
- * Is the plugin disabled?
184
- */
185
- disabled: boolean;
186
- extendManifestEntries(fn: ExtendManifestEntriesHook): void;
187
- generateSW(): Promise<void>;
188
- }
189
- export type ExtendManifestEntriesHook = (manifestEntries: (string | ManifestEntry)[]) => (string | ManifestEntry)[] | undefined;
190
- export {};
191
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceR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gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,cAAc,CAAC;AAEvG,MAAM,MAAM,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,CAAC;AAC7E,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,yBAAyB,CAAC;AAClE,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC;AAG5D,KAAK,OAAO,GAAG,EAAE,CAAC;AAElB;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;AAE5E,MAAM,WAAW,cAAc;IAC7B;;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,2 +0,0 @@
1
- export type Optional<T, U extends keyof T> = Omit<T, U> & Partial<Pick<T, U>>;
2
- //# sourceMappingURL=utils-types.d.ts.map
@@ -1 +0,0 @@
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"}