This commit is contained in:
eric sciple 2020-01-24 12:20:19 -05:00
parent beb1329f9f
commit 2b95e76931
7736 changed files with 1874747 additions and 51184 deletions

29
node_modules/husky/lib/installer/bin.js generated vendored Normal file
View file

@ -0,0 +1,29 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const is_ci_1 = __importDefault(require("is-ci"));
const path_1 = __importDefault(require("path"));
const _1 = require("./");
// Just for testing
if (process.env.HUSKY_DEBUG === 'true' || process.env.HUSKY_DEBUG === '1') {
console.log(`husky:debug INIT_CWD=${process.env.INIT_CWD}`);
}
// Action can be "install" or "uninstall"
// huskyDir is ONLY used in dev, don't use this arguments
const [, , action, huskyDir = path_1.default.join(__dirname, '../..')] = process.argv;
// Find Git dir
try {
// Run installer
if (action === 'install') {
_1.install(huskyDir, undefined, is_ci_1.default);
}
else {
_1.uninstall(huskyDir);
}
}
catch (error) {
console.log(`husky > failed to ${action}`);
console.log(error.message);
}

99
node_modules/husky/lib/installer/getScript.js generated vendored Normal file
View file

@ -0,0 +1,99 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
const slash_1 = __importDefault(require("slash"));
// Used to identify scripts created by Husky
exports.huskyIdentifier = '# husky';
// Experimental
const huskyrc = '~/.huskyrc';
// Render script
const render = ({ createdAt, homepage, node, pkgDirectory, pkgHomepage, platform, runScriptPath, version }) => `#!/bin/sh
${exports.huskyIdentifier}
# Hook created by Husky
# Version: ${version}
# At: ${createdAt}
# See: ${homepage}
# From
# Directory: ${pkgDirectory}
# Homepage: ${pkgHomepage}
scriptPath="${runScriptPath}.js"
hookName=\`basename "$0"\`
gitParams="$*"
debug() {
if [ "$\{HUSKY_DEBUG}" = "true" ] || [ "$\{HUSKY_DEBUG}" = "1" ]; then
echo "husky:debug $1"
fi
}
debug "$hookName hook started"
if [ "$\{HUSKY_SKIP_HOOKS}" = "true" ] || [ "$\{HUSKY_SKIP_HOOKS}" = "1" ]; then
debug "HUSKY_SKIP_HOOKS is set to $\{HUSKY_SKIP_HOOKS}, skipping hook"
exit 0
fi
${platform === 'win32'
? ''
: `
if ! command -v node >/dev/null 2>&1; then
echo "Info: can't find node in PATH, trying to find a node binary on your system"
fi
`}
if [ -f "$scriptPath" ]; then
# if [ -t 1 ]; then
# exec < /dev/tty
# fi
if [ -f ${huskyrc} ]; then
debug "source ${huskyrc}"
. ${huskyrc}
fi
${node} "$scriptPath" $hookName "$gitParams"
else
echo "Can't find Husky, skipping $hookName hook"
echo "You can reinstall it using 'npm install husky --save-dev' or delete this hook"
fi
`;
/**
* @param {string} rootDir - e.g. /home/typicode/project/
* @param {string} huskyDir - e.g. /home/typicode/project/node_modules/husky/
* @param {string} requireRunNodePath - path to run-node resolved by require e.g. /home/typicode/project/node_modules/run-node/run-node
* @param {string} platform - platform husky installer is running on (used to produce win32 specific script)
* @returns {string} script
*/
function default_1(rootDir, huskyDir, requireRunNodePath,
// Additional param used for testing only
platform = os_1.default.platform()) {
const runNodePath = slash_1.default(path_1.default.relative(rootDir, requireRunNodePath));
// On Windows do not rely on run-node
const node = platform === 'win32' ? 'node' : runNodePath;
// Env variable
const pkgHomepage = process && process.env && process.env.npm_package_homepage;
const pkgDirectory = process && process.env && process.env.PWD;
// Husky package.json
const { homepage, version } = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, '../../package.json'), 'utf-8'));
// Path to run.js
const runScriptPath = slash_1.default(path_1.default.join(path_1.default.relative(rootDir, huskyDir), 'run'));
// Created at
const createdAt = new Date().toLocaleString();
// Render script
return render({
createdAt,
homepage,
node,
pkgDirectory,
pkgHomepage,
platform,
runScriptPath,
version
});
}
exports.default = default_1;

