Skip to content
Browse files

Merge pull request #15 from danwrong/i_fixed_this

Fix excluded commonjs deps
  • Loading branch information...
2 parents bd14e1f + 4f8fb4a commit bf7d201b5a7b876db3cac886f8da6893c925b4f4 @danwrong committed Mar 27, 2012
Showing with 11 additions and 3 deletions.
  1. +1 −1 lib/loadbuilder/asset.js
  2. +3 −2 lib/loadbuilder/builder.js
  3. +6 −0 test/builder.js
  4. +1 −0 test/modules/bananas.js
View
2 lib/loadbuilder/asset.js
@@ -153,7 +153,7 @@ util.extend(Module.prototype, {
var requires = analyzer.analyze(REQUIRE, this.fromFile());
return requires.map(function(r) {
- var asset = this.builder.matchAsset(r.values[0]);
+ var asset = this.builder.matchAsset(r.values[0], false);
return (asset.length==0) ? null : asset;
}, this).filter(function(item){ return item!=null; });
},
View
5 lib/loadbuilder/builder.js
@@ -92,12 +92,13 @@ util.extend(Builder.prototype, {
addMatcher: function(regex, factory) {
this.matchers.push([regex, factory]);
},
- matchAsset: function(id) {
+ matchAsset: function(id, exclude) {
var m, dep, asset;
+ if (typeof exclude === 'undefined') exclude = true;
var allMatchers = this.matchers.concat(builder.matchers);
for (var i=0, matcher; matcher = allMatchers[i]; i++) {
var regex = matcher[0], factory = matcher[1];
- if (this.excludes.indexOf(id) < 0 && (m = id.match(regex))) {
+ if ((!exclude || this.excludes.indexOf(id) < 0) && (m = id.match(regex))) {
asset = factory(id);
asset.builder = this;
return asset;
View
6 test/builder.js
@@ -63,6 +63,12 @@ module.exports = {
builder(opts).include('fixtures/has_dep.js').exclude(a).toSource()
);
},
+ testShouldBeAbleToExcludeABundleWithoutBreakingCommonJS: function() {
+ assert.equal(
+ "(function() {\nvar module=define(\"modules/bananas\",[\"require\",\"exports\",\"modules/anon\"],function(require, exports) {\nvar a = require('modules/anon');\n});\n})();",
+ builder(opts).include('modules/bananas').exclude('modules/anon').toSource()
+ );
+ },
testShouldBeAbleToWriteToAFile: function() {
var path = __dirname + '/bundle.js', expected = {};
builder(opts).include('fixtures/simple.js', 'fixtures/simple2.js').write(path, function(manifest) {
View
1 test/modules/bananas.js
@@ -0,0 +1 @@
+var a = require('modules/anon');

0 comments on commit bf7d201

Please sign in to comment.
Something went wrong with that request. Please try again.