diff --git a/packager/src/ModuleGraph/types.flow.js b/packager/src/ModuleGraph/types.flow.js index 19e557d78..92ecc3cea 100644 --- a/packager/src/ModuleGraph/types.flow.js +++ b/packager/src/ModuleGraph/types.flow.js @@ -126,6 +126,7 @@ export type TransformResults = {[string]: TransformResult}; export type TransformVariants = {[key: string]: Object}; export type TransformedFile = { + assetContent: ?string, code: string, file: string, hasteID: ?string, diff --git a/packager/src/ModuleGraph/worker/__tests__/wrap-worker-fn-test.js b/packager/src/ModuleGraph/worker/__tests__/wrap-worker-fn-test.js index 201d3201d..e543511da 100644 --- a/packager/src/ModuleGraph/worker/__tests__/wrap-worker-fn-test.js +++ b/packager/src/ModuleGraph/worker/__tests__/wrap-worker-fn-test.js @@ -33,9 +33,9 @@ describe('wrapWorkerFn:', () => { const fs = require('fs'); const mkdirp = require('mkdirp'); - it('reads the passed-in file synchronously as UTF-8', done => { + it('reads the passed-in file synchronously as buffer', done => { wrapped(infile, outfile, {}, () => { - expect(fs.readFileSync).toBeCalledWith(infile, 'utf8'); + expect(fs.readFileSync).toBeCalledWith(infile); done(); }); }); diff --git a/packager/src/ModuleGraph/worker/transform-module.js b/packager/src/ModuleGraph/worker/transform-module.js index 970bfd4db..aba4191aa 100644 --- a/packager/src/ModuleGraph/worker/transform-module.js +++ b/packager/src/ModuleGraph/worker/transform-module.js @@ -39,17 +39,18 @@ const moduleFactoryParameters = ['global', 'require', 'module', 'exports']; const polyfillFactoryParameters = ['global']; function transformModule( - code: string, + content: Buffer, options: TransformOptions, callback: Callback, ): void { - if (options.filename.endsWith('.json')) { - transformJSON(code, options, callback); + if (options.filename.endsWith('.png')) { + transformAsset(content, options, callback); return; } - if (options.filename.endsWith('.png')) { - transformAsset(code, options, callback); + const code = content.toString('utf8'); + if (options.filename.endsWith('.json')) { + transformJSON(code, options, callback); return; } @@ -85,6 +86,7 @@ function transformModule( const annotations = docblock.parseAsObject(docblock.extract(code)); callback(null, { + assetContent: null, code, file: filename, hasteID: annotations.providesModule || null, @@ -115,6 +117,7 @@ function transformJSON(json, options, callback) { .forEach(key => (transformed[key] = moduleData)); const result: TransformedFile = { + assetContent: null, code: json, file: filename, hasteID: value.name, @@ -133,9 +136,14 @@ function transformJSON(json, options, callback) { callback(null, result); } -function transformAsset(data, options, callback) { +function transformAsset( + content: Buffer, + options: TransformOptions, + callback: Callback, +) { callback(null, { - code: data, + assetContent: content.toString('base64'), + code: '', file: options.filename, hasteID: null, transformed: {}, diff --git a/packager/src/ModuleGraph/worker/wrap-worker-fn.js b/packager/src/ModuleGraph/worker/wrap-worker-fn.js index 83bc16a2e..8d3df8c50 100644 --- a/packager/src/ModuleGraph/worker/wrap-worker-fn.js +++ b/packager/src/ModuleGraph/worker/wrap-worker-fn.js @@ -19,7 +19,7 @@ import type {Callback} from '../types.flow'; type Path = string; type WorkerFn = ( - fileContents: string, + fileContents: Buffer, options: Options, callback: Callback, ) => void; @@ -39,7 +39,7 @@ function wrapWorkerFn( options: Options, callback: Callback<>, ) => { - const contents = fs.readFileSync(infile, 'utf8'); + const contents = fs.readFileSync(infile); workerFunction(contents, options, (error, result) => { if (error) { callback(error);