fix(upgrade): take ownership of dependency installation · nuxt/cli@a04ec72 · GitHub
Skip to content

Commit a04ec72

Browse files
committed
fix(upgrade): take ownership of dependency installation
1 parent 846ebd5 commit a04ec72

4 files changed

Lines changed: 185 additions & 59 deletions

File tree

‎packages/nuxt-cli/src/commands/upgrade.ts‎

Lines changed: 99 additions & 55 deletions

‎packages/nuxt-cli/src/utils/install.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { delimiter, resolve } from 'node:path'
88
import process from 'node:process'
99

1010
import { log, S_BAR } from '@clack/prompts'
11-
import { addDependency, installDependencies, packageManagers } from 'nypm'
11+
import { addDependency, dedupeDependencies, installDependencies, packageManagers } from 'nypm'
1212
import colors from 'picocolors'
1313
import { provider } from 'std-env'
1414
import { normalizeSpawnCommand, x } from 'tinyexec'
@@ -107,6 +107,33 @@ export async function runInstall(options: InstallOptions): Promise<InstallResult
107107
return await execute(command, commandArgs, options)
108108
}
109109

110+
export interface DedupeOptions extends Omit<InstallOptions, 'dependencies' | 'dev' | 'workspace'> {
111+
/** Delete the lockfile and resolve dependencies from scratch. */
112+
recreateLockfile?: boolean
113+
}
114+
115+
/**
116+
* Dedupe a project's dependencies, or recreate its lockfile, with the same quiet
117+
* output handling as {@link runInstall}.
118+
*/
119+
export async function runDedupe(options: DedupeOptions): Promise<InstallResult> {
120+
const { exec } = await dedupeDependencies({
121+
cwd: options.cwd,
122+
packageManager: options.packageManager,
123+
recreateLockfile: options.recreateLockfile,
124+
dry: true,
125+
})
126+
127+
if (!exec) {
128+
return { success: true, output: '', command: '', ignoredBuilds: [] }
129+
}
130+
131+
const args = [...exec.args, ...nonInteractiveArgs(options.packageManager)]
132+
const [command, commandArgs] = await withCorepack(exec.command, args)
133+
134+
return await execute(command, commandArgs, options)
135+
}
136+
110137
/**
111138
* Flags that stop a package manager from asking a question we cannot answer, or
112139
* from failing on something the user can act on after the fact.

‎packages/nuxt-cli/src/utils/nuxt.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ interface NuxtProjectManifest {
2020
}
2121
}
2222

23-
export async function cleanupNuxtDirs(rootDir: string, buildDir: string) {
24-
logger.info('Cleaning up generated Nuxt files and caches...')
23+
/** `silent` is for callers that already report progress themselves. */
24+
export async function cleanupNuxtDirs(rootDir: string, buildDir: string, options: { silent?: boolean } = {}) {
25+
if (!options.silent) {
26+
logger.info('Cleaning up generated Nuxt files and caches...')
27+
}
2528

2629
await rmRecursive(
2730
[

‎packages/nuxt-cli/test/unit/utils/install.spec.ts‎

Lines changed: 53 additions & 1 deletion

0 commit comments

Comments
 (0)