From 37b91a63c7a8fa404a36e9c8ffa1dfd6b7f95a93 Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Mon, 27 Feb 2017 08:00:08 -0800 Subject: [PATCH] Fix flow errors Reviewed By: davidaurelio Differential Revision: D4619990 fbshipit-source-id: 80355b8f0d0c3f84691098a05cdf2ba136c4bf53 --- packager/src/Bundler/index.js | 5 +++-- packager/src/Logger/index.js | 5 +++-- packager/src/ModuleGraph/node-haste/Package.js | 3 ++- packager/src/Resolver/polyfills/require.js | 4 +++- packager/src/node-haste/Cache/index.js | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packager/src/Bundler/index.js b/packager/src/Bundler/index.js index cce95a303..126c3e79b 100644 --- a/packager/src/Bundler/index.js +++ b/packager/src/Bundler/index.js @@ -23,7 +23,6 @@ const HMRBundle = require('./HMRBundle'); const ModuleTransport = require('../lib/ModuleTransport'); const imageSize = require('image-size'); const path = require('path'); -const version = require('../../../package.json').version; const denodeify = require('denodeify'); const { @@ -34,6 +33,8 @@ const { extname, } = require('path'); +const VERSION = require('../../package.json').version; + import type AssetServer from '../AssetServer'; import type Module from '../node-haste/Module'; import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; @@ -129,7 +130,7 @@ class Bundler { const cacheKeyParts = [ 'react-packager-cache', - version, + VERSION, opts.cacheVersion, stableProjectRoots.join(',').split(pathSeparator).join('-'), transformModuleHash, diff --git a/packager/src/Logger/index.js b/packager/src/Logger/index.js index cb7ea774f..db53a1fca 100644 --- a/packager/src/Logger/index.js +++ b/packager/src/Logger/index.js @@ -12,10 +12,11 @@ 'use strict'; const os = require('os'); -const pkgjson = require('../../../package.json'); const {EventEmitter} = require('events'); +const VERSION = require('../../package.json').version; + import type { ActionLogEntryData, ActionStartLogEntry, @@ -35,7 +36,7 @@ function createEntry(data: LogEntry | string): LogEntry { return { ...logEntry, log_session, - packager_version: pkgjson.version, + packager_version: VERSION, }; } diff --git a/packager/src/ModuleGraph/node-haste/Package.js b/packager/src/ModuleGraph/node-haste/Package.js index ad328d7ab..9e982e149 100644 --- a/packager/src/ModuleGraph/node-haste/Package.js +++ b/packager/src/ModuleGraph/node-haste/Package.js @@ -11,6 +11,7 @@ 'use strict'; +const nullthrows = require('fbjs/lib/nullthrows'); const path = require('path'); import type {PackageData} from '../types.flow'; @@ -51,7 +52,7 @@ module.exports = class Package { } getName() { - return this.data.then(p => p.name); + return this.data.then(p => nullthrows(p.name)); } isHaste() { diff --git a/packager/src/Resolver/polyfills/require.js b/packager/src/Resolver/polyfills/require.js index acdc4a98e..447a47af3 100644 --- a/packager/src/Resolver/polyfills/require.js +++ b/packager/src/Resolver/polyfills/require.js @@ -10,7 +10,9 @@ * @flow */ -'use strict'; + 'use strict'; + +declare var __DEV__: boolean; type DependencyMap = Array; type Exports = any; diff --git a/packager/src/node-haste/Cache/index.js b/packager/src/node-haste/Cache/index.js index fb2a22898..64a7387dd 100644 --- a/packager/src/node-haste/Cache/index.js +++ b/packager/src/node-haste/Cache/index.js @@ -236,7 +236,7 @@ function loadCacheSync(cachePath) { } try { - return JSON.parse(fs.readFileSync(cachePath)); + return JSON.parse(fs.readFileSync(cachePath, 'utf8')); } catch (e) { if (e instanceof SyntaxError) { console.warn('Unable to parse cache file. Will clear and continue.');