@storm-software/git-tools
Version:
Tools for managing Git repositories within a Nx workspace.
84 lines (68 loc) • 4.43 kB
JavaScript
; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkMJ243FGHcjs = require('./chunk-MJ243FGH.cjs');
var _chunkFNIN2HF7cjs = require('./chunk-FNIN2HF7.cjs');
var _chunkWZ6ONU2Gcjs = require('./chunk-WZ6ONU2G.cjs');
require('./chunk-P2CHIYIK.cjs');
require('./chunk-HI7REZLL.cjs');
require('./chunk-LUO23224.cjs');
require('./chunk-7KAXYFA6.cjs');
require('./chunk-ITOSNR37.cjs');
require('./chunk-H4QPTCFG.cjs');
var _chunkKK4YC43Scjs = require('./chunk-KK4YC43S.cjs');
// bin/pre-push.ts
_chunkKK4YC43Scjs.init_cjs_shims.call(void 0, );
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
var _promises = require('fs/promises');
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
void (async () => {
const config = await _chunkWZ6ONU2Gcjs.getConfig.call(void 0, );
try {
_chunkWZ6ONU2Gcjs.handleProcess.call(void 0, config);
_chunkWZ6ONU2Gcjs.writeInfo.call(void 0, "Running pre-push hook...", config);
_chunkMJ243FGHcjs.checkPackageVersion.call(void 0, _optionalChain([process, 'access', _ => _.argv, 'optionalAccess', _2 => _2.slice, 'call', _3 => _3(1)]));
_chunkWZ6ONU2Gcjs.writeInfo.call(void 0, "\u{1F512}\u{1F512}\u{1F512} Validating lock files \u{1F512}\u{1F512}\u{1F512}\n", config);
const errors = [];
if (_fs2.default.existsSync(_path2.default.join(_nullishCoalesce(config.workspaceRoot, () => ( "./")), "package-lock.json"))) {
errors.push('Invalid occurrence of "package-lock.json" file. Please remove it and use only "pnpm-lock.yaml"');
}
if (_fs2.default.existsSync(_path2.default.join(_nullishCoalesce(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.call(void 0, _path2.default.join(_nullishCoalesce(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 (e) {
errors.push('The "pnpm-lock.yaml" does not exist or cannot be read');
}
if (errors.length > 0) {
_chunkWZ6ONU2Gcjs.writeError.call(void 0, "\u274C Lock file validation failed", config);
for (const error of errors) {
console.error(error);
}
_chunkWZ6ONU2Gcjs.exitWithError.call(void 0, config);
}
_chunkWZ6ONU2Gcjs.writeSuccess.call(void 0, "Lock file is valid \u2705", config);
_chunkFNIN2HF7cjs.run.call(void 0, config, "git lfs pre-push origin");
try {
_chunkFNIN2HF7cjs.run.call(void 0, config, "git-lfs version");
} catch (error) {
_chunkWZ6ONU2Gcjs.writeError.call(void 0, `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: ${_optionalChain([error, 'optionalAccess', _4 => _4.message])}`, config);
_chunkWZ6ONU2Gcjs.exitWithError.call(void 0, config);
}
_chunkFNIN2HF7cjs.run.call(void 0, config, "git lfs pre-push origin");
_chunkWZ6ONU2Gcjs.exitWithSuccess.call(void 0, config);
} catch (error) {
_chunkWZ6ONU2Gcjs.writeFatal.call(void 0, `A fatal error occurred while running the program: ${error.message}`, config);
_chunkWZ6ONU2Gcjs.exitWithError.call(void 0, config);
process.exit(1);
}
})();