[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 =>
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: [],
}],
})

View File

@ -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,

View File

@ -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 => {