@yarnpkg/plugin-essentials 3.2.0-rc.2 → 3.2.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ import { BaseCommand } from '@yarnpkg/cli';
2
+ import { Configuration } from '@yarnpkg/core';
3
+ export declare function getErrorCodeDetails(configuration: Configuration): Promise<Map<string, string>>;
4
+ export default class ExplainCommand extends BaseCommand {
5
+ static paths: string[][];
6
+ static usage: import("clipanion").Usage;
7
+ code: string | undefined;
8
+ json: boolean;
9
+ execute(): Promise<void>;
10
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorCodeDetails = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const cli_1 = require("@yarnpkg/cli");
6
+ const core_1 = require("@yarnpkg/core");
7
+ const clipanion_1 = require("clipanion");
8
+ const t = (0, tslib_1.__importStar)(require("typanion"));
9
+ const version_1 = require("./set/version");
10
+ function getCodeName(code) {
11
+ return core_1.MessageName[(0, core_1.parseMessageName)(code)];
12
+ }
13
+ const ERROR_CODE_DOC_REGEXP = /## (?<code>YN[0-9]{4}) - `(?<name>[A-Z_]+)`\n\n(?<details>(?:.(?!##))+)/gs;
14
+ async function getErrorCodeDetails(configuration) {
15
+ const version = core_1.miscUtils.isTaggedYarnVersion(core_1.YarnVersion)
16
+ ? core_1.YarnVersion
17
+ : await (0, version_1.resolveTag)(configuration, `canary`);
18
+ const errorCodesUrl = `https://repo.yarnpkg.com/${version}/packages/gatsby/content/advanced/error-codes.md`;
19
+ const raw = await core_1.httpUtils.get(errorCodesUrl, { configuration });
20
+ return new Map(Array.from(raw.toString().matchAll(ERROR_CODE_DOC_REGEXP), ({ groups }) => {
21
+ if (!groups)
22
+ throw new Error(`Assertion failed: Expected the match to have been successful`);
23
+ const expectedName = getCodeName(groups.code);
24
+ if (groups.name !== expectedName)
25
+ throw new Error(`Assertion failed: Invalid error code data: Expected "${groups.name}" to be named "${expectedName}"`);
26
+ return [groups.code, groups.details];
27
+ }));
28
+ }
29
+ exports.getErrorCodeDetails = getErrorCodeDetails;
30
+ // eslint-disable-next-line arca/no-default-export
31
+ class ExplainCommand extends cli_1.BaseCommand {
32
+ constructor() {
33
+ super(...arguments);
34
+ this.code = clipanion_1.Option.String({
35
+ required: false,
36
+ validator: t.applyCascade(t.isString(), [
37
+ t.matchesRegExp(/^YN[0-9]{4}$/),
38
+ ]),
39
+ });
40
+ this.json = clipanion_1.Option.Boolean(`--json`, false, {
41
+ description: `Format the output as an NDJSON stream`,
42
+ });
43
+ }
44
+ async execute() {
45
+ const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
46
+ if (typeof this.code !== `undefined`) {
47
+ const name = getCodeName(this.code);
48
+ const prettyName = core_1.formatUtils.pretty(configuration, name, core_1.formatUtils.Type.CODE);
49
+ const header = this.cli.format().header(`${this.code} - ${prettyName}`);
50
+ const errorCodeDetails = await getErrorCodeDetails(configuration);
51
+ const details = errorCodeDetails.get(this.code);
52
+ const content = typeof details !== `undefined`
53
+ ? core_1.formatUtils.jsonOrPretty(this.json, configuration, core_1.formatUtils.tuple(core_1.formatUtils.Type.MARKDOWN, {
54
+ text: details,
55
+ format: this.cli.format(),
56
+ paragraphs: true,
57
+ }))
58
+ : `This error code does not have a description.\n\nYou can help us by editing this page on GitHub 🙂:\n${core_1.formatUtils.jsonOrPretty(this.json, configuration, core_1.formatUtils.tuple(core_1.formatUtils.Type.URL, `https://github.com/yarnpkg/berry/blob/master/packages/gatsby/content/advanced/error-codes.md`))}\n`;
59
+ if (this.json) {
60
+ this.context.stdout.write(`${JSON.stringify({ code: this.code, name, details: content })}\n`);
61
+ }
62
+ else {
63
+ this.context.stdout.write(`${header}\n\n${content}\n`);
64
+ }
65
+ }
66
+ else {
67
+ const tree = {
68
+ children: core_1.miscUtils.mapAndFilter(Object.entries(core_1.MessageName), ([key, value]) => {
69
+ if (Number.isNaN(Number(key)))
70
+ return core_1.miscUtils.mapAndFilter.skip;
71
+ return {
72
+ label: (0, core_1.stringifyMessageName)(Number(key)),
73
+ value: core_1.formatUtils.tuple(core_1.formatUtils.Type.CODE, value),
74
+ };
75
+ }),
76
+ };
77
+ core_1.treeUtils.emitTree(tree, { configuration, stdout: this.context.stdout, json: this.json });
78
+ }
79
+ }
80
+ }
81
+ exports.default = ExplainCommand;
82
+ ExplainCommand.paths = [
83
+ [`explain`],
84
+ ];
85
+ ExplainCommand.usage = clipanion_1.Command.Usage({
86
+ description: `explain an error code`,
87
+ details: `
88
+ When the code argument is specified, this command prints its name and its details.
89
+
90
+ When used without arguments, this command lists all error codes and their names.
91
+ `,
92
+ examples: [[
93
+ `Explain an error code`,
94
+ `$0 explain YN0006`,
95
+ ], [
96
+ `List all error codes`,
97
+ `$0 explain`,
98
+ ]],
99
+ });
@@ -165,8 +165,10 @@ async function setVersion(configuration, bundleVersion, bundleBuffer, { report }
165
165
  yarnPath: projectPath,
166
166
  });
