Skip to content

Commit

Permalink
fix: use ofetch for fast-npm-meta
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 2, 2024
1 parent 418a22e commit 4188f8d
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions packages/devtools/src/npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,14 @@ import { createRequire } from 'node:module'
import { logger, useNuxt } from '@nuxt/kit'
import { readPackageJSON } from 'pkg-types'
import semver from 'semver'
import { fetch } from 'ofetch'
import { getPackageInfo } from 'local-pkg'
import type { PackageUpdateInfo } from '../types'

export async function getMainPackageJSON(nuxt = useNuxt()) {
return readPackageJSON(nuxt.options.rootDir)
}

export interface Packument {
'name': string
/**
* An object where each key is a version, and each value is the manifest for
* that version.
*/
'versions': Record<string, Omit<Packument, 'versions'>>
/**
* An object mapping dist-tags to version numbers. This is how `foo@latest`
* gets turned into `foo@1.2.3`.
*/
'dist-tags': { latest: string } & Record<string, string>
/**
* In the full packument, an object mapping version numbers to publication
* times, for the `opts.before` functionality.
*/
'time': Record<string, string> & {
created: string
modified: string
}
}

export async function checkForUpdateOf(name: string, current?: string, nuxt = useNuxt()): Promise<PackageUpdateInfo | undefined> {
try {
if (!current) {
Expand All @@ -45,7 +24,9 @@ export async function checkForUpdateOf(name: string, current?: string, nuxt = us
return

const { getLatestVersion } = await import('fast-npm-meta')
const { version: latest } = await getLatestVersion(name)
const { version: latest } = await getLatestVersion(name, {
fetch,
})

const needsUpdate = !!latest && latest !== current && semver.lt(current, latest)

Expand Down

0 comments on commit 4188f8d

Please sign in to comment.