Permalink
Browse files

Strips IIFEs from modules; Always require built jQuery for tests.

  • Loading branch information...
1 parent 9a3046c commit 7c23b77af2477417205fda9bde5208a81e57e40e @rwaldron rwaldron committed Jun 4, 2012
View
@@ -7,5 +7,6 @@ dist
*.patch
/*.html
.DS_Store
+dist/.sizecache.json
build/.sizecache.json
node_modules
View
@@ -1,122 +1,13 @@
-SRC_DIR = src
-TEST_DIR = test
-BUILD_DIR = build
-PREFIX = .
-DIST_DIR = ${PREFIX}/dist
+all: update_submodules
-JS_ENGINE ?= `which node nodejs 2>/dev/null`
-COMPILER = ${JS_ENGINE} ${BUILD_DIR}/uglify.js --unsafe
-POST_COMPILER = ${JS_ENGINE} ${BUILD_DIR}/post-compile.js
-
-BASE_FILES = ${SRC_DIR}/core.js\
- ${SRC_DIR}/callbacks.js\
- ${SRC_DIR}/deferred.js\
- ${SRC_DIR}/support.js\
- ${SRC_DIR}/data.js\
- ${SRC_DIR}/queue.js\
- ${SRC_DIR}/attributes.js\
- ${SRC_DIR}/event.js\
- ${SRC_DIR}/selector.js\
- ${SRC_DIR}/traversing.js\
- ${SRC_DIR}/manipulation.js\
- ${SRC_DIR}/css.js\
- ${SRC_DIR}/ajax.js\
- ${SRC_DIR}/ajax/jsonp.js\
- ${SRC_DIR}/ajax/script.js\
- ${SRC_DIR}/ajax/xhr.js\
- ${SRC_DIR}/effects.js\
- ${SRC_DIR}/offset.js\
- ${SRC_DIR}/dimensions.js\
- ${SRC_DIR}/exports.js
-
-MODULES = ${SRC_DIR}/intro.js\
- ${BASE_FILES}\
- ${SRC_DIR}/outro.js
-
-JQ = ${DIST_DIR}/jquery.js
-JQ_MIN = ${DIST_DIR}/jquery.min.js
-
-SIZZLE_DIR = ${SRC_DIR}/sizzle
-
-JQ_VER = $(shell cat version.txt)
-VER = sed "s/@VERSION/${JQ_VER}/"
-
-DATE=$(shell git log -1 --pretty=format:%ad)
-
-all: update_submodules core
-
-core: jquery min hint size
- @@echo "jQuery build complete."
-
-${DIST_DIR}:
- @@mkdir -p ${DIST_DIR}
-
-jquery: ${JQ}
-
-${JQ}: ${MODULES} | ${DIST_DIR}
- @@echo "Building" ${JQ}
-
- @@cat ${MODULES} | \
- sed 's/.function..jQuery...{//' | \
- sed 's/}...jQuery..;//' | \
- sed 's/@DATE/'"${DATE}"'/' | \
- ${VER} > ${JQ};
-
-${SRC_DIR}/selector.js: ${SIZZLE_DIR}/sizzle.js
- @@echo "Building selector code from Sizzle"
- @@sed '/EXPOSE/r src/sizzle-jquery.js' ${SIZZLE_DIR}/sizzle.js | grep -v window.Sizzle > ${SRC_DIR}/selector.js
-
-hint: jquery
- @@if test ! -z ${JS_ENGINE}; then \
- echo "Checking jQuery against JSHint..."; \
- ${JS_ENGINE} build/jshint-check.js; \
- else \
- echo "You must have NodeJS installed in order to test jQuery against JSHint."; \
- fi
-
-size: jquery min
- @@if test ! -z ${JS_ENGINE}; then \
- gzip -c ${JQ_MIN} > ${JQ_MIN}.gz; \
- wc -c ${JQ} ${JQ_MIN} ${JQ_MIN}.gz | ${JS_ENGINE} ${BUILD_DIR}/sizer.js; \
- rm ${JQ_MIN}.gz; \
- else \
- echo "You must have NodeJS installed in order to size jQuery."; \
- fi
-
-freq: jquery min
- @@if test ! -z ${JS_ENGINE}; then \
- ${JS_ENGINE} ${BUILD_DIR}/freq.js; \
- else \
- echo "You must have NodeJS installed to report the character frequency of minified jQuery."; \
- fi
-
-min: jquery ${JQ_MIN}
-
-${JQ_MIN}: ${JQ}
- @@if test ! -z ${JS_ENGINE}; then \
- echo "Minifying jQuery" ${JQ_MIN}; \
- ${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \
- ${POST_COMPILER} ${JQ_MIN}.tmp; \
- rm -f ${JQ_MIN}.tmp; \
- else \
- echo "You must have NodeJS installed in order to minify jQuery."; \
- fi
-
-clean:
- @@echo "Removing Distribution directory:" ${DIST_DIR}
- @@rm -rf ${DIST_DIR}
-
- @@echo "Removing built copy of Sizzle"
- @@rm -f src/selector.js
-
-distclean: clean
+submoduleclean: clean
@@echo "Removing submodules"
@@rm -rf test/qunit src/sizzle
# change pointers for submodules and update them to what is specified in jQuery
-# --merge doesn't work when doing an initial clone, thus test if we have non-existing
-# submodules, then do an real update
+# --merge doesn't work when doing an initial clone, thus test if we have non-existing
+# submodules, then do an real update
update_submodules:
@@if [ -d .git ]; then \
if git submodule status | grep -q -E '^-'; then \
@@ -129,9 +20,6 @@ update_submodules:
# update the submodules to the latest at the most logical branch
pull_submodules:
@@git submodule foreach "git pull \$$(git config remote.origin.url)"
- @@git submodule summary
-
-pull: pull_submodules
- @@git pull ${REMOTE} ${BRANCH}
+ #@@git submodule summary
-.PHONY: all jquery hint min clean distclean update_submodules pull_submodules pull core
+.PHONY: all submoduleclean update_submodules pull_submodules
View
@@ -11,21 +11,10 @@ In the spirit of open source software development, jQuery always encourages comm
3. [Tips For Bug Patching](http://docs.jquery.com/Tips_for_jQuery_Bug_Patching)
-Running the Unit Tests
---------------------------------------
-
-Run the unit tests with a local server that supports PHP. No database is required. Pre-configured php local servers are available for Windows and Mac. Here are some options:
-
-- Windows: [WAMP download](http://www.wampserver.com/en/)
-- Mac: [MAMP download](http://www.mamp.info/en/index.html)
-- Linux: [Setting up LAMP](https://www.linux.com/learn/tutorials/288158-easy-lamp-server-installation)
-- [Mongoose (most platforms)](http://code.google.com/p/mongoose/)
-
-
What you need to build your own jQuery
--------------------------------------
-In order to build jQuery, you need to have GNU make 3.8 or later, Node.js 0.4.12 or later, and git 1.7 or later.
+In order to build jQuery, you need to have GNU make 3.8 or later, Node.js/npm latest, and git 1.7 or later.
(Earlier versions might work OK, but are not tested.)
Windows users have two options:
@@ -50,32 +39,66 @@ if you swing that way. Easy-peasy.
How to build your own jQuery
----------------------------
-First, clone a copy of the main jQuery git repo by running `git clone git://github.com/jquery/jquery.git`.
+First, clone a copy of the main jQuery git repo by running:
+
+`git clone git://github.com/jquery/jquery.git`
+
+Enter the directory and install the node dependencies:
+
+`cd jquery && npm install`
+
+
+Make sure you have `grunt` installed by testing:
+
+`grunt -version`
+
+
+
+Then, to get a complete, minified (w/ Ugligy.js), linted (w/ JSHint) version of jQuery, type the following:
@Krinkle
Krinkle Jun 6, 2012 jQuery member

rmndr:littletypo

+
+`grunt`
-Then, to get a complete, minified, jslinted version of jQuery, simply `cd` to the `jquery` directory and type
-`make`. If you don't have Node installed and/or want to make a basic, uncompressed, unlinted version of jQuery, use
-`make jquery` instead of `make`.
The built version of jQuery will be put in the `dist/` subdirectory.
-To remove all built files, run `make clean`.
+
+Running the Unit Tests
+--------------------------------------
+
+
+Start grunt to auto-build jQuery as you work:
+
+`cd jquery && grunt watch`
+
+
+
+Run the unit tests with a local server that supports PHP. No database is required. Pre-configured php local servers are available for Windows and Mac. Here are some options:
+
+- Windows: [WAMP download](http://www.wampserver.com/en/)
+- Mac: [MAMP download](http://www.mamp.info/en/index.html)
+- Linux: [Setting up LAMP](https://www.linux.com/learn/tutorials/288158-easy-lamp-server-installation)
+- [Mongoose (most platforms)](http://code.google.com/p/mongoose/)
+
+
Building to a different directory
---------------------------------
-If you want to build jQuery to a directory that is different from the default location, you can specify the PREFIX
-directory: `make PREFIX=/home/jquery/test/ [command]`
+If you want to build jQuery to a directory that is different from the default location:
-With this example, the output files would end up in `/home/jquery/test/dist/`.
+`grunt && grunt dist:/Users/you/Dropbox/Public/`
@Krinkle
Krinkle Jun 6, 2012 jQuery member
  • ./Dropbox/Public/ is the public directory of the user's Dropbox (if he has that application installed on his Mac).
  • ./Public/Drop Box/ is a directory that other users on the computer can drop files into (and exists by default in any Mac account)

I'm not sure if either make sense here.

@rwaldron
rwaldron Jun 7, 2012 jQuery member

How is any of this relevant? It was just arbitrary example that made up...

+With this example, the output files would be:
+
+```bash
+
+/Users/you/Dropbox/Public/jquery.js
+/Users/you/Dropbox/Public/jquery.min.js
+
+```
-Troubleshooting
----------------
-Sometimes, the various git repositories get into an inconsistent state where builds don't complete properly
-(usually this results in the jquery.js or jquery.min.js being 0 bytes). If this happens, run `make clean`, then
-run `make` again.
Git for dummies
---------------
View
@@ -13,17 +13,18 @@ module.exports = function( grunt ) {
var option = grunt.option;
var config = grunt.config;
var template = grunt.template;
+ var distpaths = [
+ "dist/jquery.js",
+ "dist/jquery.min.js"
+ ];
grunt.initConfig({
pkg: "<json:package.json>",
meta: {
banner: "/*! jQuery v@<%= pkg.version %> jquery.com | jquery.org/license */"
},
compare_size: {
- files: [
- "dist/jquery.js",
- "dist/jquery.min.js"
- ]
+ files: distpaths
},
selector: {
"src/selector.js": [
@@ -67,8 +68,8 @@ module.exports = function( grunt ) {
files: "test/index.html"
},
watch: {
- files: "<config:lint.files>",
- tasks: "concat lint"
+ files: [ "<config:lint.files>", "src/**/*.js" ],
+ tasks: "default"
},
jshint: {
options: {
@@ -103,7 +104,7 @@ module.exports = function( grunt ) {
});
// Default grunt.
- grunt.registerTask( "default", "selector build:*:* lint min compare_size" );
+ grunt.registerTask( "default", "submodules selector build:*:* dist:* lint min compare_size" );
grunt.loadNpmTasks("grunt-compare-size");
@@ -184,13 +185,14 @@ module.exports = function( grunt ) {
}
// Unwrap redundant IIFEs
- compiled += file.read( filepath ).replace( /^\(function\( jQuery \) \{|\}\)\( jQuery \);\s*$/g, "" );
+ compiled += file.read( filepath );
+ //.replace( /^\(function\( jQuery \) \{|\}\)\( jQuery \);\s*$/g, "" );
});
// Embed Date
// Embed Version
compiled = compiled.replace( "@DATE", new Date() )
- .replace( "@VERSION", config("pkg.version") );
+ .replace( "@VERSION", config("pkg.version") );
// Write concatenated source to file
file.write( name, compiled );
@@ -203,4 +205,51 @@ module.exports = function( grunt ) {
// Otherwise, print a success message.
log.writeln( "File '" + name + "' created." );
});
+
+ grunt.registerTask( "submodules", function() {
+ var done = this.async();
+
+ grunt.verbose.write( "Updating submodules..." );
+
+ // TODO: migrate remaining `make` to grunt tasks
+ //
+ grunt.utils.spawn({
+ cmd: "make"
+ }, function( err, result ) {
+ if ( err ) {
+ grunt.verbose.error();
+ done( err );
+ return;
+ }
+
+ grunt.log.writeln( result );
+
+ done();
+ });
+ });
+
+ // Allow custom dist file locations
+ grunt.registerTask( "dist", function() {
+ var keys, dir;
+
+ keys = Object.keys( this.flags );
+
+ if ( keys.length ) {
+ dir = keys[0];
+
+ if ( !/\/$/.test( dir ) ) {
+ dir += "/";
+ }
+
+ // 'distpaths' is declared at the top of the
+ // module.exports function scope.
+ distpaths.forEach(function( filename ) {
+ var created = dir + filename.replace( "dist/", "" );
+
+ file.write( created, file.read( filename ) );
+
+ log.writeln( "File '" + created + "' created." );
+ });
+ }
+ });
};
View
@@ -1,5 +1,3 @@
-(function( jQuery ) {
-
var r20 = /%20/g,
rbracket = /\[\]$/,
rCRLF = /\r?\n/g,
@@ -993,5 +991,3 @@ function ajaxConvert( s, response ) {
return { state: "success", data: response };
}
-
-})( jQuery );
View
@@ -1,5 +1,3 @@
-(function( jQuery ) {
-
var oldCallbacks = [],
rquestion = /\?/,
rjsonp = /(=)\?(?=&|$)|\?\?/,
@@ -87,5 +85,3 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
return "script";
}
});
-
-})( jQuery );
View
@@ -1,5 +1,3 @@
-(function( jQuery ) {
-
// Install script dataType
jQuery.ajaxSetup({
accepts: {
@@ -85,5 +83,3 @@ jQuery.ajaxTransport( "script", function(s) {
};
}
});
-
-})( jQuery );
Oops, something went wrong. Retry.

0 comments on commit 7c23b77

Please sign in to comment.