From 57bb955ba18c4dad16fd463323c5458f713eafaa Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Wed, 31 May 2017 11:00:41 -0700 Subject: [PATCH] Move remaining Metro Bundler files around. Reviewed By: jeanlauliac Differential Revision: D5154653 fbshipit-source-id: 482bf9829263d5d8f3d0b951ee58e2020236cc2c --- jest/preprocessor.js | 6 ++--- local-cli/bundle/buildBundle.js | 8 +++---- local-cli/server/runServer.js | 8 +++---- local-cli/util/Config.js | 6 ++--- packager/package.json | 11 ++++++---- .../src/Bundler/__tests__/Bundler-test.js | 2 +- packager/src/Bundler/index.js | 2 +- packager/src/JSTransformer/worker/index.js | 2 +- packager/src/ModuleGraph/ModuleGraph.js | 2 +- .../ModuleGraph/__tests__/ModuleGraph-test.js | 2 +- .../src/ModuleGraph/node-haste/node-haste.js | 2 +- .../__tests__/indexed-ram-bundle-test.js | 2 +- .../worker/__tests__/optimize-module-test.js | 2 +- .../ModuleGraph/worker/transform-module.js | 2 +- .../src/Resolver/__tests__/Resolver-test.js | 2 +- packager/src/Resolver/index.js | 2 +- packager/src/Server/index.js | 2 +- packager/{ => src}/babelRegisterOnly.js | 0 packager/{ => src}/blacklist.js | 0 packager/{ => src}/defaults.js | 20 ++++++++--------- packager/{ => src}/index.js | 22 +++++++++---------- packager/src/node-haste/Module.js | 1 - packager/{ => src}/rn-cli.config.js | 0 packager/{ => src}/setupNodePolyfills.js | 0 packager/src/shared/output/bundle.js | 2 +- .../src/shared/output/unbundle/as-assets.js | 2 +- .../shared/output/unbundle/as-indexed-file.js | 2 +- packager/{ => src}/transformer.js | 6 ++--- setupBabel.js | 4 +--- 29 files changed, 61 insertions(+), 61 deletions(-) rename packager/{ => src}/babelRegisterOnly.js (100%) rename packager/{ => src}/blacklist.js (100%) rename packager/{ => src}/defaults.js (59%) rename packager/{ => src}/index.js (88%) rename packager/{ => src}/rn-cli.config.js (100%) rename packager/{ => src}/setupNodePolyfills.js (100%) rename packager/{ => src}/transformer.js (95%) diff --git a/jest/preprocessor.js b/jest/preprocessor.js index 2be2ec13c..af38b1a73 100644 --- a/jest/preprocessor.js +++ b/jest/preprocessor.js @@ -11,7 +11,7 @@ 'use strict'; const babel = require('babel-core'); -const babelRegisterOnly = require('../packager/babelRegisterOnly'); +const babelRegisterOnly = require('../packager/src/babelRegisterOnly'); const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction'); const path = require('path'); @@ -23,7 +23,7 @@ const nodeOptions = babelRegisterOnly.config([nodeFiles]); babelRegisterOnly([]); // has to be required after setting up babelRegisterOnly -const transformer = require('../packager/transformer.js'); +const transformer = require('../packager/src/transformer.js'); module.exports = { process(src/*: string*/, file/*: string*/) { @@ -49,7 +49,7 @@ module.exports = { getCacheKey: createCacheKeyFunction([ __filename, - path.join(__dirname, '../packager/transformer.js'), + path.join(__dirname, '../packager/src/transformer.js'), require.resolve('babel-core/package.json'), ]), }; diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index 1f208fb56..d2db60039 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -19,10 +19,10 @@ const TransformCaching = require('../../packager/src/lib/TransformCaching'); const outputBundle = require('../../packager/src/shared/output/bundle'); const path = require('path'); const saveAssets = require('./saveAssets'); -const defaultAssetExts = require('../../packager/defaults').assetExts; -const defaultSourceExts = require('../../packager/defaults').sourceExts; -const defaultPlatforms = require('../../packager/defaults').platforms; -const defaultProvidesModuleNodeModules = require('../../packager/defaults').providesModuleNodeModules; +const defaultAssetExts = require('../../packager/src/defaults').assetExts; +const defaultSourceExts = require('../../packager/src/defaults').sourceExts; +const defaultPlatforms = require('../../packager/src/defaults').platforms; +const defaultProvidesModuleNodeModules = require('../../packager/src/defaults').providesModuleNodeModules; import type {RequestOptions, OutputOptions} from './types.flow'; import type {ConfigT} from '../util/Config'; diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index fc9616d1e..0fdd9e4b1 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -20,10 +20,10 @@ const attachHMRServer = require('./util/attachHMRServer'); const connect = require('connect'); const copyToClipBoardMiddleware = require('./middleware/copyToClipBoardMiddleware'); const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware'); -const defaultAssetExts = require('../../packager/defaults').assetExts; -const defaultSourceExts = require('../../packager/defaults').sourceExts; -const defaultPlatforms = require('../../packager/defaults').platforms; -const defaultProvidesModuleNodeModules = require('../../packager/defaults') +const defaultAssetExts = require('../../packager/src/defaults').assetExts; +const defaultSourceExts = require('../../packager/src/defaults').sourceExts; +const defaultPlatforms = require('../../packager/src/defaults').platforms; +const defaultProvidesModuleNodeModules = require('../../packager/src/defaults') .providesModuleNodeModules; const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware'); const http = require('http'); diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index a99cf6a99..33f4e4d5c 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -10,12 +10,12 @@ */ 'use strict'; -const blacklist = require('../../packager/blacklist'); +const blacklist = require('../../packager/src/blacklist'); const fs = require('fs'); const invariant = require('fbjs/lib/invariant'); const path = require('path'); -const {providesModuleNodeModules} = require('../../packager/defaults'); +const {providesModuleNodeModules} = require('../../packager/src/defaults'); const RN_CLI_CONFIG = 'rn-cli.config.js'; @@ -120,7 +120,7 @@ const defaultConfig: ConfigT = { getProjectRoots: () => [process.cwd()], getProvidesModuleNodeModules: () => providesModuleNodeModules.slice(), getSourceExts: () => [], - getTransformModulePath: () => path.resolve(__dirname, '../../packager/transformer.js'), + getTransformModulePath: () => path.resolve(__dirname, '../../packager/src/transformer.js'), getTransformOptions: async () => ({}), postMinifyProcess: x => x, postProcessModules: modules => modules, diff --git a/packager/package.json b/packager/package.json index e0d117d26..d3c85b23d 100644 --- a/packager/package.json +++ b/packager/package.json @@ -1,10 +1,11 @@ { - "version": "0.6.1", - "name": "react-native-packager", - "description": "Build native apps with React!", + "version": "0.7.0", + "name": "metro-bundler", + "description": "🚇 The JavaScript bundler for React Native.", + "main": "src/index.js", "repository": { "type": "git", - "url": "git@github.com:facebook/react-native.git" + "url": "git@github.com:facebook/metro-bundler.git" }, "dependencies": { "absolute-path": "^0.0.0", @@ -12,6 +13,7 @@ "babel-core": "^6.24.1", "babel-generator": "^6.24.1", "babel-plugin-external-helpers": "^6.18.0", + "babel-preset-es2015-node": "^6.1.1", "babel-preset-fbjs": "^2.1.0", "babel-preset-react-native": "^1.9.1", "babel-register": "^6.24.1", @@ -35,6 +37,7 @@ "request": "^2.79.0", "rimraf": "^2.5.4", "source-map": "^0.5.6", + "temp": "0.8.3", "throat": "^3.0.0", "uglify-js": "2.7.5", "write-file-atomic": "^1.2.0", diff --git a/packager/src/Bundler/__tests__/Bundler-test.js b/packager/src/Bundler/__tests__/Bundler-test.js index f0dad0657..ef3ea89ca 100644 --- a/packager/src/Bundler/__tests__/Bundler-test.js +++ b/packager/src/Bundler/__tests__/Bundler-test.js @@ -30,7 +30,7 @@ jest var Bundler = require('../'); var Resolver = require('../../Resolver'); -var defaults = require('../../../defaults'); +var defaults = require('../../defaults'); var sizeOf = require('image-size'); var fs = require('fs'); const os = require('os'); diff --git a/packager/src/Bundler/index.js b/packager/src/Bundler/index.js index fe436b0e4..778b61556 100644 --- a/packager/src/Bundler/index.js +++ b/packager/src/Bundler/index.js @@ -24,7 +24,7 @@ const ModuleTransport = require('../lib/ModuleTransport'); const imageSize = require('image-size'); const path = require('path'); const denodeify = require('denodeify'); -const defaults = require('../../defaults'); +const defaults = require('../../src/defaults'); const os = require('os'); const invariant = require('fbjs/lib/invariant'); const toLocalPath = require('../node-haste/lib/toLocalPath'); diff --git a/packager/src/JSTransformer/worker/index.js b/packager/src/JSTransformer/worker/index.js index 65e3b8922..f88706ff8 100644 --- a/packager/src/JSTransformer/worker/index.js +++ b/packager/src/JSTransformer/worker/index.js @@ -11,7 +11,7 @@ 'use strict'; -const babelRegisterOnly = require('../../../babelRegisterOnly'); +const babelRegisterOnly = require('../../babelRegisterOnly'); const constantFolding = require('./constant-folding'); const extractDependencies = require('./extract-dependencies'); const inline = require('./inline'); diff --git a/packager/src/ModuleGraph/ModuleGraph.js b/packager/src/ModuleGraph/ModuleGraph.js index 3c00b69c6..d6eea08aa 100644 --- a/packager/src/ModuleGraph/ModuleGraph.js +++ b/packager/src/ModuleGraph/ModuleGraph.js @@ -10,7 +10,7 @@ */ 'use strict'; -const defaults = require('../../defaults'); +const defaults = require('../defaults'); const nullthrows = require('fbjs/lib/nullthrows'); const parallel = require('async/parallel'); const seq = require('async/seq'); diff --git a/packager/src/ModuleGraph/__tests__/ModuleGraph-test.js b/packager/src/ModuleGraph/__tests__/ModuleGraph-test.js index f51566b6c..8efc533f6 100644 --- a/packager/src/ModuleGraph/__tests__/ModuleGraph-test.js +++ b/packager/src/ModuleGraph/__tests__/ModuleGraph-test.js @@ -11,7 +11,7 @@ jest.disableAutomock(); const ModuleGraph = require('../ModuleGraph'); -const defaults = require('../../../defaults'); +const defaults = require('../../defaults'); const FILE_TYPE = 'module'; diff --git a/packager/src/ModuleGraph/node-haste/node-haste.js b/packager/src/ModuleGraph/node-haste/node-haste.js index 39c0ee070..262b80c55 100644 --- a/packager/src/ModuleGraph/node-haste/node-haste.js +++ b/packager/src/ModuleGraph/node-haste/node-haste.js @@ -30,7 +30,7 @@ const Module = require('./Module'); const ModuleCache = require('./ModuleCache'); const ResolutionRequest = require('../../node-haste/DependencyGraph/ResolutionRequest'); -const defaults = require('../../../defaults'); +const defaults = require('../../defaults'); import type {Moduleish, Packageish} from '../../node-haste/DependencyGraph/ResolutionRequest'; diff --git a/packager/src/ModuleGraph/output/__tests__/indexed-ram-bundle-test.js b/packager/src/ModuleGraph/output/__tests__/indexed-ram-bundle-test.js index ed29da34a..8305146c3 100644 --- a/packager/src/ModuleGraph/output/__tests__/indexed-ram-bundle-test.js +++ b/packager/src/ModuleGraph/output/__tests__/indexed-ram-bundle-test.js @@ -286,7 +286,7 @@ function countLines(module) { function lineByLineMap(file) { return { - file: file, + file, mappings: 'AAAA;', names: [], sources: [file], diff --git a/packager/src/ModuleGraph/worker/__tests__/optimize-module-test.js b/packager/src/ModuleGraph/worker/__tests__/optimize-module-test.js index 8863e1ed5..4f2c023e1 100644 --- a/packager/src/ModuleGraph/worker/__tests__/optimize-module-test.js +++ b/packager/src/ModuleGraph/worker/__tests__/optimize-module-test.js @@ -12,7 +12,7 @@ jest.disableAutomock(); const optimizeModule = require('../optimize-module'); const transformModule = require('../transform-module'); -const transformer = require('../../../../transformer.js'); +const transformer = require('../../../transformer.js'); const {SourceMapConsumer} = require('source-map'); const {fn} = require('../../test-helpers'); diff --git a/packager/src/ModuleGraph/worker/transform-module.js b/packager/src/ModuleGraph/worker/transform-module.js index b5704e4fe..d361ae469 100644 --- a/packager/src/ModuleGraph/worker/transform-module.js +++ b/packager/src/ModuleGraph/worker/transform-module.js @@ -15,7 +15,7 @@ const JsFileWrapping = require('./JsFileWrapping'); const asyncify = require('async/asyncify'); const collectDependencies = require('./collect-dependencies'); -const defaults = require('../../../defaults'); +const defaults = require('../../defaults'); const docblock = require('../../node-haste/DependencyGraph/docblock'); const generate = require('./generate'); const path = require('path'); diff --git a/packager/src/Resolver/__tests__/Resolver-test.js b/packager/src/Resolver/__tests__/Resolver-test.js index ae4330c69..353a68480 100644 --- a/packager/src/Resolver/__tests__/Resolver-test.js +++ b/packager/src/Resolver/__tests__/Resolver-test.js @@ -11,7 +11,7 @@ jest.useRealTimers(); jest.unmock('../'); -jest.unmock('../../../defaults'); +jest.unmock('../../defaults'); jest.mock('path'); const {join: pathJoin} = require.requireActual('path'); diff --git a/packager/src/Resolver/index.js b/packager/src/Resolver/index.js index b28d0bd9f..cedd09055 100644 --- a/packager/src/Resolver/index.js +++ b/packager/src/Resolver/index.js @@ -13,7 +13,7 @@ const DependencyGraph = require('../node-haste/DependencyGraph'); -const defaults = require('../../defaults'); +const defaults = require('../defaults'); const pathJoin = require('path').join; import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; diff --git a/packager/src/Server/index.js b/packager/src/Server/index.js index deb3fe87d..bff8d49b9 100644 --- a/packager/src/Server/index.js +++ b/packager/src/Server/index.js @@ -15,7 +15,7 @@ const AssetServer = require('../AssetServer'); const Bundler = require('../Bundler'); const MultipartResponse = require('./MultipartResponse'); -const defaults = require('../../defaults'); +const defaults = require('../defaults'); const emptyFunction = require('fbjs/lib/emptyFunction'); const mime = require('mime-types'); const parsePlatformFilePath = require('../node-haste/lib/parsePlatformFilePath'); diff --git a/packager/babelRegisterOnly.js b/packager/src/babelRegisterOnly.js similarity index 100% rename from packager/babelRegisterOnly.js rename to packager/src/babelRegisterOnly.js diff --git a/packager/blacklist.js b/packager/src/blacklist.js similarity index 100% rename from packager/blacklist.js rename to packager/src/blacklist.js diff --git a/packager/defaults.js b/packager/src/defaults.js similarity index 59% rename from packager/defaults.js rename to packager/src/defaults.js index 7f6c2e721..f5288937d 100644 --- a/packager/defaults.js +++ b/packager/src/defaults.js @@ -19,20 +19,20 @@ exports.assetExts = [ exports.sourceExts = ['js', 'json']; -exports.moduleSystem = require.resolve('./src/Resolver/polyfills/require.js'); +exports.moduleSystem = require.resolve('./Resolver/polyfills/require.js'); exports.platforms = ['ios', 'android', 'windows', 'web']; exports.polyfills = [ - require.resolve('./src/Resolver/polyfills/Object.es6.js'), - require.resolve('./src/Resolver/polyfills/console.js'), - require.resolve('./src/Resolver/polyfills/error-guard.js'), - require.resolve('./src/Resolver/polyfills/Number.es6.js'), - require.resolve('./src/Resolver/polyfills/String.prototype.es6.js'), - require.resolve('./src/Resolver/polyfills/Array.prototype.es6.js'), - require.resolve('./src/Resolver/polyfills/Array.es6.js'), - require.resolve('./src/Resolver/polyfills/Object.es7.js'), - require.resolve('./src/Resolver/polyfills/babelHelpers.js'), + require.resolve('./Resolver/polyfills/Object.es6.js'), + require.resolve('./Resolver/polyfills/console.js'), + require.resolve('./Resolver/polyfills/error-guard.js'), + require.resolve('./Resolver/polyfills/Number.es6.js'), + require.resolve('./Resolver/polyfills/String.prototype.es6.js'), + require.resolve('./Resolver/polyfills/Array.prototype.es6.js'), + require.resolve('./Resolver/polyfills/Array.es6.js'), + require.resolve('./Resolver/polyfills/Object.es7.js'), + require.resolve('./Resolver/polyfills/babelHelpers.js'), ]; exports.providesModuleNodeModules = [ diff --git a/packager/index.js b/packager/src/index.js similarity index 88% rename from packager/index.js rename to packager/src/index.js index bac1468d5..64ad2abab 100644 --- a/packager/index.js +++ b/packager/src/index.js @@ -11,18 +11,18 @@ 'use strict'; -const Logger = require('./src/Logger'); -const TransformCaching = require('./src/lib/TransformCaching'); +const Logger = require('./Logger'); +const TransformCaching = require('./lib/TransformCaching'); const debug = require('debug'); const invariant = require('fbjs/lib/invariant'); -import type {PostProcessModules, PostMinifyProcess} from './src/Bundler'; -import type Server from './src/Server'; -import type {GlobalTransformCache} from './src/lib/GlobalTransformCache'; -import type {TransformCache} from './src/lib/TransformCaching'; -import type {Reporter} from './src/lib/reporting'; -import type {HasteImpl} from './src/node-haste/Module'; +import type {PostProcessModules, PostMinifyProcess} from './Bundler'; +import type Server from './Server'; +import type {GlobalTransformCache} from './lib/GlobalTransformCache'; +import type {TransformCache} from './lib/TransformCaching'; +import type {Reporter} from './lib/reporting'; +import type {HasteImpl} from './node-haste/Module'; exports.createServer = createServer; exports.Logger = Logger; @@ -78,7 +78,7 @@ function assertPublicBundleOptions(bo: mixed): PublicBundleOptions { exports.buildBundle = function(options: Options, bundleOptions: PublicBundleOptions) { var server = createNonPersistentServer(options); - const ServerClass = require('./src/Server'); + const ServerClass = require('./Server'); return server.buildBundle({ ...ServerClass.DEFAULT_BUNDLE_OPTIONS, ...assertPublicBundleOptions(bundleOptions), @@ -129,7 +129,7 @@ function createServer(options: StrictOptions): Server { } const serverOptions = Object.assign({}, options); delete serverOptions.verbose; - const ServerClass = require('./src/Server'); + const ServerClass = require('./Server'); return new ServerClass(serverOptions); } @@ -138,7 +138,7 @@ function createNonPersistentServer(options: Options): Server { // It's unsound to set-up the reporter here, // but this allows backward compatibility. reporter: options.reporter == null - ? require('./src/lib/reporting').nullReporter + ? require('./lib/reporting').nullReporter : options.reporter, ...options, watch: !options.nonPersistent, diff --git a/packager/src/node-haste/Module.js b/packager/src/node-haste/Module.js index 670f69023..fa11ef95d 100644 --- a/packager/src/node-haste/Module.js +++ b/packager/src/node-haste/Module.js @@ -18,7 +18,6 @@ const fs = require('fs'); const invariant = require('fbjs/lib/invariant'); const isAbsolutePath = require('absolute-path'); const jsonStableStringify = require('json-stable-stringify'); -const path = require('path'); const {join: joinPath, relative: relativePath, extname} = require('path'); diff --git a/packager/rn-cli.config.js b/packager/src/rn-cli.config.js similarity index 100% rename from packager/rn-cli.config.js rename to packager/src/rn-cli.config.js diff --git a/packager/setupNodePolyfills.js b/packager/src/setupNodePolyfills.js similarity index 100% rename from packager/setupNodePolyfills.js rename to packager/src/setupNodePolyfills.js diff --git a/packager/src/shared/output/bundle.js b/packager/src/shared/output/bundle.js index cce54c6a8..bf5eb73e2 100644 --- a/packager/src/shared/output/bundle.js +++ b/packager/src/shared/output/bundle.js @@ -50,7 +50,7 @@ function saveBundleAndMap( bundleEncoding: encoding, dev, sourcemapOutput, - sourcemapSourcesRoot + sourcemapSourcesRoot, } = options; log('start'); diff --git a/packager/src/shared/output/unbundle/as-assets.js b/packager/src/shared/output/unbundle/as-assets.js index e340b31d5..8ca1652df 100644 --- a/packager/src/shared/output/unbundle/as-assets.js +++ b/packager/src/shared/output/unbundle/as-assets.js @@ -78,7 +78,7 @@ function saveAsAssets( return Promise.all([ writeUnbundle, - sourcemapOutput && writeSourceMap(sourcemapOutput, JSON.stringify(sourceMap), log) + sourcemapOutput && writeSourceMap(sourcemapOutput, JSON.stringify(sourceMap), log), ]); } diff --git a/packager/src/shared/output/unbundle/as-indexed-file.js b/packager/src/shared/output/unbundle/as-indexed-file.js index c594b6bba..d636455bc 100644 --- a/packager/src/shared/output/unbundle/as-indexed-file.js +++ b/packager/src/shared/output/unbundle/as-indexed-file.js @@ -190,7 +190,7 @@ function buildTableAndContents( return [ fileHeader, table, - startupCodeBuffer + startupCodeBuffer, ].concat(moduleBuffers.map(({buffer}) => buffer)); } diff --git a/packager/transformer.js b/packager/src/transformer.js similarity index 95% rename from packager/transformer.js rename to packager/src/transformer.js index 04360af93..d70b41aa0 100644 --- a/packager/transformer.js +++ b/packager/src/transformer.js @@ -23,10 +23,10 @@ const makeHMRConfig = require('babel-preset-react-native/configs/hmr'); const path = require('path'); const resolvePlugins = require('babel-preset-react-native/lib/resolvePlugins'); -const {compactMapping} = require('./src/Bundler/source-map'); +const {compactMapping} = require('./Bundler/source-map'); import type {Plugins as BabelPlugins} from 'babel-core'; -import type {Transformer, TransformOptions} from './src/JSTransformer/worker'; +import type {Transformer, TransformOptions} from './JSTransformer/worker'; const cacheKeyParts = [ fs.readFileSync(__filename), @@ -63,7 +63,7 @@ const getBabelRC = (function() { if (!projectBabelRCPath || !fs.existsSync(projectBabelRCPath)) { babelRC = json5.parse( fs.readFileSync( - path.resolve(__dirname, 'rn-babelrc.json')) + path.resolve(__dirname, '..', 'rn-babelrc.json')) ); // Require the babel-preset's listed in the default babel config diff --git a/setupBabel.js b/setupBabel.js index d23ac2f42..23741c5ea 100644 --- a/setupBabel.js +++ b/setupBabel.js @@ -9,14 +9,12 @@ 'use strict'; -const babelRegisterOnly = require('./packager/babelRegisterOnly'); +const babelRegisterOnly = require('./packager/src/babelRegisterOnly'); const escapeRegExp = require('lodash/escapeRegExp'); const path = require('path'); const BABEL_ENABLED_PATHS = [ - 'packager/index.js', 'packager/src', - 'packager/transformer.js', 'local-cli', ];