Skip to content

Commit 9264e15

Browse files
committed
feat: add migration from old settings to new user-preferences in LS
- Clean migrated keys from legacy storage after migration - Guard migration with `npmx-prefs-migrated` flag to run only once - Update hydration tests to use `npmx-user-preferences` storage key - Add E2E tests for legacy settings migration
1 parent a725e83 commit 9264e15

31 files changed

+709
-402
lines changed

app/app.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ if (import.meta.server) {
4747
setJsonLd(createWebSiteSchema())
4848
}
4949
50-
const keyboardShortcuts = useKeyboardShortcuts()
51-
const instantSearch = useInstantSearch()
50+
const keyboardShortcuts = useKeyboardShortcutsPreference()
51+
const instantSearch = useInstantSearchPreference()
5252
5353
onKeyDown(
5454
'/',

app/components/AppHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { NavigationConfig, NavigationConfigWithGroups } from '~/types'
44
import { isEditableElement } from '~/utils/input'
55
import { NPMX_DOCS_SITE } from '#shared/utils/constants'
66
7-
const keyboardShortcuts = useKeyboardShortcuts()
7+
const keyboardShortcuts = useKeyboardShortcutsPreference()
88
const discord = useDiscordLink()
99
1010
withDefaults(

app/components/Button/Base.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const props = withDefaults(
3333
3434
const el = useTemplateRef('el')
3535
36-
const keyboardShortcutsEnabled = useKeyboardShortcuts()
36+
const keyboardShortcutsEnabled = useKeyboardShortcutsPreference()
3737
3838
defineExpose({
3939
focus: () => el.value?.focus(),

app/components/Compare/PackageSelector.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const resultIndexOffset = computed(() => (showNoDependencyOption.value ? 1 : 0))
7575
7676
const numberFormatter = useNumberFormatter()
7777
78-
const keyboardShortcuts = useKeyboardShortcuts()
78+
const keyboardShortcuts = useKeyboardShortcutsPreference()
7979
8080
function addPackage(name: string) {
8181
if (packages.value.length >= maxPackages.value) return

app/components/DateTime.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const props = withDefaults(
3131
3232
const { locale } = useI18n()
3333
34-
const relativeDates = useRelativeDates()
34+
const relativeDates = useRelativeDatesPreference()
3535
3636
const dateFormatter = new Intl.DateTimeFormat(locale.value, {
3737
month: 'short',

app/components/Input/Base.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const emit = defineEmits<{
3030
3131
const el = useTemplateRef('el')
3232
33-
const keyboardShortcutsEnabled = useKeyboardShortcuts()
33+
const keyboardShortcutsEnabled = useKeyboardShortcutsPreference()
3434
3535
defineExpose({
3636
focus: () => el.value?.focus(),

app/components/InstantSearch.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
const instantSearch = useInstantSearch()
2+
const instantSearch = useInstantSearchPreference()
33
44
onPrehydrate(el => {
55
let userPreferences: Record<string, unknown> = {}

app/components/Link/Base.vue

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,79 @@
11
<script setup lang="ts">
2-
import type { NuxtLinkProps } from '#app'
3-
import type { IconClass } from '~/types'
2+
import type { NuxtLinkProps } from "#app";
3+
import type { IconClass } from "~/types";
44
55
const props = withDefaults(
66
defineProps<{
77
/** Disabled links will be displayed as plain text */
8-
disabled?: boolean
8+
disabled?: boolean;
99
/**
1010
* `type` should never be used, because this will always be a link.
1111
* */
12-
type?: never
12+
type?: never;
1313
/** Visual style of the link */
14-
variant?: 'button-primary' | 'button-secondary' | 'link'
14+
variant?: "button-primary" | "button-secondary" | "link";
1515
/** Size (only applicable for button variants) */
16-
size?: 'sm' | 'md'
16+
size?: "sm" | "md";
1717
/** Makes the link take full width */
18-
block?: boolean
18+
block?: boolean;
1919
2020
/** Keyboard shortcut hint */
21-
ariaKeyshortcuts?: string
21+
ariaKeyshortcuts?: string;
2222
2323
/**
2424
* Don't use this directly. This will automatically be set to `_blank` for external links passed via `to`.
2525
*/
26-
target?: never
26+
target?: never;
2727
2828
/**
2929
* Don't use this directly. This will automatically be set for external links passed via `to`.
3030
*/
31-
rel?: never
31+
rel?: never;
3232
3333
/** Icon class to display */
34-
classicon?: IconClass
34+
classicon?: IconClass;
3535
3636
/** Link destination (internal or external URL) */
37-
to?: NuxtLinkProps['to']
37+
to?: NuxtLinkProps["to"];
3838
3939
/** always use `to` instead of `href` */
40-
href?: never
40+
href?: never;
4141
4242
/** should only be used for links where the context makes it very clear they are clickable. Don't just use this, because you don't like underlines. */
43-
noUnderline?: boolean
43+
noUnderline?: boolean;
4444
4545
/**
4646
* Hide external link icon (deprecated)
4747
* @deprecated @todo remove this property and add separate clean component without this logic
4848
*/
49-
noNewTabIcon?: boolean
49+
noNewTabIcon?: boolean;
5050
}>(),
51-
{ variant: 'link', size: 'md' },
52-
)
51+
{ variant: "link", size: "md" },
52+
);
5353
5454
const isLinkExternal = computed(
5555
() =>
5656
!!props.to &&
57-
typeof props.to === 'string' &&
58-
(props.to.startsWith('http:') || props.to.startsWith('https:') || props.to.startsWith('//')),
59-
)
57+
typeof props.to === "string" &&
58+
(props.to.startsWith("http:") || props.to.startsWith("https:") || props.to.startsWith("//")),
59+
);
6060
const isLinkAnchor = computed(
61-
() => !!props.to && typeof props.to === 'string' && props.to.startsWith('#'),
62-
)
61+
() => !!props.to && typeof props.to === "string" && props.to.startsWith("#"),
62+
);
6363
6464
/** size is only applicable for button like links */
65-
const isLink = computed(() => props.variant === 'link')
66-
const isButton = computed(() => !isLink.value)
67-
const isButtonSmall = computed(() => props.size === 'sm' && !isLink.value)
68-
const isButtonMedium = computed(() => props.size === 'md' && !isLink.value)
69-
const keyboardShortcutsEnabled = useKeyboardShortcuts()
65+
const isLink = computed(() => props.variant === "link");
66+
const isButton = computed(() => !isLink.value);
67+
const isButtonSmall = computed(() => props.size === "sm" && !isLink.value);
68+
const isButtonMedium = computed(() => props.size === "md" && !isLink.value);
69+
const keyboardShortcutsEnabled = useKeyboardShortcutsPreference();
7070
</script>
7171

7272
<template>
7373
<span
7474
v-if="disabled"
7575
:class="{
76-
'flex': block,
76+
flex: block,
7777
'inline-flex': !block,
7878
'opacity-50 gap-x-1 items-center justify-center font-mono border border-transparent rounded-md':
7979
isButton,
@@ -89,7 +89,7 @@ const keyboardShortcutsEnabled = useKeyboardShortcuts()
8989
v-else
9090
class="group/link gap-x-1 items-center"
9191
:class="{
92-
'flex': block,
92+
flex: block,
9393
'inline-flex': !block,
9494
'underline-offset-[0.2rem] underline decoration-1 decoration-fg/30':
9595
!isLinkAnchor && isLink && !noUnderline,

app/components/Package/WeeklyDownloadStats.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ const dataset = computed<VueUiSparklineDatasetItem[]>(() =>
209209
const lastDatapoint = computed(() => dataset.value.at(-1)?.period ?? '')
210210
211211
const showPulse = shallowRef(true)
212-
const keyboardShortcuts = useKeyboardShortcuts()
212+
const keyboardShortcuts = useKeyboardShortcutsPreference()
213213
214214
const cheatCode = [
215215
'arrowup',

app/composables/useGlobalSearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const pagesWithLocalFilter = new Set(["~username", "org"]);
77
const SEARCH_DEBOUNCE_MS = 100;
88

99
export function useGlobalSearch(place: "header" | "content" = "content") {
10-
const instantSearch = useInstantSearch();
10+
const instantSearch = useInstantSearchPreference();
1111
const { searchProvider } = useSearchProvider();
1212
const searchProviderValue = computed(() => {
1313
const p = normalizeSearchParam(route.query.p);

0 commit comments

Comments
 (0)