Skip to content

Commit

Permalink
Upgrade to [email protected] / fix some typings (#2307)
Browse files Browse the repository at this point in the history
* Adds inquirer libdefs for more exact typings
* Refine / Fix some flowtype errors (mostly in __tests__)
* Fix a small bug in src/util/map.js found by [email protected]
  • Loading branch information
ryyppy authored and bestander committed Jan 3, 2017
1 parent cbf19f6 commit 867cf4f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
unsafe.enable_getters_and_setters=true

[version]
0.33.0
^0.37
8 changes: 7 additions & 1 deletion __tests__/__mocks__/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import type {ClientRequest} from 'http';
import type {ReadStream} from 'fs';

const realRequest = require.requireActual('request');
// TODO: create flow-typed libdefs for the 'request' module
// for now this will do its job
type RequestModule = {
Request: any,
};

const realRequest: RequestModule = (require: any).requireActual('request');
const RealRequest = realRequest.Request;

const mkdirp = require('mkdirp');
Expand Down
4 changes: 2 additions & 2 deletions __tests__/normalize-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for (const name of nativeFs.readdirSync(fixturesLoc)) {

const reporter = new NoopReporter();

// $FlowFixMe: investigate
// $FlowFixMe: Investigate
reporter.warn = function(msg) {
actualWarnings.push(msg);
};
Expand Down Expand Up @@ -101,7 +101,7 @@ test('util.extractRepositoryUrl', () => {
});

// fill out expected and normalize paths
function expand<T>(expected: T): T {
function expand<T: Object>(expected: T): T {
if (expected.man && Array.isArray(expected.man)) {
expected = {...expected, man: normalizePaths(expected.man)};
}
Expand Down
81 changes: 81 additions & 0 deletions flow-typed/npm/inquirer_v2.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// flow-typed signature: df3baa8dc9948e006e9b73243d290c89
// flow-typed version: 25ed2d5c85/inquirer_v2.x.x/flow_>=v0.25.x

// FIXME(ryyppy): Add Observable stuff
// -> https://github.com/SBoudrias/Inquirer.js/#reactive-interface
// Currently, if you are using Observables, you need to : any suffix
// the questions input for now

declare module 'inquirer' {
declare class BottomBar {
log: stream$Writable;
updateBottomBar(input: mixed): void;
}

declare type SessionT = any;

declare type AnswersT = {
[key: string]: ?boolean | ?string | ?{
confirm?: boolean,
input?: string,
rawList?: string,
list?: string,
}
};

declare class Separator {
constructor(sep ?: string): void;
}

declare type ChoiceT = string | Separator | {
name: string,
value?: string,
short?: string,
};

declare type QuestionKindT =
'input'
| 'confirm'
| 'list'
| 'rawlist'
| 'expand'
| 'checkbox'
| 'password'
| 'editor';

declare type DefaultValueT = string | number | Array<string|number>;

declare type BasicT = string | number | boolean;

declare type QuestionT = {
type: QuestionKindT,
name: string,
message: string | (a: AnswersT) => void,
default?: mixed | (a: AnswersT) => mixed,
choices?: Array<ChoiceT>,

// true => okay
// false => general error message
// string => specific error message
validate?: (input: string | Array<string>) => (boolean | string),
filter?: (input: string) => BasicT | Promise<BasicT>,
when?: boolean | (answers: AnswersT) => (boolean | Promise<boolean>),
pageSize?: number,
};

declare interface Prompt extends Promise<AnswersT> {
ui: {
process: any, // For observable interface
},
}

declare type PromptFn = (questions: QuestionT | Array<QuestionT>) => Prompt;

declare module.exports: {
Separator: typeof Separator,
prompt: PromptFn,
ui: {
BottomBar: typeof BottomBar,
},
};
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"defaults": "^1.0.3",
"detect-indent": "^4.0.0",
"diff": "^2.2.1",
"flow-bin": "^0.37.3",
"ini": "^1.3.4",
"inquirer": "^1.2.2",
"invariant": "^2.2.0",
Expand Down Expand Up @@ -64,7 +65,7 @@
"eslint-plugin-no-async-without-await": "^1.0.0",
"eslint-plugin-react": "5.2.2",
"eslint-plugin-yarn-internal": "file:scripts/eslint-rules",
"flow-bin": "0.33.0",
"flow-bin": "^0.37.3",
"gulp": "^3.9.0",
"gulp-babel": "^6.0.0",
"gulp-if": "^2.0.1",
Expand Down
8 changes: 6 additions & 2 deletions src/util/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ export default function nullify<T>(obj?: Return<T> = {}): Return<T> {
}
} else if (obj !== null && typeof obj === 'object' || typeof obj === 'function') {
Object.setPrototypeOf(obj, null);
for (const key in obj) {
nullify(obj[key]);

// for..in can only be applied to 'object', not 'function'
if (typeof obj === 'object') {
for (const key in obj) {
nullify(obj[key]);
}
}
}

Expand Down
9 changes: 4 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


abab@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d"
Expand Down Expand Up @@ -2213,9 +2211,9 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

flow-bin@0.33.0:
version "0.33.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.33.0.tgz#ef011eace7a6100f1ae08b852db78279032b8750"
flow-bin:
version "0.37.3"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.37.3.tgz#68e5841606a2be6929793ec9c4ce08b2ea39d7c2"

for-in@^0.1.5:
version "0.1.6"
Expand Down Expand Up @@ -5520,3 +5518,4 @@ yargs@~3.27.0:
os-locale "^1.4.0"
window-size "^0.1.2"
y18n "^3.2.0"

0 comments on commit 867cf4f

Please sign in to comment.