Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function parseDependency(filepath: string): Promise {
const result = await parser.parseFileAsync(filepath);
if (result.hasFatalError) {
throw new Error(`Fatal parse error in ${filepath}: ${result.errors}`);
}
if (result.dependencies.length > 1) {
throw new Error(`A JS file must have only one dependency: ${filepath}`);
}
if (result.dependencies.length === 0) {
throw new Error(`No dependencies found: ${filepath}`);
}
return result.dependencies[0];
}