diff --git a/app/components/Package/Install/AdditionalCommands.vue b/app/components/Package/Install/AdditionalCommands.vue index 712ddb2b3b..0e42a13670 100644 --- a/app/components/Package/Install/AdditionalCommands.vue +++ b/app/components/Package/Install/AdditionalCommands.vue @@ -2,6 +2,7 @@ import type { JsrPackageInfo } from '#shared/types/jsr' import type { DevDependencySuggestion } from '#shared/utils/dev-dependency' import type { PackageManagerId } from '~/utils/install-command' +import { getPackageManagerConfig } from '~/utils/install-command' const props = defineProps<{ packageName: string @@ -16,6 +17,17 @@ const props = defineProps<{ selectedPm: PackageManagerId }>() +const isMounted = ref(false) +onMounted(() => { + isMounted.value = true +}) + +const resolvedPm = computed(() => { + return isMounted.value ? props.selectedPm : 'npm' +}) + +const selectedPackageManagerConfig = computed(() => getPackageManagerConfig(resolvedPm.value)) + // Matches the summary row's copy button style (Package/Install/Dropdown.vue) for visual consistency. const copyButtonClass = 'text-fg-muted bg-bg-subtle/80 border-border transition-all duration-150 hover:scale-105 active:scale-90 select-none' @@ -24,41 +36,41 @@ const devDependencySuggestion = computed( () => props.devDependencySuggestion ?? { recommended: false as const }, ) -function getDevInstallPartsForPM(pmId: PackageManagerId) { +function getDevInstallParts() { return getInstallCommandParts({ packageName: props.packageName, - packageManager: pmId, + packageManager: selectedPackageManagerConfig.value.id, version: props.installVersionOverride ?? props.requestedVersion, jsrInfo: props.jsrInfo, dev: true, }) } -function getTypesInstallPartsForPM(pmId: PackageManagerId) { +function getTypesInstallParts() { if (!props.typesPackageName) return [] return getInstallCommandParts({ packageName: props.typesPackageName, - packageManager: pmId, + packageManager: selectedPackageManagerConfig.value.id, jsrInfo: null, dev: true, }) } -function getRunPartsForPM(pmId: PackageManagerId, command?: string) { +function getRunParts(command?: string) { return getRunCommandParts({ packageName: props.packageName, - packageManager: pmId, + packageManager: selectedPackageManagerConfig.value.id, jsrInfo: props.jsrInfo, command, isBinaryOnly: false, }) } -function getCreatePartsForPM(pmId: PackageManagerId) { +function getCreateParts() { if (!props.createPackageInfo) return [] return getExecuteCommandParts({ packageName: props.createPackageInfo.packageName, - packageManager: pmId, + packageManager: selectedPackageManagerConfig.value.id, jsrInfo: null, isCreatePackage: true, }) @@ -148,21 +160,16 @@ function copyCreateCommand() { ${{ ' ' }} + $ + {{ i > 0 ? ' ' : '' }}{{ part }} + > + @@ -187,21 +194,18 @@ function copyCreateCommand() { ${{ ' ' }} + $ + {{ i > 0 ? ' ' : '' }}{{ part }} + > + ${{ ' ' }} + $ + {{ i > 0 ? ' ' : '' }}{{ part }} + > + @@ -285,44 +288,16 @@ function copyCreateCommand() { ${{ ' ' }} + $ + {{ i > 0 ? ' ' : '' }}{{ part }} + > + - diff --git a/app/components/Package/Install/Dropdown.vue b/app/components/Package/Install/Dropdown.vue index d5ebca4aef..43d2270d10 100644 --- a/app/components/Package/Install/Dropdown.vue +++ b/app/components/Package/Install/Dropdown.vue @@ -3,6 +3,7 @@ import type { JsrPackageInfo } from '#shared/types/jsr' import type { SlimPackumentVersion } from '#shared/types' import type { DevDependencySuggestion } from '#shared/utils/dev-dependency' import type { PublishSecurityDowngrade } from '~/utils/publish-security' +import { getPackageManagerConfig } from '~/utils/install-command' const props = defineProps<{ packageName: string @@ -19,6 +20,11 @@ const props = defineProps<{ headingId: string }>() +const isMounted = ref(false) +onMounted(() => { + isMounted.value = true +}) + const { selectedPM, showTypesInInstall, copied, copyInstallCommand } = useInstallCommand( () => props.packageName, () => props.requestedVersion ?? null, @@ -27,6 +33,12 @@ const { selectedPM, showTypesInInstall, copied, copyInstallCommand } = useInstal () => props.installVersionOverride ?? null, ) +const resolvedPM = computed(() => { + return isMounted.value ? selectedPM.value : 'npm' +}) + +const selectedPackageManagerConfig = computed(() => getPackageManagerConfig(resolvedPM.value)) + const { announce } = useCommandPalette() const { polite } = useAnnouncer() async function copyInstallCommandWithAnnounce() { @@ -137,14 +149,11 @@ onPrehydrate(el => { { :show-types="showTypesInInstall" :executable-info="executableInfo" :create-package-info="createPackageInfo" - :selected-pm="selectedPM" + :selected-pm="resolvedPM" /> @@ -186,28 +195,3 @@ onPrehydrate(el => { - diff --git a/test/e2e/create-command.spec.ts b/test/e2e/create-command.spec.ts index d375656a26..7c088cecfb 100644 --- a/test/e2e/create-command.spec.ts +++ b/test/e2e/create-command.spec.ts @@ -22,8 +22,7 @@ test.describe('Create Command', () => { const createCommandSection = page.locator('[data-testid="create-command"]').first() await expect(createCommandSection).toBeVisible() - const activePm = await page.locator('[data-pm]').first().getAttribute('data-pm') - const commandRow = createCommandSection.locator(`[data-pm-additional-cmd="${activePm}"]`) + const commandRow = createCommandSection.locator('code[data-pm-additional-cmd]') await expect(commandRow).toBeVisible() await expect(commandRow).toContainText(/create vite/i) @@ -42,8 +41,7 @@ test.describe('Create Command', () => { const createCommandSection = page.locator('[data-testid="create-command"]').first() await expect(createCommandSection).toBeVisible() - const activePm = await page.locator('[data-pm]').first().getAttribute('data-pm') - const commandRow = createCommandSection.locator(`[data-pm-additional-cmd="${activePm}"]`) + const commandRow = createCommandSection.locator('code[data-pm-additional-cmd]') await expect(commandRow).toBeVisible() await expect(commandRow).toContainText(/create next-app/i) @@ -63,8 +61,7 @@ test.describe('Create Command', () => { // nuxt has create-nuxt package, so command is "npm create nuxt" const createCommandSection = page.locator('[data-testid="create-command"]').first() await expect(createCommandSection).toBeVisible() - const activePm = await page.locator('[data-pm]').first().getAttribute('data-pm') - const commandRow = createCommandSection.locator(`[data-pm-additional-cmd="${activePm}"]`) + const commandRow = createCommandSection.locator('code[data-pm-additional-cmd]') await expect(commandRow).toBeVisible() await expect(commandRow).toContainText(/create nuxt/i) })