Skip to content

Commit 97613ab

Browse files
committedOct 13, 2023
Require Node.js 18 and move to ESM
1 parent 9adfa76 commit 97613ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+622
-575
lines changed
 

‎.github/workflows/main.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 16
14-
- 14
15-
- 12
13+
- 20
14+
- 18
1615
steps:
17-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1817
with:
1918
submodules: true
2019
fetch-depth: 0
21-
- uses: actions/setup-node@v2
20+
- uses: actions/setup-node@v3
2221
with:
2322
node-version: ${{ matrix.node-version }}
2423
- run: npm install

‎cli.js

+30-32
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env node
2-
'use strict';
3-
const meow = require('meow');
4-
const findReadmeFile = require('./lib/find-readme-file.js');
5-
const awesomeLint = require('./index.js');
2+
import process from 'node:process';
3+
import meow from 'meow';
4+
import findReadmeFile from './lib/find-readme-file.js';
5+
import awesomeLint from './index.js';
66

7-
const getReporter = name => {
8-
// Check if reporter is an npm package
7+
const getReporter = async name => {
8+
// Check if reporter is an npm package.
99
try {
10-
return require(name).report;
10+
const {report} = await import(name);
11+
return report;
1112
} catch (error) {
1213
if (error.code === 'MODULE_NOT_FOUND') {
1314
console.error(`No reporter found matching \`${name}\`. Using default reporter (vfile-reporter-pretty).`);
@@ -17,34 +18,31 @@ const getReporter = name => {
1718
}
1819
};
1920

20-
const main = async () => {
21-
const cli = meow(`
22-
Usage
23-
$ awesome-lint [url|filename]
24-
25-
Options
26-
--reporter, -r Use a custom reporter
27-
`, {
28-
flags: {
29-
reporter: {
30-
type: 'string',
31-
alias: 'r'
32-
}
33-
}
34-
});
21+
const cli = meow(`
22+
Usage
23+
$ awesome-lint [url|filename]
3524
36-
const input = cli.input[0];
25+
Options
26+
--reporter, -r Use a custom reporter
27+
`, {
28+
importMeta: import.meta,
29+
flags: {
30+
reporter: {
31+
type: 'string',
32+
shortFlag: 'r',
33+
},
34+
},
35+
});
3736

38-
const options = {};
37+
const input = cli.input[0];
3938

40-
options.filename = input ? input : findReadmeFile(process.cwd());
39+
const options = {};
4140

42-
const reporterName = cli.flags.reporter;
43-
if (reporterName) {
44-
options.reporter = getReporter(reporterName);
45-
}
41+
options.filename = input ?? findReadmeFile(process.cwd());
4642

47-
await awesomeLint.report(options);
48-
};
43+
const reporterName = cli.flags.reporter;
44+
if (reporterName) {
45+
options.reporter = await getReporter(reporterName);
46+
}
4947

50-
main();
48+
await awesomeLint.report(options);

0 commit comments

Comments
 (0)
Please sign in to comment.