-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix first-run CLI command setup #611
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,30 @@ | ||
| import { describe, expect, test } from 'bun:test' | ||
| import { installGlobalPascalCommand, isNpxInvocation } from './command-install.js' | ||
|
|
||
| describe('short command installation', () => { | ||
| test('recognizes npm exec package-runner invocations', () => { | ||
| expect(isNpxInvocation({ npm_lifecycle_event: 'npx' })).toBe(true) | ||
| expect( | ||
| isNpxInvocation({ npm_command: 'exec', PATH: '/tmp/_npx/example/node_modules/.bin' }), | ||
| ).toBe(true) | ||
| expect(isNpxInvocation({ PATH: '/usr/local/bin:/usr/bin' })).toBe(false) | ||
| }) | ||
|
|
||
| test('installs the exact running version without lifecycle scripts', async () => { | ||
| let invocation: { command: string; args: string[] } | undefined | ||
| const installed = await installGlobalPascalCommand('1.2.3', async (command, args) => { | ||
| invocation = { command, args } | ||
| return 0 | ||
| }) | ||
|
|
||
| expect(installed).toBe(true) | ||
| expect(invocation).toEqual({ | ||
| command: process.platform === 'win32' ? 'npm.cmd' : 'npm', | ||
| args: ['install', '--global', '--ignore-scripts', '@pascal-app/cli@1.2.3'], | ||
| }) | ||
| }) | ||
|
|
||
| test('reports an installer failure without throwing', async () => { | ||
| expect(await installGlobalPascalCommand('1.2.3', async () => 1)).toBe(false) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { spawn } from 'node:child_process' | ||
|
|
||
| const INSTALL_TIMEOUT_MS = 2 * 60_000 | ||
|
|
||
| export function isNpxInvocation(environment: NodeJS.ProcessEnv = process.env): boolean { | ||
| return ( | ||
| environment.npm_lifecycle_event === 'npx' || | ||
| (environment.npm_command === 'exec' && | ||
| (environment.PATH ?? '').split(':').some((entry) => entry.includes('/_npx/'))) | ||
| ) | ||
|
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. Windows npx detection uses Unix PATHLow Severity The Reviewed by Cursor Bugbot for commit 9d373e4. Configure here. |
||
| } | ||
|
|
||
| export async function installGlobalPascalCommand( | ||
| packageVersion: string, | ||
| runInstaller: Installer = runNpmInstaller, | ||
| ): Promise<boolean> { | ||
| const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm' | ||
| return ( | ||
| (await runInstaller(npm, [ | ||
| 'install', | ||
| '--global', | ||
| '--ignore-scripts', | ||
| `@pascal-app/cli@${packageVersion}`, | ||
| ])) === 0 | ||
| ) | ||
| } | ||
|
|
||
| export type Installer = (command: string, args: string[]) => Promise<number> | ||
|
|
||
| async function runNpmInstaller(command: string, args: string[]): Promise<number> { | ||
| return new Promise<number>((resolve) => { | ||
| const child = spawn(command, args, { stdio: 'ignore' }) | ||
| const timeout = setTimeout(() => { | ||
| child.kill('SIGTERM') | ||
| resolve(1) | ||
| }, INSTALL_TIMEOUT_MS) | ||
| child.once('error', () => { | ||
| clearTimeout(timeout) | ||
| resolve(1) | ||
| }) | ||
| child.once('exit', (code) => { | ||
| clearTimeout(timeout) | ||
| resolve(code ?? 1) | ||
| }) | ||
| }) | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong short command for transient runners
Medium Severity
useShortCommandtreats every non-npxlaunch as ifpascalis already installed. Documented transient runners likepnpm dlxandbunxnever matchisNpxInvocationand never run the global install, so the ready output still directs users to barepascalcommands that are not onPATH, and it omits the manual install hint.Reviewed by Cursor Bugbot for commit 9d373e4. Configure here.