Skip to content

Commit

Permalink
Working AMD Strip. Fishy heuristic, but it works for every test so far.
Browse files Browse the repository at this point in the history
  • Loading branch information
SlexAxton committed Nov 8, 2012
1 parent 9fe0ea1 commit 788487b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
7 changes: 3 additions & 4 deletions app.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
//Remove AMD ceremony for use without require.js or almond.js
contents = contents.replace(/define\(.*?\{/, '');

if ( contents.match(/return.*[^return]*$/) ) {
contents = contents.replace(/\}\);\s*?$/,'');

if ( !contents.match(/Modernizr\.addTest\(/) && !contents.match(/Modernizr\.addAsyncTest\(/) ) {
//remove last return statement and trailing })
contents = contents.replace(/return.*[^return]*$/,'');
}
else {
contents = contents.replace(/\}\);\s*?$/,'');
}
}
else if ((/require\([^\{]*?\{/).test(contents)) {
contents = contents.replace(/require[^\{]+\{/, '');
Expand Down
2 changes: 1 addition & 1 deletion src/addTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define(['ModernizrProto', 'Modernizr', 'docElement', 'hasOwnProp'], function( Mo
if ( typeof feature == 'object' ) {
for ( var key in feature ) {
if ( hasOwnProp( feature, key ) ) {
Modernizr.addTest( key, feature[ key ] );
addTest( key, feature[ key ] );
}
}
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/modernizr-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,4 @@ require([

// Leak Modernizr namespace
window.Modernizr = Modernizr;

console.dir(window.Modernizr);
});
2 changes: 1 addition & 1 deletion stripdefine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ var fs = require('fs');

var mod = fs.readFileSync(__dirname + '/dist/modernizr-build.js', 'utf8');

mod = mod.replace('define("modernizr-init", function(){});', '');
mod = mod.replace('define("modernizr-init",[], function(){});', '');
fs.writeFileSync(__dirname + '/dist/modernizr-build.js', ";(function(window, document, undefined){\n" + mod + "\n})(this, document);", 'utf8');

0 comments on commit 788487b

Please sign in to comment.