-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathlint.ts
More file actions
38 lines (30 loc) · 1.19 KB
/
lint.ts
File metadata and controls
38 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* This script runs oxlint and oxfmt in a CI environment, without the need to install the entire
* project. It reads the required version from pnpm-lock.yaml and executes the linters accordingly.
* It's "stupid by design" so it could work in minimal Node.js environments.
*/
import { spawnSync } from 'node:child_process'
function getDependencyVersion(dependencyName: string): string {
const result = spawnSync('npm', ['pkg', 'get', `devDependencies.${dependencyName}`], {
encoding: 'utf8',
})
if (result.status) {
throw new Error(`Command failed: pnpm info ${dependencyName} version`)
}
return JSON.parse(result.stdout)
}
function runCommand(command: string, args: string[]) {
const result = spawnSync(command, args, { stdio: 'inherit' })
if (result.status) {
throw new Error(`Command failed: ${command} ${args.join(' ')}`)
}
}
const oxlintVersion = getDependencyVersion('oxlint')
const oxfmtVersion = getDependencyVersion('oxfmt')
const e18eVersion = getDependencyVersion('@e18e/eslint-plugin')
runCommand('pnpx', [
`--package=@e18e/eslint-plugin@${e18eVersion}`,
`--package=oxlint@${oxlintVersion}`,
'oxlint',
])
runCommand('pnpx', [`oxfmt@${oxfmtVersion}`, '--check'])