Skip to content

Commit 1183058

Browse files
F3n67ubengl
authored andcommitted
tools: refactor update-authors.js to ESM
PR-URL: #43098 Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 1da6b7c commit 1183058

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

‎.github/workflows/authors.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
with:
1616
fetch-depth: '0'# This is required to actually get all the authors
1717
persist-credentials: false
18-
- run: tools/update-authors.js# Run the AUTHORS tool
18+
- run: tools/update-authors.mjs# Run the AUTHORS tool
1919
- uses: gr2m/create-or-update-pull-request-action@v1 # Create a PR or update the Action's existing PR
2020
env:
2121
GITHUB_TOKEN: ${{secrets.GH_USER_TOKEN }}
@@ -24,7 +24,7 @@ jobs:
2424
body: >
2525
Here are some new additions to the AUTHORS file.
2626
This is an automatically generated PR by the
27-
`authors.yml` GitHub Action, which runs `tools/update-authors.js`.
27+
`authors.yml` GitHub Action, which runs `tools/update-authors.mjs`.
2828
branch: actions/authors-update # Custom branch *just* for this Action.
2929
commit-message: 'meta: update AUTHORS'
3030
labels: meta

‎AUTHORS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3460,4 +3460,4 @@ William Marlow <[email protected]>
34603460
Keyhan Vakil <[email protected]>
34613461
34623462

3463-
# Generated by tools/update-authors.js
3463+
# Generated by tools/update-authors.mjs
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
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-
constpath=require('path');
7-
constfs=require('fs');
8-
constreadline=require('readline');
4+
import{spawn}from'node:child_process';
5+
importfsfrom'node:fs';
6+
importreadlinefrom'node:readline';
97

108
classCaseIndifferentMap{
119
_map=newMap();
@@ -33,7 +31,7 @@ output.write('# Authors ordered by first contribution.\n\n');
3331

3432
constmailmap=newCaseIndifferentMap();
3533
{
36-
constlines=fs.readFileSync(path.resolve(__dirname,'../','.mailmap'),
34+
constlines=fs.readFileSync(newURL('../.mailmap',import.meta.url),
3735
{encoding: 'utf8'}).split('\n');
3836
for(letlineoflines){
3937
line=line.trim();
@@ -55,7 +53,7 @@ const mailmap = new CaseIndifferentMap();
5553

5654
constpreviousAuthors=newCaseIndifferentMap();
5755
{
58-
constlines=fs.readFileSync(path.resolve(__dirname,'../','AUTHORS'),
56+
constlines=fs.readFileSync(newURL('../AUTHORS',import.meta.url),
5957
{encoding: 'utf8'}).split('\n');
6058
for(letlineoflines){
6159
line=line.trim();
@@ -85,9 +83,9 @@ const seen = new Set();
8583
// by GitHub now.
8684
constauthorRe=
8785
/(^Author:|^Co-authored-by:)\s+(?<author>[^<]+)\s+(?<email><[^>]+>)/i;
88-
rl.on('line',(line)=>{
86+
forawait(constlineofrl){
8987
constmatch=line.match(authorRe);
90-
if(!match)return;
88+
if(!match)continue;
9189

9290
let{ author, email }=match.groups;
9391
constemailLower=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

Comments
(0)