Skip to content

Commit

Permalink
refactor: import package.json with json assertion (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Sep 7, 2023
1 parent 942b5c7 commit e293587
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { findup } from '../utils/fs'
import { defineCommand } from 'citty'

import { legacyRootDirArgs, sharedArgs } from './_shared'
import { version } from '../../package.json'
import nuxiPkg from '../../package.json'

export default defineCommand({
meta: {
Expand Down Expand Up @@ -80,7 +80,7 @@ export default defineCommand({
OperatingSystem: os.type(),
NodeVersion: process.version,
NuxtVersion: nuxtVersion,
CLIVersion: version,
CLIVersion: nuxiPkg.version,
NitroVersion: getDepVersion('nitropack'),
PackageManager: packageManager,
Builder: builder,
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { defineCommand } from 'citty'
import { commands } from './commands'
import { setupGlobalConsole } from './utils/console'
import { checkEngines } from './utils/engines'
import { name, version, description } from '../package.json'
import nuxiPkg from '../package.json' assert { type: 'json' }

// import { checkForUpdates } from './utils/update'

export const main = defineCommand({
meta: {
name,
version,
description,
name: nuxiPkg.name,
version: nuxiPkg.version,
description: nuxiPkg.description,
},
subCommands: commands,
async setup(ctx) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/banner.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import clear from 'clear'
import { bold, gray, green } from 'colorette'
import { version } from '../../package.json'
import nuxiPkg from '../../package.json'
import { tryRequireModule } from './cjs'

export function showBanner(_clear?: boolean) {
if (_clear) {
clear()
}
console.log(gray(`Nuxt CLI ${bold(version)}`))
console.log(gray(`Nuxt CLI ${bold(nuxiPkg.version)}`))
}

export function showVersions(cwd: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/engines.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { engines } from '../../package.json'
import nuxiPkg from '../../package.json'

export async function checkEngines() {
const satisfies = await import('semver/functions/satisfies.js').then(
(r) =>
r.default || (r as any as typeof import('semver/functions/satisfies.js')),
) // npm/node-semver#381
const currentNode = process.versions.node
const nodeRange = engines.node
const nodeRange = nuxiPkg.engines.node

if (!satisfies(currentNode, nodeRange)) {
console.warn(
Expand Down
10 changes: 5 additions & 5 deletions src/utils/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { name as pkgName, version as currentVersion } from '../../package.json'
import nuxiPkg from '../../package.json'
import { $fetch } from 'ofetch'
import { cyan, green, yellow, underline } from 'colorette'
import consola from 'consola'
Expand All @@ -9,12 +9,12 @@ export async function checkForUpdates() {
return
}
const { version: latestVersion = '' } = await $fetch(
`https://registry.npmjs.org/${pkgName}/latest`,
`https://registry.npmjs.org/${nuxiPkg.name}/latest`,
)
if (!latestVersion) {
return
}
if (semver.gt(latestVersion, currentVersion, { loose: true })) {
if (semver.gt(latestVersion, nuxiPkg.version, { loose: true })) {
const changelogURL = `https://github.com/nuxt/cli/releases/tag/v${latestVersion}`
consola.box({
title: 'Nuxt CLI Update is Available!',
Expand All @@ -23,11 +23,11 @@ export async function checkForUpdates() {
},
message: [
`A new version of Nuxt CLI is available: ${green(latestVersion)}`,
`You are currently using ${yellow(currentVersion)}`,
`You are currently using ${yellow(nuxiPkg.version)}`,
'',
`Release notes: ${underline(cyan(changelogURL))}`,
'',
`To update: \`npm install -g ${pkgName}\``,
`To update: \`npm install -g ${nuxiPkg.name}\``,
].join('\n'),
})
}
Expand Down

0 comments on commit e293587

Please sign in to comment.