Packager postprocessing hook

Reviewed By: davidaurelio

Differential Revision: D5244060

fbshipit-source-id: 3f5f9ab9aeeb63eca13d6dab089c2bda42f70c33
This commit is contained in:
Chris Blappert 2017-06-26 10:30:18 -07:00 committed by Facebook Github Bot
parent 83faa4b608
commit c0505cedf1
2 changed files with 17 additions and 2 deletions

View File

@ -94,6 +94,7 @@ function buildBundle(
platforms: defaultPlatforms.concat(platforms), platforms: defaultPlatforms.concat(platforms),
postMinifyProcess: config.postMinifyProcess, postMinifyProcess: config.postMinifyProcess,
postProcessModules: config.postProcessModules, postProcessModules: config.postProcessModules,
postProcessBundleSourcemap: config.postProcessBundleSourcemap,
projectRoots: config.getProjectRoots(), projectRoots: config.getProjectRoots(),
providesModuleNodeModules: providesModuleNodeModules, providesModuleNodeModules: providesModuleNodeModules,
resetCache: args.resetCache, resetCache: args.resetCache,

View File

@ -20,7 +20,13 @@ const {providesModuleNodeModules} = require('metro-bundler/src/defaults');
const RN_CLI_CONFIG = 'rn-cli.config.js'; const RN_CLI_CONFIG = 'rn-cli.config.js';
import type {GetTransformOptions, PostMinifyProcess, PostProcessModules} from 'metro-bundler/src/Bundler'; import type {
GetTransformOptions,
PostMinifyProcess,
PostProcessModules,
// $FlowFixMe: Exported by metro bundler
PostProcessBundleSourcemap
} from 'metro-bundler/src/Bundler';
import type {HasteImpl} from 'metro-bundler/src/node-haste/Module'; import type {HasteImpl} from 'metro-bundler/src/node-haste/Module';
import type {TransformVariants} from 'metro-bundler/src/ModuleGraph/types.flow'; import type {TransformVariants} from 'metro-bundler/src/ModuleGraph/types.flow';
import type {PostProcessModules as PostProcessModulesForBuck} from 'metro-bundler/src/ModuleGraph/types.flow.js'; import type {PostProcessModules as PostProcessModulesForBuck} from 'metro-bundler/src/ModuleGraph/types.flow.js';
@ -86,7 +92,7 @@ export type ConfigT = {
/** /**
* An optional function that can modify the code and source map of bundle * An optional function that can modify the code and source map of bundle
* after the minifaction took place. * after the minifaction took place. (Function applied per module).
*/ */
postMinifyProcess: PostMinifyProcess, postMinifyProcess: PostMinifyProcess,
@ -96,6 +102,13 @@ export type ConfigT = {
*/ */
postProcessModules: PostProcessModules, postProcessModules: PostProcessModules,
/**
* An optional function that can modify the code and source map of the bundle
* before it is written. Applied once for the entire bundle, only works if
* output is a plainBundle.
*/
postProcessBundleSourcemap: PostProcessBundleSourcemap,
/** /**
* Same as `postProcessModules` but for the Buck worker. Eventually we do want * Same as `postProcessModules` but for the Buck worker. Eventually we do want
* to unify both variants. * to unify both variants.
@ -161,6 +174,7 @@ const Config = {
postMinifyProcess: x => x, postMinifyProcess: x => x,
postProcessModules: modules => modules, postProcessModules: modules => modules,
postProcessModulesForBuck: modules => modules, postProcessModulesForBuck: modules => modules,
postProcessBundleSourcemap: ({code, map, outFileName}) => ({code, map}),
transformVariants: () => ({default: {}}), transformVariants: () => ({default: {}}),
getWorkerPath: () => null, getWorkerPath: () => null,
}: ConfigT), }: ConfigT),