nuxt-skew-protection 1.4.1 → 1.4.3

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
@@ -4,7 +4,7 @@
4
4
  "nuxt": ">=4.0.0"
5
5
  },
6
6
  "configKey": "skewProtection",
7
- "version": "1.4.1",
7
+ "version": "1.4.3",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -188,12 +188,17 @@ async function resolveBuildTimeDriver(storage) {
188
188
  }
189
189
 
190
190
  const virtualEntryId = "virtual:nuxt-skew-protection/cloudflare-entry";
191
+ const cloudflareAssetProtectionPluginName = "nuxt-skew-protection:cloudflare-asset-fetch";
191
192
  const resolvedVirtualEntryId = `\0${virtualEntryId}`;
192
193
  const legacyCloudflareAdapterSuffixes = [
193
194
  "/nitropack/dist/runtime/entries/cloudflare-module.mjs",
194
195
  "/nitropack/dist/runtime/entries/cloudflare.mjs",
195
196
  "/nitropack/dist/runtime/entries/cloudflare-pages.mjs"
196
197
  ];
198
+ const nitroPrerenderEntrySuffix = "/nitropack/dist/presets/_nitro/runtime/nitro-prerenderer.mjs";
199
+ function isNitroPrerenderEntry(id) {
200
+ return id.split("?", 1)[0].endsWith(nitroPrerenderEntrySuffix);
201
+ }
197
202
  function isLegacyCloudflareEntry(id) {
198
203
  const normalizedId = id.split("?", 1)[0].replaceAll("\\", "/");
199
204
  return legacyCloudflareAdapterSuffixes.some((suffix) => normalizedId.endsWith(suffix));
@@ -202,6 +207,13 @@ function normalizeBuildAssetsDir(value) {
202
207
  const path = value.replace(/^\/+|\/+$/g, "");
203
208
  return `/${path}/`;
204
209
  }
210
+ function withoutCloudflareAssetProtectionPlugin(plugins) {
211
+ return plugins.filter((plugin) => {
212
+ if (!plugin || typeof plugin !== "object" || !("name" in plugin))
213
+ return true;
214
+ return plugin.name !== cloudflareAssetProtectionPluginName;
215
+ });
216
+ }
205
217
  function renderCloudflareEntry(options) {
206
218
  const nitroEntryId = JSON.stringify(options.nitroEntryId);
207
219
  const runtimeHelperId = JSON.stringify(options.runtimeHelperId);
@@ -225,20 +237,28 @@ export default {
225
237
  function createCloudflareAssetProtectionPlugin(options) {
226
238
  let nitroEntryId;
227
239
  let wrapperLoaded = false;
240
+ let shouldWrapEntry = true;
228
241
  return {
229
- name: "nuxt-skew-protection:cloudflare-asset-fetch",
242
+ name: cloudflareAssetProtectionPluginName,
230
243
  options(inputOptions) {
244
+ nitroEntryId = void 0;
245
+ wrapperLoaded = false;
246
+ shouldWrapEntry = false;
231
247
  if (typeof inputOptions.input !== "string") {
232
248
  this.error(
233
249
  "[nuxt-skew-protection] Asset 404 protection requires one Nitro entry."
234
250
  );
235
251
  }
252
+ if (isNitroPrerenderEntry(inputOptions.input)) {
253
+ return inputOptions;
254
+ }
236
255
  if (isLegacyCloudflareEntry(inputOptions.input)) {
237
256
  this.error(
238
257
  "[nuxt-skew-protection] Asset 404 protection requires nitropack >= 2.10.0. Your project uses an older adapter without the ASSETS binding. Upgrade nitropack (or nuxt) to enable asset 404 protection."
239
258
  );
240
259
  }
241
260
  nitroEntryId = inputOptions.input;
261
+ shouldWrapEntry = true;
242
262
  return {
243
263
  ...inputOptions,
244
264
  input: virtualEntryId
@@ -258,7 +278,7 @@ function createCloudflareAssetProtectionPlugin(options) {
258
278
  });
259
279
  },
260
280
  buildEnd(error) {
261
- if (!error && !wrapperLoaded) {
281
+ if (shouldWrapEntry && !error && !wrapperLoaded) {
262
282
  this.error(
263
283
  "[nuxt-skew-protection] Nitro's Cloudflare entry was not bundled. Refusing to build without asset 404 protection."
264
284
  );
@@ -1070,6 +1090,13 @@ export {}
1070
1090
  })
1071
1091
  ];
1072
1092
  });
1093
+ nuxt.hook("nitro:init", (nitro) => {
1094
+ nitro.hooks.hook("prerender:config", (prerenderConfig) => {
1095
+ const plugins = prerenderConfig.rollupConfig?.plugins;
1096
+ if (Array.isArray(plugins))
1097
+ prerenderConfig.rollupConfig.plugins = withoutCloudflareAssetProtectionPlugin(plugins);
1098
+ });
1099
+ });
1073
1100
  }
1074
1101
  const isAdapter = isSkewAdapter(options.updateStrategy);
1075
1102
  let resolvedStrategy = "polling";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-skew-protection",
3
3
  "type": "module",
4
- "version": "1.4.1",
4
+ "version": "1.4.3",
5
5
  "description": "Solve Nuxt version skews with persistent assets and instant updates.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -82,7 +82,7 @@
82
82
  "consola": "^3.4.2",
83
83
  "cookie-es": "^3.1.1",
84
84
  "nuxt-site-config": "^4.2.0",
85
- "nuxtseo-shared": "^5.3.10",
85
+ "nuxtseo-shared": "^5.3.11",
86
86
  "ofetch": "^1.5.1",
87
87
  "pathe": "^2.0.3",
88
88
  "pkg-types": "^2.3.1",