@serwist/vite 9.0.0-preview.6 → 9.0.0-preview.8

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.
package/dist/context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ResolvedConfig } from "vite";
2
2
  import type { PluginOptions, ResolvedPluginOptions } from "./types.js";
3
- export type SerwistViteFrameworks = "nuxt" | "sveltekit";
3
+ export type SerwistViteFrameworks = "nuxt";
4
4
  export interface SerwistViteContext {
5
5
  /**
6
6
  * Resolved Vite config.
@@ -1 +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
+ {"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,CAAC;AAE3C,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"}
package/dist/index.js CHANGED
@@ -1,13 +1,258 @@
1
- import { m as mainPlugin, d as devPlugin, c as createContext, a as createApi } from './main.js';
2
- export { r as resolveEntry, t as toFs } from './main.js';
3
- import 'node:fs/promises';
4
- import 'node:path';
5
- import 'vite';
6
- import 'node:process';
7
- import 'node:crypto';
8
- import 'node:fs';
9
- import 'fast-glob';
10
- import 'node:assert';
1
+ import assert from 'node:assert';
2
+ import fs from 'node:fs/promises';
3
+ import path, { resolve } from 'node:path';
4
+ import { normalizePath } from 'vite';
5
+ import fs$1 from 'node:fs';
6
+ import process$1 from 'node:process';
7
+ import crypto from 'node:crypto';
8
+ import fg from 'fast-glob';
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.8";
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 (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
+ };
11
256
 
12
257
  const buildPlugin = (ctx, api)=>{
13
258
  return {
@@ -29,6 +274,219 @@ const buildPlugin = (ctx, api)=>{
29
274
  };
30
275
  };
31
276
 
277
+ const slash = (str)=>{
278
+ return str.replace(/\\/g, "/");
279
+ };
280
+ const resolveBasePath = (base)=>{
281
+ if (isAbsolute(base)) return base;
282
+ return !base.startsWith("/") && !base.startsWith("./") ? `/${base}` : base;
283
+ };
284
+ const isAbsolute = (url)=>{
285
+ return url.match(/^(?:[a-z]+:)?\/\//i);
286
+ };
287
+ const resolveEntry = (entry)=>{
288
+ if (fs$1.existsSync(entry)) {
289
+ const stats = fs$1.statSync(entry);
290
+ if (stats.isDirectory()) {
291
+ return resolveEntry(path.join(entry, "index"));
292
+ }
293
+ return entry;
294
+ }
295
+ const dir = path.dirname(entry);
296
+ if (fs$1.existsSync(dir)) {
297
+ const base = path.basename(entry);
298
+ const files = fs$1.readdirSync(dir);
299
+ const found = files.find((file)=>file.replace(/\.[^.]+$/, "") === base);
300
+ if (found) return path.join(dir, found);
301
+ }
302
+ return null;
303
+ };
304
+ const toFs = (str)=>{
305
+ str = str.replace(/\\/g, "/");
306
+ return `/@fs${str.startsWith("/") ? "" : "/"}${str}`;
307
+ };
308
+
309
+ const devPlugin = (ctx, api)=>{
310
+ return {
311
+ name: "@serwist/vite:dev",
312
+ apply: "serve",
313
+ configureServer (server) {
314
+ ctx.devEnvironment = true;
315
+ server.middlewares.use(async (req, res, next)=>{
316
+ if (!ctx.options.disable && req.url === ctx.options.swUrl) {
317
+ if (ctx.options.devOptions.bundle) {
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
+ res.setHeader("Content-Type", "application/javascript");
322
+ res.write(content);
323
+ res.end();
324
+ } else {
325
+ res.setHeader("Content-Type", "application/javascript");
326
+ res.write(`import "${toFs(path.resolve(ctx.options.injectManifest.swSrc))}";`);
327
+ res.end();
328
+ }
329
+ } else {
330
+ next();
331
+ }
332
+ });
333
+ },
334
+ async load (id) {
335
+ if (!ctx.options.disable && !ctx.options.devOptions.bundle) {
336
+ const swSrcId = normalizePath(ctx.options.injectManifest.swSrc);
337
+ if (id === swSrcId) {
338
+ await api.generateSW();
339
+ const content = await fs.readFile(ctx.options.injectManifest.swDest, "utf-8");
340
+ await fs.rm(ctx.options.injectManifest.swDest);
341
+ return content;
342
+ }
343
+ }
344
+ return undefined;
345
+ }
346
+ };
347
+ };
348
+
349
+ const INTERNAL_SERWIST_VIRTUAL = "virtual:internal-serwist";
350
+ const RESOLVED_INTERNAL_SERWIST_VIRTUAL = `\0${INTERNAL_SERWIST_VIRTUAL}`;
351
+
352
+ const buildManifestEntry = (publicDir, url)=>{
353
+ return new Promise((resolve$1, reject)=>{
354
+ const cHash = crypto.createHash("MD5");
355
+ const stream = fs$1.createReadStream(resolve(publicDir, url));
356
+ stream.on("error", (err)=>{
357
+ reject(err);
358
+ });
359
+ stream.on("data", (chunk)=>{
360
+ cHash.update(chunk);
361
+ });
362
+ stream.on("end", ()=>{
363
+ return resolve$1({
364
+ url,
365
+ revision: `${cHash.digest("hex")}`
366
+ });
367
+ });
368
+ });
369
+ };
370
+ const lookupAdditionalPrecacheEntries = (serwistOptions)=>{
371
+ return serwistOptions.additionalPrecacheEntries || [];
372
+ };
373
+ const normalizeIconPath = (path)=>{
374
+ return path.startsWith("/") ? path.substring(1) : path;
375
+ };
376
+ const configureStaticAssets = async (resolvedPluginOptions, viteConfig)=>{
377
+ const { injectManifest, includeAssets } = resolvedPluginOptions;
378
+ const { publicDir } = viteConfig;
379
+ const globs = [];
380
+ const manifestEntries = lookupAdditionalPrecacheEntries(injectManifest);
381
+ if (includeAssets) {
382
+ if (Array.isArray(includeAssets)) globs.push(...includeAssets.map(normalizeIconPath));
383
+ else globs.push(normalizeIconPath(includeAssets));
384
+ }
385
+ if (globs.length > 0) {
386
+ let assets = await fg(globs, {
387
+ cwd: publicDir,
388
+ onlyFiles: true,
389
+ unique: true
390
+ });
391
+ if (manifestEntries.length > 0) {
392
+ const included = manifestEntries.map((me)=>{
393
+ if (typeof me === "string") return me;
394
+ return me.url;
395
+ });
396
+ assets = assets.filter((a)=>!included.includes(a));
397
+ }
398
+ const assetsEntries = await Promise.all(assets.map((a)=>{
399
+ return buildManifestEntry(publicDir, a);
400
+ }));
401
+ manifestEntries.push(...assetsEntries);
402
+ }
403
+ if (manifestEntries.length > 0) {
404
+ injectManifest.additionalPrecacheEntries = manifestEntries;
405
+ }
406
+ };
407
+
408
+ const resolveOptions = async (options, viteConfig)=>{
409
+ const { type = "classic", mode = process$1.env.NODE_ENV === "production" || process$1.env.NODE_ENV === "development" ? 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;
410
+ const basePath = resolveBasePath(base);
411
+ const scope = _scope || basePath;
412
+ let assetsDir = slash(viteConfig.build.assetsDir ?? "assets");
413
+ if (assetsDir[assetsDir.length - 1] !== "/") assetsDir += "/";
414
+ const resolvedDevOptions = {
415
+ bundle: true,
416
+ minify: false,
417
+ ...devOptions
418
+ };
419
+ const dontCacheBustURLsMatching = new RegExp(`^${assetsDir.replace(/^\.*?\//, "")}`);
420
+ const { validateViteInjectManifestOptions } = await loadSerwistBuild();
421
+ const validatedInjectManifest = await validateViteInjectManifestOptions(injectManifest);
422
+ const { swSrc, swDest, ...userInjectManifest } = validatedInjectManifest || {};
423
+ const resolvedPluginOptions = {
424
+ base: basePath,
425
+ type,
426
+ mode,
427
+ injectRegister,
428
+ registerType,
429
+ useCredentials,
430
+ swUrl,
431
+ injectManifest: {
432
+ dontCacheBustURLsMatching,
433
+ ...userInjectManifest,
434
+ swSrc: path.resolve(viteConfig.root, swSrc),
435
+ swDest: path.resolve(viteConfig.root, viteConfig.build.outDir, swDest),
436
+ disablePrecacheManifest: !viteConfig.isProduction
437
+ },
438
+ scope,
439
+ minify,
440
+ includeAssets,
441
+ disable,
442
+ integration,
443
+ buildBase: buildBase ?? basePath,
444
+ injectManifestRollupOptions: {
445
+ plugins,
446
+ rollupOptions,
447
+ format: rollupFormat
448
+ },
449
+ devOptions: resolvedDevOptions
450
+ };
451
+ const calculateHash = !resolvedPluginOptions.disable && resolvedPluginOptions.includeAssets && viteConfig.command === "build";
452
+ if (calculateHash) await configureStaticAssets(resolvedPluginOptions, viteConfig);
453
+ return resolvedPluginOptions;
454
+ };
455
+
456
+ const mainPlugin = (ctx, api)=>{
457
+ return {
458
+ name: "@serwist/vite",
459
+ enforce: "pre",
460
+ config () {
461
+ return {
462
+ ssr: {
463
+ noExternal: []
464
+ }
465
+ };
466
+ },
467
+ async configResolved (config) {
468
+ ctx.viteConfig = config;
469
+ ctx.userOptions?.integration?.configureOptions?.(config, ctx.userOptions);
470
+ ctx.options = await resolveOptions(ctx.userOptions, config);
471
+ },
472
+ resolveId (id) {
473
+ if (id === INTERNAL_SERWIST_VIRTUAL) {
474
+ return RESOLVED_INTERNAL_SERWIST_VIRTUAL;
475
+ }
476
+ return undefined;
477
+ },
478
+ load (id) {
479
+ if (id === RESOLVED_INTERNAL_SERWIST_VIRTUAL) {
480
+ return `export const swUrl = "${path.posix.join(ctx.options.buildBase, ctx.options.swUrl)}";
481
+ export const swScope = "${ctx.options.scope}";
482
+ export const swType = "${ctx.devEnvironment ? "module" : ctx.options.type}";`;
483
+ }
484
+ return undefined;
485
+ },
486
+ api
487
+ };
488
+ };
489
+
32
490
  const serwist = (userOptions)=>{
33
491
  const ctx = createContext(userOptions, undefined);
34
492
  const api = createApi(ctx);
@@ -39,4 +497,4 @@ const serwist = (userOptions)=>{
39
497
  ];
40
498
  };
41
499
 
42
- export { buildPlugin as build, createApi, createContext, devPlugin as dev, mainPlugin as main, serwist };
500
+ export { buildPlugin as build, createApi, createContext, devPlugin as dev, mainPlugin as main, resolveEntry, serwist, toFs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/vite",
3
- "version": "9.0.0-preview.6",
3
+ "version": "9.0.0-preview.8",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Vite application.",
6
6
  "files": [
@@ -43,9 +43,6 @@
43
43
  ],
44
44
  "worker": [
45
45
  "./dist/index.worker.d.ts"
46
- ],
47
- "integration-*": [
48
- "./dist/integration/*/index.d.ts"
49
46
  ]
