@yarnpkg/cli 4.0.0-rc.48 → 4.0.0-rc.49

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.
@@ -5,67 +5,7 @@ const pnpFile = `${__dirname}/../../../.pnp.cjs`;
5
5
  if (fs.existsSync(pnpFile))
6
6
  require(pnpFile).setup();
7
7
 
8
- // Adds TS support to Node
9
8
  require(`@yarnpkg/monorepo/scripts/setup-ts-execution`);
9
+ require(`@yarnpkg/monorepo/scripts/setup-local-plugins`);
10
10
 
11
- const semver = require(`semver`);
12
-
13
- const {version} = require(`@yarnpkg/cli/package.json`);
14
-
15
- // Exposes the CLI version as like for the bundle
16
- global.YARN_VERSION = semver.prerelease(version) !== null
17
- ? `${version}.dev`
18
- : `${version}-dev`;
19
-
20
- // Inject the plugins in the runtime. With Webpack that would be through
21
- // val-loader which would execute pluginConfiguration.raw.js, so in Node
22
- // we need to do something similar and mutate the require cache.
23
- const PLUGIN_CONFIG_MODULE = `./tools/getPluginConfiguration.ts`;
24
- require.cache[require.resolve(PLUGIN_CONFIG_MODULE)] = {exports: {getPluginConfiguration}};
25
-
26
- const micromatch = require(`micromatch`);
27
-
28
- module.exports = require(`./cli`);
29
-
30
- function getPluginConfiguration() {
31
- const folders = fs.readdirSync(`${__dirname}/../../`);
32
-
33
- const pluginFolders = folders.filter(folder => {
34
- if (!folder.startsWith(`plugin-`))
35
- return false;
36
-
37
- if (process.env.BLACKLIST && micromatch.match([folder, folder.replace(`plugin-`, ``)], process.env.BLACKLIST).length > 0) {
38
- console.warn(`Disabled blacklisted plugin ${folder}`);
39
- return false;
40
- }
41
-
42
- let isRequirable;
43
- try {
44
- require(`${__dirname}/../../${folder}`);
45
- isRequirable = true;
46
- } catch (e) {
47
- console.warn(`Disabled non-requirable plugin ${folder}: ${e.message}`);
48
- isRequirable = false;
49
- }
50
- return isRequirable;
51
- });
52
-
53
- // Note that we don't need to populate the `modules` field, because the
54
- // plugins will be loaded without being transformed by the builder wrapper,
55
- // so they will simply access their own set of dependencies.
56
- const pluginConfiguration = {
57
- plugins: new Set(),
58
- modules: new Map(),
59
- };
60
-
61
- for (const folder of pluginFolders) {
62
- pluginConfiguration.plugins.add(`@yarnpkg/${folder}`);
63
- pluginConfiguration.modules.set(`@yarnpkg/${folder}`, require(`../../${folder}`));
64
- }
65
-
66
- const {getDynamicLibs} = require(`./tools/getDynamicLibs`);
67
- for (const [name, module] of getDynamicLibs())
68
- pluginConfiguration.modules.set(name, module);
69
-
70
- return pluginConfiguration;
71
- }
11
+ require(`./cli`);
package/lib/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ export { type CommandContext } from '@yarnpkg/core';
1
2
  export { BaseCommand } from './tools/BaseCommand';
2
3
  export { WorkspaceRequiredError } from './tools/WorkspaceRequiredError';
3
4
  export { getDynamicLibs } from './tools/getDynamicLibs';
4
5
  export { getPluginConfiguration } from './tools/getPluginConfiguration';
5
6
  export { openWorkspace } from './tools/openWorkspace';
6
- export { main } from './main';
7
+ export { type YarnCli, getCli, runExit } from './lib';
7
8
  export { pluginCommands } from './pluginCommands';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pluginCommands = exports.main = exports.openWorkspace = exports.getPluginConfiguration = exports.getDynamicLibs = exports.WorkspaceRequiredError = exports.BaseCommand = void 0;
3
+ exports.pluginCommands = exports.runExit = exports.getCli = exports.openWorkspace = exports.getPluginConfiguration = exports.getDynamicLibs = exports.WorkspaceRequiredError = exports.BaseCommand = void 0;
4
4
  var BaseCommand_1 = require("./tools/BaseCommand");
