From d730928b0c2e668bec68556500e93c81740a7c1a Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Wed, 2 Nov 2016 13:40:48 -0700 Subject: [PATCH] RN Package.js: @flow Reviewed By: davidaurelio Differential Revision: D4118006 fbshipit-source-id: ad8fdcb67351a9e53af0a7acbf16f269daf31f50 --- react-packager/src/node-haste/Package.js | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/react-packager/src/node-haste/Package.js b/react-packager/src/node-haste/Package.js index daeb1311..68baf060 100644 --- a/react-packager/src/node-haste/Package.js +++ b/react-packager/src/node-haste/Package.js @@ -5,6 +5,8 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow */ 'use strict'; @@ -12,9 +14,31 @@ const isAbsolutePath = require('absolute-path'); const path = require('path'); +import type { + Cache, + FastFs, +} from './Module'; + class Package { - constructor({ file, fastfs, cache }) { + path: string; + root: string; + _fastfs: FastFs; + type: string; + _cache: Cache; + + _reading: Promise<{ + name: string, + 'react-native': mixed, + browser: mixed, + main: ?string, + }>; + + constructor({ file, fastfs, cache }: { + file: string, + fastfs: FastFs, + cache: Cache, + }) { this.path = path.resolve(file); this.root = path.dirname(this.path); this._fastfs = fastfs; @@ -39,6 +63,7 @@ class Package { main; } + /* $FlowFixMe: `getReplacements` doesn't validate the return value. */ return path.join(this.root, main); }); } @@ -59,7 +84,7 @@ class Package { this._cache.invalidate(this.path); } - redirectRequire(name) { + redirectRequire(name: string) { return this.read().then(json => { var replacements = getReplacements(json); @@ -98,6 +123,7 @@ class Package { if (redirect) { return path.join( this.root, + /* $FlowFixMe: `getReplacements` doesn't validate the return value. */ redirect ); } @@ -128,10 +154,14 @@ function getReplacements(pkg) { } if (typeof rn === 'string') { + /* $FlowFixMe: It is likely unsafe to assume all packages would + * contain a "main" */ rn = { [pkg.main]: rn }; } if (typeof browser === 'string') { + /* $FlowFixMe: It is likely unsafe to assume all packages would + * contain a "main" */ browser = { [pkg.main]: browser }; }