Skip to content

Commit

Permalink
Migrates to Clipanion 3 (#2370)
Browse files Browse the repository at this point in the history
* Migrates to Clipanion 3

* Removes yup entirely

* Uncomments debug

* Bumps clipanion

* Update packages/plugin-essentials/sources/commands/run.ts

Co-authored-by: Paul Soporan <[email protected]>

* Versions

* Updates the internal builtins

* Adds missing path

* Bumps clipanion

* Bumps typanion & clipanion

* Fixes incorrect paths

* Fixes tests

* Fixes regex

Co-authored-by: Paul Soporan <[email protected]>
  • Loading branch information
arcanis and paul-soporan authored Jan 14, 2021
1 parent 552a31c commit b433198
Show file tree
Hide file tree
Showing 107 changed files with 1,262 additions and 1,026 deletions.
157 changes: 79 additions & 78 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33 changes: 33 additions & 0 deletions .yarn/versions/20c497dd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
releases:
"@yarnpkg/builder": major
"@yarnpkg/cli": major
"@yarnpkg/core": major
"@yarnpkg/doctor": major
"@yarnpkg/plugin-constraints": major
"@yarnpkg/plugin-dlx": major
"@yarnpkg/plugin-essentials": major
"@yarnpkg/plugin-init": major
"@yarnpkg/plugin-interactive-tools": major
"@yarnpkg/plugin-node-modules": major
"@yarnpkg/plugin-npm-cli": major
"@yarnpkg/plugin-pack": major
"@yarnpkg/plugin-patch": major
"@yarnpkg/plugin-pnp": major
"@yarnpkg/plugin-stage": major
"@yarnpkg/plugin-version": major
"@yarnpkg/plugin-workspace-tools": major
"@yarnpkg/pnpify": major
"@yarnpkg/shell": major

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-typescript"
- vscode-zipfs
- "@yarnpkg/pnp"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@yarnpkg/eslint-config": "workspace:^0.2.0",
"@yarnpkg/pnpify": "workspace:^2.4.0",
"babel-jest": "^26.0.1",
"clipanion": "^2.6.2",
"clipanion": "^3.0.0-rc.5",
"eslint": "^6.8.0",
"eslint-plugin-arca": "^0.10.0",
"eslint-plugin-react": "^7.20.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ describe(`Commands`, () => {
)
);

