@storm-software/git-tools
Version:
Tools for managing Git repositories within a Nx workspace.
1 lines • 3.8 kB
Source Map (JSON)
{"version":3,"sources":["../../src/hooks/pre-push.ts"],"names":["writeInfo","checkPackageVersion","fs","path","readFile","writeSuccess"],"mappings":";;;;;;;;;;;;;AASA,eAAsB,WAAA,CACpB,QACA,KAAA,EACA;AACA,EAAAA,2BAAA,CAAU,4BAA4B,MAAM,CAAA;AAC5C,EAAAC,qCAAA,CAAoB,KAAK,CAAA;AAEzB,EAAAD,2BAAA,CAAU,iFAAuC,MAAM,CAAA;AAEvD,EAAA,MAAM,SAAS,EAAC;AAChB,EAAA,IACEE,mBAAA,CAAG,WAAWC,qBAAA,CAAK,IAAA,CAAK,OAAO,aAAA,IAAiB,IAAA,EAAM,mBAAmB,CAAC,CAAA,EAC1E;AACA,IAAA,MAAA,CAAO,IAAA;AAAA,MACL;AAAA,KACF;AAAA,EACF;AACA,EAAA,IAAID,mBAAA,CAAG,WAAWC,qBAAA,CAAK,IAAA,CAAK,OAAO,aAAA,IAAiB,IAAA,EAAM,WAAW,CAAC,CAAA,EAAG;AACvE,IAAA,MAAA,CAAO,IAAA;AAAA,MACL;AAAA,KACF;AAAA,EACF;AAEA,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,MAAMC,iBAAA;AAAA,MACpBD,qBAAA,CAAK,IAAA,CAAK,MAAA,CAAO,aAAA,IAAiB,MAAM,gBAAgB,CAAA;AAAA,MACxD;AAAA,QACE,QAAA,EAAU;AAAA;AACZ,KACF;AACA,IAAA,IAAI,OAAA,EAAS,KAAA,CAAM,eAAe,CAAA,EAAG;AACnC,MAAA,MAAA,CAAO,IAAA;AAAA,QACL;AAAA,OACF;AAAA,IACF;AACA,IAAA,IAAI,OAAA,EAAS,KAAA,CAAM,uBAAuB,CAAA,EAAG;AAC3C,MAAA,MAAA,CAAO,IAAA;AAAA,QACL;AAAA,OACF;AAAA,IACF;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,MAAA,CAAO,KAAK,uDAAuD,CAAA;AAAA,EACrE;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-DPV4WJQX.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\";\n\nexport async function prePushHook(\n config: StormWorkspaceConfig,\n files: string[]\n) {\n writeInfo(\"Running pre-push hook...\", config);\n checkPackageVersion(files);\n\n writeInfo(\"🔒🔒🔒 Validating lock files 🔒🔒🔒\", config);\n\n const errors = [] as string[];\n if (\n fs.existsSync(path.join(config.workspaceRoot ?? \"./\", \"package-lock.json\"))\n ) {\n errors.push(\n 'Invalid occurrence of \"package-lock.json\" file. Please remove it and use only \"pnpm-lock.yaml\"'\n );\n }\n if (fs.existsSync(path.join(config.workspaceRoot ?? \"./\", \"yarn.lock\"))) {\n errors.push(\n 'Invalid occurrence of \"yarn.lock\" file. Please remove it and use only \"pnpm-lock.yaml\"'\n );\n }\n\n try {\n const content = await readFile(\n path.join(config.workspaceRoot ?? \"./\", \"pnpm-lock.yaml\"),\n {\n encoding: \"utf8\"\n }\n );\n if (content?.match(/localhost:487/)) {\n errors.push(\n 'The \"pnpm-lock.yaml\" has reference to local repository (\"localhost:4873\"). Please use ensure you disable local registry before running \"pnpm i\"'\n );\n }\n if (content?.match(/resolution: \\{tarball/)) {\n errors.push(\n 'The \"pnpm-lock.yaml\" has reference to tarball package. Please use npm registry only'\n );\n }\n } catch {\n errors.push('The \"pnpm-lock.yaml\" 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"]}