From 6eea41c71889fc2b434d4d891c14a00d49b23303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Bigio?= Date: Fri, 21 Aug 2015 07:02:55 -0700 Subject: [PATCH] [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`. --- .../__tests__/BundlesLayout-test.js | 20 ++++++++-------- .../BundlesLayoutIntegration-test.js | 23 +++++-------------- react-packager/src/BundlesLayout/index.js | 4 ++-- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/react-packager/src/BundlesLayout/__tests__/BundlesLayout-test.js b/react-packager/src/BundlesLayout/__tests__/BundlesLayout-test.js index 3a792a44..cca9c8a7 100644 --- a/react-packager/src/BundlesLayout/__tests__/BundlesLayout-test.js +++ b/react-packager/src/BundlesLayout/__tests__/BundlesLayout-test.js @@ -61,7 +61,7 @@ describe('BundlesLayout', () => { return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles => expect(bundles).toEqual({ id: 'bundle.0', - modules: [dep('/root/index.js'), dep('/root/a.js')], + modules: ['/root/index.js', '/root/a.js'], children: [], }) ); @@ -88,10 +88,10 @@ describe('BundlesLayout', () => { return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles => expect(bundles).toEqual({ id: 'bundle.0', - modules: [dep('/root/index.js')], + modules: ['/root/index.js'], children: [{ id:'bundle.0.1', - modules: [dep('/root/a.js')], + modules: ['/root/a.js'], children: [], }], }) @@ -124,13 +124,13 @@ describe('BundlesLayout', () => { return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles => expect(bundles).toEqual({ id: 'bundle.0', - modules: [dep('/root/index.js')], + modules: ['/root/index.js'], children: [{ id: 'bundle.0.1', - modules: [dep('/root/a.js')], + modules: ['/root/a.js'], children: [{ id: 'bundle.0.1.2', - modules: [dep('/root/b.js')], + modules: ['/root/b.js'], children: [], }], }], @@ -164,10 +164,10 @@ describe('BundlesLayout', () => { return newBundlesLayout().generateLayout(['/root/index.js']).then(bundles => expect(bundles).toEqual({ id: 'bundle.0', - modules: [dep('/root/index.js')], + modules: ['/root/index.js'], children: [{ id: 'bundle.0.1', - modules: [dep('/root/a.js'), dep('/root/b.js')], + modules: ['/root/a.js', '/root/b.js'], children: [], }], }) @@ -200,10 +200,10 @@ describe('BundlesLayout', () => { return newBundlesLayout().generateLayout(['/root/index.js']).then( bundles => expect(bundles).toEqual({ id: 'bundle.0', - modules: [dep('/root/index.js'), dep('/root/a.js')], + modules: ['/root/index.js', '/root/a.js'], children: [{ id: 'bundle.0.1', - modules: [dep('/root/b.js')], + modules: ['/root/b.js'], children: [], }], }) diff --git a/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js b/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js index e1db98ab..f834ccf5 100644 --- a/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js +++ b/react-packager/src/BundlesLayout/__tests__/BundlesLayoutIntegration-test.js @@ -80,28 +80,17 @@ describe('BundlesLayout', () => { function stripPolyfills(bundle) { return Promise - .all([ - Promise.all( - bundle.modules.map(module => module - .getName() - .then(name => [module, name]) - ), - ), - Promise.all( - bundle.children.map(childModule => stripPolyfills(childModule)), - ), - ]) - .then(([modules, children]) => { - modules = modules - .filter(([module, name]) => { // filter polyfills + .all(bundle.children.map(childModule => stripPolyfills(childModule))) + .then(children => { + const modules = bundle.modules + .filter(moduleName => { // filter polyfills for (let p of polyfills) { - if (name.indexOf(p) !== -1) { + if (moduleName.indexOf(p) !== -1) { return false; } } return true; - }) - .map(([module, name]) => module.path); + }); return { id: bundle.id, diff --git a/react-packager/src/BundlesLayout/index.js b/react-packager/src/BundlesLayout/index.js index d7693a73..c6da3157 100644 --- a/react-packager/src/BundlesLayout/index.js +++ b/react-packager/src/BundlesLayout/index.js @@ -58,7 +58,7 @@ class BundlesLayout { return promiseWhile( () => pendingSyncDeps.length > 0, () => { - const dependencies = _.values(syncDependencies); + const dependencies = Object.keys(syncDependencies); if (dependencies.length > 0) { bundle.modules = dependencies; } @@ -72,7 +72,7 @@ class BundlesLayout { if (dep.path !== pendingSyncDep && !dep.isPolyfill()) { pendingSyncDeps.push(dep.path); } - syncDependencies[dep.path] = dep; + syncDependencies[dep.path] = true; this._moduleToBundle[dep.path] = bundle.id; }); deps.asyncDependencies.forEach(asyncDeps => {