packager: correct transform for assets to avoid string

Reviewed By: davidaurelio

Differential Revision: D4913509

fbshipit-source-id: 9997da819483056d896fedecdc47510ecd381c03
This commit is contained in:
Jean Lauliac
2017-04-20 03:00:10 -07:00
committed by Facebook Github Bot
parent 350b6c6d7f
commit 79d9fd8f83
4 changed files with 20 additions and 11 deletions
@@ -39,17 +39,18 @@ const moduleFactoryParameters = ['global', 'require', 'module', 'exports'];
const polyfillFactoryParameters = ['global'];
function transformModule(
code: string,
content: Buffer,
options: TransformOptions,
callback: Callback<TransformedFile>,
): 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<TransformedFile>,
) {
callback(null, {
code: data,
assetContent: content.toString('base64'),
code: '',
file: options.filename,
hasteID: null,
transformed: {},