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 3cf8242128
commit f7ad406c23
6 changed files with 58 additions and 10 deletions

View File

@ -26,6 +26,8 @@ const {isMappingsMap} = require('../lib/SourceMap');
import type {IndexMap, MappingsMap, SourceMap} from '../lib/SourceMap';
import type {GetSourceOptions, FinalizeOptions} from './BundleBase';
import type {PostProcessBundleSourcemap} from './index.js';
export type Unbundle = {
startupModules: Array<*>,
lazyModules: Array<*>,
@ -47,12 +49,14 @@ class Bundle extends BundleBase {
_sourceMap: string | null;
_sourceMapFormat: SourceMapFormat;
_sourceMapUrl: ?string;
postProcessBundleSourcemap: ?PostProcessBundleSourcemap;
constructor({sourceMapUrl, dev, minify, ramGroups}: {
constructor({sourceMapUrl, dev, minify, ramGroups, postProcessBundleSourcemap}: {
sourceMapUrl: ?string,
dev?: boolean,
minify?: boolean,
ramGroups?: Array<string>,
postProcessBundleSourcemap?: PostProcessBundleSourcemap,
} = {}) {
super();
this._sourceMap = null;
@ -64,6 +68,7 @@ class Bundle extends BundleBase {
this._ramGroups = ramGroups;
this._ramBundle = null; // cached RAM Bundle
this.postProcessBundleSourcemap = postProcessBundleSourcemap;
}
addModule(

View File

@ -112,6 +112,12 @@ export type PostMinifyProcess = ({
map: MappingsMap,
}) => {code: string, map: MappingsMap};
export type PostProcessBundleSourcemap = ({
code: string,
map: string,
outFileName: string,
}) => {code: string, map: string};
type Options = {|
+allowBundleUpdates: boolean,
+assetExts: Array<string>,
@ -126,6 +132,7 @@ type Options = {|
+platforms: Array<string>,
+polyfillModuleNames: Array<string>,
+postMinifyProcess: PostMinifyProcess,
+postProcessBundleSourcemap?: PostProcessBundleSourcemap,
+postProcessModules?: PostProcessModules,
+projectRoots: $ReadOnlyArray<string>,
+providesModuleNodeModules?: Array<string>,
@ -251,11 +258,17 @@ class Bundler {
sourceMapUrl: ?string,
}): Promise<Bundle> {
const {dev, minify, unbundle} = options;
const postProcessBundleSourcemap = this._opts.postProcessBundleSourcemap;
return this._resolverPromise.then(
resolver => resolver.getModuleSystemDependencies({dev, unbundle}),
).then(moduleSystemDeps => this._bundle({
...options,
bundle: new Bundle({dev, minify, sourceMapUrl: options.sourceMapUrl}),
bundle: new Bundle({
dev,
minify,
sourceMapUrl: options.sourceMapUrl,
postProcessBundleSourcemap,
}),
moduleSystemDeps,
}));
}

View File

@ -37,6 +37,7 @@ import type {
GetTransformOptions,
PostProcessModules,
PostMinifyProcess,
PostProcessBundleSourcemap,
} from '../Bundler';
import type {TransformCache} from '../lib/TransformCaching';
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
@ -76,6 +77,7 @@ type Options = {
polyfillModuleNames?: Array<string>,
postProcessModules?: PostProcessModules,
postMinifyProcess: PostMinifyProcess,
postProcessBundleSourcemap: PostProcessBundleSourcemap,
projectRoots: $ReadOnlyArray<string>,
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
@ -134,6 +136,7 @@ class Server {
polyfillModuleNames: Array<string>,
postProcessModules?: PostProcessModules,
postMinifyProcess: PostMinifyProcess,
postProcessBundleSourcemap: PostProcessBundleSourcemap,
projectRoots: $ReadOnlyArray<string>,
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
@ -180,6 +183,7 @@ class Server {
polyfillModuleNames: options.polyfillModuleNames || [],
postProcessModules: options.postProcessModules,
postMinifyProcess: options.postMinifyProcess,
postProcessBundleSourcemap: options.postProcessBundleSourcemap,
projectRoots: options.projectRoots,
providesModuleNodeModules: options.providesModuleNodeModules,
reporter: options.reporter,

View File

@ -20,7 +20,7 @@ const invariant = require('fbjs/lib/invariant');
const {fromRawMappings, compactMapping} = require('./Bundler/source-map');
import type {PostProcessModules, PostMinifyProcess} from './Bundler';
import type {PostProcessModules, PostMinifyProcess, PostProcessBundleSourcemap} from './Bundler';
import type Server from './Server';
import type {GlobalTransformCache} from './lib/GlobalTransformCache';
import type {TransformCache} from './lib/TransformCaching';
@ -41,6 +41,7 @@ type Options = {
+maxWorkers?: number,
nonPersistent?: boolean,
postMinifyProcess?: PostMinifyProcess,
postProcessBundleSourcemap?: PostProcessBundleSourcemap,
postProcessModules?: PostProcessModules,
projectRoots: $ReadOnlyArray<string>,
reporter?: Reporter,

View File

@ -54,7 +54,10 @@ function saveBundleAndMap(
} = options;
log('start');
const codeWithMap = createCodeWithMap(bundle, !!dev, sourcemapSourcesRoot);
const origCodeWithMap = createCodeWithMap(bundle, !!dev, sourcemapSourcesRoot);
const codeWithMap = bundle.postProcessBundleSourcemap ?
bundle.postProcessBundleSourcemap({...origCodeWithMap, outFileName: bundleOutput}) :
origCodeWithMap;
log('finish');
log('Writing bundle output to:', bundleOutput);

View File

@ -206,7 +206,7 @@ babel-code-frame@6.22.0, babel-code-frame@^6.16.0, babel-code-frame@^6.22.0:
esutils "^2.0.2"
js-tokens "^3.0.0"
babel-core@^6.0.0, babel-core@^6.23.1, babel-core@^6.24.1:
babel-core@^6.0.0, babel-core@^6.23.1, babel-core@^6.24.1, babel-core@^6.8.0:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.24.1.tgz#8c428564dce1e1f41fb337ec34f4c3b022b5ad83"
dependencies:
@ -239,7 +239,7 @@ babel-eslint@^7.1.1:
babel-types "^6.23.0"
babylon "^6.17.0"
babel-generator@^6.18.0, babel-generator@^6.24.1:
babel-generator@^6.18.0, babel-generator@^6.24.1, babel-generator@^6.8.0:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.24.1.tgz#e715f486c58ded25649d888944d52aa07c5d9497"
dependencies:
@ -668,7 +668,7 @@ babel-runtime@^6.22.0:
core-js "^2.4.0"
regenerator-runtime "^0.10.0"
babel-template@^6.16.0, babel-template@^6.24.1:
babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.9.0:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.24.1.tgz#04ae514f1f93b3a2537f2a0f60a5a45fb8308333"
dependencies:
@ -678,7 +678,7 @@ babel-template@^6.16.0, babel-template@^6.24.1:
babylon "^6.11.0"
lodash "^4.2.0"
babel-traverse@^6.18.0, babel-traverse@^6.23.1, babel-traverse@^6.24.1:
babel-traverse@^6.18.0, babel-traverse@^6.23.1, babel-traverse@^6.24.1, babel-traverse@^6.9.0:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.24.1.tgz#ab36673fd356f9a0948659e7b338d5feadb31695"
dependencies:
@ -692,7 +692,7 @@ babel-traverse@^6.18.0, babel-traverse@^6.23.1, babel-traverse@^6.24.1:
invariant "^2.2.0"
lodash "^4.2.0"
babel-types@^6.18.0, babel-types@^6.23.0, babel-types@^6.24.1:
babel-types@^6.18.0, babel-types@^6.23.0, babel-types@^6.24.1, babel-types@^6.9.0:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.24.1.tgz#a136879dc15b3606bda0d90c1fc74304c2ff0975"
dependencies:
@ -705,7 +705,7 @@ babylon@7.0.0-beta.8:
version "7.0.0-beta.8"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.8.tgz#2bdc5ae366041442c27e068cce6f0d7c06ea9949"
babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0, babylon@^6.17.0:
babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0, babylon@^6.17.0, babylon@^6.5.2:
version "6.17.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.1.tgz#17f14fddf361b695981fe679385e4f1c01ebd86f"
@ -713,6 +713,10 @@ balanced-match@^0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"
base62@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/base62/-/base62-1.2.0.tgz#31e7e560dc846c9f44c1a531df6514da35474157"
bcrypt-pbkdf@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz#63bc5dcb61331b92bc05fd528953c33462a06f8d"
@ -3055,6 +3059,20 @@ prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
prepack@^0.2.4:
version "0.2.4"
resolved "https://registry.yarnpkg.com/prepack/-/prepack-0.2.4.tgz#6b541b086cf7d67577dbc0bc2e941bdc14d989ca"
dependencies:
babel-core "^6.8.0"
babel-generator "^6.8.0"
babel-template "^6.9.0"
babel-traverse "^6.9.0"
babel-types "^6.9.0"
babylon "^6.5.2"
base62 "^1.1.2"
seedrandom "^2.4.2"
source-map "^0.5.6"
preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
@ -3373,6 +3391,10 @@ sax@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828"
seedrandom@^2.4.2:
version "2.4.3"
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-2.4.3.tgz#2438504dad33917314bff18ac4d794f16d6aaecc"
"semver@2 || 3 || 4 || 5", semver@5.x, semver@^5.0.1, semver@^5.1.0, semver@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"