-
Notifications
You must be signed in to change notification settings - Fork 0
Fix Leadtype CLI symlinked bin execution #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "leadtype": patch | ||
| --- | ||
|
|
||
| Fix the CLI direct-run check so package-manager bin shims and symlinked workspace installs correctly run `leadtype generate`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { realpathSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
| import { pathToFileURL } from "node:url"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { getGenerateUsage, runGenerateCommand } from "./cli/generate"; | ||
| import { logger, setLogStreams } from "./internal/logger"; | ||
| import { getLintUsage, runLintCommand } from "./lint/cli"; | ||
|
|
@@ -61,9 +62,21 @@ export async function runCli( | |
| return 2; | ||
| } | ||
|
|
||
| function isDirectRun(): boolean { | ||
| const entry = process.argv[1]; | ||
| return entry ? import.meta.url === pathToFileURL(resolve(entry)).href : false; | ||
| function resolveRealPath(filePath: string): string { | ||
| try { | ||
| return realpathSync.native(resolve(filePath)); | ||
| } catch { | ||
| return resolve(filePath); | ||
| } | ||
| } | ||
|
|
||
| export function isDirectRun( | ||
| entry = process.argv[1], | ||
| moduleUrl = import.meta.url | ||
| ): boolean { | ||
|
Comment on lines
+73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win Add explicit parameter types to exported Line 74 and Line 75 currently rely on inference; make the function contract explicit since this is an exported helper. Proposed patch export function isDirectRun(
- entry = process.argv[1],
- moduleUrl = import.meta.url
+ entry: string | undefined = process.argv[1],
+ moduleUrl: string = import.meta.url
): boolean {As per coding guidelines, 🤖 Prompt for AI Agents |
||
| return entry | ||
| ? resolveRealPath(entry) === resolveRealPath(fileURLToPath(moduleUrl)) | ||
| : false; | ||
| } | ||
|
|
||
| if (isDirectRun()) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.