From 15006cf0b482bedd20fa407971c26e450ca083da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Bigio?= Date: Wed, 28 Oct 2015 13:16:40 -0700 Subject: [PATCH] Add option to indicate bundle encoding Summary: public To improve cold start performance we want to be able to avoid decoding the bundle at all. To make that happen we need to be able to generate a bundle encoded on `ucs2`. This diff adds support for indicating the encoding the Packager should use for bundling. Reviewed By: davidaurelio Differential Revision: D2582365 fb-gh-sync-id: 905384272a668910c57a1a2ca6d1b723c39233f8 --- local-cli/bundle/__tests__/saveBundleAndMap-test.js | 6 ++++-- local-cli/bundle/buildBundle.js | 1 + local-cli/bundle/bundleCommandLineArgs.js | 5 +++++ local-cli/bundle/saveBundleAndMap.js | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/local-cli/bundle/__tests__/saveBundleAndMap-test.js b/local-cli/bundle/__tests__/saveBundleAndMap-test.js index f828b7346..1d155e273 100644 --- a/local-cli/bundle/__tests__/saveBundleAndMap-test.js +++ b/local-cli/bundle/__tests__/saveBundleAndMap-test.js @@ -41,10 +41,11 @@ describe('saveBundleAndMap', () => { saveBundleAndMap( codeWithMap, 'ios', - bundleOutput + bundleOutput, + 'utf8', ); - expect(fs.writeFileSync.mock.calls[0]).toEqual([bundleOutput, code]); + expect(fs.writeFileSync.mock.calls[0]).toEqual([bundleOutput, code, 'utf8']); }); it('should save sourcemaps if required so', () => { @@ -55,6 +56,7 @@ describe('saveBundleAndMap', () => { codeWithMap, 'ios', bundleOutput, + 'utf8', sourceMapOutput ); diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index d16485e26..1260868d5 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -49,6 +49,7 @@ function buildBundle(args, config) { outputBundle, args.platform, args['bundle-output'], + args['bundle-encoding'], args['sourcemap-output'], args['assets-dest'] )); diff --git a/local-cli/bundle/bundleCommandLineArgs.js b/local-cli/bundle/bundleCommandLineArgs.js index 77033b11a..353c7ea5f 100644 --- a/local-cli/bundle/bundleCommandLineArgs.js +++ b/local-cli/bundle/bundleCommandLineArgs.js @@ -32,6 +32,11 @@ module.exports = [ description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle', type: 'string', required: true, + }, { + command: 'bundle-encoding', + description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).', + type: 'string', + default: 'utf8', }, { command: 'sourcemap-output', description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map', diff --git a/local-cli/bundle/saveBundleAndMap.js b/local-cli/bundle/saveBundleAndMap.js index 27b987850..bb6bf2291 100644 --- a/local-cli/bundle/saveBundleAndMap.js +++ b/local-cli/bundle/saveBundleAndMap.js @@ -20,11 +20,12 @@ function saveBundleAndMap( codeWithMap, platform, bundleOutput, + encoding, sourcemapOutput, assetsDest ) { log('Writing bundle output to:', bundleOutput); - fs.writeFileSync(bundleOutput, sign(codeWithMap.code)); + fs.writeFileSync(bundleOutput, sign(codeWithMap.code), encoding); log('Done writing bundle output'); if (sourcemapOutput) {