UNPKG

@storm-software/git-tools

Version:

Tools for managing Git repositories within a Nx workspace.

51 lines (48 loc) 1.76 kB
import { checkPackageVersion } from './chunk-HMHOHK22.js'; import { writeInfo, writeSuccess } from './chunk-65JOK2FH.js'; import fs from 'node:fs'; import { readFile } from 'node:fs/promises'; import path from 'node:path'; async function prePushHook(config, files) { writeInfo("Running pre-push hook...", config); checkPackageVersion(files); writeInfo("\u{1F512}\u{1F512}\u{1F512} Validating lock files \u{1F512}\u{1F512}\u{1F512}", 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) { throw new Error( "\u274C Lock file validation failed\n" + errors.join("\n") ); } writeSuccess("\u2714 Lock file is valid for push", config); } export { prePushHook };