Skip to content

Commit 6d1fedf

Browse files
fix(module,upgrade): allow adding module/nuxt version to pnpm workspace root (#1109)
1 parent 682b8ac commit 6d1fedf

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

packages/nuxi/src/commands/module/add.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import type { PackageJson } from 'pkg-types'
33

44
import type { NuxtModule } from './_utils'
55
import * as fs from 'node:fs'
6+
import { existsSync } from 'node:fs'
67
import { homedir } from 'node:os'
78
import { join } from 'node:path'
89

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

140+
const packageManager = await detectPackageManager(cwd)
141+
139142
const res = await addDependency(notInstalledModules.map(module => module.pkg), {
140143
cwd,
141144
dev: isDev,
142145
installPeerDependencies: true,
146+
packageManager,
147+
workspace: packageManager?.name === 'pnpm' && existsSync(resolve(cwd, 'pnpm-workspace.yaml')),
143148
}).then(() => true).catch(
144149
(error) => {
145150
logger.error(error)

packages/nuxi/src/commands/upgrade.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export default defineCommand({
172172
cwd,
173173
packageManager,
174174
dev: nuxtDependencyType === 'devDependencies',
175+
workspace: packageManager?.name === 'pnpm' && existsSync(resolve(cwd, 'pnpm-workspace.yaml')),
175176
})
176177

177178
if (method === 'force') {

packages/nuxi/test/unit/commands/module/add.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as versions from '../../../../src/utils/versions'
77

88
const updateConfig = vi.fn(() => Promise.resolve())
99
const addDependency = vi.fn(() => Promise.resolve())
10+
const detectPackageManager = vi.fn(() => Promise.resolve({ name: 'npm' }))
1011
let v3 = '3.0.0'
1112
interface CommandsType {
1213
subCommands: {
@@ -23,6 +24,7 @@ function applyMocks() {
2324
vi.mock('nypm', async () => {
2425
return {
2526
addDependency,
27+
detectPackageManager,
2628
}
2729
})
2830
vi.mock('pkg-types', async () => {
@@ -122,6 +124,10 @@ describe('module add', () => {
122124
cwd: '/fake-dir',
123125
dev: true,
124126
installPeerDependencies: true,
127+
packageManager: {
128+
name: 'npm',
129+
},
130+
workspace: false,
125131
})
126132
})
127133

@@ -138,6 +144,10 @@ describe('module add', () => {
138144
cwd: '/fake-dir',
139145
dev: true,
140146
installPeerDependencies: true,
147+
packageManager: {
148+
name: 'npm',
149+
},
150+
workspace: false,
141151
})
142152
})
143153

@@ -154,6 +164,10 @@ describe('module add', () => {
154164
cwd: '/fake-dir',
155165
dev: true,
156166
installPeerDependencies: true,
167+
packageManager: {
168+
name: 'npm',
169+
},
170+
workspace: false,
157171
})
158172
})
159173

@@ -170,6 +184,10 @@ describe('module add', () => {
170184
cwd: '/fake-dir',
171185
dev: true,
172186
installPeerDependencies: true,
187+
packageManager: {
188+
name: 'npm',
189+
},
190+
workspace: false,
173191
})
174192
})
175193
})

0 commit comments

Comments
 (0)