mirror of https://github.com/status-im/metro.git
metro-bundler: RAM bundles cannot contain scripts masquerading as modules
Reviewed By: davidaurelio Differential Revision: D6405614 fbshipit-source-id: 6c21fd30d6246f50c34e9f23a193452737a3b67b
This commit is contained in:
parent
ccd8eae0b0
commit
f434d43f54
|
@ -34,7 +34,7 @@ const idsForPath = ({path}) => {
|
|||
|
||||
beforeAll(() => {
|
||||
modules = [
|
||||
makeModule('a', [], 'script'),
|
||||
makeModule('a', []),
|
||||
makeModule('b', ['c']),
|
||||
makeModule('c', ['f']),
|
||||
makeModule('d', ['e']),
|
||||
|
|
|
@ -35,7 +35,7 @@ const idsForPath = ({path}) => {
|
|||
|
||||
beforeAll(() => {
|
||||
modules = [
|
||||
makeModule('a', [], 'script'),
|
||||
makeModule('a', []),
|
||||
makeModule('b'),
|
||||
makeModule('c', ['f']),
|
||||
makeModule('d', ['e']),
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
'use strict';
|
||||
|
||||
const buildSourceMapWithMetaData = require('../../shared/output/unbundle/build-unbundle-sourcemap-with-metadata.js');
|
||||
const invariant = require('invariant');
|
||||
|
||||
const {createRamBundleGroups} = require('../../Bundler/util');
|
||||
const {
|
||||
|
@ -36,6 +37,12 @@ function asIndexedRamBundle({
|
|||
const [startup, deferred] = partition(modules, preloadedModules);
|
||||
const startupModules = Array.from(concat(startup, requireCalls));
|
||||
const deferredModules = deferred.map(m => toModuleTransport(m, idsForPath));
|
||||
for (const m of deferredModules) {
|
||||
invariant(
|
||||
m.id >= 0,
|
||||
'A script (non-module) cannot be part of the deferred modules of a RAM bundle',
|
||||
);
|
||||
}
|
||||
const ramGroups = createRamBundleGroups(
|
||||
ramGroupHeads || [],
|
||||
deferredModules,
|
||||
|
|
|
@ -117,7 +117,8 @@ exports.toModuleTransport = (module: Module, idsForPath: IdsForPathFn) => {
|
|||
return {
|
||||
code: getModuleCode(module, x => idsForPath(x).moduleId),
|
||||
dependencies,
|
||||
id: idsForPath(file).localId,
|
||||
// ID is required but we provide an invalid one for "script"s.
|
||||
id: file.type === 'module' ? idsForPath(file).localId : -1,
|
||||
map: file.map,
|
||||
name: file.path,
|
||||
sourcePath: file.path,
|
||||
|
|
Loading…
Reference in New Issue