From fa0ee2f4b07246bb853653bd427cb01732027a23 Mon Sep 17 00:00:00 2001 From: segayuu Date: Wed, 13 Sep 2017 13:04:49 +0900 Subject: [PATCH 1/6] changed type from "Function" to "Arrow function format". --- types/bluebird/bluebird-tests.ts | 10 +++++----- types/bluebird/index.d.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index 32ad2dcb4b..c72581b8f9 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -13,8 +13,8 @@ var num: number; var str: string; var err: Error; var x: any; -var f: Function; -var func: Function; +var f: (...args: any[]) => any; +var asyncfunc: (...args: any[]) => Promise; var arr: any[]; var exp: RegExp; var anyArr: any[]; @@ -746,7 +746,7 @@ fooProm = Promise.attempt(() => { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -func = Promise.method(function () { +asyncfunc = Promise.method(function () { }); @@ -784,8 +784,8 @@ voidProm = Promise.delay(num); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -func = Promise.promisify(f); -func = Promise.promisify(f, obj); +asyncfunc = Promise.promisify(f); +asyncfunc = Promise.promisify(f, obj); obj = Promise.promisifyAll(obj); anyProm = Promise.fromNode(callback => nodeCallbackFunc(callback)); diff --git a/types/bluebird/index.d.ts b/types/bluebird/index.d.ts index 77327127d1..5175bb8d4b 100644 --- a/types/bluebird/index.d.ts +++ b/types/bluebird/index.d.ts @@ -609,7 +609,7 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { * Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers. */ spread(fulfilledHandler: (...values: W[]) => U | PromiseLike): Bluebird; - spread(fulfilledHandler: Function): Bluebird; + spread(fulfilledHandler: (...args: any[]) => U | PromiseLike): Bluebird; /** * Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. @@ -695,7 +695,7 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { * Returns a new function that wraps the given function `fn`. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function. * This method is convenient when a function can sometimes return synchronously or throw synchronously. */ - static method(fn: Function): Function; + static method(fn: (...args: any[]) => R | PromiseLike): (...args: any[]) => Bluebird; /** * Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state. @@ -755,7 +755,7 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { static promisify(func: (arg1: A1, arg2: A2, arg3: A3, callback: (err: any, result?: T) => void) => void, options?: Bluebird.PromisifyOptions): (arg1: A1, arg2: A2, arg3: A3) => Bluebird; static promisify(func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, callback: (err: any, result?: T) => void) => void, options?: Bluebird.PromisifyOptions): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Bluebird; static promisify(func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5, callback: (err: any, result?: T) => void) => void, options?: Bluebird.PromisifyOptions): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Bluebird; - static promisify(nodeFunction: Function, options?: Bluebird.PromisifyOptions): Function; + static promisify(nodeFunction: (...args: any[]) => void, options?: Bluebird.PromisifyOptions): (...args: any[]) => Bluebird; /** * Promisifies the entire object by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain. The promisified method name will be the original method name postfixed with `Async`. Returns the input object. @@ -777,7 +777,7 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { * Returns a function that can use `yield` to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. */ // TODO fix coroutine GeneratorFunction - static coroutine(generatorFunction: Function): Function; + static coroutine(generatorFunction: (...args: any[]) => IterableIterator): (...args: any[]) => Bluebird; /** * Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers. @@ -1011,9 +1011,9 @@ declare namespace Bluebird { } export interface PromisifyAllOptions extends PromisifyOptions { suffix?: string; - filter?: (name: string, func: Function, target?: any, passesDefaultFilter?: boolean) => boolean; + filter?: (name: string, func: (...args: any[]) => any, target?: any, passesDefaultFilter?: boolean) => boolean; // The promisifier gets a reference to the original method and should return a function which returns a promise - promisifier?: (originalMethod: Function) => () => PromiseLike; + promisifier?: (originalMethod: (...args: any[]) => any, defaultPromisifer: (...args: any[]) => (...args: any[]) => Bluebird) => () => PromiseLike; } /** From bec36516c2493b97f00fa3531b99c19ba0334654 Mon Sep 17 00:00:00 2001 From: segayuu Date: Thu, 14 Sep 2017 13:48:44 +0900 Subject: [PATCH 2/6] Added typed "hexo-bunyan". --- types/hexo-bunyan/index.d.ts | 8 ++++++++ types/hexo-bunyan/tsconfig.json | 21 +++++++++++++++++++++ types/hexo-bunyan/tslint.json | 1 + 3 files changed, 30 insertions(+) create mode 100644 types/hexo-bunyan/index.d.ts create mode 100644 types/hexo-bunyan/tsconfig.json create mode 100644 types/hexo-bunyan/tslint.json diff --git a/types/hexo-bunyan/index.d.ts b/types/hexo-bunyan/index.d.ts new file mode 100644 index 0000000000..fb39ec6684 --- /dev/null +++ b/types/hexo-bunyan/index.d.ts @@ -0,0 +1,8 @@ +// Type definitions for hexo-bunyan 1.0 +// Project: https://github.com/trentm/node-bunyan#readme +// Definitions by: segayuu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import bunyan = require("bunyan"); + +export = bunyan; diff --git a/types/hexo-bunyan/tsconfig.json b/types/hexo-bunyan/tsconfig.json new file mode 100644 index 0000000000..a2cbd4e379 --- /dev/null +++ b/types/hexo-bunyan/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts" + ] +} diff --git a/types/hexo-bunyan/tslint.json b/types/hexo-bunyan/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hexo-bunyan/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 0438cc82c3fc05d821c3ef4abcd9dbbbe6c4cb6d Mon Sep 17 00:00:00 2001 From: segayuu Date: Thu, 14 Sep 2017 13:49:07 +0900 Subject: [PATCH 3/6] Added types hexo-log --- types/hexo-log/hexo-log-tests.ts | 90 +++++++++++++++++ types/hexo-log/index.d.ts | 162 +++++++++++++++++++++++++++++++ types/hexo-log/tsconfig.json | 22 +++++ types/hexo-log/tslint.json | 1 + 4 files changed, 275 insertions(+) create mode 100644 types/hexo-log/hexo-log-tests.ts create mode 100644 types/hexo-log/index.d.ts create mode 100644 types/hexo-log/tsconfig.json create mode 100644 types/hexo-log/tslint.json diff --git a/types/hexo-log/hexo-log-tests.ts b/types/hexo-log/hexo-log-tests.ts new file mode 100644 index 0000000000..9efa129cd8 --- /dev/null +++ b/types/hexo-log/hexo-log-tests.ts @@ -0,0 +1,90 @@ +import mocha = require('mocha'); +import chai = require('chai'); +const should = chai.should(); // eslint-disable-line +import rewire = require('rewire'); +import sinon = require('sinon'); +import logger = require('hexo-log'); + +const _c = logger(); +type HexoLogger = typeof _c; + +describe('hexo-log', () => { + const loggerModule = rewire<(options?: { name?: string; silent?: boolean; debug?: boolean; }) => HexoLogger>('./'); + + it('add alias for levels', () => { + const log = logger(); + + log.d.should.eql(log.debug); + log.i.should.eql(log.info); + log.w.should.eql(log.warn); + log.e.should.eql(log.error); + log.log.should.eql(log.info); + }); + + it('default name is hexo', () => { + const log = logger(); + + log.fields.name.should.eql('hexo'); + }); + + it('options.name', () => { + const log = logger({ name: 'foo' }); + + log.fields.name.should.eql('foo'); + }); + + it('level should be trace if options.debug is true', () => { + const log: any = logger({ debug: true }); + + log.streams[0].level.should.eql(10); + }); + + it('should add file stream if options.debug is true', () => { + const log: any = logger({ debug: true }); + + log.streams[1].path.should.eql('debug.log'); + }); + + it('should remove console stream if options.silent is true', () => { + const log: any = logger({ silent: true }); + + log.streams.length.should.eql(0); + }); + + it('should display time if options.debug is true', () => { + const spy = sinon.spy(); + const now = new Date(); + + loggerModule.__with__({ + process: { + stdout: { + write: spy + } + } + })(() => { + sinon.useFakeTimers(now.valueOf()); + const log = loggerModule({ debug: true }); + log.info('test'); + sinon.restore(undefined); + }); + + spy.args[0][0].should.contain(now.toISOString().substring(11, 23)); + }); + + it('should print error to process.stderr stream', () => { + const spy = sinon.spy(); + + loggerModule.__with__({ + process: { + stderr: { + write: spy + } + } + })(() => { + const log = loggerModule(); + log.error('test'); + }); + + spy.calledOnce.should.be.true; + }); +}); diff --git a/types/hexo-log/index.d.ts b/types/hexo-log/index.d.ts new file mode 100644 index 0000000000..bbd18bbb39 --- /dev/null +++ b/types/hexo-log/index.d.ts @@ -0,0 +1,162 @@ +// Type definitions for hexo-log 0.2 +// Project: http://hexo.io/ +// Definitions by: segayuu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import bunyan = require('hexo-bunyan'); +import streams = require('stream'); + +declare class HexoLogger extends bunyan { + /* tslint:disable:unified-signatures */ + + /** + * Returns a boolean: is the `debug` level enabled? + * + * This is equivalent to `log.isDebugEnabled()` or `log.isEnabledFor(DEBUG)` in log4j. + */ + d(): boolean; + + /** + * Special case to log an `Error` instance to the record. + * This adds an `err` field with exception details + * (including the stack) and sets `msg` to the exception + * message or you can specify the `msg`. + */ + d(error: Error, ...params: any[]): void; + + /** + * The first field can optionally be a "fields" object, which + * is merged into the log record. + * + * To pass in an Error *and* other fields, use the `err` + * field name for the Error instance. + */ + d(obj: object, ...params: any[]): void; + + /** + * Uses `util.format` for msg formatting. + */ + d(format: any, ...params: any[]): void; + + /** + * Returns a boolean: is the `info` level enabled? + * + * This is equivalent to `log.isInfoEnabled()` or `log.isEnabledFor(INFO)` in log4j. + */ + i(): boolean; + + /** + * Special case to log an `Error` instance to the record. + * This adds an `err` field with exception details + * (including the stack) and sets `msg` to the exception + * message or you can specify the `msg`. + */ + i(error: Error, ...params: any[]): void; + + /** + * The first field can optionally be a "fields" object, which + * is merged into the log record. + * + * To pass in an Error *and* other fields, use the `err` + * field name for the Error instance. + */ + i(obj: object, ...params: any[]): void; + + /** + * Uses `util.format` for msg formatting. + */ + i(format: any, ...params: any[]): void; + + /** + * Returns a boolean: is the `warn` level enabled? + * + * This is equivalent to `log.isWarnEnabled()` or `log.isEnabledFor(WARN)` in log4j. + */ + w(): boolean; + + /** + * Special case to log an `Error` instance to the record. + * This adds an `err` field with exception details + * (including the stack) and sets `msg` to the exception + * message or you can specify the `msg`. + */ + w(error: Error, ...params: any[]): void; + + /** + * The first field can optionally be a "fields" object, which + * is merged into the log record. + * + * To pass in an Error *and* other fields, use the `err` + * field name for the Error instance. + */ + w(obj: object, ...params: any[]): void; + + /** + * Uses `util.format` for msg formatting. + */ + w(format: any, ...params: any[]): void; + + /** + * Returns a boolean: is the `error` level enabled? + * + * This is equivalent to `log.isErrorEnabled()` or `log.isEnabledFor(ERROR)` in log4j. + */ + e(): boolean; + + /** + * Special case to log an `Error` instance to the record. + * This adds an `err` field with exception details + * (including the stack) and sets `msg` to the exception + * message or you can specify the `msg`. + */ + e(error: Error, ...params: any[]): void; + + /** + * The first field can optionally be a "fields" object, which + * is merged into the log record. + * + * To pass in an Error *and* other fields, use the `err` + * field name for the Error instance. + */ + e(obj: object, ...params: any[]): void; + + /** + * Uses `util.format` for msg formatting. + */ + e(format: any, ...params: any[]): void; + + /** + * Returns a boolean: is the `info` level enabled? + * + * This is equivalent to `log.isInfoEnabled()` or `log.isEnabledFor(INFO)` in log4j. + */ + log(): boolean; + + /** + * Special case to log an `Error` instance to the record. + * This adds an `err` field with exception details + * (including the stack) and sets `msg` to the exception + * message or you can specify the `msg`. + */ + log(error: Error, ...params: any[]): void; + + /** + * The first field can optionally be a "fields" object, which + * is merged into the log record. + * + * To pass in an Error *and* other fields, use the `err` + * field name for the Error instance. + */ + log(obj: object, ...params: any[]): void; + + /** + * Uses `util.format` for msg formatting. + */ + log(format: any, ...params: any[]): void; + + /* tslint:enable:unified-signatures */ +} + +declare function createLogger(options?: { name?: string; silent?: boolean; debug?: boolean; }): HexoLogger; + +export = createLogger; diff --git a/types/hexo-log/tsconfig.json b/types/hexo-log/tsconfig.json new file mode 100644 index 0000000000..88d5965c59 --- /dev/null +++ b/types/hexo-log/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "hexo-log-tests.ts" + ] +} diff --git a/types/hexo-log/tslint.json b/types/hexo-log/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hexo-log/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 232eb33c31f42f03855dfdeb737c8b2ed66dc713 Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 15 Sep 2017 10:08:18 +0900 Subject: [PATCH 4/6] TypeScript Version was added to dt-header. --- types/hexo-log/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/hexo-log/index.d.ts b/types/hexo-log/index.d.ts index bbd18bbb39..07a5b74ede 100644 --- a/types/hexo-log/index.d.ts +++ b/types/hexo-log/index.d.ts @@ -2,6 +2,7 @@ // Project: http://hexo.io/ // Definitions by: segayuu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 import bunyan = require('hexo-bunyan'); import streams = require('stream'); From 9594d8d85e91b7a95890f4579b9d8addaf99057d Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 15 Sep 2017 10:16:41 +0900 Subject: [PATCH 5/6] 2 soft tab to 4 soft tab. --- types/hexo-log/hexo-log-tests.ts | 142 +++++++++++++++---------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/types/hexo-log/hexo-log-tests.ts b/types/hexo-log/hexo-log-tests.ts index 9efa129cd8..15701eeed6 100644 --- a/types/hexo-log/hexo-log-tests.ts +++ b/types/hexo-log/hexo-log-tests.ts @@ -9,82 +9,82 @@ const _c = logger(); type HexoLogger = typeof _c; describe('hexo-log', () => { - const loggerModule = rewire<(options?: { name?: string; silent?: boolean; debug?: boolean; }) => HexoLogger>('./'); + const loggerModule = rewire<(options?: { name?: string; silent?: boolean; debug?: boolean; }) => HexoLogger>('./'); - it('add alias for levels', () => { - const log = logger(); + it('add alias for levels', () => { + const log = logger(); - log.d.should.eql(log.debug); - log.i.should.eql(log.info); - log.w.should.eql(log.warn); - log.e.should.eql(log.error); - log.log.should.eql(log.info); - }); - - it('default name is hexo', () => { - const log = logger(); - - log.fields.name.should.eql('hexo'); - }); - - it('options.name', () => { - const log = logger({ name: 'foo' }); - - log.fields.name.should.eql('foo'); - }); - - it('level should be trace if options.debug is true', () => { - const log: any = logger({ debug: true }); - - log.streams[0].level.should.eql(10); - }); - - it('should add file stream if options.debug is true', () => { - const log: any = logger({ debug: true }); - - log.streams[1].path.should.eql('debug.log'); - }); - - it('should remove console stream if options.silent is true', () => { - const log: any = logger({ silent: true }); - - log.streams.length.should.eql(0); - }); - - it('should display time if options.debug is true', () => { - const spy = sinon.spy(); - const now = new Date(); - - loggerModule.__with__({ - process: { - stdout: { - write: spy - } - } - })(() => { - sinon.useFakeTimers(now.valueOf()); - const log = loggerModule({ debug: true }); - log.info('test'); - sinon.restore(undefined); + log.d.should.eql(log.debug); + log.i.should.eql(log.info); + log.w.should.eql(log.warn); + log.e.should.eql(log.error); + log.log.should.eql(log.info); }); - spy.args[0][0].should.contain(now.toISOString().substring(11, 23)); - }); + it('default name is hexo', () => { + const log = logger(); - it('should print error to process.stderr stream', () => { - const spy = sinon.spy(); - - loggerModule.__with__({ - process: { - stderr: { - write: spy - } - } - })(() => { - const log = loggerModule(); - log.error('test'); + log.fields.name.should.eql('hexo'); }); - spy.calledOnce.should.be.true; - }); + it('options.name', () => { + const log = logger({ name: 'foo' }); + + log.fields.name.should.eql('foo'); + }); + + it('level should be trace if options.debug is true', () => { + const log: any = logger({ debug: true }); + + log.streams[0].level.should.eql(10); + }); + + it('should add file stream if options.debug is true', () => { + const log: any = logger({ debug: true }); + + log.streams[1].path.should.eql('debug.log'); + }); + + it('should remove console stream if options.silent is true', () => { + const log: any = logger({ silent: true }); + + log.streams.length.should.eql(0); + }); + + it('should display time if options.debug is true', () => { + const spy = sinon.spy(); + const now = new Date(); + + loggerModule.__with__({ + process: { + stdout: { + write: spy + } + } + })(() => { + sinon.useFakeTimers(now.valueOf()); + const log = loggerModule({ debug: true }); + log.info('test'); + sinon.restore(undefined); + }); + + spy.args[0][0].should.contain(now.toISOString().substring(11, 23)); + }); + + it('should print error to process.stderr stream', () => { + const spy = sinon.spy(); + + loggerModule.__with__({ + process: { + stderr: { + write: spy + } + } + })(() => { + const log = loggerModule(); + log.error('test'); + }); + + spy.calledOnce.should.be.true; + }); }); From 317cafc3f9c85fd98c17fcec067b1b796fe426eb Mon Sep 17 00:00:00 2001 From: segayuu Date: Fri, 15 Sep 2017 10:19:28 +0900 Subject: [PATCH 6/6] delete eslint comment. --- types/hexo-log/hexo-log-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/hexo-log/hexo-log-tests.ts b/types/hexo-log/hexo-log-tests.ts index 15701eeed6..9d0c263c03 100644 --- a/types/hexo-log/hexo-log-tests.ts +++ b/types/hexo-log/hexo-log-tests.ts @@ -1,6 +1,6 @@ import mocha = require('mocha'); import chai = require('chai'); -const should = chai.should(); // eslint-disable-line +const should = chai.should(); import rewire = require('rewire'); import sinon = require('sinon'); import logger = require('hexo-log');