Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"@electric-sql/pglite": "*",
"@libsql/client": "*",
"@valibot/to-json-schema": "^1.5.0",
"better-sqlite3": "^12.5.0",
"better-sqlite3": "^12.5.0 || ^13.0.0",
"sqlite3": "*",
"valibot": "^1.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/utils/dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { addDependency } from 'nypm'
import { resolvePackageJSON } from 'pkg-types'
import { hasTTY, isCI } from 'std-env'
import { logger } from './dev'
import nuxtContentContext from './context'
import { tryUseNuxt } from '@nuxt/kit'
Expand All @@ -22,11 +23,13 @@ export async function ensurePackageInstalled(pkg: string) {
if (!await isPackageInstalled(pkg)) {
logger.error(`Nuxt Content requires \`${pkg}\` module to operate.`)

const confirm = await logger.prompt(`Do you want to install \`${pkg}\` package?`, {
type: 'confirm',
name: 'confirm',
initial: true,
})
const confirm = hasTTY && !isCI
? await logger.prompt(`Do you want to install \`${pkg}\` package?`, {
type: 'confirm',
name: 'confirm',
initial: true,
})
: false

if (!confirm) {
logger.error(`Nuxt Content requires \`${pkg}\` module to operate. Please install \`${pkg}\` package manually and try again. \`npm install ${pkg}\``)
Expand Down
29 changes: 29 additions & 0 deletions test/unit/ensurePackageInstalled.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { afterEach, describe, expect, test, vi } from 'vitest'

const logger = { error: vi.fn(), prompt: vi.fn() }
const addDependency = vi.fn()

vi.mock('std-env', async importOriginal => ({
...(await importOriginal<typeof import('std-env')>()),
hasTTY: false,
isCI: true,
}))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
vi.mock('../../src/utils/dev', () => ({ logger }))
vi.mock('nypm', () => ({ addDependency }))

describe('ensurePackageInstalled', () => {
afterEach(() => {
vi.restoreAllMocks()
})

test('reports how to install the package instead of prompting when there is no TTY', async () => {
const exit = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never)
const { ensurePackageInstalled } = await import('../../src/utils/dependencies')

await ensurePackageInstalled('@nuxt/content-not-installed')

expect(logger.prompt).not.toHaveBeenCalled()
expect(logger.error).toHaveBeenLastCalledWith(expect.stringContaining('npm install @nuxt/content-not-installed'))
expect(exit).toHaveBeenCalledWith(1)
})
})
Loading