5
5
  Object.defineProperty(exports, "BaseCommand", { enumerable: true, get: function () { return BaseCommand_1.BaseCommand; } });
6
6
  var WorkspaceRequiredError_1 = require("./tools/WorkspaceRequiredError");
@@ -11,7 +11,8 @@ var getPluginConfiguration_1 = require("./tools/getPluginConfiguration");
11
11
  Object.defineProperty(exports, "getPluginConfiguration", { enumerable: true, get: function () { return getPluginConfiguration_1.getPluginConfiguration; } });
12
12
  var openWorkspace_1 = require("./tools/openWorkspace");
13
13
  Object.defineProperty(exports, "openWorkspace", { enumerable: true, get: function () { return openWorkspace_1.openWorkspace; } });
14
- var main_1 = require("./main");
15
- Object.defineProperty(exports, "main", { enumerable: true, get: function () { return main_1.main; } });
14
+ var lib_1 = require("./lib");
15
+ Object.defineProperty(exports, "getCli", { enumerable: true, get: function () { return lib_1.getCli; } });
16
+ Object.defineProperty(exports, "runExit", { enumerable: true, get: function () { return lib_1.runExit; } });
16
17
  var pluginCommands_1 = require("./pluginCommands");
17
18
  Object.defineProperty(exports, "pluginCommands", { enumerable: true, get: function () { return pluginCommands_1.pluginCommands; } });
