Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (candidateLocators.length === 0)
return null;
// Per the requirements exposed in Resolver.ts, the best is the first one
const bestLocator = candidateLocators[0];
let {protocol, source, params, selector} = structUtils.parseRange(structUtils.convertToManifestRange(bestLocator.reference));
if (protocol === project.configuration.get(`defaultProtocol`))
protocol = null;
if (semver.valid(selector) && preserveModifier) {
const modifier = extractModifier(latestDescriptor, {project});
selector = modifier + selector;
}
return structUtils.makeDescriptor(bestLocator, structUtils.makeRange({protocol, source, params, selector}));
}
bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) {
if (FILE_REGEXP.test(descriptor.range))
descriptor = structUtils.makeDescriptor(descriptor, `${PROTOCOL}${descriptor.range}`);
return structUtils.bindDescriptor(descriptor, {
locator: structUtils.stringifyLocator(fromLocator),
});
}
bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) {
if (FILE_REGEXP.test(descriptor.range))
descriptor = structUtils.makeDescriptor(descriptor, `${PROTOCOL}${descriptor.range}`);
return structUtils.bindDescriptor(descriptor, {
locator: structUtils.stringifyLocator(fromLocator),
});
}
export function applyModifier(descriptor: Descriptor, modifier: Modifier) {
let {protocol, source, params, selector} = structUtils.parseRange(descriptor.range);
if (semver.valid(selector))
selector = `${modifier}${descriptor.range}`;
return structUtils.makeDescriptor(descriptor, structUtils.makeRange({protocol, source, params, selector}));
}
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));
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) {
reduceDependency: async (dependency, project, locator, initialDescriptor) => {
const patch = PATCHES.get(dependency.identHash);
if (typeof patch === `undefined`)
return dependency;
return structUtils.makeDescriptor(dependency, structUtils.makeRange({
protocol: `patch:`,
source: structUtils.stringifyDescriptor(dependency),
selector: `builtin`,
params: null,
}));
},
},
export async function fetchDescriptorFrom(ident: Ident, range: string, {project, cache, preserveModifier = true}: {project: Project, cache: Cache, preserveModifier?: boolean}) {
const latestDescriptor = structUtils.makeDescriptor(ident, range);
const report = new ThrowReport();
const fetcher = project.configuration.makeFetcher();
const resolver = project.configuration.makeResolver();
const resolverOptions = {checksums: project.storedChecksums, project, cache, fetcher, report, resolver};
let candidateLocators;
try {
candidateLocators = await resolver.getCandidates(latestDescriptor, new Map(), resolverOptions);
} catch {
return null;
}
if (candidateLocators.length === 0)