Skip to content

Commit 14a1406

Browse files
committed
detect main module properly
Doesn't work otherwise if it's symlinked. Fix: #288
1 parent 6297992 commit 14a1406

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/bin.mts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
import { realpathSync } from 'fs'
23
import { readFile } from 'fs/promises'
34
import type { RimrafAsyncOptions } from './index.js'
45
import { rimraf } from './index.js'
@@ -260,7 +261,10 @@ const main = async (...args: string[]) => {
260261
main.help = help
261262

262263
export default main
263-
const isMainModule = process.argv[1] === fileURLToPath(import.meta.url)
264+
265+
const isMainModule =
266+
realpathSync(String(process.argv[1])) ===
267+
realpathSync(fileURLToPath(import.meta.url))
264268

265269
if (isMainModule) {
266270
const args = process.argv.slice(2)

0 commit comments

Comments
 (0)