diff --git a/packages/nuxi/src/commands/module/add.ts b/packages/nuxi/src/commands/module/add.ts index 8a5da6779..3dabe609a 100644 --- a/packages/nuxi/src/commands/module/add.ts +++ b/packages/nuxi/src/commands/module/add.ts @@ -3,6 +3,7 @@ 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' @@ -10,7 +11,7 @@ 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' @@ -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) diff --git a/packages/nuxi/src/commands/upgrade.ts b/packages/nuxi/src/commands/upgrade.ts index 73855b3cd..cc7915efb 100644 --- a/packages/nuxi/src/commands/upgrade.ts +++ b/packages/nuxi/src/commands/upgrade.ts @@ -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') { diff --git a/packages/nuxi/test/unit/commands/module/add.spec.ts b/packages/nuxi/test/unit/commands/module/add.spec.ts index 09a31ef34..0806672fa 100644 --- a/packages/nuxi/test/unit/commands/module/add.spec.ts +++ b/packages/nuxi/test/unit/commands/module/add.spec.ts @@ -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: { @@ -23,6 +24,7 @@ function applyMocks() { vi.mock('nypm', async () => { return { addDependency, + detectPackageManager, } }) vi.mock('pkg-types', async () => { @@ -122,6 +124,10 @@ describe('module add', () => { cwd: '/fake-dir', dev: true, installPeerDependencies: true, + packageManager: { + name: 'npm', + }, + workspace: false, }) }) @@ -138,6 +144,10 @@ describe('module add', () => { cwd: '/fake-dir', dev: true, installPeerDependencies: true, + packageManager: { + name: 'npm', + }, + workspace: false, }) }) @@ -154,6 +164,10 @@ describe('module add', () => { cwd: '/fake-dir', dev: true, installPeerDependencies: true, + packageManager: { + name: 'npm', + }, + workspace: false, }) }) @@ -170,6 +184,10 @@ describe('module add', () => { cwd: '/fake-dir', dev: true, installPeerDependencies: true, + packageManager: { + name: 'npm', + }, + workspace: false, }) }) })