Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{request, issuer, dependencyLocator: Object.assign({}, dependencyLocator)},
);
}
// Now that we know which package we should resolve to, we only have to find out the file location
const dependencyLocation = ppath.resolve(runtimeState.basePath, dependencyInformation.packageLocation);
if (subPath) {
unqualifiedPath = ppath.resolve(dependencyLocation, subPath);
} else {
unqualifiedPath = dependencyLocation;
}
}
return ppath.normalize(unqualifiedPath);
};
const dependencyNameMatch = request.match(pathRegExp);
if (!dependencyNameMatch) {
if (ppath.isAbsolute(request)) {
unqualifiedPath = ppath.normalize(request);
} else {
if (!issuer) {
throw makeError(
ErrorCode.API_ERROR,
`The resolveToUnqualified function must be called with a valid issuer when the path isn't a builtin nor absolute`,
{request, issuer},
);
}
if (issuer.match(isDirRegExp)) {
unqualifiedPath = ppath.normalize(ppath.resolve(issuer, request));
} else {
unqualifiedPath = ppath.normalize(ppath.resolve(ppath.dirname(issuer), request));
}
}
// No need to use the return value; we just want to check the blacklist status
findPackageLocator(unqualifiedPath);
}
// Things are more hairy if it's a package require - we then need to figure out which package is needed, and in
// particular the exact version for the given location on the dependency tree
else {
if (!issuer) {
throw makeError(
ErrorCode.API_ERROR,
);
}
return npath.toPortablePath(result);
}
}
let unqualifiedPath: PortablePath;
// If the request is a relative or absolute path, we just return it normalized
const dependencyNameMatch = request.match(pathRegExp);
if (!dependencyNameMatch) {
if (ppath.isAbsolute(request)) {
unqualifiedPath = ppath.normalize(request);
} else {
if (!issuer) {
throw makeError(
ErrorCode.API_ERROR,
`The resolveToUnqualified function must be called with a valid issuer when the path isn't a builtin nor absolute`,
{request, issuer},
);
}
if (issuer.match(isDirRegExp)) {
unqualifiedPath = ppath.normalize(ppath.resolve(issuer, request));
} else {
unqualifiedPath = ppath.normalize(ppath.resolve(ppath.dirname(issuer), request));
}
}
result.set(propKey, getDefaultValue(configuration, propDefinition));
return result;
} break;
case SettingsType.MAP: {
return new Map();
} break;
case SettingsType.ABSOLUTE_PATH: {
if (definition.default === null)
return null;
if (configuration.projectCwd === null) {
if (ppath.isAbsolute(definition.default)) {
return ppath.normalize(definition.default);
} else if (definition.isNullable || definition.default === null) {
return null;
}
} else {
if (Array.isArray(definition.default)) {
return definition.default.map((entry: string) => ppath.resolve(configuration.projectCwd!, entry as PortablePath));
} else {
return ppath.resolve(configuration.projectCwd, definition.default);
}
}
} break;
default: {
return definition.default;
} break;
}
function resolveUnqualified(unqualifiedPath: PortablePath, {extensions = Object.keys(Module._extensions)}: ResolveUnqualifiedOptions = {}): PortablePath {
const candidates: Array = [];
const qualifiedPath = applyNodeExtensionResolution(unqualifiedPath, candidates, {extensions});
if (qualifiedPath) {
return ppath.normalize(qualifiedPath);
} else {
throw makeError(
ErrorCode.QUALIFIED_PATH_RESOLUTION_FAILED,
`Couldn't find a suitable Node resolution for the specified unqualified path\n\nSource path: ${unqualifiedPath}\n${candidates.map(candidate => `Rejected resolution: ${candidate}\n`).join(``)}`,
{unqualifiedPath},
);
}
};
function resolveVirtual(request: PortablePath) {
const normalized = ppath.normalize(request);
const resolved = VirtualFS.resolveVirtual(normalized);
return resolved !== normalized ? resolved : null;
}