-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
4 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 `[email protected]`. | ||
*/ | ||
'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) { | ||
|
@@ -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) | ||
|
||
|