nuxt-skew-protection 0.4.1 → 0.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": "0.4.1",
7
+ "version": "0.4.3",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -6,7 +6,6 @@ import { readPackageJSON } from 'pkg-types';
6
6
  import * as p from '@clack/prompts';
7
7
  import { $fetch } from 'ofetch';
8
8
  import { isTest, isCI, provider, env } from 'std-env';
9
- import { isSkewAdapter } from '../dist/runtime/adapters/types.js';
10
9
  import { join } from 'node:path';
11
10
  import { tmpdir } from 'node:os';
12
11
  import { x } from 'tinyexec';
@@ -239,6 +238,10 @@ async function resolveBuildTimeDriver(storage) {
239
238
  return lazyDriver({ base, ...driverOptions });
240
239
  }
241
240
 
241
+ function isSkewAdapter(value) {
242
+ return typeof value === "object" && value !== null && "name" in value && "subscribe" in value && "broadcast" in value && typeof value.subscribe === "function" && typeof value.broadcast === "function";
243
+ }
244
+
242
245
  async function processBatch(items, batchSize, processor) {
243
246
  const results = [];
244
247
  for (let i = 0; i < items.length; i += batchSize) {
@@ -537,6 +540,7 @@ function createAssetManager(options) {
537
540
  const assetTasks = [];
538
541
  let skippedSamePath = 0;
539
542
  let skippedSameFileId = 0;
543
+ const collectedPaths = /* @__PURE__ */ new Set();
540
544
  for (const [versionId, versionData] of Object.entries(manifest.versions)) {
541
545
  if (versionId === currentBuildId) {
542
546
  continue;
@@ -551,6 +555,10 @@ function createAssetManager(options) {
551
555
  skippedSameFileId++;
552
556
  continue;
553
557
  }
558
+ if (collectedPaths.has(asset)) {
559
+ continue;
560
+ }
561
+ collectedPaths.add(asset);
554
562
  assetTasks.push({ versionId, asset, versionData });
555
563
  }
556
564
  }
@@ -562,12 +570,17 @@ function createAssetManager(options) {
562
570
  const restoreStart = Date.now();
563
571
  let totalBytes = 0;
564
572
  let failedCount = 0;
573
+ const createdDirs = /* @__PURE__ */ new Set();
565
574
  const batchResults = await processBatch(assetTasks, 25, async ({ versionId, asset, versionData }) => {
566
575
  const storageKey = `${versionId}/${asset}`;
567
576
  return await storage.getItemRaw(storageKey).then(async (assetData) => {
568
577
  if (assetData) {
569
578
  const targetPath = join$1(publicDir, asset);
570
- await promises.mkdir(dirname(targetPath), { recursive: true });
579
+ const dir = dirname(targetPath);
580
+ if (!createdDirs.has(dir)) {
581
+ await promises.mkdir(dir, { recursive: true });
582
+ createdDirs.add(dir);
583
+ }
571
584
  let dataToWrite;
572
585
  if (Buffer.isBuffer(assetData)) {
573
586
  dataToWrite = assetData;
@@ -576,7 +589,7 @@ function createAssetManager(options) {
576
589
  } else {
577
590
  dataToWrite = Buffer.from(assetData);
578
591
  }
579
- await promises.writeFile(targetPath, dataToWrite);
592
+ await promises.writeFile(targetPath, dataToWrite, { flag: "wx" });
580
593
  totalBytes += dataToWrite.byteLength;
581
594
  const versionTimestamp = new Date(versionData.timestamp).getTime();
582
595
  const ageMs = now - versionTimestamp;
@@ -602,8 +615,10 @@ function createAssetManager(options) {
602
615
  }
603
616
  return null;
604
617
  }).catch((error) => {
605
- failedCount++;
606
- logger.debug(`Failed to restore asset ${asset} from version ${versionId}: ${error}`);
618
+ if (error.code !== "EEXIST") {
619
+ failedCount++;
620
+ logger.debug(`Failed to restore asset ${asset} from version ${versionId}: ${error}`);
621
+ }
607
622
  return null;
608
623
  });
609
624
  });
@@ -1,4 +1,4 @@
1
- import { defineAdapter } from "../types.js";
1
+ import { defineAdapter } from "../../../utils";
2
2
  import { ablyConfigSchema } from "./types.js";
3
3
  export { ablyConfigSchema } from "./types.js";
4
4
  export const ablyAdapter = defineAdapter({
@@ -1,5 +1,5 @@
1
1
  import { Rest } from "ably";
2
- import { defineNodeBroadcast } from "../types.js";
2
+ import { defineNodeBroadcast } from "../../../utils";
3
3
  export const broadcast = defineNodeBroadcast(async (config, version) => {
4
4
  const ably = new Rest({ key: config.key });
5
5
  const channelName = config.channel || "skew-protection";
@@ -1,5 +1,5 @@
1
1
  import { onNuxtReady } from "nuxt/app";
2
- import { defineWebSubscribe } from "../types.js";
2
+ import { defineWebSubscribe } from "../../../utils";
3
3
  export const subscribe = defineWebSubscribe((config, onMessage) => {
4
4
  let cleanup;
5
5
  onNuxtReady(async () => {
@@ -1,4 +1,4 @@
1
+ export { isSkewAdapter } from '../../utils.js';
1
2
  export type { AblyAdapterConfig } from './ably/types.js';
2
3
  export type { PusherAdapterConfig } from './pusher/types.js';
3
4
  export type { SkewAdapter, SkewAdapterFactory } from './types.js';
4
- export { isSkewAdapter } from './types.js';
@@ -1 +1 @@
1
- export { isSkewAdapter } from "./types.js";
1
+ export { isSkewAdapter } from "../../utils";
@@ -1,4 +1,4 @@
1
- import { defineAdapter } from "../types.js";
1
+ import { defineAdapter } from "../../../utils";
2
2
  import { pusherConfigSchema } from "./types.js";
3
3
  export { pusherConfigSchema } from "./types.js";
4
4
  export const pusherAdapter = defineAdapter({
@@ -1,5 +1,5 @@
1
1
  import { createHash, createHmac } from "node:crypto";
2
- import { defineNodeBroadcast } from "../types.js";
2
+ import { defineNodeBroadcast } from "../../../utils";
3
3
  export const broadcast = defineNodeBroadcast(async (config, version) => {
4
4
  const channelName = config.channel || "skew-protection";
5
5
  const eventName = config.event || "VersionUpdated";
@@ -1,5 +1,5 @@
1
1
  import { onNuxtReady } from "nuxt/app";
2
- import { defineWebSubscribe } from "../types.js";
2
+ import { defineWebSubscribe } from "../../../utils";
3
3
  export const subscribe = defineWebSubscribe((config, onMessage) => {
4
4
  let cleanup;
5
5
  onNuxtReady(async () => {
@@ -13,11 +13,7 @@ export interface DefineAdapterOptions<T> {
13
13
  name: string;
14
14
  schema: z.ZodType<T>;
15
15
  }
16
- export declare function defineAdapter<T>(options: DefineAdapterOptions<T>): SkewAdapterFactory<T>;
17
16
  export type BroadcastFn<T> = (config: T, version: string) => Promise<void>;
18
- export declare const defineNodeBroadcast: <T>(broadcast: BroadcastFn<T>) => BroadcastFn<T>;
19
17
  export type SubscribeFn<T> = (config: T, onMessage: (msg: {
20
18
  version: string;
21
19
  }) => void) => () => void;
22
- export declare const defineWebSubscribe: <T>(subscribe: SubscribeFn<T>) => SubscribeFn<T>;
23
- export declare function isSkewAdapter(value: unknown): value is SkewAdapter;
@@ -1,18 +0,0 @@
1
- export function defineAdapter(options) {
2
- return (config) => ({
3
- name: options.name,
4
- config,
5
- schema: options.schema,
6
- subscribe: () => {
7
- throw new Error(`${options.name}.subscribe() - use web build`);
8
- },
9
- broadcast: () => {
10
- throw new Error(`${options.name}.broadcast() - use node build`);
11
- }
12
- });
13
- }
14
- export const defineNodeBroadcast = (broadcast) => broadcast;
15
- export const defineWebSubscribe = (subscribe) => subscribe;
16
- export function isSkewAdapter(value) {
17
- return typeof value === "object" && value !== null && "name" in value && "subscribe" in value && "broadcast" in value && typeof value.subscribe === "function" && typeof value.broadcast === "function";
18
- }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-skew-protection",
3
3
  "type": "module",
4
- "version": "0.4.1",
4
+ "version": "0.4.3",
5
5
  "description": "Solve Nuxt version skews with persistent assets and instant updates.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -50,12 +50,11 @@
50
50
  "dependencies": {
51
51
  "@clack/prompts": "^0.11.0",
52
52
  "@nuxt/kit": "^4.2.2",
53
- "@nuxtjs/robots": "^5.6.3",
54
53
  "@vueuse/core": "^14.1.0",
55
54
  "consola": "^3.4.2",
56
55
  "cookie-es": "^2.0.0",
57
56
  "defu": "^6.1.4",
58
- "nuxt-site-config": "^3.2.11",
57
+ "nuxt-site-config": "^3.2.12",
59
58
  "ofetch": "^1.5.1",
60
59
  "pathe": "^2.0.3",
61
60
  "pkg-types": "^2.3.0",
@@ -100,9 +99,9 @@
100
99
  "unocss": "66.5.10",
101
100
  "vitest": "^4.0.15",
102
101
  "vue": "^3.5.25",
103
- "vue-router": "^4.6.3",
102
+ "vue-router": "^4.6.4",
104
103
  "vue-tsc": "^3.1.8",
105
- "wrangler": "^4.53.0",
104
+ "wrangler": "^4.54.0",
106
105
  "ws": "^8.18.3"
107
106
  },
108
107
  "resolutions": {