Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
`premajor`,
`preminor`,
`prepatch`,
`prerelease`,
DECLINE,
]);
// eslint-disable-next-line arca/no-default-export
export default class VersionCommand extends BaseCommand {
@Command.String()
strategy!: string;
@Command.Boolean(`-d,--deferred`)
deferred?: boolean;
@Command.Boolean(`-i,--immediate`)
immediate?: boolean;
@Command.Boolean(`-f,--force`)
force: boolean = false;
static schema = yup.object().shape({
strategy: yup.string().test({
name: `strategy`,
message: '${path} must be a semver range or one of ${strategies}',
params: {strategies: Array.from(STRATEGIES).join(`, `)},
test: (range: string) => {
return semver.valid(range) !== null || STRATEGIES.has(range);
},
}),
});
import {BaseCommand} from '@yarnpkg/cli';
import {Configuration, Project, StreamReport, MessageName, Report} from '@yarnpkg/core';
import {httpUtils} from '@yarnpkg/core';
import {xfs, PortablePath, ppath} from '@yarnpkg/fslib';
import {Command, UsageError} from 'clipanion';
import semver, {SemVer} from 'semver';
const BUNDLE_REGEXP = /^yarn-[0-9]+\.[0-9]+\.[0-9]+\.js$/;
const BERRY_RANGES = new Set([`berry`, `nightly`, `nightlies`, `rc`]);
// eslint-disable-next-line arca/no-default-export
export default class SetVersionCommand extends BaseCommand {
@Command.String()
range!: string;
@Command.Boolean(`--allow-rc`)
includePrereleases: boolean = false;
@Command.Boolean(`--dry-run`)
dryRun: boolean = false;
static usage = Command.Usage({
description: `lock the Yarn version used by the project`,
details: `
This command will download a specific release of Yarn directly from the Yarn Github repository, will store it inside your project, and will change the \`yarnPath\` settings from your project \`.yarnrc.yml\` file to point to the new file.
A very good use case for this command is to enforce the version of Yarn used by the any single member of your team inside a same project - by doing this you ensure that you have control on Yarn upgrades and downgrades (including on your deployment servers), and get rid of most of the headaches related to someone using a slightly different version and getting a different behavior than you.
The command will by default only consider stable releases as valid candidates, but releases candidates can be downloaded as well provided you add the \`--allow-rc\` flag or use an exact tag.
Note that because you're on the v2 alpha trunk, running the command without parameter will always download the latest build straight from the repository. This behavior will be tweaked near the release to only download stable releases once more.
import {BaseCommand} from '@yarnpkg/cli';
import {Configuration, Cache, StreamReport} from '@yarnpkg/core';
import {PortablePath, xfs} from '@yarnpkg/fslib';
import {Command} from 'clipanion';
// eslint-disable-next-line arca/no-default-export
export default class CacheCleanCommand extends BaseCommand {
@Command.Boolean(`--mirror`)
mirror: boolean = false;
@Command.Boolean(`--all`)
all: boolean = false;
static usage = Command.Usage({
description: `remove the shared cache files`,
details: `
This command will remove all the files in the shared cache.
`,
examples: [[
`Remove all the shared archives`,
`$0 cache clean`,
]],
});
// eslint-disable-next-line arca/no-default-export
export default class SetVersionCommand extends BaseCommand {
@Command.String(`--path`)
installPath?: string;
@Command.String(`--repository`)
repository: string = `https://github.com/yarnpkg/berry.git`;
@Command.String(`--branch`)
branch: string = `master`;
@Command.Array(`--plugin`)
plugins: Array = [];
@Command.Boolean(`-f,--force`)
force: boolean = false;
static usage = Command.Usage({
description: `build Yarn from master`,
details: `
This command will clone the Yarn repository into a temporary folder, then build it. The resulting bundle will then be copied into the local project.
`,
examples: [[
`Build Yarn from master`,
`$0 set version from sources`,
]],
});
@Command.Path(`set`, `version`, `from`, `sources`)
async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli';
import {AllDependencies, Cache, Configuration, IdentHash, Manifest} from '@yarnpkg/core';
import {MessageName, Project, StreamReport, WorkspaceResolver} from '@yarnpkg/core';
import {Workspace, structUtils} from '@yarnpkg/core';
import {Command, UsageError} from 'clipanion';
import semver from 'semver';
// Basically we only support auto-upgrading the ranges that are very simple (^x.y.z, ~x.y.z, >=x.y.z, and of course x.y.z)
const SUPPORTED_UPGRADE_REGEXP = /^(>=|[~^]|)^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/;
// eslint-disable-next-line arca/no-default-export
export default class VersionApplyCommand extends BaseCommand {
@Command.Boolean(`--all`)
all: boolean = false;
@Command.Boolean(`--json`)
json: boolean = false;
@Command.Boolean(`--dependents`)
dependents: boolean = false;
static usage = Command.Usage({
category: `Release-related commands`,
description: `apply all the deferred version bumps at once`,
details: `
This command will apply the deferred version changes (scheduled via \`yarn version major|minor|patch\`) on the current workspace (or all of them if \`--all\`) is specified.
It will also update the \`workspace:\` references across all your local workspaces so that they keep refering to the same workspace even after the version bump.
If the \`--json\` flag is set the output will follow a JSON-stream output also known as NDJSON (https://github.com/ndjson/ndjson-spec).
`,
examples: [[
import {BaseCommand, WorkspaceRequiredError} from '@berry/cli';
import {Configuration, Cache, Descriptor, Project} from '@berry/core';
import {StreamReport, Workspace} from '@berry/core';
import {structUtils} from '@berry/core';
import {Command, UsageError} from 'clipanion';
import * as suggestUtils from '../suggestUtils';
import {Hooks} from '..';
// eslint-disable-next-line arca/no-default-export
export default class RemoveCommand extends BaseCommand {
@Command.Boolean(`-A,--all`)
all: boolean = false;
@Command.Rest()
names: Array = [];
static usage = Command.Usage({
description: `remove dependencies from the project`,
details: `
This command will remove the specified packages from the current workspace.
If the \`-A,--all\` option is set, the operation will be applied to all workspaces from the current project.
`,
examples: [[
`Remove a dependency from the current project`,
`yarn remove lodash`,
], [
import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli';
import {Configuration, LocatorHash, Package} from '@yarnpkg/core';
import {IdentHash, Project} from '@yarnpkg/core';
import {miscUtils, structUtils} from '@yarnpkg/core';
import {Command} from 'clipanion';
import {Writable} from 'stream';
import {asTree} from 'treeify';
type TreeNode = {[key: string]: TreeNode};
// eslint-disable-next-line arca/no-default-export
export default class WhyCommand extends BaseCommand {
@Command.String()
package!: string;
@Command.Boolean(`-R,--recursive`)
recursive: boolean = false;
@Command.Boolean(`--peers`)
peers: boolean = false;
static usage = Command.Usage({
description: `display the reason why a package is needed`,
details: `
This command prints the exact reasons why a package appears in the dependency tree.
If \`-R,--recursive\` is set, the listing will go in depth and will list, for each workspaces, what are all the paths that lead to the dependency. Note that the display is somewhat optimized in that it will not print the package listing twice for a single package, so if you see a leaf named "Foo" when looking for "Bar", it means that "Foo" already got printed higher in the tree.
If \`--peers\` is set, the command will also print the peer dependencies that match the specified name.
`,
examples: [[
`Explain why lodash is used in your project`,
import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli';
import {Configuration, Cache, MessageName, Project, ReportError, StreamReport} from '@yarnpkg/core';
import {xfs, ppath} from '@yarnpkg/fslib';
import {parseSyml, stringifySyml} from '@yarnpkg/parsers';
import {Command} from 'clipanion';
// eslint-disable-next-line arca/no-default-export
export default class YarnCommand extends BaseCommand {
@Command.Boolean(`--json`)
json: boolean = false;
@Command.Boolean(`--immutable`)
immutable?: boolean;
@Command.Boolean(`--immutable-cache`)
immutableCache?: boolean;
@Command.Boolean(`--check-cache`)
checkCache: boolean = false;
@Command.Boolean(`--frozen-lockfile`, {hidden: true})
frozenLockfile?: boolean;
@Command.Boolean(`--prefer-offline`, {hidden: true})
preferOffline?: boolean;
@Command.Boolean(`--ignore-engines`, {hidden: true})
ignoreEngines?: boolean;
@Command.Boolean(`--inline-builds`)
inlineBuilds?: boolean;
import {Configuration, Project} from '@yarnpkg/core';
import {NodeFS, xfs, PortablePath, ppath} from '@yarnpkg/fslib';
import {Command, UsageError} from 'clipanion';
import {Driver as GitDriver} from '../drivers/GitDriver';
import {Driver as MercurialDriver} from '../drivers/MercurialDriver';
import {Hooks} from '..';
const ALL_DRIVERS = [
GitDriver,
MercurialDriver,
];
// eslint-disable-next-line arca/no-default-export
export default class StageCommand extends BaseCommand {
@Command.Boolean(`-c,--commit`)
commit: boolean = false;
@Command.Boolean(`-r,--reset`)
reset: boolean = false;
@Command.Boolean(`-u,--update`)
update: boolean = false;
@Command.Boolean(`-n,--dry-run`)
dryRun: boolean = false;
static usage = Command.Usage({
description: `add all yarn files to your vcs`,
details: `
This command will add to your staging area the files belonging to Yarn (typically any modified \`package.json\` and \`.yarnrc.yml\` files, but also linker-generated files, cache data, etc). It will take your ignore list into account, so the cache files won't be added if the cache is ignored in a \`.gitignore\` file (assuming you use Git).
import {WorkspaceRequiredError} from '@yarnpkg/cli';
import {CommandContext, Configuration, MessageName, Project, StreamReport, Workspace, execUtils, structUtils, Manifest, LocatorHash, ThrowReport} from '@yarnpkg/core';
import {Filename, PortablePath, npath, ppath, xfs} from '@yarnpkg/fslib';
import {Command, UsageError} from 'clipanion';
import {AppContext, Box, Color, StdinContext, render} from 'ink';
import React, {useCallback, useContext, useEffect, useState} from 'react';
import semver from 'semver';
type Decision = 'undecided' | 'decline' | 'major' | 'minor' | 'patch' | 'prerelease';
type Decisions = Map;
type Status = {decided: Array, undecided: Array, declined: Array};
// eslint-disable-next-line arca/no-default-export
export default class VersionApplyCommand extends Command {
@Command.Boolean(`-i,--interactive`)
interactive?: boolean;
static usage = Command.Usage({
category: `Release-related commands`,
description: `check that all the relevant packages have been bumped`,
details: `
**Warning:** This command currently requires Git.
This command will check that all the packages covered by the files listed in argument have been properly bumped or declined to bump.
In the case of a bump, the check will also cover transitive packages - meaning that should \`Foo\` be bumped, a package \`Bar\` depending on \`Foo\` will require a decision as to whether \`Bar\` will need to be bumped. This check doesn't cross packages that have declined to bump.
In case no arguments are passed to the function, the list of modified files will be generated by comparing the HEAD against \`master\`.
`,
examples: [[
`Check whether the modified packages need a bump`,