Skip to content

Commit fd918e3

Browse files
authored
fix(init,module,upgrade): validate response from consola.prompt (#687)
1 parent 269dc9a commit fd918e3

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/nuxi/src/commands/init.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ export default defineCommand({
152152
options: packageManagerOptions,
153153
})
154154

155+
if (!packageManagerOptions.includes(selectedPackageManager)) {
156+
logger.error('Invalid package manager selected.')
157+
process.exit(1)
158+
}
159+
155160
// Install project dependencies
156161
// or skip installation based on the '--no-install' flag
157162
if (ctx.args.install === false) {
@@ -183,7 +188,7 @@ export default defineCommand({
183188
if (ctx.args.gitInit === undefined) {
184189
ctx.args.gitInit = await logger.prompt('Initialize git repository?', {
185190
type: 'confirm',
186-
})
191+
}) === true
187192
}
188193
if (ctx.args.gitInit) {
189194
logger.info('Initializing git repository...\n')

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async function addModules(modules: ResolvedModule[], { skipInstall, skipConfig,
145145
},
146146
)
147147

148-
if (res === false) {
148+
if (res !== true) {
149149
return
150150
}
151151
}
@@ -268,6 +268,9 @@ async function resolveModule(moduleName: string, cwd: string): Promise<ModuleRes
268268
type: 'select',
269269
options: [_moduleVersion, pkgVersion],
270270
})
271+
if (typeof pkgVersion !== 'string') {
272+
return false
273+
}
271274
}
272275
break
273276
}

packages/nuxi/src/commands/upgrade.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ async function getNightlyVersion(packageNames: string[]): Promise<{ npmPackages:
4949
'Which nightly Nuxt release channel do you want to install? (3.x or 4.x)',
5050
{
5151
type: 'select',
52-
options: ['3.x', '4.x'],
52+
options: ['3.x', '4.x'] as const,
5353
default: '3.x',
5454
},
55-
) as '3.x' | '4.x'
55+
)
5656

5757
const nuxtVersion = typeof result === 'string' ? result : '3.x'
5858

@@ -138,7 +138,7 @@ export default defineCommand({
138138
type: 'confirm',
139139
default: true,
140140
},
141-
)
141+
) === true
142142
}
143143
if (ctx.args.force) {
144144
logger.info(

0 commit comments

Comments
 (0)