@storm-software/git-tools
Version:
Tools for managing Git repositories within a Nx workspace.
80 lines (79 loc) • 2.83 kB
JavaScript
import { checkPackageVersion } from './chunk-Q3DQKTOI.js';
import { run } from './chunk-G3YPGVPS.js';
import { getConfig, handleProcess, writeInfo, writeError, exitWithError, writeSuccess, exitWithSuccess, writeFatal } from './chunk-GMMJM4AI.js';
import fs from 'node:fs';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
void (async () => {
const config = await getConfig();
try {
handleProcess(config);
writeInfo("Running pre-push hook...", config);
checkPackageVersion(process.argv?.slice(1));
writeInfo("\u{1F512}\u{1F512}\u{1F512} Validating lock files \u{1F512}\u{1F512}\u{1F512}\n", config);
const errors = [];
if (fs.existsSync(
path.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.existsSync(path.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 readFile(
path.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) {
writeError("\u274C Lock file validation failed", config);
for (const error of errors) {
console.error(error);
}
exitWithError(config);
}
writeSuccess("Lock file is valid \u2705", config);
run(config, "git lfs pre-push origin");
try {
run(config, "git-lfs version");
} catch (error) {
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
);
exitWithError(config);
}
run(config, "git lfs pre-push origin");
exitWithSuccess(config);
} catch (error) {
writeFatal(
`A fatal error occurred while running the program: ${error.message}`,
config
);
exitWithError(config);
process.exit(1);
}
})();
//# sourceMappingURL=pre-push.js.map
//# sourceMappingURL=pre-push.js.map