package/lib/lib.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ /// <reference types="node" />
2
+ import { CommandContext, PluginConfiguration } from '@yarnpkg/core';
3
+ import { PortablePath } from '@yarnpkg/fslib';
4
+ import { Cli } from 'clipanion';
5
+ export type YarnCli = ReturnType<typeof getBaseCli>;
6
+ declare function getBaseCli({ cwd, pluginConfiguration }: {
7
+ cwd: PortablePath;
8
+ pluginConfiguration: PluginConfiguration;
9
+ }): Cli<CommandContext> & {
10
+ defaultContext: {
11
+ cwd: PortablePath;
12
+ plugins: PluginConfiguration;
13
+ quiet: boolean;
14
+ stdin: NodeJS.ReadStream & {
15
+ fd: 0;
16
+ };
17
+ stdout: NodeJS.WriteStream & {
18
+ fd: 1;
19
+ };
20
+ stderr: NodeJS.WriteStream & {
21
+ fd: 2;
22
+ };
23
+ env: NodeJS.ProcessEnv;
24
+ colorDepth: number;
25
+ };
26
+ };
27
+ export declare function getCli({ cwd, pluginConfiguration }?: {
28
+ cwd?: PortablePath;
29
+ pluginConfiguration?: PluginConfiguration;
30
+ }): Promise<Cli<CommandContext> & {
31
+ defaultContext: {
32
+ cwd: PortablePath;
33
+ plugins: PluginConfiguration;
34
+ quiet: boolean;
35
+ stdin: NodeJS.ReadStream & {
36
+ fd: 0;
37
+ };
38
+ stdout: NodeJS.WriteStream & {
39
+ fd: 1;
40
+ };
41
+ stderr: NodeJS.WriteStream & {
42
+ fd: 2;
43
+ };
44
+ env: NodeJS.ProcessEnv;
45
+ colorDepth: number;
46
+ };
47
+ }>;
48
+ export declare function runExit(argv: Array<string>, { cwd, selfPath, pluginConfiguration }: {
49
+ cwd: PortablePath;
50
+ selfPath: PortablePath | null;
51
+ pluginConfiguration: PluginConfiguration;
52
+ }): Promise<void>;
53
+ export {};
package/lib/lib.js ADDED
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runExit = exports.getCli = void 0;
4
+ const core_1 = require("@yarnpkg/core");
5
+ const fslib_1 = require("@yarnpkg/fslib");
6
+ const child_process_1 = require("child_process");
7
+ const ci_info_1 = require("ci-info");
8
+ const clipanion_1 = require("clipanion");
9
+ const pluginCommands_1 = require("./pluginCommands");
10
+ const getPluginConfiguration_1 = require("./tools/getPluginConfiguration");
11
+ function getBaseCli({ cwd, pluginConfiguration }) {
12
+ const cli = new clipanion_1.Cli({
13
+ binaryLabel: `Yarn Package Manager`,
14
+ binaryName: `yarn`,
15
+ binaryVersion: core_1.YarnVersion ?? `<unknown>`,
16
+ });
17
+ return Object.assign(cli, {
18
+ defaultContext: {
19
+ ...clipanion_1.Cli.defaultContext,
20
+ cwd,
21
+ plugins: pluginConfiguration,
22
+ quiet: false,
23
+ stdin: process.stdin,
24
+ stdout: process.stdout,
25
+ stderr: process.stderr,
26
+ },
27
+ });
28
+ }
29
+ function validateNodejsVersion(cli) {
30
+ // YARN_IGNORE_NODE is special because this code needs to execute as early as possible.
31
+ // It's not a regular core setting because Configuration.find may use functions not available
32
+ // on older Node versions.
33
+ const ignoreNode = core_1.miscUtils.parseOptionalBoolean(process.env.YARN_IGNORE_NODE);
34
+ if (ignoreNode)
35
+ return true;
36
+ const version = process.versions.node;
37
+ // Non-exhaustive known requirements:
38
+ // - 18.12 is the first LTS release
39
+ const range = `>=18.12.0`;
40
+ if (core_1.semverUtils.satisfiesWithPrereleases(version, range))
41
+ return true;
42
+ const error = new clipanion_1.UsageError(`This tool requires a Node version compatible with ${range} (got ${version}). Upgrade Node, or set \`YARN_IGNORE_NODE=1\` in your environment.`);
43
+ clipanion_1.Cli.defaultContext.stdout.write(cli.error(error));
44
+ return false;
45
+ }
46
+ async function getCoreConfiguration({ selfPath, pluginConfiguration }) {
47
+ // Since we only care about a few very specific settings we tolerate extra configuration key.
48
+ // If we didn't, we wouldn't even be able to run `yarn config` (which is recommended in the invalid config error message)
49
+ return await core_1.Configuration.find(fslib_1.npath.toPortablePath(process.cwd()), pluginConfiguration, {
50
+ strict: false,
51
+ usePathCheck: selfPath,
52
+ });
53
+ }
54
+ function runYarnPath(cli, argv, { yarnPath }) {
55
+ if (!fslib_1.xfs.existsSync(yarnPath)) {
56
+ (cli.error(new Error(`The "yarn-path" option has been set, but the specified location doesn't exist (${yarnPath}).`)));
57
+ return 1;
58
+ }
59
+ process.on(`SIGINT`, () => {
60
+ // We don't want SIGINT to kill our process; we want it to kill the
61
+ // innermost process, whose end will cause our own to exit.
62
+ });
63
+ const yarnPathExecOptions = {
64
+ stdio: `inherit`,
65
+ env: {
66
+ ...process.env,
67
+ YARN_IGNORE_PATH: `1`,
68
+ },
69
+ };
70
+ try {
71
+ (0, child_process_1.execFileSync)(process.execPath, [fslib_1.npath.fromPortablePath(yarnPath), ...argv], yarnPathExecOptions);
72
+ }
73
+ catch (err) {
74
+ return err.code ?? 1;
75
+ }
76
+ return 0;
77
+ }
78
+ function checkCwd(cli, argv) {
79
+ let cwd = null;
80
+ let postCwdArgv = argv;
81
+ if (argv.length >= 2 && argv[0] === `--cwd`) {
82
+ cwd = fslib_1.npath.toPortablePath(argv[1]);
83
+ postCwdArgv = argv.slice(2);
84
+ }
85
+ else if (argv.length >= 1 && argv[0].startsWith(`--cwd=`)) {
86
+ cwd = fslib_1.npath.toPortablePath(argv[0].slice(6));
87
+ postCwdArgv = argv.slice(1);
88
+ }
89
+ cli.defaultContext.cwd = cwd !== null
90
+ ? fslib_1.ppath.resolve(cwd)
91
+ : fslib_1.ppath.cwd();
92
+ return postCwdArgv;
93
+ }
94
+ function initTelemetry(cli, { configuration }) {
95
+ const isTelemetryEnabled = configuration.get(`enableTelemetry`);
96
+ if (!isTelemetryEnabled || ci_info_1.isCI || !process.stdout.isTTY)
97
+ return;
98
+ core_1.Configuration.telemetry = new core_1.TelemetryManager(configuration, `puba9cdc10ec5790a2cf4969dd413a47270`);
99
+ for (const name of configuration.plugins.keys())
100
+ if (pluginCommands_1.pluginCommands.has(name.match(/^@yarnpkg\/plugin-(.*)$/)?.[1] ?? ``))
101
+ core_1.Configuration.telemetry?.reportPluginName(name);
102
+ if (cli.binaryVersion) {
103
+ core_1.Configuration.telemetry.reportVersion(cli.binaryVersion);
104
+ }
105
+ }
106
+ function initCommands(cli, { configuration }) {
107
+ for (const plugin of configuration.plugins.values()) {
108
+ for (const command of plugin.commands || []) {
109
+ cli.register(command);
110
+ }
111
+ }
112
+ }
113
+ async function run(cli, argv, { selfPath, pluginConfiguration }) {
114
+ if (!validateNodejsVersion(cli))
115
+ return 1;
116
+ const configuration = await getCoreConfiguration({
117
+ selfPath,
118
+ pluginConfiguration,
119
+ });
120
+ const yarnPath = configuration.get(`yarnPath`);
121
+ const ignorePath = configuration.get(`ignorePath`);
122
+ if (yarnPath && !ignorePath)
123
+ return runYarnPath(cli, argv, { yarnPath });
124
+ delete process.env.YARN_IGNORE_PATH;
125
+ const postCwdArgv = checkCwd(cli, argv);
126
+ initTelemetry(cli, { configuration });
127
+ initCommands(cli, { configuration });
128
+ const command = cli.process(postCwdArgv, cli.defaultContext);
129
+ if (!command.help)
130
+ core_1.Configuration.telemetry?.reportCommandName(command.path.join(` `));
131
+ return await cli.run(command, cli.defaultContext);
132
+ }
133
+ async function getCli({ cwd = fslib_1.ppath.cwd(), pluginConfiguration = (0, getPluginConfiguration_1.getPluginConfiguration)() } = {}) {
134
+ const cli = getBaseCli({ cwd, pluginConfiguration });
135
+ const configuration = await getCoreConfiguration({
136
+ pluginConfiguration,
137
+ selfPath: null,
138
+ });
139
+ initCommands(cli, { configuration });
140
+ return cli;
141
+ }
142
+ exports.getCli = getCli;
143
+ async function runExit(argv, { cwd = fslib_1.ppath.cwd(), selfPath, pluginConfiguration }) {
144
+ const cli = getBaseCli({ cwd, pluginConfiguration });
145
+ try {
146
+ process.exitCode = await run(cli, argv, { selfPath, pluginConfiguration });
147
+ }
148
+ catch (error) {
149
+ clipanion_1.Cli.defaultContext.stdout.write(cli.error(error));
150
+ process.exitCode = 1;
151
+ }
152
+ finally {
153
+ await fslib_1.xfs.rmtempPromise();
154
+ }
155
+ }
156
+ exports.runExit = runExit;
@@ -1 +0,0 @@
1
- export {};
package/lib/polyfills.js CHANGED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // No polyfills are currently needed
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,4 +3,5 @@ import { Command } from 'clipanion';
3
3
  export declare abstract class BaseCommand extends Command<CommandContext> {
4
4
  cwd: string | undefined;
5
5
  abstract execute(): Promise<number | void>;
6
+ validateAndExecute(): Promise<number>;
6
7
  }
