Skip to content

Commit

Permalink
tools: refactor update-authors.js to esm module
Browse files Browse the repository at this point in the history
  • Loading branch information
F3n67u committed May 14, 2022
1 parent 556df3d commit b080a08
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
fetch-depth: '0' # This is required to actually get all the authors
persist-credentials: false
- run: tools/update-authors.js # Run the AUTHORS tool
- run: tools/update-authors.mjs # Run the AUTHORS tool
- uses: gr2m/create-or-update-pull-request-action@v1 # Create a PR or update the Action's existing PR
env:
GITHUB_TOKEN: ${{ secrets.GH_USER_TOKEN }}
Expand All @@ -24,7 +24,7 @@ jobs:
body: >
Here are some new additions to the AUTHORS file.
This is an automatically generated PR by the
`authors.yml` GitHub Action, which runs `tools/update-authors.js`.
`authors.yml` GitHub Action, which runs `tools/update-authors.mjs`.
branch: actions/authors-update # Custom branch *just* for this Action.
commit-message: 'meta: update AUTHORS'
labels: meta
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3461,4 +3461,4 @@ William Marlow <[email protected]>
Keyhan Vakil <[email protected]>
Feng Yu <[email protected]>

# Generated by tools/update-authors.js
# Generated by tools/update-authors.mjs
16 changes: 7 additions & 9 deletions tools/update-authors.js → tools/update-authors.mjs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -112,5 +110,5 @@ rl.on('line', (line) => {
});

rl.on('close', () => {
output.end('\n# Generated by tools/update-authors.js\n');
output.end('\n# Generated by tools/update-authors.mjs\n');
});

0 comments on commit b080a08

Please sign in to comment.