packager: buck worker: better types

Reviewed By: davidaurelio

Differential Revision: D4970025

fbshipit-source-id: 77db309befebe539d25bd8df1039e2304176ca3f
This commit is contained in:
Jean Lauliac
2017-05-02 03:41:39 -07:00
committed by Facebook Github Bot
parent cf4a98b053
commit 91ff2159d9
8 changed files with 72 additions and 50 deletions

View File

@@ -20,7 +20,8 @@ const {basename} = require('path');
import type {
Callback,
TransformedFile,
TransformedCodeFile,
TransformedSourceFile,
Transformer,
TransformerResult,
TransformResult,
@@ -41,7 +42,7 @@ const polyfillFactoryParameters = ['global'];
function transformModule(
content: Buffer,
options: TransformOptions,
callback: Callback<TransformedFile>,
callback: Callback<TransformedSourceFile>,
): void {
if (options.filename.endsWith('.png')) {
transformAsset(content, options, callback);
@@ -86,12 +87,15 @@ function transformModule(
const annotations = docblock.parseAsObject(docblock.extract(code));
callback(null, {
assetContent: null,
code,
file: filename,
hasteID: annotations.providesModule || null,
transformed,
type: options.polyfill ? 'script' : 'module',
type: 'code',
details: {
assetContent: null,
code,
file: filename,
hasteID: annotations.providesModule || null,
transformed,
type: options.polyfill ? 'script' : 'module',
},
});
});
return;
@@ -116,7 +120,7 @@ function transformJSON(json, options, callback) {
.keys(options.variants || defaultVariants)
.forEach(key => (transformed[key] = moduleData));
const result: TransformedFile = {
const result: TransformedCodeFile = {
assetContent: null,
code: json,
file: filename,
@@ -133,20 +137,19 @@ function transformJSON(json, options, callback) {
'react-native': value['react-native'],
};
}
callback(null, result);
callback(null, {type: 'code', details: result});
}
function transformAsset(
content: Buffer,
options: TransformOptions,
callback: Callback<TransformedFile>,
callback: Callback<TransformedSourceFile>,
) {
callback(null, {
assetContent: content.toString('base64'),
code: '',
file: options.filename,
hasteID: null,
transformed: {},
details: {
assetContentBase64: content.toString('base64'),
filePath: options.filename,
},
type: 'asset',
});
}