test(
// Clipanion doesn't support this yet
test.skip(
`should throw an error when using --jobs without --parallel`,
makeTemporaryEnv(
{
Expand All @@ -337,7 +338,7 @@ describe(`Commands`, () => {
await setupWorkspaces(path);

await run(`install`);
await expect(run(`workspaces`, `foreach`, `--parallel`, `--jobs`, `1`, `run`, `print`)).rejects.toThrowError(/jobs must be greater/);
await expect(run(`workspaces`, `foreach`, `--parallel`, `--jobs`, `1`, `run`, `print`)).rejects.toThrowError(/expected to be at least 2 \(got 1\)/);
}
)
);
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-constraints/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"main": "./sources/index.ts",
"dependencies": {
"@yarnpkg/fslib": "workspace:^2.4.0",
"clipanion": "^2.6.2",
"clipanion": "^3.0.0-rc.5",
"lodash": "^4.17.15",
"node-emoji": "^1.8.1",
"tau-prolog": "^0.2.66",
Expand Down
12 changes: 8 additions & 4 deletions packages/plugin-constraints/sources/commands/constraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {BaseCommand} from '@y
import {Configuration, IdentHash, Ident, Project, Workspace, miscUtils} from '@yarnpkg/core';
import {MessageName, StreamReport, AllDependencies} from '@yarnpkg/core';
import {formatUtils, structUtils} from '@yarnpkg/core';
import {Command, Usage} from 'clipanion';
import {Command, Option, Usage} from 'clipanion';
import getPath from 'lodash/get';
import setPath from 'lodash/set';
import unsetPath from 'lodash/unset';
Expand All @@ -11,8 +11,9 @@ import {Constraints, EnforcedDependency, EnforcedField} from '..

// eslint-disable-next-line arca/no-default-export
export default class ConstraintsCheckCommand extends BaseCommand {
@Command.Boolean(`--fix`, {description: `Attempt to automatically fix unambiguous issues, following a multi-pass process`})
fix: boolean = false;
static paths = [
[`constraints`],
];

static usage: Usage = Command.Usage({
category: `Constraints-related commands`,
Expand All @@ -33,7 +34,10 @@ export default class ConstraintsCheckCommand extends BaseCommand {
]],
});

@Command.Path(`constraints`)
fix = Option.Boolean(`--fix`, false, {
description: `Attempt to automatically fix unambiguous issues, following a multi-pass process`,
});

async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project} = await Project.find(configuration, this.context.cwd);
Expand Down
17 changes: 10 additions & 7 deletions packages/plugin-constraints/sources/commands/constraints/query.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {BaseCommand} from '@yarnpkg/cli';
import {Configuration, Project} from '@yarnpkg/core';
import {StreamReport} from '@yarnpkg/core';
import {Command, Usage} from 'clipanion';
import {Command, Option, Usage} from 'clipanion';

import {Constraints} from '../../Constraints';

// eslint-disable-next-line arca/no-default-export
export default class ConstraintsQueryCommand extends BaseCommand {
@Command.Boolean(`--json`, {description: `Format the output as an NDJSON stream`})
json: boolean = false;

@Command.String()
query!: string;
static paths = [
[`constraints`, `query`],
];

static usage: Usage = Command.Usage({
category: `Constraints-related commands`,
Expand All @@ -25,7 +23,12 @@ export default class ConstraintsQueryCommand extends BaseCommand {
]],
});

@Command.Path(`constraints`, `query`)
json = Option.Boolean(`--json`, false, {
description: `Format the output as an NDJSON stream`,
});

query = Option.String();

async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project} = await Project.find(configuration, this.context.cwd);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {BaseCommand} from '@yarnpkg/cli';
import {Configuration, Project} from '@yarnpkg/core';
import {Command, Usage} from 'clipanion';
import {Command, Option, Usage} from 'clipanion';

import {Constraints} from '../../Constraints';

// eslint-disable-next-line arca/no-default-export
export default class ConstraintsSourceCommand extends BaseCommand {
@Command.Boolean(`-v,--verbose`, {description: `Also print the fact database automatically compiled from the workspace manifests`})
verbose: boolean = false;
static paths = [
[`constraints`, `source`],
];

static usage: Usage = Command.Usage({
category: `Constraints-related commands`,
Expand All @@ -24,7 +25,10 @@ export default class ConstraintsSourceCommand extends BaseCommand {
]],
});

@Command.Path(`constraints`, `source`)
verbose = Option.Boolean(`-v,--verbose`, false, {
description: `Also print the fact database automatically compiled from the workspace manifests`,
});

async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project} = await Project.find(configuration, this.context.cwd);
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dlx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"@yarnpkg/fslib": "workspace:^2.4.0",
"@yarnpkg/json-proxy": "workspace:^2.1.0",
"clipanion": "^2.6.2",
"clipanion": "^3.0.0-rc.5",
"tslib": "^1.13.0"
},
"peerDependencies": {
Expand Down
22 changes: 12 additions & 10 deletions packages/plugin-dlx/sources/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import {BaseCommand} from '@yarnpkg/cli';
import {structUtils} from '@yarnpkg/core';
import {Command} from 'clipanion';
import {Option} from 'clipanion';

// eslint-disable-next-line arca/no-default-export
export default class CreateCommand extends BaseCommand {
@Command.String(`-p,--package`, {description: `The package to run the provided command from`})
pkg: string | undefined;
static paths = [
[`create`],
];

@Command.Boolean(`-q,--quiet`, {description: `Only report critical errors instead of printing the full install logs`})
quiet: boolean = false;
pkg = Option.String(`-p,--package`, {
description: `The package to run the provided command from`,
});

@Command.String()
command!: string;
quiet = Option.Boolean(`-q,--quiet`, false, {
description: `Only report critical errors instead of printing the full install logs`,
});

@Command.Proxy()
args: Array<string> = [];
command = Option.String();
args = Option.Proxy();

@Command.Path(`create`)
async execute() {
const flags = [];
if (this.pkg)
Expand Down
28 changes: 15 additions & 13 deletions packages/plugin-dlx/sources/commands/dlx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@ import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli';
import {Configuration, Project} from '@yarnpkg/core';
import {scriptUtils, structUtils} from '@yarnpkg/core';
import {NativePath, Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {Command, Usage} from 'clipanion';
import {Command, Option, Usage} from 'clipanion';

// eslint-disable-next-line arca/no-default-export
export default class DlxCommand extends BaseCommand {
@Command.String(`-p,--package`, {description: `The package to run the provided command from`})
pkg: string | undefined;

@Command.Boolean(`-q,--quiet`, {description: `Only report critical errors instead of printing the full install logs`})
quiet: boolean = false;

@Command.String()
command!: string;

@Command.Proxy()
args: Array<string> = [];
static paths = [
[`dlx`],
];

static usage: Usage = Command.Usage({
description: `run a package in a temporary environment`,
Expand All @@ -33,7 +25,17 @@ export default class DlxCommand extends BaseCommand {
]],
});

@Command.Path(`dlx`)
pkg = Option.String(`-p,--package`, {
description: `The package to run the provided command from`,
});

quiet = Option.Boolean(`-q,--quiet`, false, {
description: `Only report critical errors instead of printing the full install logs`,
});

command = Option.String();
args = Option.Proxy();

async execute() {
// Disable telemetry to prevent each `dlx` call from counting as a project
Configuration.telemetry = null;
Expand Down
5 changes: 2 additions & 3 deletions packages/plugin-essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"@yarnpkg/json-proxy": "workspace:^2.1.0",
"@yarnpkg/parsers": "workspace:^2.3.0",
"ci-info": "^2.0.0",
"clipanion": "^2.6.2",
"clipanion": "^3.0.0-rc.5",
"enquirer": "^2.3.6",
"lodash": "^4.17.15",
"micromatch": "^4.0.2",
"semver": "^7.1.2",
"tslib": "^1.13.0",
"yup": "^0.27.0"
"typanion": "^3.2.1"
},
"peerDependencies": {
"@yarnpkg/cli": "^2.4.0",
Expand All @@ -26,7 +26,6 @@
"@types/micromatch": "^4.0.1",
"@types/semver": "^7.1.0",
"@types/treeify": "^1.0.0",
"@types/yup": "0.26.12",
"@yarnpkg/cli": "workspace:^2.4.0",
"@yarnpkg/core": "workspace:^2.4.0"
},
Expand Down
80 changes: 46 additions & 34 deletions packages/plugin-essentials/sources/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,17 @@ import {Cache, Configuration, Descriptor, LightReport, MessageName} from '@yarnp
import {Project, StreamReport, Workspace, Ident} from '@yarnpkg/core';
import {structUtils} from '@yarnpkg/core';
import {PortablePath} from '@yarnpkg/fslib';
import {Command, Usage, UsageError} from 'clipanion';
import {Command, Option, Usage, UsageError} from 'clipanion';
import {prompt} from 'enquirer';

import * as suggestUtils from '../suggestUtils';
import {Hooks} from '..';

// eslint-disable-next-line arca/no-default-export
export default class AddCommand extends BaseCommand {
@Command.Rest()
packages: Array<string> = [];

@Command.Boolean(`--json`, {description: `Format the output as an NDJSON stream`})
json: boolean = false;

@Command.Boolean(`-E,--exact`, {description: `Don't use any semver modifier on the resolved range`})
exact: boolean = false;

@Command.Boolean(`-T,--tilde`, {description: `Use the \`~\` semver modifier on the resolved range`})
tilde: boolean = false;

@Command.Boolean(`-C,--caret`, {description: `Use the \`^\` semver modifier on the resolved range`})
caret: boolean = false;

@Command.Boolean(`-D,--dev`, {description: `Add a package as a dev dependency`})
dev: boolean = false;

@Command.Boolean(`-P,--peer`, {description: `Add a package as a peer dependency`})
peer: boolean = false;

@Command.Boolean(`-O,--optional`, {description: `Add / upgrade a package to an optional regular / peer dependency`})
optional: boolean = false;

@Command.Boolean(`--prefer-dev`, {description: `Add / upgrade a package to a dev dependency`})
preferDev: boolean = false;

@Command.Boolean(`-i,--interactive`, {description: `Reuse the specified package from other workspaces in the project`})
interactive: boolean | null = null;

@Command.Boolean(`--cached`, {description: `Reuse the highest version already used somewhere within the project`})
cached: boolean = false;
static paths = [
[`add`],
];

static usage: Usage = Command.Usage({
description: `add dependencies to the project`,
Expand Down Expand Up @@ -88,7 +59,48 @@ export default class AddCommand extends BaseCommand {
]],
});

@Command.Path(`add`)
json = Option.Boolean(`--json`, false, {
description: `Format the output as an NDJSON stream`,
});

exact = Option.Boolean(`-E,--exact`, false, {
description: `Don't use any semver modifier on the resolved range`,
});

tilde = Option.Boolean(`-T,--tilde`, false, {
description: `Use the \`~\` semver modifier on the resolved range`,
});

caret = Option.Boolean(`-C,--caret`, false, {
description: `Use the \`^\` semver modifier on the resolved range`,
});

dev = Option.Boolean(`-D,--dev`, false, {
description: `Add a package as a dev dependency`,
});

peer = Option.Boolean(`-P,--peer`, false, {
description: `Add a package as a peer dependency`,
});

optional = Option.Boolean(`-O,--optional`, false, {
description: `Add / upgrade a package to an optional regular / peer dependency`,
});

preferDev = Option.Boolean(`--prefer-dev`, false, {
description: `Add / upgrade a package to a dev dependency`,
});

interactive = Option.Boolean(`-i,--interactive`, false, {
description: `Reuse the specified package from other workspaces in the project`,
});

cached = Option.Boolean(`--cached`, false, {
description: `Reuse the highest version already used somewhere within the project`,
});

packages = Option.Rest();

async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project, workspace} = await Project.find(configuration, this.context.cwd);
Expand Down
Loading

0 comments on commit b433198

Please sign in to comment.