Move `.../<name>/index.js` to `.../<name>.js`

Summary:
Here, we move `index.js` files in directories one level up, and rename them to `<dirname>.js`.

This makes for a more pleasant development experience, as files are easier to identify even when only seeing the file name.
It also eliminates quite some `../` segments in imports.

Reviewed By: mjesun

Differential Revision: D7587186

fbshipit-source-id: cf7e6b417085435d731c5b6830309068035bcd19
This commit is contained in:
David Aurelio 2018-04-11 13:18:27 -07:00 committed by Facebook Github Bot
parent 5f0117e27a
commit 2a2b54555e
22 changed files with 85 additions and 131 deletions

View File

@ -16,7 +16,7 @@ const process = require('process');
const {EventEmitter} = require('events'); const {EventEmitter} = require('events');
const VERSION = require('../../package.json').version; const VERSION = require('../package.json').version;
type ActionLogEntryData = { type ActionLogEntryData = {
action_name: string, action_name: string,

View File

@ -1,17 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const Logger = require('./Logger');
export type {LogEntry} from './Logger';
module.exports = Logger;

View File

@ -1,15 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const Terminal = require('./Terminal');
module.exports = Terminal;

View File

@ -14,7 +14,7 @@ const {
createEntry, createEntry,
createActionStartEntry, createActionStartEntry,
createActionEndEntry, createActionEndEntry,
} = require('../'); } = require('../Logger');
/* eslint-disable no-console */ /* eslint-disable no-console */
describe('Logger', () => { describe('Logger', () => {

View File

@ -10,8 +10,8 @@
'use strict'; 'use strict';
const AmbiguousModuleResolutionError = require('./AmbiguousModuleResolutionError'); const AmbiguousModuleResolutionError = require('./errors/AmbiguousModuleResolutionError');
const PackageResolutionError = require('./PackageResolutionError'); const PackageResolutionError = require('./errors/PackageResolutionError');
module.exports = { module.exports = {
AmbiguousModuleResolutionError, AmbiguousModuleResolutionError,

View File

@ -1,15 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const formatBanner = require('./formatBanner');
module.exports = formatBanner;

View File

@ -10,7 +10,7 @@
'use strict'; 'use strict';
const AssetPaths = require('../node-haste/lib/AssetPaths'); const AssetPaths = require('./node-haste/lib/AssetPaths');
const crypto = require('crypto'); const crypto = require('crypto');
const denodeify = require('denodeify'); const denodeify = require('denodeify');
@ -18,7 +18,7 @@ const fs = require('fs');
const imageSize = require('image-size'); const imageSize = require('image-size');
const path = require('path'); const path = require('path');
const {isAssetTypeAnImage} = require('../Bundler/util'); const {isAssetTypeAnImage} = require('./Bundler/util');
const stat = denodeify(fs.stat); const stat = denodeify(fs.stat);
const readDir = denodeify(fs.readdir); const readDir = denodeify(fs.readdir);

View File

@ -10,13 +10,13 @@
'use strict'; 'use strict';
const DependencyGraph = require('../node-haste/DependencyGraph'); const DependencyGraph = require('./node-haste/DependencyGraph');
const Transformer = require('../JSTransformer'); const Transformer = require('./JSTransformer');
const assert = require('assert'); const assert = require('assert');
const defaults = require('../defaults'); const defaults = require('./defaults');
const fs = require('fs'); const fs = require('fs');
const getTransformCacheKeyFn = require('../lib/getTransformCacheKeyFn'); const getTransformCacheKeyFn = require('./lib/getTransformCacheKeyFn');
const {Cache, stableHash} = require('metro-cache'); const {Cache, stableHash} = require('metro-cache');
const { const {
@ -28,12 +28,12 @@ const {
import type { import type {
TransformedCode, TransformedCode,
Options as WorkerOptions, Options as WorkerOptions,
} from '../JSTransformer/worker'; } from './JSTransformer/worker';
import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDependencies'; import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
import type {GlobalTransformCache} from '../lib/GlobalTransformCache'; import type {GlobalTransformCache} from './lib/GlobalTransformCache';
import type {TransformCache} from '../lib/TransformCaching'; import type {TransformCache} from './lib/TransformCaching';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from './lib/reporting';
import type Module from '../node-haste/Module'; import type Module from './node-haste/Module';
import type {BabelSourceMap} from '@babel/core'; import type {BabelSourceMap} from '@babel/core';
import type {CacheStore} from 'metro-cache'; import type {CacheStore} from 'metro-cache';
import type {CustomResolver} from 'metro-resolver'; import type {CustomResolver} from 'metro-resolver';

View File

@ -10,14 +10,14 @@
'use strict'; 'use strict';
const DeltaCalculator = require('./DeltaCalculator'); const DeltaCalculator = require('./DeltaBundler/DeltaCalculator');
import type Bundler from '../Bundler'; import type Bundler from './Bundler';
import type { import type {
DeltaResult, DeltaResult,
Graph as CalculatorGraph, Graph as CalculatorGraph,
Options, Options,
} from './DeltaCalculator'; } from './DeltaBundler/DeltaCalculator';
export type Delta = DeltaResult; export type Delta = DeltaResult;
export type Graph = CalculatorGraph; export type Graph = CalculatorGraph;

View File

@ -14,7 +14,7 @@ const getAppendScripts = require('../../lib/getAppendScripts');
const {wrapModule} = require('./helpers/js'); const {wrapModule} = require('./helpers/js');
import type {Delta, Graph} from '../'; import type {Delta, Graph} from '../../DeltaBundler';
import type {DependencyEdge} from '../traverseDependencies'; import type {DependencyEdge} from '../traverseDependencies';
type Options = {| type Options = {|

View File

@ -14,7 +14,7 @@ const addParamsToDefineCall = require('../../lib/addParamsToDefineCall');
const {wrapModule} = require('./helpers/js'); const {wrapModule} = require('./helpers/js');
import type {Delta, Graph} from '../'; import type {Delta, Graph} from '../../DeltaBundler';
import type {DependencyEdge} from '../traverseDependencies'; import type {DependencyEdge} from '../traverseDependencies';
type Options = { type Options = {

View File

@ -10,20 +10,20 @@
'use strict'; 'use strict';
const formatBundlingError = require('../lib/formatBundlingError'); const formatBundlingError = require('./lib/formatBundlingError');
const getAbsolutePath = require('../lib/getAbsolutePath'); const getAbsolutePath = require('./lib/getAbsolutePath');
const hmrJSBundle = require('../DeltaBundler/Serializers/hmrJSBundle'); const hmrJSBundle = require('./DeltaBundler/Serializers/hmrJSBundle');
const nullthrows = require('fbjs/lib/nullthrows'); const nullthrows = require('fbjs/lib/nullthrows');
const parseCustomTransformOptions = require('../lib/parseCustomTransformOptions'); const parseCustomTransformOptions = require('./lib/parseCustomTransformOptions');
const url = require('url'); const url = require('url');
const { const {
Logger: {createActionStartEntry, createActionEndEntry, log}, Logger: {createActionStartEntry, createActionEndEntry, log},
} = require('metro-core'); } = require('metro-core');
import type {Graph} from '../DeltaBundler/DeltaCalculator'; import type {Graph} from './DeltaBundler/DeltaCalculator';
import type PackagerServer from '../Server'; import type PackagerServer from './Server';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from './lib/reporting';
type Client = {| type Client = {|
graph: Graph, graph: Graph,

View File

@ -17,13 +17,13 @@ const debug = require('debug')('Metro:JStransformer');
const Worker = require('jest-worker').default; const Worker = require('jest-worker').default;
import type {BabelSourceMap} from '@babel/core'; import type {BabelSourceMap} from '@babel/core';
import type {Options, TransformedCode} from './worker'; import type {Options, TransformedCode} from './JSTransformer/worker';
import type {LocalPath} from '../node-haste/lib/toLocalPath'; import type {LocalPath} from './node-haste/lib/toLocalPath';
import type {MetroMinifier} from 'metro-minify-uglify'; import type {MetroMinifier} from 'metro-minify-uglify';
import type {ResultWithMap} from 'metro-minify-uglify'; import type {ResultWithMap} from 'metro-minify-uglify';
import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDependencies'; import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
import typeof {transform as Transform} from './worker'; import typeof {transform as Transform} from './JSTransformer/worker';
type WorkerInterface = Worker & { type WorkerInterface = Worker & {
minify: MetroMinifier, minify: MetroMinifier,
@ -60,7 +60,7 @@ module.exports = class Transformer {
this._asyncRequireModulePath = options.asyncRequireModulePath; this._asyncRequireModulePath = options.asyncRequireModulePath;
this._dynamicDepsInPackages = options.dynamicDepsInPackages; this._dynamicDepsInPackages = options.dynamicDepsInPackages;
this._minifierPath = options.minifierPath; this._minifierPath = options.minifierPath;
const {workerPath = require.resolve('./worker')} = options; const {workerPath = require.resolve('./JSTransformer/worker')} = options;
if (options.maxWorkers > 1) { if (options.maxWorkers > 1) {
this._worker = this._makeFarm( this._worker = this._makeFarm(

View File

@ -10,24 +10,24 @@
'use strict'; 'use strict';
const JsFileWrapping = require('../../ModuleGraph/worker/JsFileWrapping'); const JsFileWrapping = require('../ModuleGraph/worker/JsFileWrapping');
const assetTransformer = require('../../assetTransformer'); const assetTransformer = require('../assetTransformer');
const collectDependencies = require('../../ModuleGraph/worker/collectDependencies'); const collectDependencies = require('../ModuleGraph/worker/collectDependencies');
const constantFoldingPlugin = require('./constant-folding-plugin'); const constantFoldingPlugin = require('./worker/constant-folding-plugin');
const crypto = require('crypto'); const crypto = require('crypto');
const fs = require('fs'); const fs = require('fs');
const getMinifier = require('../../lib/getMinifier'); const getMinifier = require('../lib/getMinifier');
const inlinePlugin = require('./inline-plugin'); const inlinePlugin = require('./worker/inline-plugin');
const optimizeDependencies = require('../../ModuleGraph/worker/optimizeDependencies'); const optimizeDependencies = require('../ModuleGraph/worker/optimizeDependencies');
const path = require('path'); const path = require('path');
const {babylon} = require('../../babel-bridge'); const {babylon} = require('../babel-bridge');
const {babelGenerate: generate} = require('../../babel-bridge'); const {babelGenerate: generate} = require('../babel-bridge');
const {toSegmentTuple} = require('metro-source-map'); const {toSegmentTuple} = require('metro-source-map');
import type {DynamicRequiresBehavior} from '../../ModuleGraph/worker/collectDependencies'; import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDependencies';
import type {LocalPath} from '../../node-haste/lib/toLocalPath'; import type {LocalPath} from '../node-haste/lib/toLocalPath';
import type {Ast} from '@babel/core'; import type {Ast} from '@babel/core';
import type {BabelSourceMap} from '@babel/core'; import type {BabelSourceMap} from '@babel/core';
import type {Plugins as BabelPlugins} from 'babel-core'; import type {Plugins as BabelPlugins} from 'babel-core';

View File

@ -20,7 +20,7 @@ const sourceMap = require('source-map');
const {transformSync} = require('../../babel-bridge'); const {transformSync} = require('../../babel-bridge');
import type {PostMinifyProcess} from '../../Bundler/index.js'; import type {PostMinifyProcess} from '../../Bundler';
import type {TransformedSourceFile, TransformResult} from '../types.flow'; import type {TransformedSourceFile, TransformResult} from '../types.flow';
import type {BabelSourceMap} from '@babel/core'; import type {BabelSourceMap} from '@babel/core';
import type {TransformResult as BabelTransformResult} from '@babel/core'; import type {TransformResult as BabelTransformResult} from '@babel/core';

View File

@ -10,59 +10,60 @@
'use strict'; 'use strict';
const Bundler = require('../Bundler'); const Bundler = require('./Bundler');
const DeltaBundler = require('../DeltaBundler'); const DeltaBundler = require('./DeltaBundler');
const MultipartResponse = require('./MultipartResponse'); const MultipartResponse = require('./Server/MultipartResponse');
const crypto = require('crypto'); const crypto = require('crypto');
const defaultCreateModuleIdFactory = require('../lib/createModuleIdFactory'); const defaultCreateModuleIdFactory = require('./lib/createModuleIdFactory');
const deltaJSBundle = require('../DeltaBundler/Serializers/deltaJSBundle'); const deltaJSBundle = require('./DeltaBundler/Serializers/deltaJSBundle');
const getAllFiles = require('../DeltaBundler/Serializers/getAllFiles'); const getAllFiles = require('./DeltaBundler/Serializers/getAllFiles');
const getAssets = require('../DeltaBundler/Serializers/getAssets'); const getAssets = require('./DeltaBundler/Serializers/getAssets');
const getRamBundleInfo = require('../DeltaBundler/Serializers/getRamBundleInfo'); const getRamBundleInfo = require('./DeltaBundler/Serializers/getRamBundleInfo');
const plainJSBundle = require('../DeltaBundler/Serializers/plainJSBundle'); const plainJSBundle = require('./DeltaBundler/Serializers/plainJSBundle');
const sourceMapObject = require('../DeltaBundler/Serializers/sourceMapObject'); const sourceMapObject = require('./DeltaBundler/Serializers/sourceMapObject');
const sourceMapString = require('../DeltaBundler/Serializers/sourceMapString'); const sourceMapString = require('./DeltaBundler/Serializers/sourceMapString');
const debug = require('debug')('Metro:Server'); const debug = require('debug')('Metro:Server');
const defaults = require('../defaults'); const defaults = require('./defaults');
const formatBundlingError = require('../lib/formatBundlingError'); const formatBundlingError = require('./lib/formatBundlingError');
const getAbsolutePath = require('../lib/getAbsolutePath'); const getAbsolutePath = require('./lib/getAbsolutePath');
const getMaxWorkers = require('../lib/getMaxWorkers'); const getMaxWorkers = require('./lib/getMaxWorkers');
const getPrependedScripts = require('../lib/getPrependedScripts'); const getPrependedScripts = require('./lib/getPrependedScripts');
const mime = require('mime-types'); const mime = require('mime-types');
const mapGraph = require('../lib/mapGraph'); const mapGraph = require('./lib/mapGraph');
const nullthrows = require('fbjs/lib/nullthrows'); const nullthrows = require('fbjs/lib/nullthrows');
const parseCustomTransformOptions = require('../lib/parseCustomTransformOptions'); const parseCustomTransformOptions = require('./lib/parseCustomTransformOptions');
const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath'); const parsePlatformFilePath = require('./node-haste/lib/parsePlatformFilePath');
const path = require('path'); const path = require('path');
const symbolicate = require('./symbolicate/symbolicate'); const symbolicate = require('./Server/symbolicate/symbolicate');
const url = require('url'); const url = require('url');
const {getAsset} = require('../Assets'); const {getAsset} = require('./Assets');
const resolveSync: ResolveSync = require('resolve').sync; const resolveSync: ResolveSync = require('resolve').sync;
import type {CustomError} from '../lib/formatBundlingError'; import type {CustomError} from './lib/formatBundlingError';
import type {DependencyEdge} from '../DeltaBundler/traverseDependencies'; import type {DependencyEdge} from './DeltaBundler/traverseDependencies';
import type {IncomingMessage, ServerResponse} from 'http'; import type {IncomingMessage, ServerResponse} from 'http';
import type {Reporter} from '../lib/reporting'; import type {Reporter} from './lib/reporting';
import type {RamBundleInfo} from '../DeltaBundler/Serializers/getRamBundleInfo'; import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo';
import type {BundleOptions, Options} from '../shared/types.flow'; import type {BundleOptions, Options} from './shared/types.flow';
import type { import type {
GetTransformOptions, GetTransformOptions,
PostMinifyProcess, PostMinifyProcess,
PostProcessBundleSourcemap, PostProcessBundleSourcemap,
} from '../Bundler'; } from './Bundler';
import type {CacheStore} from 'metro-cache'; import type {CacheStore} from 'metro-cache';
import type {Delta, Graph} from '../DeltaBundler'; import type {Delta, Graph} from './DeltaBundler';
import type {CustomResolver} from 'metro-resolver'; import type {CustomResolver} from 'metro-resolver';
import type {MetroSourceMap} from 'metro-source-map'; import type {MetroSourceMap} from 'metro-source-map';
import type {TransformCache} from '../lib/TransformCaching'; import type {TransformCache} from './lib/TransformCaching';
import type {Symbolicate} from './symbolicate/symbolicate'; import type {Symbolicate} from './Server/symbolicate/symbolicate';
import type {AssetData} from '../Assets'; import type {AssetData} from './Assets';
import type { import type {
CustomTransformOptions, CustomTransformOptions,
TransformedCode, TransformedCode,
} from '../JSTransformer/worker'; } from './JSTransformer/worker';
const { const {
Logger: {createActionStartEntry, createActionEndEntry, log}, Logger: {createActionStartEntry, createActionEndEntry, log},
} = require('metro-core'); } = require('metro-core');
@ -152,7 +153,7 @@ class Server {
constructor(options: Options) { constructor(options: Options) {
const reporter = const reporter =
options.reporter || require('../lib/reporting').nullReporter; options.reporter || require('./lib/reporting').nullReporter;
const maxWorkers = getMaxWorkers(options.maxWorkers); const maxWorkers = getMaxWorkers(options.maxWorkers);
const assetExts = options.assetExts || defaults.assetExts; const assetExts = options.assetExts || defaults.assetExts;
const sourceExts = options.sourceExts || defaults.sourceExts; const sourceExts = options.sourceExts || defaults.sourceExts;

View File

@ -13,7 +13,7 @@
jest.mock('fs', () => new (require('metro-memory-fs'))()); jest.mock('fs', () => new (require('metro-memory-fs'))());
jest.mock('image-size'); jest.mock('image-size');
const {getAssetData, getAsset} = require('../'); const {getAssetData, getAsset} = require('../Assets');
const crypto = require('crypto'); const crypto = require('crypto');
const fs = require('fs'); const fs = require('fs');
const mkdirp = require('mkdirp'); const mkdirp = require('mkdirp');

View File

@ -10,13 +10,13 @@
'use strict'; 'use strict';
const Server = require('../../../Server'); const Server = require('../../Server');
const asAssets = require('./as-assets'); const asAssets = require('./unbundle/as-assets');
const asIndexedFile = require('./as-indexed-file').save; const asIndexedFile = require('./unbundle/as-indexed-file').save;
import type {OutputOptions, RequestOptions} from '../../types.flow'; import type {OutputOptions, RequestOptions} from '../types.flow';
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo'; import type {RamBundleInfo} from '../../DeltaBundler/Serializers/getRamBundleInfo';
async function buildBundle( async function buildBundle(
packagerClient: Server, packagerClient: Server,