1
1
#!/usr/bin/env node
2
- // Usage: tools/update-author.js [--dry]
2
+ // Usage: tools/update-author.mjs [--dry]
3
3
// 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' ;
9
7
10
8
class CaseIndifferentMap {
11
9
_map = new Map ( ) ;
@@ -33,7 +31,7 @@ output.write('# Authors ordered by first contribution.\n\n');
33
31
34
32
const mailmap = new CaseIndifferentMap ( ) ;
35
33
{
36
- const lines = fs . readFileSync ( path . resolve ( __dirname , '../' , '.mailmap' ) ,
34
+ const lines = fs . readFileSync ( new URL ( '../.mailmap ' , import . meta . url ) ,
37
35
{ encoding : 'utf8' } ) . split ( '\n' ) ;
38
36
for ( let line of lines ) {
39
37
line = line . trim ( ) ;
@@ -55,7 +53,7 @@ const mailmap = new CaseIndifferentMap();
55
53
56
54
const previousAuthors = new CaseIndifferentMap ( ) ;
57
55
{
58
- const lines = fs . readFileSync ( path . resolve ( __dirname , '../' , 'AUTHORS' ) ,
56
+ const lines = fs . readFileSync ( new URL ( '../AUTHORS ' , import . meta . url ) ,
59
57
{ encoding : 'utf8' } ) . split ( '\n' ) ;
60
58
for ( let line of lines ) {
61
59
line = line . trim ( ) ;
@@ -85,9 +83,9 @@ const seen = new Set();
85
83
// by GitHub now.
86
84
const authorRe =
87
85
/ ( ^ 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 ) {
89
87
const match = line . match ( authorRe ) ;
90
- if ( ! match ) return ;
88
+ if ( ! match ) continue ;
91
89
92
90
let { author, email } = match . groups ;
93
91
const emailLower = email . toLowerCase ( ) ;
@@ -99,7 +97,7 @@ rl.on('line', (line) => {
99
97
}
100
98
101
99
if ( seen . has ( email ) ) {
102
- return ;
100
+ continue ;
103
101
}
104
102
105
103
seen . add ( email ) ;
@@ -109,8 +107,6 @@ rl.on('line', (line) => {
109
107
console . warn ( 'Author name already in AUTHORS file. Possible duplicate:' ) ;
110
108
console . warn ( ` ${ author } ${ email } ` ) ;
111
109
}
112
- } ) ;
110
+ }
113
111
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