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
7 changes: 6 additions & 1 deletion packages/nuxi/src/commands/module/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import type { PackageJson } from 'pkg-types'

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

import process from 'node:process'
import { updateConfig } from 'c12/update'
import { defineCommand } from 'citty'
import { colors } from 'consola/utils'
import { addDependency } from 'nypm'
import { addDependency, detectPackageManager } from 'nypm'
import { $fetch } from 'ofetch'
import { resolve } from 'pathe'
import { readPackageJSON } from 'pkg-types'
Expand Down Expand Up @@ -136,10 +137,14 @@ async function addModules(modules: ResolvedModule[], { skipInstall, skipConfig,
const a = notInstalledModules.length > 1 ? '' : ' a'
logger.info(`Installing \`${notInstalledModulesList}\` as${a}${isDev ? ' development' : ''} ${dependency}`)

const packageManager = await detectPackageManager(cwd)

const res = await addDependency(notInstalledModules.map(module => module.pkg), {
cwd,
dev: isDev,
installPeerDependencies: true,
packageManager,
workspace: packageManager?.name === 'pnpm' && existsSync(resolve(cwd, 'pnpm-workspace.yaml')),
}).then(() => true).catch(
(error) => {
logger.error(error)
Expand Down
1 change: 1 addition & 0 deletions packages/nuxi/src/commands/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export default defineCommand({
cwd,
packageManager,
dev: nuxtDependencyType === 'devDependencies',
workspace: packageManager?.name === 'pnpm' && existsSync(resolve(cwd, 'pnpm-workspace.yaml')),
})

if (method === 'force') {
Expand Down
18 changes: 18 additions & 0 deletions packages/nuxi/test/unit/commands/module/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as versions from '../../../../src/utils/versions'

const updateConfig = vi.fn(() => Promise.resolve())
const addDependency = vi.fn(() => Promise.resolve())
const detectPackageManager = vi.fn(() => Promise.resolve({ name: 'npm' }))
let v3 = '3.0.0'
interface CommandsType {
subCommands: {
Expand All @@ -23,6 +24,7 @@ function applyMocks() {
vi.mock('nypm', async () => {
return {
addDependency,
detectPackageManager,
}
})
vi.mock('pkg-types', async () => {
Expand Down Expand Up @@ -122,6 +124,10 @@ describe('module add', () => {
cwd: '/fake-dir',
dev: true,
installPeerDependencies: true,
packageManager: {
name: 'npm',
},
workspace: false,
})
})

Expand All @@ -138,6 +144,10 @@ describe('module add', () => {
cwd: '/fake-dir',
dev: true,
installPeerDependencies: true,
packageManager: {
name: 'npm',
},
workspace: false,
})
})

Expand All @@ -154,6 +164,10 @@ describe('module add', () => {
cwd: '/fake-dir',
dev: true,
installPeerDependencies: true,
packageManager: {
name: 'npm',
},
workspace: false,
})
})

Expand All @@ -170,6 +184,10 @@ describe('module add', () => {
cwd: '/fake-dir',
dev: true,
installPeerDependencies: true,
packageManager: {
name: 'npm',
},
workspace: false,
})
})
})
Loading