44 * It's "stupid by design" so it could work in minimal Node.js environments.
55 */
66
7+ import { cpSync , mkdtempSync , rmSync , writeFileSync } from 'node:fs'
78import { spawnSync } from 'node:child_process'
9+ import { tmpdir } from 'node:os'
10+ import { join } from 'node:path'
11+
12+ const projectDir = process . cwd ( )
813
914function getDependencyVersion ( dependencyName : string ) : string {
1015 const result = spawnSync ( 'npm' , [ 'pkg' , 'get' , `devDependencies.${ dependencyName } ` ] , {
@@ -18,8 +23,8 @@ function getDependencyVersion(dependencyName: string): string {
1823 return JSON . parse ( result . stdout )
1924}
2025
21- function runCommand ( command : string , args : string [ ] ) {
22- const result = spawnSync ( command , args , { stdio : 'inherit' } )
26+ function runCommand ( command : string , args : string [ ] , cwd ?: string ) {
27+ const result = spawnSync ( command , args , { stdio : 'inherit' , cwd } )
2328
2429 if ( result . status ) {
2530 throw new Error ( `Command failed: ${ command } ${ args . join ( ' ' ) } ` )
@@ -30,7 +35,21 @@ const oxlintVersion = getDependencyVersion('oxlint')
3035const oxfmtVersion = getDependencyVersion ( 'oxfmt' )
3136const e18eVersion = getDependencyVersion ( '@e18e/eslint-plugin' )
3237
33- // Install globally so we can also install peers
34- runCommand ( 'pnpm' , [ 'i' , '-g' , `@e18e/eslint-plugin@${ e18eVersion } ` , `oxlint@${ oxlintVersion } ` ] )
35- runCommand ( 'pnpm' , [ 'exec' , 'oxlint' ] )
38+ // Create a temp dir because:
39+ // 1. oxlint seems to try to resolve plugins from the dir of the config file
40+ // 2. pnpx/pnpm dlx doesn't have a clue about peers (plugins here), so doesn't have a way to install them
41+ const tempDir = mkdtempSync ( join ( tmpdir ( ) , 'oxlint-' ) )
42+ try {
43+ writeFileSync ( join ( tempDir , 'package.json' ) , '{"name": "temp", "version": "1.0.0"}' )
44+ cpSync ( '.oxlintrc.json' , join ( tempDir , '.oxlintrc.json' ) )
45+ runCommand (
46+ 'pnpm' ,
47+ [ 'install' , '-D' , `oxlint@${ oxlintVersion } ` , `@e18e/eslint-plugin@${ e18eVersion } ` ] ,
48+ tempDir ,
49+ )
50+ runCommand ( 'pnpm' , [ 'exec' , 'oxlint' , '-c' , join ( tempDir , '.oxlintrc.json' ) , projectDir ] , tempDir )
51+ } finally {
52+ rmSync ( tempDir , { recursive : true , force : true } )
53+ }
54+
3655runCommand ( 'pnpx' , [ `oxfmt@${ oxfmtVersion } ` , '--check' ] )
0 commit comments