Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: import package.json with json assertion #151

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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