nuxt / nuxt.com

The Nuxt website, made with Nuxt.
https://nuxt.com
MIT License
299 stars 156 forks source link

feat: add persistence to package manager choice #1635

Closed gustavwilliam closed 2 months ago

gustavwilliam commented 2 months ago

๐Ÿ”— Linked issue

Resolves nuxt/nuxt#28499

โ“ Type of change

๐Ÿ“š Description

Adds a new content type in the docs for package manager instructions. When the user selects a package manager, the choice of package manager will be:

If the persisted package manager is not available for a given codegroup, the preference will default to npm.

All package manager code groups have been updated to the order npm -> yarn -> pnpm -> bun. An accompanying PR (nuxt/nuxt#28514) has been opened on nuxt/nuxt, to utilize this new PackageManagers component.

Implementation choices

Watches exposed property selectedIndex from the Nuxt UI Pro CodeGroup component. On selecting a new package manager, all package managers code groups will update instantly. This document-wide update is done using a document event listener. While a state management system like Pinia could be used to do this, I didn't find anything like that installed yet, and this small feature didn't justify adding the dependency in my opinion.

In order to allow flexibility with what package managers are available, I opted to not implement automatic sorting of the available package managers in the code groups. Instead, the PackageManagers component dynamically gets the index of the persisted package manager. This means that regardless of the order of package managers passed to the component, the correct package manager will be selected.

gustavwilliam commented 2 months ago

@Flosciante from my debugging efforts, I can't isolate this PR as the cause of the warning. I'm getting the same warnings in the console when:

At least this is what happens when I run it locally. Are you getting similar results?

Flosciante commented 2 months ago

oh you're right @gustavwilliam, my fault I should have checked without this PR too ! I think we can open an issue on the production site in this case :-) so, LGTM on your PR, I'll let you make transition to nuxt/nuxt to say that it's ok on the nuxt.com side ^^