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 VERSION = require('../../package.json').version;
const VERSION = require('../package.json').version;
type ActionLogEntryData = {
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,
createActionStartEntry,
createActionEndEntry,
} = require('../');
} = require('../Logger');
/* eslint-disable no-console */
describe('Logger', () => {

View File

@ -10,8 +10,8 @@
'use strict';
const AmbiguousModuleResolutionError = require('./AmbiguousModuleResolutionError');
const PackageResolutionError = require('./PackageResolutionError');
const AmbiguousModuleResolutionError = require('./errors/AmbiguousModuleResolutionError');
const PackageResolutionError = require('./errors/PackageResolutionError');
module.exports = {
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';
const AssetPaths = require('../node-haste/lib/AssetPaths');
const AssetPaths = require('./node-haste/lib/AssetPaths');
const crypto = require('crypto');
const denodeify = require('denodeify');
@ -18,7 +18,7 @@ const fs = require('fs');
const imageSize = require('image-size');
const path = require('path');
const {isAssetTypeAnImage} = require('../Bundler/util');
const {isAssetTypeAnImage} = require('./Bundler/util');
const stat = denodeify(fs.stat);
const readDir = denodeify(fs.readdir);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,24 +10,24 @@
'use strict';
const JsFileWrapping = require('../../ModuleGraph/worker/JsFileWrapping');
const JsFileWrapping = require('../ModuleGraph/worker/JsFileWrapping');
const assetTransformer = require('../../assetTransformer');
const collectDependencies = require('../../ModuleGraph/worker/collectDependencies');
const constantFoldingPlugin = require('./constant-folding-plugin');
const assetTransformer = require('../assetTransformer');
const collectDependencies = require('../ModuleGraph/worker/collectDependencies');
const constantFoldingPlugin = require('./worker/constant-folding-plugin');
const crypto = require('crypto');
const fs = require('fs');
const getMinifier = require('../../lib/getMinifier');
const inlinePlugin = require('./inline-plugin');
const optimizeDependencies = require('../../ModuleGraph/worker/optimizeDependencies');
const getMinifier = require('../lib/getMinifier');
const inlinePlugin = require('./worker/inline-plugin');
const optimizeDependencies = require('../ModuleGraph/worker/optimizeDependencies');
const path = require('path');
const {babylon} = require('../../babel-bridge');
const {babelGenerate: generate} = require('../../babel-bridge');
const {babylon} = require('../babel-bridge');
const {babelGenerate: generate} = require('../babel-bridge');
const {toSegmentTuple} = require('metro-source-map');
import type {DynamicRequiresBehavior} from '../../ModuleGraph/worker/collectDependencies';
import type {LocalPath} from '../../node-haste/lib/toLocalPath';
import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDependencies';
import type {LocalPath} from '../node-haste/lib/toLocalPath';
import type {Ast} from '@babel/core';
import type {BabelSourceMap} 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');
import type {PostMinifyProcess} from '../../Bundler/index.js';
import type {PostMinifyProcess} from '../../Bundler';
import type {TransformedSourceFile, TransformResult} from '../types.flow';
import type {BabelSourceMap} from '@babel/core';
import type {TransformResult as BabelTransformResult} from '@babel/core';

View File

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

View File

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

View File

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