mirror of https://github.com/status-im/metro.git
Codemod prettier to 1.5.2
Differential Revision: D5339725 fbshipit-source-id: 631338436a7d69b0ab0721507bdab4ae4e207065
This commit is contained in:
parent
138ae9623c
commit
e0ea0aae1d
|
@ -16,8 +16,7 @@ const BundleBase = require('./BundleBase');
|
||||||
const ModuleTransport = require('../lib/ModuleTransport');
|
const ModuleTransport = require('../lib/ModuleTransport');
|
||||||
|
|
||||||
import type Resolver from '../Resolver';
|
import type Resolver from '../Resolver';
|
||||||
import type ResolutionResponse
|
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
||||||
from '../node-haste/DependencyGraph/ResolutionResponse';
|
|
||||||
import type Module from '../node-haste/Module';
|
import type Module from '../node-haste/Module';
|
||||||
|
|
||||||
class HMRBundle extends BundleBase {
|
class HMRBundle extends BundleBase {
|
||||||
|
|
|
@ -49,7 +49,7 @@ describe('Bundle', () => {
|
||||||
[
|
[
|
||||||
'transformed foo;',
|
'transformed foo;',
|
||||||
'transformed bar;',
|
'transformed bar;',
|
||||||
'\/\/# sourceMappingURL=test_url',
|
'//# sourceMappingURL=test_url',
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -112,7 +112,7 @@ describe('Bundle', () => {
|
||||||
'transformed bar;',
|
'transformed bar;',
|
||||||
';require("bar");',
|
';require("bar");',
|
||||||
';require("foo");',
|
';require("foo");',
|
||||||
'\/\/# sourceMappingURL=test_url',
|
'//# sourceMappingURL=test_url',
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -376,8 +376,12 @@ describe('Bundle', () => {
|
||||||
const {groups} = bundle.getUnbundle(); //eslint-disable-line no-unused-vars
|
const {groups} = bundle.getUnbundle(); //eslint-disable-line no-unused-vars
|
||||||
}).toThrow(
|
}).toThrow(
|
||||||
new Error(
|
new Error(
|
||||||
`Module ${fsLocation('invariant')} belongs to groups ${fsLocation('React')}` +
|
`Module ${fsLocation('invariant')} belongs to groups ${fsLocation(
|
||||||
`, and ${fsLocation('OtherFramework')}. Ensure that each module is only part of one group.`,
|
'React',
|
||||||
|
)}` +
|
||||||
|
`, and ${fsLocation(
|
||||||
|
'OtherFramework',
|
||||||
|
)}. Ensure that each module is only part of one group.`,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -119,7 +119,9 @@ function transformModule(
|
||||||
function transformJSON(json, options, callback) {
|
function transformJSON(json, options, callback) {
|
||||||
const value = JSON.parse(json);
|
const value = JSON.parse(json);
|
||||||
const {filename} = options;
|
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 = {
|
const moduleData = {
|
||||||
code,
|
code,
|
||||||
|
|
|
@ -28,8 +28,7 @@ const url = require('url');
|
||||||
|
|
||||||
import type Module, {HasteImpl} from '../node-haste/Module';
|
import type Module, {HasteImpl} from '../node-haste/Module';
|
||||||
import type {IncomingMessage, ServerResponse} from 'http';
|
import type {IncomingMessage, ServerResponse} from 'http';
|
||||||
import type ResolutionResponse
|
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
||||||
from '../node-haste/DependencyGraph/ResolutionResponse';
|
|
||||||
import type Bundle from '../Bundler/Bundle';
|
import type Bundle from '../Bundler/Bundle';
|
||||||
import type HMRBundle from '../Bundler/HMRBundle';
|
import type HMRBundle from '../Bundler/HMRBundle';
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
|
@ -176,9 +175,8 @@ class Server {
|
||||||
globalTransformCache: options.globalTransformCache,
|
globalTransformCache: options.globalTransformCache,
|
||||||
hasteImpl: options.hasteImpl,
|
hasteImpl: options.hasteImpl,
|
||||||
maxWorkers,
|
maxWorkers,
|
||||||
moduleFormat: options.moduleFormat != null
|
moduleFormat:
|
||||||
? options.moduleFormat
|
options.moduleFormat != null ? options.moduleFormat : 'haste',
|
||||||
: 'haste',
|
|
||||||
platforms: options.platforms || defaults.platforms,
|
platforms: options.platforms || defaults.platforms,
|
||||||
polyfillModuleNames: options.polyfillModuleNames || [],
|
polyfillModuleNames: options.polyfillModuleNames || [],
|
||||||
postProcessModules: options.postProcessModules,
|
postProcessModules: options.postProcessModules,
|
||||||
|
@ -314,7 +312,8 @@ class Server {
|
||||||
|
|
||||||
getShallowDependencies(options: DependencyOptions): Promise<Array<Module>> {
|
getShallowDependencies(options: DependencyOptions): Promise<Array<Module>> {
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
const platform = options.platform != null
|
const platform =
|
||||||
|
options.platform != null
|
||||||
? options.platform
|
? options.platform
|
||||||
: parsePlatformFilePath(options.entryFile, this._platforms).platform;
|
: parsePlatformFilePath(options.entryFile, this._platforms).platform;
|
||||||
const {entryFile, dev, minify, hot} = options;
|
const {entryFile, dev, minify, hot} = options;
|
||||||
|
@ -337,7 +336,8 @@ class Server {
|
||||||
options: DependencyOptions,
|
options: DependencyOptions,
|
||||||
): Promise<ResolutionResponse<Module, *>> {
|
): Promise<ResolutionResponse<Module, *>> {
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
const platform = options.platform != null
|
const platform =
|
||||||
|
options.platform != null
|
||||||
? options.platform
|
? options.platform
|
||||||
: parsePlatformFilePath(options.entryFile, this._platforms).platform;
|
: parsePlatformFilePath(options.entryFile, this._platforms).platform;
|
||||||
const {entryFile, dev, minify, hot} = options;
|
const {entryFile, dev, minify, hot} = options;
|
||||||
|
@ -911,7 +911,8 @@ class Server {
|
||||||
res.end(
|
res.end(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'InternalError',
|
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',
|
'please check your terminal error output for more details',
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -985,7 +986,8 @@ class Server {
|
||||||
'entryModuleOnly',
|
'entryModuleOnly',
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
generateSourceMaps: minify ||
|
generateSourceMaps:
|
||||||
|
minify ||
|
||||||
!dev ||
|
!dev ||
|
||||||
this._getBoolOptionFromQuery(urlObj.query, 'babelSourcemap', false),
|
this._getBoolOptionFromQuery(urlObj.query, 'babelSourcemap', false),
|
||||||
assetPlugins,
|
assetPlugins,
|
||||||
|
|
|
@ -352,10 +352,14 @@ function readMetadataFileSync(
|
||||||
if (
|
if (
|
||||||
typeof cachedResultHash !== 'string' ||
|
typeof cachedResultHash !== 'string' ||
|
||||||
typeof cachedSourceHash !== 'string' ||
|
typeof cachedSourceHash !== 'string' ||
|
||||||
!(Array.isArray(dependencies) &&
|
!(
|
||||||
dependencies.every(dep => typeof dep === 'string')) ||
|
Array.isArray(dependencies) &&
|
||||||
!(Array.isArray(dependencyOffsets) &&
|
dependencies.every(dep => typeof dep === 'string')
|
||||||
dependencyOffsets.every(offset => typeof offset === 'number')) ||
|
) ||
|
||||||
|
!(
|
||||||
|
Array.isArray(dependencyOffsets) &&
|
||||||
|
dependencyOffsets.every(offset => typeof offset === 'number')
|
||||||
|
) ||
|
||||||
!(sourceMap == null || typeof sourceMap === 'object')
|
!(sourceMap == null || typeof sourceMap === 'object')
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
* Copyright (c) 2015-present, Facebook, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -35,7 +35,6 @@ type Options<TModule, TPackage> = {|
|
||||||
|};
|
|};
|
||||||
|
|
||||||
class HasteMap<TModule: Moduleish, TPackage: Packageish> extends EventEmitter {
|
class HasteMap<TModule: Moduleish, TPackage: Packageish> extends EventEmitter {
|
||||||
|
|
||||||
_extensions: Array<string>;
|
_extensions: Array<string>;
|
||||||
_files: Array<string>;
|
_files: Array<string>;
|
||||||
_helpers: DependencyGraphHelpers;
|
_helpers: DependencyGraphHelpers;
|
||||||
|
@ -61,8 +60,14 @@ class HasteMap<TModule: Moduleish, TPackage: Packageish> extends EventEmitter {
|
||||||
this._platforms = platforms;
|
this._platforms = platforms;
|
||||||
this._preferNativePlatform = preferNativePlatform;
|
this._preferNativePlatform = preferNativePlatform;
|
||||||
|
|
||||||
(this: any)._processHastePackage = throat(1, this._processHastePackage.bind(this));
|
(this: any)._processHastePackage = throat(
|
||||||
(this: any)._processHasteModule = throat(1, this._processHasteModule.bind(this));
|
1,
|
||||||
|
this._processHastePackage.bind(this),
|
||||||
|
);
|
||||||
|
(this: any)._processHasteModule = throat(
|
||||||
|
1,
|
||||||
|
this._processHasteModule.bind(this),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
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') {
|
if (path.basename(absPath) === 'package.json') {
|
||||||
return this._processHastePackage(absPath, invalidated);
|
return this._processHastePackage(absPath, invalidated);
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,30 +159,36 @@ class HasteMap<TModule: Moduleish, TPackage: Packageish> extends EventEmitter {
|
||||||
const module = this._moduleCache.getModule(file);
|
const module = this._moduleCache.getModule(file);
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
const isHaste = module.isHaste();
|
const isHaste = module.isHaste();
|
||||||
return isHaste && module.getName()
|
return (
|
||||||
.then(name => {
|
isHaste &&
|
||||||
|
module.getName().then(name => {
|
||||||
const result = this._updateHasteMap(name, module);
|
const result = this._updateHasteMap(name, module);
|
||||||
if (previousName && name !== previousName) {
|
if (previousName && name !== previousName) {
|
||||||
this.emit('change');
|
this.emit('change');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_processHastePackage(file: string, previousName: ?string) {
|
_processHastePackage(file: string, previousName: ?string) {
|
||||||
const p = this._moduleCache.getPackage(file);
|
const p = this._moduleCache.getPackage(file);
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve()
|
||||||
|
.then(() => {
|
||||||
const isHaste = p.isHaste();
|
const isHaste = p.isHaste();
|
||||||
return isHaste && p.getName()
|
return (
|
||||||
.then(name => {
|
isHaste &&
|
||||||
|
p.getName().then(name => {
|
||||||
const result = this._updateHasteMap(name, p);
|
const result = this._updateHasteMap(name, p);
|
||||||
if (previousName && name !== previousName) {
|
if (previousName && name !== previousName) {
|
||||||
this.emit('change');
|
this.emit('change');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
})
|
||||||
}).catch(e => {
|
);
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
if (e instanceof SyntaxError) {
|
if (e instanceof SyntaxError) {
|
||||||
// Malformed package.json.
|
// Malformed package.json.
|
||||||
return;
|
return;
|
||||||
|
@ -207,7 +221,7 @@ class HasteMap<TModule: Moduleish, TPackage: Packageish> extends EventEmitter {
|
||||||
` Duplicate module name: ${name}\n` +
|
` Duplicate module name: ${name}\n` +
|
||||||
` Paths: ${mod.path} collides with ${existingModule.path}\n\n` +
|
` Paths: ${mod.path} collides with ${existingModule.path}\n\n` +
|
||||||
'This error is caused by a @providesModule declaration ' +
|
'This error is caused by a @providesModule declaration ' +
|
||||||
'with the same name across two different files.'
|
'with the same name across two different files.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,7 @@ const path = require('path');
|
||||||
|
|
||||||
import type DependencyGraphHelpers from './DependencyGraphHelpers';
|
import type DependencyGraphHelpers from './DependencyGraphHelpers';
|
||||||
import type ResolutionResponse from './ResolutionResponse';
|
import type ResolutionResponse from './ResolutionResponse';
|
||||||
import type {
|
import type {Options as TransformWorkerOptions} from '../../JSTransformer/worker';
|
||||||
Options as TransformWorkerOptions,
|
|
||||||
} from '../../JSTransformer/worker';
|
|
||||||
import type {ReadResult, CachedReadResult} from '../Module';
|
import type {ReadResult, CachedReadResult} from '../Module';
|
||||||
import type {ModuleResolver} from './ModuleResolution';
|
import type {ModuleResolver} from './ModuleResolution';
|
||||||
|
|
||||||
|
@ -310,7 +308,8 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
|
||||||
* not obsolete, and required from somewhere */
|
* not obsolete, and required from somewhere */
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const dependencies = cached.result != null
|
const dependencies =
|
||||||
|
cached.result != null
|
||||||
? cached.result.dependencies
|
? cached.result.dependencies
|
||||||
: cached.outdatedDependencies;
|
: cached.outdatedDependencies;
|
||||||
return this.tryResolveModuleDependencies(
|
return this.tryResolveModuleDependencies(
|
||||||
|
|
|
@ -33,8 +33,7 @@ import type {
|
||||||
ReadTransformProps,
|
ReadTransformProps,
|
||||||
} from '../lib/TransformCaching';
|
} from '../lib/TransformCaching';
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
import type DependencyGraphHelpers
|
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
||||||
from './DependencyGraph/DependencyGraphHelpers';
|
|
||||||
import type ModuleCache from './ModuleCache';
|
import type ModuleCache from './ModuleCache';
|
||||||
import type {LocalPath} from './lib/toLocalPath';
|
import type {LocalPath} from './lib/toLocalPath';
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,7 @@ const toLocalPath = require('./lib/toLocalPath');
|
||||||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||||
import type {GetTransformCacheKey} from '../lib/TransformCaching';
|
import type {GetTransformCacheKey} from '../lib/TransformCaching';
|
||||||
import type {Reporter} from '../lib/reporting';
|
import type {Reporter} from '../lib/reporting';
|
||||||
import type DependencyGraphHelpers
|
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
||||||
from './DependencyGraph/DependencyGraphHelpers';
|
|
||||||
import type {TransformCode, Options as ModuleOptions} from './Module';
|
import type {TransformCode, Options as ModuleOptions} from './Module';
|
||||||
|
|
||||||
type GetClosestPackageFn = (filePath: string) => ?string;
|
type GetClosestPackageFn = (filePath: string) => ?string;
|
||||||
|
|
|
@ -2247,7 +2247,8 @@ describe('DependencyGraph', function() {
|
||||||
'node-package-c': 'rn-package-c',
|
'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_modules: {
|
||||||
'node-package-a': {
|
'node-package-a': {
|
||||||
'package.json': JSON.stringify({
|
'package.json': JSON.stringify({
|
||||||
|
@ -3256,7 +3257,8 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'submodule/main.js',
|
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: [],
|
dependencies: [],
|
||||||
isAsset: false,
|
isAsset: false,
|
||||||
isJSON: false,
|
isJSON: false,
|
||||||
|
@ -4238,7 +4240,8 @@ describe('DependencyGraph', function() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'submodule/main.js',
|
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: [],
|
dependencies: [],
|
||||||
isAsset: false,
|
isAsset: false,
|
||||||
isJSON: false,
|
isJSON: false,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
* Copyright (c) 2015-present, Facebook, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -47,10 +47,7 @@ function parseBaseName(
|
||||||
* Return `null` if the `filePath` doesn't have a valid extension, required
|
* Return `null` if the `filePath` doesn't have a valid extension, required
|
||||||
* to describe the type of an asset.
|
* to describe the type of an asset.
|
||||||
*/
|
*/
|
||||||
function tryParse(
|
function tryParse(filePath: string, platforms: Set<string>): ?AssetData {
|
||||||
filePath: string,
|
|
||||||
platforms: Set<string>,
|
|
||||||
): ?AssetData {
|
|
||||||
const result = parsePlatformFilePath(filePath, platforms);
|
const result = parsePlatformFilePath(filePath, platforms);
|
||||||
const {dirPath, baseName, platform, extension} = result;
|
const {dirPath, baseName, platform, extension} = result;
|
||||||
if (extension == null) {
|
if (extension == null) {
|
||||||
|
@ -66,13 +63,10 @@ function tryParse(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse(
|
function parse(filePath: string, platforms: Set<string>): AssetData {
|
||||||
filePath: string,
|
|
||||||
platforms: Set<string>,
|
|
||||||
): AssetData {
|
|
||||||
const result = tryParse(filePath, platforms);
|
const result = tryParse(filePath, platforms);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw new Error('invalid asset file path: \`${filePath}');
|
throw new Error('invalid asset file path: `${filePath}');
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue