#!/usr/bin/env node

const fs = require("node:fs");
const path = require("node:path");

const packageDir = process.argv[2];

if (!packageDir) {
  console.error("Usage: node scripts/playwrightPackageVersion.cjs <package-dir>");
  process.exit(2);
}

const packageJsonPath = path.resolve(process.cwd(), packageDir, "package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
const version =
  packageJson.devDependencies?.["@playwright/test"] ??
  packageJson.dependencies?.["@playwright/test"];

if (!version) {
  console.error(`@playwright/test version not found in ${packageJsonPath}`);
  process.exit(1);
}

console.log(`version=${version.replace(/^[^0-9]*/, "")}`);
