MCPcopy Create free account
hub / github.com/vercel/vercel / executeUpgrade

Function executeUpgrade

packages/cli/src/util/upgrade.ts:106–205  ·  view source on GitHub ↗
(targetVersion?: string)

Source from the content-addressed store, hash-verified

104 * reported without relying on whichever binary happens to be on `PATH`.
105 */
106export async function executeUpgrade(targetVersion?: string): Promise<number> {
107 const totalSteps = targetVersion ? 2 : 3;
108 renderUpgradeProgress(0, totalSteps, 'Resolving installer…');
109
110 const { command: updateCommand, global } = await getUpdateCommandInfo().catch(
111 error => {
112 output.stopSpinner();
113 throw error;
114 }
115 );
116 const [command, ...args] = updateCommand.split(' ');
117
118 const cwd = global ? tmpdir() : process.cwd();
119
120 // The version currently running, captured before the install overwrites it.
121 // This is what `vc --version` reports, for both Node.js and native binary.
122 const versionBefore = pkg.version;
123
124 let resolvedTargetVersion = targetVersion;
125 if (!resolvedTargetVersion) {
126 renderUpgradeProgress(1, totalSteps, 'Checking for updates…');
127 resolvedTargetVersion = await getLatestPackageVersion(command, args);
128 }
129
130 if (
131 resolvedTargetVersion &&
132 isVersionCurrent(versionBefore, resolvedTargetVersion)
133 ) {
134 renderUpgradeProgress(totalSteps, totalSteps);
135 output.stopSpinner();
136 output.log(
137 `No upgrade available. Vercel CLI is already up to date (v${versionBefore}).`
138 );
139 return 0;
140 }
141
142 output.debug(`Executing: ${updateCommand} (cwd: ${cwd})`);
143 renderUpgradeProgress(targetVersion ? 1 : 2, totalSteps, 'Installing…');
144
145 return new Promise<number>(resolve => {
146 const stdout: Uint8Array[] = [];
147 const stderr: Uint8Array[] = [];
148
149 const upgradeProcess = spawn(command, args, {
150 cwd,
151 stdio: ['inherit', 'pipe', 'pipe'],
152 shell: false,
153 });
154
155 upgradeProcess.stdout?.on('data', (data: Buffer) => {
156 stdout.push(Uint8Array.from(data));
157 });
158
159 upgradeProcess.stderr?.on('data', (data: Buffer) => {
160 stderr.push(Uint8Array.from(data));
161 });
162
163 upgradeProcess.on('error', (err: Error) => {

Callers 4

upgrade.test.tsFile · 0.90
promptAndUpgradeFunction · 0.90
index.tsFile · 0.90
upgradeFunction · 0.90

Calls 14

getUpdateCommandInfoFunction · 0.90
renderUpgradeProgressFunction · 0.85
getLatestPackageVersionFunction · 0.85
isVersionCurrentFunction · 0.85
spawnFunction · 0.85
splitMethod · 0.80
cwdMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80
printMethod · 0.80
pushMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected