Skip to content
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
2 changes: 1 addition & 1 deletion src/commands/build-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default defineCommand({
// Find local installed version
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir)

const hasLocal = await readPackageJSON(MODULE_BUILDER_PKG, { url: cwd })
const hasLocal = await readPackageJSON(MODULE_BUILDER_PKG, { url: cwd }).catch(() => false)

const execArgs = Object.entries({
'--stub': ctx.args.stub,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NuxtConfig, NuxtModule } from '@nuxt/schema'
import type { PackageJson } from 'pkg-types'

import os from 'node:os'
import process from 'node:process'
Expand Down Expand Up @@ -35,7 +36,7 @@ export default defineCommand({
const nuxtConfig = await getNuxtConfig(cwd)

// Find nearest package.json
const { dependencies = {}, devDependencies = {} } = await readPackageJSON(cwd)
const { dependencies = {}, devDependencies = {} } = await readPackageJSON(cwd).catch(() => ({} as PackageJson))

// Utils to query a dependency version
const nuxtPath = await tryResolveNuxt(cwd)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/module/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function checkNuxtCompatibility(
}

export async function getNuxtVersion(cwd: string) {
const nuxtPkg = await readPackageJSON('nuxt', { url: cwd })
const nuxtPkg = await readPackageJSON('nuxt', { url: cwd }).catch(() => null)
if (nuxtPkg) {
return nuxtPkg.version!
}
Expand Down
7 changes: 4 additions & 3 deletions src/commands/module/add.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { FileHandle } from 'node:fs/promises'
import type { NuxtModule } from './_utils'
import type { PackageJson } from 'pkg-types'

import type { NuxtModule } from './_utils'
import * as fs from 'node:fs'
import { homedir } from 'node:os'
import { join } from 'node:path'
import process from 'node:process'

import process from 'node:process'
import { updateConfig } from 'c12/update'
import { defineCommand } from 'citty'
import { colors } from 'consola/utils'
Expand Down Expand Up @@ -63,7 +64,7 @@ export default defineCommand({
async setup(ctx) {
const cwd = resolve(ctx.args.cwd)
const modules = ctx.args._.map(e => e.trim()).filter(Boolean)
const projectPkg = await readPackageJSON(cwd)
const projectPkg = await readPackageJSON(cwd).catch(() => ({} as PackageJson))

if (!projectPkg.dependencies?.nuxt && !projectPkg.devDependencies?.nuxt) {
logger.warn(`No \`nuxt\` dependency detected in \`${cwd}\`.`)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function showVersions(cwd: string) {
if (!url) {
continue
}
const p = await readPackageJSON(pkg, { url })
const p = await readPackageJSON(pkg, { url }).catch(() => null)
if (p) {
return p.version!
}
Expand Down
Loading