import {
  z
} from "./chunk-5TQBOAE7.js";
import {
  FRAGMENT_VERSION_PATH
} from "./chunk-WS2PJBP6.js";
import {
  init_cjs_shims
} from "./chunk-7GH3YGSC.js";

// src/version.ts
init_cjs_shims();
import { readFileSync, writeFileSync } from "node:fs";
var VersionSchema = z.object({
  lastCheckedMs: z.number()
});
async function updateVersionFile(debug) {
  try {
    writeFileSync(
      FRAGMENT_VERSION_PATH,
      JSON.stringify({
        lastCheckedMs: Date.now()
      })
    );
  } catch (e) {
    debug(`Failed to write version file: ${e}`);
  }
}
async function readVersionFile(debug) {
  try {
    const parsedResult = VersionSchema.safeParse(
      JSON.parse(readFileSync(FRAGMENT_VERSION_PATH, "utf-8"))
    );
    if (parsedResult.success) {
      return parsedResult.data;
    }
    debug(`Failed to parse version file: ${parsedResult.error}`);
  } catch (e) {
    debug(`Failed to read version file: ${e}`);
  }
}

export {
  VersionSchema,
  updateVersionFile,
  readVersionFile
};
