Skip to content

Commit bc8118d

Browse files
F3n67ujuanarbol
authored andcommitted
tools: refactor update-authors.js to ESM
PR-URL: #43098 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 1f2d23c commit bc8118d

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

.github/workflows/authors.yml

+2-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3460,4 +3460,4 @@ William Marlow <william.marlow@ibm.com>
34603460
Keyhan Vakil <60900335+airtable-keyhanvakil@users.noreply.github.com>
34613461
Feng Yu <F3n67u@outlook.com>
34623462

3463-
# Generated by tools/update-authors.js
3463+
# Generated by tools/update-authors.mjs

tools/update-authors.js tools/update-authors.mjs

+11-15
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-
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

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

3432
const 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

5654
const 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.
8684
const authorRe =
8785
/(^Author:|^Co-authored-by:)\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

Comments
 (0)