| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- "use strict";
- module.exports = function( grunt ) {
- function readOptionalJSON( filepath ) {
- var stripJSONComments = require( "strip-json-comments" ),
- data = {};
- try {
- data = JSON.parse( stripJSONComments(
- fs.readFileSync( filepath, { encoding: "utf8" } )
- ) );
- } catch ( e ) {}
- return data;
- }
- var fs = require( "fs" ),
- gzip = require( "gzip-js" ),
- isTravis = process.env.TRAVIS,
- travisBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," );
- if ( !grunt.option( "filename" ) ) {
- grunt.option( "filename", "jquery.js" );
- }
- grunt.initConfig( {
- pkg: grunt.file.readJSON( "package.json" ),
- dst: readOptionalJSON( "dist/.destination.json" ),
- "compare_size": {
- files: [ "dist/jquery.js", "dist/jquery.min.js" ],
- options: {
- compress: {
- gz: function( contents ) {
- return gzip.zip( contents, {} ).length;
- }
- },
- cache: "build/.sizecache.json"
- }
- },
- babel: {
- options: {
- sourceMap: "inline",
- retainLines: true,
- plugins: [ "@babel/transform-for-of" ]
- },
- tests: {
- files: {
- "test/data/core/jquery-iterability-transpiled.js":
- "test/data/core/jquery-iterability-transpiled-es6.js"
- }
- }
- },
- build: {
- all: {
- dest: "dist/jquery.js",
- minimum: [
- "core",
- "selector"
- ],
- // Exclude specified modules if the module matching the key is removed
- removeWith: {
- ajax: [ "manipulation/_evalUrl", "deprecated/ajax-event-alias" ],
- callbacks: [ "deferred" ],
- css: [ "effects", "dimensions", "offset" ],
- "css/showHide": [ "effects" ],
- deferred: {
- remove: [ "ajax", "effects", "queue", "core/ready" ],
- include: [ "core/ready-no-deferred" ]
- },
- event: [ "deprecated/ajax-event-alias", "deprecated/event" ],
- sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
- }
- }
- },
- npmcopy: {
- all: {
- options: {
- destPrefix: "external"
- },
- files: {
- "sizzle/dist": "sizzle/dist",
- "sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
- "npo/npo.js": "native-promise-only/lib/npo.src.js",
- "qunit/qunit.js": "qunit/qunit/qunit.js",
- "qunit/qunit.css": "qunit/qunit/qunit.css",
- "qunit/LICENSE.txt": "qunit/LICENSE.txt",
- "requirejs/require.js": "requirejs/require.js",
- "sinon/sinon.js": "sinon/pkg/sinon.js",
- "sinon/LICENSE.txt": "sinon/LICENSE"
- }
- }
- },
- jsonlint: {
- pkg: {
- src: [ "package.json" ]
- }
- },
- eslint: {
- options: {
- // See https://github.com/sindresorhus/grunt-eslint/issues/119
- quiet: true
- },
- // We have to explicitly declare "src" property otherwise "newer"
- // task wouldn't work properly :/
- dist: {
- src: [ "dist/jquery.js", "dist/jquery.min.js" ]
- },
- dev: {
- src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
- }
- },
- testswarm: {
- tests: [
- // A special module with basic tests, meant for
- // not fully supported environments like Android 2.3,
- // jsdom or PhantomJS. We run it everywhere, though,
- // to make sure tests are not broken.
- "basic",
- "ajax",
- "animation",
- "attributes",
- "callbacks",
- "core",
- "css",
- "data",
- "deferred",
- "deprecated",
- "dimensions",
- "effects",
- "event",
- "manipulation",
- "offset",
- "queue",
- "selector",
- "serialize",
- "support",
- "traversing",
- "tween"
- ]
- },
- karma: {
- options: {
- customContextFile: "test/karma.context.html",
- customDebugFile: "test/karma.debug.html",
- customLaunchers: {
- ChromeHeadlessNoSandbox: {
- base: "ChromeHeadless",
- flags: [ "--no-sandbox" ]
- }
- },
- frameworks: [ "qunit" ],
- middleware: [ "mockserver" ],
- plugins: [
- "karma-*",
- {
- "middleware:mockserver": [
- "factory",
- require( "./test/middleware-mockserver.js" )
- ]
- }
- ],
- client: {
- qunit: {
- // We're running `QUnit.start()` ourselves via `loadTests()`
- // in test/jquery.js
- autostart: false
- }
- },
- files: [
- "test/data/jquery-1.9.1.js",
- "external/sinon/sinon.js",
- "external/npo/npo.js",
- "external/requirejs/require.js",
- "test/data/testinit.js",
- "test/jquery.js",
- {
- pattern: "dist/jquery.*",
- included: false,
- served: true,
- nocache: true
- },
- {
- pattern: "src/**",
- included: false,
- served: true,
- nocache: true
- },
- {
- pattern: "external/**",
- included: false,
- served: true,
- nocache: true
- },
- { pattern: "node_modules/**", included: false, served: true },
- {
- pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
- included: false,
- served: true,
- nocache: true
- }
- ],
- reporters: [ "dots" ],
- autoWatch: false,
- concurrency: 3,
- captureTimeout: 20 * 1000,
- singleRun: true
- },
- main: {
- browsers: isTravis && travisBrowsers || [ "ChromeHeadless", "FirefoxHeadless" ]
- },
- amd: {
- browsers: isTravis && travisBrowsers || [ "ChromeHeadless" ],
- options: {
- client: {
- qunit: {
- // We're running `QUnit.start()` ourselves via `loadTests()`
- // in test/jquery.js
- autostart: false,
- amd: true
- }
- }
- }
- },
- jsdom: {
- options: {
- files: [
- "test/data/jquery-1.9.1.js",
- "test/data/testinit-jsdom.js",
- // We don't support various loading methods like AMD,
- // choosing a version etc. for jsdom.
- "dist/jquery.js",
- // A partial replacement for testinit.js#loadTests()
- "test/data/testrunner.js",
- // jsdom only runs basic tests
- "test/unit/basic.js",
- { pattern: "external/**", included: false, served: true },
- {
- pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
- included: false,
- served: true
- }
- ]
- },
- browsers: [ "jsdom" ]
- },
- // To debug tests with Karma:
- // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
- // (any karma subtask that has singleRun=false)
- // 2. Press "Debug" in the opened browser window to start
- // the tests. Unlike the other karma tasks, the debug task will
- // keep the browser window open.
- "chrome-debug": {
- browsers: [ "Chrome" ],
- singleRun: false
- },
- "firefox-debug": {
- browsers: [ "Firefox" ],
- singleRun: false
- },
- "ie-debug": {
- browsers: [ "IE" ],
- singleRun: false
- }
- },
- watch: {
- files: [ "<%= eslint.dev.src %>" ],
- tasks: [ "dev" ]
- },
- uglify: {
- all: {
- files: {
- "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
- "dist/<%= grunt.option('filename') %>"
- },
- options: {
- preserveComments: false,
- sourceMap: true,
- sourceMapName:
- "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
- report: "min",
- output: {
- "ascii_only": true,
- // Support: Android 4.0 only
- // UglifyJS 3 breaks Android 4.0 if this option is not enabled.
- // This is in lieu of setting ie8 for all of mangle, compress, and output
- "ie8": true
- },
- banner: "/*! jQuery v<%= pkg.version %> | " +
- "(c) OpenJS Foundation and other contributors | jquery.org/license */",
- compress: {
- "hoist_funs": false,
- loops: false,
- // Support: IE <11
- // typeofs transformation is unsafe for IE9-10
- // See https://github.com/mishoo/UglifyJS2/issues/2198
- typeofs: false
- }
- }
- }
- }
- } );
- // Load grunt tasks from NPM packages
- require( "load-grunt-tasks" )( grunt );
- // Integrate jQuery specific tasks
- grunt.loadTasks( "build/tasks" );
- grunt.registerTask( "lint", [
- "jsonlint",
- // Running the full eslint task without breaking it down to targets
- // would run the dist target first which would point to errors in the built
- // file, making it harder to fix them. We want to check the built file only
- // if we already know the source files pass the linter.
- "eslint:dev",
- "eslint:dist"
- ] );
- grunt.registerTask( "lint:newer", [
- "newer:jsonlint",
- // Don't replace it with just the task; see the above comment.
- "newer:eslint:dev",
- "newer:eslint:dist"
- ] );
- grunt.registerTask( "test:fast", "node_smoke_tests" );
- grunt.registerTask( "test:slow", [
- "promises_aplus_tests",
- "karma:jsdom"
- ] );
- grunt.registerTask( "test:prepare", [
- "qunit_fixture",
- "babel:tests"
- ] );
- grunt.registerTask( "test", [
- "test:prepare",
- "test:fast",
- "test:slow"
- ] );
- grunt.registerTask( "dev", [
- "build:*:*",
- "newer:eslint:dev",
- "newer:uglify",
- "remove_map_comment",
- "dist:*",
- "qunit_fixture",
- "compare_size"
- ] );
- grunt.registerTask( "default", [
- "eslint:dev",
- "build:*:*",
- "uglify",
- "remove_map_comment",
- "dist:*",
- "test:prepare",
- "eslint:dist",
- "test:fast",
- "compare_size"
- ] );
- };
|