File tree Expand file tree Collapse file tree 3 files changed +5
-17
lines changed
Expand file tree Collapse file tree 3 files changed +5
-17
lines changed Original file line number Diff line number Diff line change 11import validatePackageName from 'validate-npm-package-name'
2+ import { encodePackageName } from '#shared/utils/npm'
23
34/**
45 * Normalize a package name for comparison by removing common variations.
@@ -77,11 +78,7 @@ export async function checkPackageExists(
7778 options : Parameters < typeof $fetch > [ 1 ] = { } ,
7879) : Promise < boolean > {
7980 try {
80- const encodedName = name . startsWith ( '@' )
81- ? `@${ encodeURIComponent ( name . slice ( 1 ) ) } `
82- : encodeURIComponent ( name )
83-
84- await $fetch ( `${ NPM_REGISTRY } /${ encodedName } ` , {
81+ await $fetch ( `${ NPM_REGISTRY } /${ encodePackageName ( name ) } ` , {
8582 ...options ,
8683 method : 'HEAD' ,
8784 } )
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
1818 ERROR_PACKAGE_ANALYSIS_FAILED ,
1919} from '#shared/utils/constants'
2020import { parseRepoUrl } from '#shared/utils/git-providers'
21+ import { encodePackageName } from '#shared/utils/npm'
2122import { getLatestVersion , getLatestVersionBatch } from 'fast-npm-meta'
2223
2324export default defineCachedEventHandler (
@@ -76,13 +77,6 @@ export default defineCachedEventHandler(
7677 } ,
7778)
7879
79- function encodePackageName ( name : string ) : string {
80- if ( name . startsWith ( '@' ) ) {
81- return `@${ encodeURIComponent ( name . slice ( 1 ) ) } `
82- }
83- return encodeURIComponent ( name )
84- }
85-
8680/**
8781 * Fetch @types package info including deprecation status using fast-npm-meta.
8882 * Returns undefined if the package doesn't exist.
Original file line number Diff line number Diff line change 11import type { Packument , PackumentVersion , DependencyDepth } from '#shared/types'
22import { mapWithConcurrency } from '#shared/utils/async'
3+ import { encodePackageName } from '#shared/utils/npm'
34import { maxSatisfying } from 'semver'
45
56/** Concurrency limit for fetching packuments during dependency resolution */
@@ -21,11 +22,7 @@ export const TARGET_PLATFORM = {
2122export const fetchPackument = defineCachedFunction (
2223 async ( name : string ) : Promise < Packument | null > => {
2324 try {
24- const encodedName = name . startsWith ( '@' )
25- ? `@${ encodeURIComponent ( name . slice ( 1 ) ) } `
26- : encodeURIComponent ( name )
27-
28- return await $fetch < Packument > ( `https://registry.npmjs.org/${ encodedName } ` )
25+ return await $fetch < Packument > ( `https://registry.npmjs.org/${ encodePackageName ( name ) } ` )
2926 } catch ( error ) {
3027 if ( import . meta. dev ) {
3128 // oxlint-disable-next-line no-console -- log npm registry failures for debugging
You can’t perform that action at this time.
0 commit comments