From 23a3171dabc881a811adcf1080858056dc28942a Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Mon, 22 Jan 2024 22:12:33 -0500 Subject: [PATCH] Build: migrate grunt authors to a custom script - the new script pulls all authors from the Sizzle repo - added temporary grunt task for releases Close gh-5396 --- AUTHORS.txt | 30 +++++------ Gruntfile.js | 8 +++ build/release/authors.js | 105 +++++++++++++++++++++++++++++++++++++++ package-lock.json | 10 ---- package.json | 3 +- 5 files changed, 130 insertions(+), 26 deletions(-) create mode 100644 build/release/authors.js diff --git a/AUTHORS.txt b/AUTHORS.txt index 648a3f0f4..1006a165f 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -1,3 +1,5 @@ +Authors ordered by first contribution. + John Resig Gilles van den Hoven Michael Geary @@ -29,7 +31,6 @@ Michael Bensoussan Louis-Rémi Babé Robert Katić Damian Janowski -Anton Kovalyov Dušan B. Jovanovic Earle Castledine Rich Dougherty @@ -67,11 +68,11 @@ temp01 Colin Snover Jared Grippe Ryan W Tenney -Alex Sexton Pinhook Ron Otten Jephte Clain Anton Matzneller +Alex Sexton Dan Heberden Henri Wiechers Russell Holbrook @@ -85,9 +86,10 @@ Sylvester Keil Brandon Sterne Mathias Bynens Lee Carpenter -Timmy Willison <4timmywil@gmail.com> +Timmy Willison Corey Frang Digitalxero +Anton Kovalyov David Murdoch Josh Varner Charles McNulty @@ -149,7 +151,6 @@ Chris Faulkner Marcel Greter Elijah Manor Daniel Chatfield -Daniel Gálvez Nikita Govorov Wesley Walser Mike Pennisi @@ -160,9 +161,7 @@ Dave Riddle Callum Macrae Jonathan Sampson Benjamin Truyman -Jay Merrifield James Huston -Sai Lung Wong Erick Ruiz de Chávez David Bonner Allen J Schmidt Jr @@ -172,8 +171,11 @@ Ismail Khair Carl Danley Mike Petrovich Greg Lavallee +Daniel Gálvez +Sai Lung Wong Tom H Fuertes Roland Eckl +Jay Merrifield Yiming He David Fox Bennett Sorbo @@ -190,9 +192,9 @@ Diego Tres Jean Boussier Andrew Plummer Mark Raddatz -Pascal Borreli Isaac Z. Schlueter Karl Sieburg +Pascal Borreli Nguyen Phuc Lam Dmitry Gusev Steven Benner @@ -200,7 +202,6 @@ Li Xudong Michał Gołębiowski-Owczarek Renato Oliveira dos Santos Frederic Junod -Tom H Fuertes Mitch Foley ros3cin Kyle Robinson Young @@ -248,7 +249,6 @@ Dan Hart Nazar Mokrynskyi Benjamin Tan Amit Merchant -Jason Bedard Veaceslav Grimalschi Richard McDaniel Arthur Verschaeve @@ -271,12 +271,12 @@ Jon Hester Colin Frick Winston Howes Alexander O'Mara -Chris Rebert Bastian Buchholz Mu Haibao Calvin Metcalf Arthur Stolyar Gabriel Schulhof +Chris Rebert Gilad Peleg Julian Alexander Murillo Kevin Kirsche @@ -295,15 +295,14 @@ Christian Grete Tom von Clef Liza Ramo Joelle Fleurantin -Steve Mao Jon Dufresne Jae Sung Park Josh Soref -Saptak Sengupta Henry Wong Jun Sun Martijn W. van der Lee Devin Wilson +Steve Mao Damian Senn Zack Hall Vitaliy Terziev @@ -334,6 +333,7 @@ Jordan Beland Henry Zhu Nilton Cesar basil.belokon +Saptak Sengupta Andrey Meshkov tmybr11 Luis Emilio Velasco Sanchez @@ -342,18 +342,18 @@ Bert Zhang Sébastien Règne wartmanm <3869625+wartmanm@users.noreply.github.com> Siddharth Dungarwal -abnud1 Andrei Fangli Marja Hölttä +abnud1 buddh4 Hoang +Sean Robinson Wonseop Kim Pat O'Callaghan JuanMa Ruiz Ahmed.S.ElAfifi Christian Oliff Christian Wenz -Sean Robinson Jonathan Pierre Grimaud Beatriz Rezener @@ -366,6 +366,6 @@ Simon Legner Vladimir Sitnikov Anders Kaseorg Alex -Timo Tijhof Gabriela Gutierrez Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> +Stephen Sigwart diff --git a/Gruntfile.js b/Gruntfile.js index 15fd93695..6dfe6c9ce 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -209,6 +209,14 @@ module.exports = function( grunt ) { grunt.log.writeln( "Node.js 17 or newer detected, skipping jsdom tests..." ); } ); + grunt.registerTask( "authors", async function() { + const done = this.async(); + const { getAuthors } = require( "./build/release/authors.js" ); + const authors = await getAuthors(); + console.log( authors.join( "\n" ) ); + done(); + } ); + grunt.registerTask( "test:jsdom", [ // Support: Node.js 17+ diff --git a/build/release/authors.js b/build/release/authors.js new file mode 100644 index 000000000..dc9707c6b --- /dev/null +++ b/build/release/authors.js @@ -0,0 +1,105 @@ +"use strict"; + +const fs = require( "node:fs" ); +const util = require( "node:util" ); +const exec = util.promisify( require( "node:child_process" ).exec ); +const rnewline = /\r?\n/; +const rdate = /^\[(\d+)\] /; + +const ignore = [ + /dependabot\[bot\]/ +]; + +function compareAuthors( a, b ) { + const aName = a.replace( rdate, "" ).replace( / <.*>/, "" ); + const bName = b.replace( rdate, "" ).replace( / <.*>/, "" ); + return aName === bName; +} + +function uniq( arr ) { + const unique = []; + for ( const item of arr ) { + if ( ignore.some( re => re.test( item ) ) ) { + continue; + } + if ( item && !unique.find( ( e ) => compareAuthors( e, item ) ) ) { + unique.push( item ); + } + } + return unique; +} + +function cleanupSizzle() { + console.log( "Cleaning up..." ); + return exec( "npx rimraf .sizzle" ); +} + +function cloneSizzle() { + console.log( "Cloning Sizzle..." ); + return exec( "git clone https://github.com/jquery/sizzle .sizzle" ); +} + +async function getLastAuthor() { + const authorsTxt = await fs.promises.readFile( "AUTHORS.txt", "utf8" ); + return authorsTxt.trim().split( rnewline ).pop(); +} + +async function logAuthors( preCommand ) { + let command = "git log --pretty=format:\"[%at] %aN <%aE>\""; + if ( preCommand ) { + command = preCommand + " && " + command; + } + const { stdout } = await exec( command ); + return uniq( stdout.trim().split( rnewline ).reverse() ); +} + +async function getSizzleAuthors() { + await cloneSizzle(); + const authors = await logAuthors( "cd .sizzle" ); + await cleanupSizzle(); + return authors; +} + +function sortAuthors( a, b ) { + const [ , aDate ] = rdate.exec( a ); + const [ , bDate ] = rdate.exec( b ); + return parseInt( aDate ) - parseInt( bDate ); +} + +function formatAuthor( author ) { + return author.replace( rdate, "" ); +} + +async function getAuthors() { + console.log( "Getting authors..." ); + const authors = await logAuthors(); + const sizzleAuthors = await getSizzleAuthors(); + return uniq( authors.concat( sizzleAuthors ) ).sort( sortAuthors ).map( formatAuthor ); +} + +async function checkAuthors() { + const authors = await getAuthors(); + const lastAuthor = await getLastAuthor(); + + if ( authors[ authors.length - 1 ] !== lastAuthor ) { + console.log( "AUTHORS.txt: ", lastAuthor ); + console.log( "Last 20 in git: ", authors.slice( -20 ) ); + throw new Error( "Last author in AUTHORS.txt does not match last git author" ); + } + console.log( "AUTHORS.txt is up to date" ); +} + +async function updateAuthors() { + const authors = await getAuthors(); + + const authorsTxt = "Authors ordered by first contribution.\n\n" + authors.join( "\n" ) + "\n"; + await fs.promises.writeFile( "AUTHORS.txt", authorsTxt ); + + console.log( "AUTHORS.txt updated" ); +} + +module.exports = { + checkAuthors, + getAuthors, + updateAuthors +}; diff --git a/package-lock.json b/package-lock.json index 59d255612..b2b3b2448 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,6 @@ "globals": "13.20.0", "grunt": "1.5.3", "grunt-cli": "1.4.3", - "grunt-git-authors": "3.2.0", "grunt-karma": "4.0.2", "husky": "8.0.3", "jsdom": "19.0.0", @@ -3630,15 +3629,6 @@ "nopt": "bin/nopt.js" } }, - "node_modules/grunt-git-authors": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/grunt-git-authors/-/grunt-git-authors-3.2.0.tgz", - "integrity": "sha1-D/WrbTxu/+CrIV1jNDRcD2v+FnI=", - "dev": true, - "dependencies": { - "spawnback": "~1.0.0" - } - }, "node_modules/grunt-karma": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/grunt-karma/-/grunt-karma-4.0.2.tgz", diff --git a/package.json b/package.json index 62f7c10ca..e96fff70c 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "version": "3.7.2-pre", "main": "dist/jquery.js", "scripts": { + "authors:check": "node -e \"require('./build/release/authors.js').checkAuthors()\"", + "authors:update": "node -e \"require('./build/release/authors.js').updateAuthors()\"", "babel:tests": "babel test/data/core/jquery-iterability-transpiled-es6.js --out-file test/data/core/jquery-iterability-transpiled.js", "build": "node ./build/command.js", "build:all": "node -e \"require('./build/tasks/build.js').buildDefaultFiles()\"", @@ -65,7 +67,6 @@ "globals": "13.20.0", "grunt": "1.5.3", "grunt-cli": "1.4.3", - "grunt-git-authors": "3.2.0", "grunt-karma": "4.0.2", "husky": "8.0.3", "jsdom": "19.0.0", -- 2.39.5