From c5018d4a5aea4cb44e22a6c6817be62afe311c56 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 18 Apr 2026 23:21:08 +0800 Subject: [PATCH] Handle symlinked npm CLI entrypoints --- packages/cli/src/index.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 6dfb88c..cf93a0e 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -1,10 +1,11 @@ #!/usr/bin/env node import { Command } from 'commander'; +import { realpathSync } from 'node:fs'; import { chmod, mkdir, readFile, rename, writeFile } from 'node:fs/promises'; import { homedir } from 'node:os'; import { dirname, join } from 'node:path'; -import { pathToFileURL } from 'node:url'; +import { fileURLToPath, pathToFileURL } from 'node:url'; import { GraphQLClient } from 'graphql-request'; import { type ViewerAssertionSubjectType, @@ -1199,7 +1200,19 @@ export function createProgram(): Command { const currentEntryPoint = process.argv[1]; -if (currentEntryPoint && import.meta.url === pathToFileURL(currentEntryPoint).href) { +function isCliEntrypoint(entryPoint: string | undefined): boolean { + if (!entryPoint) { + return false; + } + + try { + return realpathSync(entryPoint) === realpathSync(fileURLToPath(import.meta.url)); + } catch { + return import.meta.url === pathToFileURL(entryPoint).href; + } +} + +if (isCliEntrypoint(currentEntryPoint)) { createProgram().parse(process.argv); }