50
47
  }
51
48
  },
@@ -62,20 +59,16 @@
62
59
  "types": "./dist/index.worker.d.ts",
63
60
  "default": "./dist/index.worker.js"
64
61
  },
65
- "./integration-*": {
66
- "types": "./dist/integration/*/index.d.ts",
67
- "default": "./dist/integration/*/index.js"
68
- },
69
62
  "./package.json": "./package.json"
70
63
  },
71
64
  "dependencies": {
72
65
  "debug": "4.3.4",
73
66
  "fast-glob": "3.3.2",
74
67
  "pretty-bytes": "6.1.1",
75
- "@serwist/build": "9.0.0-preview.6",
76
- "@serwist/expiration": "9.0.0-preview.6",
77
- "@serwist/strategies": "9.0.0-preview.6",
78
- "@serwist/window": "9.0.0-preview.6"
68
+ "@serwist/build": "9.0.0-preview.8",
69
+ "@serwist/expiration": "9.0.0-preview.8",
70
+ "@serwist/strategies": "9.0.0-preview.8",
71
+ "@serwist/window": "9.0.0-preview.8"
79
72
  },
80
73
  "devDependencies": {
81
74
  "@playwright/test": "1.41.2",
@@ -96,8 +89,8 @@
96
89
  "typescript": "5.4.0-dev.20240206",
97
90
  "vite": "5.0.12",
98
91
  "vue": "3.4.15",
99
- "@serwist/constants": "9.0.0-preview.6",
100
- "@serwist/sw": "9.0.0-preview.6"
92
+ "@serwist/constants": "9.0.0-preview.8",
93
+ "@serwist/sw": "9.0.0-preview.8"
101
94
  },
