packager: buck: transform-module: add support for assets
Reviewed By: davidaurelio Differential Revision: D4868312 fbshipit-source-id: 44d20a5ed73637a9b3f43a99b5c82931f3e15dc6
This commit is contained in:
parent
1c53c9b20f
commit
4ab4df07af
|
@ -30,7 +30,7 @@ export type File = {|
|
||||||
type: FileTypes,
|
type: FileTypes,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
type FileTypes = 'module' | 'script';
|
type FileTypes = 'module' | 'script' | 'asset';
|
||||||
|
|
||||||
export type GraphFn = (
|
export type GraphFn = (
|
||||||
entryPoints: Iterable<string>,
|
entryPoints: Iterable<string>,
|
||||||
|
|
|
@ -48,6 +48,11 @@ function transformModule(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.filename.endsWith('.png')) {
|
||||||
|
transformAsset(code, options, callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const {filename, transformer, variants = defaultVariants} = options;
|
const {filename, transformer, variants = defaultVariants} = options;
|
||||||
const tasks = {};
|
const tasks = {};
|
||||||
Object.keys(variants).forEach(name => {
|
Object.keys(variants).forEach(name => {
|
||||||
|
@ -114,7 +119,7 @@ function transformJSON(json, options, callback) {
|
||||||
file: filename,
|
file: filename,
|
||||||
hasteID: value.name,
|
hasteID: value.name,
|
||||||
transformed,
|
transformed,
|
||||||
type: 'module',
|
type: 'asset',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (basename(filename) === 'package.json') {
|
if (basename(filename) === 'package.json') {
|
||||||
|
@ -128,6 +133,16 @@ function transformJSON(json, options, callback) {
|
||||||
callback(null, result);
|
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) {
|
function makeResult(ast, filename, sourceCode, isPolyfill = false) {
|
||||||
let dependencies, dependencyMapName, file;
|
let dependencies, dependencyMapName, file;
|
||||||
if (isPolyfill) {
|
if (isPolyfill) {
|
||||||
|
|
Loading…
Reference in New Issue