11#!/usr/bin/env node
2- // Usage: tools/update-author.js [--dry]
2+ // Usage: tools/update-author.mjs [--dry]
33// Passing --dry will redirect output to stdout rather than write to 'AUTHORS'.
4- 'use strict' ;
5- const { spawn } = require ( 'child_process' ) ;
6- const path = require ( 'path' ) ;
7- const fs = require ( 'fs' ) ;
8- const readline = require ( 'readline' ) ;
4+ import { spawn } from 'node:child_process' ;
5+ import fs from 'node:fs' ;
6+ import readline from 'node:readline' ;
97
108class CaseIndifferentMap {
119 _map = new Map ( ) ;
@@ -33,7 +31,7 @@ output.write('# Authors ordered by first contribution.\n\n');
3331
3432const mailmap = new CaseIndifferentMap ( ) ;
3533{
36- const lines = fs . readFileSync ( path . resolve ( __dirname , '../' , '.mailmap' ) ,
34+ const lines = fs . readFileSync ( new URL ( '../.mailmap ' , import . meta . url ) ,
3735 { encoding : 'utf8' } ) . split ( '\n' ) ;
3836 for ( let line of lines ) {
3937 line = line . trim ( ) ;
@@ -55,7 +53,7 @@ const mailmap = new CaseIndifferentMap();
5553
5654const previousAuthors = new CaseIndifferentMap ( ) ;
5755{
58- const lines = fs . readFileSync ( path . resolve ( __dirname , '../' , 'AUTHORS' ) ,
56+ const lines = fs . readFileSync ( new URL ( '../AUTHORS ' , import . meta . url ) ,
5957 { encoding : 'utf8' } ) . split ( '\n' ) ;
6058 for ( let line of lines ) {
6159 line = line . trim ( ) ;
@@ -85,9 +83,9 @@ const seen = new Set();
8583// by GitHub now.
8684const authorRe =
8785 / ( ^ A u t h o r : | ^ C o - a u t h o r e d - b y : ) \s + (?< author > [ ^ < ] + ) \s + (?< email > < [ ^ > ] + > ) / i;
88- rl . on ( 'line' , ( line ) => {
86+ for await ( const line of rl ) {
8987 const match = line . match ( authorRe ) ;
90- if ( ! match ) return ;
88+ if ( ! match ) continue ;
9189
9290 let { author, email } = match . groups ;
9391 const emailLower = email . toLowerCase ( ) ;
@@ -99,7 +97,7 @@ rl.on('line', (line) => {
9997 }
10098
10199 if ( seen . has ( email ) ) {
102- return ;
100+ continue ;
103101 }
104102
105103 seen . add ( email ) ;
@@ -109,8 +107,6 @@ rl.on('line', (line) => {
109107 console . warn ( 'Author name already in AUTHORS file. Possible duplicate:' ) ;
110108 console . warn ( ` ${ author } ${ email } ` ) ;
111109 }
112- } ) ;
110+ }
113111
114- rl . on ( 'close' , ( ) => {
115- output . end ( '\n# Generated by tools/update-authors.js\n' ) ;
116- } ) ;
112+ output . end ( '\n# Generated by tools/update-authors.mjs\n' ) ;
0 commit comments