Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// oxlint-disable no-console

import { parseArgs, styleText } from 'node:util'
import { readFileSync } from 'node:fs'
import { readFileSync, realpathSync } from 'node:fs'
import { resolve, sep } from 'node:path'
import { fileURLToPath } from 'node:url'

Expand Down Expand Up @@ -116,7 +116,10 @@ async function read_stdin(): Promise<string> {
return Buffer.concat(chunks).toString('utf-8')
}

if (process.argv[1] === import.meta.filename) {
// Guards against run() firing when this module is imported (e.g. in tests).
// realpathSync is needed because pnpm's bin wrapper is a symlink, making process.argv[1]
// a different path than import.meta.filename without resolving it first.
if (process.argv[1] !== undefined && realpathSync(process.argv[1]) === import.meta.filename) {
try {
await run(process.argv.slice(2), {
readFile: (path) => readFileSync(path, 'utf-8'),
Expand Down