From ec415c61add9e56f30f00cb5b9f3d3e928b02256 Mon Sep 17 00:00:00 2001 From: typicode Date: Mon, 1 Oct 2018 17:43:35 +0200 Subject: [PATCH] Fix TypeScript errors --- package-lock.json | 34 +++++++++++++++++++++++++++++++- package.json | 1 + src/installer/__tests__/index.ts | 4 ++-- src/runner/__tests__/index.ts | 18 ++++++++--------- src/runner/index.ts | 2 +- 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index b877cc18c..af3f4adac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,21 @@ } } }, + "@types/del": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/del/-/del-3.0.1.tgz", + "integrity": "sha512-y6qRq6raBuu965clKgx6FHuiPu3oHdtmzMPXi8Uahsjdq1L6DL5fS/aY5/s71YwM7k6K1QIWvem5vNwlnNGIkQ==", + "dev": true, + "requires": { + "@types/glob": "*" + } + }, + "@types/events": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz", + "integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==", + "dev": true + }, "@types/execa": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/@types/execa/-/execa-0.9.0.tgz", @@ -56,12 +71,29 @@ "@types/node": "*" } }, + "@types/glob": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz", + "integrity": "sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==", + "dev": true, + "requires": { + "@types/events": "*", + "@types/minimatch": "*", + "@types/node": "*" + } + }, "@types/jest": { "version": "23.3.2", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-23.3.2.tgz", "integrity": "sha512-D1xlXHZpDonVX+VJ28XtcD5xlu8ex6Fc4cQNnrm2wJvlQnbec9RedhCrhQr6kRAE9XWHSec+JPuTmqJ9jC0qsA==", "dev": true }, + "@types/minimatch": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", + "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", + "dev": true + }, "@types/mkdirp": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/@types/mkdirp/-/mkdirp-0.5.2.tgz", @@ -4100,7 +4132,7 @@ "dependencies": { "minimist": { "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true } diff --git a/package.json b/package.json index 926369a92..f8e647501 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "slash": "^2.0.0" }, "devDependencies": { + "@types/del": "^3.0.1", "@types/execa": "^0.9.0", "@types/find-up": "^2.1.1", "@types/get-stdin": "^5.0.1", diff --git a/src/installer/__tests__/index.ts b/src/installer/__tests__/index.ts index 7dc1b44ec..99b25e48f 100644 --- a/src/installer/__tests__/index.ts +++ b/src/installer/__tests__/index.ts @@ -7,7 +7,7 @@ import * as tempy from 'tempy' import { install, uninstall } from '../' import { huskyIdentifier } from '../getScript' -let tempDir +let tempDir: string const pkg = JSON.stringify({}) @@ -236,7 +236,7 @@ describe('install', () => { writeFile('package.json', pkg) installFrom(huskyDir) - expect(exists('.git/hooks/pre-commit')).toBeFalsy() + expect(exists(hookFilename)).toBeFalsy() }) it('should migrate existing scripts (ghooks)', () => { diff --git a/src/runner/__tests__/index.ts b/src/runner/__tests__/index.ts index 25d8344b8..ba54a428e 100644 --- a/src/runner/__tests__/index.ts +++ b/src/runner/__tests__/index.ts @@ -5,9 +5,9 @@ import * as path from 'path' import * as tempy from 'tempy' import index from '../' -let spy +let spy: jest.SpyInstance -function getScriptPath(dir) { +function getScriptPath(dir: string) { return path.join(dir, 'node_modules/husky/runner/index.js') } @@ -35,7 +35,7 @@ describe('run', () => { }) ) - const status = await index([, getScriptPath(dir), 'pre-commit']) + const status = await index(['', getScriptPath(dir), 'pre-commit']) expect(execa.shellSync).toHaveBeenCalledWith('echo success', { cwd: dir, env: {}, @@ -60,7 +60,7 @@ describe('run', () => { }) ) - const status = await index([, getScriptPath(subDir), 'pre-commit']) + const status = await index(['', getScriptPath(subDir), 'pre-commit']) expect(execa.shellSync).toHaveBeenCalledWith('echo success', { cwd: subDir, env: {}, @@ -81,7 +81,7 @@ describe('run', () => { }) ) - const status = await index([, getScriptPath(dir), 'pre-commit']) + const status = await index(['', getScriptPath(dir), 'pre-commit']) expect(execa.shellSync).not.toBeCalled() expect(status).toBe(0) }) @@ -100,7 +100,7 @@ describe('run', () => { }) ) - const status = await index([, getScriptPath(dir), 'pre-commit']) + const status = await index(['', getScriptPath(dir), 'pre-commit']) expect(execa.shellSync).toHaveBeenCalledWith('echo fail && exit 2', { cwd: dir, env: {}, @@ -121,7 +121,7 @@ describe('run', () => { }) ) - const status = await index([, getScriptPath(dir), 'pre-commit']) + const status = await index(['', getScriptPath(dir), 'pre-commit']) expect(execa.shellSync).toHaveBeenCalledWith('echo success', { cwd: dir, env: {}, @@ -144,7 +144,7 @@ describe('run', () => { }) ) - const status = await index([, getScriptPath(dir), 'pre-push'], () => + const status = await index(['', getScriptPath(dir), 'pre-push'], () => Promise.resolve('foo') ) expect(execa.shellSync).toHaveBeenCalledWith('echo success', { @@ -173,7 +173,7 @@ describe('run', () => { // commit-msg takes one parameter from git const status = await index([ - , + '', getScriptPath(dir), 'commit-msg', 'git fake param' diff --git a/src/runner/index.ts b/src/runner/index.ts index 23603fad7..30a65d960 100644 --- a/src/runner/index.ts +++ b/src/runner/index.ts @@ -14,7 +14,7 @@ export interface IEnv extends NodeJS.ProcessEnv { */ export default async function run( [, scriptPath, hookName = '', HUSKY_GIT_PARAMS]: string[], - getStdinFn = getStdin // Used for mocking + getStdinFn: () => Promise = getStdin // Used for mocking ): Promise { const cwd = path.resolve(scriptPath.split('node_modules')[0]) const pkg = readPkg.sync({ cwd, normalize: false })