From 14a14061414b498a699484e60862718fb99d7e3f Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 25 Sep 2023 15:13:40 -0700 Subject: [PATCH] detect main module properly Doesn't work otherwise if it's symlinked. Fix: /~https://github.com/isaacs/rimraf/issues/288 --- src/bin.mts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bin.mts b/src/bin.mts index 24bee3c9..324de6cd 100755 --- a/src/bin.mts +++ b/src/bin.mts @@ -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' @@ -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)