Thank you for your interest in contributing! ❤️ This document provides guidelines and instructions for contributing.
Important
Please be respectful and constructive in all interactions. We aim to maintain a welcoming environment for all contributors. 👉 Read more
We want to create 'a fast, modern browser for the npm registry.' This means, among other things:
- We don't aim to replace the npmjs.com registry, just provide a better UI and DX.
- Layout shift, flakiness, slowness is The Worst. We need to continually iterate to create the most performant, best DX possible.
- We want to provide information in the best way. We don't want noise, cluttered display, or confusing UI. If in doubt: choose simplicity.
-
fork and clone the repository
-
install dependencies:
pnpm install
-
start the development server:
pnpm dev
-
(optional) if you want to test the admin UI/flow, you can run the local connector:
pnpm npmx-connector
# Development
pnpm dev # Start development server
pnpm build # Production build
pnpm preview # Preview production build
# Code Quality
pnpm lint # Run linter (oxlint + oxfmt)
pnpm lint:fix # Auto-fix lint issues
pnpm test:types # TypeScript type checking
# Testing
pnpm test # Run all Vitest tests
pnpm test:unit # Unit tests only
pnpm test:nuxt # Nuxt component tests
pnpm test:browser # Playwright E2E testsapp/ # Nuxt 4 app directory
├── components/ # Vue components (PascalCase.vue)
├── composables/ # Vue composables (useFeature.ts)
├── pages/ # File-based routing
├── plugins/ # Nuxt plugins
├── app.vue # Root component
└── error.vue # Error page
server/ # Nitro server
├── api/ # API routes
└── utils/ # Server utilities
shared/ # Shared between app and server
└── types/ # TypeScript type definitions
cli/ # Local connector CLI (separate workspace)
test/ # Vitest tests
├── unit/ # Unit tests (*.spec.ts)
└── nuxt/ # Nuxt component tests
tests/ # Playwright E2E tests
Tip
For more about the meaning of these directories, check out the docs on the Nuxt directory structure.
The cli/ workspace contains a local connector that enables authenticated npm operations from the web UI. It runs on your machine and uses your existing npm credentials.
# run the connector from the root of the repository
pnpm npmx-connectorThe connector will check your npm authentication, generate a connection token, and listen for requests from npmx.dev.
- We care about good types – never cast things to
any💪 - Validate rather than just assert
Use Valibot schemas from #shared/schemas/ to validate API inputs. This ensures type safety and provides consistent error messages:
import * as v from 'valibot'
import { PackageRouteParamsSchema } from '#shared/schemas/package'
// In your handler:
const { packageName, version } = v.parse(PackageRouteParamsSchema, {
packageName: rawPackageName,
version: rawVersion,
})Use the handleApiError utility for consistent error handling in API routes. It re-throws H3 errors (like 404s) and wraps other errors with a fallback message:
import { ERROR_NPM_FETCH_FAILED } from '#shared/utils/constants'
try {
// API logic...
} catch (error: unknown) {
handleApiError(error, {
statusCode: 502,
message: ERROR_NPM_FETCH_FAILED,
})
}Use parsePackageParams to extract package name and version from URL segments:
const pkgParamSegments = getRouterParam(event, 'pkg')?.split('/') ?? []
const { rawPackageName, rawVersion } = parsePackageParams(pkgParamSegments)This handles patterns like /pkg, /pkg/v/1.0.0, /@scope/pkg, and /@scope/pkg/v/1.0.0.
Define error messages and other string constants in #shared/utils/constants.ts to ensure consistency across the codebase:
export const ERROR_NPM_FETCH_FAILED = 'Failed to fetch package from npm registry.'- Type imports first (
import type { ... }) - External packages
- Internal aliases (
#shared/types,#server/, etc.) - No blank lines between groups
import type { Packument, NpmSearchResponse } from '#shared/types'
import type { Tokens } from 'marked'
import { marked } from 'marked'
import { hasProtocol } from 'ufo'| Type | Convention | Example |
|---|---|---|
| Vue components | PascalCase | MarkdownText.vue |
| Pages | kebab-case | search.vue, [...name].vue |
| Composables | camelCase + use prefix |
useNpmRegistry.ts |
| Server routes | kebab-case + method | search.get.ts |
| Functions | camelCase | fetchPackage, formatDate |
| Constants | SCREAMING_SNAKE_CASE | NPM_REGISTRY, ALLOWED_TAGS |
| Types/Interfaces | PascalCase | NpmSearchResponse |
Tip
Exports in app/composables/, app/utils/, and server/utils/ are auto-imported by Nuxt. To prevent knip from flagging them as unused, add a @public JSDoc annotation:
/**
* @public
*/
export function myAutoImportedFunction() {
// ...
}- Use Composition API with
<script setup lang="ts"> - Define props with TypeScript:
defineProps<{ text: string }>() - Keep functions under 50 lines
- Accessibility is a first-class consideration – always consider ARIA attributes and keyboard navigation
<script setup lang="ts">
import type { PackumentVersion } from '#shared/types'
const props = defineProps<{
version: PackumentVersion
}>()
</script>Ideally, extract utilities into separate files so they can be unit tested. 🙏
We support right-to-left languages, we need to make sure that the UI is working correctly in both directions.
Simple approach used by most websites of relying on direction set in HTML element does not work because direction for various items, such as timeline, does not always match direction set in HTML.
We've added some UnoCSS utilities styles to help you with that:
- Do not use
left/rightpadding and margin: for examplepl-1. Usepadding-inline-start/endinstead. Sopl-1should beps-1,pr-1should bepe-1. The same rules apply to margin. - Do not use
rtl-classes, such asrtl-left-0. - For icons that should be rotated for RTL, add
class="rtl-flip". This can only be used for icons outside of elements withdir="auto". - For absolute positioned elements, don't use
left/right: for exampleleft-0. Useinset-inline-start/endinstead.UnoCSSshortcuts areinset-isforinset-inline-startandinset-ieforinset-inline-end. Example:left-0should be replaced withinset-is-0. - If you need to change the border radius for an entire left or right side, use
border-inline-start/end.UnoCSSshortcuts arerounded-isfor left side,rounded-iefor right side. Example:rounded-l-5should be replaced withrounded-ie-5. - If you need to change the border radius for one corner, use
border-start-end-radiusand similar rules.UnoCSSshortcuts arerounded+ top/bottom as either-bs(top) or-be(bottom) + left/right as either-is(left) or-ie(right). Example:rounded-tl-0should be replaced withrounded-bs-is-0.
npmx.dev uses @nuxtjs/i18n for internationalization. We aim to make the UI accessible to users in their preferred language.
- All user-facing strings should use translation keys via
$t()in templates and script - Translation files live in
i18n/locales/(e.g.,en-US.json) - We use the
no_prefixstrategy (no/en-US/or/fr-FR/in URLs) - Locale preference is stored in cookies and respected on subsequent visits
We are using localization using country variants (ISO-6391) via multiple translation files to avoid repeating every key per country.
The config/i18n.ts configuration file will be used to register the new locale:
countryLocaleVariantsobject will be used to register the country variantslocalesobject will be used to link the supported locales (country and single one)buildLocalesfunction will build the target locales
To register a new locale:
- for a single country, your JSON file should include the language and the country in the name (for example,
pl-PL.json) and register the info atlocalesobject - for multiple country variants, you need to add the default language JSON file (for example for Spanish,
es.json) and one of the country variants (for example for Spanish for Spain,es-ES.json); register the language atcountryLocaleVariantsobject adding the country variants with the JSON country file and register the language atlocalesobject using the language JSON file (check how we registeres,es-ESandes-419in config/i18n.ts)
The country file should contain will contain only the translations that differ from the language JSON file, Vue I18n will merge the messages for us.
To add a new locale:
- Add a new file at locales folder with the language code as the filename.
- Copy en and translate the strings
- Add the language to the
localesarray in config/i18n.ts, belowenandar:- If your language has multiple country variants, add the generic one for language only (only if there are a lot of common entries, you can always add it as a new one)
- Add all country variants in country variants object
- Add all country variants files with empty
messagesobject:{} - Translate the strings in the generic language file
- Later, when anyone wants to add the corresponding translations for the country variant, just override any entry in the corresponding file: you can see an example with
esvariants.
- If the generic language already exists:
- If the translation doesn't differ from the generic language, then add the corresponding translations in the corresponding file
- If the translation differs from the generic language, then add the corresponding translations in the corresponding file and remove it from the country variants entry
- If your language has multiple country variants, add the generic one for language only (only if there are a lot of common entries, you can always add it as a new one)
- If the language is
right-to-left, adddiroption withrtlvalue, for example, for ar - If the language requires special pluralization rules, add
pluralRulecallback option, for example, for ar
Check Pluralization rule callback for more info.
-
Add your translation key to
i18n/locales/en.jsonfirst (American English is the source of truth) -
Use the key in your component:
<template> <p>{{ $t('my.translation.key') }}</p> </template>
Or in script:
<script setup lang="ts"> const message = computed(() => $t('my.translation.key')) </script>
-
For dynamic values, use interpolation:
{ "greeting": "Hello, {name}!" }<p>{{ $t('greeting', { name: userName }) }}</p>
- Use dot notation for hierarchy:
section.subsection.key - Keep keys descriptive but concise
- Group related keys together
- Use
common.*for shared strings (loading, retry, close, etc.) - Use component-specific prefixes:
package.card.*,settings.*,nav.*
We recommend the i18n-ally VSCode extension for a better development experience:
- Inline translation previews in your code
- Auto-completion for translation keys
- Missing translation detection
- Easy navigation to translation files
The extension is included in our workspace recommendations, so VSCode should prompt you to install it.
When formatting numbers or dates that should respect the user's locale, pass the locale:
const { locale } = useI18n()
const formatted = formatNumber(12345, locale.value) // "12,345" in en-USWrite unit tests for core functionality using Vitest:
import { describe, it, expect } from 'vitest'
describe('featureName', () => {
it('should handle expected case', () => {
expect(result).toBe(expected)
})
})Tip
If you need access to the Nuxt context in your unit or component test, place your test in the test/nuxt/ directory and run with pnpm test:nuxt
All new components should have a basic accessibility test in test/nuxt/components.spec.ts. These tests use axe-core to catch common accessibility violations.
import MyComponent from '~/components/MyComponent.vue'
describe('MyComponent', () => {
it('should have no accessibility violations', async () => {
const component = await mountSuspended(MyComponent, {
props: {
/* required props */
},
})
const results = await runAxe(component)
expect(results.violations).toEqual([])
})
})The runAxe helper handles DOM isolation and disables page-level rules that don't apply to isolated component testing.
Important
Just because axe-core doesn't find any obvious issues, it does not mean a component is accessible. Please do additional checks and use best practices.
Write end-to-end tests using Playwright:
pnpm test:browser # Run tests
pnpm test:browser:ui # Run with Playwright UIMake sure to read about Playwright best practices and don't rely on classes/IDs but try to follow user-replicable behaviour (like selecting an element based on text content instead).
- ensure your code follows the style guidelines
- run linting:
pnpm lint:fix - run type checking:
pnpm test:types - run tests:
pnpm test - write or update tests for your changes
- create a feature branch from
main - make your changes with clear, descriptive commits
- push your branch and open a pull request
- ensure CI checks pass (lint, type check, tests)
- request review from maintainers
Write clear, concise PR titles that explain the "why" behind changes.
We use Conventional Commits. Since we squash on merge, the PR title becomes the commit message in main, so it's important to get it right.
Format: type(scope): description
Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
Scopes (optional): docs, i18n, deps
Examples:
fix: resolve search pagination issuefeat: add package version comparisonfix(i18n): update French translationschore(deps): update vite to v6
Note
The subject must start with a lowercase letter. Individual commit messages within your PR don't need to follow this format since they'll be squashed.
The project uses lint-staged with simple-git-hooks to automatically lint files on commit.
You're welcome to use AI tools to help you contribute. But there are two important ground rules:
When you write a comment, issue, or PR description, use your own words. Grammar and spelling don't matter – real connection does. AI-generated summaries tend to be long-winded, dense, and often inaccurate. Simplicity is an art. The goal is not to sound impressive, but to communicate clearly.
Feel free to use AI to write code, tests, or point you in the right direction. But always understand what it's written before contributing it. Take personal responsibility for your contributions. Don't say "ChatGPT says..." – tell us what you think.
For more context, see Using AI in open source.
If you have questions or need help, feel free to open an issue for discussion or join our Discord server.
By contributing to npmx.dev, you agree that your contributions will be licensed under the MIT License.