aboutsummaryrefslogtreecommitdiffstats
path: root/Gruntfile.cjs
diff options
context:
space:
mode:
authorTimmy Willison <timmywil@users.noreply.github.com>2023-09-18 12:39:00 -0400
committerGitHub <noreply@github.com>2023-09-18 12:39:00 -0400
commit2bdecf8b7bd10864e5337a4e24e39476c78cf23a (patch)
tree4685fc5ca912e368c294a3949c7ef5b663fec980 /Gruntfile.cjs
parentf75daab09102a4dd5107deadb55d4a169f86254a (diff)
downloadjquery-2bdecf8b7bd10864e5337a4e24e39476c78cf23a.tar.gz
jquery-2bdecf8b7bd10864e5337a4e24e39476c78cf23a.zip
Build: migrate most grunt tasks off of grunt
Updated tasks include: - lint - npmcopy - build, minify, and process for distribution. - new custom build command using yargs - compare size of minified/gzip built files - pretest scripts, including qunit-fixture, babel transpilation, and npmcopy - node smoke tests - promises aplus tests - new watch task using `rollup.watch` directly Also: - upgraded husky and added the new lint command - updated lint config to use new "flat" config format. See https://eslint.org/docs/latest/use/configure/configuration-files-new - Temporarily disabled one lint rule until flat config is supported by eslint-plugin-import. See https://github.com/import-js/eslint-plugin-import/issues/2556 - committed package-lock.json - updated all test scripts to use the new build - added an express test server that uses middleware-mockserver (this can be used to run tests without karma) - build-all-variants is now build:all Close gh-5318
Diffstat (limited to 'Gruntfile.cjs')
-rw-r--r--Gruntfile.cjs264
1 files changed, 11 insertions, 253 deletions
diff --git a/Gruntfile.cjs b/Gruntfile.cjs
index 51f36a8e4..f2f04d536 100644
--- a/Gruntfile.cjs
+++ b/Gruntfile.cjs
@@ -1,20 +1,6 @@
"use strict";
module.exports = function( grunt ) {
- function readOptionalJSON( filepath ) {
- const stripJSONComments = require( "strip-json-comments" );
- let data = {};
- try {
- data = JSON.parse( stripJSONComments(
- fs.readFileSync( filepath, { encoding: "utf8" } )
- ) );
- } catch ( e ) {}
- return data;
- }
-
- const fs = require( "fs" );
- const { spawn } = require( "child_process" );
- const gzip = require( "gzip-js" );
const nodeV16OrNewer = !/^v1[0-5]\./.test( process.version );
const nodeV17OrNewer = !/^v1[0-6]\./.test( process.version );
const customBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," );
@@ -34,137 +20,8 @@ module.exports = function( grunt ) {
grunt.option( "filename", "jquery.js" );
}
- grunt.option( "dist-folder", grunt.option( "esm" ) ? "dist-module" : "dist" );
-
- const builtJsFiles = [
- "dist/jquery.js",
- "dist/jquery.min.js",
- "dist/jquery.slim.js",
- "dist/jquery.slim.min.js",
- "dist-module/jquery.module.js",
- "dist-module/jquery.module.min.js",
- "dist-module/jquery.slim.module.js",
- "dist-module/jquery.slim.module.min.js"
- ];
-
- const builtJsMinFiles = builtJsFiles
- .filter( filepath => filepath.endsWith( ".min.js" ) );
-
grunt.initConfig( {
pkg: grunt.file.readJSON( "package.json" ),
- dst: readOptionalJSON( "dist/.destination.json" ),
- compare_size: {
- files: builtJsMinFiles,
- 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"
- ],
-
- // 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" ],
- selector: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
- }
- }
- },
- npmcopy: {
- all: {
- options: {
- destPrefix: "external"
- },
- files: {
- "bootstrap/bootstrap.css": "bootstrap/dist/css/bootstrap.css",
- "bootstrap/bootstrap.min.css": "bootstrap/dist/css/bootstrap.min.css",
- "bootstrap/bootstrap.min.css.map": "bootstrap/dist/css/bootstrap.min.css.map",
-
- "core-js-bundle/core-js-bundle.js": "core-js-bundle/minified.js",
- "core-js-bundle/LICENSE": "core-js-bundle/LICENSE",
-
- "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: {
- maxWarnings: 0
- },
-
- // We have to explicitly declare "src" property otherwise "newer"
- // task wouldn't work properly :/
- dist: {
- src: builtJsFiles
- },
- dev: {
- src: [
- "src/**/*.js",
- "Gruntfile.js",
- "test/**/*.js",
- "build/**/*.js",
-
- // Ignore files from .eslintignore
- // See https://github.com/sindresorhus/grunt-eslint/issues/119
- ...fs
- .readFileSync( `${ __dirname }/.eslintignore`, "utf-8" )
- .split( "\n" )
- .filter( filePath => filePath )
- .map( filePath => filePath[ 0 ] === "!" ?
- filePath.slice( 1 ) :
- `!${ filePath }`
- ),
-
- // Explicitly ignore `dist/` & `dist-module/` as it could be unignored
- // by the above `.eslintignore` parsing.
- "!dist/**/*.js",
- "!dist-module/**/*.js"
- ]
- }
- },
testswarm: {
tests: [
@@ -230,10 +87,15 @@ module.exports = function( grunt ) {
"external/npo/npo.js",
"external/requirejs/require.js",
"test/data/testinit.js",
-
"test/jquery.js",
{
+ pattern: "external/**",
+ included: false,
+ served: true,
+ nocache: true
+ },
+ {
pattern: "dist/jquery.*",
included: false,
served: true,
@@ -246,7 +108,6 @@ module.exports = function( grunt ) {
served: true,
nocache: true
},
- { pattern: "external/**", included: false, served: true },
{
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
included: false,
@@ -328,108 +189,27 @@ module.exports = function( grunt ) {
browsers: [ "IE" ],
singleRun: false
}
- },
- watch: {
- files: [ "<%= eslint.dev.src %>" ],
- tasks: [ "dev" ]
- },
- minify: {
- all: {
- files: {
- [ "<%= grunt.option('dist-folder') %>/" +
- "<%= grunt.option('filename').replace(/\\.js$/, '.min.js') %>" ]:
- "<%= grunt.option('dist-folder') %>/<%= grunt.option('filename') %>"
- },
- options: {
- sourceMap: {
- filename: "<%= grunt.option('dist-folder') %>/" +
- "<%= grunt.option('filename')" +
- ".replace(/\\.js$/, '.min.map') %>",
-
- // The map's `files` & `sources` property are set incorrectly, fix
- // them via overrides from the task config.
- // See https://github.com/swc-project/swc/issues/7588#issuecomment-1624345254
- overrides: {
- file: "jquery.min.js",
- sources: [
- "jquery.js"
- ]
- }
- },
- swc: {
- format: {
- ecma: grunt.option( "esm" ) ? 2015 : 5,
- asciiOnly: true,
- comments: false,
- preamble: "/*! jQuery v4.0.0-pre | " +
- "(c) OpenJS Foundation and other contributors | " +
- "jquery.org/license */\n"
- },
- compress: {
- ecma: grunt.option( "esm" ) ? 2015 : 5,
- hoist_funs: false,
- loops: false
- },
- mangle: true
- }
- }
- }
}
} );
// Load grunt tasks from NPM packages
require( "load-grunt-tasks" )( grunt, {
- pattern: nodeV16OrNewer ? [ "grunt-*" ] : [ "grunt-*", "!grunt-eslint" ]
+ pattern: [ "grunt-*" ]
} );
// Integrate jQuery specific tasks
- grunt.loadTasks( "build/tasks" );
+ grunt.loadTasks( "build/grunt-tasks" );
grunt.registerTask( "print_old_node_message", ( ...args ) => {
var task = args.join( ":" );
grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
} );
- grunt.registerTask( "build-all-variants",
- "Build all variants of the full/slim build & a script/ESM one",
- function() {
- const done = this.async();
-
- spawn( "npm run build-all-variants", {
- stdio: "inherit",
- shell: true
- } )
- .on( "close", code => {
- done( code === 0 );
- } );
- } );
-
grunt.registerTask( "print_jsdom_message", () => {
grunt.log.writeln( "Node.js 17 or newer detected, skipping jsdom tests..." );
} );
- 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.
- runIfNewNode( "eslint:dev" ),
- runIfNewNode( "eslint:dist" )
- ] );
-
- grunt.registerTask( "lint:newer", [
- "newer:jsonlint",
-
- // Don't replace it with just the task; see the above comment.
- runIfNewNode( "newer:eslint:dev" ),
- runIfNewNode( "newer:eslint:dist" )
- ] );
-
- grunt.registerTask( "test:fast", [ "node_smoke_tests:commonjs:jquery" ] );
- grunt.registerTask( "test:slow", [
- runIfNewNode( "promises_aplus_tests" ),
+ grunt.registerTask( "test:jsdom", [
// Support: Node.js 17+
// jsdom fails to connect to the Karma server in Node 17+.
@@ -437,33 +217,11 @@ module.exports = function( grunt ) {
nodeV17OrNewer ? "print_jsdom_message" : runIfNewNode( "karma:jsdom" )
] );
- grunt.registerTask( "test:prepare", [
- "npmcopy",
- "qunit_fixture",
- "babel:tests"
- ] );
-
grunt.registerTask( "test", [
- "test:prepare",
- "test:fast",
- "test:slow"
- ] );
-
- grunt.registerTask( "dev", [
- "build:*:*",
- runIfNewNode( "newer:eslint:dev" ),
- "newer:minify",
- "dist:*",
- "qunit_fixture",
- "compare_size"
+ "test:jsdom"
] );
grunt.registerTask( "default", [
- runIfNewNode( "eslint:dev" ),
- "build-all-variants",
- "test:prepare",
- runIfNewNode( "eslint:dist" ),
- "test:fast",
- "compare_size"
+ "test"
] );
};