How to use the @yarnpkg/core.structUtils.prettyRange function in @yarnpkg/core

To help you get started, we’ve selected a few @yarnpkg/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yarnpkg / berry / packages / plugin-essentials / sources / commands / why.ts View on Github external
const printAllDependents = (pkg: Package, tree: TreeNode, range: string | null) => {
    if (!dependents.has(pkg.locatorHash))
      return;

    const label = range !== null
      ? `${structUtils.prettyLocator(configuration, pkg)} (via ${structUtils.prettyRange(configuration, range)})`
      : `${structUtils.prettyLocator(configuration, pkg)}`;

    const node = {} as TreeNode;
    tree[label] = node;

    // We don't want to reprint the children for a package that already got
    // printed as part of another branch
    if (printed.has(pkg.locatorHash))
      return;

    printed.add(pkg.locatorHash);

    // We don't want to print the children of our transitive workspace
    // dependencies, as they will be printed in their own top-level branch
    if (range !== null && project.tryWorkspaceByLocator(pkg))
      return;
github yarnpkg / berry / packages / plugin-essentials / sources / commands / why.ts View on Github external
const nextPkg = project.storedPackages.get(resolution);
      if (!nextPkg)
        throw new Error(`Assertion failed: The package should have been registered`);

      if (nextPkg.identHash !== identHash)
        continue;

      if (node === null) {
        node = {} as TreeNode;

        const label = `${structUtils.prettyLocator(configuration, pkg)}`;
        tree[label] = node;
      }

      const label = `${structUtils.prettyLocator(configuration, nextPkg)} (via ${structUtils.prettyRange(configuration, dependency.range)})`;
      node[label] = {};
    }
  }

  return tree;
}
github yarnpkg / berry / packages / plugin-constraints / sources / commands / constraints.ts View on Github external
allIdents.set(dependencyIdent.identHash, dependencyIdent);
    byDependencyTypeStore.add(dependencyRange);
  }

  for (const [workspace, byWorkspacesStore] of byWorkspaces) {
    for (const [identHash, byIdentStore] of byWorkspacesStore) {
      const dependencyIdent = allIdents.get(identHash);
      if (typeof dependencyIdent === `undefined`)
        throw new Error(`Assertion failed: The ident should have been registered`);

      for (const [dependencyType, byDependencyTypeStore] of byIdentStore) {
        const expectedRanges = [...byDependencyTypeStore];
        if (expectedRanges.length > 2) {
          report.reportError(MessageName.CONSTRAINTS_AMBIGUITY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} via conflicting ranges ${expectedRanges.slice(0, -1).map(expectedRange => structUtils.prettyRange(configuration, String(expectedRange))).join(`, `)}, and ${structUtils.prettyRange(configuration, String(expectedRanges[expectedRanges.length - 1]))} (in ${dependencyType})`);
        } else if (expectedRanges.length > 1) {
          report.reportError(MessageName.CONSTRAINTS_AMBIGUITY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} via conflicting ranges ${structUtils.prettyRange(configuration, String(expectedRanges[0]))} and ${structUtils.prettyRange(configuration, String(expectedRanges[1]))} (in ${dependencyType})`);
        } else {
          const dependencyDescriptor = workspace.manifest[dependencyType].get(dependencyIdent.identHash);
          const [expectedRange] = expectedRanges;

          if (expectedRange !== null) {
            if (!dependencyDescriptor) {
              if (fix) {
                workspace.manifest[dependencyType].set(dependencyIdent.identHash, structUtils.makeDescriptor(dependencyIdent, expectedRange));
                toSave.add(workspace);
                hasFixes = true;
              } else {
                report.reportError(MessageName.CONSTRAINTS_MISSING_DEPENDENCY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} (via ${structUtils.prettyRange(configuration, expectedRange)}), but doesn't (in ${dependencyType})`);
              }
            } else if (dependencyDescriptor.range !== expectedRange) {
              if (fix) {
                workspace.manifest[dependencyType].set(dependencyIdent.identHash, structUtils.makeDescriptor(dependencyIdent, expectedRange));
github yarnpkg / berry / packages / plugin-constraints / sources / commands / constraints.ts View on Github external
if (expectedRange !== null) {
            if (!dependencyDescriptor) {
              if (fix) {
                workspace.manifest[dependencyType].set(dependencyIdent.identHash, structUtils.makeDescriptor(dependencyIdent, expectedRange));
                toSave.add(workspace);
                hasFixes = true;
              } else {
                report.reportError(MessageName.CONSTRAINTS_MISSING_DEPENDENCY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} (via ${structUtils.prettyRange(configuration, expectedRange)}), but doesn't (in ${dependencyType})`);
              }
            } else if (dependencyDescriptor.range !== expectedRange) {
              if (fix) {
                workspace.manifest[dependencyType].set(dependencyIdent.identHash, structUtils.makeDescriptor(dependencyIdent, expectedRange));
                toSave.add(workspace);
                hasFixes = true;
              } else {
                report.reportError(MessageName.CONSTRAINTS_INCOMPATIBLE_DEPENDENCY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} via ${structUtils.prettyRange(configuration, expectedRange)}, but uses ${structUtils.prettyRange(configuration, dependencyDescriptor.range)} instead (in ${dependencyType})`);
              }
            }
          } else {
            if (dependencyDescriptor) {
              if (fix) {
                workspace.manifest[dependencyType].delete(dependencyIdent.identHash);
                toSave.add(workspace);
                hasFixes = true;
              } else {
                report.reportError(MessageName.CONSTRAINTS_EXTRANEOUS_DEPENDENCY, `${structUtils.prettyWorkspace(configuration, workspace)} has an extraneous dependency on ${structUtils.prettyIdent(configuration, dependencyIdent)} (in ${dependencyType})`);
              }
            }
          }
        }
      }
    }
github yarnpkg / berry / packages / plugin-constraints / sources / commands / constraints.ts View on Github external
if (expectedRanges.length > 2) {
          report.reportError(MessageName.CONSTRAINTS_AMBIGUITY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} via conflicting ranges ${expectedRanges.slice(0, -1).map(expectedRange => structUtils.prettyRange(configuration, String(expectedRange))).join(`, `)}, and ${structUtils.prettyRange(configuration, String(expectedRanges[expectedRanges.length - 1]))} (in ${dependencyType})`);
        } else if (expectedRanges.length > 1) {
          report.reportError(MessageName.CONSTRAINTS_AMBIGUITY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} via conflicting ranges ${structUtils.prettyRange(configuration, String(expectedRanges[0]))} and ${structUtils.prettyRange(configuration, String(expectedRanges[1]))} (in ${dependencyType})`);
        } else {
          const dependencyDescriptor = workspace.manifest[dependencyType].get(dependencyIdent.identHash);
          const [expectedRange] = expectedRanges;

          if (expectedRange !== null) {
            if (!dependencyDescriptor) {
              if (fix) {
                workspace.manifest[dependencyType].set(dependencyIdent.identHash, structUtils.makeDescriptor(dependencyIdent, expectedRange));
                toSave.add(workspace);
                hasFixes = true;
              } else {
                report.reportError(MessageName.CONSTRAINTS_MISSING_DEPENDENCY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} (via ${structUtils.prettyRange(configuration, expectedRange)}), but doesn't (in ${dependencyType})`);
              }
            } else if (dependencyDescriptor.range !== expectedRange) {
              if (fix) {
                workspace.manifest[dependencyType].set(dependencyIdent.identHash, structUtils.makeDescriptor(dependencyIdent, expectedRange));
                toSave.add(workspace);
                hasFixes = true;
              } else {
                report.reportError(MessageName.CONSTRAINTS_INCOMPATIBLE_DEPENDENCY, `${structUtils.prettyWorkspace(configuration, workspace)} must depend on ${structUtils.prettyIdent(configuration, dependencyIdent)} via ${structUtils.prettyRange(configuration, expectedRange)}, but uses ${structUtils.prettyRange(configuration, dependencyDescriptor.range)} instead (in ${dependencyType})`);
              }
            }
          } else {
            if (dependencyDescriptor) {
              if (fix) {
                workspace.manifest[dependencyType].delete(dependencyIdent.identHash);
                toSave.add(workspace);
                hasFixes = true;