@yarnpkg/plugin-essentials 4.0.0-rc.5 → 4.0.0-rc.50

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.
Files changed (69) hide show
  1. package/lib/commands/add.d.ts +1 -1
  2. package/lib/commands/add.js +34 -25
  3. package/lib/commands/bin.d.ts +1 -1
  4. package/lib/commands/bin.js +1 -1
  5. package/lib/commands/cache/clean.d.ts +1 -1
  6. package/lib/commands/cache/clean.js +1 -1
  7. package/lib/commands/config/get.d.ts +1 -1
  8. package/lib/commands/config/get.js +1 -1
  9. package/lib/commands/config/set.d.ts +1 -1
  10. package/lib/commands/config/set.js +1 -1
  11. package/lib/commands/config/unset.d.ts +1 -1
  12. package/lib/commands/config/unset.js +1 -1
  13. package/lib/commands/config.d.ts +1 -1
  14. package/lib/commands/config.js +1 -1
  15. package/lib/commands/dedupe.d.ts +1 -1
  16. package/lib/commands/dedupe.js +7 -8
  17. package/lib/commands/entries/clipanion.js +1 -1
  18. package/lib/commands/entries/help.js +1 -1
  19. package/lib/commands/entries/version.js +1 -1
  20. package/lib/commands/exec.js +1 -1
  21. package/lib/commands/explain/peerRequirements.d.ts +2 -2
  22. package/lib/commands/explain/peerRequirements.js +4 -6
  23. package/lib/commands/explain.js +1 -1
  24. package/lib/commands/info.js +8 -12
  25. package/lib/commands/install.d.ts +1 -1
  26. package/lib/commands/install.js +188 -107
  27. package/lib/commands/link.d.ts +2 -2
  28. package/lib/commands/link.js +36 -32
  29. package/lib/commands/node.js +1 -1
  30. package/lib/commands/plugin/check.d.ts +8 -0
  31. package/lib/commands/plugin/check.js +61 -0
  32. package/lib/commands/plugin/import/sources.d.ts +3 -3
  33. package/lib/commands/plugin/import/sources.js +5 -5
  34. package/lib/commands/plugin/import.d.ts +5 -4
  35. package/lib/commands/plugin/import.js +15 -28
  36. package/lib/commands/plugin/list.d.ts +2 -2
  37. package/lib/commands/plugin/list.js +5 -6
  38. package/lib/commands/plugin/remove.d.ts +1 -1
  39. package/lib/commands/plugin/remove.js +14 -13
  40. package/lib/commands/plugin/runtime.d.ts +2 -2
  41. package/lib/commands/plugin/runtime.js +4 -4
  42. package/lib/commands/rebuild.d.ts +2 -2
  43. package/lib/commands/rebuild.js +10 -10
  44. package/lib/commands/remove.d.ts +1 -1
  45. package/lib/commands/remove.js +7 -8
  46. package/lib/commands/run.js +1 -1
  47. package/lib/commands/runIndex.d.ts +2 -2
  48. package/lib/commands/runIndex.js +3 -3
  49. package/lib/commands/set/resolution.d.ts +1 -1
  50. package/lib/commands/set/resolution.js +4 -6
  51. package/lib/commands/set/version/sources.d.ts +3 -2
  52. package/lib/commands/set/version/sources.js +21 -12
  53. package/lib/commands/set/version.d.ts +2 -3
  54. package/lib/commands/set/version.js +20 -16
  55. package/lib/commands/unlink.d.ts +1 -1
  56. package/lib/commands/unlink.js +7 -8
  57. package/lib/commands/up.d.ts +3 -3
  58. package/lib/commands/up.js +19 -17
  59. package/lib/commands/why.js +5 -13
  60. package/lib/commands/workspace.js +2 -5
  61. package/lib/commands/workspaces/list.d.ts +2 -1
  62. package/lib/commands/workspaces/list.js +8 -1
  63. package/lib/dedupeUtils.d.ts +3 -3
  64. package/lib/dedupeUtils.js +3 -5
  65. package/lib/index.d.ts +76 -1
  66. package/lib/index.js +40 -1
  67. package/lib/suggestUtils.d.ts +4 -4
  68. package/lib/suggestUtils.js +10 -10
  69. package/package.json +23 -17
@@ -22,8 +22,15 @@ class SetVersionCommand extends cli_1.BaseCommand {
22
22
  }
