packager: buck: transform-module: add support for assets

Reviewed By: davidaurelio

Differential Revision: D4868312

fbshipit-source-id: 44d20a5ed73637a9b3f43a99b5c82931f3e15dc6
This commit is contained in:
Jean Lauliac 2017-04-18 09:31:16 -07:00 committed by Facebook Github Bot
parent 781b3b9bb7
commit e18d213116
2 changed files with 17 additions and 2 deletions

View File

@ -30,7 +30,7 @@ export type File = {|
type: FileTypes,
|};
type FileTypes = 'module' | 'script';
type FileTypes = 'module' | 'script' | 'asset';
export type GraphFn = (
entryPoints: Iterable<string>,

View File

@ -48,6 +48,11 @@ function transformModule(
return;
}
if (options.filename.endsWith('.png')) {
transformAsset(code, options, callback);
return;
}
const {filename, transformer, variants = defaultVariants} = options;
const tasks = {};
Object.keys(variants).forEach(name => {
@ -114,7 +119,7 @@ function transformJSON(json, options, callback) {
file: filename,
hasteID: value.name,
transformed,
type: 'module',
type: 'asset',
};
if (basename(filename) === 'package.json') {
@ -128,6 +133,16 @@ function transformJSON(json, options, callback) {
callback(null, result);
}
function transformAsset(data, options, callback) {
callback(null, {
code: data,
file: options.filename,
hasteID: null,
transformed: {},
type: 'module',
});
}
function makeResult(ast, filename, sourceCode, isPolyfill = false) {
let dependencies, dependencyMapName, file;
if (isPolyfill) {