@@ -7,5 +7,10 @@ class BaseCommand extends clipanion_1.Command {
7
7
  super(...arguments);
8
8
  this.cwd = clipanion_1.Option.String(`--cwd`, { hidden: true });
9
9
  }
10
+ validateAndExecute() {
11
+ if (typeof this.cwd !== `undefined`)
12
+ throw new clipanion_1.UsageError(`The --cwd option is ambiguous when used anywhere else than the very first parameter provided in the command line, before even the command path`);
13
+ return super.validateAndExecute();
14
+ }
10
15
  }
11
16
  exports.BaseCommand = BaseCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarnpkg/cli",
3
- "version": "4.0.0-rc.48",
3
+ "version": "4.0.0-rc.49",
4
4
  "stableVersion": "3.6.1",
5
5
  "license": "BSD-2-Clause",
6
6
  "main": "./lib/index.js",
@@ -9,49 +9,48 @@
9
9
  "./package.json": "./package.json"
10
10
  },
11
11
  "dependencies": {
12
- "@yarnpkg/core": "^4.0.0-rc.48",
13
- "@yarnpkg/fslib": "^3.0.0-rc.48",
14
- "@yarnpkg/libzip": "^3.0.0-rc.48",
15
- "@yarnpkg/parsers": "^3.0.0-rc.48",
16
- "@yarnpkg/plugin-compat": "^4.0.0-rc.48",
17
- "@yarnpkg/plugin-constraints": "^4.0.0-rc.48",
18
- "@yarnpkg/plugin-dlx": "^4.0.0-rc.48",
19
- "@yarnpkg/plugin-essentials": "^4.0.0-rc.48",
20
- "@yarnpkg/plugin-exec": "^3.0.0-rc.48",
21
- "@yarnpkg/plugin-file": "^3.0.0-rc.48",
22
- "@yarnpkg/plugin-git": "^3.0.0-rc.48",
23
- "@yarnpkg/plugin-github": "^3.0.0-rc.48",
24
- "@yarnpkg/plugin-http": "^3.0.0-rc.48",
25
- "@yarnpkg/plugin-init": "^4.0.0-rc.48",
26
- "@yarnpkg/plugin-interactive-tools": "^4.0.0-rc.48",
27
- "@yarnpkg/plugin-link": "^3.0.0-rc.48",
28
- "@yarnpkg/plugin-nm": "^4.0.0-rc.48",
29
- "@yarnpkg/plugin-npm": "^3.0.0-rc.48",
30
- "@yarnpkg/plugin-npm-cli": "^4.0.0-rc.48",
31
- "@yarnpkg/plugin-pack": "^4.0.0-rc.48",
32
- "@yarnpkg/plugin-patch": "^4.0.0-rc.48",
33
- "@yarnpkg/plugin-pnp": "^4.0.0-rc.48",
34
- "@yarnpkg/plugin-pnpm": "^2.0.0-rc.48",
35
- "@yarnpkg/plugin-stage": "^4.0.0-rc.48",
36
- "@yarnpkg/plugin-typescript": "^4.0.0-rc.48",
37
- "@yarnpkg/plugin-version": "^4.0.0-rc.48",
38
- "@yarnpkg/plugin-workspace-tools": "^4.0.0-rc.48",
39
- "@yarnpkg/shell": "^4.0.0-rc.48",
12
+ "@yarnpkg/core": "^4.0.0-rc.49",
13
+ "@yarnpkg/fslib": "^3.0.0-rc.49",
14
+ "@yarnpkg/libzip": "^3.0.0-rc.49",
15
+ "@yarnpkg/parsers": "^3.0.0-rc.49",
16
+ "@yarnpkg/plugin-compat": "^4.0.0-rc.49",
17
+ "@yarnpkg/plugin-constraints": "^4.0.0-rc.49",
18
+ "@yarnpkg/plugin-dlx": "^4.0.0-rc.49",
19
+ "@yarnpkg/plugin-essentials": "^4.0.0-rc.49",
20
+ "@yarnpkg/plugin-exec": "^3.0.0-rc.49",
21
+ "@yarnpkg/plugin-file": "^3.0.0-rc.49",
22
+ "@yarnpkg/plugin-git": "^3.0.0-rc.49",
23
+ "@yarnpkg/plugin-github": "^3.0.0-rc.49",
24
+ "@yarnpkg/plugin-http": "^3.0.0-rc.49",
25
+ "@yarnpkg/plugin-init": "^4.0.0-rc.49",
26
+ "@yarnpkg/plugin-interactive-tools": "^4.0.0-rc.49",
27
+ "@yarnpkg/plugin-link": "^3.0.0-rc.49",
28
+ "@yarnpkg/plugin-nm": "^4.0.0-rc.49",
29
+ "@yarnpkg/plugin-npm": "^3.0.0-rc.49",
30
+ "@yarnpkg/plugin-npm-cli": "^4.0.0-rc.49",
31
+ "@yarnpkg/plugin-pack": "^4.0.0-rc.49",
32
+ "@yarnpkg/plugin-patch": "^4.0.0-rc.49",
33
+ "@yarnpkg/plugin-pnp": "^4.0.0-rc.49",
34
+ "@yarnpkg/plugin-pnpm": "^2.0.0-rc.49",
35
+ "@yarnpkg/plugin-stage": "^4.0.0-rc.49",
36
+ "@yarnpkg/plugin-typescript": "^4.0.0-rc.49",
37
+ "@yarnpkg/plugin-version": "^4.0.0-rc.49",
38
+ "@yarnpkg/plugin-workspace-tools": "^4.0.0-rc.49",
39
+ "@yarnpkg/shell": "^4.0.0-rc.49",
40
40
  "ci-info": "^3.2.0",
41
- "clipanion": "^3.2.1",
41
+ "clipanion": "^4.0.0-rc.2",
42
42
  "semver": "^7.1.2",
43
43
  "tslib": "^2.4.0",
44
- "typanion": "^3.12.1"
44
+ "typanion": "^3.14.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/semver": "^7.1.0",
48
- "@yarnpkg/builder": "^4.0.0-rc.48",
48
+ "@yarnpkg/builder": "^4.0.0-rc.49",
49
49
  "@yarnpkg/monorepo": "^0.0.0",
50
- "@yarnpkg/pnpify": "^4.0.0-rc.48",
51
- "micromatch": "^4.0.2"
50
+ "@yarnpkg/pnpify": "^4.0.0-rc.49"
52
51
  },
