Add a bundle type to logger output and type

Reviewed By: rafeca

Differential Revision: D6405599

fbshipit-source-id: 2f3da971d55fae28fbd94ed9f60d3bc2be176d6a
This commit is contained in:
Peter van der Zee 2017-11-28 04:41:10 -08:00 committed by Facebook Github Bot
parent b0de96c74a
commit 37995e2196
8 changed files with 24 additions and 7 deletions

View File

@ -35,6 +35,7 @@ module.exports = function getBundlingOptionsForHmr(
return {
...mainOptions,
assetPlugins: [],
bundleType: 'hmr',
dev: true,
entryModuleOnly: false,
excludeSource: false,

View File

@ -189,6 +189,7 @@ describe('processRequest', () => {
expect(response.body).toEqual('this is the source');
expect(Serializers.fullBundle).toBeCalledWith(expect.any(DeltaBundler), {
assetPlugins: [],
bundleType: 'bundle',
deltaBundleId: expect.any(String),
dev: true,
entryFile: 'index.ios.js',
@ -218,6 +219,7 @@ describe('processRequest', () => {
expect(response.body).toEqual('this is the source');
expect(Serializers.fullBundle).toBeCalledWith(expect.any(DeltaBundler), {
assetPlugins: [],
bundleType: 'bundle',
deltaBundleId: expect.any(String),
dev: true,
entryFile: 'index.js',
@ -247,6 +249,7 @@ describe('processRequest', () => {
expect(response.body).toEqual('this is the source');
expect(Serializers.fullBundle).toBeCalledWith(expect.any(DeltaBundler), {
assetPlugins: ['assetPlugin1', 'assetPlugin2'],
bundleType: 'bundle',
deltaBundleId: expect.any(String),
dev: true,
entryFile: 'index.js',

View File

@ -258,6 +258,7 @@ class Server {
const bundleOptions = {
...Server.DEFAULT_BUNDLE_OPTIONS,
...options,
bundleType: 'delta',
deltaBundleId: null,
};
@ -754,6 +755,8 @@ class Server {
/* $FlowFixMe: `pathname` could be empty for an invalid URL */
const pathname = decodeURIComponent(urlObj.pathname);
let isMap = false;
// Backwards compatibility. Options used to be as added as '.' to the
// entry module name. We can safely remove these options.
const entryFile =
@ -761,11 +764,14 @@ class Server {
.replace(/^\//, '')
.split('.')
.filter(part => {
if (part === 'map') {
isMap = true;
return false;
}
if (
part === 'includeRequire' ||
part === 'runModule' ||
part === 'bundle' ||
part === 'map' ||
part === 'delta' ||
part === 'assets'
) {
@ -797,12 +803,18 @@ class Server {
'excludeSource',
false,
);
const includeSource = this._getBoolOptionFromQuery(
urlObj.query,
'inlineSourceMap',
false,
);
return {
sourceMapUrl: url.format({
...urlObj,
pathname: pathname.replace(/\.(bundle|delta)$/, '.map'),
}),
bundleType: isMap ? 'map' : deltaBundleId ? 'delta' : 'bundle',
entryFile,
deltaBundleId,
dev,
@ -811,11 +823,7 @@ class Server {
hot: true,
runBeforeMainModule: this._opts.getModulesRunBeforeMainModule(entryFile),
runModule: this._getBoolOptionFromQuery(urlObj.query, 'runModule', true),
inlineSourceMap: this._getBoolOptionFromQuery(
urlObj.query,
'inlineSourceMap',
false,
),
inlineSourceMap: includeSource,
isolateModuleIDs: false,
platform,
resolutionResponse: null,

View File

@ -112,6 +112,7 @@ exports.build = async function(
const result = await server.build({
...ServerClass.DEFAULT_BUNDLE_OPTIONS,
...assertPublicBundleOptions(bundleOptions),
bundleType: 'todo',
});
server.end();

View File

@ -113,7 +113,7 @@ class TerminalReporter {
const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
return (
chalk.inverse.green.bold(' BUNDLE ') +
chalk.inverse.green.bold(` ${bundleOptions.bundleType.toUpperCase()} `) +
chalk.dim(` [${platform}${devOrProd}${min}] ${dirName}/`) +
chalk.bold(fileName) +
' ' +

View File

@ -29,6 +29,7 @@ function buildBundle(
return packagerClient.build({
...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOptions,
bundleType: 'bundle',
isolateModuleIDs: true,
});
}

View File

@ -28,6 +28,7 @@ async function buildBundle(
const options = {
...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOptions,
bundleType: 'ram',
isolateModuleIDs: true,
};
return await packagerClient.getRamBundleInfo(options);

View File

@ -24,10 +24,12 @@ import type {TransformCache} from '../lib/TransformCaching';
import type {Reporter} from '../lib/reporting';
import type {HasteImpl} from '../node-haste/Module';
type BundleType = 'bundle' | 'delta' | 'map' | 'ram' | 'cli' | 'hmr' | 'todo';
type SourceMapOrMappings = SourceMap | Array<RawMapping>;
export type BundleOptions = {
+assetPlugins: Array<string>,
bundleType: BundleType,
dev: boolean,
entryFile: string,
+entryModuleOnly: boolean,