@yarnpkg/plugin-essentials 4.0.0-rc.2 → 4.0.0-rc.21

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.
@@ -86,24 +86,27 @@ class AddCommand extends cli_1.BaseCommand {
86
86
  : core_3.structUtils.tryParseDescriptor(pseudoDescriptor);
87
87
  const unsupportedPrefix = pseudoDescriptor.match(/^(https?:|git@github)/);
88
88
  if (unsupportedPrefix)
89
- throw new clipanion_1.UsageError(`It seems you are trying to add a package using a ${core_1.formatUtils.pretty(configuration, `${unsupportedPrefix[0]}...`, core_1.FormatType.RANGE)} url; we now require package names to be explicitly specified.\nTry running the command again with the package name prefixed: ${core_1.formatUtils.pretty(configuration, `yarn add`, core_1.FormatType.CODE)} ${core_1.formatUtils.pretty(configuration, core_3.structUtils.makeDescriptor(core_3.structUtils.makeIdent(null, `my-package`), `${unsupportedPrefix[0]}...`), core_1.FormatType.DESCRIPTOR)}`);
89
+ throw new clipanion_1.UsageError(`It seems you are trying to add a package using a ${core_1.formatUtils.pretty(configuration, `${unsupportedPrefix[0]}...`, core_1.formatUtils.Type.RANGE)} url; we now require package names to be explicitly specified.\nTry running the command again with the package name prefixed: ${core_1.formatUtils.pretty(configuration, `yarn add`, core_1.formatUtils.Type.CODE)} ${core_1.formatUtils.pretty(configuration, core_3.structUtils.makeDescriptor(core_3.structUtils.makeIdent(null, `my-package`), `${unsupportedPrefix[0]}...`), core_1.formatUtils.Type.DESCRIPTOR)}`);
90
90
  if (!request)
91
- throw new clipanion_1.UsageError(`The ${core_1.formatUtils.pretty(configuration, pseudoDescriptor, core_1.FormatType.CODE)} string didn't match the required format (package-name@range). Did you perhaps forget to explicitly reference the package name?`);
92
- const target = suggestTarget(workspace, request, {
91
+ throw new clipanion_1.UsageError(`The ${core_1.formatUtils.pretty(configuration, pseudoDescriptor, core_1.formatUtils.Type.CODE)} string didn't match the required format (package-name@range). Did you perhaps forget to explicitly reference the package name?`);
92
+ const targetList = suggestTargetList(workspace, request, {
93
93
  dev: this.dev,
94
94
  peer: this.peer,
95
95
  preferDev: this.preferDev,
96
96
  optional: this.optional,
97
97
  });
98
- const suggestions = await suggestUtils.getSuggestedDescriptors(request, { project, workspace, cache, fixed, target, modifier, strategies, maxResults });
99
- return [request, suggestions, target];
100
- }));
98
+ const results = await Promise.all(targetList.map(async (target) => {
99
+ const suggestedDescriptors = await suggestUtils.getSuggestedDescriptors(request, { project, workspace, cache, fixed, target, modifier, strategies, maxResults });
100
+ return { request, suggestedDescriptors, target };
101
+ }));
102
+ return results;
103
+ })).then(results => results.flat());
101
104
  const checkReport = await core_1.LightReport.start({
102
105
  configuration,
103
106
  stdout: this.context.stdout,
104
107
  suggestInstall: false,
105
108
  }, async (report) => {
106
- for (const [request, { suggestions, rejections }] of allSuggestions) {
109
+ for (const { request, suggestedDescriptors: { suggestions, rejections } } of allSuggestions) {
107
110
  const nonNullSuggestions = suggestions.filter(suggestion => {
108
111
  return suggestion.descriptor !== null;
109
112
  });
@@ -125,7 +128,7 @@ class AddCommand extends cli_1.BaseCommand {
125
128
  let askedQuestions = false;
126
129
  const afterWorkspaceDependencyAdditionList = [];
127
130
  const afterWorkspaceDependencyReplacementList = [];
128
- for (const [/*request*/ , { suggestions }, target] of allSuggestions) {
131
+ for (const { suggestedDescriptors: { suggestions }, target } of allSuggestions) {
129
132
  let selected;
130
133
  const nonNullSuggestions = suggestions.filter(suggestion => {
131
134
  return suggestion.descriptor !== null;
@@ -262,7 +265,7 @@ AddCommand.usage = clipanion_1.Command.Usage({
262
265
  `$0 add lodash-es@lodash/lodash#es`,
263
266
  ]],
264
267
  });
265
- function suggestTarget(workspace, ident, { dev, peer, preferDev, optional }) {
268
+ function suggestTargetList(workspace, ident, { dev, peer, preferDev, optional }) {
266
269
  const hasRegular = workspace.manifest[suggestUtils.Target.REGULAR].has(ident.identHash);
267
270
  const hasDev = workspace.manifest[suggestUtils.Target.DEVELOPMENT].has(ident.identHash);
268
271
  const hasPeer = workspace.manifest[suggestUtils.Target.PEER].has(ident.identHash);
@@ -276,13 +279,21 @@ function suggestTarget(workspace, ident, { dev, peer, preferDev, optional }) {
276
279
  throw new clipanion_1.UsageError(`Package "${core_3.structUtils.prettyIdent(workspace.project.configuration, ident)}" is already listed as a peer dependency - remove the -O flag or add the -P flag or remove it from your peer dependencies first`);
277
280
  if ((dev || preferDev) && optional)
278
281
  throw new clipanion_1.UsageError(`Package "${core_3.structUtils.prettyIdent(workspace.project.configuration, ident)}" cannot simultaneously be a dev dependency and an optional dependency`);
282
+ // When the program executes this line, the command is expected to be legal
283
+ const targetList = [];
279
284
  if (peer)
280
- return suggestUtils.Target.PEER;
285
+ targetList.push(suggestUtils.Target.PEER);
281
286
  if (dev || preferDev)
282
- return suggestUtils.Target.DEVELOPMENT;
283
- if (hasRegular)
284
- return suggestUtils.Target.REGULAR;
287
+ targetList.push(suggestUtils.Target.DEVELOPMENT);
288
+ if (optional)
289
+ targetList.push(suggestUtils.Target.REGULAR);
290
+ // The user explicitly define the targets
291
+ if (targetList.length > 0)
292
+ return targetList;
293
+ // The user does not define the targets, find it from the `workspace.manifest`
285
294
  if (hasDev)
286
- return suggestUtils.Target.DEVELOPMENT;
287
- return suggestUtils.Target.REGULAR;
295
+ return [suggestUtils.Target.DEVELOPMENT];
296
+ if (hasPeer)
297
+ return [suggestUtils.Target.PEER];
298
+ return [suggestUtils.Target.REGULAR];
288
299
  }
@@ -160,7 +160,7 @@ class InfoCommand extends cli_1.BaseCommand {
160
160
  const infoTreeChildren = {};
161
161
  const infoTree = { children: infoTreeChildren };
162
162
  const fetcher = configuration.makeFetcher();
163
- const fetcherOptions = { project, fetcher, cache, checksums: project.storedChecksums, report: new core_1.ThrowReport(), cacheOptions: { skipIntegrityCheck: true }, skipIntegrityCheck: true };
163
+ const fetcherOptions = { project, fetcher, cache, checksums: project.storedChecksums, report: new core_1.ThrowReport(), cacheOptions: { skipIntegrityCheck: true } };
164
164
  const builtinInfoBuilders = [
165
165
  // Manifest fields
166
166
  async (pkg, extra, registerData) => {
@@ -6,6 +6,6 @@ export default class LinkCommand extends BaseCommand {
6
6
  all: boolean;
7
7
  private: boolean;
8
8
  relative: boolean;
9
- destination: string;
9
+ destinations: string[];
10
10
  execute(): Promise<1 | 0>;
11
11
  }
@@ -9,15 +9,15 @@ class LinkCommand extends cli_1.BaseCommand {
9
9
  constructor() {
10
10
  super(...arguments);
11
11
  this.all = clipanion_1.Option.Boolean(`-A,--all`, false, {
12
- description: `Link all workspaces belonging to the target project to the current one`,
12
+ description: `Link all workspaces belonging to the target projects to the current one`,
13
13
  });
14
14
  this.private = clipanion_1.Option.Boolean(`-p,--private`, false, {
15
- description: `Also link private workspaces belonging to the target project to the current one`,
15
+ description: `Also link private workspaces belonging to the target projects to the current one`,
16
16
  });
17
17
  this.relative = clipanion_1.Option.Boolean(`-r,--relative`, false, {
18
18
  description: `Link workspaces using relative paths instead of absolute paths`,
19
19
  });
20
- this.destination = clipanion_1.Option.String();
20
+ this.destinations = clipanion_1.Option.Rest();
21
21
  }
22
22
  async execute() {
23
23
  const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
@@ -28,29 +28,35 @@ class LinkCommand extends cli_1.BaseCommand {
28
28
  await project.restoreInstallState({
29
29
  restoreResolutions: false,
30
30
  });
31
- const absoluteDestination = fslib_1.ppath.resolve(this.context.cwd, fslib_1.npath.toPortablePath(this.destination));
32
- const configuration2 = await core_1.Configuration.find(absoluteDestination, this.context.plugins, { useRc: false, strict: false });
33
- const { project: project2, workspace: workspace2 } = await core_1.Project.find(configuration2, absoluteDestination);
34
- if (project.cwd === project2.cwd)
35
- throw new clipanion_1.UsageError(`Invalid destination; Can't link the project to itself`);
36
- if (!workspace2)
37
- throw new cli_1.WorkspaceRequiredError(project2.cwd, absoluteDestination);
38
31
  const topLevelWorkspace = project.topLevelWorkspace;
39
32
  const linkedWorkspaces = [];
40
- if (this.all) {
41
- for (const workspace of project2.workspaces)
42
- if (workspace.manifest.name && (!workspace.manifest.private || this.private))
43
- linkedWorkspaces.push(workspace);
44
- if (linkedWorkspaces.length === 0) {
45
- throw new clipanion_1.UsageError(`No workspace found to be linked in the target project`);
33
+ for (const destination of this.destinations) {
34
+ const absoluteDestination = fslib_1.ppath.resolve(this.context.cwd, fslib_1.npath.toPortablePath(destination));
35
+ const configuration2 = await core_1.Configuration.find(absoluteDestination, this.context.plugins, { useRc: false, strict: false });
36
+ const { project: project2, workspace: workspace2 } = await core_1.Project.find(configuration2, absoluteDestination);
37
+ if (project.cwd === project2.cwd)
38
+ throw new clipanion_1.UsageError(`Invalid destination '${destination}'; Can't link the project to itself`);
39
+ if (!workspace2)
40
+ throw new cli_1.WorkspaceRequiredError(project2.cwd, absoluteDestination);
41
+ if (this.all) {
42
+ let found = false;
43
+ for (const workspace of project2.workspaces) {
44
+ if (workspace.manifest.name && (!workspace.manifest.private || this.private)) {
45
+ linkedWorkspaces.push(workspace);
46
+ found = true;
47
+ }
48
+ }
49
+ if (!found) {
50
+ throw new clipanion_1.UsageError(`No workspace found to be linked in the target project: ${destination}`);
51
+ }
52
+ }
53
+ else {
54
+ if (!workspace2.manifest.name)
55
+ throw new clipanion_1.UsageError(`The target workspace at '${destination}' doesn't have a name and thus cannot be linked`);
56
+ if (workspace2.manifest.private && !this.private)
57
+ throw new clipanion_1.UsageError(`The target workspace at '${destination}' is marked private - use the --private flag to link it anyway`);
58
+ linkedWorkspaces.push(workspace2);
46
59
  }
47
- }
48
- else {
49
- if (!workspace2.manifest.name)
50
- throw new clipanion_1.UsageError(`The target workspace doesn't have a name and thus cannot be linked`);
51
- if (workspace2.manifest.private && !this.private)
52
- throw new clipanion_1.UsageError(`The target workspace is marked private - use the --private flag to link it anyway`);
53
- linkedWorkspaces.push(workspace2);
54
60
  }
55
61
  for (const workspace of linkedWorkspaces) {
56
62
  const fullName = core_1.structUtils.stringifyIdent(workspace.locator);
@@ -81,8 +87,8 @@ LinkCommand.usage = clipanion_1.Command.Usage({
81
87
  This command will set a new \`resolutions\` field in the project-level manifest and point it to the workspace at the specified location (even if part of another project).
82
88
  `,
83
89
  examples: [[
84
- `Register a remote workspace for use in the current project`,
85
- `$0 link ~/ts-loader`,
90
+ `Register one or more remote workspaces for use in the current project`,
91
+ `$0 link ~/ts-loader ~/jest`,
86
92
  ], [
87
93
  `Register all workspaces from a remote project for use in the current project`,
88
94
  `$0 link ~/jest --all`,
@@ -3,7 +3,7 @@ import { Report, CommandContext } from '@yarnpkg/core';
3
3
  import { Project } from '@yarnpkg/core';
4
4
  import { PortablePath } from '@yarnpkg/fslib';
5
5
  import { Usage } from 'clipanion';
6
- export default class PluginDlSourcesCommand extends BaseCommand {
6
+ export default class PluginImportSourcesCommand extends BaseCommand {
7
7
  static paths: string[][];
8
8
  static usage: Usage;
9
9
  installPath: string | undefined;
@@ -14,7 +14,7 @@ const buildWorkflow = ({ pluginName, noMinify }, target) => [
14
14
  [`yarn`, `build:${pluginName}`, ...noMinify ? [`--no-minify`] : [], `|`],
15
15
  ];
16
16
  // eslint-disable-next-line arca/no-default-export
17
- class PluginDlSourcesCommand extends cli_1.BaseCommand {
17
+ class PluginImportSourcesCommand extends cli_1.BaseCommand {
18
18
  constructor() {
19
19
  super(...arguments);
20
20
  this.installPath = clipanion_1.Option.String(`--path`, {
@@ -56,11 +56,11 @@ class PluginDlSourcesCommand extends cli_1.BaseCommand {
56
56
  return report.exitCode();
57
57
  }
58
58
  }
59
- exports.default = PluginDlSourcesCommand;
60
- PluginDlSourcesCommand.paths = [
59
+ exports.default = PluginImportSourcesCommand;
60
+ PluginImportSourcesCommand.paths = [
61
61
  [`plugin`, `import`, `from`, `sources`],
62
62
  ];
63
- PluginDlSourcesCommand.usage = clipanion_1.Command.Usage({
63
+ PluginImportSourcesCommand.usage = clipanion_1.Command.Usage({
64
64
  category: `Plugin-related commands`,
65
65
  description: `build a plugin from sources`,
66
66
  details: `
@@ -1,9 +1,8 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { BaseCommand } from '@yarnpkg/cli';
4
3
  import { Project, Report } from '@yarnpkg/core';
5
4
  import { Usage } from 'clipanion';
6
- export default class PluginDlCommand extends BaseCommand {
5
+ export default class PluginImportCommand extends BaseCommand {
7
6
  static paths: string[][];
8
7
  static usage: Usage;
9
8
  name: string;
@@ -12,7 +12,7 @@ const url_1 = require("url");
12
12
  const vm_1 = require("vm");
13
13
  const list_1 = require("./list");
14
14
  // eslint-disable-next-line arca/no-default-export
15
- class PluginDlCommand extends cli_1.BaseCommand {
15
+ class PluginImportCommand extends cli_1.BaseCommand {
16
16
  constructor() {
17
17
  super(...arguments);
18
18
  this.name = clipanion_1.Option.String();
@@ -50,8 +50,14 @@ class PluginDlCommand extends cli_1.BaseCommand {
50
50
  throw new core_1.ReportError(core_1.MessageName.UNNAMED, `Official plugins only accept strict version references. Use an explicit URL if you wish to download them from another location.`);
51
51
  const identStr = core_2.structUtils.stringifyIdent(locator);
52
52
  const data = await (0, list_1.getAvailablePlugins)(configuration, core_2.YarnVersion);
53
- if (!Object.prototype.hasOwnProperty.call(data, identStr))
54
- throw new core_1.ReportError(core_1.MessageName.PLUGIN_NAME_NOT_FOUND, `Couldn't find a plugin named "${identStr}" on the remote registry. Note that only the plugins referenced on our website (https://github.com/yarnpkg/berry/blob/master/plugins.yml) can be referenced by their name; any other plugin will have to be referenced through its public url (for example https://github.com/yarnpkg/berry/raw/master/packages/plugin-typescript/bin/%40yarnpkg/plugin-typescript.js).`);
53
+ if (!Object.prototype.hasOwnProperty.call(data, identStr)) {
54
+ let message = `Couldn't find a plugin named ${core_2.structUtils.prettyIdent(configuration, locator)} on the remote registry.\n`;
55
+ if (configuration.plugins.has(identStr))
56
+ message += `A plugin named ${core_2.structUtils.prettyIdent(configuration, locator)} is already installed; possibly attempting to import a built-in plugin.`;
57
+ else
58
+ message += `Note that only the plugins referenced on our website (${core_2.formatUtils.pretty(configuration, `https://github.com/yarnpkg/berry/blob/master/plugins.yml`, core_2.formatUtils.Type.URL)}) can be referenced by their name; any other plugin will have to be referenced through its public url (for example ${core_2.formatUtils.pretty(configuration, `https://github.com/yarnpkg/berry/raw/master/packages/plugin-typescript/bin/%40yarnpkg/plugin-typescript.js`, core_2.formatUtils.Type.URL)}).`;
59
+ throw new core_1.ReportError(core_1.MessageName.PLUGIN_NAME_NOT_FOUND, message);
60
+ }
55
61
  pluginSpec = identStr;
56
62
  pluginUrl = data[identStr].url;
57
63
  if (locator.reference !== `unknown`) {
@@ -69,11 +75,11 @@ class PluginDlCommand extends cli_1.BaseCommand {
69
75
  return report.exitCode();
70
76
  }
71
77
  }
72
- exports.default = PluginDlCommand;
73
- PluginDlCommand.paths = [
78
+ exports.default = PluginImportCommand;
79
+ PluginImportCommand.paths = [
74
80
  [`plugin`, `import`],
75
81
  ];
76
- PluginDlCommand.usage = clipanion_1.Command.Usage({
82
+ PluginImportCommand.usage = clipanion_1.Command.Usage({
77
83
  category: `Plugin-related commands`,
78
84
  description: `download a plugin`,
79
85
  details: `
@@ -4,7 +4,7 @@ import { Usage } from 'clipanion';
4
4
  export declare function getAvailablePlugins(configuration: Configuration, version: string | null): Promise<{
5
5
  [k: string]: any;
6
6
  }>;
7
- export default class PluginDlCommand extends BaseCommand {
7
+ export default class PluginListCommand extends BaseCommand {
8
8
  static paths: string[][];
9
9
  static usage: Usage;
10
10
  json: boolean;
@@ -11,12 +11,12 @@ async function getAvailablePlugins(configuration, version) {
11
11
  const data = (0, parsers_1.parseSyml)(raw.toString());
12
12
  return Object.fromEntries(Object.entries(data).filter(([pluginName, pluginData]) => {
13
13
  var _a;
14
- return !version || core_1.semverUtils.satisfiesWithPrereleases(version, (_a = pluginData.range) !== null && _a !== void 0 ? _a : `<4.0.0`);
14
+ return !version || core_1.semverUtils.satisfiesWithPrereleases(version, (_a = pluginData.range) !== null && _a !== void 0 ? _a : `<4.0.0-rc.1`);
15
15
  }));
16
16
  }
17
17
  exports.getAvailablePlugins = getAvailablePlugins;
18
18
  // eslint-disable-next-line arca/no-default-export
19
- class PluginDlCommand extends cli_1.BaseCommand {
19
+ class PluginListCommand extends cli_1.BaseCommand {
20
20
  constructor() {
21
21
  super(...arguments);
22
22
  this.json = clipanion_1.Option.Boolean(`--json`, false, {
@@ -42,11 +42,11 @@ class PluginDlCommand extends cli_1.BaseCommand {
42
42
  return report.exitCode();
43
43
  }
44
44
  }
45
- exports.default = PluginDlCommand;
46
- PluginDlCommand.paths = [
45
+ exports.default = PluginListCommand;
46
+ PluginListCommand.paths = [
47
47
  [`plugin`, `list`],
48
48
  ];
49
- PluginDlCommand.usage = clipanion_1.Command.Usage({
49
+ PluginListCommand.usage = clipanion_1.Command.Usage({
50
50
  category: `Plugin-related commands`,
51
51
  description: `list the available official plugins`,
52
52
  details: `
@@ -1,6 +1,6 @@
1
1
  import { BaseCommand } from '@yarnpkg/cli';
2
2
  import { Usage } from 'clipanion';
3
- export default class PluginListCommand extends BaseCommand {
3
+ export default class PluginRuntimeCommand extends BaseCommand {
4
4
  static paths: string[][];
5
5
  static usage: Usage;
6
6
  json: boolean;
@@ -4,7 +4,7 @@ const cli_1 = require("@yarnpkg/cli");
4
4
  const core_1 = require("@yarnpkg/core");
5
5
  const clipanion_1 = require("clipanion");
6
6
  // eslint-disable-next-line arca/no-default-export
7
- class PluginListCommand extends cli_1.BaseCommand {
7
+ class PluginRuntimeCommand extends cli_1.BaseCommand {
8
8
  constructor() {
9
9
  super(...arguments);
10
10
  this.json = clipanion_1.Option.Boolean(`--json`, false, {
@@ -30,11 +30,11 @@ class PluginListCommand extends cli_1.BaseCommand {
30
30
  return report.exitCode();
31
31
  }
32
32
  }
33
- exports.default = PluginListCommand;
34
- PluginListCommand.paths = [
33
+ exports.default = PluginRuntimeCommand;
34
+ PluginRuntimeCommand.paths = [
35
35
  [`plugin`, `runtime`],
36
36
  ];
37
- PluginListCommand.usage = clipanion_1.Command.Usage({
37
+ PluginRuntimeCommand.usage = clipanion_1.Command.Usage({
38
38
  category: `Plugin-related commands`,
39
39
  description: `list the active plugins`,
40
40
  details: `
@@ -1,6 +1,6 @@
1
1
  import { BaseCommand } from '@yarnpkg/cli';
2
2
  import { Usage } from 'clipanion';
3
- export default class RunCommand extends BaseCommand {
3
+ export default class RebuildCommand extends BaseCommand {
4
4
  static paths: string[][];
5
5
  static usage: Usage;
6
6
  idents: string[];
@@ -5,7 +5,7 @@ const core_1 = require("@yarnpkg/core");
5
5
  const core_2 = require("@yarnpkg/core");
6
6
  const clipanion_1 = require("clipanion");
7
7
  // eslint-disable-next-line arca/no-default-export
8
- class RunCommand extends cli_1.BaseCommand {
8
+ class RebuildCommand extends cli_1.BaseCommand {
9
9
  constructor() {
10
10
  super(...arguments);
11
11
  this.idents = clipanion_1.Option.Rest();
@@ -46,11 +46,11 @@ class RunCommand extends cli_1.BaseCommand {
46
46
  return installReport.exitCode();
47
47
  }
48
48
  }
49
- exports.default = RunCommand;
50
- RunCommand.paths = [
49
+ exports.default = RebuildCommand;
50
+ RebuildCommand.paths = [
51
51
  [`rebuild`],
52
52
  ];
53
- RunCommand.usage = clipanion_1.Command.Usage({
53
+ RebuildCommand.usage = clipanion_1.Command.Usage({
54
54
  description: `rebuild the project's native packages`,
55
55
  details: `
56
56
  This command will automatically cause Yarn to forget about previous compilations of the given packages and to run them again.
@@ -89,7 +89,7 @@ class RemoveCommand extends cli_1.BaseCommand {
89
89
  ? `any`
90
90
  : `this`;
91
91
  if (unreferencedPatterns.length > 0)
92
- throw new clipanion_1.UsageError(`${patterns} ${core_1.formatUtils.prettyList(configuration, unreferencedPatterns, core_1.FormatType.CODE)} ${dont} match any packages referenced by ${which} workspace`);
92
+ throw new clipanion_1.UsageError(`${patterns} ${core_1.formatUtils.prettyList(configuration, unreferencedPatterns, core_1.formatUtils.Type.CODE)} ${dont} match any packages referenced by ${which} workspace`);
93
93
  if (hasChanged) {
94
94
  await configuration.triggerMultipleHooks((hooks) => hooks.afterWorkspaceDependencyRemoval, afterWorkspaceDependencyRemovalList);
95
95
  const report = await core_2.StreamReport.start({
@@ -7,6 +7,7 @@ export default class RunCommand extends BaseCommand {
7
7
  inspectBrk: string | boolean;
8
8
  topLevel: boolean;
9
9
  binariesOnly: boolean;
10
+ require: string | undefined;
10
11
  silent: boolean | undefined;
11
12
  scriptName: string;
12
13
  args: string[];
@@ -22,6 +22,9 @@ class RunCommand extends cli_1.BaseCommand {
22
22
  this.binariesOnly = clipanion_1.Option.Boolean(`-B,--binaries-only`, false, {
23
23
  description: `Ignore any user defined scripts and only check for binaries`,
24
24
  });
25
+ this.require = clipanion_1.Option.String(`--require`, {
26
+ description: `Forwarded to the underlying Node process when executing a binary`,
27
+ });
25
28
  // The v1 used to print the Yarn version header when using "yarn run", which
26
29
  // was messing with the output of things like `--version` & co. We don't do
27
30
  // this anymore, but many workflows use `yarn run --silent` to make sure that
@@ -64,6 +67,8 @@ class RunCommand extends cli_1.BaseCommand {
64
67
  nodeArgs.push(`--inspect-brk`);
65
68
  }
66
69
  }
70
+ if (this.require)
71
+ nodeArgs.push(`--require=${this.require}`);
67
72
  return await core_2.scriptUtils.executePackageAccessibleBinary(effectiveLocator, this.scriptName, this.args, {
68
73
  cwd: this.context.cwd,
69
74
  project,
@@ -1,5 +1,5 @@
1
1
  import { BaseCommand } from '@yarnpkg/cli';
2
- export default class RunCommand extends BaseCommand {
2
+ export default class RunIndexCommand extends BaseCommand {
3
3
  static paths: string[][];
4
4
  execute(): Promise<1 | 0>;
5
5
  }
@@ -5,7 +5,7 @@ const core_1 = require("@yarnpkg/core");
5
5
  const core_2 = require("@yarnpkg/core");
6
6
  const util_1 = require("util");
7
7
  // eslint-disable-next-line arca/no-default-export
8
- class RunCommand extends cli_1.BaseCommand {
8
+ class RunIndexCommand extends cli_1.BaseCommand {
9
9
  async execute() {
10
10
  const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
11
11
  const { project, workspace } = await core_1.Project.find(configuration, this.context.cwd);
@@ -32,7 +32,7 @@ class RunCommand extends cli_1.BaseCommand {
32
32
  return report.exitCode();
33
33
  }
34
34
  }
35
- exports.default = RunCommand;
36
- RunCommand.paths = [
35
+ exports.default = RunIndexCommand;
36
+ RunIndexCommand.paths = [
37
37
  [`run`],
38
38
  ];
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { BaseCommand } from '@yarnpkg/cli';
4
3
  import { Configuration, Report } from '@yarnpkg/core';
5
4
  import { Usage } from 'clipanion';
@@ -40,7 +40,7 @@ class SetVersionCommand extends cli_1.BaseCommand {
40
40
  else if (this.version === `canary`)
41
41
  bundleRef = getRef(`https://repo.yarnpkg.com/{}/packages/yarnpkg-cli/bin/yarn.js`, await resolveTag(configuration, `canary`));
42
42
  else if (this.version === `classic`)
43
- bundleRef = { url: `https://nightly.yarnpkg.com/latest.js`, version: `classic` };
43
+ bundleRef = { url: `https://classic.yarnpkg.com/latest.js`, version: `classic` };
44
44
  else if (this.version.match(/^https?:/))
45
45
  bundleRef = { url: this.version, version: `remote` };
46
46
  else if (this.version.match(/^\.{0,2}[\\/]/) || fslib_1.npath.isAbsolute(this.version))
@@ -61,11 +61,11 @@ class SetVersionCommand extends cli_1.BaseCommand {
61
61
  const fetchBuffer = async () => {
62
62
  const filePrefix = `file://`;
63
63
  if (bundleRef.url.startsWith(filePrefix)) {
64
- report.reportInfo(core_1.MessageName.UNNAMED, `Retrieving ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_1.FormatType.PATH)}`);
64
+ report.reportInfo(core_1.MessageName.UNNAMED, `Retrieving ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_2.formatUtils.Type.PATH)}`);
65
65
  return await fslib_1.xfs.readFilePromise(bundleRef.url.slice(filePrefix.length));
66
66
  }
67
67
  else {
68
- report.reportInfo(core_1.MessageName.UNNAMED, `Downloading ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_1.FormatType.URL)}`);
68
+ report.reportInfo(core_1.MessageName.UNNAMED, `Downloading ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_2.formatUtils.Type.URL)}`);
69
69
  return await core_2.httpUtils.get(bundleRef.url, { configuration });
70
70
  }
71
71
  };
@@ -140,9 +140,9 @@ class UpCommand extends cli_1.BaseCommand {
140
140
  }
141
141
  }
142
142
  if (unreferencedPatterns.length > 1)
143
- throw new clipanion_1.UsageError(`Patterns ${core_3.formatUtils.prettyList(configuration, unreferencedPatterns, core_3.FormatType.CODE)} don't match any packages referenced by any workspace`);
143
+ throw new clipanion_1.UsageError(`Patterns ${core_3.formatUtils.prettyList(configuration, unreferencedPatterns, core_3.formatUtils.Type.CODE)} don't match any packages referenced by any workspace`);
144
144
  if (unreferencedPatterns.length > 0)
145
- throw new clipanion_1.UsageError(`Pattern ${core_3.formatUtils.prettyList(configuration, unreferencedPatterns, core_3.FormatType.CODE)} doesn't match any packages referenced by any workspace`);
145
+ throw new clipanion_1.UsageError(`Pattern ${core_3.formatUtils.prettyList(configuration, unreferencedPatterns, core_3.formatUtils.Type.CODE)} doesn't match any packages referenced by any workspace`);
146
146
  const allSuggestions = await Promise.all(allSuggestionsPromises);
147
147
  const checkReport = await core_3.LightReport.start({
148
148
  configuration,
@@ -223,7 +223,8 @@ class UpCommand extends cli_1.BaseCommand {
223
223
  else {
224
224
  const resolver = configuration.makeResolver();
225
225
  const resolveOptions = { project, resolver };
226
- const bound = resolver.bindDescriptor(current, workspace.anchoredLocator, resolveOptions);
226
+ const normalizedDependency = configuration.normalizeDependency(current);
227
+ const bound = resolver.bindDescriptor(normalizedDependency, workspace.anchoredLocator, resolveOptions);
227
228
  project.forgetResolution(bound);
228
229
  }
229
230
  }
@@ -5,6 +5,7 @@ export default class WorkspacesListCommand extends BaseCommand {
5
5
  static usage: Usage;
6
6
  since: string | boolean | undefined;
7
7
  recursive: boolean;
8
+ noPrivate: boolean | undefined;
8
9
  verbose: boolean;
9
10
  json: boolean;
10
11
  execute(): Promise<1 | 0>;
@@ -15,6 +15,9 @@ class WorkspacesListCommand extends cli_1.BaseCommand {
15
15
  this.recursive = clipanion_1.Option.Boolean(`-R,--recursive`, false, {
16
16
  description: `Find packages via dependencies/devDependencies instead of using the workspaces field`,
17
17
  });
18
+ this.noPrivate = clipanion_1.Option.Boolean(`--no-private`, {
19
+ description: `Exclude workspaces that have the private field set to true`,
20
+ });
18
21
  this.verbose = clipanion_1.Option.Boolean(`-v,--verbose`, false, {
19
22
  description: `Also return the cross-dependencies between workspaces`,
20
23
  });
@@ -40,6 +43,8 @@ class WorkspacesListCommand extends cli_1.BaseCommand {
40
43
  workspaces.add(dependent);
41
44
  for (const workspace of workspaces) {
42
45
  const { manifest } = workspace;
46
+ if (manifest.private && this.noPrivate)
47
+ continue;
43
48
  let extra;
44
49
  if (this.verbose) {
45
50
  const workspaceDependencies = new Set();
@@ -93,6 +98,8 @@ WorkspacesListCommand.usage = clipanion_1.Command.Usage({
93
98
 
94
99
  - If \`-R,--recursive\` is set, Yarn will find workspaces to run the command on by recursively evaluating \`dependencies\` and \`devDependencies\` fields, instead of looking at the \`workspaces\` fields.
95
100
 
101
+ - If \`--no-private\` is set, Yarn will not list any workspaces that have the \`private\` field set to \`true\`.
102
+
96
103
  - If both the \`-v,--verbose\` and \`--json\` options are set, Yarn will also return the cross-dependencies between each workspaces (useful when you wish to automatically generate Buck / Bazel rules).
97
104
  `,
98
105
  });
@@ -109,7 +109,6 @@ async function dedupe(project, { strategy, patterns, cache, report }) {
109
109
  fetcher,
110
110
  project,
111
111
  report: throwReport,
112
- skipIntegrityCheck: true,
113
112
  cacheOptions: {
114
113
  skipIntegrityCheck: true,
115
114
  },
package/lib/index.d.ts CHANGED
@@ -1,8 +1,81 @@
1
1
  import { Descriptor, Plugin, Package, formatUtils } from '@yarnpkg/core';
2
2
  import { Workspace } from '@yarnpkg/core';
3
+ import AddCommand from './commands/add';
4
+ import BinCommand from './commands/bin';
5
+ import CacheCleanCommand from './commands/cache/clean';
6
+ import ConfigGetCommand from './commands/config/get';
7
+ import ConfigSetCommand from './commands/config/set';
8
+ import ConfigUnsetCommand from './commands/config/unset';
9
+ import ConfigCommand from './commands/config';
10
+ import DedupeCommand from './commands/dedupe';
11
+ import ClipanionCommand from './commands/entries/clipanion';
12
+ import HelpCommand from './commands/entries/help';
13
+ import EntryCommand from './commands/entries/run';
14
+ import VersionCommand from './commands/entries/version';
15
+ import ExecCommand from './commands/exec';
16
+ import ExplainPeerRequirementsCommand from './commands/explain/peerRequirements';
17
+ import ExplainCommand from './commands/explain';
18
+ import InfoCommand from './commands/info';
19
+ import YarnCommand from './commands/install';
20
+ import LinkCommand from './commands/link';
21
+ import NodeCommand from './commands/node';
22
+ import PluginImportSourcesCommand from './commands/plugin/import/sources';
23
+ import PluginImportCommand from './commands/plugin/import';
24
+ import PluginListCommand from './commands/plugin/list';
25
+ import PluginRemoveCommand from './commands/plugin/remove';
26
+ import PluginRuntimeCommand from './commands/plugin/runtime';
27
+ import RebuildCommand from './commands/rebuild';
28
+ import RemoveCommand from './commands/remove';
29
+ import RunIndexCommand from './commands/runIndex';
30
+ import RunCommand from './commands/run';
31
+ import SetResolutionCommand from './commands/set/resolution';
32
+ import SetVersionSourcesCommand from './commands/set/version/sources';
33
+ import SetVersionCommand from './commands/set/version';
34
+ import UnlinkCommand from './commands/unlink';
35
+ import UpCommand from './commands/up';
36
+ import WhyCommand from './commands/why';
37
+ import WorkspacesListCommand from './commands/workspaces/list';
38
+ import WorkspaceCommand from './commands/workspace';
3
39
  import * as dedupeUtils from './dedupeUtils';
4
40
  import * as suggestUtils from './suggestUtils';
5
- export { dedupeUtils, suggestUtils, };
41
+ export { AddCommand };
42
+ export { BinCommand };
43
+ export { CacheCleanCommand };
44
+ export { ConfigGetCommand };
45
+ export { ConfigSetCommand };
46
+ export { ConfigUnsetCommand };
47
+ export { ConfigCommand };
48
+ export { DedupeCommand };
49
+ export { ClipanionCommand };
50
+ export { HelpCommand };
51
+ export { EntryCommand };
52
+ export { VersionCommand };
53
+ export { ExecCommand };
54
+ export { ExplainPeerRequirementsCommand };
55
+ export { ExplainCommand };
56
+ export { InfoCommand };
57
+ export { YarnCommand };
58
+ export { LinkCommand };
59
+ export { NodeCommand };
60
+ export { PluginImportSourcesCommand };
61
+ export { PluginImportCommand };
62
+ export { PluginListCommand };
63
+ export { PluginRemoveCommand };
64
+ export { PluginRuntimeCommand };
65
+ export { RebuildCommand };
66
+ export { RemoveCommand };
67
+ export { RunIndexCommand };
68
+ export { RunCommand };
69
+ export { SetResolutionCommand };
70
+ export { SetVersionSourcesCommand };
71
+ export { SetVersionCommand };
72
+ export { UnlinkCommand };
73
+ export { UpCommand };
74
+ export { WhyCommand };
75
+ export { WorkspacesListCommand };
76
+ export { WorkspaceCommand };
77
+ export { dedupeUtils };
78
+ export { suggestUtils };
6
79
  export interface Hooks {
7
80
  /**
8
81
  * Called when a new dependency is added to a workspace. Note that this hook
package/lib/index.js CHANGED
@@ -1,45 +1,81 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.suggestUtils = exports.dedupeUtils = void 0;
3
+ exports.suggestUtils = exports.dedupeUtils = exports.WorkspaceCommand = exports.WorkspacesListCommand = exports.WhyCommand = exports.UpCommand = exports.UnlinkCommand = exports.SetVersionCommand = exports.SetVersionSourcesCommand = exports.SetResolutionCommand = exports.RunCommand = exports.RunIndexCommand = exports.RemoveCommand = exports.RebuildCommand = exports.PluginRuntimeCommand = exports.PluginRemoveCommand = exports.PluginListCommand = exports.PluginImportCommand = exports.PluginImportSourcesCommand = exports.NodeCommand = exports.LinkCommand = exports.YarnCommand = exports.InfoCommand = exports.ExplainCommand = exports.ExplainPeerRequirementsCommand = exports.ExecCommand = exports.VersionCommand = exports.EntryCommand = exports.HelpCommand = exports.ClipanionCommand = exports.DedupeCommand = exports.ConfigCommand = exports.ConfigUnsetCommand = exports.ConfigSetCommand = exports.ConfigGetCommand = exports.CacheCleanCommand = exports.BinCommand = exports.AddCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@yarnpkg/core");
6
6
  const ci_info_1 = require("ci-info");
7
7
  const add_1 = tslib_1.__importDefault(require("./commands/add"));
8
+ exports.AddCommand = add_1.default;
8
9
  const bin_1 = tslib_1.__importDefault(require("./commands/bin"));
10
+ exports.BinCommand = bin_1.default;
9
11
  const clean_1 = tslib_1.__importDefault(require("./commands/cache/clean"));
12
+ exports.CacheCleanCommand = clean_1.default;
10
13
  const get_1 = tslib_1.__importDefault(require("./commands/config/get"));
14
+ exports.ConfigGetCommand = get_1.default;
11
15
  const set_1 = tslib_1.__importDefault(require("./commands/config/set"));
16
+ exports.ConfigSetCommand = set_1.default;
12
17
  const unset_1 = tslib_1.__importDefault(require("./commands/config/unset"));
18
+ exports.ConfigUnsetCommand = unset_1.default;
13
19
  const config_1 = tslib_1.__importDefault(require("./commands/config"));
20
+ exports.ConfigCommand = config_1.default;
14
21
  const dedupe_1 = tslib_1.__importDefault(require("./commands/dedupe"));
22
+ exports.DedupeCommand = dedupe_1.default;
15
23
  const clipanion_1 = tslib_1.__importDefault(require("./commands/entries/clipanion"));
24
+ exports.ClipanionCommand = clipanion_1.default;
16
25
  const help_1 = tslib_1.__importDefault(require("./commands/entries/help"));
26
+ exports.HelpCommand = help_1.default;
17
27
  const run_1 = tslib_1.__importDefault(require("./commands/entries/run"));
28
+ exports.EntryCommand = run_1.default;
18
29
  const version_1 = tslib_1.__importDefault(require("./commands/entries/version"));
30
+ exports.VersionCommand = version_1.default;
19
31
  const exec_1 = tslib_1.__importDefault(require("./commands/exec"));
32
+ exports.ExecCommand = exec_1.default;
20
33
  const peerRequirements_1 = tslib_1.__importDefault(require("./commands/explain/peerRequirements"));
34
+ exports.ExplainPeerRequirementsCommand = peerRequirements_1.default;
21
35
  const explain_1 = tslib_1.__importDefault(require("./commands/explain"));
36
+ exports.ExplainCommand = explain_1.default;
22
37
  const info_1 = tslib_1.__importDefault(require("./commands/info"));
38
+ exports.InfoCommand = info_1.default;
23
39
  const install_1 = tslib_1.__importDefault(require("./commands/install"));
40
+ exports.YarnCommand = install_1.default;
24
41
  const link_1 = tslib_1.__importDefault(require("./commands/link"));
42
+ exports.LinkCommand = link_1.default;
25
43
  const node_1 = tslib_1.__importDefault(require("./commands/node"));
44
+ exports.NodeCommand = node_1.default;
26
45
  const sources_1 = tslib_1.__importDefault(require("./commands/plugin/import/sources"));
46
+ exports.PluginImportSourcesCommand = sources_1.default;
27
47
  const import_1 = tslib_1.__importDefault(require("./commands/plugin/import"));
48
+ exports.PluginImportCommand = import_1.default;
28
49
  const list_1 = tslib_1.__importDefault(require("./commands/plugin/list"));
50
+ exports.PluginListCommand = list_1.default;
29
51
  const remove_1 = tslib_1.__importDefault(require("./commands/plugin/remove"));
52
+ exports.PluginRemoveCommand = remove_1.default;
30
53
  const runtime_1 = tslib_1.__importDefault(require("./commands/plugin/runtime"));
54
+ exports.PluginRuntimeCommand = runtime_1.default;
31
55
  const rebuild_1 = tslib_1.__importDefault(require("./commands/rebuild"));
56
+ exports.RebuildCommand = rebuild_1.default;
32
57
  const remove_2 = tslib_1.__importDefault(require("./commands/remove"));
58
+ exports.RemoveCommand = remove_2.default;
33
59
  const runIndex_1 = tslib_1.__importDefault(require("./commands/runIndex"));
60
+ exports.RunIndexCommand = runIndex_1.default;
34
61
  const run_2 = tslib_1.__importDefault(require("./commands/run"));
62
+ exports.RunCommand = run_2.default;
35
63
  const resolution_1 = tslib_1.__importDefault(require("./commands/set/resolution"));
64
+ exports.SetResolutionCommand = resolution_1.default;
36
65
  const sources_2 = tslib_1.__importDefault(require("./commands/set/version/sources"));
66
+ exports.SetVersionSourcesCommand = sources_2.default;
37
67
  const version_2 = tslib_1.__importDefault(require("./commands/set/version"));
68
+ exports.SetVersionCommand = version_2.default;
38
69
  const unlink_1 = tslib_1.__importDefault(require("./commands/unlink"));
70
+ exports.UnlinkCommand = unlink_1.default;
39
71
  const up_1 = tslib_1.__importDefault(require("./commands/up"));
72
+ exports.UpCommand = up_1.default;
40
73
  const why_1 = tslib_1.__importDefault(require("./commands/why"));
74
+ exports.WhyCommand = why_1.default;
41
75
  const list_2 = tslib_1.__importDefault(require("./commands/workspaces/list"));
76
+ exports.WorkspacesListCommand = list_2.default;
42
77
  const workspace_1 = tslib_1.__importDefault(require("./commands/workspace"));
78
+ exports.WorkspaceCommand = workspace_1.default;
43
79
  const dedupeUtils = tslib_1.__importStar(require("./dedupeUtils"));
44
80
  exports.dedupeUtils = dedupeUtils;
45
81
  const suggestUtils = tslib_1.__importStar(require("./suggestUtils"));
@@ -88,9 +88,15 @@ export declare function getSuggestedDescriptors(request: Descriptor, { project,
88
88
  strategies: Array<Strategy>;
89
89
  maxResults?: number;
90
90
  }): Promise<Results>;
91
- export declare function fetchDescriptorFrom(ident: Ident, range: string, { project, cache, workspace, preserveModifier }: {
91
+ export declare type FetchDescriptorFromOptions = {
92
92
  project: Project;
93
93
  cache: Cache;
94
94
  workspace: Workspace;
95
+ } & ({
95
96
  preserveModifier?: boolean | string;
96
- }): Promise<Descriptor | null>;
97
+ modifier?: undefined;
98
+ } | {
99
+ preserveModifier?: undefined;
100
+ modifier: Modifier;
101
+ });
102
+ export declare function fetchDescriptorFrom(ident: Ident, range: string, { project, cache, workspace, preserveModifier, modifier }: FetchDescriptorFromOptions): Promise<Descriptor | null>;
@@ -169,7 +169,7 @@ async function getSuggestedDescriptors(request, { project, workspace, cache, tar
169
169
  if (!(maxResults >= 0))
170
170
  throw new Error(`Invalid maxResults (${maxResults})`);
171
171
  const [requestRange, requestTag] = request.range !== `unknown`
172
- ? fixed || semver_1.default.validRange(request.range) || !request.range.match(/^[a-z0-9._-]+$/i)
172
+ ? fixed || core_2.semverUtils.validRange(request.range) || !request.range.match(/^[a-z0-9._-]+$/i)
173
173
  ? [request.range, `latest`]
174
174
  : [`unknown`, request.range]
175
175
  : [`unknown`, `latest`];
@@ -285,9 +285,8 @@ async function getSuggestedDescriptors(request, { project, workspace, cache, tar
285
285
  });
286
286
  }
287
287
  else {
288
- let latest = await fetchDescriptorFrom(request, `${project.configuration.get(`defaultProtocol`)}${requestTag}`, { project, cache, workspace, preserveModifier: false });
288
+ const latest = await fetchDescriptorFrom(request, requestTag, { project, cache, workspace, modifier });
289
289
  if (latest) {
290
- latest = applyModifier(latest, modifier);
291
290
  suggested.push({
292
291
  descriptor: latest,
293
292
  name: `Use ${core_2.structUtils.prettyDescriptor(project.configuration, latest)}`,
@@ -306,12 +305,12 @@ async function getSuggestedDescriptors(request, { project, workspace, cache, tar
306
305
  };
307
306
  }
308
307
  exports.getSuggestedDescriptors = getSuggestedDescriptors;
309
- async function fetchDescriptorFrom(ident, range, { project, cache, workspace, preserveModifier = true }) {
310
- const latestDescriptor = core_2.structUtils.makeDescriptor(ident, range);
308
+ async function fetchDescriptorFrom(ident, range, { project, cache, workspace, preserveModifier = true, modifier }) {
309
+ const latestDescriptor = project.configuration.normalizeDependency(core_2.structUtils.makeDescriptor(ident, range));
311
310
  const report = new core_1.ThrowReport();
312
311
  const fetcher = project.configuration.makeFetcher();
313
312
  const resolver = project.configuration.makeResolver();
314
- const fetchOptions = { project, fetcher, cache, checksums: project.storedChecksums, report, cacheOptions: { skipIntegrityCheck: true }, skipIntegrityCheck: true };
313
+ const fetchOptions = { project, fetcher, cache, checksums: project.storedChecksums, report, cacheOptions: { skipIntegrityCheck: true } };
315
314
  const resolveOptions = { ...fetchOptions, resolver, fetchOptions };
316
315
  // The descriptor has to be bound for the resolvers that need a parent locator. (e.g. FileResolver)
317
316
  // If we didn't bind it, `yarn add ./folder` wouldn't work.
@@ -324,12 +323,32 @@ async function fetchDescriptorFrom(ident, range, { project, cache, workspace, pr
324
323
  let { protocol, source, params, selector } = core_2.structUtils.parseRange(core_2.structUtils.convertToManifestRange(bestLocator.reference));
325
324
  if (protocol === project.configuration.get(`defaultProtocol`))
326
325
  protocol = null;
327
- if (semver_1.default.valid(selector) && preserveModifier !== false) {
328
- const referenceRange = typeof preserveModifier === `string`
329
- ? preserveModifier
330
- : latestDescriptor.range;
331
- const modifier = extractRangeModifier(referenceRange, { project });
332
- selector = modifier + selector;
326
+ if (semver_1.default.valid(selector)) {
327
+ const rawSelector = selector;
328
+ if (typeof modifier !== `undefined`) {
329
+ selector = modifier + selector;
330
+ }
331
+ else if (preserveModifier !== false) {
332
+ const referenceRange = typeof preserveModifier === `string`
333
+ ? preserveModifier
334
+ : latestDescriptor.range;
335
+ const modifier = extractRangeModifier(referenceRange, { project });
336
+ selector = modifier + selector;
337
+ }
338
+ const screeningDescriptor = core_2.structUtils.makeDescriptor(bestLocator, core_2.structUtils.makeRange({ protocol, source, params, selector }));
339
+ const screeningLocators = await resolver.getCandidates(project.configuration.normalizeDependency(screeningDescriptor), {}, resolveOptions);
340
+ // If turning 1.0.0 into ^1.0.0 would cause it to resolve to something else
341
+ // (for example 1.1.0), then we don't add the modifier.
342
+ //
343
+ // This is to account for "weird" release strategies where things like
344
+ // prereleases are released as older versions than the latest available
345
+ // ones.
346
+ //
347
+ // Ex 1: https://github.com/parcel-bundler/parcel/issues/8010
348
+ // Ex 2: https://github.com/sveltejs/kit/discussions/4645
349
+ if (screeningLocators.length !== 1) {
350
+ selector = rawSelector;
351
+ }
333
352
  }
334
353
  return core_2.structUtils.makeDescriptor(bestLocator, core_2.structUtils.makeRange({ protocol, source, params, selector }));
335
354
  }
package/package.json CHANGED
@@ -1,32 +1,36 @@
1
1
  {
2
2
  "name": "@yarnpkg/plugin-essentials",
3
- "version": "4.0.0-rc.2",
3
+ "version": "4.0.0-rc.21",
4
4
  "license": "BSD-2-Clause",
5
5
  "main": "./lib/index.js",
6
+ "exports": {
7
+ ".": "./lib/index.js",
8
+ "./package.json": "./package.json"
9
+ },
6
10
  "dependencies": {
7
- "@yarnpkg/fslib": "^3.0.0-rc.2",
8
- "@yarnpkg/parsers": "^3.0.0-rc.2",
11
+ "@yarnpkg/fslib": "^3.0.0-rc.21",
12
+ "@yarnpkg/parsers": "^3.0.0-rc.21",
9
13
  "ci-info": "^3.2.0",
10
14
  "clipanion": "^3.2.0-rc.10",
11
15
  "enquirer": "^2.3.6",
12
16
  "lodash": "^4.17.15",
13
17
  "micromatch": "^4.0.2",
14
18
  "semver": "^7.1.2",
15
- "tslib": "^1.13.0",
19
+ "tslib": "^2.4.0",
16
20
  "typanion": "^3.3.0"
17
21
  },
18
22
  "peerDependencies": {
19
- "@yarnpkg/cli": "^4.0.0-rc.2",
20
- "@yarnpkg/core": "^4.0.0-rc.2",
21
- "@yarnpkg/plugin-git": "^3.0.0-rc.2"
23
+ "@yarnpkg/cli": "^4.0.0-rc.21",
24
+ "@yarnpkg/core": "^4.0.0-rc.21",
25
+ "@yarnpkg/plugin-git": "^3.0.0-rc.21"
22
26
  },
23
27
  "devDependencies": {
24
28
  "@types/lodash": "^4.14.136",
25
29
  "@types/micromatch": "^4.0.1",
26
30
  "@types/semver": "^7.1.0",
27
- "@yarnpkg/cli": "^4.0.0-rc.2",
28
- "@yarnpkg/core": "^4.0.0-rc.2",
29
- "@yarnpkg/plugin-git": "^3.0.0-rc.2"
31
+ "@yarnpkg/cli": "^4.0.0-rc.21",
32
+ "@yarnpkg/core": "^4.0.0-rc.21",
33
+ "@yarnpkg/plugin-git": "^3.0.0-rc.21"
30
34
  },
31
35
  "repository": {
32
36
  "type": "git",
@@ -39,7 +43,10 @@
39
43
  },
40
44
  "publishConfig": {
41
45
  "main": "./lib/index.js",
42
- "typings": "./lib/index.d.ts"
46
+ "exports": {
47
+ ".": "./lib/index.js",
48
+ "./package.json": "./package.json"
49
+ }
43
50
  },
44
51
  "files": [
45
52
  "/lib/**/*"
@@ -47,6 +54,5 @@
47
54
  "engines": {
48
55
  "node": ">=14.15.0"
49
56
  },
50
- "stableVersion": "3.2.0",
51
- "typings": "./lib/index.d.ts"
57
+ "stableVersion": "3.2.0"
52
58
  }