Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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];
}
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)}`)];
}
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)}`)];
}
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})];
}
}
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);
}
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)}`)];
}
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)}`)];
}
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);
}
export function makeDescriptor(ident: Ident, {parentLocator, sourceDescriptor, patchPaths}: ReturnType) {
return structUtils.makeLocator(ident, makeSpec({parentLocator, sourceItem: sourceDescriptor, patchPaths}, structUtils.stringifyDescriptor));
}
export function normalizeLocator(locator: Locator) {
return structUtils.makeLocator(locator, normalizeRepoUrl(locator.reference));
}