How to use the @yarnpkg/core.structUtils.prettyIdent 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 / yarnpkg-check / sources / cli.ts View on Github external
function checkForUndeclaredDependency(workspace: Workspace, referenceNode: ts.Node, moduleName: string, {configuration, report}: {configuration: Configuration, report: Report}) {
  if (BUILTINS.has(moduleName))
    return;

  const idents = extractIdents(moduleName);

  for (const ident of idents) {
    if (isValidDependency(ident, {workspace}))
      continue;

    const prettyLocation = ast.prettyNodeLocation(configuration, referenceNode);
    report.reportError(MessageName.UNNAMED, `${prettyLocation}: Undeclared dependency on ${structUtils.prettyIdent(configuration, ident)}`);
  }
}
github yarnpkg / berry / packages / plugin-essentials / sources / commands / add.ts View on Github external
function suggestTarget(workspace: Workspace, ident: Ident, {dev, peer, preferDev}: {dev: boolean, peer: boolean, preferDev: boolean}) {
  const hasRegular = workspace.manifest[suggestUtils.Target.REGULAR].has(ident.identHash);
  const hasDev = workspace.manifest[suggestUtils.Target.DEVELOPMENT].has(ident.identHash);
  const hasPeer = workspace.manifest[suggestUtils.Target.PEER].has(ident.identHash);

  if ((dev || peer) && hasRegular)
    throw new UsageError(`Package "${structUtils.prettyIdent(workspace.project.configuration, ident)}" is already listed as a regular dependency - remove the -D,-P flags or remove it from your dependencies first`);
  if (!dev && !peer && hasPeer)
    throw new UsageError(`Package "${structUtils.prettyIdent(workspace.project.configuration, ident)}" is already listed as a peer dependency - use either of -D or -P, or remove it from your peer dependencies first`);

  if (hasRegular)
    return suggestUtils.Target.REGULAR;
  if (hasDev)
    return suggestUtils.Target.DEVELOPMENT;

  if (peer)
    return suggestUtils.Target.PEER;
  if (dev || preferDev)
    return suggestUtils.Target.DEVELOPMENT;

  return suggestUtils.Target.REGULAR;
}
github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
private getPackageInformation(locator: Locator) {
    const key1 = structUtils.requirableIdent(locator);
    const key2 = locator.reference;

    const packageInformationStore = this.packageRegistry.get(key1);
    if (!packageInformationStore)
      throw new Error(`Assertion failed: The package information store should have been available (for ${structUtils.prettyIdent(this.opts.project.configuration, locator)})`);

    const packageInformation = packageInformationStore.get(key2);
    if (!packageInformation)
      throw new Error(`Assertion failed: The package information should have been available (for ${structUtils.prettyLocator(this.opts.project.configuration, locator)})`);

    return packageInformation;
  }
github yarnpkg / berry / packages / plugin-essentials / sources / commands / up.ts View on Github external
existing,
              await suggestUtils.getSuggestedDescriptors(descriptor, {project, workspace, cache, target, modifier, strategies}),
            ] as [
              Workspace,
              suggestUtils.Target,
              Descriptor,
              Array
            ];
          }));

          isReferenced = true;
        }
      }

      if (!isReferenced) {
        unreferencedPackages.push(structUtils.prettyIdent(configuration, descriptor));
      }
    }

    if (unreferencedPackages.length > 1)
      throw new UsageError(`Packages ${unreferencedPackages.join(`, `)} aren't referenced by any workspace`);
    if (unreferencedPackages.length > 0)
      throw new UsageError(`Package ${unreferencedPackages[0]} isn't referenced by any workspace`);

    const allSuggestions = await Promise.all(allSuggestionsPromises);

    const checkReport = await LightReport.start({
      configuration,
      stdout: this.context.stdout,
      suggestInstall: false,
    }, async report => {
      for (const [/*workspace*/, /*target*/, existing, suggestions] of allSuggestions) {
github yarnpkg / berry / packages / plugin-essentials / sources / commands / add.ts View on Github external
function suggestTarget(workspace: Workspace, ident: Ident, {dev, peer, preferDev}: {dev: boolean, peer: boolean, preferDev: boolean}) {
  const hasRegular = workspace.manifest[suggestUtils.Target.REGULAR].has(ident.identHash);
  const hasDev = workspace.manifest[suggestUtils.Target.DEVELOPMENT].has(ident.identHash);
  const hasPeer = workspace.manifest[suggestUtils.Target.PEER].has(ident.identHash);

  if ((dev || peer) && hasRegular)
    throw new UsageError(`Package "${structUtils.prettyIdent(workspace.project.configuration, ident)}" is already listed as a regular dependency - remove the -D,-P flags or remove it from your dependencies first`);
  if (!dev && !peer && hasPeer)
    throw new UsageError(`Package "${structUtils.prettyIdent(workspace.project.configuration, ident)}" is already listed as a peer dependency - use either of -D or -P, or remove it from your peer dependencies first`);

  if (hasRegular)
    return suggestUtils.Target.REGULAR;
  if (hasDev)
    return suggestUtils.Target.DEVELOPMENT;

  if (peer)
    return suggestUtils.Target.PEER;
  if (dev || preferDev)
    return suggestUtils.Target.DEVELOPMENT;

  return suggestUtils.Target.REGULAR;
}
github yarnpkg / berry / packages / plugin-node-modules / sources / NodeModulesLinker.ts View on Github external
private getPackageInformation(locator: Locator) {
    const key1 = structUtils.requirableIdent(locator);
    const key2 = locator.reference;

    const packageInformationStore = this.packageRegistry.get(key1);
    if (!packageInformationStore)
      throw new Error(`Assertion failed: The package information store should have been available (for ${structUtils.prettyIdent(this.opts.project.configuration, locator)})`);

    const packageInformation = packageInformationStore.get(key2);
    if (!packageInformation)
      throw new Error(`Assertion failed: The package information should have been available (for ${structUtils.prettyLocator(this.opts.project.configuration, locator)})`);

    return packageInformation;
  }