Comparing version 5.0.4 to 5.0.5
@@ -22,32 +22,48 @@ #!/usr/bin/env node | ||
console.log(`Usage | ||
husky install [path from git root to package.json] | ||
husky install [dir] (default: .husky) | ||
husky uninstall | ||
husky add <hookname> [cmd] | ||
husky add <file> [cmd] | ||
Examples | ||
husky add pre-commit | ||
husky add pre-commit "npm test" | ||
husky install | ||
husky install .config/husky | ||
husky add .husky/pre-commit | ||
husky add .husky/pre-commit "npm test" | ||
husky add .config/husky/pre-commit "npm test" | ||
`); | ||
} | ||
if (arg === 'add') { | ||
add_1.add({ | ||
cwd: process.cwd(), | ||
hookName: params[0], | ||
cmd: params[1], | ||
}); | ||
switch (arg) { | ||
case 'install': { | ||
if (params.length > 2) { | ||
help(); | ||
process.exit(2); | ||
} | ||
install_1.install(params[0]); | ||
break; | ||
} | ||
case 'uninstall': { | ||
uninstall_1.uninstall(); | ||
break; | ||
} | ||
case 'add': { | ||
if (params.length === 0 || params.length > 2) { | ||
help(); | ||
process.exit(2); | ||
} | ||
add_1.add(params[0], params[1]); | ||
break; | ||
} | ||
case '--version': { | ||
version(); | ||
break; | ||
} | ||
case '-v': { | ||
version(); | ||
break; | ||
} | ||
default: | ||
help(); | ||
} | ||
else if (arg === 'install') { | ||
install_1.install({ | ||
cwd: process.cwd(), | ||
dir: params[0], | ||
}); | ||
} | ||
else if (arg === 'uninstall') { | ||
uninstall_1.uninstall(); | ||
} | ||
else if (['--version', '-v'].includes(arg)) { | ||
version(); | ||
} | ||
else { | ||
help(); | ||
} |
@@ -9,31 +9,21 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const hooksDir = '.husky'; | ||
function getHookFile(cwd, hookName) { | ||
return path_1.default.join(cwd, hooksDir, hookName); | ||
function makeHookExecutable(file) { | ||
fs_1.default.chmodSync(file, 0o0755); | ||
} | ||
function makeHookExecutable(cwd, hookName) { | ||
const hookFile = getHookFile(cwd, hookName); | ||
fs_1.default.chmodSync(hookFile, 0o0755); | ||
} | ||
function createHookFile(cwd, hookName, cmd) { | ||
if (!fs_1.default.existsSync(path_1.default.join(cwd, hooksDir))) { | ||
throw new Error("can't create hook, .husky directory doesn't exist"); | ||
function createHookFile(file, cmd) { | ||
const dir = path_1.default.dirname(file); | ||
if (!fs_1.default.existsSync(dir)) { | ||
throw new Error(`can't create hook, ${dir} directory doesn't exist`); | ||
} | ||
const filename = getHookFile(cwd, hookName); | ||
if (fs_1.default.existsSync(filename)) { | ||
throw new Error(`${hookName} already exists`); | ||
if (fs_1.default.existsSync(file)) { | ||
throw new Error(`${file} already exists`); | ||
} | ||
const data = [ | ||
'#!/bin/sh', | ||
'. "$(dirname $0)/_/husky.sh"', | ||
'', | ||
cmd, | ||
].join('\n'); | ||
fs_1.default.writeFileSync(filename, data, 'utf-8'); | ||
console.log(path_1.default.relative(cwd, filename)); | ||
const data = ['#!/bin/sh', '. "$(dirname $0)/_/husky.sh"', '', cmd].join('\n'); | ||
fs_1.default.writeFileSync(file, data, 'utf-8'); | ||
console.log(`created ${dir}${path_1.default.sep}${path_1.default.basename(file)}`); | ||
} | ||
function add({ cwd, hookName, cmd, }) { | ||
createHookFile(cwd, hookName, cmd); | ||
makeHookExecutable(cwd, hookName); | ||
function add(file, cmd) { | ||
createHookFile(file, cmd); | ||
makeHookExecutable(file); | ||
} | ||
exports.add = add; |
@@ -14,13 +14,10 @@ "use strict"; | ||
} | ||
function install({ cwd, dir = '.', }) { | ||
const absoluteHooksDir = path_1.default.resolve(cwd, dir); | ||
if (!absoluteHooksDir.startsWith(cwd)) { | ||
function install(dir = '.husky') { | ||
const absoluteHooksDir = path_1.default.resolve(process.cwd(), dir); | ||
if (!absoluteHooksDir.startsWith(process.cwd())) { | ||
throw new Error('.. not allowed'); | ||
} | ||
if (!fs_1.default.existsSync(path_1.default.join(cwd, '.git'))) { | ||
if (!fs_1.default.existsSync('.git')) { | ||
throw new Error(".git can't be found"); | ||
} | ||
if (!fs_1.default.existsSync(path_1.default.join(absoluteHooksDir, 'package.json'))) { | ||
throw new Error("package.json can't be found"); | ||
} | ||
const tmpDir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'husky-')); | ||
@@ -35,3 +32,3 @@ copyScript('husky.sh', tmpDir); | ||
...process.env, | ||
husky_dir: path_1.default.join(dir, '.husky'), | ||
husky_dir: dir, | ||
}, | ||
@@ -38,0 +35,0 @@ }); |
{ | ||
"name": "husky", | ||
"version": "5.0.4", | ||
"version": "5.0.5", | ||
"description": "Git hooks made easy", | ||
@@ -20,13 +20,13 @@ "bin": "lib/bin.js", | ||
"@tsconfig/node10": "^1.0.7", | ||
"@types/node": "^14.10.1", | ||
"@typescript-eslint/eslint-plugin": "^4.1.1", | ||
"@typescript-eslint/parser": "^4.1.1", | ||
"docsify-cli": "^4.4.1", | ||
"eslint": "^7.9.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"pinst": "^2.0.0", | ||
"prettier": "^2.1.1", | ||
"type-fest": "^0.16.0", | ||
"typescript": "^4.0.2" | ||
"@types/node": "^14.14.12", | ||
"@typescript-eslint/eslint-plugin": "^4.9.1", | ||
"@typescript-eslint/parser": "^4.9.1", | ||
"docsify-cli": "^4.4.2", | ||
"eslint": "^7.15.0", | ||
"eslint-config-prettier": "^7.0.0", | ||
"eslint-plugin-prettier": "^3.2.0", | ||
"pinst": "^2.1.1", | ||
"prettier": "^2.2.1", | ||
"type-fest": "^0.20.2", | ||
"typescript": "^4.1.3" | ||
}, | ||
@@ -46,3 +46,3 @@ "scripts": { | ||
"pretest": "npm run build --silent && npm pack --silent", | ||
"test": "sh ./test/default.sh && sh ./test/subdir.sh", | ||
"test": "sh ./test/default.sh && sh ./test/sub-dir.sh && sh ./test/config-dir.sh", | ||
"posttest": "rm husky-*.tgz", | ||
@@ -49,0 +49,0 @@ "commit": "commit" |
@@ -9,4 +9,4 @@ # husky | ||
* [__Documentation v5 (recommended)__](https://typicode.github.io/husky) | ||
* [Documentation v4 (current latest)](https://github.com/typicode/husky/tree/master) | ||
- [**Documentation v5 (recommended for Open Source and Sponsors)**](https://typicode.github.io/husky) | ||
- [Documentation v4 (current latest)](https://github.com/typicode/husky/tree/master) | ||
@@ -19,4 +19,6 @@ --- | ||
If you can't sponsor Husky, that's okay, [husky v4](https://github.com/typicode/husky/tree/master) is free to use in any project. During the early access, v4 will continue to receive maintainance updates. | ||
If you can't sponsor Husky, that's okay, [husky v4](https://github.com/typicode/husky/tree/master) is free to use in any project. During the early access, v4 will continue to receive maintainance updates. | ||
After the early access, husky v5 will be MIT again. | ||
--- | ||
@@ -89,2 +91,1 @@ | ||
GitHub sponsors can be viewed on my [profile](https://github.com/typicode). All past and current Open Collective sponsors can be viewed on [Husky's Open Collective](https://opencollective.com/husky). | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45963
29
721
89
17
6