From 0d7796ad73127fd86171ba8f0c5ae9fd47c57c31 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Tue, 25 Dec 2018 22:12:53 +0100 Subject: [PATCH 1/2] [parse-git-config] Move v2 types to sub-dir --- types/parse-git-config/{ => v2}/index.d.ts | 0 .../{ => v2}/parse-git-config-tests.ts | 0 types/parse-git-config/{ => v2}/tsconfig.json | 11 ++++++++--- types/parse-git-config/{ => v2}/tslint.json | 0 4 files changed, 8 insertions(+), 3 deletions(-) rename types/parse-git-config/{ => v2}/index.d.ts (100%) rename types/parse-git-config/{ => v2}/parse-git-config-tests.ts (100%) rename types/parse-git-config/{ => v2}/tsconfig.json (72%) rename types/parse-git-config/{ => v2}/tslint.json (100%) diff --git a/types/parse-git-config/index.d.ts b/types/parse-git-config/v2/index.d.ts similarity index 100% rename from types/parse-git-config/index.d.ts rename to types/parse-git-config/v2/index.d.ts diff --git a/types/parse-git-config/parse-git-config-tests.ts b/types/parse-git-config/v2/parse-git-config-tests.ts similarity index 100% rename from types/parse-git-config/parse-git-config-tests.ts rename to types/parse-git-config/v2/parse-git-config-tests.ts diff --git a/types/parse-git-config/tsconfig.json b/types/parse-git-config/v2/tsconfig.json similarity index 72% rename from types/parse-git-config/tsconfig.json rename to types/parse-git-config/v2/tsconfig.json index 5295cbc1ee..88a5878593 100644 --- a/types/parse-git-config/tsconfig.json +++ b/types/parse-git-config/v2/tsconfig.json @@ -8,10 +8,15 @@ "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, - "baseUrl": "../", + "baseUrl": "../../", "typeRoots": [ - "../" + "../../" ], + "paths": { + "parse-git-config": [ + "parse-git-config/v2" + ] + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true @@ -20,4 +25,4 @@ "index.d.ts", "parse-git-config-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/parse-git-config/tslint.json b/types/parse-git-config/v2/tslint.json similarity index 100% rename from types/parse-git-config/tslint.json rename to types/parse-git-config/v2/tslint.json From 5e43f569d756356aeac6b4d7010c50fb4946c737 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Tue, 25 Dec 2018 23:09:24 +0100 Subject: [PATCH 2/2] [parse-git-config] Update types to v3 --- types/parse-git-config/index.d.ts | 90 +++++++++++++++++++ .../parse-git-config-tests.ts | 53 +++++++++++ types/parse-git-config/tsconfig.json | 23 +++++ types/parse-git-config/tslint.json | 3 + 4 files changed, 169 insertions(+) create mode 100644 types/parse-git-config/index.d.ts create mode 100644 types/parse-git-config/parse-git-config-tests.ts create mode 100644 types/parse-git-config/tsconfig.json create mode 100644 types/parse-git-config/tslint.json diff --git a/types/parse-git-config/index.d.ts b/types/parse-git-config/index.d.ts new file mode 100644 index 0000000000..ca218eae52 --- /dev/null +++ b/types/parse-git-config/index.d.ts @@ -0,0 +1,90 @@ +// Type definitions for parse-git-config 3.0 +// Project: https://github.com/jonschlinkert/parse-git-config +// Definitions by: Leonard Thieu +// Nikita Litvin +// BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +export = parse; + +/** + * Asynchronously parse a `.git/config` file. If only the callback is passed, + * the `.git/config` file relative to `process.cwd()` is used. + * + * @example ```js + * parse((err, config) => { + * if (err) throw err; + * // do stuff with config + * }); + * + * // or, using async/await + * (async () => { + * console.log(await parse()); + * console.log(await parse({ cwd: 'foo' })); + * console.log(await parse({ cwd: 'foo', path: 'some/.git/config' })); + * })(); + * ``` + * @param options Options with `cwd` or `path`, the cwd to use, or the callback function. + * @param callback callback function if the first argument is options or cwd. + */ +declare function parse(cb: parse.ParseCallback): void; +declare function parse(options?: parse.Options | string): Promise; +declare function parse(options: parse.Options | string, cb: parse.ParseCallback): void; + +declare namespace parse { + /** + * Asynchronously parse a .git/config file. Returns a promise. + * Resolves with `null` if unable to resolve path to the git config file. + * If no arguments are passed, the .git/config file relative to process.cwd() is used. + */ + function promise(options?: Options | string): Promise; + + /** + * Synchronously parse a `.git/config` file. If no arguments are passed, + * the `.git/config` file relative to `process.cwd()` is used. + * + * @example ```js + * console.log(parse.sync()); + * console.log(parse.sync({ cwd: 'foo' })); + * console.log(parse.sync({ cwd: 'foo', path: 'some/.git/config' })); + * ``` + * @param options Options with `cwd` or `path`, or the cwd to use. + */ + function sync(options?: Options | string): Config; + + /** + * Returns an object with only the properties that had ini-style keys + * converted to objects. + * + * @example ```js + * const config = parse.sync({ path: '/path/to/.gitconfig' }); + * const obj = parse.expandKeys(config); + * ``` + * @param config The parsed git config object. + */ + function expandKeys(config: Config): Config; + + /** + * Resolve the git config path + */ + function resolveConfigPath(options: string | ResolveConfigOptions): string | null; + + interface ResolveConfigOptions { + type?: 'global'; + cwd?: string; + path?: string; + } + + interface Options extends ResolveConfigOptions { + include?: boolean; + expandKeys?: boolean; + } + + type ParseCallback = ((err: Error | null, config: Config) => void); + + // TODO: Can this be defined more precisely? + interface Config { + [key: string]: any; + } +} diff --git a/types/parse-git-config/parse-git-config-tests.ts b/types/parse-git-config/parse-git-config-tests.ts new file mode 100644 index 0000000000..7f02418fbf --- /dev/null +++ b/types/parse-git-config/parse-git-config-tests.ts @@ -0,0 +1,53 @@ +import parse = require('parse-git-config'); + +parse({ cwd: 'foo' }); +parse({ path: '.git/config' }); +parse({ type: 'global' }); +parse({ type: 'foo' }); // $ExpectError +parse({ include: true }); +parse({ expandKeys: true }); + +parse(); // $ExpectType Promise +parse('foo'); // $ExpectType Promise +parse({ cwd: 'foo' }); // $ExpectType Promise +// $ExpectType void +parse((err, config) => { + err; // $ExpectType Error | null + config; // $ExpectType Config +}); +// $ExpectType void +parse('foo', (err, config) => { + err; // $ExpectType Error | null + config; // $ExpectType Config +}); +// $ExpectType void +parse({ cwd: 'foo' }, (err, config) => { + err; // $ExpectType Error | null + config; // $ExpectType Config +}); + +parse.promise(); // $ExpectType Promise +parse.promise('foo'); // $ExpectType Promise +parse.promise({ cwd: 'foo' }); // $ExpectType Promise + +parse.sync(); // $ExpectType Config +parse.sync('foo'); // $ExpectType Config +parse.sync({ cwd: 'foo' }); // $ExpectType Config + +function test_expandKeys() { + const config = { + 'foo "bar"': { doStuff: true }, + 'foo "baz"': { doStuff: true }, + }; + const keys = parse.expandKeys(config); + + keys.foo.bar.doStuff === true; + keys.foo.baz.doStuff === true; +} + +parse.resolveConfigPath('foo'); // $ExpectType string | null +parse.resolveConfigPath({ cwd: 'foo' }); // $ExpectType string | null +parse.resolveConfigPath({ path: '.git/config' }); // $ExpectType string | null +parse.resolveConfigPath({ type: 'global' }); // $ExpectType string | null +parse.resolveConfigPath({ type: 'foo' }); // $ExpectError +parse.resolveConfigPath({ include: true }); // $ExpectError diff --git a/types/parse-git-config/tsconfig.json b/types/parse-git-config/tsconfig.json new file mode 100644 index 0000000000..55d738d024 --- /dev/null +++ b/types/parse-git-config/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "parse-git-config-tests.ts" + ] +} diff --git a/types/parse-git-config/tslint.json b/types/parse-git-config/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/parse-git-config/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}