167
167
  const manifest = (await core_1.Manifest.tryFind(projectCwd)) || new core_1.Manifest();
168
- if (bundleVersion && core_2.miscUtils.isTaggedYarnVersion(bundleVersion))
169
- manifest.packageManager = `yarn@${bundleVersion}`;
168
+ manifest.packageManager = `yarn@${bundleVersion && core_2.miscUtils.isTaggedYarnVersion(bundleVersion)
169
+ ? bundleVersion
170
+ // If the version isn't tagged, we use the latest stable version as the wrapper
171
+ : await resolveTag(configuration, `stable`)}`;
170
172
  const data = {};
171
173
  manifest.exportTo(data);
172
174
  const path = fslib_1.ppath.join(projectCwd, core_1.Manifest.fileName);
package/lib/index.d.ts CHANGED
@@ -4,9 +4,36 @@ import * as dedupeUtils from './dedupeUtils';
4
4
  import * as suggestUtils from './suggestUtils';
5
5
  export { dedupeUtils, suggestUtils, };
6
6
  export interface Hooks {
7
+ /**
8
+ * Called when a new dependency is added to a workspace. Note that this hook
9
+ * is only called by the CLI commands like `yarn add` - manually adding the
10
+ * dependencies into the manifest and running `yarn install` won't trigger
11
+ * it.
12
+ */
7
13
  afterWorkspaceDependencyAddition?: (workspace: Workspace, target: suggestUtils.Target, descriptor: Descriptor, strategies: Array<suggestUtils.Strategy>) => Promise<void>;
14
+ /**
15
+ * Called when a dependency range is replaced inside a workspace. Note that
16
+ * this hook is only called by the CLI commands like `yarn add` - manually
17
+ * updating the dependencies from the manifest and running `yarn install`
18
+ * won't trigger it.
19
+ */
8
20
  afterWorkspaceDependencyReplacement?: (workspace: Workspace, target: suggestUtils.Target, fromDescriptor: Descriptor, toDescriptor: Descriptor) => Promise<void>;
21
+ /**
22
+ * Called when a dependency range is removed from a workspace. Note that
23
+ * this hook is only called by the CLI commands like `yarn remove` - manually
24
+ * removing the dependencies from the manifest and running `yarn install`
25
+ * won't trigger it.
26
+ */
9
27
  afterWorkspaceDependencyRemoval?: (workspace: Workspace, target: suggestUtils.Target, descriptor: Descriptor) => Promise<void>;
28
+ /**
29
+ * Called by `yarn info`. The `extra` field is the set of parameters passed
30
+ * to the `-X,--extra` flag. Calling `registerData` will add a new set of
31
+ * data that will be added to the package information.
32
+ *
33
+ * For instance, an "audit" plugin could check in `extra` whether the user
34
+ * requested audit information (via `-X audit`), and call `registerData`
35
+ * with those information (retrieved dynamically) if they did.
36
+ */
10
37
  fetchPackageInfo?: (pkg: Package, extra: Set<string>, registerData: (namespace: string, data: Array<formatUtils.Tuple> | {
11
38
  [key: string]: formatUtils.Tuple | undefined;
12
39
  }) => void) => Promise<void>;
package/lib/index.js CHANGED
@@ -18,6 +18,7 @@ const run_1 = (0, tslib_1.__importDefault)(require("./commands/entries/run"));
18
18
  const version_1 = (0, tslib_1.__importDefault)(require("./commands/entries/version"));
19
19
  const exec_1 = (0, tslib_1.__importDefault)(require("./commands/exec"));
20
20
  const peerRequirements_1 = (0, tslib_1.__importDefault)(require("./commands/explain/peerRequirements"));
21
+ const explain_1 = (0, tslib_1.__importDefault)(require("./commands/explain"));
21
22
  const info_1 = (0, tslib_1.__importDefault)(require("./commands/info"));
22
23
  const install_1 = (0, tslib_1.__importDefault)(require("./commands/install"));
23
24
  const link_1 = (0, tslib_1.__importDefault)(require("./commands/link"));
@@ -76,6 +77,7 @@ const plugin = {
76
77
  dedupe_1.default,
77
78
  exec_1.default,
78
79
  peerRequirements_1.default,
80
+ explain_1.default,
79
81
  info_1.default,
80
82
  install_1.default,
81
83
  link_1.default,
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@yarnpkg/plugin-essentials",
3
- "version": "3.2.0-rc.2",
3
+ "version": "3.2.0-rc.6",
4
4
  "license": "BSD-2-Clause",
5
5
  "main": "./lib/index.js",
6
6
  "dependencies": {
7
- "@yarnpkg/fslib": "^2.6.0",
7
+ "@yarnpkg/fslib": "^2.6.1-rc.3",
8
8
  "@yarnpkg/json-proxy": "^2.1.1",
9
- "@yarnpkg/parsers": "^2.5.0-rc.2",
9
+ "@yarnpkg/parsers": "^2.5.0-rc.6",
10
10
  "ci-info": "^3.2.0",
11
- "clipanion": "^3.0.1",
11
+ "clipanion": "^3.2.0-rc.4",
12
12
  "enquirer": "^2.3.6",
13
13
  "lodash": "^4.17.15",
14
14
  "micromatch": "^4.0.2",
@@ -17,18 +17,18 @@
17
17
  "typanion": "^3.3.0"
18
18
  },
19
19
  "peerDependencies": {
20
- "@yarnpkg/cli": "^3.2.0-rc.4",
21
- "@yarnpkg/core": "^3.2.0-rc.4",
22
- "@yarnpkg/plugin-git": "^2.6.0-rc.4"
20
+ "@yarnpkg/cli": "^3.2.0-rc.8",
21
+ "@yarnpkg/core": "^3.2.0-rc.8",
22
+ "@yarnpkg/plugin-git": "^2.6.0-rc.8"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/lodash": "^4.14.136",
26
26
  "@types/micromatch": "^4.0.1",
27
27
  "@types/semver": "^7.1.0",
28
28
  "@types/treeify": "^1.0.0",
29
- "@yarnpkg/cli": "^3.2.0-rc.4",
30
- "@yarnpkg/core": "^3.2.0-rc.4",
31
- "@yarnpkg/plugin-git": "^2.6.0-rc.4"
29
+ "@yarnpkg/cli": "^3.2.0-rc.8",
30
+ "@yarnpkg/core": "^3.2.0-rc.8",
31
+ "@yarnpkg/plugin-git": "^2.6.0-rc.8"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",