Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'clipanion' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
`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, WorkspaceRequiredError} from '@yarnpkg/cli';
import {Configuration, Project, StreamReport} from '@yarnpkg/core';
import {miscUtils} from '@yarnpkg/core';
import {Command} from 'clipanion';
import {inspect} from 'util';
// eslint-disable-next-line arca/no-default-export
export default class RunCommand extends BaseCommand {
@Command.Path(`run`)
async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {workspace} = await Project.find(configuration, this.context.cwd);
if (!workspace)
throw new WorkspaceRequiredError(this.context.cwd);
const report = await StreamReport.start({
configuration,
stdout: this.context.stdout,
}, async report => {
const scripts = workspace!.manifest.scripts;
const keys = miscUtils.sortMap(scripts.keys(), key => key);
const inspectConfig = {
breakLength: Infinity,
colors: configuration.get(`enableColors`),
// eslint-disable-next-line arca/no-default-export
export default class BuildBundleCommand extends Command {
@Command.String(`--profile`)
profile: string = `standard`;
@Command.Array(`--plugin`)
plugins: Array = [];
@Command.Boolean(`--no-minify`)
noMinify: boolean = false;
static usage = Command.Usage({
description: `build the local bundle`,
});
@Command.Path(`build`, `bundle`)
async execute() {
const basedir = process.cwd();
const plugins = findPlugins({basedir, profile: this.profile, plugins: this.plugins});
const modules = Array.from(dynamicLibs).concat(plugins);
const output = `${basedir}/bundles/yarn.js`;
const compiler = webpack(makeConfig({
context: basedir,
entry: `./sources/cli.ts`,
bail: true,
...!this.noMinify && {
mode: `production`,
},
import {Filename, npath, ppath, xfs} from '@yarnpkg/fslib';
import chalk from 'chalk';
import {Command, UsageError} from 'clipanion';
import path from 'path';
// eslint-disable-next-line arca/no-default-export
export default class NewPluginCommand extends Command {
@Command.String()
target!: string;
static usage = Command.Usage({
description: `generate the template for a new plugin`,
});
@Command.Path(`new`, `plugin`)
async execute() {
const target = npath.toPortablePath(path.resolve(this.target));
if (await xfs.existsPromise(target)) {
const listing = await xfs.readdirPromise(target);
if (listing.length !== 0) {
throw new UsageError(`The target directory (${this.target}) isn't empty; aborting the scaffolding.`);
}
}
await xfs.mkdirpPromise(target);
await xfs.mkdirpPromise(ppath.join(target, `sources` as Filename));
await xfs.writeFilePromise(ppath.join(target, `sources/index.ts` as Filename), [
`import {CommandContext, Plugin} from '@yarnpkg/core';\n`,
`import {Command} from 'clipanion';\n`,
`\n`,
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.
Adding the \`--dry-run\` flag will cause Yarn not to persist the changes on the disk.
`,
examples: [[
`Download the latest release from the Yarn repository`,
`$0 set version latest`,
], [
import {Filename, npath, ppath, xfs} from '@yarnpkg/fslib';
import chalk from 'chalk';
import {Command, UsageError} from 'clipanion';
import path from 'path';
// eslint-disable-next-line arca/no-default-export
export default class NewPluginCommand extends Command {
@Command.String()
target!: string;
static usage = Command.Usage({
description: `generate the template for a new plugin`,
});
@Command.Path(`new`, `plugin`)
async execute() {
const target = npath.toPortablePath(path.resolve(this.target));
if (await xfs.existsPromise(target)) {
const listing = await xfs.readdirPromise(target);
if (listing.length !== 0) {
throw new UsageError(`The target directory (${this.target}) isn't empty; aborting the scaffolding.`);
}
}
await xfs.mkdirpPromise(target);
await xfs.mkdirpPromise(ppath.join(target, `sources` as Filename));
import {CommandContext, Configuration, Project, Workspace} from "@yarnpkg/core";
import {structUtils} from "@yarnpkg/core";
import {Command, UsageError} from "clipanion";
// eslint-disable-next-line arca/no-default-export
export default class WorkspaceCommand extends Command {
@Command.String()
workspaceName!: string;
@Command.String()
commandName!: string;
@Command.Proxy()
args: Array = [];
static usage = Command.Usage({
category: `Workspace-related commands`,
description: `run a command within the specified workspace`,
details: `
> In order to use this command you need to add \`@yarnpkg/plugin-workspace-tools\` to your plugins.
This command will run a given sub-command on a single workspace.
`,
examples: [[
`Add a package to a single workspace`,
`yarn workspace components add -D react`,
], [
`Run build script on a single workspace`,
`yarn workspace components run build`,
]],
});
import {BaseCommand} from '@yarnpkg/cli';
import {Configuration, Project} from '@yarnpkg/core';
import {execUtils, scriptUtils} from '@yarnpkg/core';
import {Command} from 'clipanion';
// eslint-disable-next-line arca/no-default-export
export default class NodeCommand extends BaseCommand {
@Command.Proxy()
args: Array = [];
static usage = Command.Usage({
description: `run node with the hook already setup`,
details: `
This command simply runs Node. It also makes sure to call it in a way that's compatible with the current project (for example, on PnP projects the environment will be setup in such a way that PnP will be correctly injected into the environment).
The Node process will use the exact same version of Node as the one used to run Yarn itself, which might be a good way to ensure that your commands always use a consistent Node version.
`,
examples: [[
`Run a Node script`,
`$0 node ./my-script.js`,
]],
});
@Command.Path(`node`)
async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project} = await Project.find(configuration, this.context.cwd);
// 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: [[
`Apply the version change to the local workspace`,
`yarn version apply`,
], [
`Apply the version change to all the workspaces in the local workspace`,
`yarn version apply --all`,
]],
import {WorkspaceRequiredError} from '@yarnpkg/cli';
import {CommandContext, Configuration, MessageName, Project, StreamReport, Workspace, execUtils, structUtils, Manifest} from '@yarnpkg/core';
import {Filename, PortablePath, fromPortablePath, ppath, toPortablePath, xfs} from '@yarnpkg/fslib';
import {Command, UsageError} from 'clipanion';
// eslint-disable-next-line arca/no-default-export
export default class VersionApplyCommand extends Command {
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`,
`yarn version check`,
]],
});