How to use the @yarnpkg/core.structUtils.makeLocator 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-git / sources / GitResolver.ts View on Github external
async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
    const reference = await gitUtils.resolveUrl(descriptor.range, opts.project.configuration);
    const locator = structUtils.makeLocator(descriptor, reference);

    return [locator];
  }
github yarnpkg / berry / packages / plugin-file / sources / TarballFileResolver.ts View on Github external
async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
    let path = descriptor.range;

    if (path.startsWith(PROTOCOL))
      path = path.slice(PROTOCOL.length);

    return [structUtils.makeLocator(descriptor, `${PROTOCOL}${npath.toPortablePath(path)}`)];
  }
github yarnpkg / berry / packages / plugin-link / sources / LinkResolver.ts View on Github external
async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
    const path = descriptor.range.slice(LINK_PROTOCOL.length);

    return [structUtils.makeLocator(descriptor, `${LINK_PROTOCOL}${npath.toPortablePath(path)}`)];
  }
github yarnpkg / berry / packages / plugin-npm / sources / NpmTagResolver.ts View on Github external
const registryData = await npmHttpUtils.get(npmHttpUtils.getIdentUrl(descriptor), {
      configuration: opts.project.configuration,
      ident: descriptor,
      json: true,
    });

    if (!Object.prototype.hasOwnProperty.call(registryData, `dist-tags`))
      throw new ReportError(MessageName.REMOTE_INVALID, `Registry returned invalid data - missing "dist-tags" field`);

    const distTags = registryData[`dist-tags`];

    if (!Object.prototype.hasOwnProperty.call(distTags, tag))
      throw new ReportError(MessageName.REMOTE_NOT_FOUND, `Registry failed to return tag "${tag}"`);

    const version = distTags[tag];
    const versionLocator = structUtils.makeLocator(descriptor, `${PROTOCOL}${version}`);

    const archiveUrl = registryData.versions[version].dist.tarball;

    if (NpmSemverFetcher.isConventionalTarballUrl(versionLocator, archiveUrl, {configuration: opts.project.configuration})) {
      return [versionLocator];
    } else {
      return [structUtils.bindLocator(versionLocator, {__archiveUrl: archiveUrl})];
    }
  }
github yarnpkg / berry / packages / plugin-node-modules / sources / NodeModulesLinker.ts View on Github external
async findPackageLocator(location: PortablePath, opts: LinkOptions) {
    const pnpPath = getPnpPath(opts.project);
    if (!xfs.existsSync(pnpPath))
      throw new UsageError(`The project in ${opts.project.cwd}/package.json doesn't seem to have been installed - running an install there might help`);

    const physicalPath = npath.fromPortablePath(pnpPath);
    const pnpFile = miscUtils.dynamicRequire(physicalPath);
    delete require.cache[physicalPath];

    const locator = pnpFile.findPackageLocator(npath.fromPortablePath(location));
    if (!locator)
      return null;

    return structUtils.makeLocator(structUtils.parseIdent(locator.name), locator.reference);
  }
github yarnpkg / berry / packages / plugin-link / sources / RawLinkResolver.ts View on Github external
async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
    const path = descriptor.range.slice(RAW_LINK_PROTOCOL.length);

    return [structUtils.makeLocator(descriptor, `${RAW_LINK_PROTOCOL}${npath.toPortablePath(path)}`)];
  }
github yarnpkg / berry / packages / plugin-exec / sources / ExecResolver.ts View on Github external
async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
    let path = descriptor.range;

    if (path.startsWith(PROTOCOL))
      path = path.slice(PROTOCOL.length);

    return [structUtils.makeLocator(descriptor, `${PROTOCOL}${npath.toPortablePath(path)}`)];
  }
github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
async findPackageLocator(location: PortablePath, opts: LinkOptions) {
    const pnpPath = getPnpPath(opts.project);
    if (!xfs.existsSync(pnpPath))
      throw new UsageError(`The project in ${opts.project.cwd}/package.json doesn't seem to have been installed - running an install there might help`);

    const physicalPath = npath.fromPortablePath(pnpPath);
    const pnpFile = miscUtils.dynamicRequire(physicalPath);
    delete require.cache[physicalPath];

    const locator = pnpFile.findPackageLocator(npath.fromPortablePath(location));
    if (!locator)
      return null;

    return structUtils.makeLocator(structUtils.parseIdent(locator.name), locator.reference);
  }
github yarnpkg / berry / packages / plugin-patch / sources / patchUtils.ts View on Github external
export function makeDescriptor(ident: Ident, {parentLocator, sourceDescriptor, patchPaths}: ReturnType) {
  return structUtils.makeLocator(ident, makeSpec({parentLocator, sourceItem: sourceDescriptor, patchPaths}, structUtils.stringifyDescriptor));
}
github yarnpkg / berry / packages / plugin-git / sources / gitUtils.ts View on Github external
export function normalizeLocator(locator: Locator) {
  return structUtils.makeLocator(locator, normalizeRepoUrl(locator.reference));
}