Skip to content

Commit 3eadbe5

Browse files
authored
Switch validate-pr to ESM (#3774) (#3777)
(cherry picked from commit 5263910) # Conflicts: # .github/validate-pr/index.js
1 parent 5631724 commit 3eadbe5

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

.github/validate-pr/index.js

+35-15
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,37 @@
1919

2020
/* global argv, path, cd */
2121

22-
'use strict'
22+
import { dirname } from 'path'
23+
import { fileURLToPath } from 'url'
24+
import 'zx/globals'
25+
import assert from 'assert'
26+
import * as core from '@actions/core'
27+
import { copyFile } from 'fs/promises'
28+
import * as github from '@actions/github'
29+
import specification from '../../output/schema/schema.json' assert { type: 'json' }
30+
import { run as getReport } from '../../../clients-flight-recorder/scripts/types-validator/index.js'
31+
import {
32+
getNamespace,
33+
getName
34+
} from '../../../clients-flight-recorder/scripts/types-validator/utils.js'
35+
36+
const __dirname = dirname(fileURLToPath(import.meta.url))
2337

24-
require('zx/globals')
25-
const assert = require('assert')
26-
const core = require('@actions/core')
27-
const { copyFile } = require('fs/promises')
28-
const github = require('@actions/github')
2938
const octokit = github.getOctokit(argv.token)
30-
const specification = require('../../output/schema/schema.json')
31-
const getReport = require('../../../clients-flight-recorder/scripts/types-validator')
32-
const { getNamespace, getName } = require('../../../clients-flight-recorder/scripts/types-validator/utils')
3339

3440
const privateNames = ['_global']
3541
const tick = '`'
36-
const tsValidationPath = path.join(__dirname, '..', '..', '..', 'clients-flight-recorder', 'scripts', 'types-validator')
37-
38-
async function run () {
42+
const tsValidationPath = path.join(
43+
__dirname,
44+
'..',
45+
'..',
46+
'..',
47+
'clients-flight-recorder',
48+
'scripts',
49+
'types-validator'
50+
)
51+
52+
async function run() {
3953
await copyFile(
4054
path.join(__dirname, '..', '..', 'output', 'typescript', 'types.ts'),
4155
path.join(tsValidationPath, 'types.ts')
@@ -53,14 +67,20 @@ async function run () {
5367
per_page: 100
5468
})
5569
if (data.length > 0) {
56-
files.push(...data.map(entry => entry.filename))
70+
files.push(
71+
...data
72+
.filter((entry) => entry.status !== 'deleted')
73+
.map((entry) => entry.filename)
74+
)
5775
page += 1
5876
} else {
5977
break
6078
}
6179
}
6280

63-
const specFiles = files.filter(file => file.includes('specification') && !file.includes('compiler/test'))
81+
const specFiles = files.filter(
82+
(file) => file.includes('specification') && !file.includes('compiler/test')
83+
)
6484
const table = []
6585

6686
cd(tsValidationPath)
@@ -163,7 +183,7 @@ function generateResponse (r) {
163183
return `${r.passingResponse}/${r.totalResponse}`
164184
}
165185

166-
run().catch(err => {
186+
run().catch((err) => {
167187
core.error(err)
168188
process.exit(1)
169189
})

.github/validate-pr/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "validate-pr",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
5+
"type": "module",
6+
"exports": "./index.js",
67
"scripts": {
78
"test": "echo \"Error: no test specified\" && exit 1"
89
},

0 commit comments

Comments
 (0)