11<script setup lang="ts">
22import type { JsrPackageInfo } from ' #shared/types/jsr'
3+ import type { DevDependencySuggestion } from ' #shared/utils/dev-dependency'
34import type { PackageManagerId } from ' ~/utils/install-command'
45
56const props = defineProps <{
67 packageName: string
78 requestedVersion? : string | null
89 installVersionOverride? : string | null
910 jsrInfo? : JsrPackageInfo | null
11+ devDependencySuggestion? : DevDependencySuggestion | null
1012 typesPackageName? : string | null
1113 executableInfo? : { hasExecutable: boolean ; primaryCommand? : string } | null
1214 createPackageInfo? : { packageName: string } | null
@@ -30,6 +32,20 @@ function getInstallPartsForPM(pmId: PackageManagerId) {
3032 })
3133}
3234
35+ const devDependencySuggestion = computed (
36+ () => props .devDependencySuggestion ?? { recommended: false as const },
37+ )
38+
39+ function getDevInstallPartsForPM(pmId : PackageManagerId ) {
40+ return getInstallCommandParts ({
41+ packageName: props .packageName ,
42+ packageManager: pmId ,
43+ version: props .requestedVersion ,
44+ jsrInfo: props .jsrInfo ,
45+ dev: true ,
46+ })
47+ }
48+
3349// Generate run command parts for a specific package manager
3450function getRunPartsForPM(pmId : PackageManagerId , command ? : string ) {
3551 return getRunCommandParts ({
@@ -68,7 +84,7 @@ function getTypesInstallPartsForPM(pmId: PackageManagerId) {
6884 const pm = packageManagers .find (p => p .id === pmId )
6985 if (! pm ) return []
7086
71- const devFlag = pmId === ' bun ' ? ' -d ' : ' -D '
87+ const devFlag = getDevDependencyFlag ( pmId )
7288 const pkgSpec = pmId === ' deno' ? ` npm:${props .typesPackageName } ` : props .typesPackageName
7389
7490 return [pm .label , pm .action , devFlag , pkgSpec ]
@@ -95,6 +111,18 @@ const copyRunCommand = (command?: string) => copyRun(getFullRunCommand(command))
95111
96112const { copied : createCopied, copy : copyCreate } = useClipboard ({ copiedDuring: 2000 })
97113const copyCreateCommand = () => copyCreate (getFullCreateCommand ())
114+
115+ const { copied : devInstallCopied, copy : copyDevInstall } = useClipboard ({ copiedDuring: 2000 })
116+ const copyDevInstallCommand = () =>
117+ copyDevInstall (
118+ getInstallCommand ({
119+ packageName: props .packageName ,
120+ packageManager: selectedPM .value ,
121+ version: props .requestedVersion ,
122+ jsrInfo: props .jsrInfo ,
123+ dev: true ,
124+ }),
125+ )
98126 </script >
99127
100128<template >
@@ -133,6 +161,42 @@ const copyCreateCommand = () => copyCreate(getFullCreateCommand())
133161 </button >
134162 </div >
135163
164+ <!-- Suggested dev dependency install command -->
165+ <template v-if =" devDependencySuggestion .recommended " >
166+ <div class =" flex items-center gap-2 pt-1 select-none" >
167+ <span class =" text-fg-subtle font-mono text-sm"
168+ ># {{ $t('package.get_started.dev_dependency_hint') }}</span
169+ >
170+ </div >
171+ <div
172+ v-for =" pm in packageManagers"
173+ :key =" `install-dev-${pm.id}`"
174+ :data-pm-cmd =" pm.id"
175+ class =" flex items-center gap-2 group/devinstallcmd min-w-0"
176+ >
177+ <span class =" text-fg-subtle font-mono text-sm select-none shrink-0" >$</span >
178+ <code class =" font-mono text-sm min-w-0"
179+ ><span
180+ v-for =" (part, i) in getDevInstallPartsForPM(pm.id)"
181+ :key =" i"
182+ :class =" i === 0 ? 'text-fg' : 'text-fg-muted'"
183+ >{{ i > 0 ? ' ' : '' }}{{ part }}</span
184+ ></code
185+ >
186+ <ButtonBase
187+ type =" button"
188+ size =" small"
189+ class =" text-fg-muted bg-bg-subtle/80 border-border opacity-0 group-hover/devinstallcmd:opacity-100 active:scale-95 focus-visible:opacity-100 select-none"
190+ :aria-label =" $t('package.get_started.copy_dev_command')"
191+ @click.stop =" copyDevInstallCommand"
192+ >
193+ <span aria-live =" polite" >{{
194+ devInstallCopied ? $t('common.copied') : $t('common.copy')
195+ }}</span >
196+ </ButtonBase >
197+ </div >
198+ </template >
199+
136200 <!-- @types package install - render all PM variants when types package exists -->
137201 <template v-if =" typesPackageName && showTypesInInstall " >
138202 <div
0 commit comments