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 { return {
...mainOptions, ...mainOptions,
assetPlugins: [], assetPlugins: [],
bundleType: 'hmr',
dev: true, dev: true,
entryModuleOnly: false, entryModuleOnly: false,
excludeSource: false, excludeSource: false,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,6 +28,7 @@ async function buildBundle(
const options = { const options = {
...Server.DEFAULT_BUNDLE_OPTIONS, ...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOptions, ...requestOptions,
bundleType: 'ram',
isolateModuleIDs: true, isolateModuleIDs: true,
}; };
return await packagerClient.getRamBundleInfo(options); 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 {Reporter} from '../lib/reporting';
import type {HasteImpl} from '../node-haste/Module'; import type {HasteImpl} from '../node-haste/Module';
type BundleType = 'bundle' | 'delta' | 'map' | 'ram' | 'cli' | 'hmr' | 'todo';
type SourceMapOrMappings = SourceMap | Array<RawMapping>; type SourceMapOrMappings = SourceMap | Array<RawMapping>;
export type BundleOptions = { export type BundleOptions = {
+assetPlugins: Array<string>, +assetPlugins: Array<string>,
bundleType: BundleType,
dev: boolean, dev: boolean,
entryFile: string, entryFile: string,
+entryModuleOnly: boolean, +entryModuleOnly: boolean,