Skip to content

Commit

Permalink
detect main module properly
Browse files Browse the repository at this point in the history
Doesn't work otherwise if it's symlinked.

Fix: #288
  • Loading branch information
isaacs committed Sep 25, 2023
1 parent 6297992 commit 14a1406
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/bin.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
import { realpathSync } from 'fs'
import { readFile } from 'fs/promises'
import type { RimrafAsyncOptions } from './index.js'
import { rimraf } from './index.js'
Expand Down Expand Up @@ -260,7 +261,10 @@ const main = async (...args: string[]) => {
main.help = help

export default main
const isMainModule = process.argv[1] === fileURLToPath(import.meta.url)

const isMainModule =
realpathSync(String(process.argv[1])) ===
realpathSync(fileURLToPath(import.meta.url))

if (isMainModule) {
const args = process.argv.slice(2)
Expand Down

0 comments on commit 14a1406

Please sign in to comment.