Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-git-hooks

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-git-hooks - npm Package Compare versions

Comparing version 2.10.0 to 2.11.0

5

cli.js
#!/usr/bin/env node
const {setHooksFromConfig} = require('./simple-git-hooks')
const {SKIP_INSTALL_SIMPLE_GIT_HOOKS} = process.env
if (['1', 'true'].includes(SKIP_INSTALL_SIMPLE_GIT_HOOKS)) {
console.log(`[INFO] SKIP_INSTALL_SIMPLE_GIT_HOOKS is set to "${SKIP_INSTALL_SIMPLE_GIT_HOOKS}", skipping installing hook.`)
return
}
try {

@@ -5,0 +10,0 @@ setHooksFromConfig(process.cwd(), process.argv)

13

package.json
{
"name": "simple-git-hooks",
"version": "2.10.0",
"version": "2.11.0",
"description": "A simple, zero dependency tool for setting up git hooks for small projects",
"author": "Mikhail Gorbunov <toplenboren@gmail.com> (toplenboren.github.io)",
"author": "Mikhail Gorbunov <toplenboren@gmail.com>",
"main": "simple-git-hooks.js",
"bin": "./cli.js",
"keywords": [
"pre-commit",
"pre-push",
"git",
"hook",
"lint",
"linter"
],
"keywords": ["pre-commit","pre-push","git","hook","lint","linter"],
"license": "MIT",

@@ -17,0 +10,0 @@ "repository": "toplenboren/simple-git-hooks",

@@ -10,5 +10,3 @@ #!/usr/bin/env node

projectDirectory = parsedProjectDirectory
} else {
projectDirectory = process.cwd()
}
} else { projectDirectory = process.cwd() }
if (checkSimpleGitHooksInDependencies(projectDirectory)) {

@@ -15,0 +13,0 @@ try {

@@ -5,2 +5,2 @@ # simple-git-hooks

Full readme can be read on github: https://github.com/toplenboren/simple-git-hooks
Full README here: https://github.com/toplenboren/simple-git-hooks/tree/master

@@ -1,5 +0,5 @@

const fs = require('fs');
const path = require('path');
const VALID_GIT_HOOKS = ['applypatch-msg', 'pre-applypatch', 'post-applypatch', 'pre-commit', 'pre-merge-commit', 'prepare-commit-msg', 'commit-msg', 'post-commit', 'pre-rebase', 'post-checkout', 'post-merge', 'pre-push', 'pre-receive', 'update', 'proc-receive', 'post-receive', 'post-update', 'reference-transaction', 'push-to-checkout', 'pre-auto-gc', 'post-rewrite', 'sendemail-validate', 'fsmonitor-watchman', 'p4-changelist', 'p4-prepare-changelist', 'p4-post-changelist', 'p4-pre-submit', 'post-index-change']
const VALID_OPTIONS = ['preserveUnused'];
const fs = require('fs')
const path = require('path')
const VALID_GIT_HOOKS = ['applypatch-msg', 'pre-applypatch', 'post-applypatch', 'pre-commit', 'pre-merge-commit', 'prepare-commit-msg', 'commit-msg', 'post-commit', 'pre-rebase', 'post-checkout', 'post-merge', 'pre-push', 'pre-receive', 'update', 'proc-receive', 'post-receive', 'post-update', 'reference-transaction', 'push-to-checkout', 'pre-auto-gc', 'post-rewrite', 'sendemail-validate', 'fsmonitor-watchman', 'p4-changelist', 'p4-prepare-changelist', 'p4-post-changelist', 'p4-pre-submit', 'post-index-change', ]
const VALID_OPTIONS = ['preserveUnused']
const PREPEND_SCRIPT = `#!/bin/sh

@@ -16,5 +16,5 @@

`;
`
function getGitProjectRoot(directory = process.cwd()) {
let start = directory;
let start = directory
if (typeof start === 'string') {

@@ -24,3 +24,3 @@ if (start[start.length - 1] !== path.sep) {

}
start = path.normalize(start);
start = path.normalize(start)
start = start.split(path.sep)

@@ -31,5 +31,5 @@ }

}
start.pop();
let dir = start.join(path.sep);
let fullPath = path.join(dir, '.git');
start.pop()
let dir = start.join(path.sep)
let fullPath = path.join(dir, '.git')
if (fs.existsSync(fullPath)) {

@@ -39,6 +39,6 @@ if (!fs.lstatSync(fullPath).isDirectory()) {

encoding: 'utf-8'
});
let match = /^gitdir: (.*)\s*$/.exec(content);
})
let match = /^gitdir: (.*)\s*$/.exec(content)
if (match) {
let gitDir = match[1];
let gitDir = match[1]
let commonDir = path.join(gitDir, 'commondir');

@@ -61,10 +61,10 @@ if (fs.existsSync(commonDir)) {

}
const projDir = projectPath.split(/[\\/]/);
const indexOfPnpmDir = projDir.indexOf('.pnpm');
const projDir = projectPath.split(/[\\/]/) // <- would split both on '/' and '\'
const indexOfPnpmDir = projDir.indexOf('.pnpm')
if (indexOfPnpmDir > -1) {
return projDir.slice(0, indexOfPnpmDir - 1).join('/')
return projDir.slice(0, indexOfPnpmDir - 1).join('/');
}
const indexOfStoreDir = projDir.indexOf('.store');
const indexOfStoreDir = projDir.indexOf('.store')
if (indexOfStoreDir > -1) {
return projDir.slice(0, indexOfStoreDir - 1).join('/')
return projDir.slice(0, indexOfStoreDir - 1).join('/');
}

@@ -85,6 +85,6 @@ if (projDir.includes('.yarn') && projDir.includes('unplugged')) {

packageJsonContent
} = _getPackageJson(projectRootPath);
} = _getPackageJson(projectRootPath)
if ('dependencies' in packageJsonContent && 'simple-git-hooks' in packageJsonContent.dependencies) {
console.warn('[WARN] You should move simple-git-hooks to the devDependencies!');
return true;
console.warn('[WARN] You should move simple-git-hooks to the devDependencies!')
return true
}

@@ -97,8 +97,8 @@ if (!('devDependencies' in packageJsonContent)) {

function setHooksFromConfig(projectRootPath = process.cwd(), argv = process.argv) {
const customConfigPath = _getCustomConfigPath(argv);
const config = _getConfig(projectRootPath, customConfigPath);
const customConfigPath = _getCustomConfigPath(argv)
const config = _getConfig(projectRootPath, customConfigPath)
if (!config) {
throw ('[ERROR] Config was not found! Please add `.simple-git-hooks.js` or `simple-git-hooks.js` or `.simple-git-hooks.json` or `simple-git-hooks.json` or `simple-git-hooks` entry in package.json.\r\nCheck README for details')
}
const preserveUnused = Array.isArray(config.preserveUnused) ? config.preserveUnused : config.preserveUnused ? VALID_GIT_HOOKS : [];
const preserveUnused = Array.isArray(config.preserveUnused) ? config.preserveUnused : config.preserveUnused ? VALID_GIT_HOOKS : []
for (let hook of VALID_GIT_HOOKS) {

@@ -113,17 +113,17 @@ if (Object.prototype.hasOwnProperty.call(config, hook)) {

function _setHook(hook, command, projectRoot = process.cwd()) {
const gitRoot = getGitProjectRoot(projectRoot);
const gitRoot = getGitProjectRoot(projectRoot)
if (!gitRoot) {
console.info('[INFO] No `.git` root folder found, skipping');
console.info('[INFO] No `.git` root folder found, skipping')
return
}
const hookCommand = PREPEND_SCRIPT + command;
const hookDirectory = gitRoot + '/hooks/';
const hookPath = path.normalize(hookDirectory + hook);
const normalizedHookDirectory = path.normalize(hookDirectory);
const hookCommand = PREPEND_SCRIPT + command
const hookDirectory = gitRoot + '/hooks/'
const hookPath = path.normalize(hookDirectory + hook)
const normalizedHookDirectory = path.normalize(hookDirectory)
if (!fs.existsSync(normalizedHookDirectory)) {
fs.mkdirSync(normalizedHookDirectory)
}
fs.writeFileSync(hookPath, hookCommand);
fs.chmodSync(hookPath, 0o0755);
console.info(`[INFO] Successfully set the ${ hook } with command: ${ command }`)
fs.writeFileSync(hookPath, hookCommand)
fs.chmodSync(hookPath, 0o0755)
console.info(`[INFO] Successfully set the ${hook} with command: ${command}`)
}

@@ -136,4 +136,4 @@ function removeHooks(projectRoot = process.cwd()) {

function _removeHook(hook, projectRoot = process.cwd()) {
const gitRoot = getGitProjectRoot(projectRoot);
const hookPath = path.normalize(gitRoot + '/hooks/' + hook);
const gitRoot = getGitProjectRoot(projectRoot)
const hookPath = path.normalize(gitRoot + '/hooks/' + hook)
if (fs.existsSync(hookPath)) {

@@ -147,7 +147,7 @@ fs.unlinkSync(hookPath)

}
const targetPackageJson = path.normalize(projectPath + '/package.json');
const targetPackageJson = path.normalize(projectPath + '/package.json')
if (!fs.statSync(targetPackageJson).isFile()) {
throw Error("Package.json doesn't exist")
}
const packageJsonDataRaw = fs.readFileSync(targetPackageJson);
const packageJsonDataRaw = fs.readFileSync(targetPackageJson)
return {

@@ -165,3 +165,5 @@ packageJsonContent: JSON.parse(packageJsonDataRaw),

}
const sources = [() => _getConfigFromFile(projectRootPath, '.simple-git-hooks.cjs'), () => _getConfigFromFile(projectRootPath, '.simple-git-hooks.js'), () => _getConfigFromFile(projectRootPath, 'simple-git-hooks.cjs'), () => _getConfigFromFile(projectRootPath, 'simple-git-hooks.js'), () => _getConfigFromFile(projectRootPath, '.simple-git-hooks.json'), () => _getConfigFromFile(projectRootPath, 'simple-git-hooks.json'), () => _getConfigFromPackageJson(projectRootPath)];
const sources = [
() => _getConfigFromFile(projectRootPath, '.simple-git-hooks.cjs'), () => _getConfigFromFile(projectRootPath, '.simple-git-hooks.js'), () => _getConfigFromFile(projectRootPath, 'simple-git-hooks.cjs'), () => _getConfigFromFile(projectRootPath, 'simple-git-hooks.js'), () => _getConfigFromFile(projectRootPath, '.simple-git-hooks.json'), () => _getConfigFromFile(projectRootPath, 'simple-git-hooks.json'), () => _getConfigFromPackageJson(projectRootPath),
]
if (configFileName) {

@@ -171,3 +173,3 @@ sources.unshift(() => _getConfigFromFile(projectRootPath, configFileName))

for (let executeSource of sources) {
let config = executeSource();
let config = executeSource()
if (config && _validateHooks(config)) {

@@ -184,3 +186,3 @@ return config

packageJsonContent
} = _getPackageJson(projectRootPath);
} = _getPackageJson(projectRootPath)
const config = packageJsonContent['simple-git-hooks'];

@@ -197,7 +199,7 @@ return typeof config === 'string' ? _getConfig(config) : packageJsonContent['simple-git-hooks']

try {
const filePath = path.isAbsolute(fileName) ? fileName : path.normalize(projectRootPath + '/' + fileName);
const filePath = path.isAbsolute(fileName) ? fileName : path.normalize(projectRootPath + '/' + fileName)
if (filePath === __filename) {
return undefined
}
return require(filePath);
return require(filePath)
} catch (err) {

@@ -222,2 +224,2 @@ return undefined

PREPEND_SCRIPT
};
}
#!/usr/bin/env node
const {removeHooks} = require("./simple-git-hooks");
const { removeHooks} = require("./simple-git-hooks");
function uninstall() {

@@ -6,0 +5,0 @@ console.log("[INFO] Removing git hooks from .git/hooks")

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc