Skip to content

Commit 8806536

Browse files
committed
migrate script to generate problem matcher from commonjs to ESM
1 parent 201ad96 commit 8806536

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

.github/workflows/matcher.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Update test data
2727
run: make ./scripts/generate-actionlint-matcher/test/* SKIP_GO_GENERATE=true
2828
- name: Test actionlint-matcher.json
29-
run: node ./scripts/generate-actionlint-matcher/test.js
29+
run: node ./scripts/generate-actionlint-matcher/test.mjs
3030
- name: Ensure .github/actionlint-matcher.json is up-to-date
3131
run: |
3232
make .github/actionlint-matcher.json

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ man: man/actionlint.1
5858
bench:
5959
go test -bench Lint -benchmem
6060

61-
.github/actionlint-matcher.json: scripts/generate-actionlint-matcher/object.js
62-
node ./scripts/generate-actionlint-matcher/main.js .github/actionlint-matcher.json
61+
.github/actionlint-matcher.json: scripts/generate-actionlint-matcher/object.mjs
62+
node ./scripts/generate-actionlint-matcher/main.mjs .github/actionlint-matcher.json
6363

6464
scripts/generate-actionlint-matcher/test/escape.txt: actionlint
6565
./actionlint -color ./testdata/err/one_error.yaml > ./scripts/generate-actionlint-matcher/test/escape.txt || true

scripts/generate-actionlint-matcher/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ make .github/actionlint-matcher.json
1212
or directly run the script
1313

1414
```sh
15-
node ./scripts/generate-actionlint-matcher/main.js .github/actionlint-matcher.json
15+
node ./scripts/generate-actionlint-matcher/main.mjs .github/actionlint-matcher.json
1616
```
1717

1818
## Test
1919

2020
```sh
21-
node ./scripts/generate-actionlint-matcher/test.js
21+
node ./scripts/generate-actionlint-matcher/test.mjs
2222
```
2323

2424
The test uses test data at `./scripts/generate-actionlint-matcher/test/*.txt`. They should be updated when actionlint changes

scripts/generate-actionlint-matcher/main.js scripts/generate-actionlint-matcher/main.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require('fs').promises;
2-
const object = require('./object.js');
1+
import { promises as fs } from 'node:fs';
2+
import object from './object.mjs';
33

44
async function main(args) {
55
const json = JSON.stringify(object, null, 2);

scripts/generate-actionlint-matcher/object.js scripts/generate-actionlint-matcher/object.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ const object = {
3131
],
3232
};
3333

34-
module.exports = object;
34+
export default object;

scripts/generate-actionlint-matcher/test.js scripts/generate-actionlint-matcher/test.mjs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
const path = require('path');
2-
const fs = require('fs');
3-
const assert = require('assert').strict;
4-
const pattern = require('./object.js').problemMatcher[0].pattern[0];
1+
import path from 'node:path';
2+
import fs from 'node:fs';
3+
import assert from 'node:assert';
4+
import { fileURLToPath } from 'node:url';
5+
import object from './object.mjs';
6+
7+
const pattern = object.problemMatcher[0].pattern[0];
58
const regexp = new RegExp(pattern.regexp);
9+
const dirname = path.dirname(fileURLToPath(import.meta.url));
610

711
{
8-
const want = require('./test/want.json')[0];
12+
const want = JSON.parse(fs.readFileSync(path.join(dirname, 'test/want.json'), 'utf8'))[0];
913

1014
for (const file of ['escape.txt', 'no_escape.txt']) {
1115
console.log(`Testing test/${file}`);
12-
const escaped = path.join(__dirname, 'test', file);
16+
const escaped = path.join(dirname, 'test', file);
1317
const lines = fs.readFileSync(escaped, 'utf8').split('\n');
1418
const m = lines[0].match(regexp);
1519
assert.ok(m); // not null
@@ -23,7 +27,7 @@ const regexp = new RegExp(pattern.regexp);
2327
}
2428

2529
for (const parent of ['examples', 'err']) {
26-
const dir = path.join(__dirname, '..', '..', 'testdata', parent);
30+
const dir = path.join(dirname, '..', '..', 'testdata', parent);
2731
for (const name of fs.readdirSync(dir)) {
2832
if (!name.endsWith('.out')) {
2933
continue;

0 commit comments

Comments
 (0)