From: Timmy Willison Date: Tue, 23 Jan 2024 02:08:16 +0000 (-0500) Subject: Build: migrate grunt authors to a custom script X-Git-Tag: 4.0.0-beta~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=af79c99939628255f46f30bced000eba9aa6711f;p=jquery.git 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-5395 --- diff --git a/AUTHORS.txt b/AUTHORS.txt index 06df1a533..fb936882b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -31,7 +31,6 @@ Michael Bensoussan Louis-Rémi Babé Robert Katić Damian Janowski -Anton Kovalyov Dušan B. Jovanovic Earle Castledine Rich Dougherty @@ -69,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 @@ -87,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 @@ -111,7 +111,7 @@ Mike Sherov Greg Hazel Schalk Neethling Denis Knauf -Timo Tijhof +Timo Tijhof Steen Nielsen Anton Ryzhov Shi Chuan @@ -151,7 +151,6 @@ Chris Faulkner Marcel Greter Elijah Manor Daniel Chatfield -Daniel Gálvez Nikita Govorov Wesley Walser Mike Pennisi @@ -162,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 @@ -174,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 @@ -192,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 @@ -202,7 +202,6 @@ Li Xudong Michał Gołębiowski-Owczarek Renato Oliveira dos Santos Frederic Junod -Tom H Fuertes Mitch Foley ros3cin Kyle Robinson Young @@ -250,7 +249,6 @@ Dan Hart Nazar Mokrynskyi Benjamin Tan Amit Merchant -Jason Bedard Veaceslav Grimalschi Richard McDaniel Arthur Verschaeve @@ -273,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 @@ -297,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 @@ -336,6 +333,7 @@ Jordan Beland Henry Zhu Nilton Cesar basil.belokon +Saptak Sengupta Andrey Meshkov tmybr11 Luis Emilio Velasco Sanchez @@ -344,14 +342,32 @@ 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 -Sean Robinson Christian Oliff +Christian Wenz +Jonathan +Ed Sanders +Pierre Grimaud +Beatriz Rezener +Necmettin Karakaya +Wonhyoung Park +Dallas Fraser +高灰 +fecore1 <89127124+fecore1@users.noreply.github.com> +ygj6 <7699524+ygj6@users.noreply.github.com> +Bruno PIERRE +Simon Legner +Baoshuo Ren +Anders Kaseorg +Alex +Gabriela Gutierrez +Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> diff --git a/Gruntfile.cjs b/Gruntfile.cjs index f2f04d536..1b21f2c35 100644 --- a/Gruntfile.cjs +++ b/Gruntfile.cjs @@ -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..9ecd9f642 --- /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 Number( aDate ) - Number( 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 ec2b4b480..6092cce16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,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", @@ -3930,15 +3929,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 5d16b6d04..c03a1afb6 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,8 @@ }, "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()\"", @@ -101,7 +103,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",