UNPKG

@storm-software/git-tools

Version:

Tools for managing Git repositories within a Nx workspace.

84 lines (82 loc) 2.89 kB
#!/usr/bin/env node import { checkPackageVersion } from "./chunk-6GPR6NFP.js"; import { run } from "./chunk-NIRUYN54.js"; import { exitWithError, exitWithSuccess, getConfig, handleProcess, writeError, writeFatal, writeInfo, writeSuccess } from "./chunk-JT7CY52A.js"; import "./chunk-5L6OQPTU.js"; import "./chunk-44NY3AUB.js"; import "./chunk-7TOVDNAL.js"; import "./chunk-TX4MSLH2.js"; import "./chunk-5HEUR3SM.js"; import "./chunk-KOSP4IZ7.js"; import { init_esm_shims } from "./chunk-AX5TUBFG.js"; // bin/pre-push.ts init_esm_shims(); import fs from "node:fs"; import { readFile } from "node:fs/promises"; import path from "node:path"; void (async () => { const config = await getConfig(); try { handleProcess(config); writeInfo("Running pre-push hook...", config); checkPackageVersion(process.argv?.slice(1)); writeInfo("\u{1F512}\u{1F512}\u{1F512} Validating lock files \u{1F512}\u{1F512}\u{1F512}\n", config); const errors = []; if (fs.existsSync(path.join(config.workspaceRoot ?? "./", "package-lock.json"))) { errors.push('Invalid occurrence of "package-lock.json" file. Please remove it and use only "pnpm-lock.yaml"'); } if (fs.existsSync(path.join(config.workspaceRoot ?? "./", "yarn.lock"))) { errors.push('Invalid occurrence of "yarn.lock" file. Please remove it and use only "pnpm-lock.yaml"'); } try { const content = await readFile(path.join(config.workspaceRoot ?? "./", "pnpm-lock.yaml"), { encoding: "utf8" }); if (content.match(/localhost:487/)) { errors.push('The "pnpm-lock.yaml" has reference to local repository ("localhost:4873"). Please use ensure you disable local registry before running "pnpm i"'); } if (content.match(/resolution: \{tarball/)) { errors.push('The "pnpm-lock.yaml" has reference to tarball package. Please use npm registry only'); } } catch { errors.push('The "pnpm-lock.yaml" does not exist or cannot be read'); } if (errors.length > 0) { writeError("\u274C Lock file validation failed", config); for (const error of errors) { console.error(error); } exitWithError(config); } writeSuccess("Lock file is valid \u2705", config); run(config, "git lfs pre-push origin"); try { run(config, "git-lfs version"); } catch (error) { writeError(`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. Error: ${error?.message}`, config); exitWithError(config); } run(config, "git lfs pre-push origin"); exitWithSuccess(config); } catch (error) { writeFatal(`A fatal error occurred while running the program: ${error.message}`, config); exitWithError(config); process.exit(1); } })();