Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add self update #6736

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cli/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
export default ({
'upgrade-interactive': 'upgradeInteractive',
'generate-lock-entry': 'generateLockEntry',
'self-update': 'selfUpdate',
}: {[key: string]: string});
2 changes: 2 additions & 0 deletions src/cli/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import * as policies from './policies.js';
import * as publish from './publish.js';
import * as remove from './remove.js';
import * as run from './run.js';
import * as selfUpdate from './self-update.js';
import * as tag from './tag.js';
import * as team from './team.js';
import * as unplug from './unplug.js';
Expand Down Expand Up @@ -84,6 +85,7 @@ const commands = {
publish,
remove,
run,
selfUpdate,
tag,
team,
unplug,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type Flags = {
* Try and detect the installation method for Yarn and provide a command to update it with.
*/

function getUpdateCommand(installationMethod: InstallationMethod): ?string {
export function getUpdateCommand(installationMethod: InstallationMethod): ?string {
if (installationMethod === 'tar') {
return `curl --compressed -o- -L ${constants.YARN_INSTALLER_SH} | bash`;
}
Expand Down
63 changes: 63 additions & 0 deletions src/cli/commands/self-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* @flow */

import semver from 'semver';
import type Config from '../../config.js';
import {SELF_UPDATE_VERSION_URL} from '../../constants.js';
import type {Reporter} from '../../reporters/index.js';
import {getInstallationMethod} from '../../util/yarn-version.js';
import {getUpdateCommand} from './install';
import {execCommand} from '../../util/execute-lifecycle-script.js';

export const noArguments = true;
export const requireLockfile = false;

export function setFlags(commander: Object) {
commander.description('Updates yarn according to the instalation method');
}

export function hasWrapper(commander: Object, args: Array<string>): boolean {
return true;
}

export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
const currentVersion = flags.version();
const latestVersion = await config.requestManager.request({
url: SELF_UPDATE_VERSION_URL,
headers: {
Accept: 'text/plain',
},
});

// Check if we already use the latest or a newer version
if (semver.compare(currentVersion, latestVersion) >= 0) {
reporter.info('already on latest version or higher');
return;
}

const installationMethod = await getInstallationMethod();

reporter.info(installationMethod);

if (installationMethod === 'unknown') {
reporter.info('installation method could not be identified');
return;
}

const command = getUpdateCommand(installationMethod);
if (command) {
reporter.info(`installation method: , ${installationMethod}`);

reporter.info('running');

await execCommand({
// Could not figure out to which stage should this belong to.
stage: 'self-update',
config,
cmd: command,
cwd: config.cwd,
isInteractive: true,
});
} else {
reporter.info('could not find command for instalation method');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

installation

}
}