@vite-pwa/nuxt 0.3.5 → 0.3.6

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/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.6.5",
6
6
  "bridge": false
7
7
  },
8
- "version": "0.3.5"
8
+ "version": "0.3.6"
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,10 +1,12 @@
1
1
  import { join } from 'node:path';
2
- import { writeFile, mkdir } from 'node:fs/promises';
2
+ import { lstat, writeFile, mkdir } from 'node:fs/promises';
3
3
  import { defineNuxtModule, createResolver, getNuxtVersion, addPlugin, addComponent, extendWebpackConfig } from '@nuxt/kit';
4
4
  import { VitePWA } from 'vite-plugin-pwa';
5
+ import { createHash } from 'node:crypto';
6
+ import { createReadStream } from 'node:fs';
5
7
  import { resolve } from 'pathe';
6
8
 
7
- const version = "0.3.5";
9
+ const version = "0.3.6";
8
10
 
9
11
  function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
10
12
  if (!options.outDir) {
@@ -53,11 +55,11 @@ function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
53
55
  config.globPatterns.push(`${appManifestFolder}**/*.json`);
54
56
  }
55
57
  if (!nuxt.options.dev && !config.manifestTransforms)
56
- config.manifestTransforms = [createManifestTransform(nuxt.options.app.baseURL ?? "/", appManifestFolder)];
58
+ config.manifestTransforms = [createManifestTransform(nuxt.options.app.baseURL ?? "/", options.outDir, appManifestFolder)];
57
59
  }
58
- function createManifestTransform(base, appManifestFolder) {
60
+ function createManifestTransform(base, publicFolder, appManifestFolder) {
59
61
  return async (entries) => {
60
- entries.filter((e) => e && e.url.endsWith(".html")).forEach((e) => {
62
+ entries.filter((e) => e.url.endsWith(".html")).forEach((e) => {
61
63
  const url = e.url.startsWith("/") ? e.url.slice(1) : e.url;
62
64
  if (url === "index.html") {
63
65
  e.url = base;
@@ -69,9 +71,32 @@ function createManifestTransform(base, appManifestFolder) {
69
71
  });
70
72
  if (appManifestFolder) {
71
73
  const regExp = /(\/)?[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}\.json$/i;
72
- entries.filter((e) => e && e.url.startsWith(appManifestFolder) && regExp.test(e.url)).forEach((e) => {
74
+ entries.filter((e) => e.url.startsWith(appManifestFolder) && regExp.test(e.url)).forEach((e) => {
73
75
  e.revision = null;
74
76
  });
77
+ const latest = `${appManifestFolder}latest.json`;
78
+ const latestJson = resolve(publicFolder, latest);
79
+ const data = await lstat(latestJson).catch(() => void 0);
80
+ if (data?.isFile()) {
81
+ const revision = await new Promise((resolve2, reject) => {
82
+ const cHash = createHash("MD5");
83
+ const stream = createReadStream(latestJson);
84
+ stream.on("error", (err) => {
85
+ reject(err);
86
+ });
87
+ stream.on("data", (chunk) => cHash.update(chunk));
88
+ stream.on("end", () => {
89
+ resolve2(cHash.digest("hex"));
90
+ });
91
+ });
92
+ const latestEntry = entries.find((e) => e.url === latest);
93
+ if (latestEntry)
94
+ latestEntry.revision = revision;
95
+ else
96
+ entries.push({ url: latest, revision, size: data.size });
97
+ } else {
98
+ entries = entries.filter((e) => e.url !== latest);
99
+ }
75
100
  }
76
101
  return { manifest: entries, warnings: [] };
77
102
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@vite-pwa/nuxt",
3
3
  "type": "module",
4
- "version": "0.3.5",
5
- "packageManager": "pnpm@8.11.0",
4
+ "version": "0.3.6",
5
+ "packageManager": "pnpm@8.12.1",
6
6
  "description": "Zero-config PWA for Nuxt 3",
7
7
  "author": "antfu <anthonyfu117@hotmail.com>",
8
8
  "license": "MIT",
@@ -97,4 +97,4 @@
97
97
  "stackblitz": {
98
98
  "startCommand": "nr prepack && nr dev:prepare && nr dev"
99
99
  }
100
- }
100
+ }