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

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.
@@ -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`) {
@@ -11,7 +11,7 @@ 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;
@@ -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,
@@ -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
  }
@@ -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>;
@@ -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,8 +305,8 @@ 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();
@@ -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,11 +1,11 @@
1
1
  {
2
2
  "name": "@yarnpkg/plugin-essentials",
3
- "version": "4.0.0-rc.2",
3
+ "version": "4.0.0-rc.3",
4
4
  "license": "BSD-2-Clause",
5
5
  "main": "./lib/index.js",
6
6
  "dependencies": {
7
- "@yarnpkg/fslib": "^3.0.0-rc.2",
8
- "@yarnpkg/parsers": "^3.0.0-rc.2",
7
+ "@yarnpkg/fslib": "^3.0.0-rc.3",
8
+ "@yarnpkg/parsers": "^3.0.0-rc.3",
9
9
  "ci-info": "^3.2.0",
10
10
  "clipanion": "^3.2.0-rc.10",
11
11
  "enquirer": "^2.3.6",
@@ -16,17 +16,17 @@
16
16
  "typanion": "^3.3.0"
17
17
  },
18
18
  "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"
19
+ "@yarnpkg/cli": "^4.0.0-rc.3",
20
+ "@yarnpkg/core": "^4.0.0-rc.3",
21
+ "@yarnpkg/plugin-git": "^3.0.0-rc.3"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/lodash": "^4.14.136",
25
25
  "@types/micromatch": "^4.0.1",
26
26
  "@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"
27
+ "@yarnpkg/cli": "^4.0.0-rc.3",
28
+ "@yarnpkg/core": "^4.0.0-rc.3",
29
+ "@yarnpkg/plugin-git": "^3.0.0-rc.3"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",