{"version":3,"sources":["../../src/hooks/pre-push.ts"],"names":["writeInfo","checkPackageVersion","getLockFileName","getInstallCommand","getOtherLockFileNames","fs","path","readFile","writeSuccess"],"mappings":";;;;;;;;;;;;;AAcA,eAAsB,WAAA,CACpB,QACA,KAAA,EACA;AACA,EAAAA,2BAAA,CAAU,4BAA4B,MAAM,CAAA;AAC5C,EAAAC,qCAAA,CAAoB,OAAO,MAAM,CAAA;AAEjC,EAAAD,2BAAA,CAAU,iFAAuC,MAAM,CAAA;AAEvD,EAAA,MAAM,aAAA,GAAgB,OAAO,aAAA,IAAiB,IAAA;AAC9C,EAAA,MAAM,YAAA,GAAeE,iCAAA,CAAgB,MAAA,CAAO,cAAc,CAAA;AAC1D,EAAA,MAAM,cAAA,GAAiBC,mCAAA,CAAkB,MAAA,CAAO,cAAc,CAAA;AAC9D,EAAA,MAAM,SAAS,EAAC;AAEhB,EAAA,KAAA,MAAW,aAAA,IAAiBC,uCAAA,CAAsB,MAAA,CAAO,cAAc,CAAA,EAAG;AACxE,IAAA,IAAIC,oBAAG,UAAA,CAAWC,qBAAA,CAAK,KAAK,aAAA,EAAe,aAAa,CAAC,CAAA,EAAG;AAC1D,MAAA,MAAA,CAAO,IAAA;AAAA,QACL,CAAA,uBAAA,EAA0B,aAAa,CAAA,uCAAA,EAA0C,YAAY,CAAA,CAAA;AAAA,OAC/F;AAAA,IACF;AAAA,EACF;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,MAAMC,iBAAA,CAASD,sBAAK,IAAA,CAAK,aAAA,EAAe,YAAY,CAAA,EAAG;AAAA,MACrE,QAAA,EAAU;AAAA,KACX,CAAA;AAED,IAAA,IAAI,MAAA,CAAO,mBAAmB,MAAA,EAAQ;AACpC,MAAA,IAAI,OAAA,EAAS,KAAA,CAAM,eAAe,CAAA,EAAG;AACnC,QAAA,MAAA,CAAO,IAAA;AAAA,UACL,CAAA,KAAA,EAAQ,YAAY,CAAA,iHAAA,EAAoH,cAAc,CAAA,CAAA;AAAA,SACxJ;AAAA,MACF;AACA,MAAA,IAAI,OAAA,EAAS,KAAA,CAAM,uBAAuB,CAAA,EAAG;AAC3C,QAAA,MAAA,CAAO,IAAA;AAAA,UACL,QAAQ,YAAY,CAAA,gEAAA;AAAA,SACtB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,MAAA,CAAO,IAAA,CAAK,CAAA,KAAA,EAAQ,YAAY,CAAA,kCAAA,CAAoC,CAAA;AAAA,EACtE;AAEA,EAAA,IAAI,MAAA,CAAO,SAAS,CAAA,EAAG;AACrB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,sCAAA,GAAyC,MAAA,CAAO,IAAA,CAAK,IAAI;AAAA,KAC3D;AAAA,EACF;AAEA,EAAAE,8BAAA,CAAa,sCAAiC,MAAM,CAAA;AAetD","file":"chunk-XVVRI3DK.cjs","sourcesContent":["#!/usr/bin/env node\n\nimport { StormWorkspaceConfig } from \"@storm-software/config\";\nimport { writeInfo, writeSuccess } from \"@storm-software/config-tools\";\nimport fs from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { checkPackageVersion } from \"../utilities/check-package-version\";\nimport {\n  getInstallCommand,\n  getLockFileName,\n  getOtherLockFileNames\n} from \"../utilities/package-manager\";\n\nexport async function prePushHook(\n  config: StormWorkspaceConfig,\n  files: string[]\n) {\n  writeInfo(\"Running pre-push hook...\", config);\n  checkPackageVersion(files, config);\n\n  writeInfo(\"🔒🔒🔒 Validating lock files 🔒🔒🔒\", config);\n\n  const workspaceRoot = config.workspaceRoot ?? \"./\";\n  const lockFileName = getLockFileName(config.packageManager);\n  const installCommand = getInstallCommand(config.packageManager);\n  const errors = [] as string[];\n\n  for (const otherLockFile of getOtherLockFileNames(config.packageManager)) {\n    if (fs.existsSync(path.join(workspaceRoot, otherLockFile))) {\n      errors.push(\n        `Invalid occurrence of \"${otherLockFile}\" file. Please remove it and use only \"${lockFileName}\"`\n      );\n    }\n  }\n\n  try {\n    const content = await readFile(path.join(workspaceRoot, lockFileName), {\n      encoding: \"utf8\"\n    });\n\n    if (config.packageManager === \"pnpm\") {\n      if (content?.match(/localhost:487/)) {\n        errors.push(\n          `The \"${lockFileName}\" has reference to local repository (\"localhost:4873\"). Please ensure you disable local registry before running \"${installCommand}\"`\n        );\n      }\n      if (content?.match(/resolution: \\{tarball/)) {\n        errors.push(\n          `The \"${lockFileName}\" has reference to tarball package. Please use npm registry only`\n        );\n      }\n    }\n  } catch {\n    errors.push(`The \"${lockFileName}\" does not exist or cannot be read`);\n  }\n\n  if (errors.length > 0) {\n    throw new Error(\n      \"❌ Lock file validation failed\" + \"\\n\" + errors.join(\"\\n\")\n    );\n  }\n\n  writeSuccess(\"✔ Lock file is valid for push\", config);\n\n  // run(config, \"git lfs pre-push origin\");\n\n  // try {\n  //   run(config, \"git-lfs version\");\n  // } catch (error) {\n  //   throw new Error(\n  //     `This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\\nError: ${\n  //       (error as Error)?.message\n  //     }`\n  //   );\n  // }\n\n  // run(config, \"git lfs pre-push origin\");\n}\n"]}