Codemod prettier to 1.5.2

Differential Revision: D5339725

fbshipit-source-id: 631338436a7d69b0ab0721507bdab4ae4e207065
This commit is contained in:
Christopher Chedeau 2017-06-28 12:39:28 -07:00 committed by Facebook Github Bot
parent 138ae9623c
commit e0ea0aae1d
11 changed files with 95 additions and 76 deletions

View File

@ -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 {

View File

@ -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.`,
),
);
});

View File

@ -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,

View File

@ -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<Array<Module>> {
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<ResolutionResponse<Module, *>> {
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,

View File

@ -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;

View File

@ -1,4 +1,4 @@
/**
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
@ -35,7 +35,6 @@ type Options<TModule, TPackage> = {|
|};
class HasteMap<TModule: Moduleish, TPackage: Packageish> extends EventEmitter {
_extensions: Array<string>;
_files: Array<string>;
_helpers: DependencyGraphHelpers;
@ -61,8 +60,14 @@ class HasteMap<TModule: Moduleish, TPackage: Packageish> 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<TModule: Moduleish, TPackage: Packageish> 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<TModule: Moduleish, TPackage: Packageish> 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<TModule: Moduleish, TPackage: Packageish> 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.',
);
}
}

View File

@ -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<TModule: Moduleish, TPackage: Packageish> {
* 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,

View File

@ -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';

View File

@ -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;

View File

@ -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,

View File

@ -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<string>,
): ?AssetData {
function tryParse(filePath: string, platforms: Set<string>): ?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<string>,
): AssetData {
function parse(filePath: string, platforms: Set<string>): 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;
}