Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorFeng Yu <F3n67u@outlook.com>2022-05-21 18:31:31 +0300
committerBryan English <bryan@bryanenglish.com>2022-05-30 19:33:54 +0300
commit11830589089bd76cd4d6e370c1013034450e3f1c (patch)
tree7f7e9a4aeb45feac7edf227b2a14a6bd5bc4333a /tools
parent1da6b7c32b0feb394e11c7b698f855945e1f6c6e (diff)
tools: refactor update-authors.js to ESM
PR-URL: https://github.com/nodejs/node/pull/43098 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/update-authors.mjs (renamed from tools/update-authors.js)26
1 files changed, 11 insertions, 15 deletions
diff --git a/tools/update-authors.js b/tools/update-authors.mjs
index 5d8a5e7b368..971fe160e3c 100755
--- a/tools/update-authors.js
+++ b/tools/update-authors.mjs
@@ -1,11 +1,9 @@
#!/usr/bin/env node
-// Usage: tools/update-author.js [--dry]
+// Usage: tools/update-author.mjs [--dry]
// Passing --dry will redirect output to stdout rather than write to 'AUTHORS'.
-'use strict';
-const { spawn } = require('child_process');
-const path = require('path');
-const fs = require('fs');
-const readline = require('readline');
+import { spawn } from 'node:child_process';
+import fs from 'node:fs';
+import readline from 'node:readline';
class CaseIndifferentMap {
_map = new Map();
@@ -33,7 +31,7 @@ output.write('# Authors ordered by first contribution.\n\n');
const mailmap = new CaseIndifferentMap();
{
- const lines = fs.readFileSync(path.resolve(__dirname, '../', '.mailmap'),
+ const lines = fs.readFileSync(new URL('../.mailmap', import.meta.url),
{ encoding: 'utf8' }).split('\n');
for (let line of lines) {
line = line.trim();
@@ -55,7 +53,7 @@ const mailmap = new CaseIndifferentMap();
const previousAuthors = new CaseIndifferentMap();
{
- const lines = fs.readFileSync(path.resolve(__dirname, '../', 'AUTHORS'),
+ const lines = fs.readFileSync(new URL('../AUTHORS', import.meta.url),
{ encoding: 'utf8' }).split('\n');
for (let line of lines) {
line = line.trim();
@@ -85,9 +83,9 @@ const seen = new Set();
// by GitHub now.
const authorRe =
/(^Author:|^Co-authored-by:)\s+(?<author>[^<]+)\s+(?<email><[^>]+>)/i;
-rl.on('line', (line) => {
+for await (const line of rl) {
const match = line.match(authorRe);
- if (!match) return;
+ if (!match) continue;
let { author, email } = match.groups;
const emailLower = email.toLowerCase();
@@ -99,7 +97,7 @@ rl.on('line', (line) => {
}
if (seen.has(email)) {
- return;
+ continue;
}
seen.add(email);
@@ -109,8 +107,6 @@ rl.on('line', (line) => {
console.warn('Author name already in AUTHORS file. Possible duplicate:');
console.warn(` ${author} ${email}`);
}
-});
+}
-rl.on('close', () => {
- output.end('\n# Generated by tools/update-authors.js\n');
-});
+output.end('\n# Generated by tools/update-authors.mjs\n');