@storm-software/git-tools
Version:
Tools for managing Git repositories within a Nx workspace.
103 lines (87 loc) • 4.59 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 _chunkHTVOKCRJcjs = require('./chunk-HTVOKCRJ.cjs');
var _chunkGWDOCACNcjs = require('./chunk-GWDOCACN.cjs');
var _chunk53F2DJBEcjs = require('./chunk-53F2DJBE.cjs');
require('./chunk-FMYKTN2Z.cjs');
require('./chunk-MXO7CLUN.cjs');
require('./chunk-GSZ2Y7H4.cjs');
require('./chunk-H4MEIOPL.cjs');
require('./chunk-TVPM4C6Y.cjs');
require('./chunk-UQFYXF6V.cjs');
var _chunkIG6EXAQUcjs = require('./chunk-IG6EXAQU.cjs');
// bin/pre-push.ts
_chunkIG6EXAQUcjs.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 _chunk53F2DJBEcjs.getConfig.call(void 0, );
try {
_chunk53F2DJBEcjs.handleProcess.call(void 0, config);
_chunk53F2DJBEcjs.writeInfo.call(void 0, "Running pre-push hook...", config);
_chunkHTVOKCRJcjs.checkPackageVersion.call(void 0, _optionalChain([process, 'access', _ => _.argv, 'optionalAccess', _2 => _2.slice, 'call', _3 => _3(1)]));
_chunk53F2DJBEcjs.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) {
_chunk53F2DJBEcjs.writeError.call(void 0, "\u274C Lock file validation failed", config);
for (const error of errors) {
console.error(error);
}
_chunk53F2DJBEcjs.exitWithError.call(void 0, config);
}
_chunk53F2DJBEcjs.writeSuccess.call(void 0, "Lock file is valid \u2705", config);
_chunkGWDOCACNcjs.run.call(void 0, config, "git lfs pre-push origin");
try {
_chunkGWDOCACNcjs.run.call(void 0, config, "git-lfs version");
} catch (error) {
_chunk53F2DJBEcjs.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
);
_chunk53F2DJBEcjs.exitWithError.call(void 0, config);
}
_chunkGWDOCACNcjs.run.call(void 0, config, "git lfs pre-push origin");
_chunk53F2DJBEcjs.exitWithSuccess.call(void 0, config);
} catch (error) {
_chunk53F2DJBEcjs.writeFatal.call(void 0,
`A fatal error occurred while running the program: ${error.message}`,
config
);
_chunk53F2DJBEcjs.exitWithError.call(void 0, config);
process.exit(1);
}
})();