mirror of https://github.com/status-im/metro.git
Unify source map approach for RA bundles on iOS/Android
Reviewed By: javache Differential Revision: D3229780 fb-gh-sync-id: a3148d7626b32a2e6803ae8c35ac75025a992a32 fbshipit-source-id: a3148d7626b32a2e6803ae8c35ac75025a992a32
This commit is contained in:
parent
cfdd04f2d2
commit
2a77da76ae
|
@ -107,61 +107,23 @@ class Bundle extends BundleBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
getUnbundle(type) {
|
getUnbundle(type) {
|
||||||
if (this._ramBundle) {
|
this.assertFinalized();
|
||||||
return this._ramBundle;
|
if (!this._ramBundle) {
|
||||||
}
|
const modules = this.getModules().slice();
|
||||||
|
|
||||||
switch (type) {
|
// separate modules we need to preload from the ones we don't
|
||||||
case 'INDEX':
|
const [startupModules, lazyModules] = partition(modules, shouldPreload);
|
||||||
this._ramBundle = this._getAsIndexedFileUnbundle();
|
|
||||||
break;
|
this._ramBundle = {
|
||||||
case 'ASSETS':
|
startupModules,
|
||||||
this._ramBundle = this._getAsAssetsUnbundle();
|
lazyModules,
|
||||||
break;
|
allModules: modules,
|
||||||
default:
|
};
|
||||||
throw new Error('Unkown RAM Bundle type:', type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._ramBundle;
|
return this._ramBundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
_getAsIndexedFileUnbundle() {
|
|
||||||
const modules = this.getModules();
|
|
||||||
|
|
||||||
// separate modules we need to preload from the ones we don't
|
|
||||||
const shouldPreload = (module) => module.meta && module.meta.preloaded;
|
|
||||||
const preloaded = modules.filter(module => shouldPreload(module));
|
|
||||||
const notPreloaded = modules.filter(module => !shouldPreload(module));
|
|
||||||
|
|
||||||
// code that will be executed on bridge start up
|
|
||||||
const startupCode = preloaded.map(({code}) => code).join('\n');
|
|
||||||
|
|
||||||
return {
|
|
||||||
// include copy of all modules on the order they're writen on the bundle:
|
|
||||||
// polyfills, preloaded, additional requires, non preloaded
|
|
||||||
allModules: preloaded.concat(notPreloaded),
|
|
||||||
startupCode, // no entries on the index for these modules, only the code
|
|
||||||
modules: notPreloaded, // we include both the code and entries on the index
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
_getAsAssetsUnbundle() {
|
|
||||||
const allModules = this.getModules().slice();
|
|
||||||
const prependedModules = this._numPrependedModules;
|
|
||||||
const requireCalls = this._numRequireCalls;
|
|
||||||
|
|
||||||
const modules =
|
|
||||||
allModules
|
|
||||||
.splice(prependedModules, allModules.length - requireCalls - prependedModules);
|
|
||||||
const startupCode = allModules.map(({code}) => code).join('\n');
|
|
||||||
|
|
||||||
return {
|
|
||||||
startupCode,
|
|
||||||
startupModules: allModules,
|
|
||||||
modules,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combine each of the sourcemaps multiple modules have into a single big
|
* Combine each of the sourcemaps multiple modules have into a single big
|
||||||
* one. This works well thanks to a neat trick defined on the sourcemap spec
|
* one. This works well thanks to a neat trick defined on the sourcemap spec
|
||||||
|
@ -351,4 +313,15 @@ function generateSourceMapForVirtualModule(module) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldPreload({meta}) {
|
||||||
|
return meta && meta.preloaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
function partition(array, predicate) {
|
||||||
|
const included = [];
|
||||||
|
const excluded = [];
|
||||||
|
array.forEach(item => (predicate(item) ? included : excluded).push(item));
|
||||||
|
return [included, excluded];
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Bundle;
|
module.exports = Bundle;
|
||||||
|
|
|
@ -556,12 +556,11 @@ class Bundler {
|
||||||
]).then((
|
]).then((
|
||||||
[name, {code, dependencies, dependencyOffsets, map, source}]
|
[name, {code, dependencies, dependencyOffsets, map, source}]
|
||||||
) => {
|
) => {
|
||||||
|
const {preloadedModules} = transformOptions.transform;
|
||||||
const preloaded =
|
const preloaded =
|
||||||
module.path === entryFilePath ||
|
module.path === entryFilePath ||
|
||||||
module.isPolyfill() || (
|
module.isPolyfill() ||
|
||||||
transformOptions.transform.preloadedModules &&
|
preloadedModules && preloadedModules.hasOwnProperty(module.path);
|
||||||
transformOptions.transform.preloadedModules.hasOwnProperty(module.path)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new ModuleTransport({
|
return new ModuleTransport({
|
||||||
name,
|
name,
|
||||||
|
@ -571,7 +570,7 @@ class Bundler {
|
||||||
meta: {dependencies, dependencyOffsets, preloaded},
|
meta: {dependencies, dependencyOffsets, preloaded},
|
||||||
sourceCode: source,
|
sourceCode: source,
|
||||||
sourcePath: module.path
|
sourcePath: module.path
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue