Skip to content

Commit

Permalink
refactor: improve third party type declarations (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba authored Aug 7, 2016
1 parent 5de7a0d commit 241ae89
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 28 deletions.
32 changes: 28 additions & 4 deletions decl/chalk.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
// @flow
declare module 'chalk' {
declare function blue(source: string): string;
declare function cyan(source: string): string;
// Styles
declare function reset(source: string): string;
declare function bold(source: string): string;
declare function dim(source: string): string;
declare function green(source: string): string;
declare function magenta(source: string): string;
declare function italic(source: string): string;
declare function underline(source: string): string;
declare function inverse(source: string): string;
declare function hidden(source: string): string;
declare function strikethrough(source: string): string;
declare function black(source: string): string;
declare function red(source: string): string;
declare function green(source: string): string;
declare function yellow(source: string): string;
declare function blue(source: string): string;
declare function magenta(source: string): string;
declare function cyan(source: string): string;
declare function white(source: string): string;
declare function gray(source: string): string;
declare function grey(source: string): string;
declare function bgBlack(source: string): string;
declare function bgRed(source: string): string;
declare function bgGreen(source: string): string;
declare function bgYellow(source: string): string;
declare function bgBlue(source: string): string;
declare function bgMagenta(source: string): string;
declare function bgCyan(source: string): string;
declare function bgWhit(source: string): string;

// Utils
declare function hasColor(source: string): boolean;
declare function stripColor(source: string): string;
}
2 changes: 1 addition & 1 deletion decl/cluster.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import { EventEmitter } from 'events';
import EventEmitter from 'events';

declare module 'cluster' {
declare class Worker extends EventEmitter {
Expand Down
21 changes: 9 additions & 12 deletions decl/events.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// @flow
declare module 'events' {
declare class EventEmitter {
static listenerCount(emitter: EventEmitter, event: string): number;

addListener(event: string, listener: Function): EventEmitter;
emit(event: string, ...args:Array<any>): boolean;
listeners(event: string): Array<Function>;
listenerCount(event: string): number;
on(event: string, listener: Function): EventEmitter;
once(event: string, listener: Function): EventEmitter;
removeAllListeners(event?: string): EventEmitter;
removeListener(event: string, listener: Function): EventEmitter;
setMaxListeners(n: number): void;
/**
* NOTE: This is a temporary fix until the following facebook/flow PR is merged
* https://github.com/facebook/flow/pull/2201
*/
declare module 'events' {
declare class EventEmitter extends events$EventEmitter {
static EventEmitter: typeof EventEmitter;
}

declare var exports: typeof EventEmitter;
}
26 changes: 21 additions & 5 deletions decl/inflection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
// @flow
declare module 'inflection' {
declare function camelize(source: string, lower: boolean): string;
declare function classify(source: string): string;
declare function indexOf<T: Object>(
arr: Array<T>,
item: T,
fromIndex?: number,
compareFunc?: Function
): string;

declare function pluralize(source: string, plural?: string): string;
declare function singularize(source: string, singular?: string): string;
declare function inflect(source: string): string;
declare function camelize(source: string, lowerFirst?: boolean): string;
declare function underscore(source: string, allUpperCase?: boolean): string;
declare function humanize(source: string, lowerFirst?: boolean): string;
declare function capitalize(source: string): string;
declare function dasherize(source: string): string;
declare function pluralize(source: string): string;
declare function singularize(source: string): string;
declare function underscore(source: string, upper: boolean): string;
declare function titleize(source: string): string;
declare function demodulize(source: string): string;
declare function tableize(source: string): string;
declare function classify(source: string): string;
declare function foreign_key(source: string, lowerFirst?: boolean): string;
declare function ordinalize(source: string): string;
declare function transform(source: string, transforms: Array<string>): string;
}
4 changes: 1 addition & 3 deletions src/packages/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import createManifest from './utils/create-manifest';
import createBootScript from './utils/create-boot-script';
import { default as onwarn } from './utils/handle-warning';

import type { Bundle } from 'rollup';

/**
* @private
*/
Expand Down Expand Up @@ -75,7 +73,7 @@ export async function compile(dir: string, env: string, {
})
]);

const bundle: Bundle = await rollup({
const bundle = await rollup({
entry,
onwarn,
external,
Expand Down
4 changes: 2 additions & 2 deletions src/packages/pm/cluster/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import EventEmitter from 'events';
import os from 'os';
import cluster from 'cluster';
import { EventEmitter } from 'events';
import { join as joinPath } from 'path';
import { red, green } from 'chalk';

Expand Down Expand Up @@ -148,7 +148,7 @@ class Cluster extends EventEmitter {
});
}

shutdown(worker: Worker): Promise<Object> {
shutdown(worker: Worker): Promise<Worker> {
return new Promise(resolve => {
this.workers.delete(worker);

Expand Down
2 changes: 1 addition & 1 deletion src/packages/watcher/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import EventEmitter from 'events';
import { Client } from 'fb-watchman';
import { FSWatcher } from 'fs';
import { EventEmitter } from 'events';

import initialize from './initialize';

Expand Down

0 comments on commit 241ae89

Please sign in to comment.