-
-
Notifications
You must be signed in to change notification settings - Fork 424
feat: add binary run scripts to package page #209
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f69bd6b
Add binary run scripts to package page
vinnymac b8e54e4
test: remove dupe test
danielroe 315dbf2
Add inline run commands
vinnymac 507ded2
Fix highlighting
vinnymac cab5532
Update exec, add create support, and remove more than one binary
vinnymac 447f536
fix: add composable for package analysis and copy, fix create edge ca…
vinnymac b1ece56
fix: package vue i18n
vinnymac 12c1d45
fix: theming of create commands
vinnymac 1e0fecd
fix: type narrowing
vinnymac 950e585
fix: prefer `$t`
danielroe 47013e9
refactor: use `useClipboard` from vueuse
danielroe 5bb7fea
test: add playwright test for commands
danielroe 4a27f3b
Merge remote-tracking branch 'origin/main' into vt/commands
danielroe de59402
test: update tests for vueuse
danielroe 98b96a2
fix: increase colour contrast
danielroe c8dbc91
test: try to address flakiness
danielroe f981dd5
Merge upstream/main into vt/commands
vinnymac 88b1dc8
fix: create command tests
vinnymac d0af775
Merge main into vt/commands
vinnymac 22bd7a8
fix: a11y ci tests
vinnymac 895549f
Merge branch 'main' into vt/commands
danielroe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import type { JsrPackageInfo } from '#shared/types/jsr' | ||
| import { getPackageSpecifier, packageManagers } from './install-command' | ||
| import type { PackageManagerId } from './install-command' | ||
|
|
||
| /** | ||
| * Metadata needed to determine if a package is binary-only. | ||
| */ | ||
| export interface PackageMetadata { | ||
| name: string | ||
| bin?: string | Record<string, string> | ||
| main?: string | ||
| module?: unknown | ||
| exports?: unknown | ||
| } | ||
|
|
||
| /** | ||
| * Determine if a package is "binary-only" (executable without library entry points). | ||
| * Binary-only packages should show execute commands without install commands. | ||
| * | ||
| * A package is binary-only if: | ||
| * - Name starts with "create-" (e.g., create-vite) | ||
| * - Scoped name contains "/create-" (e.g., @vue/create-app) | ||
| * - Has bin field but no main, module, or exports fields | ||
| */ | ||
| export function isBinaryOnlyPackage(pkg: PackageMetadata): boolean { | ||
| const baseName = pkg.name.startsWith('@') ? pkg.name.split('/')[1] : pkg.name | ||
|
|
||
| // Check create-* patterns | ||
| if (baseName?.startsWith('create-') || pkg.name.includes('/create-')) { | ||
| return true | ||
| } | ||
|
|
||
| // Has bin but no entry points | ||
| const hasBin = | ||
| pkg.bin !== undefined && (typeof pkg.bin === 'string' || Object.keys(pkg.bin).length > 0) | ||
| const hasEntryPoint = !!pkg.main || !!pkg.module || !!pkg.exports | ||
|
|
||
| return hasBin && !hasEntryPoint | ||
| } | ||
|
|
||
| /** | ||
| * Check if a package uses the create-* naming convention. | ||
| */ | ||
| export function isCreatePackage(packageName: string): boolean { | ||
| const baseName = packageName.startsWith('@') ? packageName.split('/')[1] : packageName | ||
| return baseName?.startsWith('create-') || packageName.includes('/create-') || false | ||
| } | ||
|
|
||
| /** | ||
| * Information about executable commands provided by a package. | ||
| */ | ||
| export interface ExecutableInfo { | ||
| /** Primary command name (typically the package name or first bin key) */ | ||
| primaryCommand: string | ||
| /** All available command names */ | ||
| commands: string[] | ||
| /** Whether this package has any executables */ | ||
| hasExecutable: boolean | ||
| } | ||
|
|
||
| /** | ||
| * Extract executable command information from a package's bin field. | ||
| * Handles both string format ("bin": "./cli.js") and object format ("bin": { "cmd": "./cli.js" }). | ||
| */ | ||
| export function getExecutableInfo( | ||
| packageName: string, | ||
| bin: string | Record<string, string> | undefined, | ||
| ): ExecutableInfo { | ||
| if (!bin) { | ||
| return { primaryCommand: '', commands: [], hasExecutable: false } | ||
| } | ||
|
|
||
| // String format: package name becomes the command | ||
| if (typeof bin === 'string') { | ||
| return { | ||
| primaryCommand: packageName, | ||
| commands: [packageName], | ||
| hasExecutable: true, | ||
| } | ||
| } | ||
|
|
||
| // Object format: keys are command names | ||
| const commands = Object.keys(bin) | ||
| const firstCommand = commands[0] | ||
| if (!firstCommand) { | ||
| return { primaryCommand: '', commands: [], hasExecutable: false } | ||
| } | ||
|
|
||
| // Prefer command matching package name if it exists, otherwise use first | ||
| const baseName = packageName.startsWith('@') ? packageName.split('/')[1] : packageName | ||
| const primaryCommand = baseName && commands.includes(baseName) ? baseName : firstCommand | ||
|
|
||
| return { | ||
| primaryCommand, | ||
| commands, | ||
| hasExecutable: true, | ||
| } | ||
| } | ||
|
|
||
| export interface RunCommandOptions { | ||
| packageName: string | ||
| packageManager: PackageManagerId | ||
| version?: string | null | ||
| jsrInfo?: JsrPackageInfo | null | ||
| /** Specific command to run (for packages with multiple bin entries) */ | ||
| command?: string | ||
| /** Whether this is a binary-only package (affects which execute command to use) */ | ||
| isBinaryOnly?: boolean | ||
| } | ||
|
|
||
| /** | ||
| * Generate run command as an array of parts. | ||
| * First element is the package manager label (e.g., "pnpm"), rest are arguments. | ||
| * For example: ["pnpm", "exec", "eslint"] or ["pnpm", "dlx", "create-vite"] | ||
| */ | ||
| export function getRunCommandParts(options: RunCommandOptions): string[] { | ||
| const pm = packageManagers.find(p => p.id === options.packageManager) | ||
| if (!pm) return [] | ||
|
|
||
| const spec = getPackageSpecifier(options) | ||
|
|
||
| // Choose execute command based on package type | ||
| const executeCmd = options.isBinaryOnly ? pm.executeRemote : pm.executeLocal | ||
| const executeParts = executeCmd.split(' ') | ||
|
|
||
| // For deno, always use the package specifier | ||
| if (options.packageManager === 'deno') { | ||
| return [...executeParts, spec] | ||
| } | ||
|
|
||
| // For local execute with specific command name different from package name | ||
| // e.g., `pnpm exec tsc` for typescript package | ||
| if (options.command && options.command !== options.packageName) { | ||
| const baseName = options.packageName.startsWith('@') | ||
| ? options.packageName.split('/')[1] | ||
| : options.packageName | ||
| // If command matches base package name, use the package spec | ||
| if (options.command === baseName) { | ||
| return [...executeParts, spec] | ||
| } | ||
| // Otherwise use the command name directly | ||
| return [...executeParts, options.command] | ||
| } | ||
|
|
||
| return [...executeParts, spec] | ||
| } | ||
|
|
||
| /** | ||
| * Generate the full run command for a package. | ||
| */ | ||
| export function getRunCommand(options: RunCommandOptions): string { | ||
| return getRunCommandParts(options).join(' ') | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.