From a3237f641ee8d9fdc5eb077eb6c30d111bb9f598 Mon Sep 17 00:00:00 2001 From: Gabe Levi Date: Thu, 18 May 2017 16:51:37 -0700 Subject: [PATCH] Fix react-native function call arity errors Reviewed By: zertosh Differential Revision: D5081816 fbshipit-source-id: 5978770c30a69fb287d03aa7511999ce30f856a1 --- packages/metro-bundler/src/Bundler/index.js | 17 ++++--- .../metro-bundler/src/JSTransformer/index.js | 6 +-- .../metro-bundler/src/ModuleGraph/Graph.js | 6 +-- packages/metro-bundler/src/Server/index.js | 10 ++-- .../metro-bundler/src/lib/TransformCache.js | 46 +++++++++++-------- .../src/node-haste/DependencyGraph.js | 8 ++-- 6 files changed, 49 insertions(+), 44 deletions(-) diff --git a/packages/metro-bundler/src/Bundler/index.js b/packages/metro-bundler/src/Bundler/index.js index 38cf5ac0..b4e57d04 100644 --- a/packages/metro-bundler/src/Bundler/index.js +++ b/packages/metro-bundler/src/Bundler/index.js @@ -14,6 +14,7 @@ const assert = require('assert'); const crypto = require('crypto'); const debug = require('debug')('RNP:Bundler'); +const emptyFunction = require('fbjs/lib/emptyFunction'); const fs = require('fs'); const Transformer = require('../JSTransformer'); const Resolver = require('../Resolver'); @@ -89,8 +90,6 @@ export type ExtendedAssetDescriptor = AssetDescriptor & { const sizeOf = denodeify(imageSize); -const noop = () => {}; - const { createActionStartEntry, createActionEndEntry, @@ -173,7 +172,7 @@ class Bundler { this._getModuleId = createModuleIdFactory(); - let getCacheKey = () => ''; + let getCacheKey = (options: mixed) => ''; if (opts.transformModulePath) { /* $FlowFixMe: dynamic requires prevent static typing :'( */ const transformer = require(opts.transformModulePath); @@ -283,7 +282,7 @@ class Bundler { const matchingRoot = this._projectRoots.find(root => filePath.startsWith(root)); if (!matchingRoot) { - throw new Error('No matching project root for ', filePath); + throw new Error('No matching project root for ' + filePath); } // Replaces '\' with '/' for Windows paths. @@ -422,10 +421,10 @@ class Bundler { isolateModuleIDs, generateSourceMaps, assetPlugins, - onResolutionResponse = noop, - onModuleTransformed = noop, - finalizeBundle = noop, - onProgress = noop, + onResolutionResponse = emptyFunction, + onModuleTransformed = emptyFunction, + finalizeBundle = emptyFunction, + onProgress = emptyFunction, }: *) { const transformingFilesLogEntry = log(createActionStartEntry({ @@ -641,7 +640,7 @@ class Bundler { bundle: Bundle, entryFilePath: string, options: BundlingOptions, - getModuleId: () => number, + getModuleId: (module: Module) => number, dependencyPairs: Array<[string, Module]>, assetPlugins: Array, }): Promise { diff --git a/packages/metro-bundler/src/JSTransformer/index.js b/packages/metro-bundler/src/JSTransformer/index.js index 7b23fd1f..66a96b8f 100644 --- a/packages/metro-bundler/src/JSTransformer/index.js +++ b/packages/metro-bundler/src/JSTransformer/index.js @@ -166,11 +166,11 @@ function TransformError() { } util.inherits(TransformError, SyntaxError); -function formatError(err, filename, source) { +function formatError(err, filename) { if (err.loc) { - return formatBabelError(err, filename, source); + return formatBabelError(err, filename); } else { - return formatGenericError(err, filename, source); + return formatGenericError(err, filename); } } diff --git a/packages/metro-bundler/src/ModuleGraph/Graph.js b/packages/metro-bundler/src/ModuleGraph/Graph.js index e8079139..4e5236a0 100644 --- a/packages/metro-bundler/src/ModuleGraph/Graph.js +++ b/packages/metro-bundler/src/ModuleGraph/Graph.js @@ -10,6 +10,7 @@ */ 'use strict'; +const emptyFunction = require('fbjs/lib/emptyFunction'); const invariant = require('fbjs/lib/invariant'); const memoize = require('async/memoize'); const nullthrows = require('fbjs/lib/nullthrows'); @@ -51,11 +52,10 @@ type LoadQueue = const createParentModule = () => ({file: {code: '', type: 'script', path: ''}, dependencies: []}); -const noop = () => {}; const NO_OPTIONS = {}; exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn { - function Graph(entryPoints, platform, options, callback = noop) { + function Graph(entryPoints, platform, options, callback = emptyFunction) { const { log = (console: any), optimize = false, @@ -80,7 +80,7 @@ exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn { callback(null, collect()); }; loadQueue.error = error => { - loadQueue.error = noop; + loadQueue.error = emptyFunction; loadQueue.kill(); callback(error); }; diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index fae8323b..db2d10b8 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -16,6 +16,7 @@ const Bundler = require('../Bundler'); const MultipartResponse = require('./MultipartResponse'); const defaults = require('../../defaults'); +const emptyFunction = require('fbjs/lib/emptyFunction'); const mime = require('mime-types'); const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath'); const path = require('path'); @@ -26,7 +27,6 @@ const url = require('url'); const debug = require('debug')('RNP:Server'); import type Module, {HasteImpl} from '../node-haste/Module'; -import type {Stats} from 'fs'; import type {IncomingMessage, ServerResponse} from 'http'; import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; import type Bundle from '../Bundler/Bundle'; @@ -175,7 +175,7 @@ class Server { watch: options.watch || false, }; const processFileChange = - ({type, filePath, stat}) => this.onFileChange(type, filePath, stat); + ({type, filePath}) => this.onFileChange(type, filePath); this._reporter = options.reporter; this._projectRoots = this._opts.projectRoots; @@ -316,8 +316,8 @@ class Server { }); } - onFileChange(type: string, filePath: string, stat: Stats) { - this._assetServer.onFileChange(type, filePath, stat); + onFileChange(type: string, filePath: string) { + this._assetServer.onFileChange(type, filePath); // If Hot Loading is enabled avoid rebuilding bundles and sending live // updates. Instead, send the HMR updates right away and clear the bundles @@ -653,7 +653,7 @@ class Server { entry_point: options.entryFile, })); - let reportProgress = () => {}; + let reportProgress = emptyFunction; if (!this._opts.silent) { reportProgress = (transformedFileCount, totalFileCount) => { this._reporter.update({ diff --git a/packages/metro-bundler/src/lib/TransformCache.js b/packages/metro-bundler/src/lib/TransformCache.js index eb98342a..d32189b8 100644 --- a/packages/metro-bundler/src/lib/TransformCache.js +++ b/packages/metro-bundler/src/lib/TransformCache.js @@ -90,14 +90,16 @@ class TransformCache { * close to each others, one of the workers is going to loose its results no * matter what. */ - writeSync(props: { - filePath: string, - sourceCode: string, - getTransformCacheKey: GetTransformCacheKey, - transformOptions: WorkerOptions, - transformOptionsKey: string, - result: CachedResult, - }): void { + writeSync( + props: { + filePath: string, + sourceCode: string, + getTransformCacheKey: GetTransformCacheKey, + transformOptions: WorkerOptions, + transformOptionsKey: string, + result: CachedResult, + }, + ): void { const cacheFilePath = this._getCacheFilePaths(props); mkdirp.sync(path.dirname(cacheFilePath.transformedCode)); const {result} = props; @@ -233,7 +235,7 @@ class TransformCache { mkdirp.sync(cacheDirPath); const cacheCollectionFilePath = path.join(cacheDirPath, 'last_collected'); const lastCollected = Number.parseInt( - tryReadFileSync(cacheCollectionFilePath, 'utf8'), + tryReadFileSync(cacheCollectionFilePath), 10, ); if ( @@ -253,10 +255,12 @@ class TransformCache { * account because it would generate lots of file during development. (The * source hash is stored in the metadata instead). */ - _getCacheFilePaths(props: { - filePath: string, - transformOptionsKey: string, - }): CacheFilePaths { + _getCacheFilePaths( + props: { + filePath: string, + transformOptionsKey: string, + }, + ): CacheFilePaths { const hasher = crypto .createHash('sha1') .update(props.filePath) @@ -384,13 +388,15 @@ function tryParseJSON(str: string): any { } } -function hashSourceCode(props: { - filePath: string, - sourceCode: string, - getTransformCacheKey: GetTransformCacheKey, - transformOptions: WorkerOptions, - transformOptionsKey: string, -}): string { +function hashSourceCode( + props: { + filePath: string, + sourceCode: string, + getTransformCacheKey: GetTransformCacheKey, + transformOptions: WorkerOptions, + transformOptionsKey: string, + }, +): string { return crypto .createHash('sha1') .update(props.getTransformCacheKey(props.transformOptions)) diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph.js b/packages/metro-bundler/src/node-haste/DependencyGraph.js index 7516bc8f..ff049c98 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph.js @@ -156,8 +156,8 @@ class DependencyGraph extends EventEmitter { this._filesByDirNameIndex = new FilesByDirNameIndex(hasteFS.getAllFiles()); this._assetResolutionCache.clear(); this._moduleMap = moduleMap; - eventsQueue.forEach(({type, filePath, stat}) => - this._moduleCache.processFileChange(type, filePath, stat) + eventsQueue.forEach(({type, filePath}) => + this._moduleCache.processFileChange(type, filePath) ); this.emit('change'); } @@ -290,11 +290,11 @@ class DependencyGraph extends EventEmitter { } -function NotFoundError() { +function NotFoundError(...args) { /* $FlowFixMe: monkey-patching */ Error.call(this); Error.captureStackTrace(this, this.constructor); - var msg = util.format.apply(util, arguments); + var msg = util.format.apply(util, args); this.message = msg; this.type = this.name = 'NotFoundError'; this.status = 404;