packager: add preprocess for buck worker

Summary: For the Buck integration (work-in-progress), we want to add the ability to do some custom preprocessing similar to the packager server. The signature is different so I prefer to have a separate function for that. Also we don't need the transform options right now, I suggest we don't add them for now and add them later if necessary.

Reviewed By: davidaurelio

Differential Revision: D5094632

fbshipit-source-id: 1775ddef90b331deabc5be3e57a67436bce06c82
This commit is contained in:
Jean Lauliac
2017-05-22 09:03:36 -07:00
committed by Facebook Github Bot
parent 8f31444c60
commit bfc0e8c26f
4 changed files with 38 additions and 11 deletions
+12 -4
View File
@@ -22,6 +22,7 @@ import type {
GraphFn,
GraphResult,
Module,
PostProcessModules,
} from './types.flow';
type BuildFn = (
@@ -37,6 +38,7 @@ type BuildOptions = {|
exports.createBuildSetup = (
graph: GraphFn,
postProcessModules: PostProcessModules,
translateDefaultsPath: string => string = x => x,
): BuildFn =>
(entryPoints, options, callback) => {
@@ -51,10 +53,16 @@ exports.createBuildSetup = (
const graphOnlyModules = seq(graphWithOptions, getModules);
parallel({
graph: cb => graphWithOptions(
entryPoints,
cb,
),
graph: cb => graphWithOptions(entryPoints, (error, result) => {
if (error) {
cb(error);
return;
}
/* $FlowFixMe: not undefined if there is no error */
const {modules, entryModules} = result;
const prModules = postProcessModules(modules, [...entryPoints]);
cb(null, {modules: prModules, entryModules});
}),
moduleSystem: cb => graphOnlyModules(
[translateDefaultsPath(defaults.moduleSystem)],
cb,