diff --git a/package-lock.json b/package-lock.json index c20ce7793..eb5dc1315 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "husky", - "version": "4.0.7", + "version": "4.0.8", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3568,11 +3568,6 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, - "get-stdin": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-7.0.0.tgz", - "integrity": "sha512-zRKcywvrXlXsA0v0i9Io4KDRaAw7+a1ZpjRwl9Wox8PFlVCCHra7E9c4kqXCoCM9nR5tBkaTTZRBoCm60bFqTQ==" - }, "get-value": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz", diff --git a/package.json b/package.json index 770eb0d69..0ba54c184 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "husky", - "version": "4.0.7", + "version": "4.0.8", "description": "Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...)", "bin": { "husky-run": "./run.js", @@ -52,7 +52,6 @@ "chalk": "^3.0.0", "ci-info": "^2.0.0", "cosmiconfig": "^6.0.0", - "get-stdin": "^7.0.0", "opencollective-postinstall": "^2.0.2", "pkg-dir": "^4.2.0", "please-upgrade-node": "^3.2.0", diff --git a/src/installer/__tests__/__snapshots__/getScript.ts.snap b/src/installer/__tests__/__snapshots__/getScript.ts.snap index 6415e7128..cb8c5db3b 100644 --- a/src/installer/__tests__/__snapshots__/getScript.ts.snap +++ b/src/installer/__tests__/__snapshots__/getScript.ts.snap @@ -4,7 +4,7 @@ exports[`hookScript should match snapshot 1`] = ` "#!/bin/sh # husky -# Hook created by Husky v4.0.7 (https://github.com/typicode/husky#readme) +# Hook created by Husky v4.0.8 (https://github.com/typicode/husky#readme) # At: # From: /home/typicode/projects/foo-package (https://github.com/foo/foo-package) # With: npm @@ -45,7 +45,7 @@ run_command () { fi } -debug \\"husky v4.0.7 (created at )\\" +debug \\"husky v4.0.8 (created at )\\" debug \\"$hookName hook started\\" debug \\"Current working directory is \`pwd\`\\" @@ -68,6 +68,11 @@ fi cd \\".\\" +case $hookName in + \\"pre-push\\"|\\"pre-receive\\"|\\"post-receive\\"|\\"post-rewrite\\") + export HUSKY_GIT_STDIN=\`cat\`;; +esac + if command_exists winpty && test -t 1; then exec < /dev/tty fi diff --git a/src/installer/getScript.ts b/src/installer/getScript.ts index 3bc803720..f591dfc5a 100644 --- a/src/installer/getScript.ts +++ b/src/installer/getScript.ts @@ -94,6 +94,11 @@ fi cd "${relativeUserPkgDir}" +case $hookName in + "pre-push"|"pre-receive"|"post-receive"|"post-rewrite") + export HUSKY_GIT_STDIN=\`cat\`;; +esac + if command_exists winpty && test -t 1; then exec < /dev/tty fi diff --git a/src/runner/__tests__/index.ts b/src/runner/__tests__/index.ts index 6c3e3e4a4..b249afa0c 100644 --- a/src/runner/__tests__/index.ts +++ b/src/runner/__tests__/index.ts @@ -107,32 +107,6 @@ describe('run', (): void => { expect(status).toBe(0) }) - it('should set HUSKY_GIT_STDIN env for some hooks', async (): Promise< - void - > => { - const dir = tempy.directory() - - fs.writeFileSync( - path.join(dir, 'package.json'), - JSON.stringify({ - husky: { - hooks: { - 'pre-push': 'echo success' - } - } - }) - ) - - const status = await index(['', '', 'pre-push'], { - cwd: dir, - getStdinFn: (): Promise => Promise.resolve('foo') - }) - expectSpawnSyncToHaveBeenCalledWith(dir, 'echo success', { - HUSKY_GIT_STDIN: 'foo' - }) - expect(status).toBe(0) - }) - it('should set HUSKY_GIT_PARAMS', async (): Promise => { const dir = tempy.directory() @@ -160,8 +134,7 @@ describe('run', (): void => { it("should not throw if there's no package.json", async (): Promise => { const dir = tempy.directory() await index(['', '', 'pre-push'], { - cwd: dir, - getStdinFn: (): Promise => Promise.resolve('foo') + cwd: dir }) }) }) diff --git a/src/runner/index.ts b/src/runner/index.ts index 43d6ec7d6..e2c76c7a3 100644 --- a/src/runner/index.ts +++ b/src/runner/index.ts @@ -1,6 +1,5 @@ import chalk from 'chalk' import { spawnSync } from 'child_process' -import getStdin from 'get-stdin' import getConf from '../getConf' import { readPkg } from '../read-pkg' @@ -70,10 +69,7 @@ function runCommand( */ export default async function run( [, , hookName = '', HUSKY_GIT_PARAMS]: string[], - { - cwd = process.cwd(), - getStdinFn = getStdin - }: { cwd?: string; getStdinFn?: () => Promise } = {} + { cwd = process.cwd() }: { cwd?: string } = {} ): Promise { const oldCommand = getOldCommand(cwd, hookName) const command = getCommand(cwd, hookName) @@ -85,17 +81,6 @@ export default async function run( env.HUSKY_GIT_PARAMS = HUSKY_GIT_PARAMS } - // Read stdin and add HUSKY_GIT_STDIN - const hooksWithStdin = [ - 'pre-push', - 'pre-receive', - 'post-receive', - 'post-rewrite' - ] - if (hooksWithStdin.includes(hookName)) { - env.HUSKY_GIT_STDIN = await getStdinFn() - } - if (command) { return runCommand(cwd, hookName, command, env) }