mirror of
				https://github.com/shivammathur/setup-php.git
				synced 2025-10-31 07:16:22 +07:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										15
									
								
								node_modules/husky/lib/getConf.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								node_modules/husky/lib/getConf.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| "use strict"; | ||||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||||
|     return (mod && mod.__esModule) ? mod : { "default": mod }; | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| const cosmiconfig_1 = __importDefault(require("cosmiconfig")); | ||||
| function getConf(dir) { | ||||
|     const explorer = cosmiconfig_1.default('husky'); | ||||
|     const { config = {} } = explorer.searchSync(dir) || {}; | ||||
|     const defaults = { | ||||
|         skipCI: true | ||||
|     }; | ||||
|     return Object.assign({}, defaults, config); | ||||
| } | ||||
| exports.default = getConf; | ||||
							
								
								
									
										29
									
								
								node_modules/husky/lib/installer/bin.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								node_modules/husky/lib/installer/bin.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										99
									
								
								node_modules/husky/lib/installer/getScript.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										171
									
								
								node_modules/husky/lib/installer/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										24
									
								
								node_modules/husky/lib/installer/is.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										39
									
								
								node_modules/husky/lib/installer/resolveGitDir.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal 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; | ||||
							
								
								
									
										12
									
								
								node_modules/husky/lib/runner/bin.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								node_modules/husky/lib/runner/bin.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| "use strict"; | ||||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||||
|     return (mod && mod.__esModule) ? mod : { "default": mod }; | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| const _1 = __importDefault(require("./")); | ||||
| _1.default(process.argv) | ||||
|     .then((status) => process.exit(status)) | ||||
|     .catch((err) => { | ||||
|     console.log('Husky > unexpected error', err); | ||||
|     process.exit(1); | ||||
| }); | ||||
							
								
								
									
										83
									
								
								node_modules/husky/lib/runner/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								node_modules/husky/lib/runner/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,83 @@ | ||||
| "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()); | ||||
|     }); | ||||
| }; | ||||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||||
|     return (mod && mod.__esModule) ? mod : { "default": mod }; | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| const execa_1 = __importDefault(require("execa")); | ||||
| const get_stdin_1 = __importDefault(require("get-stdin")); | ||||
| const path_1 = __importDefault(require("path")); | ||||
| const read_pkg_1 = __importDefault(require("read-pkg")); | ||||
| const getConf_1 = __importDefault(require("../getConf")); | ||||
| /** | ||||
|  * @param {array} argv - process.argv | ||||
|  * @param {promise} getStdinFn - used for mocking only | ||||
|  */ | ||||
| function run([, scriptPath, hookName = '', HUSKY_GIT_PARAMS], getStdinFn = get_stdin_1.default) { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         const cwd = path_1.default.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 = read_pkg_1.default.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)) { | ||||
|                 // Wait for stdin | ||||
|                 env.HUSKY_GIT_STDIN = yield getStdinFn(); | ||||
|             } | ||||
|             if (command) { | ||||
|                 console.log(`husky > ${hookName} (node ${process.version})`); | ||||
|                 execa_1.default.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_1.default.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; | ||||
							
								
								
									
										8
									
								
								node_modules/husky/lib/upgrader/bin.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								node_modules/husky/lib/upgrader/bin.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | ||||
| #!/usr/bin/env node | ||||
| "use strict"; | ||||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||||
|     return (mod && mod.__esModule) ? mod : { "default": mod }; | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| const index_1 = __importDefault(require("./index")); | ||||
| index_1.default(process.cwd()); | ||||
							
								
								
									
										64
									
								
								node_modules/husky/lib/upgrader/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								node_modules/husky/lib/upgrader/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,64 @@ | ||||
| "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 path_1 = __importDefault(require("path")); | ||||
| const read_pkg_1 = __importDefault(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_1.default.join(cwd, 'package.json'); | ||||
|     if (fs_1.default.existsSync(pkgFile)) { | ||||
|         const pkg = read_pkg_1.default.sync({ cwd, normalize: false }); | ||||
|         console.log(`husky > upgrading ${pkgFile}`); | ||||
|         // Don't overwrite 'husky' field if it exists | ||||
|         if (pkg.husky) { | ||||
|             return console.log(`husky field in package.json isn't empty, skipping automatic upgrade`); | ||||
|         } | ||||
|         const hooks = {}; | ||||
|         // Find hooks in package.json 'scripts' field | ||||
|         Object.keys(hookList).forEach((name) => { | ||||
|             if (pkg.scripts) { | ||||
|                 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}`); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|         // Move found hooks to 'husky.hooks' field | ||||
|         if (Object.keys(hooks).length) { | ||||
|             pkg.husky = { hooks }; | ||||
|         } | ||||
|         else { | ||||
|             console.log('no hooks found'); | ||||
|         } | ||||
|         // Update package.json | ||||
|         fs_1.default.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`, 'utf-8'); | ||||
|         console.log(`husky > done`); | ||||
|     } | ||||
| } | ||||
| exports.default = upgrade; | ||||
		Reference in New Issue
	
	Block a user
	 Shivam Mathur
					Shivam Mathur