Permalink
Browse files

fix(bundler): don't trace dependencies which have no main file

  • Loading branch information...
JeroenVinke committed Apr 17, 2017
1 parent 7f5e84c commit a2cf32b5d2d748e4866fdfda5bd3e9d575f8b6ed
@@ -8,7 +8,10 @@ exports.DependencyInclusion = class {
this.description = description;
this.items = [];
this.traceDependencies = true;
bundle.bundler.addFile(new DependencyFile(bundle, description), this);
if (description.loaderConfig.main !== false) {
bundle.bundler.addFile(new DependencyFile(bundle, description), this);
}
}
traceResources() {
@@ -3,6 +3,7 @@
const BundlerMock = require('../../mocks/bundler');
const Bundle = require('../../../lib/build/bundle').Bundle;
const CLIOptionsMock = require('../../mocks/cli-options');
const DependencyDescription = require('../../../lib/build/dependency-description').DependencyDescription;
describe('the Bundle module', () => {
let sut;
@@ -118,11 +119,16 @@ describe('the Bundle module', () => {
return true;
});
bundler.configureDependency.and.callFake(dep => {
return Promise.resolve({
loaderConfig: {
name: dep.name || dep
}
});
let depName = dep.name || dep;
let description = new DependencyDescription(depName);
description.loaderConfig = {
name: depName,
path: '../node_modules/' + depName,
main: 'index.js'
};
return Promise.resolve(description);
});
let config = {
@@ -211,10 +217,12 @@ describe('the Bundle module', () => {
let configuredDependencies = [];
bundler.configureDependency.and.callFake(dep => {
let depName = dep.name || dep;
let description = {
loaderConfig: {
name: depName
}
let description = new DependencyDescription(depName);
description.loaderConfig = {
name: depName,
path: '../node_modules/' + depName,
main: 'index.js'
};
return new Promise(resolve => {
@@ -262,11 +270,12 @@ describe('the Bundle module', () => {
it('add dependencies in the same order as they were entered to prevent a wrong module load order', done => {
let bundler = new BundlerMock();
bundler.configureDependency.and.callFake(dep => {
return Promise.resolve({
loaderConfig: {
name: dep.name || dep
}
});
let description = new DependencyDescription(dep.name || dep);
description.loaderConfig = {
name: dep.name || dep
};
return Promise.resolve(description);
});
bundler.itemIncludedInBuild.and.callFake((dep) => true);
@@ -0,0 +1,100 @@
'use strict';
const BundlerMock = require('../../mocks/bundler');
const DependencyInclusion = require('../../../lib/build/dependency-inclusion').DependencyInclusion;
const DependencyDescription = require('../../../lib/build/dependency-description').DependencyDescription;
const mockfs = require('mock-fs');
describe('the DependencyInclusion module', () => {
let bundler;
beforeEach(() => {
bundler = new BundlerMock();
});
afterEach(() => {
mockfs.restore();
});
it('adds a dependency file to the bundle when there is a main file', () => {
let bundle = {
bundler: bundler
};
let description = new DependencyDescription();
description.loaderConfig = {
path: '../node_modules/my-package',
name: 'my-package',
main: 'index.js'
};
// eslint-disable-next-line no-unused-vars
let sut = new DependencyInclusion(bundle, description);
expect(bundler.addFile).toHaveBeenCalled();
});
it('adds a dependency file to the bundle when the path is a file', () => {
mockfs({
'../node_modules': {
'my-package': {
'index.js': 'some-content'
}
}
});
let bundle = {
bundler: bundler
};
let description = new DependencyDescription();
description.loaderConfig = {
path: '../node_modules/my-package/index.js',
name: 'my-package'
};
// eslint-disable-next-line no-unused-vars
let sut = new DependencyInclusion(bundle, description);
expect(bundler.addFile).toHaveBeenCalled();
});
it('does not add dependency file to the bundle when main is set to false', () => {
mockfs();
let bundle = {
bundler: bundler
};
let description = new DependencyDescription();
description.loaderConfig = {
path: '../node_modules/my-package',
name: 'my-package',
main: false
};
// eslint-disable-next-line no-unused-vars
let sut = new DependencyInclusion(bundle, description);
expect(bundler.addFile).not.toHaveBeenCalled();
});
it('adds dependency file to the bundle when main is set to something other than false', () => {
mockfs();
let bundle = {
bundler: bundler
};
let description = new DependencyDescription();
description.loaderConfig = {
path: '../node_modules/my-package',
name: 'my-package',
main: 'my-main-file.js'
};
// eslint-disable-next-line no-unused-vars
let sut = new DependencyInclusion(bundle, description);
expect(bundler.addFile).toHaveBeenCalled();
});
});
View
@@ -1,6 +1,8 @@
'use strict';
const Configuration = require('../../lib/configuration').Configuration;
const CLIOptions = require('../../lib/cli-options').CLIOptions;
const ProjectMock = require('./project-mock');
module.exports = class Bundler {
constructor() {
@@ -9,6 +11,8 @@ module.exports = class Bundler {
this.configureDependency = jasmine.createSpy('configureDependency');
this.addFile = jasmine.createSpy('addFile');
CLIOptions.instance = new CLIOptions();
this.buildOptions = new Configuration({}, {});
this.project = new ProjectMock();
}
};
@@ -0,0 +1,9 @@
'use strict';
module.exports = class ProjectMock {
constructor() {
this.paths = {
root: ''
};
}
};

0 comments on commit a2cf32b

Please sign in to comment.