feat: add typings for git-diff-parser module (#43599)

This commit is contained in:
Alexej Yaroshevich 2020-04-06 19:46:11 +03:00 committed by GitHub
parent 9a2f620ce7
commit 7c71949f51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import parser = require("git-diff-parser");
const input = `commit cd4a4e2db47f9642cf322fe109b5bfb3f6eb23c7 (HEAD -> master, origin/master, origin/HEAD)
Author: John Doe <johndoe@google.com>
Date: Thu Apr 1 23:59:59 2020 -0100
Just a typical commit message
diff --git a/types/pkg/index.d.ts b/types/pkg/index.d.ts
index 60bb057b92..5c25c419d1 100644
--- a/types/pkg/index.d.ts
+++ b/types/pkg/index.d.ts
@@ -3,3 +3,3 @@ declare namespace A {
*/
- aaa
+ bbb
/**`;
parser(input); // $ExpectType Result

67
types/git-diff-parser/index.d.ts vendored Normal file
View File

@ -0,0 +1,67 @@
// Type definitions for git-diff-parser 1.0
// Project: https://github.com/spookd/git-diff-parser
// Definitions by: Alexey Yaroshevich <https://github.com/qfox>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types='node' />
declare function GitDiffParser(input: string | Buffer): GitDiffParser.Result;
declare namespace GitDiffParser {
/** Represents prefix in `git diff` output: '+', '-', or space */
type LineType = 'deleted' | 'added' | 'normal';
interface Line {
type: LineType;
/** Has line break. Always false for added failes */
break: boolean;
/** Content of removed or added string */
text: string;
/** The main line number */
ln1: number;
/** New line number (for type normal) */
ln2?: number;
}
interface File {
deleted: boolean;
added: boolean;
renamed: boolean;
binary: boolean;
lines: Line[];
index?: string[];
oldName?: string;
name: string;
}
interface Commit {
files: File[];
}
interface DetailedCommit extends Commit {
message?: string;
sha?: string;
date?: Date;
author?: string;
email?: string;
}
interface Result {
detailed: boolean;
commits: Commit[];
}
interface DryResult extends Result {
detailed: false;
}
interface DetailedResult extends Result {
detailed: true;
commits: DetailedCommit[];
}
}
export = GitDiffParser;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"git-diff-parser-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }