@storm-software/git-tools
Version:
Tools for managing Git repositories within a Nx workspace.
86 lines (81 loc) • 3.25 kB
JavaScript
;
var chunkSWXHQXUT_cjs = require('./chunk-SWXHQXUT.cjs');
var chunkCIJVSMK2_cjs = require('./chunk-CIJVSMK2.cjs');
var chunkOYO5BO7W_cjs = require('./chunk-OYO5BO7W.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 chunkOYO5BO7W_cjs.getConfig();
try {
chunkOYO5BO7W_cjs.handleProcess(config);
chunkOYO5BO7W_cjs.writeInfo("Running pre-push hook...", config);
chunkSWXHQXUT_cjs.checkPackageVersion(process.argv?.slice(1));
chunkOYO5BO7W_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) {
chunkOYO5BO7W_cjs.writeError("\u274C Lock file validation failed", config);
for (const error of errors) {
console.error(error);
}
chunkOYO5BO7W_cjs.exitWithError(config);
}
chunkOYO5BO7W_cjs.writeSuccess("Lock file is valid \u2705", config);
chunkCIJVSMK2_cjs.run(config, "git lfs pre-push origin");
try {
chunkCIJVSMK2_cjs.run(config, "git-lfs version");
} catch (error) {
chunkOYO5BO7W_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
);
chunkOYO5BO7W_cjs.exitWithError(config);
}
chunkCIJVSMK2_cjs.run(config, "git lfs pre-push origin");
chunkOYO5BO7W_cjs.exitWithSuccess(config);
} catch (error) {
chunkOYO5BO7W_cjs.writeFatal(
`A fatal error occurred while running the program: ${error.message}`,
config
);
chunkOYO5BO7W_cjs.exitWithError(config);
process.exit(1);
}
})();