From e0ea0aae1dce37479e143ea06b71b088746c90f2 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Wed, 28 Jun 2017 12:39:28 -0700 Subject: [PATCH] Codemod prettier to 1.5.2 Differential Revision: D5339725 fbshipit-source-id: 631338436a7d69b0ab0721507bdab4ae4e207065 --- .../metro-bundler/src/Bundler/HMRBundle.js | 3 +- .../src/Bundler/__tests__/Bundle-test.js | 12 ++-- .../ModuleGraph/worker/transform-module.js | 4 +- packages/metro-bundler/src/Server/index.js | 28 ++++---- .../metro-bundler/src/lib/TransformCaching.js | 12 ++-- .../node-haste/DependencyGraph/HasteMap.js | 72 +++++++++++-------- .../DependencyGraph/ResolutionRequest.js | 11 ++- .../metro-bundler/src/node-haste/Module.js | 3 +- .../src/node-haste/ModuleCache.js | 3 +- .../__tests__/DependencyGraph-test.js | 9 ++- .../src/node-haste/lib/AssetPaths.js | 14 ++-- 11 files changed, 95 insertions(+), 76 deletions(-) diff --git a/packages/metro-bundler/src/Bundler/HMRBundle.js b/packages/metro-bundler/src/Bundler/HMRBundle.js index db3b0ac3..077beef8 100644 --- a/packages/metro-bundler/src/Bundler/HMRBundle.js +++ b/packages/metro-bundler/src/Bundler/HMRBundle.js @@ -16,8 +16,7 @@ const BundleBase = require('./BundleBase'); const ModuleTransport = require('../lib/ModuleTransport'); import type Resolver from '../Resolver'; -import type ResolutionResponse - from '../node-haste/DependencyGraph/ResolutionResponse'; +import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; import type Module from '../node-haste/Module'; class HMRBundle extends BundleBase { diff --git a/packages/metro-bundler/src/Bundler/__tests__/Bundle-test.js b/packages/metro-bundler/src/Bundler/__tests__/Bundle-test.js index 9ae64913..85b7f746 100644 --- a/packages/metro-bundler/src/Bundler/__tests__/Bundle-test.js +++ b/packages/metro-bundler/src/Bundler/__tests__/Bundle-test.js @@ -49,7 +49,7 @@ describe('Bundle', () => { [ 'transformed foo;', 'transformed bar;', - '\/\/# sourceMappingURL=test_url', + '//# sourceMappingURL=test_url', ].join('\n'), ); }); @@ -112,7 +112,7 @@ describe('Bundle', () => { 'transformed bar;', ';require("bar");', ';require("foo");', - '\/\/# sourceMappingURL=test_url', + '//# sourceMappingURL=test_url', ].join('\n'), ); }); @@ -376,8 +376,12 @@ describe('Bundle', () => { const {groups} = bundle.getUnbundle(); //eslint-disable-line no-unused-vars }).toThrow( new Error( - `Module ${fsLocation('invariant')} belongs to groups ${fsLocation('React')}` + - `, and ${fsLocation('OtherFramework')}. Ensure that each module is only part of one group.`, + `Module ${fsLocation('invariant')} belongs to groups ${fsLocation( + 'React', + )}` + + `, and ${fsLocation( + 'OtherFramework', + )}. Ensure that each module is only part of one group.`, ), ); }); diff --git a/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js b/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js index ccf06956..c0ff1ae8 100644 --- a/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js +++ b/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js @@ -119,7 +119,9 @@ function transformModule( function transformJSON(json, options, callback) { const value = JSON.parse(json); const {filename} = options; - const code = `__d(function(${JsFileWrapping.MODULE_FACTORY_PARAMETERS.join(', ')}) { module.exports = \n${json}\n});`; + const code = `__d(function(${JsFileWrapping.MODULE_FACTORY_PARAMETERS.join( + ', ', + )}) { module.exports = \n${json}\n});`; const moduleData = { code, diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index 18948dc5..711a051d 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -28,8 +28,7 @@ const url = require('url'); import type Module, {HasteImpl} from '../node-haste/Module'; import type {IncomingMessage, ServerResponse} from 'http'; -import type ResolutionResponse - from '../node-haste/DependencyGraph/ResolutionResponse'; +import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; import type Bundle from '../Bundler/Bundle'; import type HMRBundle from '../Bundler/HMRBundle'; import type {Reporter} from '../lib/reporting'; @@ -176,9 +175,8 @@ class Server { globalTransformCache: options.globalTransformCache, hasteImpl: options.hasteImpl, maxWorkers, - moduleFormat: options.moduleFormat != null - ? options.moduleFormat - : 'haste', + moduleFormat: + options.moduleFormat != null ? options.moduleFormat : 'haste', platforms: options.platforms || defaults.platforms, polyfillModuleNames: options.polyfillModuleNames || [], postProcessModules: options.postProcessModules, @@ -314,9 +312,10 @@ class Server { getShallowDependencies(options: DependencyOptions): Promise> { return Promise.resolve().then(() => { - const platform = options.platform != null - ? options.platform - : parsePlatformFilePath(options.entryFile, this._platforms).platform; + const platform = + options.platform != null + ? options.platform + : parsePlatformFilePath(options.entryFile, this._platforms).platform; const {entryFile, dev, minify, hot} = options; return this._bundler.getShallowDependencies({ entryFile, @@ -337,9 +336,10 @@ class Server { options: DependencyOptions, ): Promise> { return Promise.resolve().then(() => { - const platform = options.platform != null - ? options.platform - : parsePlatformFilePath(options.entryFile, this._platforms).platform; + const platform = + options.platform != null + ? options.platform + : parsePlatformFilePath(options.entryFile, this._platforms).platform; const {entryFile, dev, minify, hot} = options; return this._bundler.getDependencies({ entryFile, @@ -911,7 +911,8 @@ class Server { res.end( JSON.stringify({ type: 'InternalError', - message: 'react-packager has encountered an internal error, ' + + message: + 'react-packager has encountered an internal error, ' + 'please check your terminal error output for more details', }), ); @@ -985,7 +986,8 @@ class Server { 'entryModuleOnly', false, ), - generateSourceMaps: minify || + generateSourceMaps: + minify || !dev || this._getBoolOptionFromQuery(urlObj.query, 'babelSourcemap', false), assetPlugins, diff --git a/packages/metro-bundler/src/lib/TransformCaching.js b/packages/metro-bundler/src/lib/TransformCaching.js index 4dbdebde..6fd6ffd4 100644 --- a/packages/metro-bundler/src/lib/TransformCaching.js +++ b/packages/metro-bundler/src/lib/TransformCaching.js @@ -352,10 +352,14 @@ function readMetadataFileSync( if ( typeof cachedResultHash !== 'string' || typeof cachedSourceHash !== 'string' || - !(Array.isArray(dependencies) && - dependencies.every(dep => typeof dep === 'string')) || - !(Array.isArray(dependencyOffsets) && - dependencyOffsets.every(offset => typeof offset === 'number')) || + !( + Array.isArray(dependencies) && + dependencies.every(dep => typeof dep === 'string') + ) || + !( + Array.isArray(dependencyOffsets) && + dependencyOffsets.every(offset => typeof offset === 'number') + ) || !(sourceMap == null || typeof sourceMap === 'object') ) { return null; diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph/HasteMap.js b/packages/metro-bundler/src/node-haste/DependencyGraph/HasteMap.js index df9e021c..45595f94 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/HasteMap.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/HasteMap.js @@ -1,4 +1,4 @@ - /** +/** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * @@ -35,7 +35,6 @@ type Options = {| |}; class HasteMap extends EventEmitter { - _extensions: Array; _files: Array; _helpers: DependencyGraphHelpers; @@ -61,8 +60,14 @@ class HasteMap extends EventEmitter { this._platforms = platforms; this._preferNativePlatform = preferNativePlatform; - (this: any)._processHastePackage = throat(1, this._processHastePackage.bind(this)); - (this: any)._processHasteModule = throat(1, this._processHasteModule.bind(this)); + (this: any)._processHastePackage = throat( + 1, + this._processHastePackage.bind(this), + ); + (this: any)._processHasteModule = throat( + 1, + this._processHasteModule.bind(this), + ); } build() { @@ -111,7 +116,10 @@ class HasteMap extends EventEmitter { } } - if (type !== 'delete' && this._extensions.indexOf(this._helpers.extname(absPath)) !== -1) { + if ( + type !== 'delete' && + this._extensions.indexOf(this._helpers.extname(absPath)) !== -1 + ) { if (path.basename(absPath) === 'package.json') { return this._processHastePackage(absPath, invalidated); } else { @@ -151,36 +159,42 @@ class HasteMap extends EventEmitter { const module = this._moduleCache.getModule(file); return Promise.resolve().then(() => { const isHaste = module.isHaste(); - return isHaste && module.getName() - .then(name => { + return ( + isHaste && + module.getName().then(name => { const result = this._updateHasteMap(name, module); if (previousName && name !== previousName) { this.emit('change'); } return result; - }); + }) + ); }); } _processHastePackage(file: string, previousName: ?string) { const p = this._moduleCache.getPackage(file); - return Promise.resolve().then(() => { - const isHaste = p.isHaste(); - return isHaste && p.getName() - .then(name => { - const result = this._updateHasteMap(name, p); - if (previousName && name !== previousName) { - this.emit('change'); - } - return result; - }); - }).catch(e => { - if (e instanceof SyntaxError) { - // Malformed package.json. - return; - } - throw e; - }); + return Promise.resolve() + .then(() => { + const isHaste = p.isHaste(); + return ( + isHaste && + p.getName().then(name => { + const result = this._updateHasteMap(name, p); + if (previousName && name !== previousName) { + this.emit('change'); + } + return result; + }) + ); + }) + .catch(e => { + if (e instanceof SyntaxError) { + // Malformed package.json. + return; + } + throw e; + }); } _updateHasteMap(name: string, mod: TModule | TPackage) { @@ -204,10 +218,10 @@ class HasteMap extends EventEmitter { if (existingModule && existingModule.path !== mod.path) { throw new Error( `@providesModule naming collision:\n` + - ` Duplicate module name: ${name}\n` + - ` Paths: ${mod.path} collides with ${existingModule.path}\n\n` + - 'This error is caused by a @providesModule declaration ' + - 'with the same name across two different files.' + ` Duplicate module name: ${name}\n` + + ` Paths: ${mod.path} collides with ${existingModule.path}\n\n` + + 'This error is caused by a @providesModule declaration ' + + 'with the same name across two different files.', ); } } diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js index 3b7e3e6e..d132b7d9 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/ResolutionRequest.js @@ -22,9 +22,7 @@ const path = require('path'); import type DependencyGraphHelpers from './DependencyGraphHelpers'; import type ResolutionResponse from './ResolutionResponse'; -import type { - Options as TransformWorkerOptions, -} from '../../JSTransformer/worker'; +import type {Options as TransformWorkerOptions} from '../../JSTransformer/worker'; import type {ReadResult, CachedReadResult} from '../Module'; import type {ModuleResolver} from './ModuleResolution'; @@ -310,9 +308,10 @@ class ResolutionRequest { * not obsolete, and required from somewhere */ }); } - const dependencies = cached.result != null - ? cached.result.dependencies - : cached.outdatedDependencies; + const dependencies = + cached.result != null + ? cached.result.dependencies + : cached.outdatedDependencies; return this.tryResolveModuleDependencies( module, dependencies, diff --git a/packages/metro-bundler/src/node-haste/Module.js b/packages/metro-bundler/src/node-haste/Module.js index 1103ac75..b4722e7a 100644 --- a/packages/metro-bundler/src/node-haste/Module.js +++ b/packages/metro-bundler/src/node-haste/Module.js @@ -33,8 +33,7 @@ import type { ReadTransformProps, } from '../lib/TransformCaching'; import type {Reporter} from '../lib/reporting'; -import type DependencyGraphHelpers - from './DependencyGraph/DependencyGraphHelpers'; +import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers'; import type ModuleCache from './ModuleCache'; import type {LocalPath} from './lib/toLocalPath'; diff --git a/packages/metro-bundler/src/node-haste/ModuleCache.js b/packages/metro-bundler/src/node-haste/ModuleCache.js index 7d94509e..cc99b13b 100644 --- a/packages/metro-bundler/src/node-haste/ModuleCache.js +++ b/packages/metro-bundler/src/node-haste/ModuleCache.js @@ -22,8 +22,7 @@ const toLocalPath = require('./lib/toLocalPath'); import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; import type {GetTransformCacheKey} from '../lib/TransformCaching'; import type {Reporter} from '../lib/reporting'; -import type DependencyGraphHelpers - from './DependencyGraph/DependencyGraphHelpers'; +import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers'; import type {TransformCode, Options as ModuleOptions} from './Module'; type GetClosestPackageFn = (filePath: string) => ?string; diff --git a/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js b/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js index fac0e9c4..e593e3d3 100644 --- a/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js +++ b/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js @@ -2247,7 +2247,8 @@ describe('DependencyGraph', function() { 'node-package-c': 'rn-package-c', }, }), - 'index.js': 'require("node-package-a"); require("node-package-b"); require("node-package-c");', + 'index.js': + 'require("node-package-a"); require("node-package-b"); require("node-package-c");', node_modules: { 'node-package-a': { 'package.json': JSON.stringify({ @@ -3256,7 +3257,8 @@ describe('DependencyGraph', function() { }, { id: 'submodule/main.js', - path: '/root/node_modules/react-haste/node_modules/submodule/main.js', + path: + '/root/node_modules/react-haste/node_modules/submodule/main.js', dependencies: [], isAsset: false, isJSON: false, @@ -4238,7 +4240,8 @@ describe('DependencyGraph', function() { }, { id: 'submodule/main.js', - path: 'C:\\root\\node_modules\\react-haste\\node_modules\\submodule\\main.js', + path: + 'C:\\root\\node_modules\\react-haste\\node_modules\\submodule\\main.js', dependencies: [], isAsset: false, isJSON: false, diff --git a/packages/metro-bundler/src/node-haste/lib/AssetPaths.js b/packages/metro-bundler/src/node-haste/lib/AssetPaths.js index 35083431..f7bb167c 100644 --- a/packages/metro-bundler/src/node-haste/lib/AssetPaths.js +++ b/packages/metro-bundler/src/node-haste/lib/AssetPaths.js @@ -1,4 +1,4 @@ - /** +/** * Copyright (c) 2015-present, Facebook, Inc. * All rights reserved. * @@ -47,10 +47,7 @@ function parseBaseName( * Return `null` if the `filePath` doesn't have a valid extension, required * to describe the type of an asset. */ -function tryParse( - filePath: string, - platforms: Set, -): ?AssetData { +function tryParse(filePath: string, platforms: Set): ?AssetData { const result = parsePlatformFilePath(filePath, platforms); const {dirPath, baseName, platform, extension} = result; if (extension == null) { @@ -66,13 +63,10 @@ function tryParse( }; } -function parse( - filePath: string, - platforms: Set, -): AssetData { +function parse(filePath: string, platforms: Set): AssetData { const result = tryParse(filePath, platforms); if (result == null) { - throw new Error('invalid asset file path: \`${filePath}'); + throw new Error('invalid asset file path: `${filePath}'); } return result; }