[react-packager] Avoid referring `Module` like objects in `BundlesLayout`

Summary:
The `BundlesLayout` will be used as a persistent index. As such, it would be easier to avoid having dependencies to `Module`, `Package`, `Asset`, etc. We're not using that information for now and if we happen to need to use it we could always fetch it using the `ModuleCache`.
This commit is contained in:
Martín Bigio 2015-08-21 07:02:55 -07:00
parent 51e1a1f6a2
commit 6eea41c718
3 changed files with 18 additions and 29 deletions

View File

@ -61,7 +61,7 @@ describe('BundlesLayout', () => {
return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles => return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles =>
expect(bundles).toEqual({ expect(bundles).toEqual({
id: 'bundle.0', id: 'bundle.0',
modules: [dep('/root/index.js'), dep('/root/a.js')], modules: ['/root/index.js', '/root/a.js'],
children: [], children: [],
}) })
); );
@ -88,10 +88,10 @@ describe('BundlesLayout', () => {
return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles => return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles =>
expect(bundles).toEqual({ expect(bundles).toEqual({
id: 'bundle.0', id: 'bundle.0',
modules: [dep('/root/index.js')], modules: ['/root/index.js'],
children: [{ children: [{
id:'bundle.0.1', id:'bundle.0.1',
modules: [dep('/root/a.js')], modules: ['/root/a.js'],
children: [], children: [],
}], }],
}) })
@ -124,13 +124,13 @@ describe('BundlesLayout', () => {
return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles => return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles =>
expect(bundles).toEqual({ expect(bundles).toEqual({
id: 'bundle.0', id: 'bundle.0',
modules: [dep('/root/index.js')], modules: ['/root/index.js'],
children: [{ children: [{
id: 'bundle.0.1', id: 'bundle.0.1',
modules: [dep('/root/a.js')], modules: ['/root/a.js'],
children: [{ children: [{
id: 'bundle.0.1.2', id: 'bundle.0.1.2',
modules: [dep('/root/b.js')], modules: ['/root/b.js'],
children: [], children: [],
}], }],
}], }],
@ -164,10 +164,10 @@ describe('BundlesLayout', () => {
return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles => return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles =>
expect(bundles).toEqual({ expect(bundles).toEqual({
id: 'bundle.0', id: 'bundle.0',
modules: [dep('/root/index.js')], modules: ['/root/index.js'],
children: [{ children: [{
id: 'bundle.0.1', id: 'bundle.0.1',
modules: [dep('/root/a.js'), dep('/root/b.js')], modules: ['/root/a.js', '/root/b.js'],
children: [], children: [],
}], }],
}) })
@ -200,10 +200,10 @@ describe('BundlesLayout', () => {
return newBundlesLayout().generateLayout(['/root/index.js']).then( return newBundlesLayout().generateLayout(['/root/index.js']).then(
bundles => expect(bundles).toEqual({ bundles => expect(bundles).toEqual({
id: 'bundle.0', id: 'bundle.0',
modules: [dep('/root/index.js'), dep('/root/a.js')], modules: ['/root/index.js', '/root/a.js'],
children: [{ children: [{
id: 'bundle.0.1', id: 'bundle.0.1',
modules: [dep('/root/b.js')], modules: ['/root/b.js'],
children: [], children: [],
}], }],
}) })

View File

@ -80,28 +80,17 @@ describe('BundlesLayout', () => {
function stripPolyfills(bundle) { function stripPolyfills(bundle) {
return Promise return Promise
.all([ .all(bundle.children.map(childModule => stripPolyfills(childModule)))
Promise.all( .then(children => {
bundle.modules.map(module => module const modules = bundle.modules
.getName() .filter(moduleName => { // filter polyfills
.then(name => [module, name])
),
),
Promise.all(
bundle.children.map(childModule => stripPolyfills(childModule)),
),
])
.then(([modules, children]) => {
modules = modules
.filter(([module, name]) => { // filter polyfills
for (let p of polyfills) { for (let p of polyfills) {
if (name.indexOf(p) !== -1) { if (moduleName.indexOf(p) !== -1) {
return false; return false;
} }
} }
return true; return true;
}) });
.map(([module, name]) => module.path);
return { return {
id: bundle.id, id: bundle.id,

View File

@ -58,7 +58,7 @@ class BundlesLayout {
return promiseWhile( return promiseWhile(
() => pendingSyncDeps.length > 0, () => pendingSyncDeps.length > 0,
() => { () => {
const dependencies = _.values(syncDependencies); const dependencies = Object.keys(syncDependencies);
if (dependencies.length > 0) { if (dependencies.length > 0) {
bundle.modules = dependencies; bundle.modules = dependencies;
} }
@ -72,7 +72,7 @@ class BundlesLayout {
if (dep.path !== pendingSyncDep && !dep.isPolyfill()) { if (dep.path !== pendingSyncDep && !dep.isPolyfill()) {
pendingSyncDeps.push(dep.path); pendingSyncDeps.push(dep.path);
} }
syncDependencies[dep.path] = dep; syncDependencies[dep.path] = true;
this._moduleToBundle[dep.path] = bundle.id; this._moduleToBundle[dep.path] = bundle.id;
}); });
deps.asyncDependencies.forEach(asyncDeps => { deps.asyncDependencies.forEach(asyncDeps => {