Skip to content

Commit

Permalink
Build: Update jscs and lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog committed Aug 16, 2015
1 parent 21d0a19 commit 7d59668
Show file tree
Hide file tree
Showing 88 changed files with 8,179 additions and 7,570 deletions.
6 changes: 5 additions & 1 deletion .jscsrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"preset": "jquery",

// remove after https://github.com/jscs-dev/node-jscs/issues/1685
// and https://github.com/jscs-dev/node-jscs/issues/1686
"requireCapitalizedComments": null,

"excludeFiles": [ "external", "src/intro.js", "src/outro.js",
"test/node_smoke_tests/lib/ensure_iterability.js" ]
"test/node_smoke_tests/lib/ensure_iterability.js", "node_modules" ]
}
12 changes: 9 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function( grunt ) {
// But our modules can
delete srcHintOptions.onevar;

grunt.initConfig({
grunt.initConfig( {
pkg: grunt.file.readJSON( "package.json" ),
dst: readOptionalJSON( "dist/.destination.json" ),
"compare_size": {
Expand Down Expand Up @@ -53,6 +53,7 @@ module.exports = function( grunt ) {
"core",
"selector"
],

// Exclude specified modules if the module matching the key is removed
removeWith: {
ajax: [ "manipulation/_evalUrl", "event/ajax" ],
Expand Down Expand Up @@ -108,7 +109,12 @@ module.exports = function( grunt ) {
gruntfile: "Gruntfile.js",

// Check parts of tests that pass
test: [ "test/data/testrunner.js", "test/unit/animation.js", "test/unit/tween.js" ],
test: [
"test/data/testrunner.js",
"test/unit/animation.js",
"test/unit/tween.js",
"test/unit/wrap.js"
],
release: [ "build/*.js", "!build/release-notes.js" ],
tasks: "build/tasks/*.js"
},
Expand Down Expand Up @@ -162,7 +168,7 @@ module.exports = function( grunt ) {
}
}
}
});
} );

// Load grunt tasks from NPM packages
require( "load-grunt-tasks" )( grunt );
Expand Down
7 changes: 4 additions & 3 deletions build/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function( Release ) {

npmTags = Release.npmTags;

Release.define({
Release.define( {
npmPublish: true,
issueTracker: "github",
/**
Expand All @@ -36,6 +36,7 @@ module.exports = function( Release ) {
* for publishing the distribution repo instead
*/
npmTags: function() {

// origRepo is not defined if dist was skipped
Release.dir.repo = Release.dir.origRepo || Release.dir.repo;
return npmTags();
Expand All @@ -47,9 +48,9 @@ module.exports = function( Release ) {
dist: function( callback ) {
cdn.makeArchives( Release, function() {
dist( Release, callback );
});
} );
}
});
} );
};

module.exports.dependencies = [
Expand Down
51 changes: 36 additions & 15 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ module.exports = function( grunt ) {
baseUrl: "src",
name: "jquery",
out: "dist/jquery.js",

// We have multiple minify steps
optimize: "none",

// Include dependencies loaded with require
findNestedDependencies: true,

// Avoid inserting define() placeholder
skipModuleInsertion: true,

// Avoid breaking semicolons inserted by r.js
skipSemiColonInsertion: true,
wrap: {
Expand All @@ -47,22 +51,25 @@ module.exports = function( grunt ) {
*/
function convert( name, path, contents ) {
var amdName;

// Convert var modules
if ( /.\/var\//.test( path ) ) {
contents = contents
.replace( /define\([\w\W]*?return/, "var " + (/var\/([\w-]+)/.exec(name)[1]) + " =" )
.replace( /define\([\w\W]*?return/, "var " + ( /var\/([\w-]+)/.exec( name )[ 1 ] ) + " =" )
.replace( rdefineEnd, "" );

// Sizzle treatment
} else if ( /^sizzle$/.test( name ) ) {
contents = "var Sizzle =\n" + contents

// Remove EXPOSE lines from Sizzle
.replace( /\/\/\s*EXPOSE[\w\W]*\/\/\s*EXPOSE/, "return Sizzle;" );

} else {

contents = contents
.replace( /\s*return\s+[^\}]+(\}\s*?\);[^\w\}]*)$/, "$1" )

// Multiple exports
.replace( /\s*exports\.\w+\s*=\s*\w+;/g, "" );

Expand All @@ -82,13 +89,15 @@ module.exports = function( grunt ) {
contents = contents
.replace( /define\(\[[^\]]*\]\)[\W\n]+$/, "" );
}

// AMD Name
if ( (amdName = grunt.option( "amd" )) != null && /^exports\/amd$/.test( name ) ) {
if (amdName) {
if ( ( amdName = grunt.option( "amd" ) ) != null && /^exports\/amd$/.test( name ) ) {
if ( amdName ) {
grunt.log.writeln( "Naming jQuery with AMD name: " + amdName );
} else {
grunt.log.writeln( "AMD name now anonymous" );
}

// Remove the comma for anonymous defines
contents = contents
.replace( /(\s*)"jquery"(\,\s*)/, amdName ? "$1\"" + amdName + "\"$2" : "" );
Expand Down Expand Up @@ -121,7 +130,8 @@ module.exports = function( grunt ) {
excludeList = function( list, prepend ) {
if ( list ) {
prepend = prepend ? prepend + "/" : "";
list.forEach(function( module ) {
list.forEach( function( module ) {

// Exclude var modules as well
if ( module === "var" ) {
excludeList(
Expand All @@ -130,20 +140,22 @@ module.exports = function( grunt ) {
return;
}
if ( prepend ) {

// Skip if this is not a js file and we're walking files in a dir
if ( !(module = /([\w-\/]+)\.js$/.exec( module )) ) {
if ( !( module = /([\w-\/]+)\.js$/.exec( module ) ) ) {
return;
}

// Prepend folder name if passed
// Remove .js extension
module = prepend + module[1];
module = prepend + module[ 1 ];
}

// Avoid infinite recursion
if ( excluded.indexOf( module ) === -1 ) {
excluder( "-" + module );
}
});
} );
}
},
/**
Expand All @@ -158,12 +170,15 @@ module.exports = function( grunt ) {
module = m[ 2 ];

if ( exclude ) {

// Can't exclude certain modules
if ( minimum.indexOf( module ) === -1 ) {

// Add to excluded
if ( excluded.indexOf( module ) === -1 ) {
grunt.log.writeln( flag );
excluded.push( module );

// Exclude all files in the folder of the same name
// These are the removable dependencies
// It's fine if the directory is not there
Expand All @@ -173,10 +188,11 @@ module.exports = function( grunt ) {
grunt.verbose.writeln( e );
}
}

// Check removeWith list
excludeList( removeWith[ module ] );
} else {
grunt.log.error( "Module \"" + module + "\" is a minimum requirement.");
grunt.log.error( "Module \"" + module + "\" is a minimum requirement." );
if ( module === "selector" ) {
grunt.log.error(
"If you meant to replace Sizzle, use -sizzle instead."
Expand Down Expand Up @@ -215,13 +231,13 @@ module.exports = function( grunt ) {

// Handle Sizzle exclusion
// Replace with selector-native
if ( (index = excluded.indexOf( "sizzle" )) > -1 ) {
if ( ( index = excluded.indexOf( "sizzle" ) ) > -1 ) {
config.rawText.selector = "define(['./selector-native']);";
excluded.splice( index, 1 );
}

// Replace exports/global with a noop noConflict
if ( (index = excluded.indexOf( "exports/global" )) > -1 ) {
if ( ( index = excluded.indexOf( "exports/global" ) ) > -1 ) {
config.rawText[ "exports/global" ] = "define(['../core']," +
"function( jQuery ) {\njQuery.noConflict = function() {};\n});";
excluded.splice( index, 1 );
Expand All @@ -233,9 +249,11 @@ module.exports = function( grunt ) {
// append excluded modules to version
if ( excluded.length ) {
version += " -" + excluded.join( ",-" );

// set pkg.version to version with excludes, so minified file picks it up
grunt.config.set( "pkg.version", version );
grunt.verbose.writeln( "Version changed to " + version );

// Have to use shallow or core will get excluded since it is a dependency
config.excludeShallow = excluded;
}
Expand All @@ -247,8 +265,10 @@ module.exports = function( grunt ) {
*/
config.out = function( compiled ) {
compiled = compiled

// Embed Version
.replace( /@VERSION/g, version )

// Embed Date
// yyyy-mm-ddThh:mmZ
.replace( /@DATE/g, ( new Date() ).toISOString().replace( /:\d+\.\d+Z$/, "Z" ) );
Expand All @@ -259,9 +279,10 @@ module.exports = function( grunt ) {

// Turn off opt-in if necessary
if ( !optIn ) {

// Overwrite the default inclusions with the explicit ones provided
config.rawText.jquery = "define([" +
(included.length ? included.join(",") : "") +
( included.length ? included.join( "," ) : "" ) +
"]);";
}

Expand All @@ -272,8 +293,8 @@ module.exports = function( grunt ) {
done();
}, function( err ) {
done( err );
});
});
} );
} );

// Special "alias" task to make custom build creation less grawlix-y
// Translation example
Expand All @@ -289,6 +310,6 @@ module.exports = function( grunt ) {

grunt.log.writeln( "Creating custom build...\n" );

grunt.task.run([ "build:*:*" + (modules ? ":" + modules : ""), "uglify", "dist" ]);
});
grunt.task.run( [ "build:*:*" + ( modules ? ":" + modules : "" ), "uglify", "dist" ] );
} );
};
14 changes: 7 additions & 7 deletions build/tasks/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ module.exports = function( grunt ) {
flags = Object.keys( this.flags );

// Combine all output target paths
paths = [].concat( stored, flags ).filter(function( path ) {
paths = [].concat( stored, flags ).filter( function( path ) {
return path !== "*";
});
} );

// Ensure the dist files are pure ASCII
nonascii = false;

distpaths.forEach(function( filename ) {
distpaths.forEach( function( filename ) {
var i, c,
text = fs.readFileSync( filename, "utf8" );

Expand All @@ -53,7 +53,7 @@ module.exports = function( grunt ) {
}

// Optionally copy dist files to other locations
paths.forEach(function( path ) {
paths.forEach( function( path ) {
var created;

if ( !/\/$/.test( path ) ) {
Expand All @@ -63,9 +63,9 @@ module.exports = function( grunt ) {
created = path + filename.replace( "dist/", "" );
grunt.file.write( created, text );
grunt.log.writeln( "File '" + created + "' created." );
});
});
} );
} );

return !nonascii;
});
} );
};
2 changes: 1 addition & 1 deletion build/tasks/install_jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ module.exports = function( grunt ) {
args: [ "install", "jsdom@" + version ],
opts: { stdio: "inherit" }
}, this.async() );
});
} );
};
3 changes: 2 additions & 1 deletion build/tasks/sourcemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ var fs = require( "fs" );
module.exports = function( grunt ) {
var minLoc = Object.keys( grunt.config( "uglify.all.files" ) )[ 0 ];
grunt.registerTask( "remove_map_comment", function() {

// Remove the source map comment; it causes way too many problems.
// The map file is still generated for manual associations
// https://github.com/jquery/jquery/issues/1707
var text = fs.readFileSync( minLoc, "utf8" )
.replace( /\/\/# sourceMappingURL=\S+/, "" );
fs.writeFileSync( minLoc, text );
});
} );
};
13 changes: 7 additions & 6 deletions build/tasks/testswarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ module.exports = function( grunt ) {
config = grunt.file.readJSON( configFile )[ projectName ];
browserSets = browserSets || config.browserSets;
if ( browserSets[ 0 ] === "[" ) {

// We got an array, parse it
browserSets = JSON.parse( browserSets );
}
timeout = timeout || 1000 * 60 * 15;
tests = grunt.config([ this.name, "tests" ]);
tests = grunt.config( [ this.name, "tests" ] );

if ( pull ) {
jobName = "Pull <a href='https://github.com/jquery/jquery/pull/" +
Expand All @@ -28,18 +29,18 @@ module.exports = function( grunt ) {
commit + "'>" + commit.substr( 0, 10 ) + "</a>";
}

tests.forEach(function( test ) {
tests.forEach( function( test ) {
runs[ test ] = config.testUrl + commit + "/test/index.html?module=" + test;
});
} );

testswarm.createClient({
testswarm.createClient( {
url: config.swarmUrl
} )
.addReporter( testswarm.reporters.cli )
.auth( {
id: config.authUsername,
token: config.authToken
})
} )
.addjob(
{
name: jobName,
Expand All @@ -54,5 +55,5 @@ module.exports = function( grunt ) {
done( passed );
}
);
});
} );
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"grunt-cli": "0.1.13",
"grunt-compare-size": "0.4.0",
"grunt-contrib-jshint": "0.11.2",
"grunt-contrib-uglify": "0.7.0",
"grunt-contrib-uglify": "0.9.1",
"grunt-contrib-watch": "0.6.1",
"grunt-git-authors": "2.0.1",
"grunt-jscs-checker": "0.8.1",
"grunt-jscs": "2.1.0",
"grunt-jsonlint": "1.0.4",
"grunt-npmcopy": "0.1.0",
"gzip-js": "0.3.2",
Expand Down
Loading

0 comments on commit 7d59668

Please sign in to comment.