53
52
  "peerDependencies": {
54
- "@yarnpkg/core": "^4.0.0-rc.48"
53
+ "@yarnpkg/core": "^4.0.0-rc.49"
55
54
  },
56
55
  "scripts": {
57
56
  "postpack": "rm -rf lib",
package/lib/main.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { PluginConfiguration } from '@yarnpkg/core';
2
- export declare function main({ binaryVersion, pluginConfiguration }: {
3
- binaryVersion: string;
4
- pluginConfiguration: PluginConfiguration;
5
- }): Promise<void>;
package/lib/main.js DELETED
@@ -1,150 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
4
- const core_1 = require("@yarnpkg/core");
5
- const fslib_1 = require("@yarnpkg/fslib");
6
- const child_process_1 = require("child_process");
7
- const ci_info_1 = require("ci-info");
8
- const clipanion_1 = require("clipanion");
9
- const fs_1 = require("fs");
10
- const pluginCommands_1 = require("./pluginCommands");
11
- function runBinary(path) {
12
- const physicalPath = fslib_1.npath.fromPortablePath(path);
13
- process.on(`SIGINT`, () => {
14
- // We don't want SIGINT to kill our process; we want it to kill the
15
- // innermost process, whose end will cause our own to exit.
16
- });
17
- if (physicalPath) {
18
- (0, child_process_1.execFileSync)(process.execPath, [physicalPath, ...process.argv.slice(2)], {
19
- stdio: `inherit`,
20
- env: {
21
- ...process.env,
22
- YARN_IGNORE_PATH: `1`,
23
- YARN_IGNORE_CWD: `1`,
24
- },
25
- });
26
- }
27
- else {
28
- (0, child_process_1.execFileSync)(physicalPath, process.argv.slice(2), {
29
- stdio: `inherit`,
30
- env: {
31
- ...process.env,
32
- YARN_IGNORE_PATH: `1`,
33
- YARN_IGNORE_CWD: `1`,
34
- },
35
- });
36
- }
37
- }
38
- async function main({ binaryVersion, pluginConfiguration }) {
39
- async function run() {
40
- const cli = new clipanion_1.Cli({
41
- binaryLabel: `Yarn Package Manager`,
42
- binaryName: `yarn`,
43
- binaryVersion,
44
- });
45
- try {
46
- await exec(cli);
47
- }
48
- catch (error) {
49
- process.stdout.write(cli.error(error));
50
- process.exitCode = 1;
51
- }
52
- }
53
- async function exec(cli) {
54
- // Non-exhaustive known requirements:
55
- // - 18.12 is the first LTS release
56
- var _a, _b, _c, _d, _e;
57
- const version = process.versions.node;
58
- const range = `>=18.12.0`;
59
- // YARN_IGNORE_NODE is special because this code needs to execute as early as possible.
60
- // It's not a regular core setting because Configuration.find may use functions not available
61
- // on older Node versions.
62
- const ignoreNode = core_1.miscUtils.parseOptionalBoolean(process.env.YARN_IGNORE_NODE);
63
- if (!ignoreNode && !core_1.semverUtils.satisfiesWithPrereleases(version, range))
64
- throw new clipanion_1.UsageError(`This tool requires a Node version compatible with ${range} (got ${version}). Upgrade Node, or set \`YARN_IGNORE_NODE=1\` in your environment.`);
65
- // Since we only care about a few very specific settings (yarn-path and ignore-path) we tolerate extra configuration key.
66
- // If we didn't, we wouldn't even be able to run `yarn config` (which is recommended in the invalid config error message)
67
- const configuration = await core_1.Configuration.find(fslib_1.npath.toPortablePath(process.cwd()), pluginConfiguration, {
68
- usePath: true,
69
- strict: false,
70
- });
71
- const yarnPath = configuration.get(`yarnPath`);
72
- const ignorePath = configuration.get(`ignorePath`);
73
- const ignoreCwd = configuration.get(`ignoreCwd`);
74
- const selfPath = fslib_1.npath.toPortablePath(fslib_1.npath.resolve(process.argv[1]));
75
- const tryRead = (p) => fslib_1.xfs.readFilePromise(p).catch(() => {
76
- return Buffer.of();
77
- });
78
- const isSameBinary = async () => yarnPath && (yarnPath === selfPath ||
79
- Buffer.compare(...await Promise.all([
80
- tryRead(yarnPath),
81
- tryRead(selfPath),
82
- ])) === 0);
83
- // Avoid unnecessary spawn when run directly
84
- if (!ignorePath && !ignoreCwd && await isSameBinary()) {
85
- process.env.YARN_IGNORE_PATH = `1`;
86
- process.env.YARN_IGNORE_CWD = `1`;
87
- await exec(cli);
88
- return;
89
- }
90
- else if (yarnPath !== null && !ignorePath) {
91
- if (!fslib_1.xfs.existsSync(yarnPath)) {
92
- process.stdout.write(cli.error(new Error(`The "yarn-path" option has been set (in ${configuration.sources.get(`yarnPath`)}), but the specified location doesn't exist (${yarnPath}).`)));
93
- process.exitCode = 1;
94
- }
95
- else {
96
- try {
97
- runBinary(yarnPath);
98
- }
99
- catch (error) {
100
- process.exitCode = error.code || 1;
101
- }
102
- }
103
- }
104
- else {
105
- if (ignorePath)
106
- delete process.env.YARN_IGNORE_PATH;
107
- const isTelemetryEnabled = configuration.get(`enableTelemetry`);
108
- if (isTelemetryEnabled && !ci_info_1.isCI && process.stdout.isTTY)
109
- core_1.Configuration.telemetry = new core_1.TelemetryManager(configuration, `puba9cdc10ec5790a2cf4969dd413a47270`);
110
- (_a = core_1.Configuration.telemetry) === null || _a === void 0 ? void 0 : _a.reportVersion(binaryVersion);
111
- for (const [name, plugin] of configuration.plugins.entries()) {
112
- if (pluginCommands_1.pluginCommands.has((_c = (_b = name.match(/^@yarnpkg\/plugin-(.*)$/)) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : ``))
113
- (_d = core_1.Configuration.telemetry) === null || _d === void 0 ? void 0 : _d.reportPluginName(name);
114
- for (const command of plugin.commands || []) {
115
- cli.register(command);
116
- }
117
- }
118
- const context = {
119
- cwd: fslib_1.npath.toPortablePath(process.cwd()),
120
- plugins: pluginConfiguration,
121
- quiet: false,
122
- stdin: process.stdin,
123
- stdout: process.stdout,
124
- stderr: process.stderr,
125
- };
126
- const command = cli.process(process.argv.slice(2), context);
127
- if (!command.help)
128
- (_e = core_1.Configuration.telemetry) === null || _e === void 0 ? void 0 : _e.reportCommandName(command.path.join(` `));
129
- // @ts-expect-error: The cwd is a global option defined by BaseCommand
130
- const cwd = command.cwd;
131
- if (typeof cwd !== `undefined` && !ignoreCwd) {
132
- const iAmHere = (0, fs_1.realpathSync)(process.cwd());
133
- const iShouldBeHere = (0, fs_1.realpathSync)(cwd);
134
- if (iAmHere !== iShouldBeHere) {
135
- process.chdir(cwd);
136
- await run();
137
- return;
138
- }
139
- }
140
- await cli.runExit(command, context);
141
- }
142
- }
143
- return run()
144
- .catch(error => {
145
- process.stdout.write(error.stack || error.message);
146
- process.exitCode = 1;
147
- })
148
- .finally(() => fslib_1.xfs.rmtempPromise());
149
- }
150
- exports.main = main;