Skip to content
Browse files

Assign a cached module's exports before requiring another

This makes sprockets-commonjs compliant with the "Module context"
contract, paragraph 1.3: "[...]the object returned by "require" must
contain at least the exports that the foreign module has

Some code bases use the (not yet specified/clarified in CommonJS)
method of assigning exports to export things. If, in these code bases,
they then go on to require more code that depends on the previous
module's exports, that new code won't see these exports unless we
re-cache the exports here, thus breaking that paragraph above.
  • Loading branch information...
1 parent 4dc97c2 commit f94897ba0e93d2d3c33260f390f9a1843244955c @antifuchs antifuchs committed Mar 11, 2013
Showing with 1 addition and 0 deletions.
  1. +1 −0 lib/assets/javascripts/sprockets/commonjs.js
1 lib/assets/javascripts/sprockets/commonjs.js
@@ -11,6 +11,7 @@
module = {id: path, exports: {}};
cache[path] = module.exports;
fn(module.exports, function(name) {
+ cache[path] = module.exports;
return require(name, dirname(path));
}, module);
return cache[path] = module.exports;

0 comments on commit f94897b

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