From 4ab4df07afb9766fda373138897bbbecb1d2d90d Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Tue, 18 Apr 2017 09:31:16 -0700 Subject: [PATCH] packager: buck: transform-module: add support for assets Reviewed By: davidaurelio Differential Revision: D4868312 fbshipit-source-id: 44d20a5ed73637a9b3f43a99b5c82931f3e15dc6 --- packager/src/ModuleGraph/types.flow.js | 2 +- .../src/ModuleGraph/worker/transform-module.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packager/src/ModuleGraph/types.flow.js b/packager/src/ModuleGraph/types.flow.js index 0e57f6bb3..19e557d78 100644 --- a/packager/src/ModuleGraph/types.flow.js +++ b/packager/src/ModuleGraph/types.flow.js @@ -30,7 +30,7 @@ export type File = {| type: FileTypes, |}; -type FileTypes = 'module' | 'script'; +type FileTypes = 'module' | 'script' | 'asset'; export type GraphFn = ( entryPoints: Iterable, diff --git a/packager/src/ModuleGraph/worker/transform-module.js b/packager/src/ModuleGraph/worker/transform-module.js index 1dca4e559..488d982d9 100644 --- a/packager/src/ModuleGraph/worker/transform-module.js +++ b/packager/src/ModuleGraph/worker/transform-module.js @@ -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) {