WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

12
node_modules/husky/lib/getConf.js generated vendored Normal file
View File

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cosmiconfig = require("cosmiconfig");
function getConf(dir) {
const explorer = cosmiconfig('husky');
const { config = {} } = explorer.searchSync(dir) || {};
const defaults = {
skipCI: true
};
return Object.assign({}, defaults, config);
}
exports.default = getConf;

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

@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const isCI = require("is-ci");
const path = require("path");
const _1 = require("./");
// Just for testing
if (process.env.HUSKY_DEBUG === 'true') {
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.join(__dirname, '../..')] = process.argv;
// Find Git dir
try {
// Run installer
if (action === 'install') {
_1.install(huskyDir, undefined, isCI);
}
else {
_1.uninstall(huskyDir);
}
}
catch (error) {
console.log(`husky > failed to ${action}`);
console.log(error.message);
}

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

@ -0,0 +1,90 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const os = require("os");
const path = require("path");
const slash = 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, pkgName, platform, runScriptPath, version }) => `#!/bin/sh
${exports.huskyIdentifier}
# Hook created by Husky
# Version: ${version}
# At: ${createdAt}
# See: ${homepage}
# From npm package
# Name: ${pkgName}
# Directory: ${pkgDirectory}
# Homepage: ${pkgHomepage}
scriptPath="${runScriptPath}.js"
hookName=\`basename "$0"\`
gitParams="$*"
debug() {
[ "$\{HUSKY_DEBUG\}" = "true" ] && echo "husky:debug $1"
}
debug "$hookName hook started..."
${platform !== 'win32'
? `
if ! command -v node >/dev/null 2>&1; then
echo "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}"
source ${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 rootDir - e.g. /home/typicode/project/
* @param huskyDir - e.g. /home/typicode/project/node_modules/husky/
* @param requireRunNodePath - path to run-node resolved by require e.g. /home/typicode/project/node_modules/.bin/run-node
* @param platform - platform husky installer is running on (used to produce win32 specific script)
*/
function default_1(rootDir, huskyDir, requireRunNodePath,
// Additional param used for testing only
platform = os.platform()) {
const runNodePath = slash(path.relative(rootDir, requireRunNodePath));
// On Windows do not rely on run-node
const node = platform === 'win32' ? 'node' : runNodePath;
// Env variable
const pkgName = process && process.env && process.env.npm_package_name;
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.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8'));
// Path to run.js
const runScriptPath = slash(path.join(path.relative(rootDir, huskyDir), 'run'));
// created at
const createdAt = new Date().toLocaleString();
// Render script
return render({
createdAt,
homepage,
node,
pkgDirectory,
pkgHomepage,
pkgName,
platform,
runScriptPath,
version
});
}
exports.default = default_1;

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

@ -0,0 +1,166 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const findUp = require("find-up");
const fs = require("fs");
const path = require("path");
const pkgDir = require("pkg-dir");
const getConf_1 = require("../getConf");
const getScript_1 = require("./getScript");
const is_1 = require("./is");
const resolveGitDir_1 = 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.writeFileSync(filename, script, 'utf-8');
fs.chmodSync(filename, parseInt('0755', 8));
}
function createHook(filename, script) {
// Get name, used for logging
const name = path.basename(filename);
// Check if hook exist
if (fs.existsSync(filename)) {
const hook = fs.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.existsSync(filename)) {
const data = fs.readFileSync(filename, 'utf-8');
return is_1.isHusky(data);
}
return false;
}
function removeHook(filename) {
fs.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.join(gitDir, 'hooks');
return hookList.map(hookName => path.join(gitHooksDir, hookName));
}
/**
* @param huskyDir - e.g. /home/typicode/project/node_modules/husky/
* @param requireRunNodePath - path to run-node resolved by require e.g. /home/typicode/project/node_modules/.bin/run-node
* @param isCI - true if running in CI
*/
function install(huskyDir, requireRunNodePath = require.resolve('.bin/run-node'), isCI) {
console.log('husky > setting up git hooks');
// First directory containing user's package.json
const userPkgDir = pkgDir.sync(path.join(huskyDir, '..'));
// 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 = findUp.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) {
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 (userPkgDir === null) {
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;
}
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.existsSync(path.join(resolvedGitDir, 'hooks'))) {
fs.mkdirSync(path.join(resolvedGitDir, 'hooks'));
}
// Create hooks
// Get root dir based on the first .git directory of file found
const rootDir = path.dirname(gitDirOrFile);
const hooks = getHooks(resolvedGitDir);
const script = getScript_1.default(rootDir, huskyDir, requireRunNodePath);
createHooks(hooks, script);
console.log(`husky > done`);
}
exports.install = install;
function uninstall(huskyDir) {
console.log('husky > uninstalling git hooks');
const userPkgDir = pkgDir.sync(path.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) {
// 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;

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

@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const findUp = require("find-up");
const fs = require("fs");
const path = require("path");
function default_1(cwd) {
const foundPath = findUp.sync('.git', { cwd });
if (foundPath) {
const stats = fs.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.readFileSync(foundPath, 'utf-8');
const resolvedGitDir = gitFileData
.split(':')
.slice(1)
.join(':')
.trim();
return path.resolve(path.dirname(foundPath), resolvedGitDir);
}
// Else return path to .git directory
return foundPath;
}
return null;
}
exports.default = default_1;

9
node_modules/husky/lib/runner/bin.js generated vendored Normal file
View File

@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require("./");
_1.default(process.argv)
.then(status => process.exit(status))
.catch(err => {
console.log('Husky > unexpected error', err);
process.exit(1);
});

79
node_modules/husky/lib/runner/index.js generated vendored Normal file
View File

@ -0,0 +1,79 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const execa = require("execa");
const getStdin = require("get-stdin");
const path = require("path");
const readPkg = require("read-pkg");
const getConf_1 = require("../getConf");
/**
* @param argv - process.argv
*/
function run([, scriptPath, hookName = '', HUSKY_GIT_PARAMS], getStdinFn = getStdin // Used for mocking
) {
return __awaiter(this, void 0, void 0, function* () {
const cwd = path.resolve(scriptPath.split('node_modules')[0]);
// In some cases, package.json may not exist
// For example, when switching to gh-page branch
let pkg;
try {
pkg = readPkg.sync({ cwd, normalize: false });
}
catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
const config = getConf_1.default(cwd);
const command = config && config.hooks && config.hooks[hookName];
const oldCommand = pkg && pkg.scripts && pkg.scripts[hookName.replace('-', '')];
// Run command
try {
const env = {};
if (HUSKY_GIT_PARAMS) {
env.HUSKY_GIT_PARAMS = HUSKY_GIT_PARAMS;
}
if (['pre-push', 'pre-receive', 'post-receive', 'post-rewrite'].includes(hookName)) {
env.HUSKY_GIT_STDIN = yield getStdinFn();
}
if (command) {
console.log(`husky > ${hookName} (node ${process.version})`);
execa.shellSync(command, { cwd, env, stdio: 'inherit' });
return 0;
}
if (oldCommand) {
console.log();
console.log(`Warning: Setting ${hookName} script in package.json > scripts will be deprecated`);
console.log(`Please move it to husky.hooks in package.json, a .huskyrc file, or a husky.config.js file`);
console.log(`Or run ./node_modules/.bin/husky-upgrade for automatic update`);
console.log();
console.log(`See https://github.com/typicode/husky for usage`);
console.log();
console.log(`husky > ${hookName} (node ${process.version})`);
execa.shellSync(oldCommand, { cwd, env, stdio: 'inherit' });
return 0;
}
return 0;
}
catch (err) {
const noVerifyMessage = [
'commit-msg',
'pre-commit',
'pre-rebase',
'pre-push'
].includes(hookName)
? '(add --no-verify to bypass)'
: '(cannot be bypassed with --no-verify due to Git specs)';
console.log(`husky > ${hookName} hook failed ${noVerifyMessage}`);
return err.code;
}
});
}
exports.default = run;

5
node_modules/husky/lib/upgrader/bin.js generated vendored Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
index_1.default(process.cwd());

58
node_modules/husky/lib/upgrader/index.js generated vendored Normal file
View File

@ -0,0 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const readPkg = require("read-pkg");
const hookList = {
applypatchmsg: 'applypatch-msg',
commitmsg: 'commit-msg',
postapplypatch: 'post-applypatch',
postcheckout: 'post-checkout',
postcommit: 'post-commit',
postmerge: 'post-merge',
postreceive: 'post-receive',
postrewrite: 'post-rewrite',
postupdate: 'post-update',
preapplypatch: 'pre-applypatch',
preautogc: 'pre-auto-gc',
precommit: 'pre-commit',
preparecommitmsg: 'prepare-commit-msg',
prepush: 'pre-push',
prerebase: 'pre-rebase',
prereceive: 'pre-receive',
pushtocheckout: 'push-to-checkout',
sendemailvalidate: 'sendemail-validate',
update: 'update'
};
function upgrade(cwd) {
const pkgFile = path.join(cwd, 'package.json');
if (fs.existsSync(pkgFile)) {
const pkg = readPkg.sync({ cwd, normalize: false });
console.log(`husky > upgrading ${pkgFile}`);
// Don't overwrite pkg.husky if it exists
if (pkg.husky) {
return console.log(`husky field in package.json isn't empty, skipping automatic upgrade`);
}
const hooks = {};
// Loop trhough hooks and move them to husky.hooks
Object.keys(hookList).forEach(name => {
const script = pkg.scripts[name];
if (script) {
delete pkg.scripts[name];
const newName = hookList[name];
hooks[newName] = script.replace(/\bGIT_PARAMS\b/g, 'HUSKY_GIT_PARAMS');
console.log(`moved scripts.${name} to husky.hooks.${newName}`);
}
});
if (Object.keys(hooks).length) {
pkg.husky = { hooks };
}
else {
console.log('no hooks found');
}
// Update package.json
fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`, 'utf-8');
console.log(`husky > done`);
}
}
exports.default = upgrade;