@storm-software/git-tools
Version:
Tools for managing Git repositories within a Nx workspace.
58 lines (52 loc) • 2.12 kB
JavaScript
;
var chunkQCNDIFYQ_cjs = require('./chunk-QCNDIFYQ.cjs');
var chunkKPQYZBLU_cjs = require('./chunk-KPQYZBLU.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);
async function prePushHook(config, files) {
chunkKPQYZBLU_cjs.writeInfo("Running pre-push hook...", config);
chunkQCNDIFYQ_cjs.checkPackageVersion(files);
chunkKPQYZBLU_cjs.writeInfo("\u{1F512}\u{1F512}\u{1F512} Validating lock files \u{1F512}\u{1F512}\u{1F512}", 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) {
throw new Error(
"\u274C Lock file validation failed\n" + errors.join("\n")
);
}
chunkKPQYZBLU_cjs.writeSuccess("\u2714 Lock file is valid for push", config);
}
exports.prePushHook = prePushHook;