From ba8bbcbe2f319406d0d606162d78d9533b1349bf Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Mon, 7 Nov 2016 03:36:51 -0800 Subject: [PATCH] Remove prepack bundle functionality Reviewed By: davidaurelio Differential Revision: D4138495 fbshipit-source-id: 52793fc1a8ef8b2fc461156607c360f34c4cb362 --- local-cli/bundle/bundle.js | 3 +- local-cli/bundle/bundleCommandLineArgs.js | 6 - local-cli/bundle/output/prepack.js | 34 ---- .../src/Bundler/PrepackBundle.js | 149 ------------------ .../src/Bundler/__tests__/Bundler-test.js | 1 - packager/react-packager/src/Bundler/index.js | 41 ----- packager/react-packager/src/Server/index.js | 11 -- 7 files changed, 1 insertion(+), 244 deletions(-) delete mode 100644 local-cli/bundle/output/prepack.js delete mode 100644 packager/react-packager/src/Bundler/PrepackBundle.js diff --git a/local-cli/bundle/bundle.js b/local-cli/bundle/bundle.js index 8f2b1816dc..5077a9947d 100644 --- a/local-cli/bundle/bundle.js +++ b/local-cli/bundle/bundle.js @@ -9,7 +9,6 @@ const buildBundle = require('./buildBundle'); const outputBundle = require('./output/bundle'); -const outputPrepack = require('./output/prepack'); const bundleCommandLineArgs = require('./bundleCommandLineArgs'); /** @@ -17,7 +16,7 @@ const bundleCommandLineArgs = require('./bundleCommandLineArgs'); */ function bundleWithOutput(argv, config, args, output, packagerInstance) { if (!output) { - output = args.prepack ? outputPrepack : outputBundle; + output = outputBundle; } return buildBundle(args, config, output, packagerInstance); } diff --git a/local-cli/bundle/bundleCommandLineArgs.js b/local-cli/bundle/bundleCommandLineArgs.js index 41a3478d53..61430a7e04 100644 --- a/local-cli/bundle/bundleCommandLineArgs.js +++ b/local-cli/bundle/bundleCommandLineArgs.js @@ -24,12 +24,6 @@ module.exports = [ description: 'If false, warnings are disabled and the bundle is minified', parse: (val) => val === 'false' ? false : true, default: true, - }, { - command: '--prepack', - description: 'When passed, the output bundle will use the Prepack format.', - }, { - command: '--bridge-config [string]', - description: 'File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json', }, { command: '--bundle-output ', description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle', diff --git a/local-cli/bundle/output/prepack.js b/local-cli/bundle/output/prepack.js deleted file mode 100644 index d13d44f8f8..0000000000 --- a/local-cli/bundle/output/prepack.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -'use strict'; - -const writeFile = require('./writeFile'); - -function buildPrepackBundle(packagerClient, requestOptions) { - return packagerClient.buildPrepackBundle(requestOptions); -} - -function savePrepackBundle(bundle, options, log) { - const { - bundleOutput, - bridgeConfig, - } = options; - - const result = bundle.build({ - batchedBridgeConfig: bridgeConfig - }); - - log('Writing prepack bundle output to:', bundleOutput); - const writePrepackBundle = writeFile(bundleOutput, result, 'ucs-2'); - writePrepackBundle.then(() => log('Done writing prepack bundle output')); - return writePrepackBundle; -} - -exports.build = buildPrepackBundle; -exports.save = savePrepackBundle; diff --git a/packager/react-packager/src/Bundler/PrepackBundle.js b/packager/react-packager/src/Bundler/PrepackBundle.js deleted file mode 100644 index 123d3297a5..0000000000 --- a/packager/react-packager/src/Bundler/PrepackBundle.js +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -'use strict'; - -const fs = require('fs'); - -class PrepackBundle { - constructor(sourceMapUrl) { - this._finalized = false; - this._moduleIds = Object.create(null); - this._modules = Object.create(null); - this._eagerModules = []; - this._mainModule = null; - this._assets = []; - this._sourceMapUrl = sourceMapUrl; - } - - addModule(id, module, deps, isPolyfill) { - this._modules[module.sourcePath] = { module, deps }; - this._moduleIds[id] = module.sourcePath; - if (isPolyfill) { - this._eagerModules.push(id); - } - } - - addAsset(asset) { - this._assets.push(asset); - } - - // Synchronously load a file path. - _loadFilename(path) { - const module = this._modules[path]; - if (!module) { - throw new Error('Could not find file "' + path + '" in preloaded files.'); - } - return module.module.code; - } - - // Synchronously resolve a relative require from a parent module. - _resolveFilename(parentPath, relativePath) { - if (!parentPath) { - const resolvedPath = this._moduleIds[relativePath]; - if (!resolvedPath) { - throw new Error('Could not resolve "' + relativePath + '".'); - } - return resolvedPath; - } - const deps = this._modules[parentPath].deps; - const resolvedPath = deps[relativePath]; - if (!resolvedPath) { - throw new Error( - 'Could not resolve "' + relativePath + '" from "' + parentPath + '".' - ); - } - return resolvedPath; - } - - build(options) { - var prepack = require('prepack'); - - var batchedBridgeConfig = (options && options.batchedBridgeConfig) || null; - if (typeof batchedBridgeConfig === 'string') { - batchedBridgeConfig = JSON.parse( - fs.readFileSync(batchedBridgeConfig, 'utf-8') - ); - } - - var options = { - batchedBridgeConfig: batchedBridgeConfig, - environment: 'react-native', - resolveFilename: this._resolveFilename.bind(this), - loadFilename: this._loadFilename.bind(this), - eagerModules: this._eagerModules - }; - - return prepack.compileModule(this._mainModule, options); - } - - finalize(options) { - options = options || {}; - if (options.runMainModule) { - options.runBeforeMainModule.forEach(this._addRequireCall, this); - this._mainModule = options.mainModuleId; - } - - Object.freeze(this._moduleIds); - Object.freeze(this._modules); - Object.freeze(this._assets); - Object.freeze(this._eagerModules); - this._finalized = true; - } - - _addRequireCall(moduleId) { - this._eagerModules.push(moduleId); - } - - _assertFinalized() { - if (!this._finalized) { - throw new Error('Bundle needs to be finalized before getting any source'); - } - } - - getAssets() { - return this._assets; - } - - toJSON() { - if (!this._finalized) { - throw new Error('Cannot serialize bundle unless finalized'); - } - - return { - modules: this._modules, - moduleIds: this._moduleIds, - assets: this._assets, - sourceMapUrl: this._sourceMapUrl, - mainModule: this._mainModule, - eagerModules: this._eagerModules, - }; - } - - static fromJSON(json) { - const bundle = new PrepackBundle(json.sourceMapUrl); - bundle._assets = json.assets; - bundle._moduleIds = json.moduleIds; - bundle._modules = json.modules; - bundle._sourceMapUrl = json.sourceMapUrl; - - bundle._eagerModules = json.eagerModules; - bundle._mainModule = json.mainModule; - - Object.freeze(bundle._moduleIds); - Object.freeze(bundle._modules); - Object.freeze(bundle._assets); - Object.freeze(bundle._eagerModules); - - bundle._finalized = true; - - return bundle; - } -} - -module.exports = PrepackBundle; diff --git a/packager/react-packager/src/Bundler/__tests__/Bundler-test.js b/packager/react-packager/src/Bundler/__tests__/Bundler-test.js index 6faf646b02..9ef47830e0 100644 --- a/packager/react-packager/src/Bundler/__tests__/Bundler-test.js +++ b/packager/react-packager/src/Bundler/__tests__/Bundler-test.js @@ -22,7 +22,6 @@ jest .mock('../../lib/declareOpts') .mock('../../Resolver') .mock('../Bundle') - .mock('../PrepackBundle') .mock('../HMRBundle') .mock('../../Logger') .mock('../../lib/declareOpts'); diff --git a/packager/react-packager/src/Bundler/index.js b/packager/react-packager/src/Bundler/index.js index d8544a8e00..26cdbe6355 100644 --- a/packager/react-packager/src/Bundler/index.js +++ b/packager/react-packager/src/Bundler/index.js @@ -18,7 +18,6 @@ const Transformer = require('../JSTransformer'); const Resolver = require('../Resolver'); const Bundle = require('./Bundle'); const HMRBundle = require('./HMRBundle'); -const PrepackBundle = require('./PrepackBundle'); const ModuleTransport = require('../lib/ModuleTransport'); const declareOpts = require('../lib/declareOpts'); const imageSize = require('image-size'); @@ -313,46 +312,6 @@ class Bundler { }); } - prepackBundle({ - entryFile, - runModule: runMainModule, - runBeforeMainModule, - sourceMapUrl, - dev, - platform, - assetPlugins, - }) { - const onModuleTransformed = ({module, transformed, response, bundle}) => { - const deps = Object.create(null); - const pairs = response.getResolvedDependencyPairs(module); - if (pairs) { - pairs.forEach(pair => { - deps[pair[0]] = pair[1].path; - }); - } - - return module.getName().then(name => { - bundle.addModule(name, transformed, deps, module.isPolyfill()); - }); - }; - const finalizeBundle = ({bundle, response}) => { - const {mainModuleId} = response; - bundle.finalize({runBeforeMainModule, runMainModule, mainModuleId}); - return bundle; - }; - - return this._buildBundle({ - entryFile, - dev, - platform, - onModuleTransformed, - finalizeBundle, - minify: false, - bundle: new PrepackBundle(sourceMapUrl), - assetPlugins, - }); - } - _buildBundle({ entryFile, dev, diff --git a/packager/react-packager/src/Server/index.js b/packager/react-packager/src/Server/index.js index 5c1eb615d3..178f7ea23d 100644 --- a/packager/react-packager/src/Server/index.js +++ b/packager/react-packager/src/Server/index.js @@ -329,17 +329,6 @@ class Server { }); } - buildPrepackBundle(options) { - return Promise.resolve().then(() => { - if (!options.platform) { - options.platform = getPlatformExtension(options.entryFile); - } - - const opts = bundleOpts(options); - return this._bundler.prepackBundle(opts); - }); - } - buildBundleFromUrl(reqUrl) { const options = this._getOptionsFromUrl(reqUrl); return this.buildBundle(options);