23
23
  async execute() {
24
24
  const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
25
- if (configuration.get(`yarnPath`) && this.onlyIfNeeded)
26
- return 0;
25
+ if (this.onlyIfNeeded && configuration.get(`yarnPath`)) {
26
+ const yarnPathSource = configuration.sources.get(`yarnPath`);
27
+ if (!yarnPathSource)
28
+ throw new Error(`Assertion failed: Expected 'yarnPath' to have a source`);
29
+ const projectCwd = configuration.projectCwd ?? configuration.startingCwd;
30
+ if (fslib_1.ppath.contains(projectCwd, yarnPathSource)) {
31
+ return 0;
32
+ }
33
+ }
27
34
  const getBundlePath = () => {
28
35
  if (typeof core_1.YarnVersion === `undefined`)
29
36
  throw new clipanion_1.UsageError(`The --install flag can only be used without explicit version specifier from the Yarn CLI`);
@@ -34,13 +41,13 @@ class SetVersionCommand extends cli_1.BaseCommand {
34
41
  return { version, url: url.replace(/\{\}/g, version) };
35
42
  };
36
43
  if (this.version === `self`)
37
- bundleRef = { url: getBundlePath(), version: core_1.YarnVersion !== null && core_1.YarnVersion !== void 0 ? core_1.YarnVersion : `self` };
44
+ bundleRef = { url: getBundlePath(), version: core_1.YarnVersion ?? `self` };
38
45
  else if (this.version === `latest` || this.version === `berry` || this.version === `stable`)
39
46
  bundleRef = getRef(`https://repo.yarnpkg.com/{}/packages/yarnpkg-cli/bin/yarn.js`, await resolveTag(configuration, `stable`));
40
47
  else if (this.version === `canary`)
41
48
  bundleRef = getRef(`https://repo.yarnpkg.com/{}/packages/yarnpkg-cli/bin/yarn.js`, await resolveTag(configuration, `canary`));
42
49
  else if (this.version === `classic`)
43
- bundleRef = { url: `https://nightly.yarnpkg.com/latest.js`, version: `classic` };
50
+ bundleRef = { url: `https://classic.yarnpkg.com/latest.js`, version: `classic` };
44
51
  else if (this.version.match(/^https?:/))
45
52
  bundleRef = { url: this.version, version: `remote` };
46
53
  else if (this.version.match(/^\.{0,2}[\\/]/) || fslib_1.npath.isAbsolute(this.version))
@@ -61,11 +68,11 @@ class SetVersionCommand extends cli_1.BaseCommand {
61
68
  const fetchBuffer = async () => {
62
69
  const filePrefix = `file://`;
63
70
  if (bundleRef.url.startsWith(filePrefix)) {
64
- report.reportInfo(core_1.MessageName.UNNAMED, `Retrieving ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_1.FormatType.PATH)}`);
71
+ report.reportInfo(core_1.MessageName.UNNAMED, `Retrieving ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_2.formatUtils.Type.PATH)}`);
65
72
  return await fslib_1.xfs.readFilePromise(bundleRef.url.slice(filePrefix.length));
66
73
  }
67
74
  else {
68
- report.reportInfo(core_1.MessageName.UNNAMED, `Downloading ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_1.FormatType.URL)}`);
75
+ report.reportInfo(core_1.MessageName.UNNAMED, `Downloading ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_2.formatUtils.Type.URL)}`);
69
76
  return await core_2.httpUtils.get(bundleRef.url, { configuration });
70
77
  }
71
78
  };
@@ -74,7 +81,6 @@ class SetVersionCommand extends cli_1.BaseCommand {
74
81
  return report.exitCode();
75
82
  }
76
83
  }
77
- exports.default = SetVersionCommand;
78
84
  SetVersionCommand.paths = [
79
85
  [`set`, `version`],
80
86
  ];
@@ -85,7 +91,7 @@ SetVersionCommand.usage = clipanion_1.Command.Usage({
85
91
 
86
92
  By default it only will set the \`packageManager\` field at the root of your project, but if the referenced release cannot be represented this way, if you already have \`yarnPath\` configured, or if you set the \`--yarn-path\` command line flag, then the release will also be downloaded from the Yarn GitHub repository, stored inside your project, and referenced via the \`yarnPath\` settings from your project \`.yarnrc.yml\` file.
87
93
 
88
- A very good use case for this command is to enforce the version of Yarn used by the any single member of your team inside a same project - by doing this you ensure that you have control on Yarn upgrades and downgrades (including on your deployment servers), and get rid of most of the headaches related to someone using a slightly different version and getting a different behavior than you.
94
+ A very good use case for this command is to enforce the version of Yarn used by any single member of your team inside the same project - by doing this you ensure that you have control over Yarn upgrades and downgrades (including on your deployment servers), and get rid of most of the headaches related to someone using a slightly different version and getting different behavior.
89
95
 
90
96
  The version specifier can be:
91
97
 
@@ -131,6 +137,7 @@ SetVersionCommand.usage = clipanion_1.Command.Usage({
131
137
  `$0 set version self`,
132
138
  ]],
133
139
  });
140
+ exports.default = SetVersionCommand;
134
141
  async function resolveRange(configuration, request) {
135
142
  const data = await core_2.httpUtils.get(`https://repo.yarnpkg.com/tags`, { configuration, jsonResponse: true });
136
143
  const candidates = data.tags.filter(version => core_2.semverUtils.satisfiesWithPrereleases(version, request));
@@ -148,7 +155,6 @@ async function resolveTag(configuration, request) {
148
155
  }
149
156
  exports.resolveTag = resolveTag;
150
157
  async function setVersion(configuration, bundleVersion, fetchBuffer, { report, useYarnPath }) {
151
- var _a;
152
158
  let bundleBuffer;
153
159
  const ensureBuffer = async () => {
154
160
  if (typeof bundleBuffer === `undefined`)
@@ -162,7 +168,7 @@ async function setVersion(configuration, bundleVersion, fetchBuffer, { report, u
162
168
  await fslib_1.xfs.writeFilePromise(temporaryPath, bundleBuffer);
163
169
  const { stdout } = await core_2.execUtils.execvp(process.execPath, [fslib_1.npath.fromPortablePath(temporaryPath), `--version`], {
164
170
  cwd: tmpDir,
165
- env: { ...process.env, YARN_IGNORE_PATH: `1` },
171
+ env: { ...configuration.env, YARN_IGNORE_PATH: `1` },
166
172
  });
167
173
  bundleVersion = stdout.trim();
168
174
  if (!semver_1.default.valid(bundleVersion)) {
@@ -170,7 +176,7 @@ async function setVersion(configuration, bundleVersion, fetchBuffer, { report, u
170
176
  }
171
177
  });
172
178
  }
173
- const projectCwd = (_a = configuration.projectCwd) !== null && _a !== void 0 ? _a : configuration.startingCwd;
179
+ const projectCwd = configuration.projectCwd ?? configuration.startingCwd;
174
180
  const releaseFolder = fslib_1.ppath.resolve(projectCwd, `.yarn/releases`);
175
181
  const absolutePath = fslib_1.ppath.resolve(releaseFolder, `yarn-${bundleVersion}.cjs`);
176
182
  const displayPath = fslib_1.ppath.relative(configuration.startingCwd, absolutePath);
@@ -193,11 +199,9 @@ async function setVersion(configuration, bundleVersion, fetchBuffer, { report, u
193
199
  await fslib_1.xfs.removePromise(fslib_1.ppath.dirname(absolutePath));
194
200
  await fslib_1.xfs.mkdirPromise(fslib_1.ppath.dirname(absolutePath), { recursive: true });
195
201
  await fslib_1.xfs.writeFilePromise(absolutePath, bundleBuffer, { mode: 0o755 });
196
- if (!yarnPath || fslib_1.ppath.contains(releaseFolder, yarnPath)) {
197
- await core_1.Configuration.updateConfiguration(projectCwd, {
198
- yarnPath: fslib_1.ppath.relative(projectCwd, absolutePath),
199
- });
200
- }
202
+ await core_1.Configuration.updateConfiguration(projectCwd, {
203
+ yarnPath: fslib_1.ppath.relative(projectCwd, absolutePath),
204
+ });
201
205
  }
202
206
  else {
203
207
  await fslib_1.xfs.removePromise(fslib_1.ppath.dirname(absolutePath));
@@ -5,5 +5,5 @@ export default class UnlinkCommand extends BaseCommand {
5
5
  static usage: Usage;
6
6
  all: boolean;
7
7
  leadingArguments: string[];
8
- execute(): Promise<1 | 0>;
8
+ execute(): Promise<0 | 1>;
9
9
  }
@@ -41,7 +41,7 @@ class UnlinkCommand extends cli_1.BaseCommand {
41
41
  if (this.all) {
42
42
  for (const workspace of project2.workspaces)
43
43
  if (workspace.manifest.name)
44
- workspacesToUnlink.add(core_1.structUtils.stringifyIdent(workspace.locator));
44
+ workspacesToUnlink.add(core_1.structUtils.stringifyIdent(workspace.anchoredLocator));
45
45
  if (workspacesToUnlink.size === 0) {
46
46
  throw new clipanion_1.UsageError(`No workspace found to be unlinked in the target project`);
47
47
  }
@@ -49,7 +49,7 @@ class UnlinkCommand extends cli_1.BaseCommand {
49
49
  else {
50
50
  if (!workspace2.manifest.name)
51
51
  throw new clipanion_1.UsageError(`The target workspace doesn't have a name and thus cannot be unlinked`);
52
- workspacesToUnlink.add(core_1.structUtils.stringifyIdent(workspace2.locator));
52
+ workspacesToUnlink.add(core_1.structUtils.stringifyIdent(workspace2.anchoredLocator));
53
53
  }
54
54
  }
55
55
  else {
@@ -63,16 +63,14 @@ class UnlinkCommand extends cli_1.BaseCommand {
63
63
  topLevelWorkspace.manifest.resolutions = topLevelWorkspace.manifest.resolutions.filter(({ pattern }) => {
64
64
  return !workspacesToUnlink.has(pattern.descriptor.fullName);
65
65
  });
66
- const report = await core_1.StreamReport.start({
67
- configuration,
66
+ return await project.installWithNewReport({
68
67
  stdout: this.context.stdout,
69
- }, async (report) => {
70
- await project.install({ cache, report });
68
+ quiet: this.context.quiet,
69
+ }, {
70
+ cache,
71
71
  });
72
- return report.exitCode();
73
72
  }
74
73
  }
75
- exports.default = UnlinkCommand;
76
74
  UnlinkCommand.paths = [
77
75
  [`unlink`],
78
76
  ];
@@ -95,3 +93,4 @@ UnlinkCommand.usage = clipanion_1.Command.Usage({
95
93
  `$0 unlink '@babel/*' 'pkg-{a,b}'`,
96
94
  ]],
97
95
  });
96
+ exports.default = UnlinkCommand;
@@ -18,7 +18,7 @@ export default class UpCommand extends BaseCommand {
18
18
  }, {
19
19
  [key: string]: unknown;
20
20
  }>[];
21
- execute(): Promise<1 | 0>;
22
- executeUpRecursive(): Promise<1 | 0>;
23
- executeUpClassic(): Promise<1 | 0>;
21
+ execute(): Promise<0 | 1>;
22
+ executeUpRecursive(): Promise<0 | 1>;
23
+ executeUpClassic(): Promise<0 | 1>;
24
24
  }
@@ -75,16 +75,14 @@ class UpCommand extends cli_1.BaseCommand {
75
75
  project.storedDescriptors.delete(descriptor.descriptorHash);
76
76
  project.storedResolutions.delete(descriptor.descriptorHash);
77
77
  }
78
- const installReport = await core_2.StreamReport.start({
79
- configuration,
78
+ return await project.installWithNewReport({
80
79
  stdout: this.context.stdout,
81
- }, async (report) => {
82
- await project.install({ cache, report });
80
+ }, {
81
+ cache,
82
+ mode: this.mode,
83
83
  });
84
- return installReport.exitCode();
85
84
  }
86
85
  async executeUpClassic() {
87
- var _a;
88
86
  const configuration = await core_3.Configuration.find(this.context.cwd, this.context.plugins);
89
87
  const { project, workspace } = await core_2.Project.find(configuration, this.context.cwd);
90
88
  const cache = await core_3.Cache.find(configuration);
@@ -94,7 +92,7 @@ class UpCommand extends cli_1.BaseCommand {
94
92
  restoreResolutions: false,
95
93
  });
96
94
  const fixed = this.fixed;
97
- const interactive = (_a = this.interactive) !== null && _a !== void 0 ? _a : configuration.get(`preferInteractive`);
95
+ const interactive = this.interactive ?? configuration.get(`preferInteractive`);
98
96
  const modifier = suggestUtils.getModifier(this, project);
99
97
  const strategies = interactive ? [
100
98
  suggestUtils.Strategy.KEEP,
@@ -111,13 +109,18 @@ class UpCommand extends cli_1.BaseCommand {
111
109
  let isReferenced = false;
112
110
  // The range has to be static
113
111
  const pseudoDescriptor = core_1.structUtils.parseDescriptor(pattern);
112
+ const stringifiedPseudoDescriptor = core_1.structUtils.stringifyIdent(pseudoDescriptor);
114
113
  for (const workspace of project.workspaces) {
115
114
  for (const target of [suggestUtils.Target.REGULAR, suggestUtils.Target.DEVELOPMENT]) {
116
115
  const descriptors = workspace.manifest.getForScope(target);
117
116
  const stringifiedIdents = [...descriptors.values()].map(descriptor => {
118
117
  return core_1.structUtils.stringifyIdent(descriptor);
119
118
  });
120
- for (const stringifiedIdent of (0, micromatch_1.default)(stringifiedIdents, core_1.structUtils.stringifyIdent(pseudoDescriptor))) {
119
+ // As a special case, we support "*" as a pattern to upgrade all packages
120
+ const matches = stringifiedPseudoDescriptor === `*`
121
+ ? stringifiedIdents
122
+ : (0, micromatch_1.default)(stringifiedIdents, stringifiedPseudoDescriptor);
123
+ for (const stringifiedIdent of matches) {
121
124
  const ident = core_1.structUtils.parseIdent(stringifiedIdent);
122
125
  const existingDescriptor = workspace.manifest[target].get(ident.identHash);
123
126
  if (typeof existingDescriptor === `undefined`)
@@ -140,9 +143,9 @@ class UpCommand extends cli_1.BaseCommand {
140
143
  }
141
144
  }
142
145
  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`);
146
+ 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
147
  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`);
148
+ 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
149
  const allSuggestions = await Promise.all(allSuggestionsPromises);
147
150
  const checkReport = await core_3.LightReport.start({
148
151
  configuration,
@@ -231,16 +234,14 @@ class UpCommand extends cli_1.BaseCommand {
231
234
  await configuration.triggerMultipleHooks((hooks) => hooks.afterWorkspaceDependencyReplacement, afterWorkspaceDependencyReplacementList);
232
235
  if (askedQuestions)
233
236
  this.context.stdout.write(`\n`);
234
- const installReport = await core_2.StreamReport.start({
235
- configuration,
237
+ return await project.installWithNewReport({
236
238
  stdout: this.context.stdout,
237
- }, async (report) => {
238
- await project.install({ cache, report, mode: this.mode });
239
+ }, {
240
+ cache,
241
+ mode: this.mode,
239
242
  });
240
- return installReport.exitCode();
241
243
  }
242
244
  }
243
- exports.default = UpCommand;
244
245
  UpCommand.paths = [
245
246
  [`up`],
246
247
  ];
@@ -257,7 +258,7 @@ UpCommand.usage = clipanion_1.Command.Usage({
257
258
 
258
259
  If the \`--mode=<mode>\` option is set, Yarn will change which artifacts are generated. The modes currently supported are:
259
260
 
260
- - \`skip-build\` will not run the build scripts at all. Note that this is different from setting \`enableScripts\` to false because the later will disable build scripts, and thus affect the content of the artifacts generated on disk, whereas the former will just disable the build step - but not the scripts themselves, which just won't run.
261
+ - \`skip-build\` will not run the build scripts at all. Note that this is different from setting \`enableScripts\` to false because the latter will disable build scripts, and thus affect the content of the artifacts generated on disk, whereas the former will just disable the build step - but not the scripts themselves, which just won't run.
261
262
 
262
263
  - \`update-lockfile\` will skip the link step altogether, and only fetch packages that are missing from the lockfile (or that have no associated checksums). This mode is typically used by tools like Renovate or Dependabot to keep a lockfile up-to-date without incurring the full install cost.
263
264
 
@@ -290,3 +291,4 @@ UpCommand.usage = clipanion_1.Command.Usage({
290
291
  UpCommand.schema = [
291
292
  t.hasKeyRelationship(`recursive`, t.KeyRelationship.Forbids, [`interactive`, `exact`, `tilde`, `caret`], { ignore: [undefined, false] }),
292
293
  ];
294
+ exports.default = UpCommand;
@@ -38,7 +38,6 @@ class WhyCommand extends cli_1.BaseCommand {
38
38
  });
39
39
  }
40
40
  }
41
- exports.default = WhyCommand;
42
41
  WhyCommand.paths = [
43
42
  [`why`],
44
43
  ];
@@ -54,6 +53,7 @@ WhyCommand.usage = clipanion_1.Command.Usage({
54
53
  `$0 why lodash`,
55
54
  ]],
56
55
  });
56
+ exports.default = WhyCommand;
57
57
  function whySimple(project, identHash, { configuration, peers }) {
58
58
  const sortedPackages = core_3.miscUtils.sortMap(project.storedPackages.values(), pkg => {
59
59
  return core_3.structUtils.stringifyLocator(pkg);
@@ -121,12 +121,8 @@ function whyRecursive(project, identHash, { configuration, peers }) {
121
121
  dependents.add(pkg.locatorHash);
122
122
  return depends;
123
123
  };
124
- for (const workspace of sortedWorkspaces) {
125
- const pkg = project.storedPackages.get(workspace.anchoredLocator.locatorHash);
126
- if (!pkg)
127
- throw new Error(`Assertion failed: The package should have been registered`);
128
- markAllDependents(pkg);
129
- }
124
+ for (const workspace of sortedWorkspaces)
125
+ markAllDependents(workspace.anchoredPackage);
130
126
  const printed = new Set();
131
127
  const rootChildren = {};
132
128
  const root = { children: rootChildren };
@@ -164,11 +160,7 @@ function whyRecursive(project, identHash, { configuration, peers }) {
164
160
  printAllDependents(nextPkg, nodeChildren, dependency);
165
161
  }
166
162
  };
167
- for (const workspace of sortedWorkspaces) {
168
- const pkg = project.storedPackages.get(workspace.anchoredLocator.locatorHash);
169
- if (!pkg)
170
- throw new Error(`Assertion failed: The package should have been registered`);
171
- printAllDependents(pkg, rootChildren, null);
172
- }
163
+ for (const workspace of sortedWorkspaces)
164
+ printAllDependents(workspace.anchoredPackage, rootChildren, null);
173
165
  return root;
174
166
  }
@@ -18,10 +18,7 @@ class WorkspaceCommand extends cli_1.BaseCommand {
18
18
  if (!cwdWorkspace)
19
19
  throw new cli_1.WorkspaceRequiredError(project.cwd, this.context.cwd);
20
20
  const candidates = project.workspaces;
21
- const candidatesByName = new Map(candidates.map((workspace) => {
22
- const ident = core_2.structUtils.convertToIdent(workspace.locator);
23
- return [core_2.structUtils.stringifyIdent(ident), workspace];
24
- }));
21
+ const candidatesByName = new Map(candidates.map(workspace => [core_2.structUtils.stringifyIdent(workspace.anchoredLocator), workspace]));
25
22
  const workspace = candidatesByName.get(this.workspaceName);
26
23
  if (workspace === undefined) {
27
24
  const otherNames = Array.from(candidatesByName.keys()).sort();
@@ -30,7 +27,6 @@ class WorkspaceCommand extends cli_1.BaseCommand {
30
27
  return this.cli.run([this.commandName, ...this.args], { cwd: workspace.cwd });
31
28
  }
32
29
  }
33
- exports.default = WorkspaceCommand;
34
30
  WorkspaceCommand.paths = [
35
31
  [`workspace`],
36
32
  ];
@@ -48,3 +44,4 @@ WorkspaceCommand.usage = clipanion_1.Command.Usage({
48
44
  `yarn workspace components run build`,
49
45
  ]],
50
46
  });
47
+ exports.default = WorkspaceCommand;
@@ -5,7 +5,8 @@ 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
- execute(): Promise<1 | 0>;
11
+ execute(): Promise<0 | 1>;
11
12
  }
@@ -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();
@@ -79,7 +84,6 @@ class WorkspacesListCommand extends cli_1.BaseCommand {
79
84
  return report.exitCode();
80
85
  }
81
86
  }
82
- exports.default = WorkspacesListCommand;
83
87
  WorkspacesListCommand.paths = [
84
88
  [`workspaces`, `list`],
85
89
  ];
@@ -93,6 +97,9 @@ WorkspacesListCommand.usage = clipanion_1.Command.Usage({
93
97
 
94
98
  - 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
99
 
100
+ - If \`--no-private\` is set, Yarn will not list any workspaces that have the \`private\` field set to \`true\`.
101
+
96
102
  - 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
103
  `,
98
104
  });
105
+ exports.default = WorkspacesListCommand;
@@ -1,12 +1,12 @@
1
1
  import { Project, ResolveOptions, Resolver, Descriptor, Package, Report, Cache } from '@yarnpkg/core';
2
2
  import { Fetcher, FetchOptions } from '@yarnpkg/core';
3
- export declare type PackageUpdate = {
3
+ export type PackageUpdate = {
4
4
  descriptor: Descriptor;
5
5
  currentPackage: Package;
6
6
  updatedPackage: Package;
7
7
  resolvedPackage: Package;
8
8
  };
9
- export declare type Algorithm = (project: Project, patterns: Array<string>, opts: {
9
+ export type Algorithm = (project: Project, patterns: Array<string>, opts: {
10
10
  resolver: Resolver;
11
11
  resolveOptions: ResolveOptions;
12
12
  fetcher: Fetcher;
@@ -23,7 +23,7 @@ export declare enum Strategy {
23
23
  HIGHEST = "highest"
24
24
  }
25
25
  export declare const acceptedStrategies: Set<Strategy.HIGHEST>;
26
- export declare type DedupeOptions = {
26
+ export type DedupeOptions = {
27
27
  strategy: Strategy;
28
28
  patterns: Array<string>;
29
29
  cache: Cache;
@@ -15,7 +15,7 @@ var Strategy;
15
15
  * - dependencies are never downgraded
16
16
  */
17
17
  Strategy["HIGHEST"] = "highest";
18
- })(Strategy = exports.Strategy || (exports.Strategy = {}));
18
+ })(Strategy || (exports.Strategy = Strategy = {}));
19
19
  exports.acceptedStrategies = new Set(Object.values(Strategy));
20
20
  const DEDUPE_ALGORITHMS = {
21
21
  highest: async (project, patterns, { resolver, fetcher, resolveOptions, fetchOptions }) => {
@@ -44,7 +44,6 @@ const DEDUPE_ALGORITHMS = {
44
44
  if (typeof currentPackage === `undefined`)
45
45
  throw new Error(`Assertion failed: The package (${currentResolution}) should have been registered`);
46
46
  Promise.resolve().then(async () => {
47
- var _a;
48
47
  const dependencies = resolver.getResolutionDependencies(descriptor, resolveOptions);
49
48
  const resolvedDependencies = Object.fromEntries(await core_1.miscUtils.allSettledSafe(Object.entries(dependencies).map(async ([dependencyName, dependency]) => {
50
49
  const dependencyDeferred = deferredMap.get(dependency.descriptorHash);
@@ -74,7 +73,7 @@ const DEDUPE_ALGORITHMS = {
74
73
  return pkg;
75
74
  });
76
75
  const satisfying = await resolver.getSatisfying(descriptor, resolvedDependencies, candidates, resolveOptions);
77
- const bestLocator = (_a = satisfying.locators) === null || _a === void 0 ? void 0 : _a[0];
76
+ const bestLocator = satisfying.locators?.[0];
78
77
  if (typeof bestLocator === `undefined` || !satisfying.sorted)
79
78
  return currentPackage;
80
79
  const updatedPackage = project.originalPackages.get(bestLocator.locatorHash);
@@ -109,7 +108,6 @@ async function dedupe(project, { strategy, patterns, cache, report }) {
109
108
  fetcher,
110
109
  project,
111
110
  report: throwReport,
112
- skipIntegrityCheck: true,
113
111
  cacheOptions: {
114
112
  skipIntegrityCheck: true,
115
113
  },
@@ -124,7 +122,7 @@ async function dedupe(project, { strategy, patterns, cache, report }) {
124
122
  const algorithm = DEDUPE_ALGORITHMS[strategy];
125
123
  const dedupePromises = await algorithm(project, patterns, { resolver, resolveOptions, fetcher, fetchOptions });
126
124
  const progress = core_1.Report.progressViaCounter(dedupePromises.length);
127
- report.reportProgress(progress);
125
+ await report.reportProgress(progress);
128
126
  let dedupedPackageCount = 0;
129
127
  await Promise.all(dedupePromises.map(dedupePromise => dedupePromise
130
128
  .then(dedupe => {
package/lib/index.d.ts CHANGED
@@ -1,8 +1,83 @@
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 PluginCheckCommand from './commands/plugin/check';
23
+ import PluginImportSourcesCommand from './commands/plugin/import/sources';
24
+ import PluginImportCommand from './commands/plugin/import';
25
+ import PluginListCommand from './commands/plugin/list';
26
+ import PluginRemoveCommand from './commands/plugin/remove';
27
+ import PluginRuntimeCommand from './commands/plugin/runtime';
28
+ import RebuildCommand from './commands/rebuild';
29
+ import RemoveCommand from './commands/remove';
30
+ import RunIndexCommand from './commands/runIndex';
31
+ import RunCommand from './commands/run';
32
+ import SetResolutionCommand from './commands/set/resolution';
33
+ import SetVersionSourcesCommand from './commands/set/version/sources';
34
+ import SetVersionCommand from './commands/set/version';
35
+ import UnlinkCommand from './commands/unlink';
36
+ import UpCommand from './commands/up';
37
+ import WhyCommand from './commands/why';
38
+ import WorkspacesListCommand from './commands/workspaces/list';
39
+ import WorkspaceCommand from './commands/workspace';
3
40
  import * as dedupeUtils from './dedupeUtils';
4
41
  import * as suggestUtils from './suggestUtils';
5
- export { dedupeUtils, suggestUtils, };
42
+ export { AddCommand };
43
+ export { BinCommand };
44
+ export { CacheCleanCommand };
45
+ export { ConfigGetCommand };
46
+ export { ConfigSetCommand };
47
+ export { ConfigUnsetCommand };
48
+ export { ConfigCommand };
49
+ export { DedupeCommand };
50
+ export { ClipanionCommand };
51
+ export { HelpCommand };
52
+ export { EntryCommand };
53
+ export { VersionCommand };
54
+ export { ExecCommand };
55
+ export { ExplainPeerRequirementsCommand };
56
+ export { ExplainCommand };
57
+ export { InfoCommand };
58
+ export { YarnCommand };
59
+ export { LinkCommand };
60
+ export { NodeCommand };
61
+ export { PluginImportSourcesCommand };
62
+ export { PluginCheckCommand };
63
+ export { PluginImportCommand };
64
+ export { PluginListCommand };
65
+ export { PluginRemoveCommand };
66
+ export { PluginRuntimeCommand };
67
+ export { RebuildCommand };
68
+ export { RemoveCommand };
69
+ export { RunIndexCommand };
70
+ export { RunCommand };
71
+ export { SetResolutionCommand };
72
+ export { SetVersionSourcesCommand };
73
+ export { SetVersionCommand };
74
+ export { UnlinkCommand };
75
+ export { UpCommand };
76
+ export { WhyCommand };
77
+ export { WorkspacesListCommand };
78
+ export { WorkspaceCommand };
79
+ export { dedupeUtils };
80
+ export { suggestUtils };
6
81
  export interface Hooks {
7
82
  /**
8
83
  * Called when a new dependency is added to a workspace. Note that this hook
package/lib/index.js CHANGED
@@ -1,45 +1,83 @@
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.PluginCheckCommand = 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;
45
+ const check_1 = tslib_1.__importDefault(require("./commands/plugin/check"));
46
+ exports.PluginCheckCommand = check_1.default;
26
47
  const sources_1 = tslib_1.__importDefault(require("./commands/plugin/import/sources"));
48
+ exports.PluginImportSourcesCommand = sources_1.default;
27
49
  const import_1 = tslib_1.__importDefault(require("./commands/plugin/import"));
50
+ exports.PluginImportCommand = import_1.default;
28
51
  const list_1 = tslib_1.__importDefault(require("./commands/plugin/list"));
52
+ exports.PluginListCommand = list_1.default;
29
53
  const remove_1 = tslib_1.__importDefault(require("./commands/plugin/remove"));
54
+ exports.PluginRemoveCommand = remove_1.default;
30
55
  const runtime_1 = tslib_1.__importDefault(require("./commands/plugin/runtime"));
56
+ exports.PluginRuntimeCommand = runtime_1.default;
31
57
  const rebuild_1 = tslib_1.__importDefault(require("./commands/rebuild"));
58
+ exports.RebuildCommand = rebuild_1.default;
32
59
  const remove_2 = tslib_1.__importDefault(require("./commands/remove"));
60
+ exports.RemoveCommand = remove_2.default;
33
61
  const runIndex_1 = tslib_1.__importDefault(require("./commands/runIndex"));
62
+ exports.RunIndexCommand = runIndex_1.default;
34
63
  const run_2 = tslib_1.__importDefault(require("./commands/run"));
64
+ exports.RunCommand = run_2.default;
35
65
  const resolution_1 = tslib_1.__importDefault(require("./commands/set/resolution"));
66
+ exports.SetResolutionCommand = resolution_1.default;
36
67
  const sources_2 = tslib_1.__importDefault(require("./commands/set/version/sources"));
68
+ exports.SetVersionSourcesCommand = sources_2.default;
37
69
  const version_2 = tslib_1.__importDefault(require("./commands/set/version"));
70
+ exports.SetVersionCommand = version_2.default;
38
71
  const unlink_1 = tslib_1.__importDefault(require("./commands/unlink"));
72
+ exports.UnlinkCommand = unlink_1.default;
39
73
  const up_1 = tslib_1.__importDefault(require("./commands/up"));
74
+ exports.UpCommand = up_1.default;
40
75
  const why_1 = tslib_1.__importDefault(require("./commands/why"));
76
+ exports.WhyCommand = why_1.default;
41
77
  const list_2 = tslib_1.__importDefault(require("./commands/workspaces/list"));
78
+ exports.WorkspacesListCommand = list_2.default;
42
79
  const workspace_1 = tslib_1.__importDefault(require("./commands/workspace"));
80
+ exports.WorkspaceCommand = workspace_1.default;
43
81
  const dedupeUtils = tslib_1.__importStar(require("./dedupeUtils"));
44
82
  exports.dedupeUtils = dedupeUtils;
45
83
  const suggestUtils = tslib_1.__importStar(require("./suggestUtils"));
@@ -88,6 +126,7 @@ const plugin = {
88
126
  link_1.default,
89
127
  unlink_1.default,
90
128
  node_1.default,
129
+ check_1.default,
91
130
  sources_1.default,
92
131
  import_1.default,
93
132
  remove_1.default,