From 921005d44d2763c638444ca59069e618ef00b4fc 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 --- packages/metro-bundler/package.json | 11 ++++++---- .../src/Bundler/__tests__/Bundler-test.js | 2 +- packages/metro-bundler/src/Bundler/index.js | 2 +- .../src/JSTransformer/worker/index.js | 2 +- .../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 +- packages/metro-bundler/src/Resolver/index.js | 2 +- packages/metro-bundler/src/Server/index.js | 2 +- .../{ => src}/babelRegisterOnly.js | 0 packages/metro-bundler/{ => src}/blacklist.js | 0 packages/metro-bundler/{ => src}/defaults.js | 20 ++++++++--------- packages/metro-bundler/{ => src}/index.js | 22 +++++++++---------- .../metro-bundler/src/node-haste/Module.js | 1 - .../metro-bundler/{ => src}/rn-cli.config.js | 0 .../{ => src}/setupNodePolyfills.js | 0 .../metro-bundler/src/shared/output/bundle.js | 2 +- .../src/shared/output/unbundle/as-assets.js | 2 +- .../shared/output/unbundle/as-indexed-file.js | 2 +- .../metro-bundler/{ => src}/transformer.js | 6 ++--- 24 files changed, 46 insertions(+), 44 deletions(-) rename packages/metro-bundler/{ => src}/babelRegisterOnly.js (100%) rename packages/metro-bundler/{ => src}/blacklist.js (100%) rename packages/metro-bundler/{ => src}/defaults.js (59%) rename packages/metro-bundler/{ => src}/index.js (88%) rename packages/metro-bundler/{ => src}/rn-cli.config.js (100%) rename packages/metro-bundler/{ => src}/setupNodePolyfills.js (100%) rename packages/metro-bundler/{ => src}/transformer.js (95%) diff --git a/packages/metro-bundler/package.json b/packages/metro-bundler/package.json index e0d117d2..d3c85b23 100644 --- a/packages/metro-bundler/package.json +++ b/packages/metro-bundler/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/packages/metro-bundler/src/Bundler/__tests__/Bundler-test.js b/packages/metro-bundler/src/Bundler/__tests__/Bundler-test.js index f0dad065..ef3ea89c 100644 --- a/packages/metro-bundler/src/Bundler/__tests__/Bundler-test.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/Bundler/index.js b/packages/metro-bundler/src/Bundler/index.js index fe436b0e..778b6155 100644 --- a/packages/metro-bundler/src/Bundler/index.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/JSTransformer/worker/index.js b/packages/metro-bundler/src/JSTransformer/worker/index.js index 65e3b892..f88706ff 100644 --- a/packages/metro-bundler/src/JSTransformer/worker/index.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js b/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js index 3c00b69c..d6eea08a 100644 --- a/packages/metro-bundler/src/ModuleGraph/ModuleGraph.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/ModuleGraph/__tests__/ModuleGraph-test.js b/packages/metro-bundler/src/ModuleGraph/__tests__/ModuleGraph-test.js index f51566b6..8efc533f 100644 --- a/packages/metro-bundler/src/ModuleGraph/__tests__/ModuleGraph-test.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/ModuleGraph/node-haste/node-haste.js b/packages/metro-bundler/src/ModuleGraph/node-haste/node-haste.js index 39c0ee07..262b80c5 100644 --- a/packages/metro-bundler/src/ModuleGraph/node-haste/node-haste.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/ModuleGraph/output/__tests__/indexed-ram-bundle-test.js b/packages/metro-bundler/src/ModuleGraph/output/__tests__/indexed-ram-bundle-test.js index ed29da34..8305146c 100644 --- a/packages/metro-bundler/src/ModuleGraph/output/__tests__/indexed-ram-bundle-test.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/ModuleGraph/worker/__tests__/optimize-module-test.js b/packages/metro-bundler/src/ModuleGraph/worker/__tests__/optimize-module-test.js index 8863e1ed..4f2c023e 100644 --- a/packages/metro-bundler/src/ModuleGraph/worker/__tests__/optimize-module-test.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js b/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js index b5704e4f..d361ae46 100644 --- a/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/Resolver/__tests__/Resolver-test.js b/packages/metro-bundler/src/Resolver/__tests__/Resolver-test.js index ae4330c6..353a6848 100644 --- a/packages/metro-bundler/src/Resolver/__tests__/Resolver-test.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/Resolver/index.js b/packages/metro-bundler/src/Resolver/index.js index b28d0bd9..cedd0905 100644 --- a/packages/metro-bundler/src/Resolver/index.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index deb3fe87..bff8d49b 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/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/packages/metro-bundler/babelRegisterOnly.js b/packages/metro-bundler/src/babelRegisterOnly.js similarity index 100% rename from packages/metro-bundler/babelRegisterOnly.js rename to packages/metro-bundler/src/babelRegisterOnly.js diff --git a/packages/metro-bundler/blacklist.js b/packages/metro-bundler/src/blacklist.js similarity index 100% rename from packages/metro-bundler/blacklist.js rename to packages/metro-bundler/src/blacklist.js diff --git a/packages/metro-bundler/defaults.js b/packages/metro-bundler/src/defaults.js similarity index 59% rename from packages/metro-bundler/defaults.js rename to packages/metro-bundler/src/defaults.js index 7f6c2e72..f5288937 100644 --- a/packages/metro-bundler/defaults.js +++ b/packages/metro-bundler/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/packages/metro-bundler/index.js b/packages/metro-bundler/src/index.js similarity index 88% rename from packages/metro-bundler/index.js rename to packages/metro-bundler/src/index.js index bac1468d..64ad2aba 100644 --- a/packages/metro-bundler/index.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/node-haste/Module.js b/packages/metro-bundler/src/node-haste/Module.js index 670f6902..fa11ef95 100644 --- a/packages/metro-bundler/src/node-haste/Module.js +++ b/packages/metro-bundler/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/packages/metro-bundler/rn-cli.config.js b/packages/metro-bundler/src/rn-cli.config.js similarity index 100% rename from packages/metro-bundler/rn-cli.config.js rename to packages/metro-bundler/src/rn-cli.config.js diff --git a/packages/metro-bundler/setupNodePolyfills.js b/packages/metro-bundler/src/setupNodePolyfills.js similarity index 100% rename from packages/metro-bundler/setupNodePolyfills.js rename to packages/metro-bundler/src/setupNodePolyfills.js diff --git a/packages/metro-bundler/src/shared/output/bundle.js b/packages/metro-bundler/src/shared/output/bundle.js index cce54c6a..bf5eb73e 100644 --- a/packages/metro-bundler/src/shared/output/bundle.js +++ b/packages/metro-bundler/src/shared/output/bundle.js @@ -50,7 +50,7 @@ function saveBundleAndMap( bundleEncoding: encoding, dev, sourcemapOutput, - sourcemapSourcesRoot + sourcemapSourcesRoot, } = options; log('start'); diff --git a/packages/metro-bundler/src/shared/output/unbundle/as-assets.js b/packages/metro-bundler/src/shared/output/unbundle/as-assets.js index e340b31d..8ca1652d 100644 --- a/packages/metro-bundler/src/shared/output/unbundle/as-assets.js +++ b/packages/metro-bundler/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/packages/metro-bundler/src/shared/output/unbundle/as-indexed-file.js b/packages/metro-bundler/src/shared/output/unbundle/as-indexed-file.js index c594b6bb..d636455b 100644 --- a/packages/metro-bundler/src/shared/output/unbundle/as-indexed-file.js +++ b/packages/metro-bundler/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/packages/metro-bundler/transformer.js b/packages/metro-bundler/src/transformer.js similarity index 95% rename from packages/metro-bundler/transformer.js rename to packages/metro-bundler/src/transformer.js index 04360af9..d70b41aa 100644 --- a/packages/metro-bundler/transformer.js +++ b/packages/metro-bundler/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