Permalink
Browse files

Fixed #11

  • Loading branch information...
1 parent 3dc2e49 commit 72c68d210445dbc7c233e0737ee72c3403bef2c8 @bengourley bengourley committed May 29, 2012
Showing with 58 additions and 8 deletions.
  1. +7 −3 lib/compact.js
  2. +1 −0 test/assets-alt/x/a.js
  3. +50 −5 test/compact.test.js
View
@@ -4,7 +4,8 @@ var path = require('path')
, async = require('async')
, _ = require('underscore')
, parser = require('uglify-js').parser
- , uglifyer = require('uglify-js').uglify;
+ , uglifyer = require('uglify-js').uglify
+ , crypto = require('crypto');
module.exports.createCompact = function(options) {
@@ -88,9 +89,12 @@ module.exports.createCompact = function(options) {
}
function copyFile(src, callback) {
+ var md5 = crypto.createHash('md5');
+ md5.update(src);
+ var hash = md5.digest('hex').substr(0, 10);
require('util').pump(fs.createReadStream(src),
- fs.createWriteStream(options.destPath + '/' + path.basename(src)), function(error) {
- callback(error, path.normalize(options.webPath + '/' + path.basename(src)));
+ fs.createWriteStream(options.destPath + '/' + hash + '-' + path.basename(src)), function(error) {
+ callback(error, path.normalize(options.webPath + '/' + hash + '-' + path.basename(src)));
});
}
View
@@ -0,0 +1 @@
+console.log("hello from alt!")
View
@@ -169,7 +169,8 @@ describe('compact.js', function() {
req = {
app: {
helpers: function(helper) {
- helper.compactJs().should.eql(['/a.js', '/b.js']);
+ helper.compactJs()[0].should.match(/\-a.js$/);
+ helper.compactJs()[1].should.match(/\-b.js$/);
done();
},
configure: function(fn) {
@@ -216,7 +217,11 @@ describe('compact.js', function() {
req = {
app: {
helpers: function(helper) {
- helper.compactJs().should.eql(['/large.js', '/a.js', '/b.js', '/c.js' ]);
+ var c = helper.compactJs();
+ c[0].should.match(/\-large.js$/);
+ c[1].should.match(/\-a.js$/);
+ c[2].should.match(/\-b.js$/);
+ c[3].should.match(/\-c.js$/);
},
configure: function(fn) {
fn();
@@ -278,7 +283,10 @@ describe('compact.js', function() {
req = {
app: {
helpers: function(helper) {
- helper.compactJs().should.eql(['/a.js', '/b.js', '/c.js']);
+ var c = helper.compactJs();
+ c[0].should.match(/\-a.js$/);
+ c[1].should.match(/\-b.js$/);
+ c[2].should.match(/\-c.js$/);
done();
},
configure: function(fn) {
@@ -387,9 +395,14 @@ describe('compact.js', function() {
});
- it('should differentiate between files with the same name from different locations', function (done) {
+ it('should differentiate between files with the same name from ' +
+ 'different locations in different namespaces', function (done) {
- var compactDebug = require('../../compact').createCompact({ srcPath: srcPath, destPath: destPath, debug: true });
+ var compactDebug = require('../../compact').createCompact({
+ srcPath: srcPath,
+ destPath: destPath,
+ debug: true
+ });
compactDebug.addNamespace('global')
@@ -416,5 +429,37 @@ describe('compact.js', function() {
});
+ it('should differentiate between files with the same name from ' +
+ 'different locations from the same namespace', function (done) {
+
+ var compactDebug = require('../../compact').createCompact({
+ srcPath: altPath,
+ destPath: destPath,
+ debug: true
+ });
+
+
+ compactDebug.addNamespace('global')
+ .addJs('/a.js')
+ .addJs('/x/a.js');
+
+ var
+ req = {
+ app: {
+ helpers: function(helper) {
+ helper.compactJs()[0].should.not.equal(helper.compactJs()[1]);
+ done();
+ },
+ configure: function(fn) {
+ fn();
+ }
+ }
+ }
+ , res;
+
+ compactDebug.js(['global'])(req, res, function() {});
+
+ });
+
});
});

0 comments on commit 72c68d2

Please sign in to comment.