UNPKG

@storm-software/git-tools

Version:

Tools for managing Git repositories within a Nx workspace.

87 lines (83 loc) 3.33 kB
#!/usr/bin/env node 'use strict'; var chunkAU5PZKTN_cjs = require('./chunk-AU5PZKTN.cjs'); var chunkFH5OSXAJ_cjs = require('./chunk-FH5OSXAJ.cjs'); var chunk3PQ6YKQX_cjs = require('./chunk-3PQ6YKQX.cjs'); var fs = require('fs'); var promises = require('fs/promises'); var path = require('path'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var fs__default = /*#__PURE__*/_interopDefault(fs); var path__default = /*#__PURE__*/_interopDefault(path); void (async () => { const config = await chunk3PQ6YKQX_cjs.getConfig(); try { chunk3PQ6YKQX_cjs.handleProcess(config); chunk3PQ6YKQX_cjs.writeInfo("Running pre-push hook...", config); chunkAU5PZKTN_cjs.checkPackageVersion(process.argv?.slice(1)); chunk3PQ6YKQX_cjs.writeInfo("\u{1F512}\u{1F512}\u{1F512} Validating lock files \u{1F512}\u{1F512}\u{1F512}\n", config); const errors = []; if (fs__default.default.existsSync( path__default.default.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__default.default.existsSync(path__default.default.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 promises.readFile( path__default.default.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) { chunk3PQ6YKQX_cjs.writeError("\u274C Lock file validation failed", config); for (const error of errors) { console.error(error); } chunk3PQ6YKQX_cjs.exitWithError(config); } chunk3PQ6YKQX_cjs.writeSuccess("Lock file is valid \u2705", config); chunkFH5OSXAJ_cjs.run(config, "git lfs pre-push origin"); try { chunkFH5OSXAJ_cjs.run(config, "git-lfs version"); } catch (error) { chunk3PQ6YKQX_cjs.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 ); chunk3PQ6YKQX_cjs.exitWithError(config); } chunkFH5OSXAJ_cjs.run(config, "git lfs pre-push origin"); chunk3PQ6YKQX_cjs.exitWithSuccess(config); } catch (error) { chunk3PQ6YKQX_cjs.writeFatal( `A fatal error occurred while running the program: ${error.message}`, config ); chunk3PQ6YKQX_cjs.exitWithError(config); process.exit(1); } })(); //# sourceMappingURL=pre-push.cjs.map //# sourceMappingURL=pre-push.cjs.map