171
node_modules/husky/lib/installer/index.js generated vendored Normal file
View file

@ -0,0 +1,171 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const find_up_1 = __importDefault(require("find-up"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const pkg_dir_1 = __importDefault(require("pkg-dir"));
const getConf_1 = __importDefault(require("../getConf"));
const getScript_1 = __importDefault(require("./getScript"));
const is_1 = require("./is");
const resolveGitDir_1 = __importDefault(require("./resolveGitDir"));
const hookList = [
'applypatch-msg',
'pre-applypatch',
'post-applypatch',
'pre-commit',
'prepare-commit-msg',
'commit-msg',
'post-commit',
'pre-rebase',
'post-checkout',
'post-merge',
'pre-push',
'pre-receive',
'update',
'post-receive',
'post-update',
'push-to-checkout',
'pre-auto-gc',
'post-rewrite',
'sendemail-validate'
];
function writeHook(filename, script) {
fs_1.default.writeFileSync(filename, script, 'utf-8');
fs_1.default.chmodSync(filename, 0o0755);
}
function createHook(filename, script) {
// Get name, used for logging
const name = path_1.default.basename(filename);
// Check if hook exist
if (fs_1.default.existsSync(filename)) {
const hook = fs_1.default.readFileSync(filename, 'utf-8');
// Migrate
if (is_1.isGhooks(hook)) {
console.log(`migrating existing ghooks script: ${name}`);
return writeHook(filename, script);
}
// Migrate
if (is_1.isPreCommit(hook)) {
console.log(`migrating existing pre-commit script: ${name}`);
return writeHook(filename, script);
}
// Update
if (is_1.isHusky(hook) || is_1.isYorkie(hook)) {
return writeHook(filename, script);
}
// Skip
console.log(`skipping existing user hook: ${name}`);
return;
}
// Create hook if it doesn't exist
writeHook(filename, script);
}
function createHooks(filenames, script) {
filenames.forEach((filename) => createHook(filename, script));
}
function canRemove(filename) {
if (fs_1.default.existsSync(filename)) {
const data = fs_1.default.readFileSync(filename, 'utf-8');
return is_1.isHusky(data);
}
return false;
}
function removeHook(filename) {
fs_1.default.unlinkSync(filename);
}
function removeHooks(filenames) {
filenames.filter(canRemove).forEach(removeHook);
}
// This prevents the case where someone would want to debug a node_module that has
// husky as devDependency and run npm install from node_modules directory
function isInNodeModules(dir) {
// INIT_CWD holds the full path you were in when you ran npm install (supported also by yarn and pnpm)
// See https://docs.npmjs.com/cli/run-script
if (process.env.INIT_CWD) {
return process.env.INIT_CWD.indexOf('node_modules') !== -1;
}
// Old technique
return (dir.match(/node_modules/g) || []).length > 1;
}
function getHooks(gitDir) {
const gitHooksDir = path_1.default.join(gitDir, 'hooks');
return hookList.map((hookName) => path_1.default.join(gitHooksDir, hookName));
}
/**
* @param {string} huskyDir - e.g. /home/typicode/project/node_modules/husky/
* @param {string} requireRunNodePath - path to run-node resolved by require e.g. /home/typicode/project/node_modules/run-node/run-node
* @param {string} isCI - true if running in CI
*/
function install(huskyDir, requireRunNodePath = require.resolve('run-node/run-node'), isCI) {
console.log('husky > Setting up git hooks');
// First directory containing user's package.json
const userPkgDir = pkg_dir_1.default.sync(path_1.default.join(huskyDir, '..'));
if (userPkgDir === undefined) {
console.log("Can't find package.json, skipping Git hooks installation.");
console.log('Please check that your project has a package.json or create it and reinstall husky.');
return;
}
// Get conf from package.json or .huskyrc
const conf = getConf_1.default(userPkgDir);
// Get directory containing .git directory or in the case of Git submodules, the .git file
const gitDirOrFile = find_up_1.default.sync('.git', { cwd: userPkgDir });
// Resolve git directory (e.g. .git/ or .git/modules/path/to/submodule)
const resolvedGitDir = resolveGitDir_1.default(userPkgDir);
// Checks
if (process.env.HUSKY_SKIP_INSTALL === 'true') {
console.log("HUSKY_SKIP_INSTALL environment variable is set to 'true',", 'skipping Git hooks installation.');
return;
}
if (gitDirOrFile === null || gitDirOrFile === undefined) {
console.log("Can't find .git, skipping Git hooks installation.");
console.log("Please check that you're in a cloned repository", "or run 'git init' to create an empty Git repository and reinstall husky.");
return;
}
if (resolvedGitDir === null) {
console.log("Can't find resolved .git directory, skipping Git hooks installation.");
return;
}
if (isCI && conf.skipCI) {
console.log('CI detected, skipping Git hooks installation.');
return;
}
if (isInNodeModules(huskyDir)) {
console.log('Trying to install from node_modules directory, skipping Git hooks installation.');
return;
}
// Create hooks directory if doesn't exist
if (!fs_1.default.existsSync(path_1.default.join(resolvedGitDir, 'hooks'))) {
fs_1.default.mkdirSync(path_1.default.join(resolvedGitDir, 'hooks'));
}
// Create hooks
// Get root dir based on the first .git directory of file found
const rootDir = path_1.default.dirname(gitDirOrFile);
const hooks = getHooks(resolvedGitDir);
const script = getScript_1.default(rootDir, huskyDir, requireRunNodePath);
createHooks(hooks, script);
console.log(`husky > Done`);
console.log('husky > Like husky? You can support the project on Patreon:');
console.log('husky > \x1b[36m%s\x1b[0m 🐕', 'https://www.patreon.com/typicode');
}
exports.install = install;
function uninstall(huskyDir) {
console.log('husky > Uninstalling git hooks');
const userPkgDir = pkg_dir_1.default.sync(path_1.default.join(huskyDir, '..'));
const resolvedGitDir = resolveGitDir_1.default(userPkgDir);
if (resolvedGitDir === null) {
console.log("Can't find resolved .git directory, skipping Git hooks uninstallation.");
return;
}
if (isInNodeModules(huskyDir)) {
console.log('Trying to uninstall from node_modules directory, skipping Git hooks uninstallation.');
return;
}
// Remove hooks
const hooks = getHooks(resolvedGitDir);
removeHooks(hooks);
console.log('husky > Done');
}
exports.uninstall = uninstall;

24
node_modules/husky/lib/installer/is.js generated vendored Normal file
View file

@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const getScript_1 = require("./getScript");
function isHusky(data) {
// Husky v0.14 and prior used #husky as an identifier.
// Just in case some previous hooks weren't correctly uninstalled,
// and for a better transition this will allow v0.15+ to uninstall them as well.
const previousHuskyIdentifier = '#husky';
return (data.indexOf(getScript_1.huskyIdentifier) !== -1 ||
data.indexOf(previousHuskyIdentifier) !== -1);
}
exports.isHusky = isHusky;
function isYorkie(data) {
return data.indexOf('#yorkie') !== -1;
}
exports.isYorkie = isYorkie;
function isGhooks(data) {
return data.indexOf('// Generated by ghooks. Do not edit this file.') !== -1;
}
exports.isGhooks = isGhooks;
function isPreCommit(data) {
return data.indexOf('./node_modules/pre-commit/hook') !== -1;
}
exports.isPreCommit = isPreCommit;

39
node_modules/husky/lib/installer/resolveGitDir.js generated vendored Normal file
View file

@ -0,0 +1,39 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const find_up_1 = __importDefault(require("find-up"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
function default_1(cwd) {
const foundPath = find_up_1.default.sync('.git', { cwd });
if (foundPath) {
const stats = fs_1.default.lstatSync(foundPath);
// If it's a .git file resolve path
if (stats.isFile()) {
// Expect following format
// git: pathToGit
// On Windows pathToGit can contain ':' (example "gitdir: C:/Some/Path")
const gitFileData = fs_1.default.readFileSync(foundPath, 'utf-8');
const gitDir = gitFileData
.split(':')
.slice(1)
.join(':')
.trim();
const resolvedGitDir = path_1.default.resolve(path_1.default.dirname(foundPath), gitDir);
// For git-worktree, check if commondir file exists and return that path
const pathCommonDir = path_1.default.join(resolvedGitDir, 'commondir');
if (fs_1.default.existsSync(pathCommonDir)) {
const commondir = fs_1.default.readFileSync(pathCommonDir, 'utf-8').trim();
const resolvedCommonGitDir = path_1.default.join(resolvedGitDir, commondir);
return resolvedCommonGitDir;
}
return resolvedGitDir;
}
// Else return path to .git directory
return foundPath;
}
return null;
}
exports.default = default_1;