102
95
  "peerDependencies": {
103
96
  "@sveltejs/kit": "^1.0.0 || ^2.0.0",
@@ -108,7 +101,7 @@
108
101
  "typescript": ">=5.0.0",
109
102
  "vite": "^5.0.0",
110
103
  "vue": "^3.0.0",
111
- "@serwist/sw": "9.0.0-preview.6"
104
+ "@serwist/sw": "9.0.0-preview.8"
112
105
  },
113
106
  "peerDependenciesMeta": {
114
107
  "@serwist/sw": {
package/src/context.ts CHANGED
@@ -2,7 +2,7 @@ import type { ResolvedConfig } from "vite";
2
2
 
3
3
  import type { PluginOptions, ResolvedPluginOptions } from "./types.js";
4
4
 
5
- export type SerwistViteFrameworks = "nuxt" | "sveltekit";
5
+ export type SerwistViteFrameworks = "nuxt";
6
6
 
7
7
  export interface SerwistViteContext {
8
8
  /**
package/src/modules.ts CHANGED
@@ -50,7 +50,7 @@ export const generateServiceWorker = async (ctx: SerwistViteContext) => {
50
50
  const isProduction = ctx.options.mode === "production";
51
51
  const isDev = ctx.options.mode === "development";
52
52
 
53
- if ((isProduction && ctx.framework === "sveltekit") || (isDev && !ctx.options.devOptions.bundle)) {
53
+ if (isDev && !ctx.options.devOptions.bundle) {
54
54
  if (!injectManifestResult) {
55
55
  throw new Error("injectManifest failed to generate results. This is likely a bug.");
56
56
  }
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,8 +11,6 @@ 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,
36
14
  },
37
15
  output: {
38
16
  dir: "dist",
@@ -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"}